r33069 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33068‎ | r33069 | r33070 >
Date:10:51, 10 April 2008
Author:catrope
Status:old
Tags:
Comment:
(bug 13544) Added oldid parameter to action=parse to allow for parsing of old revisions
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiParse.php
@@ -43,30 +43,49 @@
4444 $text = $params['text'];
4545 $title = $params['title'];
4646 $page = $params['page'];
 47+ $oldid = $params['oldid'];
4748 if(!is_null($page) && (!is_null($text) || $title != "API"))
4849 $this->dieUsage("The page parameter cannot be used together with the text and title parameters", 'params');
4950 $prop = array_flip($params['prop']);
5051 $revid = false;
5152
5253 global $wgParser, $wgUser;
53 - if(!is_null($page)) {
54 - $titleObj = Title::newFromText($page);
55 - if(!$titleObj)
56 - $this->dieUsage("The page you specified doesn't exist", 'missingtitle');
 54+ if(!is_null($oldid) || !is_null($page))
 55+ {
 56+ if(!is_null($oldid))
 57+ {
 58+ # Don't use the parser cache
 59+ $rev = Revision::newFromID($oldid);
 60+ if(!$rev)
 61+ $this->dieUsage("There is no revision ID $oldid", 'missingrev');
 62+ if(!$rev->userCan(Revision::DELETED_TEXT))
 63+ $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
 64+ $text = $rev->getRawText();
 65+ $titleObj = $rev->getTitle();
 66+ $p_result = $wgParser->parse($text, $titleObj, new ParserOptions());
 67+ }
 68+ else
 69+ {
 70+ $titleObj = Title::newFromText($page);
 71+ if(!$titleObj)
 72+ $this->dieUsage("The page you specified doesn't exist", 'missingtitle');
5773
58 - // Try the parser cache first
59 - $articleObj = new Article($titleObj);
60 - if(isset($prop['revid']))
61 - $revid = $articleObj->getRevIdFetched();
62 - $pcache = ParserCache::singleton();
63 - $p_result = $pcache->get($articleObj, $wgUser);
64 - if(!$p_result) {
65 - $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, new ParserOptions());
66 - global $wgUseParserCache;
67 - if($wgUseParserCache)
68 - $pcache->save($p_result, $articleObj, $wgUser);
 74+ // Try the parser cache first
 75+ $articleObj = new Article($titleObj);
 76+ if(isset($prop['revid']))
 77+ $oldid = $articleObj->getRevIdFetched();
 78+ $pcache = ParserCache::singleton();
 79+ $p_result = $pcache->get($articleObj, $wgUser);
 80+ if(!$p_result) {
 81+ $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, new ParserOptions());
 82+ global $wgUseParserCache;
 83+ if($wgUseParserCache)
 84+ $pcache->save($p_result, $articleObj, $wgUser);
 85+ }
6986 }
70 - } else {
 87+ }
 88+ else
 89+ {
7190 $titleObj = Title::newFromText($title);
7291 if(!$titleObj)
7392 $titleObj = Title::newFromText("API");
@@ -94,8 +113,8 @@
95114 $result_array['externallinks'] = array_keys($p_result->getExternalLinks());
96115 if(isset($prop['sections']))
97116 $result_array['sections'] = $p_result->getSections();
98 - if($revid !== false)
99 - $result_array['revid'] = $revid;
 117+ if($oldid !== false)
 118+ $result_array['revid'] = $oldid;
100119
101120 $result_mapping = array(
102121 'langlinks' => 'll',
@@ -162,6 +181,7 @@
163182 ),
164183 'text' => null,
165184 'page' => null,
 185+ 'oldid' => null,
166186 'prop' => array(
167187 ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid',
168188 ApiBase :: PARAM_ISMULTI => true,
@@ -185,6 +205,7 @@
186206 'text' => 'Wikitext to parse',
187207 'title' => 'Title of page the text belongs to',
188208 'page' => 'Parse the content of this page. Cannot be used together with text and title',
 209+ 'oldid' => 'Parse the content of this revision. Overrides page',
189210 'prop' => array('Which pieces of information to get.',
190211 'NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present'
191212 ),
Index: trunk/phase3/RELEASE-NOTES
@@ -208,6 +208,7 @@
209209 * (bug 12136) Extend allowed characters in JSON callback to ][.'"_A-Za-z0-9
210210 * (bug 11673) Return error 'unknown_action' in specified format
211211 * (bug 13618) Added rcprop=redirect and rcshow=redirect to list=recentchanges
 212+* (bug 13544) Added oldid parameter to action=parse to allow for parsing of old revisions
212213
213214 === Languages updated in 1.13 ===
214215

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r32541(bug 13544) Added prop=revid to action=parsecatrope13:27, 28 March 2008

Status & tagging log