From 49c8975c3b5e751d3423c39ff6d5bd5d66fb765d Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 1 Jan 2011 23:01:24 +0000 Subject: [PATCH] Allow section to work with oldid when oldid == currentrevid (worked with older id) --- includes/api/ApiParse.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) 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 ); -- 2.20.1