Index: trunk/phase3/includes/api/ApiParse.php |
— | — | @@ -45,11 +45,18 @@ |
46 | 46 | $page = $params['page']; |
47 | 47 | $pageid = $params['pageid']; |
48 | 48 | $oldid = $params['oldid']; |
| 49 | + |
49 | 50 | if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) { |
50 | 51 | $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' ); |
51 | 52 | } |
52 | 53 | $prop = array_flip( $params['prop'] ); |
53 | 54 | $revid = false; |
| 55 | + |
| 56 | + if ( isset( $params['section'] ) ) { |
| 57 | + $this->section = $params['section']; |
| 58 | + } else { |
| 59 | + $this->section = false; |
| 60 | + } |
54 | 61 | |
55 | 62 | // The parser needs $wgTitle to be set, apparently the |
56 | 63 | // $title parameter in Parser::parse isn't enough *sigh* |
— | — | @@ -80,6 +87,11 @@ |
81 | 88 | $text = $rev->getText( Revision::FOR_THIS_USER ); |
82 | 89 | $titleObj = $rev->getTitle(); |
83 | 90 | $wgTitle = $titleObj; |
| 91 | + |
| 92 | + if ( $this->section !== false ) { |
| 93 | + $text = $this->getSectionText( $text, 'r' . $rev ); |
| 94 | + } |
| 95 | + |
84 | 96 | $p_result = $wgParser->parse( $text, $titleObj, $popts ); |
85 | 97 | } else { |
86 | 98 | if ( !is_null ( $pageid ) ) { |
— | — | @@ -117,18 +129,24 @@ |
118 | 130 | if ( isset( $prop['revid'] ) ) { |
119 | 131 | $oldid = $articleObj->getRevIdFetched(); |
120 | 132 | } |
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 ); |
129 | 133 | |
| 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(); |
130 | 141 | if ( $wgEnableParserCache ) { |
131 | | - $pcache->save( $p_result, $articleObj, $popts ); |
| 142 | + $p_result = $pcache->get( $articleObj, $wgUser ); |
132 | 143 | } |
| 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 | + } |
133 | 151 | } |
134 | 152 | } |
135 | 153 | } else { |
— | — | @@ -137,6 +155,11 @@ |
138 | 156 | $titleObj = Title::newFromText( 'API' ); |
139 | 157 | } |
140 | 158 | $wgTitle = $titleObj; |
| 159 | + |
| 160 | + if ( $this->section !== false ) { |
| 161 | + $text = $this->getSectionText( $text, $titleObj->getText() ); |
| 162 | + } |
| 163 | + |
141 | 164 | if ( $params['pst'] || $params['onlypst'] ) { |
142 | 165 | $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts ); |
143 | 166 | } |
— | — | @@ -228,6 +251,15 @@ |
229 | 252 | } |
230 | 253 | } |
231 | 254 | |
| 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 | + |
232 | 264 | private function formatLangLinks( $links ) { |
233 | 265 | $result = array(); |
234 | 266 | foreach ( $links as $link ) { |
— | — | @@ -317,6 +349,8 @@ |
318 | 350 | ), |
319 | 351 | 'pst' => false, |
320 | 352 | 'onlypst' => false, |
| 353 | + 'uselang' => null, |
| 354 | + 'section' => null, |
321 | 355 | ); |
322 | 356 | } |
323 | 357 | |
— | — | @@ -338,7 +372,8 @@ |
339 | 373 | 'onlypst' => array( 'Do a pre-save transform (PST) on the input, but don\'t parse it.', |
340 | 374 | 'Returns the same wikitext, after a PST has been applied. Ignored if page, pageid or oldid is used.' |
341 | 375 | ), |
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', |
343 | 378 | ); |
344 | 379 | } |
345 | 380 | |
— | — | @@ -352,6 +387,7 @@ |
353 | 388 | array( 'code' => 'missingrev', 'info' => 'There is no revision ID oldid' ), |
354 | 389 | array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revisions' ), |
355 | 390 | array( 'code' => 'missingtitle', 'info' => 'The page you specified doesn\'t exist' ), |
| 391 | + array( 'code' => 'nosuchsection', 'info' => 'There is no section in '), |
356 | 392 | array( 'nosuchpageid' ), |
357 | 393 | ) ); |
358 | 394 | } |
Index: trunk/phase3/includes/api/ApiQueryRevisions.php |
— | — | @@ -425,12 +425,13 @@ |
426 | 426 | |
427 | 427 | $text = null; |
428 | 428 | if ( $this->fld_content || !is_null( $this->difftotext ) ) { |
429 | | - global $wgParser; |
430 | 429 | $text = $revision->getText(); |
431 | 430 | // Expand templates after getting section content because |
432 | 431 | // template-added sections don't count and Parser::preprocess() |
433 | 432 | // will have less input |
434 | 433 | if ( $this->section !== false ) { |
| 434 | + global $wgParser; |
| 435 | + |
435 | 436 | $text = $wgParser->getSection( $text, $this->section, false ); |
436 | 437 | if ( $text === false ) { |
437 | 438 | $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' ); |
— | — | @@ -557,7 +558,7 @@ |
558 | 559 | 'excludeuser' => 'Exclude revisions made by user', |
559 | 560 | 'expandtemplates' => 'Expand templates in revision content', |
560 | 561 | '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', |
562 | 563 | 'token' => 'Which tokens to obtain for each revision', |
563 | 564 | 'continue' => 'When more results are available, use this to continue', |
564 | 565 | 'diffto' => array( 'Revision ID to diff each revision to.', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -171,6 +171,7 @@ |
172 | 172 | is empty, for consistency with list=recentchanges |
173 | 173 | * (bug 19721) API action=help should have a way to just list for a specific module |
174 | 174 | * (bug 23458) Add support for pageid parameter to action=parse requests |
| 175 | +* (bug 23460) Parse action should have a section option |
175 | 176 | |
176 | 177 | === Languages updated in 1.17 === |
177 | 178 | |