From: Alexandre Emsenhuber Date: Fri, 18 Nov 2011 21:36:57 +0000 (+0000) Subject: * Use ParserOptions::newFromContext() to not depend on $wgUser and $wgLang X-Git-Tag: 1.31.0-rc.0~26433 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=b1bb28c606814c6c5abb632df92026b3c439c349;p=lhc%2Fweb%2Fwiklou.git * 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 --- diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 26ad39a0e4..9df69c7ef7 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -67,7 +67,7 @@ class ApiParse extends ApiBase { $wgLang = Language::factory( $params['uselang'] ); } - $popts = new ParserOptions(); + $popts = ParserOptions::newFromContext( $this->getContext() ); $popts->setTidy( true ); $popts->enableLimitReport( !$params['disablepp'] ); @@ -93,15 +93,11 @@ class ApiParse extends ApiBase { // If for some reason the "oldid" is actually the current revision, it may be cached if ( $titleObj->getLatestRevID() === intval( $oldid ) ) { - $articleObj = new Article( $titleObj, 0 ); - // May get from/save to parser cache - $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid, + $p_result = $this->getParsedSectionOrText( $titleObj, $popts, $pageid, isset( $prop['wikitext'] ) ) ; } else { // This is an old revision, so get the text differently - $this->text = $rev->getText( Revision::FOR_THIS_USER ); - - $wgTitle = $titleObj; + $this->text = $rev->getText( Revision::FOR_THIS_USER, $this->getUser() ); if ( $this->section !== false ) { $this->text = $this->getSectionText( $this->text, 'r' . $rev->getId() ); @@ -152,13 +148,12 @@ class ApiParse extends ApiBase { } $wgTitle = $titleObj; - $articleObj = new Article( $titleObj, 0 ); if ( isset( $prop['revid'] ) ) { - $oldid = $articleObj->getRevIdFetched(); + $oldid = $titleObj->getLatestRevID(); } // Potentially cached - $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid, + $p_result = $this->getParsedSectionOrText( $titleObj, $popts, $pageid, isset( $prop['wikitext'] ) ) ; } } else { // Not $oldid, $pageid, $page. Hence based on $text @@ -308,18 +303,19 @@ class ApiParse extends ApiBase { } /** - * @param $articleObj Article * @param $titleObj Title * @param $popts ParserOptions * @param $pageId Int * @param $getWikitext Bool * @return ParserOutput */ - private function getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageId = null, $getWikitext = false ) { - if ( $this->section !== false ) { - global $wgParser; + private function getParsedSectionOrText( $titleObj, $popts, $pageId = null, $getWikitext = false ) { + global $wgParser; - $this->text = $this->getSectionText( $articleObj->getRawText(), !is_null( $pageId ) + $page = WikiPage::factory( $titleObj ); + + if ( $this->section !== false ) { + $this->text = $this->getSectionText( $page->getRawText(), !is_null( $pageId ) ? 'page id ' . $pageId : $titleObj->getText() ); // Not cached (save or load) @@ -327,12 +323,9 @@ class ApiParse extends ApiBase { } else { // Try the parser cache first // getParserOutput will save to Parser cache if able - $pout = $articleObj->getParserOutput(); + $pout = $page->getParserOutput( $popts ); if ( $getWikitext ) { - $rev = Revision::newFromTitle( $titleObj ); - if ( $rev ) { - $this->text = $rev->getText(); - } + $this->text = $page->getRawText(); } return $pout; }