r81407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81406‎ | r81407 | r81408 >
Date:19:18, 2 February 2011
Author:catrope
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/REL1_17/phase3/RELEASE-NOTES (modified) (history)
  • /branches/REL1_17/phase3/includes/api/ApiParamInfo.php (modified) (history)
  • /branches/REL1_17/phase3/includes/api/ApiParse.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/api/ApiParse.php
@@ -34,7 +34,7 @@
3535 */
3636 class ApiParse extends ApiBase {
3737
38 - private $section;
 38+ private $section, $text, $pstText = null;
3939
4040 public function __construct( $main, $action ) {
4141 parent::__construct( $main, $action );
@@ -77,8 +77,11 @@
7878 $popts = new ParserOptions();
7979 $popts->setTidy( true );
8080 $popts->enableLimitReport( !$params['disablepp'] );
 81+
8182 $redirValues = null;
 83+
8284 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
 85+
8386 if ( !is_null( $oldid ) ) {
8487 // Don't use the parser cache
8588 $rev = Revision::newFromID( $oldid );
@@ -95,38 +98,33 @@
9699
97100 //If for some reason the "oldid" is actually the current revision, it may be cached
98101 if ( $titleObj->getLatestRevID() === $oldid ) {
99 - $p_result = false;
100 - $pcache = ParserCache::singleton();
101 - if ( $wgEnableParserCache ) {
102 - $p_result = $pcache->get( $titleObj, $popts );
103 - }
104 - if ( !$p_result ) {
105 - $text = $rev->getText( Revision::FOR_THIS_USER );
106 - $p_result = $wgParser->parse( $text, $titleObj, $popts );
 102+ $articleObj = new Article( $titleObj, 0 );
107103
108 - if ( $wgEnableParserCache ) {
109 - $pcache->save( $p_result, $titleObj, $popts );
110 - }
111 - }
112 - } else {
113 - $text = $rev->getText( Revision::FOR_THIS_USER );
 104+ $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid,
 105+ isset( $prop['wikitext'] ) ) ;
114106
 107+ } else { // This is an old revision, so get the text differently
 108+ $this->text = $rev->getText( Revision::FOR_THIS_USER );
 109+
115110 $wgTitle = $titleObj;
116111
117112 if ( $this->section !== false ) {
118 - $text = $this->getSectionText( $text, 'r' . $rev->getId() );
 113+ $this->text = $this->getSectionText( $this->text, 'r' . $rev->getId() );
119114 }
120115
121 - $p_result = $wgParser->parse( $text, $titleObj, $popts );
 116+ $p_result = $wgParser->parse( $this->text, $titleObj, $popts );
122117 }
123 - } else {
 118+
 119+ } else { // Not $oldid
 120+
124121 if ( !is_null ( $pageid ) ) {
125122 $titleObj = Title::newFromID( $pageid );
126123
127124 if ( !$titleObj ) {
128125 $this->dieUsageMsg( array( 'nosuchpageid', $pageid ) );
129126 }
130 - } else {
 127+ } else { // $page
 128+
131129 if ( $params['redirects'] ) {
132130 $req = new FauxRequest( array(
133131 'action' => 'query',
@@ -145,37 +143,24 @@
146144 $to = $page;
147145 }
148146 $titleObj = Title::newFromText( $to );
149 - if ( !$titleObj ) {
 147+ if ( !$titleObj || !$titleObj->exists() ) {
150148 $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
151149 }
152150 }
153151 $wgTitle = $titleObj;
154152
155 - $articleObj = new Article( $titleObj );
 153+ $articleObj = new Article( $titleObj, 0 );
156154 if ( isset( $prop['revid'] ) ) {
157155 $oldid = $articleObj->getRevIdFetched();
158156 }
159157
160 - if ( $this->section !== false ) {
161 - $text = $this->getSectionText( $text, !is_null ( $pageid ) ? 'page id ' . $pageid : $titleObj->getText() );
162 - $p_result = $wgParser->parse( $text, $titleObj, $popts );
163 - } else {
164 - // Try the parser cache first
165 - $p_result = false;
166 - $pcache = ParserCache::singleton();
167 - if ( $wgEnableParserCache ) {
168 - $p_result = $pcache->get( $articleObj, $popts );
169 - }
170 - if ( !$p_result ) {
171 - $p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts );
 158+ $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid,
 159+ isset( $prop['wikitext'] ) ) ;
 160+ }
172161
173 - if ( $wgEnableParserCache ) {
174 - $pcache->save( $p_result, $articleObj, $popts );
175 - }
176 - }
177 - }
178 - }
179 - } else {
 162+ } else { // Not $oldid, $pageid, $page. Hence based on $text
 163+
 164+ $this->text = $text;
180165 $titleObj = Title::newFromText( $title );
181166 if ( !$titleObj ) {
182167 $titleObj = Title::newFromText( 'API' );
@@ -183,20 +168,24 @@
184169 $wgTitle = $titleObj;
185170
186171 if ( $this->section !== false ) {
187 - $text = $this->getSectionText( $text, $titleObj->getText() );
 172+ $this->text = $this->getSectionText( $this->text, $titleObj->getText() );
188173 }
189174
190175 if ( $params['pst'] || $params['onlypst'] ) {
191 - $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts );
 176+ $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $wgUser, $popts );
192177 }
193178 if ( $params['onlypst'] ) {
194179 // Build a result and bail out
195180 $result_array['text'] = array();
196 - $this->getResult()->setContent( $result_array['text'], $text );
 181+ $this->getResult()->setContent( $result_array['text'], $this->pstText );
 182+ if ( isset( $prop['wikitext'] ) ) {
 183+ $result_array['wikitext'] = array();
 184+ $this->getResult()->setContent( $result_array['wikitext'], $this->text );
 185+ }
197186 $this->getResult()->addValue( null, $this->getModuleName(), $result_array );
198187 return;
199188 }
200 - $p_result = $wgParser->parse( $text, $titleObj, $popts );
 189+ $p_result = $wgParser->parse( $params['pst'] ? $this->pstText : $this->text, $titleObj, $popts );
201190 }
202191
203192 // Return result
@@ -279,6 +268,15 @@
280269 if ( isset( $prop['iwlinks'] ) ) {
281270 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
282271 }
 272+
 273+ if ( isset( $prop['wikitext'] ) ) {
 274+ $result_array['wikitext'] = array();
 275+ $result->setContent( $result_array['wikitext'], $this->text );
 276+ if ( !is_null( $this->pstText ) ) {
 277+ $result_array['psttext'] = array();
 278+ $result->setContent( $result_array['psttext'], $this->pstText );
 279+ }
 280+ }
283281
284282 if ( !is_null( $oldid ) ) {
285283 $result_array['revid'] = intval( $oldid );
@@ -304,6 +302,35 @@
305303 }
306304 }
307305
 306+ /**
 307+ * @param $articleObj Article
 308+ * @param $titleObj Title
 309+ * @param $popts ParserOptions
 310+ * @param $pageId Int
 311+ * @param $getWikitext Bool
 312+ * @return ParserOutput
 313+ */
 314+ private function getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageId = null, $getWikitext = false ) {
 315+ if ( $this->section !== false ) {
 316+ global $wgParser;
 317+
 318+ $this->text = $this->getSectionText( $articleObj->getRawText(), !is_null ( $pageId )
 319+ ? 'page id ' . $pageId : $titleObj->getText() );
 320+
 321+ return $wgParser->parse( $this->text, $titleObj, $popts );
 322+ } else {
 323+ // Try the parser cache first
 324+ $pout = $articleObj->getParserOutput();
 325+ if ( $getWikitext ) {
 326+ $rev = Revision::newFromTitle( $titleObj );
 327+ if ( $rev ) {
 328+ $this->text = $rev->getText();
 329+ }
 330+ }
 331+ return $pout;
 332+ }
 333+ }
 334+
308335 private function getSectionText( $text, $what ) {
309336 global $wgParser;
310337 $text = $wgParser->getSection( $text, $this->section, false );
@@ -318,7 +345,12 @@
319346 foreach ( $links as $link ) {
320347 $entry = array();
321348 $bits = explode( ':', $link, 2 );
 349+ $title = Title::newFromText( $link );
 350+
322351 $entry['lang'] = $bits[0];
 352+ if ( $title ) {
 353+ $entry['url'] = $title->getFullURL();
 354+ }
323355 $this->getResult()->setContent( $entry, $bits[1] );
324356 $result[] = $entry;
325357 }
@@ -445,6 +477,7 @@
446478 'headitems',
447479 'headhtml',
448480 'iwlinks',
 481+ 'wikitext',
449482 )
450483 ),
451484 'pst' => false,
@@ -482,6 +515,7 @@
483516 ' headitems - Gives items to put in the <head> of the page',
484517 ' headhtml - Gives parsed <head> of the page',
485518 ' iwlinks - Gives interwiki links in the parsed wikitext',
 519+ ' wikitext - Gives the original wikitext that was parsed',
486520 'NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present'
487521 ),
488522 'pst' => array(
Property changes on: branches/REL1_17/phase3/includes/api/ApiParse.php
___________________________________________________________________
Modified: svn:mergeinfo
489523 Merged /trunk/phase3/includes/api/ApiParse.php:r79454-79456,79536,79727,79733,79773-79774,80728,81121,81124,81406
Index: branches/REL1_17/phase3/includes/api/ApiParamInfo.php
@@ -88,6 +88,7 @@
8989 $result = $this->getResult();
9090 $retval['classname'] = get_class( $obj );
9191 $retval['description'] = implode( "\n", (array)$obj->getDescription() );
 92+ $retval['examples'] = implode( "\n", (array)$obj->getExamples() );
9293 $retval['version'] = implode( "\n", (array)$obj->getVersion() );
9394 $retval['prefix'] = $obj->getModulePrefix();
9495
Index: branches/REL1_17/phase3/RELEASE-NOTES
@@ -495,6 +495,7 @@
496496 * BREAKING CHANGE: action=patrol now requires POST
497497 * BREAKING CHANGE: patrol token is no longer the same as edit token
498498 * (bug 24650) Fix API to work with categorylinks changes
 499+* action=parse now correctly returns an error for nonexistent pages
499500
500501 * (bug 22738) Allow filtering by action type on query=logevent.
501502 * (bug 22764) uselang parameter for action=parse.
Property changes on: branches/REL1_17/phase3/RELEASE-NOTES
___________________________________________________________________
Modified: svn:mergeinfo
502503 Merged /trunk/phase3/RELEASE-NOTES:r79454-79456,79536,79727,79733,79773-79774,80728,81121,81124

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79454Per Platonides on CR r75334, use $article->getParserOutput() to get latest re...reedy22:49, 1 January 2011
r79455Allow section to work with oldid when oldid == currentrevid (worked with olde...reedy23:01, 1 January 2011
r79456Add missing $popts parameter, and pass it from r79455reedy23:06, 1 January 2011
r79536make action=parse return a missingtitle error if the page param refers to a m...vyznev23:20, 3 January 2011
r79727Fix -rakkaus/#mediawiki-i18n- [06-Jan-2011 16:10:59] PHP Notice: Undefined v...reedy16:24, 6 January 2011
r79733Pass 0 as 2nd parameter of an Article Constructor (2 cases)reedy17:06, 6 January 2011
r79773Adding some spaces, and some else block comments (due to length or ApiParse [...reedy23:19, 6 January 2011
r79774More tweaks/comments/fixups per r79455...reedy23:35, 6 January 2011
r80728Make paraminfo output examples along with parameter information.zak23:12, 21 January 2011
r81121Add the resolved URL of each langlink to the API's action=parse outputcatrope01:09, 28 January 2011
r81124Implement prop=wikitext in action=parse, (optionally) returning the original ...catrope01:47, 28 January 2011
r81406Fix regression in r81124, causing &pst to be ignored for the purposees of act...catrope19:16, 2 February 2011

Status & tagging log