Index: trunk/phase3/includes/api/ApiParse.php |
— | — | @@ -43,30 +43,49 @@ |
44 | 44 | $text = $params['text']; |
45 | 45 | $title = $params['title']; |
46 | 46 | $page = $params['page']; |
| 47 | + $oldid = $params['oldid']; |
47 | 48 | if(!is_null($page) && (!is_null($text) || $title != "API")) |
48 | 49 | $this->dieUsage("The page parameter cannot be used together with the text and title parameters", 'params'); |
49 | 50 | $prop = array_flip($params['prop']); |
50 | 51 | $revid = false; |
51 | 52 | |
52 | 53 | 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'); |
57 | 73 | |
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 | + } |
69 | 86 | } |
70 | | - } else { |
| 87 | + } |
| 88 | + else |
| 89 | + { |
71 | 90 | $titleObj = Title::newFromText($title); |
72 | 91 | if(!$titleObj) |
73 | 92 | $titleObj = Title::newFromText("API"); |
— | — | @@ -94,8 +113,8 @@ |
95 | 114 | $result_array['externallinks'] = array_keys($p_result->getExternalLinks()); |
96 | 115 | if(isset($prop['sections'])) |
97 | 116 | $result_array['sections'] = $p_result->getSections(); |
98 | | - if($revid !== false) |
99 | | - $result_array['revid'] = $revid; |
| 117 | + if($oldid !== false) |
| 118 | + $result_array['revid'] = $oldid; |
100 | 119 | |
101 | 120 | $result_mapping = array( |
102 | 121 | 'langlinks' => 'll', |
— | — | @@ -162,6 +181,7 @@ |
163 | 182 | ), |
164 | 183 | 'text' => null, |
165 | 184 | 'page' => null, |
| 185 | + 'oldid' => null, |
166 | 186 | 'prop' => array( |
167 | 187 | ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid', |
168 | 188 | ApiBase :: PARAM_ISMULTI => true, |
— | — | @@ -185,6 +205,7 @@ |
186 | 206 | 'text' => 'Wikitext to parse', |
187 | 207 | 'title' => 'Title of page the text belongs to', |
188 | 208 | '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', |
189 | 210 | 'prop' => array('Which pieces of information to get.', |
190 | 211 | 'NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present' |
191 | 212 | ), |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -208,6 +208,7 @@ |
209 | 209 | * (bug 12136) Extend allowed characters in JSON callback to ][.'"_A-Za-z0-9 |
210 | 210 | * (bug 11673) Return error 'unknown_action' in specified format |
211 | 211 | * (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 |
212 | 213 | |
213 | 214 | === Languages updated in 1.13 === |
214 | 215 | |