X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiParse.php;h=92857edae40fda69c2d61306ba52c5fe06447497;hb=ee3e7075a51f110eb0bf0070799b81ce526a6aa3;hp=7c1637b63531a17ab44e760576c9286131bf8f17;hpb=b6f58ed41671913cc40010df584cb894d77687cf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 7c1637b635..92857edae4 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -53,6 +53,7 @@ class ApiParse extends ApiBase { $popts = new ParserOptions(); $popts->setTidy(true); $popts->enableLimitReport(); + $redirValues = null; if(!is_null($oldid) || !is_null($page)) { if(!is_null($oldid)) @@ -69,17 +70,35 @@ class ApiParse extends ApiBase { } else { - $titleObj = Title::newFromText($page); + if($params['redirects']) + { + $req = new FauxRequest(array( + 'action' => 'query', + 'redirects' => '', + 'titles' => $page + )); + $main = new ApiMain($req); + $main->execute(); + $data = $main->getResultData(); + $redirValues = @$data['query']['redirects']; + $to = $page; + foreach((array)$redirValues as $r) + $to = $r['to']; + } + else + $to = $page; + $titleObj = Title::newFromText($to); 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(); + // Try the parser cache first $pcache = ParserCache::singleton(); $p_result = $pcache->get($articleObj, $wgUser); - if(!$p_result) { + if(!$p_result) + { $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, $popts); global $wgUseParserCache; if($wgUseParserCache) @@ -98,6 +117,8 @@ class ApiParse extends ApiBase { // Return result $result = $this->getResult(); $result_array = array(); + if($params['redirects'] && !is_null($redirValues)) + $result_array['redirects'] = $redirValues; if(isset($prop['text'])) { $result_array['text'] = array(); $result->setContent($result_array['text'], $p_result->getText()); @@ -120,6 +141,7 @@ class ApiParse extends ApiBase { $result_array['revid'] = $oldid; $result_mapping = array( + 'redirects' => 'r', 'langlinks' => 'll', 'categories' => 'cl', 'links' => 'pl', @@ -184,6 +206,7 @@ class ApiParse extends ApiBase { ), 'text' => null, 'page' => null, + 'redirects' => false, 'oldid' => null, 'prop' => array( ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid', @@ -206,6 +229,7 @@ class ApiParse extends ApiBase { public function getParamDescription() { return array ( 'text' => 'Wikitext to parse', + 'redirects' => 'If the page parameter is set to a redirect, resolve it', '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',