(bug 13544) Added oldid parameter to action=parse to allow for parsing of old revisions
This commit is contained in:
parent
59c7812ca3
commit
c338619cd3
2 changed files with 41 additions and 19 deletions
|
|
@ -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 ===
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
// 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);
|
||||
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 {
|
||||
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']))
|
||||
$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
|
||||
{
|
||||
$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'
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in a new issue