From: Roan Kattouw Date: Thu, 10 Apr 2008 10:51:40 +0000 (+0000) Subject: (bug 13544) Added oldid parameter to action=parse to allow for parsing of old revisions X-Git-Tag: 1.31.0-rc.0~48465 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=c338619cd3389b87001405905e14ea07b2a8c864;p=lhc%2Fweb%2Fwiklou.git (bug 13544) Added oldid parameter to action=parse to allow for parsing of old revisions --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 808adf4d86..8d9bf070c6 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -208,6 +208,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 12136) Extend allowed characters in JSON callback to ][.'"_A-Za-z0-9 * (bug 11673) Return error 'unknown_action' in specified format * (bug 13618) Added rcprop=redirect and rcshow=redirect to list=recentchanges +* (bug 13544) Added oldid parameter to action=parse to allow for parsing of old revisions === Languages updated in 1.13 === diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index a8d2ea584c..16d400baef 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -43,30 +43,49 @@ class ApiParse extends ApiBase { $text = $params['text']; $title = $params['title']; $page = $params['page']; + $oldid = $params['oldid']; if(!is_null($page) && (!is_null($text) || $title != "API")) $this->dieUsage("The page parameter cannot be used together with the text and title parameters", 'params'); $prop = array_flip($params['prop']); $revid = false; global $wgParser, $wgUser; - if(!is_null($page)) { - $titleObj = Title::newFromText($page); - if(!$titleObj) - $this->dieUsage("The page you specified doesn't exist", 'missingtitle'); + if(!is_null($oldid) || !is_null($page)) + { + if(!is_null($oldid)) + { + # Don't use the parser cache + $rev = Revision::newFromID($oldid); + if(!$rev) + $this->dieUsage("There is no revision ID $oldid", 'missingrev'); + if(!$rev->userCan(Revision::DELETED_TEXT)) + $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied'); + $text = $rev->getRawText(); + $titleObj = $rev->getTitle(); + $p_result = $wgParser->parse($text, $titleObj, new ParserOptions()); + } + else + { + $titleObj = Title::newFromText($page); + if(!$titleObj) + $this->dieUsage("The page you specified doesn't exist", 'missingtitle'); - // Try the parser cache first - $articleObj = new Article($titleObj); - if(isset($prop['revid'])) - $revid = $articleObj->getRevIdFetched(); - $pcache = ParserCache::singleton(); - $p_result = $pcache->get($articleObj, $wgUser); - if(!$p_result) { - $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, new ParserOptions()); - global $wgUseParserCache; - if($wgUseParserCache) - $pcache->save($p_result, $articleObj, $wgUser); + // Try the parser cache first + $articleObj = new Article($titleObj); + if(isset($prop['revid'])) + $oldid = $articleObj->getRevIdFetched(); + $pcache = ParserCache::singleton(); + $p_result = $pcache->get($articleObj, $wgUser); + if(!$p_result) { + $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, new ParserOptions()); + global $wgUseParserCache; + if($wgUseParserCache) + $pcache->save($p_result, $articleObj, $wgUser); + } } - } else { + } + else + { $titleObj = Title::newFromText($title); if(!$titleObj) $titleObj = Title::newFromText("API"); @@ -94,8 +113,8 @@ class ApiParse extends ApiBase { $result_array['externallinks'] = array_keys($p_result->getExternalLinks()); if(isset($prop['sections'])) $result_array['sections'] = $p_result->getSections(); - if($revid !== false) - $result_array['revid'] = $revid; + if($oldid !== false) + $result_array['revid'] = $oldid; $result_mapping = array( 'langlinks' => 'll', @@ -162,6 +181,7 @@ class ApiParse extends ApiBase { ), 'text' => null, 'page' => null, + 'oldid' => null, 'prop' => array( ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid', ApiBase :: PARAM_ISMULTI => true, @@ -185,6 +205,7 @@ class ApiParse extends ApiBase { 'text' => 'Wikitext to parse', 'title' => 'Title of page the text belongs to', 'page' => 'Parse the content of this page. Cannot be used together with text and title', + 'oldid' => 'Parse the content of this revision. Overrides page', 'prop' => array('Which pieces of information to get.', 'NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present' ),