r103613 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103612‎ | r103613 | r103614 >
Date:21:36, 18 November 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Use ParserOptions::newFromContext() to not depend on $wgUser and $wgLang
* Use a WikiPage object instead of Article to get the text or the ParserOutput and create the object directly in getParsedSectionOrText()
* Use Title::getLatestRevID() instead of Article::getRevIdFetched() since the latter will always return the current revision ID when 0 is passed as second parameter to the constructor
* Pass the User object to Revision::getText()
* Removed double setting of $wgTitle
Modified paths:
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiParse.php
@@ -67,7 +67,7 @@
6868 $wgLang = Language::factory( $params['uselang'] );
6969 }
7070
71 - $popts = new ParserOptions();
 71+ $popts = ParserOptions::newFromContext( $this->getContext() );
7272 $popts->setTidy( true );
7373 $popts->enableLimitReport( !$params['disablepp'] );
7474
@@ -93,16 +93,12 @@
9494
9595 // If for some reason the "oldid" is actually the current revision, it may be cached
9696 if ( $titleObj->getLatestRevID() === intval( $oldid ) ) {
97 - $articleObj = new Article( $titleObj, 0 );
98 -
9997 // May get from/save to parser cache
100 - $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid,
 98+ $p_result = $this->getParsedSectionOrText( $titleObj, $popts, $pageid,
10199 isset( $prop['wikitext'] ) ) ;
102100 } else { // This is an old revision, so get the text differently
103 - $this->text = $rev->getText( Revision::FOR_THIS_USER );
 101+ $this->text = $rev->getText( Revision::FOR_THIS_USER, $this->getUser() );
104102
105 - $wgTitle = $titleObj;
106 -
107103 if ( $this->section !== false ) {
108104 $this->text = $this->getSectionText( $this->text, 'r' . $rev->getId() );
109105 }
@@ -152,13 +148,12 @@
153149 }
154150 $wgTitle = $titleObj;
155151
156 - $articleObj = new Article( $titleObj, 0 );
157152 if ( isset( $prop['revid'] ) ) {
158 - $oldid = $articleObj->getRevIdFetched();
 153+ $oldid = $titleObj->getLatestRevID();
159154 }
160155
161156 // Potentially cached
162 - $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid,
 157+ $p_result = $this->getParsedSectionOrText( $titleObj, $popts, $pageid,
163158 isset( $prop['wikitext'] ) ) ;
164159 }
165160 } else { // Not $oldid, $pageid, $page. Hence based on $text
@@ -308,18 +303,19 @@
309304 }
310305
311306 /**
312 - * @param $articleObj Article
313307 * @param $titleObj Title
314308 * @param $popts ParserOptions
315309 * @param $pageId Int
316310 * @param $getWikitext Bool
317311 * @return ParserOutput
318312 */
319 - private function getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageId = null, $getWikitext = false ) {
320 - if ( $this->section !== false ) {
321 - global $wgParser;
 313+ private function getParsedSectionOrText( $titleObj, $popts, $pageId = null, $getWikitext = false ) {
 314+ global $wgParser;
322315
323 - $this->text = $this->getSectionText( $articleObj->getRawText(), !is_null( $pageId )
 316+ $page = WikiPage::factory( $titleObj );
 317+
 318+ if ( $this->section !== false ) {
 319+ $this->text = $this->getSectionText( $page->getRawText(), !is_null( $pageId )
324320 ? 'page id ' . $pageId : $titleObj->getText() );
325321
326322 // Not cached (save or load)
@@ -327,12 +323,9 @@
328324 } else {
329325 // Try the parser cache first
330326 // getParserOutput will save to Parser cache if able
331 - $pout = $articleObj->getParserOutput();
 327+ $pout = $page->getParserOutput( $popts );
332328 if ( $getWikitext ) {
333 - $rev = Revision::newFromTitle( $titleObj );
334 - if ( $rev ) {
335 - $this->text = $rev->getText();
336 - }
 329+ $this->text = $page->getRawText();
337330 }
338331 return $pout;
339332 }

Comments

#Comment by Aaron Schulz (talk | contribs)   00:57, 14 December 2011
-				$rev = Revision::newFromTitle( $titleObj );
-				if ( $rev ) {
-					$this->text = $rev->getText();
-				}
+				$this->text = $page->getRawText();

The permission checks on the text fell off.

#Comment by IAlex (talk | contribs)   19:19, 16 December 2011

Such case will the handled by the $rev->userCan( Revision::DELETED_TEXT ) check on line 86.

#Comment by Aaron Schulz (talk | contribs)   19:37, 16 December 2011

Looks OK then. Not sure how to decrease the "reviewer anxiety" in this code, maybe with some comments. The current page text cannot be deleted, so the non-oldid case is fine too.

#Comment by IAlex (talk | contribs)   19:38, 16 December 2011

Article::getRawText() is basically safe because it returns only the current content and it cannot be deleted.

#Comment by Aaron Schulz (talk | contribs)   19:48, 16 December 2011

That's what I meant above :)

Status & tagging log