/** * Get the target language for the content being parsed. This is usually the * language that the content is in. * * @since 1.19 * * @throws MWException * @return Language|null */ public function getTargetLanguage() { $target = $this->mOptions->getTargetLanguage(); if ($target !== null) { return $target; } elseif ($this->mOptions->getInterfaceMessage()) { return $this->mOptions->getUserLangObj(); } elseif (is_null($this->mTitle)) { throw new MWException(__METHOD__ . ': $this->mTitle is null'); } return $this->mTitle->getPageLanguage(); }
/** * Fill $output with information derived from the content. * @param $title Title * @param $revId int * @param $options ParserOptions * @param $generateHtml bool * @param $output ParserOutput */ protected function fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output) { global $wgParser; $this->decode(); $lang = $options->getTargetLanguage(); if (!$lang) { $lang = $title->getPageLanguage(); } $listOptions = $this->getFullRenderListOptions() + (array) $this->options + $this->getDefaultOptions(); $text = $this->convertToWikitext($lang, $listOptions); $output = $wgParser->parse($text, $title, $options, true, true, $revId); if ($this->displaymode == 'members') { $isMemberList = true; } else { $isMemberList = false; } $output->addJsConfigVars('wgCollaborationKitIsMemberList', $isMemberList); }
/** * @return Language */ function getFunctionLang() { $target = $this->mOptions->getTargetLanguage(); if ($target !== null) { return $target; } elseif ($this->mOptions->getInterfaceMessage()) { global $wgLang; return $wgLang; } elseif (is_null($this->mTitle)) { throw new MWException(__METHOD__ . ': $this->mTitle is null'); } return $this->mTitle->getPageLanguage(); }
/** * Helper function for fillParserOutput; the bulk of the actual content * @param $title Title * @param $options ParserOptions * @param &$output ParserOutput * @return string */ protected function getParsedContent(Title $title, ParserOptions $options, ParserOutput &$output) { global $wgParser; $lang = $options->getTargetLanguage(); if (!$lang) { $lang = $title->getPageLanguage(); } $html = ''; foreach ($this->getContent() as $item) { if (!isset($item['title']) || $item['title'] == '') { continue; } $spTitle = Title::newFromText($item['title']); $spRev = Revision::newFromTitle($spTitle); // open element and do header $html .= $this->makeHeader($title, $item); if (isset($spRev)) { // DO CONTENT FROM PAGE $spContent = $spRev->getContent(); $spContentModel = $spRev->getContentModel(); if ($spContentModel == 'CollaborationHubContent') { // this is dumb, but we'll just rebuild the intro here for now $text = Html::rawElement('div', ['class' => 'mw-ck-hub-image'], $spContent->getParsedImage($spContent->getImage(), 100)); $text .= $spContent->getParsedIntroduction($spTitle, $options); } elseif ($spContentModel == 'CollaborationListContent') { // convert to wikitext with maxItems limit in place $wikitext = $spContent->convertToWikitext($lang, ['includeDesc' => false, 'maxItems' => 4, 'defaultSort' => 'random']); $text = $wgParser->parse($wikitext, $title, $options)->getText(); } elseif ($spContentModel == 'wikitext') { // to grab first section only $spContent = $spContent->getSection(0); // Do template preproccessing magic // ... parse, get text into $text $rawText = $spContent->serialize(); // Get rid of all <noinclude>'s. $wgParser->startExternalParse($title, $options, Parser::OT_WIKI); $frame = $wgParser->getPreprocessor()->newFrame()->newChild([], $spTitle); $node = $wgParser->preprocessToDom($rawText, Parser::PTD_FOR_INCLUSION); $processedText = $frame->expand($node, PPFrame::RECOVER_ORIG & ~PPFrame::NO_IGNORE); $parsedWikitext = $wgParser->parse($processedText, $title, $options); $text = $parsedWikitext->getText(); $output->addModuleStyles($parsedWikitext->getModuleStyles()); } else { // Parse whatever (else) as whatever $contentOutput = $spContent->getParserOutput($spTitle, $spRev, $options); $output->addModuleStyles($contentOutput->getModuleStyles()); $text = $contentOutput->getRawText(); } $html .= $text; // register as template for stuff $output->addTemplate($spTitle, $spTitle->getArticleId(), $spRev->getId()); } else { // DO CONTENT FOR NOT YET MADE PAGE $html .= Html::rawElement('p', ['class' => 'mw-ck-hub-missingfeature-note'], wfMessage('collaborationkit-hub-missingpage-note')->inContentLanguage()->parse()); $html .= new OOUI\ButtonWidget(['label' => wfMessage('collaborationkit-hub-missingpage-create')->inContentLanguage()->text(), 'href' => SpecialPage::getTitleFor('CreateHubFeature')->getFullUrl(['collaborationhub' => $title->getFullText(), 'feature' => $spTitle->getSubpageText()])]); // register as template for stuff $output->addTemplate($spTitle, $spTitle->getArticleId(), null); } $html .= Html::closeElement('div'); } return $html; }