Is it dangerous to call WikiPage->doEdit inside a parser tag callback?
I'm writing a parser tag extension <whatever>, whose callback function is:
public static function myCallback($input, $argv, $parser) { $t = Title::newFromText('anytitle'); // any article title at all $p = WikiPage::factory($t); $p->doEdit('my text', 'my comment'); return 'foo'; }
The doEdit always succeeds (based on its return Status). But somewhere later, as the parser tag renders, the following error always gets thrown:
Invalid marker: UNIQ586469ef5f8b5a1a-whatever-00000000-QINU
Backtrace:
#0 /var/www/html/w/includes/parser/StripState.php(66): StripState->addItem('general', 'UNIQ586469ef5f...', 'foo') #1 /var/www/html/w/includes/parser/Parser.php(3844): StripState->addGeneral('UNIQ586469ef5f...', 'foo') #2 /var/www/html/w/includes/parser/Preprocessor_DOM.php(1150): Parser->extensionSubstitution(Array, Object(PPFrame_DOM)) #3 /var/www/html/w/includes/parser/Parser.php(3038): PPFrame_DOM->expand(Object(PPNode_DOM), 0) #4 /var/www/html/w/includes/parser/Parser.php(1136): Parser->replaceVariables('<whatever/>') #5 /var/www/html/w/includes/parser/Parser.php(370): Parser->internalParse('<whatever/>') #6 /var/www/html/w/includes/WikiPage.php(3110): Parser->parse('<whatever/>', Object(Title), Object(ParserOptions), true, true, 1429350) #7 /var/www/html/w/includes/PoolCounter.php(209): PoolWorkArticleView->doWork() #8 /var/www/html/w/includes/Article.php(631): PoolCounterWork->execute() #9 /var/www/html/w/includes/actions/ViewAction.php(37): Article->view() #10 /var/www/html/w/includes/Wiki.php(427): ViewAction->show() #11 /var/www/html/w/includes/Wiki.php(304): MediaWiki->performAction(Object(Article)) #12 /var/www/html/w/includes/Wiki.php(536): MediaWiki->performRequest() #13 /var/www/html/w/includes/Wiki.php(446): MediaWiki->main() #14 /var/www/html/w/index.php(75): MediaWiki->run() #15 {main}
So I am wondering: is it dangerous to call doEdit inside a parser tag's callback? Is there another way to make a parser tag create an article? This is MediaWiki 1.20. Thank you, DanB
The doEdit() call needs to parse and reuses $wgParser, which is already in use so it probably breaks the state of it. Maybe you could use a DeferredUpdate to actually to the edits, or do them via an api.php request, or stash $wgParser, replace it with a new one before doing the edit and then swap it back.
In any case doing edits on tag parse could be kind of slow (e.g. someone does a page preview with hundreds of tags in it). One might want to limit that somehow.
-- View this message in context: http://wikimedia.7.x6.nabble.com/Is-WikiPage-doEdit-dangerous-in-a-parser-ta... Sent from the Wikipedia Developers mailing list archive at Nabble.com.
On 2013-10-11 1:24 PM, "Aaron Schulz" aschulz4587@gmail.com wrote:
The doEdit() call needs to parse and reuses $wgParser, which is already in use so it probably breaks the state of it. Maybe you could use a DeferredUpdate to actually to the edits, or do them via an api.php
request,
or stash $wgParser, replace it with a new one before doing the edit and
then
swap it back.
In any case doing edits on tag parse could be kind of slow (e.g. someone does a page preview with hundreds of tags in it). One might want to limit that somehow.
-- View this message in context:
http://wikimedia.7.x6.nabble.com/Is-WikiPage-doEdit-dangerous-in-a-parser-ta...
Sent from the Wikipedia Developers mailing list archive at Nabble.com.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
The babel extension works around this by mixing the globals.
Note calling api.php internally to edit (not making actual http request) will still cause parser to be called recursively and is unsafe from parser tags.
-bawolff
Thanks for your suggestion!
I wound up deferring the edits by adding them to the MediaWiki job queue.
DanB
wikitech-l@lists.wikimedia.org