Example #1
0
 public function execute()
 {
     // The data is hot but user-dependent, like page views, so we set vary cookies
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     $text = $params['text'];
     $title = $params['title'];
     if ($title === null) {
         $titleProvided = false;
         // A title is needed for parsing, so arbitrarily choose one
         $title = 'API';
     } else {
         $titleProvided = true;
     }
     $page = $params['page'];
     $pageid = $params['pageid'];
     $oldid = $params['oldid'];
     $model = $params['contentmodel'];
     $format = $params['contentformat'];
     if (!is_null($page) && (!is_null($text) || $titleProvided)) {
         $this->dieUsage('The page parameter cannot be used together with the text and title parameters', 'params');
     }
     $prop = array_flip($params['prop']);
     if (isset($params['section'])) {
         $this->section = $params['section'];
     } else {
         $this->section = false;
     }
     // The parser needs $wgTitle to be set, apparently the
     // $title parameter in Parser::parse isn't enough *sigh*
     // TODO: Does this still need $wgTitle?
     global $wgParser, $wgTitle;
     // Currently unnecessary, code to act as a safeguard against any change
     // in current behavior of uselang
     $oldLang = null;
     if (isset($params['uselang']) && $params['uselang'] != $this->getContext()->getLanguage()->getCode()) {
         $oldLang = $this->getContext()->getLanguage();
         // Backup language
         $this->getContext()->setLanguage(Language::factory($params['uselang']));
     }
     $redirValues = null;
     // Return result
     $result = $this->getResult();
     if (!is_null($oldid) || !is_null($pageid) || !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');
             }
             $this->checkReadPermissions($rev->getTitle());
             if (!$rev->userCan(Revision::DELETED_TEXT, $this->getUser())) {
                 $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
             }
             $titleObj = $rev->getTitle();
             $wgTitle = $titleObj;
             $pageObj = WikiPage::factory($titleObj);
             $popts = $this->makeParserOptions($pageObj, $params);
             // If for some reason the "oldid" is actually the current revision, it may be cached
             if ($rev->isCurrent()) {
                 // May get from/save to parser cache
                 $p_result = $this->getParsedContent($pageObj, $popts, $pageid, isset($prop['wikitext']));
             } else {
                 // This is an old revision, so get the text differently
                 $this->content = $rev->getContent(Revision::FOR_THIS_USER, $this->getUser());
                 if ($this->section !== false) {
                     $this->content = $this->getSectionContent($this->content, 'r' . $rev->getId());
                 }
                 // Should we save old revision parses to the parser cache?
                 $p_result = $this->content->getParserOutput($titleObj, $rev->getId(), $popts);
             }
         } else {
             // Not $oldid, but $pageid or $page
             if ($params['redirects']) {
                 $reqParams = array('action' => 'query', 'redirects' => '');
                 if (!is_null($pageid)) {
                     $reqParams['pageids'] = $pageid;
                 } else {
                     // $page
                     $reqParams['titles'] = $page;
                 }
                 $req = new FauxRequest($reqParams);
                 $main = new ApiMain($req);
                 $main->execute();
                 $data = $main->getResultData();
                 $redirValues = isset($data['query']['redirects']) ? $data['query']['redirects'] : array();
                 $to = $page;
                 foreach ((array) $redirValues as $r) {
                     $to = $r['to'];
                 }
                 $pageParams = array('title' => $to);
             } elseif (!is_null($pageid)) {
                 $pageParams = array('pageid' => $pageid);
             } else {
                 // $page
                 $pageParams = array('title' => $page);
             }
             $pageObj = $this->getTitleOrPageId($pageParams, 'fromdb');
             $titleObj = $pageObj->getTitle();
             if (!$titleObj || !$titleObj->exists()) {
                 $this->dieUsage("The page you specified doesn't exist", 'missingtitle');
             }
             $this->checkReadPermissions($titleObj);
             $wgTitle = $titleObj;
             if (isset($prop['revid'])) {
                 $oldid = $pageObj->getLatest();
             }
             $popts = $this->makeParserOptions($pageObj, $params);
             // Potentially cached
             $p_result = $this->getParsedContent($pageObj, $popts, $pageid, isset($prop['wikitext']));
         }
     } else {
         // Not $oldid, $pageid, $page. Hence based on $text
         $titleObj = Title::newFromText($title);
         if (!$titleObj || $titleObj->isExternal()) {
             $this->dieUsageMsg(array('invalidtitle', $title));
         }
         $wgTitle = $titleObj;
         if ($titleObj->canExist()) {
             $pageObj = WikiPage::factory($titleObj);
         } else {
             // Do like MediaWiki::initializeArticle()
             $article = Article::newFromTitle($titleObj, $this->getContext());
             $pageObj = $article->getPage();
         }
         $popts = $this->makeParserOptions($pageObj, $params);
         $textProvided = !is_null($text);
         if (!$textProvided) {
             if ($titleProvided && ($prop || $params['generatexml'])) {
                 $this->setWarning("'title' used without 'text', and parsed page properties were requested " . "(did you mean to use 'page' instead of 'title'?)");
             }
             // Prevent warning from ContentHandler::makeContent()
             $text = '';
         }
         // If we are parsing text, do not use the content model of the default
         // API title, but default to wikitext to keep BC.
         if ($textProvided && !$titleProvided && is_null($model)) {
             $model = CONTENT_MODEL_WIKITEXT;
             $this->setWarning("No 'title' or 'contentmodel' was given, assuming {$model}.");
         }
         try {
             $this->content = ContentHandler::makeContent($text, $titleObj, $model, $format);
         } catch (MWContentSerializationException $ex) {
             $this->dieUsage($ex->getMessage(), 'parseerror');
         }
         if ($this->section !== false) {
             $this->content = $this->getSectionContent($this->content, $titleObj->getText());
         }
         if ($params['pst'] || $params['onlypst']) {
             $this->pstContent = $this->content->preSaveTransform($titleObj, $this->getUser(), $popts);
         }
         if ($params['onlypst']) {
             // Build a result and bail out
             $result_array = array();
             $result_array['text'] = array();
             ApiResult::setContent($result_array['text'], $this->pstContent->serialize($format));
             if (isset($prop['wikitext'])) {
                 $result_array['wikitext'] = array();
                 ApiResult::setContent($result_array['wikitext'], $this->content->serialize($format));
             }
             $result->addValue(null, $this->getModuleName(), $result_array);
             return;
         }
         // Not cached (save or load)
         if ($params['pst']) {
             $p_result = $this->pstContent->getParserOutput($titleObj, null, $popts);
         } else {
             $p_result = $this->content->getParserOutput($titleObj, null, $popts);
         }
     }
     $result_array = array();
     $result_array['title'] = $titleObj->getPrefixedText();
     if (!is_null($oldid)) {
         $result_array['revid'] = intval($oldid);
     }
     if ($params['redirects'] && !is_null($redirValues)) {
         $result_array['redirects'] = $redirValues;
     }
     if ($params['disabletoc']) {
         $p_result->setTOCEnabled(false);
     }
     if (isset($prop['text'])) {
         $result_array['text'] = array();
         ApiResult::setContent($result_array['text'], $p_result->getText());
     }
     if (!is_null($params['summary'])) {
         $result_array['parsedsummary'] = array();
         ApiResult::setContent($result_array['parsedsummary'], Linker::formatComment($params['summary'], $titleObj));
     }
     if (isset($prop['langlinks']) || isset($prop['languageshtml'])) {
         $langlinks = $p_result->getLanguageLinks();
         if ($params['effectivelanglinks']) {
             // Link flags are ignored for now, but may in the future be
             // included in the result.
             $linkFlags = array();
             wfRunHooks('LanguageLinks', array($titleObj, &$langlinks, &$linkFlags));
         }
     } else {
         $langlinks = false;
     }
     if (isset($prop['langlinks'])) {
         $result_array['langlinks'] = $this->formatLangLinks($langlinks);
     }
     if (isset($prop['languageshtml'])) {
         $languagesHtml = $this->languagesHtml($langlinks);
         $result_array['languageshtml'] = array();
         ApiResult::setContent($result_array['languageshtml'], $languagesHtml);
     }
     if (isset($prop['categories'])) {
         $result_array['categories'] = $this->formatCategoryLinks($p_result->getCategories());
     }
     if (isset($prop['categorieshtml'])) {
         $categoriesHtml = $this->categoriesHtml($p_result->getCategories());
         $result_array['categorieshtml'] = array();
         ApiResult::setContent($result_array['categorieshtml'], $categoriesHtml);
     }
     if (isset($prop['links'])) {
         $result_array['links'] = $this->formatLinks($p_result->getLinks());
     }
     if (isset($prop['templates'])) {
         $result_array['templates'] = $this->formatLinks($p_result->getTemplates());
     }
     if (isset($prop['images'])) {
         $result_array['images'] = array_keys($p_result->getImages());
     }
     if (isset($prop['externallinks'])) {
         $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 (isset($prop['headitems']) || isset($prop['headhtml'])) {
         $context = new DerivativeContext($this->getContext());
         $context->setTitle($titleObj);
         $context->setWikiPage($pageObj);
         // We need an OutputPage tied to $context, not to the
         // RequestContext at the root of the stack.
         $output = new OutputPage($context);
         $output->addParserOutputNoText($p_result);
         if (isset($prop['headitems'])) {
             $headItems = $this->formatHeadItems($p_result->getHeadItems());
             $css = $this->formatCss($output->buildCssLinksArray());
             $scripts = array($output->getHeadScripts());
             $result_array['headitems'] = array_merge($headItems, $css, $scripts);
         }
         if (isset($prop['headhtml'])) {
             $result_array['headhtml'] = array();
             ApiResult::setContent($result_array['headhtml'], $output->headElement($context->getSkin()));
         }
     }
     if (isset($prop['iwlinks'])) {
         $result_array['iwlinks'] = $this->formatIWLinks($p_result->getInterwikiLinks());
     }
     if (isset($prop['wikitext'])) {
         $result_array['wikitext'] = array();
         ApiResult::setContent($result_array['wikitext'], $this->content->serialize($format));
         if (!is_null($this->pstContent)) {
             $result_array['psttext'] = array();
             ApiResult::setContent($result_array['psttext'], $this->pstContent->serialize($format));
         }
     }
     if (isset($prop['properties'])) {
         $result_array['properties'] = $this->formatProperties($p_result->getProperties());
     }
     if (isset($prop['limitreportdata'])) {
         $result_array['limitreportdata'] = $this->formatLimitReportData($p_result->getLimitReportData());
     }
     if (isset($prop['limitreporthtml'])) {
         $limitreportHtml = EditPage::getPreviewLimitReport($p_result);
         $result_array['limitreporthtml'] = array();
         ApiResult::setContent($result_array['limitreporthtml'], $limitreportHtml);
     }
     if ($params['generatexml']) {
         if ($this->content->getModel() != CONTENT_MODEL_WIKITEXT) {
             $this->dieUsage("generatexml is only supported for wikitext content", "notwikitext");
         }
         $wgParser->startExternalParse($titleObj, $popts, OT_PREPROCESS);
         $dom = $wgParser->preprocessToDom($this->content->getNativeData());
         if (is_callable(array($dom, 'saveXML'))) {
             $xml = $dom->saveXML();
         } else {
             $xml = $dom->__toString();
         }
         $result_array['parsetree'] = array();
         ApiResult::setContent($result_array['parsetree'], $xml);
     }
     $result_mapping = array('redirects' => 'r', 'langlinks' => 'll', 'categories' => 'cl', 'links' => 'pl', 'templates' => 'tl', 'images' => 'img', 'externallinks' => 'el', 'iwlinks' => 'iw', 'sections' => 's', 'headitems' => 'hi', 'properties' => 'pp', 'limitreportdata' => 'lr');
     $this->setIndexedTagNames($result_array, $result_mapping);
     $result->addValue(null, $this->getModuleName(), $result_array);
     if (!is_null($oldLang)) {
         $this->getContext()->setLanguage($oldLang);
         // Reset language to $oldLang
     }
 }
Example #2
0
 public function execute()
 {
     // The data is hot but user-dependent, like page views, so we set vary cookies
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     $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;
     // The parser needs $wgTitle to be set, apparently the
     // $title parameter in Parser::parse isn't enough *sigh*
     global $wgParser, $wgUser, $wgTitle, $wgEnableParserCache;
     $popts = new ParserOptions();
     $popts->setTidy(true);
     $popts->enableLimitReport();
     $redirValues = null;
     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->getText(Revision::FOR_THIS_USER);
             $titleObj = $rev->getTitle();
             $wgTitle = $titleObj;
             $p_result = $wgParser->parse($text, $titleObj, $popts);
         } else {
             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');
             }
             $articleObj = new Article($titleObj);
             if (isset($prop['revid'])) {
                 $oldid = $articleObj->getRevIdFetched();
             }
             // Try the parser cache first
             $p_result = false;
             $pcache = ParserCache::singleton();
             if ($wgEnableParserCache) {
                 $p_result = $pcache->get($articleObj, $wgUser);
             }
             if (!$p_result) {
                 $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, $popts);
                 if ($wgEnableParserCache) {
                     $pcache->save($p_result, $articleObj, $popts);
                 }
             }
         }
     } else {
         $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']) {
             // Build a result and bail out
             $result_array['text'] = array();
             $this->getResult()->setContent($result_array['text'], $text);
             $this->getResult()->addValue(null, $this->getModuleName(), $result_array);
             return;
         }
         $p_result = $wgParser->parse($text, $titleObj, $popts);
     }
     // 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());
     }
     if (!is_null($params['summary'])) {
         $result_array['parsedsummary'] = array();
         $result->setContent($result_array['parsedsummary'], $wgUser->getSkin()->formatComment($params['summary'], $titleObj));
     }
     if (isset($prop['langlinks'])) {
         $result_array['langlinks'] = $this->formatLangLinks($p_result->getLanguageLinks());
     }
     if (isset($prop['categories'])) {
         $result_array['categories'] = $this->formatCategoryLinks($p_result->getCategories());
     }
     if (isset($prop['links'])) {
         $result_array['links'] = $this->formatLinks($p_result->getLinks());
     }
     if (isset($prop['templates'])) {
         $result_array['templates'] = $this->formatLinks($p_result->getTemplates());
     }
     if (isset($prop['images'])) {
         $result_array['images'] = array_keys($p_result->getImages());
     }
     if (isset($prop['externallinks'])) {
         $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 (isset($prop['headitems'])) {
         $result_array['headitems'] = $this->formatHeadItems($p_result->getHeadItems());
     }
     if (isset($prop['headhtml'])) {
         $out = new OutputPage();
         $out->addParserOutputNoText($p_result);
         $result_array['headhtml'] = array();
         $result->setContent($result_array['headhtml'], $out->headElement($wgUser->getSkin()));
     }
     if (!is_null($oldid)) {
         $result_array['revid'] = intval($oldid);
     }
     $result_mapping = array('redirects' => 'r', 'langlinks' => 'll', 'categories' => 'cl', 'links' => 'pl', 'templates' => 'tl', 'images' => 'img', 'externallinks' => 'el', 'sections' => 's', 'headitems' => 'hi');
     $this->setIndexedTagNames($result_array, $result_mapping);
     $result->addValue(null, $this->getModuleName(), $result_array);
 }
Example #3
0
 public function execute()
 {
     // The data is hot but user-dependent, like page views, so we set vary cookies
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     $text = $params['text'];
     $title = $params['title'];
     if ($title === null) {
         $titleProvided = false;
         // A title is needed for parsing, so arbitrarily choose one
         $title = 'API';
     } else {
         $titleProvided = true;
     }
     $page = $params['page'];
     $pageid = $params['pageid'];
     $oldid = $params['oldid'];
     $model = $params['contentmodel'];
     $format = $params['contentformat'];
     if (!is_null($page) && (!is_null($text) || $titleProvided)) {
         $this->dieUsage('The page parameter cannot be used together with the text and title parameters', 'params');
     }
     $prop = array_flip($params['prop']);
     if (isset($params['section'])) {
         $this->section = $params['section'];
         if (!preg_match('/^((T-)?\\d+|new)$/', $this->section)) {
             $this->dieUsage('The section parameter must be a valid section id or "new"', 'invalidsection');
         }
     } else {
         $this->section = false;
     }
     // The parser needs $wgTitle to be set, apparently the
     // $title parameter in Parser::parse isn't enough *sigh*
     // TODO: Does this still need $wgTitle?
     global $wgParser, $wgTitle;
     $redirValues = null;
     // Return result
     $result = $this->getResult();
     if (!is_null($oldid) || !is_null($pageid) || !is_null($page)) {
         if ($this->section === 'new') {
             $this->dieUsage('section=new cannot be combined with oldid, pageid or page parameters. ' . 'Please use text', 'params');
         }
         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');
             }
             $this->checkReadPermissions($rev->getTitle());
             if (!$rev->userCan(Revision::DELETED_TEXT, $this->getUser())) {
                 $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
             }
             $titleObj = $rev->getTitle();
             $wgTitle = $titleObj;
             $pageObj = WikiPage::factory($titleObj);
             list($popts, $reset, $suppressCache) = $this->makeParserOptions($pageObj, $params);
             // If for some reason the "oldid" is actually the current revision, it may be cached
             // Deliberately comparing $pageObj->getLatest() with $rev->getId(), rather than
             // checking $rev->isCurrent(), because $pageObj is what actually ends up being used,
             // and if its ->getLatest() is outdated, $rev->isCurrent() won't tell us that.
             if (!$suppressCache && $rev->getId() == $pageObj->getLatest()) {
                 // May get from/save to parser cache
                 $p_result = $this->getParsedContent($pageObj, $popts, $pageid, isset($prop['wikitext']));
             } else {
                 // This is an old revision, so get the text differently
                 $this->content = $rev->getContent(Revision::FOR_THIS_USER, $this->getUser());
                 if ($this->section !== false) {
                     $this->content = $this->getSectionContent($this->content, 'r' . $rev->getId());
                 }
                 // Should we save old revision parses to the parser cache?
                 $p_result = $this->content->getParserOutput($titleObj, $rev->getId(), $popts);
             }
         } else {
             // Not $oldid, but $pageid or $page
             if ($params['redirects']) {
                 $reqParams = ['redirects' => ''];
                 if (!is_null($pageid)) {
                     $reqParams['pageids'] = $pageid;
                 } else {
                     // $page
                     $reqParams['titles'] = $page;
                 }
                 $req = new FauxRequest($reqParams);
                 $main = new ApiMain($req);
                 $pageSet = new ApiPageSet($main);
                 $pageSet->execute();
                 $redirValues = $pageSet->getRedirectTitlesAsResult($this->getResult());
                 $to = $page;
                 foreach ($pageSet->getRedirectTitles() as $title) {
                     $to = $title->getFullText();
                 }
                 $pageParams = ['title' => $to];
             } elseif (!is_null($pageid)) {
                 $pageParams = ['pageid' => $pageid];
             } else {
                 // $page
                 $pageParams = ['title' => $page];
             }
             $pageObj = $this->getTitleOrPageId($pageParams, 'fromdb');
             $titleObj = $pageObj->getTitle();
             if (!$titleObj || !$titleObj->exists()) {
                 $this->dieUsage("The page you specified doesn't exist", 'missingtitle');
             }
             $this->checkReadPermissions($titleObj);
             $wgTitle = $titleObj;
             if (isset($prop['revid'])) {
                 $oldid = $pageObj->getLatest();
             }
             list($popts, $reset, $suppressCache) = $this->makeParserOptions($pageObj, $params);
             // Don't pollute the parser cache when setting options that aren't
             // in ParserOptions::optionsHash()
             /// @todo: This should be handled closer to the actual cache instead of here, see T110269
             $suppressCache = $suppressCache || $params['disablepp'] || $params['disablelimitreport'] || $params['preview'] || $params['sectionpreview'] || $params['disabletidy'];
             if ($suppressCache) {
                 $this->content = $this->getContent($pageObj, $pageid);
                 $p_result = $this->content->getParserOutput($titleObj, null, $popts);
             } else {
                 // Potentially cached
                 $p_result = $this->getParsedContent($pageObj, $popts, $pageid, isset($prop['wikitext']));
             }
         }
     } else {
         // Not $oldid, $pageid, $page. Hence based on $text
         $titleObj = Title::newFromText($title);
         if (!$titleObj || $titleObj->isExternal()) {
             $this->dieUsageMsg(['invalidtitle', $title]);
         }
         $wgTitle = $titleObj;
         if ($titleObj->canExist()) {
             $pageObj = WikiPage::factory($titleObj);
         } else {
             // Do like MediaWiki::initializeArticle()
             $article = Article::newFromTitle($titleObj, $this->getContext());
             $pageObj = $article->getPage();
         }
         list($popts, $reset) = $this->makeParserOptions($pageObj, $params);
         $textProvided = !is_null($text);
         if (!$textProvided) {
             if ($titleProvided && ($prop || $params['generatexml'])) {
                 $this->setWarning("'title' used without 'text', and parsed page properties were requested " . "(did you mean to use 'page' instead of 'title'?)");
             }
             // Prevent warning from ContentHandler::makeContent()
             $text = '';
         }
         // If we are parsing text, do not use the content model of the default
         // API title, but default to wikitext to keep BC.
         if ($textProvided && !$titleProvided && is_null($model)) {
             $model = CONTENT_MODEL_WIKITEXT;
             $this->setWarning("No 'title' or 'contentmodel' was given, assuming {$model}.");
         }
         try {
             $this->content = ContentHandler::makeContent($text, $titleObj, $model, $format);
         } catch (MWContentSerializationException $ex) {
             $this->dieUsage($ex->getMessage(), 'parseerror');
         }
         if ($this->section !== false) {
             if ($this->section === 'new') {
                 // Insert the section title above the content.
                 if (!is_null($params['sectiontitle']) && $params['sectiontitle'] !== '') {
                     $this->content = $this->content->addSectionHeader($params['sectiontitle']);
                 }
             } else {
                 $this->content = $this->getSectionContent($this->content, $titleObj->getPrefixedText());
             }
         }
         if ($params['pst'] || $params['onlypst']) {
             $this->pstContent = $this->content->preSaveTransform($titleObj, $this->getUser(), $popts);
         }
         if ($params['onlypst']) {
             // Build a result and bail out
             $result_array = [];
             $result_array['text'] = $this->pstContent->serialize($format);
             $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
             if (isset($prop['wikitext'])) {
                 $result_array['wikitext'] = $this->content->serialize($format);
                 $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
             }
             if (!is_null($params['summary']) || !is_null($params['sectiontitle']) && $this->section === 'new') {
                 $result_array['parsedsummary'] = $this->formatSummary($titleObj, $params);
                 $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
             }
             $result->addValue(null, $this->getModuleName(), $result_array);
             return;
         }
         // Not cached (save or load)
         if ($params['pst']) {
             $p_result = $this->pstContent->getParserOutput($titleObj, null, $popts);
         } else {
             $p_result = $this->content->getParserOutput($titleObj, null, $popts);
         }
     }
     $result_array = [];
     $result_array['title'] = $titleObj->getPrefixedText();
     $result_array['pageid'] = $pageid ?: $pageObj->getId();
     if (!is_null($oldid)) {
         $result_array['revid'] = intval($oldid);
     }
     if ($params['redirects'] && !is_null($redirValues)) {
         $result_array['redirects'] = $redirValues;
     }
     if ($params['disabletoc']) {
         $p_result->setTOCEnabled(false);
     }
     if (isset($prop['text'])) {
         $result_array['text'] = $p_result->getText();
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
     }
     if (!is_null($params['summary']) || !is_null($params['sectiontitle']) && $this->section === 'new') {
         $result_array['parsedsummary'] = $this->formatSummary($titleObj, $params);
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
     }
     if (isset($prop['langlinks'])) {
         $langlinks = $p_result->getLanguageLinks();
         if ($params['effectivelanglinks']) {
             // Link flags are ignored for now, but may in the future be
             // included in the result.
             $linkFlags = [];
             Hooks::run('LanguageLinks', [$titleObj, &$langlinks, &$linkFlags]);
         }
     } else {
         $langlinks = false;
     }
     if (isset($prop['langlinks'])) {
         $result_array['langlinks'] = $this->formatLangLinks($langlinks);
     }
     if (isset($prop['categories'])) {
         $result_array['categories'] = $this->formatCategoryLinks($p_result->getCategories());
     }
     if (isset($prop['categorieshtml'])) {
         $result_array['categorieshtml'] = $this->categoriesHtml($p_result->getCategories());
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'categorieshtml';
     }
     if (isset($prop['links'])) {
         $result_array['links'] = $this->formatLinks($p_result->getLinks());
     }
     if (isset($prop['templates'])) {
         $result_array['templates'] = $this->formatLinks($p_result->getTemplates());
     }
     if (isset($prop['images'])) {
         $result_array['images'] = array_keys($p_result->getImages());
     }
     if (isset($prop['externallinks'])) {
         $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() ?: $titleObj->getPrefixedText();
     }
     if (isset($prop['headitems'])) {
         $result_array['headitems'] = $this->formatHeadItems($p_result->getHeadItems());
         $this->logFeatureUsage('action=parse&prop=headitems');
         $this->setWarning('headitems is deprecated since MediaWiki 1.28. ' . 'Use prop=headhtml when creating new HTML documents, or ' . 'prop=modules|jsconfigvars when updating a document client-side.');
     }
     if (isset($prop['headhtml'])) {
         $context = new DerivativeContext($this->getContext());
         $context->setTitle($titleObj);
         $context->setWikiPage($pageObj);
         // We need an OutputPage tied to $context, not to the
         // RequestContext at the root of the stack.
         $output = new OutputPage($context);
         $output->addParserOutputMetadata($p_result);
         $result_array['headhtml'] = $output->headElement($context->getSkin());
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';
     }
     if (isset($prop['modules'])) {
         $result_array['modules'] = array_values(array_unique($p_result->getModules()));
         $result_array['modulescripts'] = array_values(array_unique($p_result->getModuleScripts()));
         $result_array['modulestyles'] = array_values(array_unique($p_result->getModuleStyles()));
     }
     if (isset($prop['jsconfigvars'])) {
         $result_array['jsconfigvars'] = ApiResult::addMetadataToResultVars($p_result->getJsConfigVars());
     }
     if (isset($prop['encodedjsconfigvars'])) {
         $result_array['encodedjsconfigvars'] = FormatJson::encode($p_result->getJsConfigVars(), false, FormatJson::ALL_OK);
         $result_array[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars';
     }
     if (isset($prop['modules']) && !isset($prop['jsconfigvars']) && !isset($prop['encodedjsconfigvars'])) {
         $this->setWarning('Property "modules" was set but not "jsconfigvars" ' . 'or "encodedjsconfigvars". Configuration variables are necessary ' . 'for proper module usage.');
     }
     if (isset($prop['indicators'])) {
         $result_array['indicators'] = (array) $p_result->getIndicators();
         ApiResult::setArrayType($result_array['indicators'], 'BCkvp', 'name');
     }
     if (isset($prop['iwlinks'])) {
         $result_array['iwlinks'] = $this->formatIWLinks($p_result->getInterwikiLinks());
     }
     if (isset($prop['wikitext'])) {
         $result_array['wikitext'] = $this->content->serialize($format);
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
         if (!is_null($this->pstContent)) {
             $result_array['psttext'] = $this->pstContent->serialize($format);
             $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'psttext';
         }
     }
     if (isset($prop['properties'])) {
         $result_array['properties'] = (array) $p_result->getProperties();
         ApiResult::setArrayType($result_array['properties'], 'BCkvp', 'name');
     }
     if (isset($prop['limitreportdata'])) {
         $result_array['limitreportdata'] = $this->formatLimitReportData($p_result->getLimitReportData());
     }
     if (isset($prop['limitreporthtml'])) {
         $result_array['limitreporthtml'] = EditPage::getPreviewLimitReport($p_result);
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'limitreporthtml';
     }
     if (isset($prop['parsetree']) || $params['generatexml']) {
         if ($this->content->getModel() != CONTENT_MODEL_WIKITEXT) {
             $this->dieUsage('parsetree is only supported for wikitext content', 'notwikitext');
         }
         $wgParser->startExternalParse($titleObj, $popts, Parser::OT_PREPROCESS);
         $dom = $wgParser->preprocessToDom($this->content->getNativeData());
         if (is_callable([$dom, 'saveXML'])) {
             $xml = $dom->saveXML();
         } else {
             $xml = $dom->__toString();
         }
         $result_array['parsetree'] = $xml;
         $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
     }
     $result_mapping = ['redirects' => 'r', 'langlinks' => 'll', 'categories' => 'cl', 'links' => 'pl', 'templates' => 'tl', 'images' => 'img', 'externallinks' => 'el', 'iwlinks' => 'iw', 'sections' => 's', 'headitems' => 'hi', 'modules' => 'm', 'indicators' => 'ind', 'modulescripts' => 'm', 'modulestyles' => 'm', 'properties' => 'pp', 'limitreportdata' => 'lr'];
     $this->setIndexedTagNames($result_array, $result_mapping);
     $result->addValue(null, $this->getModuleName(), $result_array);
 }