Extension talk:AutoCreatePage

Jump to navigation Jump to search

About this board

Trigger for creating new page

Tommyheyser (talkcontribs)

After I had installed the extension and added the parser function to an existing template that's used on a bunch of pages, new pages weren't being created as I had hoped. It turns out that new page creation isn't triggered until the page that contains the template is edited and saved (a null edit works), but purge (refresh) doesn't seem to trigger this. I hadn't read the instruction on GitHub, but it does mention this, just not on the MediaWiki extension page. I'm assuming this is because the name of the edit user is required so that the new page can be attributed to the same user.

Is it possible to trigger this somehow for multiple pages? I have 300+ pages that I'd like to use this on and not too thrill about null-editing 300+ pages. I could use ReplaceText on the pages, but I also have the ApprovedRevs extension installed, which means that I would then have to approve all the pages. I don't want to then use the mass approve script that comes with ApprovedRevs, since there are existing unapproved pages that I cannot approve (cannot as in I don't have the authorisation to approve those pages).

Edit: ReplaceText doesn't trigger the new page creation.

Reply to "Trigger for creating new page"

here it's working, there it's not

أحمد (talkcontribs)

I have one wiki where #createpageifnotex is working flawlessly on custom domains whose names are in $wgContentNamespaces, but not in a another wiki in a custom domain that is also in $wgContentNamespaces.

Am I missing something?

Oetterer (talkcontribs)

The documentation might be a bit misleading: $egAutoCreatePageNamespaces will be initialized with $wgContentNamespaces. If you add namespaces later, you have to add them to both config settings.

أحمد (talkcontribs)

Do you mean that the initialisation of $egAutoCreatePageNamespaces takes place upon the first run and is somehow persisted for later invocations?

Oetterer (talkcontribs)

I'm not shure what you mean with later invocations. In your config, you should have an entry that looks like this:

require_once "$IP/extensions/AutoCreatePage/AutoCreatePage.php";
$egAutoCreatePageNamespaces = [

Where NS_CUSTOM is the constant you defined for an additional namespace the extension should work in. Note that this is only an example, you can have as many entries in that array as you need.

أحمد (talkcontribs)

I now understand what you mean: If $egAutoCreatePageNamespaces is set to any value in config, then it no longer merges the values from $wgContentNamespaces. In other words the setting in config overrides the default, instead of appending to it.

Oetterer (talkcontribs)

Correct. AutoCreatePage does not use the new extension loader, so the moment the require command in your config is executed, $egAutoCreatePageNamespaces will be initialized with $wgContentNamespaces. After that, they will be treated separately. You can have

$wgContentNamespaces = [

require_once "$IP/extensions/AutoCreatePage/AutoCreatePage.php";

but not

require_once "$IP/extensions/AutoCreatePage/AutoCreatePage.php";
$wgContentNamespaces = [


You could have something like this

$wgContentNamespaces = [

require_once "$IP/extensions/AutoCreatePage/AutoCreatePage.php";
$egAutoCreatePageNamespaces[] = NS_CUSTOM2

Which will result in $egAutoCreatePageNamespaces containing three values.

Reply to "here it's working, there it's not"

Extension not working at all

Summary by Kghbln
JeremiPlazas (talkcontribs)

Hi there,

Working on

Product Version
MediaWiki 1.29.2
PHP 5.6.36 (apache2handler)
MySQL 5.6.40
ICU 50.1.2
Elasticsearch 5.3.3

Extension was working until a little while ago. Not sure what happened. It was inside #if function. Multiple instances of #createpageifnotex function on same page. Tried reducing to one instance inside a template. Tried increasing $egAutoCreatePageMaxRecursion and toggle $egAutoCreatePageIgnoreEmptyTitle to true. Nothing is working. Even specified $egAutoCreatePageNamespaces to include TEMPLATE namespace. No errors, even with debug on. Just nothing happening. Tried running the jobs list. still nothing.

Any clues anyone?


Kghbln (talkcontribs)

> Extension was working until a little while ago. Not sure what happened.

Did you upgrade MediaWiki, PHP, etc.? If yes which versions were you using before.? This will probably help developers to assess the situation a bit better.

Kghbln (talkcontribs)
JeremiPlazas (talkcontribs)

Thanks much. Logged in to sandbox and tested. Everything working fine there. Of course the software setup is newer. But still...


Oetterer (talkcontribs)

I'm running it succesfully on 1.27.4. Just to be sure: you added NS_TEMPLATEto the array $egAutoCreatePageNamespaces?

JeremiPlazas (talkcontribs)

Yes I did. And no I did not update MW or PHP. It just stopped working at some point. Also it is now breaking another wiki on that same farm:

[85b369eaf612a29031da2ec0] /index.php/Main_Page MWException from line 336 of /mnt/centaurdata/websites/MediaWikiFarm/includes/MagicWord.php: Error: invalid magic word 'createPage'


#0 /mnt/centaurdata/websites/MediaWikiFarm/includes/MagicWord.php(261): MagicWord->load(string)

#1 /mnt/centaurdata/websites/MediaWikiFarm/includes/parser/Parser.php(4858): MagicWord::get(string)

#2 /mnt/centaurdata/websites/MediaWikiFarm/extensions/AutoCreatePage/AutoCreatePage.php(55): Parser->setFunctionHook(string, Closure)

#3 [internal function]: {closure}(Parser)

#4 /mnt/centaurdata/websites/MediaWikiFarm/includes/Hooks.php(186): call_user_func_array(Closure, array)

#5 /mnt/centaurdata/websites/MediaWikiFarm/includes/parser/Parser.php(337): Hooks::run(string, array)

#6 [internal function]: Parser->firstCallInit()

#7 /mnt/centaurdata/websites/MediaWikiFarm/includes/StubObject.php(113): call_user_func_array(array, array)

#8 /mnt/centaurdata/websites/MediaWikiFarm/includes/StubObject.php(139): StubObject->_call(string, array)

#9 /mnt/centaurdata/websites/MediaWikiFarm/includes/cache/MessageCache.php(1112): StubObject->__call(string, array)

#10 /mnt/centaurdata/websites/MediaWikiFarm/includes/cache/MessageCache.php(1112): StubObject->firstCallInit()

#11 /mnt/centaurdata/websites/MediaWikiFarm/includes/cache/MessageCache.php(1088): MessageCache->getParser()

#12 /mnt/centaurdata/websites/MediaWikiFarm/includes/Message.php(1259): MessageCache->transform(string, boolean, Language, Title)

#13 /mnt/centaurdata/websites/MediaWikiFarm/includes/Message.php(874): Message->transformText(string)

#14 /mnt/centaurdata/websites/MediaWikiFarm/includes/Message.php(934): Message->toString(string)

#15 /mnt/centaurdata/websites/MediaWikiFarm/includes/OutputPage.php(936): Message->text()

#16 /mnt/centaurdata/websites/MediaWikiFarm/includes/OutputPage.php(984): OutputPage->setHTMLTitle(Message)

#17 /mnt/centaurdata/websites/MediaWikiFarm/includes/page/Article.php(464): OutputPage->setPageTitle(string)

#18 /mnt/centaurdata/websites/MediaWikiFarm/includes/actions/ViewAction.php(68): Article->view()

#19 /mnt/centaurdata/websites/MediaWikiFarm/includes/MediaWiki.php(499): ViewAction->show()

#20 /mnt/centaurdata/websites/MediaWikiFarm/includes/MediaWiki.php(293): MediaWiki->performAction(Article, Title)

#21 /mnt/centaurdata/websites/MediaWikiFarm/includes/MediaWiki.php(862): MediaWiki->performRequest()

#22 /mnt/centaurdata/websites/MediaWikiFarm/includes/MediaWiki.php(523): MediaWiki->main()

#23 /mnt/centaurdata/websites/MediaWikiFarm/index.php(43): MediaWiki->run()

#24 {main}

JeremiPlazas (talkcontribs)

Hey all, so it seems i've figured out why it wouldn't work on my initial wiki. (Still don't know why it's breaking this other wiki above, if you have info on that, t'would be great.) But i was trying to run the parser function from a subpage, which doesn't seem to work. When i call the function from a root page it works fine. Is there any way to make it work from subpages?

Thanks again for the help! (talkcontribs)

That is at least partially good news. It would be best, if you could add an issue on the extension’s github page concerning the problem with subpages. This way you maximize your chances for a fix.

JeremiPlazas (talkcontribs)
Kghbln (talkcontribs)

@Oetter: On sandbox I added the template namespace to the configuration parameter though I am not sure why this is needed.

@JeremiPlazas You claim in your original report that it worked from subpages before. Thus it will be nice if you could add the info what exactly changed in your setup.

Apart from that it is great to see that the extension at least works from regular pages.

JeremiPlazas (talkcontribs)

Also, tested the #createpageifnotex parser function from a subpage on sandbox and that works fine. So something preventing it for me. Version issue?

Kghbln (talkcontribs)

You said that it worked some time. So what changed? Did you upgrade? Did you add another extension?

Summary by Kghbln

Works with MW 1.30.x and 1.31.x

أحمد (talkcontribs)

Few questions:

  1. Does this still work in mw1.30?
  2. Can it create a page with a namespace specified? Is any special escaping needed for the colon?
  3. With the default of $egAutoCreatePageNamespaces = [ NS_MAIN, NS_USER, NS_CUSTOM ];, does it mean that it will work in template included in a page in the main namespace? Or Do I should add "NS_TEMPLATE"?
أحمد (talkcontribs)

After some testing, I have affirmative answers for 1, 2 and 3

Baxi69 (talkcontribs)


I added 3 lines to AutoCreatePage.php behind line 94:

$newPageContent = str_replace ( "{" , "{" , str_replace ( "}" , "}" , $newPageContent ) );

$newPageContent = str_replace ( "|" , "|" , $newPageContent );

$newPageContent = str_replace ( """ , "#" , $newPageContent );

This makes the use of templates much easier. Just write in the template what you need with &#123&#59;, &#125&#59, and &#124&#59; and &#34&#59; into a template. Include the template in the parameter, and all works as expected. Made my life much easier...

Kghbln (talkcontribs)

Heiya, thank you for sharing your improvement. Why not creating a pull request at GitHub? Cheers

Baxi69 (talkcontribs)

I'm a bit in war with git...

Wanted to place an extension there, failed, and didn't have time to learn all about git...

I'm not English native, and did not find good documentation.

Kghbln (talkcontribs)
Markus Krötzsch (talkcontribs)

You can just write <nowiki> around your content to achieve this, like so:

{{#createpageifnotex:New page title|<nowiki>{{Template|parameter=value}}</nowiki>}}

Maybe the documentation on the extension page needs to be extended to clarify this.

Baxi69 (talkcontribs)

It's not so easy sometimes. If you place the new content into a template, and you pass parameters to the template, you can get fast a lot of blocks like:<nowik>...some content...</nowiki>{{{...|}}}<nowik>...some content...</nowiki> inside the template, while replacing the "&#xxx;" makes the source much easier to read.

My call looks like this:

{{#createpageifnotex:New page title|{{Template|parameter=value}} }}

Meaning, I call the template with params, and want the params to get placed into the template content. But I don't want to get the template functions executed.

Reply to "Added 3 stripping lines"

Accepting Template Parameter for the magic word?

Summary by TheD3xus

Used wrong parameter. Works now! THANK YOU FOR AN AMAZING EXTENSION!

TheD3xus (talkcontribs)

This extension works perfectly with explicitly stated strings and text, but I'm having trouble transcluding parameters from a template onto this magic word.


{{#createpageifnotex:{{{1|}}}|#REDIRECT [[{{{2|}}}]]}}

I keep getting an error of: Error: this function must be given a valid title text for the page to be created. What am I doing wrong?


Oetterer (talkcontribs)

I'm using your extension for my new project and I must say: it's a real life saver! Thank you very much for your work, it is really appreciated! :)

During development, I was wondering: since a similar parser functions #ifexist is categorized as expensive does that apply to #createpageifnotex as well. And if so: regarding performance is it better to use #createpageifnotex directly without #ifexist?

Thanks in advance! :)

Regards, Tobi

Reply to "Expensive parser function?"
There are no older topics