From: Sam Reed Date: Sat, 1 Jan 2011 23:01:24 +0000 (+0000) Subject: Allow section to work with oldid when oldid == currentrevid (worked with older id) X-Git-Tag: 1.31.0-rc.0~32905 X-Git-Url: https://git.cyclocoop.org/%20%27.%28%24debut%20%20%20%24par_page%29.%27?a=commitdiff_plain;h=49c8975c3b5e751d3423c39ff6d5bd5d66fb765d;p=lhc%2Fweb%2Fwiklou.git Allow section to work with oldid when oldid == currentrevid (worked with older id) --- diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 7029683128..6f3ddaa47d 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -96,9 +96,9 @@ 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 ); - $wgTitle = $titleObj; - $p_result = $articleObj->getParserOutput(); + $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $pageid ) ; + } else { $text = $rev->getText( Revision::FOR_THIS_USER ); @@ -147,15 +147,7 @@ class ApiParse extends ApiBase { $oldid = $articleObj->getRevIdFetched(); } - if ( $this->section !== false ) { - $text = $this->getSectionText( $text, !is_null ( $pageid ) - ? 'page id ' . $pageid : $titleObj->getText() ); - - $p_result = $wgParser->parse( $text, $titleObj, $popts ); - } else { - // Try the parser cache first - $p_result = $articleObj->getParserOutput(); - } + $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $pageid ) ; } } else { $titleObj = Title::newFromText( $title ); @@ -286,6 +278,26 @@ class ApiParse extends ApiBase { } } + /** + * @param $articleObj Article + * @param $titleObj Title + * @param $pageId Int + * @return ParserOutput + */ + private function getParsedSectionOrText( $articleObj, $titleObj, $pageId = null ) { + global $wgParser; + + if ( $this->section !== false ) { + $text = $this->getSectionText( $text, !is_null ( $pageId ) + ? 'page id ' . $pageId : $titleObj->getText() ); + + return $wgParser->parse( $text, $titleObj, $popts ); + } else { + // Try the parser cache first + return $articleObj->getParserOutput(); + } + } + private function getSectionText( $text, $what ) { global $wgParser; $text = $wgParser->getSection( $text, $this->section, false );