Allow gender based localisation for 'lastmodifiedatby'
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index 2f74226..d998070 100644 (file)
@@ -49,7 +49,9 @@ class ApiParse extends ApiBase {
                $prop = array_flip($params['prop']);
                $revid = false;
 
-               global $wgParser, $wgUser;
+               // The parser needs $wgTitle to be set, apparently the
+               // $title parameter in Parser::parse isn't enough *sigh*
+               global $wgParser, $wgUser, $wgTitle;
                $popts = new ParserOptions();
                $popts->setTidy(true);
                $popts->enableLimitReport();
@@ -66,6 +68,7 @@ class ApiParse extends ApiBase {
                                        $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
                                $text = $rev->getText( Revision::FOR_THIS_USER );
                                $titleObj = $rev->getTitle();
+                               $wgTitle = $titleObj;
                                $p_result = $wgParser->parse($text, $titleObj, $popts);
                        }
                        else
@@ -102,7 +105,7 @@ class ApiParse extends ApiBase {
                                        $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, $popts);
                                        global $wgUseParserCache;
                                        if($wgUseParserCache)
-                                               $pcache->save($p_result, $articleObj, $wgUser);
+                                               $pcache->save($p_result, $articleObj, $popts);
                                }
                        }
                }
@@ -111,6 +114,7 @@ class ApiParse extends ApiBase {
                        $titleObj = Title::newFromText($title);
                        if(!$titleObj)
                                $titleObj = Title::newFromText("API");
+                       $wgTitle = $titleObj;
                        if($params['pst'] || $params['onlypst'])
                                $text = $wgParser->preSaveTransform($text, $titleObj, $wgUser, $popts);
                        if($params['onlypst'])
@@ -147,8 +151,12 @@ class ApiParse extends ApiBase {
                        $result_array['externallinks'] = array_keys($p_result->getExternalLinks());
                if(isset($prop['sections']))
                        $result_array['sections'] = $p_result->getSections();
+               if(isset($prop['displaytitle']))
+                       $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
+                                                       $p_result->getDisplayTitle() :
+                                                       $titleObj->getPrefixedText();
                if(!is_null($oldid))
-                       $result_array['revid'] = $oldid;
+                       $result_array['revid'] = intval($oldid);
 
                $result_mapping = array(
                        'redirects' => 'r',
@@ -219,7 +227,7 @@ class ApiParse extends ApiBase {
                        'redirects' => false,
                        'oldid' => null,
                        'prop' => array(
-                               ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid',
+                               ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
                                ApiBase :: PARAM_ISMULTI => true,
                                ApiBase :: PARAM_TYPE => array(
                                        'text',
@@ -230,7 +238,8 @@ class ApiParse extends ApiBase {
                                        'images',
                                        'externallinks',
                                        'sections',
-                                       'revid'
+                                       'revid',
+                                       'displaytitle',
                                )
                        ),
                        'pst' => false,