r66150 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66149‎ | r66150 | r66151 >
Date:18:27, 10 May 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 23460) Parse action should have a section option

Also add uselang parameter, not originally added in r63428

Clarify section description in both. Move global into if statement
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiParse.php
@@ -45,11 +45,18 @@
4646 $page = $params['page'];
4747 $pageid = $params['pageid'];
4848 $oldid = $params['oldid'];
 49+
4950 if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) {
5051 $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' );
5152 }
5253 $prop = array_flip( $params['prop'] );
5354 $revid = false;
 55+
 56+ if ( isset( $params['section'] ) ) {
 57+ $this->section = $params['section'];
 58+ } else {
 59+ $this->section = false;
 60+ }
5461
5562 // The parser needs $wgTitle to be set, apparently the
5663 // $title parameter in Parser::parse isn't enough *sigh*
@@ -80,6 +87,11 @@
8188 $text = $rev->getText( Revision::FOR_THIS_USER );
8289 $titleObj = $rev->getTitle();
8390 $wgTitle = $titleObj;
 91+
 92+ if ( $this->section !== false ) {
 93+ $text = $this->getSectionText( $text, 'r' . $rev );
 94+ }
 95+
8496 $p_result = $wgParser->parse( $text, $titleObj, $popts );
8597 } else {
8698 if ( !is_null ( $pageid ) ) {
@@ -117,18 +129,24 @@
118130 if ( isset( $prop['revid'] ) ) {
119131 $oldid = $articleObj->getRevIdFetched();
120132 }
121 - // Try the parser cache first
122 - $p_result = false;
123 - $pcache = ParserCache::singleton();
124 - if ( $wgEnableParserCache ) {
125 - $p_result = $pcache->get( $articleObj, $wgUser );
126 - }
127 - if ( !$p_result ) {
128 - $p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts );
129133
 134+ if ( $this->section !== false ) {
 135+ $text = $this->getSectionText( $text, !is_null ( $pageid ) ? 'page id ' . $pageid : $titleObj->getText() );
 136+ $p_result = $wgParser->parse( $text, $titleObj, $popts );
 137+ } else {
 138+ // Try the parser cache first
 139+ $p_result = false;
 140+ $pcache = ParserCache::singleton();
130141 if ( $wgEnableParserCache ) {
131 - $pcache->save( $p_result, $articleObj, $popts );
 142+ $p_result = $pcache->get( $articleObj, $wgUser );
132143 }
 144+ if ( !$p_result ) {
 145+ $p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts );
 146+
 147+ if ( $wgEnableParserCache ) {
 148+ $pcache->save( $p_result, $articleObj, $popts );
 149+ }
 150+ }
133151 }
134152 }
135153 } else {
@@ -137,6 +155,11 @@
138156 $titleObj = Title::newFromText( 'API' );
139157 }
140158 $wgTitle = $titleObj;
 159+
 160+ if ( $this->section !== false ) {
 161+ $text = $this->getSectionText( $text, $titleObj->getText() );
 162+ }
 163+
141164 if ( $params['pst'] || $params['onlypst'] ) {
142165 $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts );
143166 }
@@ -228,6 +251,15 @@
229252 }
230253 }
231254
 255+ private function getSectionText( $text, $what ) {
 256+ global $wgParser;
 257+ $text = $wgParser->getSection( $text, $this->section, false );
 258+ if ( $text === false ) {
 259+ $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
 260+ }
 261+ return $text;
 262+ }
 263+
232264 private function formatLangLinks( $links ) {
233265 $result = array();
234266 foreach ( $links as $link ) {
@@ -317,6 +349,8 @@
318350 ),
319351 'pst' => false,
320352 'onlypst' => false,
 353+ 'uselang' => null,
 354+ 'section' => null,
321355 );
322356 }
323357
@@ -338,7 +372,8 @@
339373 'onlypst' => array( 'Do a pre-save transform (PST) on the input, but don\'t parse it.',
340374 'Returns the same wikitext, after a PST has been applied. Ignored if page, pageid or oldid is used.'
341375 ),
342 - 'uselang' => 'Which language to parse the request in.'
 376+ 'uselang' => 'Which language to parse the request in.',
 377+ 'section' => 'Only retrieve the content of this section number',
343378 );
344379 }
345380
@@ -352,6 +387,7 @@
353388 array( 'code' => 'missingrev', 'info' => 'There is no revision ID oldid' ),
354389 array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revisions' ),
355390 array( 'code' => 'missingtitle', 'info' => 'The page you specified doesn\'t exist' ),
 391+ array( 'code' => 'nosuchsection', 'info' => 'There is no section in '),
356392 array( 'nosuchpageid' ),
357393 ) );
358394 }
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -425,12 +425,13 @@
426426
427427 $text = null;
428428 if ( $this->fld_content || !is_null( $this->difftotext ) ) {
429 - global $wgParser;
430429 $text = $revision->getText();
431430 // Expand templates after getting section content because
432431 // template-added sections don't count and Parser::preprocess()
433432 // will have less input
434433 if ( $this->section !== false ) {
 434+ global $wgParser;
 435+
435436 $text = $wgParser->getSection( $text, $this->section, false );
436437 if ( $text === false ) {
437438 $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
@@ -557,7 +558,7 @@
558559 'excludeuser' => 'Exclude revisions made by user',
559560 'expandtemplates' => 'Expand templates in revision content',
560561 'generatexml' => 'Generate XML parse tree for revision content',
561 - 'section' => 'Only retrieve the content of this section',
 562+ 'section' => 'Only retrieve the content of this section number',
562563 'token' => 'Which tokens to obtain for each revision',
563564 'continue' => 'When more results are available, use this to continue',
564565 'diffto' => array( 'Revision ID to diff each revision to.',
Index: trunk/phase3/RELEASE-NOTES
@@ -171,6 +171,7 @@
172172 is empty, for consistency with list=recentchanges
173173 * (bug 19721) API action=help should have a way to just list for a specific module
174174 * (bug 23458) Add support for pageid parameter to action=parse requests
 175+* (bug 23460) Parse action should have a section option
175176
176177 === Languages updated in 1.17 ===
177178

Follow-up revisions

RevisionCommit summaryAuthorDate
r66152Fixup getPossibleErrors description from r66150, add missing placeholdersreedy18:54, 10 May 2010
r79762Fix string concat error in r66150. Also was a bug/notice in TWreedy22:06, 6 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r63428* (bug 22764) uselang parameter for action=parse...reedy22:32, 8 March 2010

Comments

#Comment by Catrope (talk | contribs)   18:51, 10 May 2010
+			array( 'code' => 'nosuchsection', 'info' => 'There is no section  in '),

Seems to be missing placeholders, is this intentional?

#Comment by Reedy (talk | contribs)   18:52, 10 May 2010

Ooops, no. Seems I got distracted

#Comment by Duplicatebug (talk | contribs)   22:02, 6 January 2011

You cannot use $rev inside a string concat. Maybe use $rev->getId() (Fails for revid != latestrevid and section)

#Comment by Reedy (talk | contribs)   22:05, 6 January 2011

Ahh. Cheers. That's the source of a bug for TW I think...

Status & tagging log