Thread:Project:Support desk/How can I make an Extension create an Article?

Hi everyone.

I'm trying to write a piece of code, that imports one (specific) ical-file (calendar-data) into the wiki (=creates an article), so a calendar extension uses it. The code should be executed when the calendar is viewed (there'll be restrictions to that). For test purposes I use a tag on a page to start it and just let it create a "test" page with some text. But there are two basic problems:


 * One: The "test" page is only created when the starter page is saved (or previewed) - not when it's viewed.
 * Two: When the "test" page is created, the title of the starter page is changed to "test"

The problem lies in the $article->doEdit part. Here's a simple code for reproduction: setHook( 'test', 'autoEdit' ); return true; }

function autoEdit($paramstring, $params = array) { $debug="check"; $newtitle="test"; $newarticle = new Article(Title::newFromText($newtitle), 0);

$testtext="ThisPageWasCreatedByAnExtension";

$newarticle->doEdit($testtext, EDIT_UPDATE); return $debug; }

This is in MW 1.17.0 and 1.19alpha/1.18alpha (intern/download) with php: 5.3.3-1ubuntu9.5 (apache2handler) However, 1.18 doesn't change the "starter"-title but instead reports an internal error: Invalid marker: UNIQ1b659bf462b401f8-test-00000001-QINU

Backtrace:


 * 1) 0 /home/inviron/www/TestWiki118a/includes/parser/StripState.php(37): StripState->addItem('general', 'UNIQ1b659bf462...', 'check')
 * 2) 1 /home/inviron/www/TestWiki118a/includes/parser/Parser.php(3745): StripState->addGeneral('UNIQ1b659bf462...', 'check')
 * 3) 2 /home/inviron/www/TestWiki118a/includes/parser/Preprocessor_DOM.php(1110): Parser->extensionSubstitution(Array, Object(PPFrame_DOM))
 * 4) 3 /home/inviron/www/TestWiki118a/includes/parser/Parser.php(2983): PPFrame_DOM->expand(Object(PPNode_DOM), 0)
 * 5) 4 /home/inviron/www/TestWiki118a/includes/parser/Parser.php(1142): Parser->replaceVariables(' ')
 * 6) 5 /home/inviron/www/TestWiki118a/includes/parser/Parser.php(340): Parser->internalParse(' ')
 * 7) 6 /home/inviron/www/TestWiki118a/includes/WikiPage.php(1927): Parser->parse(' ', Object(Title), Object(ParserOptions), true, true, NULL)
 * 8) 7 /home/inviron/www/TestWiki118a/includes/WikiPage.php(1057): WikiPage->prepareTextForEdit(' ', NULL, Object(User))
 * 9) 8 [internal function]: WikiPage->doEdit(' ', '', 97)
 * 10) 9 /home/inviron/www/TestWiki118a/includes/Article.php(2012): call_user_func_array(Array, Array)
 * 11) 10 /home/inviron/www/TestWiki118a/includes/EditPage.php(1161): Article->__call('doEdit', Array)
 * 12) 11 /home/inviron/www/TestWiki118a/includes/EditPage.php(1161): Article->doEdit(' ', '', 97)
 * 13) 12 /home/inviron/www/TestWiki118a/includes/EditPage.php(2815): EditPage->internalAttemptSave(false, false)
 * 14) 13 /home/inviron/www/TestWiki118a/includes/EditPage.php(475): EditPage->attemptSave
 * 15) 14 /home/inviron/www/TestWiki118a/includes/EditPage.php(353): EditPage->edit
 * 16) 15 /home/inviron/www/TestWiki118a/includes/Wiki.php(496): EditPage->submit
 * 17) 16 /home/inviron/www/TestWiki118a/includes/Wiki.php(236): MediaWiki->performAction(Object(Article))
 * 18) 17 /home/inviron/www/TestWiki118a/includes/Wiki.php(621): MediaWiki->performRequest
 * 19) 18 /home/inviron/www/TestWiki118a/includes/Wiki.php(529): MediaWiki->main
 * 20) 19 /home/inviron/www/TestWiki118a/index.php(57): MediaWiki->run
 * 21) 20 {main}

This might be related to https://bugzilla.wikimedia.org/show_bug.cgi?id=24997

Is this even the right way to create a wikipage in an extension? Should this work? Is there another way to do it?

Any help is appreciated.