Example #1
0
    /**
     * Generate a babel box for the given language and level.
     *
     * @param $code String: Language code to use.
     * @param $level String or Integer: Level of ability to use.
     * @return String: A single babel box, in wikitext format.
     */
    protected static function mGenerateBox($code, $level)
    {
        wfProfileIn(__METHOD__);
        $lang = wfBCP47($code);
        $portal = wfMessage('babel-portal', $code)->inContentLanguage()->plain();
        if ($portal !== '') {
            $portal = "[[{$portal}|{$lang}]]";
        } else {
            $portal = $lang;
        }
        $header = "{$portal}<span class=\"mw-babel-box-level-{$level}\">-{$level}</span>";
        $code = strtolower($code);
        $name = BabelLanguageCodes::getName($code);
        $code = BabelLanguageCodes::getCode($code);
        $text = self::mGetText($name, $code, $level);
        $dir_current = Language::factory($code)->getDir();
        $spacing = Babel::mCssAttrib('border-spacing', 'babel-cellspacing', true);
        $padding = Babel::mCssAttrib('padding', 'babel-cellpadding', true);
        if ($spacing === '') {
            $style = $padding === '' ? '' : 'style="' . $padding . '"';
        } else {
            $style = $padding === '' ? 'style="' . $spacing . '"' : 'style="' . $padding . ' ' . $spacing . '"';
        }
        $dir_head = self::$title->getPageLanguage()->getDir();
        $box = <<<EOT
<div class="mw-babel-box mw-babel-box-{$level}" dir="{$dir_head}">
{|{$style}
! dir="{$dir_head}" | {$header}
| dir="{$dir_current}" lang="{$lang}" | {$text}
|}
</div>
EOT;
        wfProfileOut(__METHOD__);
        return $box;
    }
Example #2
0
 /**
  * Format a list of articles chunked by letter, either as a
  * bullet list or a columnar format, depending on the length.
  *
  * @param $articles Array
  * @param $articles_start_char Array
  * @param $cutoff Int
  * @return String
  * @private
  */
 function formatList($articles, $articles_start_char, $cutoff = 6)
 {
     $list = '';
     if (count($articles) > $cutoff) {
         $list = self::columnList($articles, $articles_start_char);
     } elseif (count($articles) > 0) {
         // for short lists of articles in categories.
         $list = self::shortList($articles, $articles_start_char);
     }
     $pageLang = $this->title->getPageLanguage();
     $attribs = array('lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(), 'class' => 'mw-content-' . $pageLang->getDir());
     $list = Html::rawElement('div', $attribs, $list);
     return $list;
 }
 /**
  * Returns an array of language variants that the page is available in
  * @return array
  */
 private function getLanguageVariants()
 {
     $pageLang = $this->title->getPageLanguage();
     $variants = $pageLang->getVariants();
     if (count($variants) > 1) {
         $pageLangCode = $pageLang->getCode();
         $output = array();
         // Loops over each variant
         foreach ($variants as $code) {
             // Gets variant name from language code
             $varname = $pageLang->getVariantname($code);
             // Don't list the current variant
             if ($varname !== $pageLangCode) {
                 // Appends variant link
                 $output[] = array('langname' => $varname, 'url' => $this->title->getLocalURL(array('variant' => $code)), 'lang' => wfBCP47($code));
             }
         }
         return $output;
     } else {
         // No variants
         return array();
     }
 }
 public function getContext(Title $title, $skinName)
 {
     $wrapper = new GlobalStateWrapper(['wgTitle' => $title]);
     $wg = F::app()->wg;
     return $wrapper->wrap(function () use($title, $wg, $skinName) {
         $wikiFactoryHub = WikiFactoryHub::getInstance();
         $hubService = new HubService();
         $adPageTypeService = new AdEngine2PageTypeService();
         $wikiaPageType = new WikiaPageType();
         $sevenOneMediaCombinedUrl = null;
         if (!empty($wg->AdDriverUseSevenOneMedia)) {
             // TODO: implicitly gets the skin from the context!
             $sevenOneMediaCombinedUrl = ResourceLoader::makeCustomURL($wg->Out, ['wikia.ext.adengine.sevenonemedia'], 'scripts');
         }
         $monetizationServiceAds = null;
         if (!empty($wg->AdDriverUseMonetizationService) && !empty($wg->EnableMonetizationModuleExt)) {
             $monetizationServiceAds = F::app()->sendRequest('MonetizationModule', 'index')->getData()['data'];
         }
         $langCode = $title->getPageLanguage()->getCode();
         return ['opts' => $this->filterOutEmptyItems(['adsInContent' => $wg->EnableAdsInContent, 'delayBtf' => $wg->AdDriverDelayBelowTheFold, 'enableAdsInMaps' => $wg->AdDriverEnableAdsInMaps, 'pageType' => $adPageTypeService->getPageType(), 'paidAssetDropConfig' => $wg->PaidAssetDropConfig, 'showAds' => $adPageTypeService->areAdsShowableOnPage(), 'trackSlotState' => $wg->AdDriverTrackState, 'usePostScribe' => $wg->Request->getBool('usepostscribe', false)]), 'targeting' => $this->filterOutEmptyItems(['enablePageCategories' => array_search($langCode, $wg->AdPageLevelCategoryLangs) !== false, 'pageArticleId' => $title->getArticleId(), 'pageIsArticle' => !!$title->getArticleId(), 'pageIsHub' => $wikiaPageType->isWikiaHub(), 'pageName' => $title->getPrefixedDBKey(), 'pageType' => $wikiaPageType->getPageType(), 'sevenOneMediaSub2Site' => $wg->AdDriverSevenOneMediaOverrideSub2Site, 'skin' => $skinName, 'wikiCategory' => $wikiFactoryHub->getCategoryShort($wg->CityId), 'wikiCustomKeyValues' => $wg->DartCustomKeyValues, 'wikiDbName' => $wg->DBname, 'wikiDirectedAtChildren' => $wg->WikiDirectedAtChildrenByFounder || $wg->WikiDirectedAtChildrenByStaff, 'wikiIsCorporate' => $wikiaPageType->isCorporatePage(), 'wikiIsTop1000' => $wg->AdDriverWikiIsTop1000, 'wikiLanguage' => $langCode, 'wikiVertical' => $hubService->getCategoryInfoForCity($wg->CityId)->cat_name]), 'providers' => $this->filterOutEmptyItems(['monetizationService' => $wg->AdDriverUseMonetizationService, 'monetizationServiceAds' => $monetizationServiceAds, 'sevenOneMedia' => $wg->AdDriverUseSevenOneMedia, 'sevenOneMediaCombinedUrl' => $sevenOneMediaCombinedUrl, 'taboola' => $wg->AdDriverUseTaboola]), 'slots' => $this->filterOutEmptyItems(['exitstitial' => $wg->EnableOutboundScreenExt, 'exitstitialRedirectDelay' => $wg->OutboundScreenRedirectDelay, 'invisibleHighImpact' => $wg->AdDriverEnableInvisibleHighImpactSlot]), 'forcedProvider' => $wg->AdDriverForcedProvider];
     });
 }
 /**
  * Renders the supplied wikitext as html
  *
  * @param Title $title
  * @param string $text
  * @return string
  */
 private function generateHtml(Title $title, $text)
 {
     global $wgParser;
     $popts = ParserOptions::newFromContext($this->getContext());
     $popts->setTargetLanguage($title->getPageLanguage());
     $pout = $wgParser->parse($text, $title, $popts);
     return $pout->getText();
 }
Example #6
0
 /**
  * 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();
 }
Example #7
0
 /**
  * @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();
 }
Example #8
0
 /**
  * Get the rendered text for previewing.
  * @return string
  */
 function getPreviewText()
 {
     global $wgOut, $wgUser, $wgParser, $wgRawHtml;
     wfProfileIn(__METHOD__);
     if ($wgRawHtml && !$this->mTokenOk) {
         // Could be an offsite preview attempt. This is very unsafe if
         // HTML is enabled, as it could be an attack.
         $parsedNote = '';
         if ($this->textbox1 !== '') {
             // Do not put big scary notice, if previewing the empty
             // string, which happens when you initially edit
             // a category page, due to automatic preview-on-open.
             $parsedNote = $wgOut->parse("<div class='previewnote'>" . wfMsg('session_fail_preview_html') . "</div>", true, true);
         }
         wfProfileOut(__METHOD__);
         return $parsedNote;
     }
     if ($this->mTriedSave && !$this->mTokenOk) {
         if ($this->mTokenOkExceptSuffix) {
             $note = wfMsg('token_suffix_mismatch');
         } else {
             $note = wfMsg('session_fail_preview');
         }
     } elseif ($this->incompleteForm) {
         $note = wfMsg('edit_form_incomplete');
     } else {
         $note = wfMsg('previewnote');
     }
     $parserOptions = ParserOptions::newFromUser($wgUser);
     $parserOptions->setEditSection(false);
     $parserOptions->setTidy(true);
     $parserOptions->setIsPreview(true);
     $parserOptions->setIsSectionPreview(!is_null($this->section) && $this->section !== '');
     # don't parse non-wikitext pages, show message about preview
     # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
     if ($this->isCssJsSubpage || !$this->mTitle->isWikitextPage()) {
         if ($this->mTitle->isCssJsSubpage()) {
             $level = 'user';
         } elseif ($this->mTitle->isCssOrJsPage()) {
             $level = 'site';
         } else {
             $level = false;
         }
         # Used messages to make sure grep find them:
         # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
         if ($level) {
             if (preg_match("/\\.css\$/", $this->mTitle->getText())) {
                 $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg("{$level}csspreview") . "\n</div>";
                 $class = "mw-code mw-css";
             } elseif (preg_match("/\\.js\$/", $this->mTitle->getText())) {
                 $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg("{$level}jspreview") . "\n</div>";
                 $class = "mw-code mw-js";
             } else {
                 throw new MWException('A CSS/JS (sub)page but which is not css nor js!');
             }
         }
         $parserOutput = $wgParser->parse($previewtext, $this->mTitle, $parserOptions);
         $previewHTML = $parserOutput->mText;
         $previewHTML .= "<pre class=\"{$class}\" dir=\"ltr\">\n" . htmlspecialchars($this->textbox1) . "\n</pre>\n";
     } else {
         $rt = Title::newFromRedirectArray($this->textbox1);
         if ($rt) {
             $previewHTML = $this->mArticle->viewRedirect($rt, false);
         } else {
             $toparse = $this->textbox1;
             # If we're adding a comment, we need to show the
             # summary as the headline
             if ($this->section == "new" && $this->summary != "") {
                 $toparse = wfMsgForContent('newsectionheaderdefaultlevel', $this->summary) . "\n\n" . $toparse;
             }
             wfRunHooks('EditPageGetPreviewText', array($this, &$toparse));
             $parserOptions->enableLimitReport();
             $toparse = $wgParser->preSaveTransform($toparse, $this->mTitle, $wgUser, $parserOptions);
             $parserOutput = $wgParser->parse($toparse, $this->mTitle, $parserOptions);
             $previewHTML = $parserOutput->getText();
             $this->mParserOutput = $parserOutput;
             $wgOut->addParserOutputNoText($parserOutput);
             if (count($parserOutput->getWarnings())) {
                 $note .= "\n\n" . implode("\n\n", $parserOutput->getWarnings());
             }
         }
     }
     if ($this->isConflict) {
         $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars(wfMsg('previewconflict')) . "</h2>\n";
     } else {
         $conflict = '<hr />';
     }
     $previewhead = "<div class='previewnote'>\n" . '<h2 id="mw-previewheader">' . htmlspecialchars(wfMsg('preview')) . "</h2>" . $wgOut->parse($note, true, true) . $conflict . "</div>\n";
     $pageLang = $this->mTitle->getPageLanguage();
     $attribs = array('lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(), 'class' => 'mw-content-' . $pageLang->getDir());
     $previewHTML = Html::rawElement('div', $attribs, $previewHTML);
     wfProfileOut(__METHOD__);
     return $previewhead . $previewHTML . $this->previewTextAfterContent;
 }
Example #9
0
 /**
  * Get a result array with information about a title
  * @param int $pageid Page ID (negative for missing titles)
  * @param Title $title
  * @return array|null
  */
 private function extractPageInfo($pageid, $title)
 {
     $pageInfo = array();
     // $title->exists() needs pageid, which is not set for all title objects
     $titleExists = $pageid > 0;
     $ns = $title->getNamespace();
     $dbkey = $title->getDBkey();
     $pageInfo['contentmodel'] = $title->getContentModel();
     $pageInfo['pagelanguage'] = $title->getPageLanguage()->getCode();
     if ($titleExists) {
         $pageInfo['touched'] = wfTimestamp(TS_ISO_8601, $this->pageTouched[$pageid]);
         $pageInfo['lastrevid'] = intval($this->pageLatest[$pageid]);
         $pageInfo['length'] = intval($this->pageLength[$pageid]);
         if (isset($this->pageIsRedir[$pageid]) && $this->pageIsRedir[$pageid]) {
             $pageInfo['redirect'] = true;
         }
         if ($this->pageIsNew[$pageid]) {
             $pageInfo['new'] = true;
         }
     }
     if (!is_null($this->params['token'])) {
         $tokenFunctions = $this->getTokenFunctions();
         $pageInfo['starttimestamp'] = wfTimestamp(TS_ISO_8601, time());
         foreach ($this->params['token'] as $t) {
             $val = call_user_func($tokenFunctions[$t], $pageid, $title);
             if ($val === false) {
                 $this->setWarning("Action '{$t}' is not allowed for the current user");
             } else {
                 $pageInfo[$t . 'token'] = $val;
             }
         }
     }
     if ($this->fld_protection) {
         $pageInfo['protection'] = array();
         if (isset($this->protections[$ns][$dbkey])) {
             $pageInfo['protection'] = $this->protections[$ns][$dbkey];
         }
         ApiResult::setIndexedTagName($pageInfo['protection'], 'pr');
         $pageInfo['restrictiontypes'] = array();
         if (isset($this->restrictionTypes[$ns][$dbkey])) {
             $pageInfo['restrictiontypes'] = $this->restrictionTypes[$ns][$dbkey];
         }
         ApiResult::setIndexedTagName($pageInfo['restrictiontypes'], 'rt');
     }
     if ($this->fld_watched) {
         $pageInfo['watched'] = isset($this->watched[$ns][$dbkey]);
     }
     if ($this->fld_watchers) {
         if (isset($this->watchers[$ns][$dbkey])) {
             $pageInfo['watchers'] = $this->watchers[$ns][$dbkey];
         } elseif ($this->showZeroWatchers) {
             $pageInfo['watchers'] = 0;
         }
     }
     if ($this->fld_notificationtimestamp) {
         $pageInfo['notificationtimestamp'] = '';
         if (isset($this->notificationtimestamps[$ns][$dbkey])) {
             $pageInfo['notificationtimestamp'] = wfTimestamp(TS_ISO_8601, $this->notificationtimestamps[$ns][$dbkey]);
         }
     }
     if ($this->fld_talkid && isset($this->talkids[$ns][$dbkey])) {
         $pageInfo['talkid'] = $this->talkids[$ns][$dbkey];
     }
     if ($this->fld_subjectid && isset($this->subjectids[$ns][$dbkey])) {
         $pageInfo['subjectid'] = $this->subjectids[$ns][$dbkey];
     }
     if ($this->fld_url) {
         $pageInfo['fullurl'] = wfExpandUrl($title->getFullURL(), PROTO_CURRENT);
         $pageInfo['editurl'] = wfExpandUrl($title->getFullURL('action=edit'), PROTO_CURRENT);
         $pageInfo['canonicalurl'] = wfExpandUrl($title->getFullURL(), PROTO_CANONICAL);
     }
     if ($this->fld_readable) {
         $pageInfo['readable'] = $title->userCan('read', $this->getUser());
     }
     if ($this->fld_preload) {
         if ($titleExists) {
             $pageInfo['preload'] = '';
         } else {
             $text = null;
             Hooks::run('EditFormPreloadText', array(&$text, &$title));
             $pageInfo['preload'] = $text;
         }
     }
     if ($this->fld_displaytitle) {
         if (isset($this->displaytitles[$pageid])) {
             $pageInfo['displaytitle'] = $this->displaytitles[$pageid];
         } else {
             $pageInfo['displaytitle'] = $title->getPrefixedText();
         }
     }
     if ($this->params['testactions']) {
         $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
         if ($this->countTestedActions >= $limit) {
             return null;
             // force a continuation
         }
         $user = $this->getUser();
         $pageInfo['actions'] = array();
         foreach ($this->params['testactions'] as $action) {
             $this->countTestedActions++;
             $pageInfo['actions'][$action] = $title->userCan($action, $user);
         }
     }
     return $pageInfo;
 }
Example #10
0
 protected function showTextbox($text, $name, $customAttribs = array())
 {
     global $wgOut, $wgUser;
     $wikitext = $this->safeUnicodeOutput($text);
     if (strval($wikitext) !== '') {
         // Ensure there's a newline at the end, otherwise adding lines
         // is awkward.
         // But don't add a newline if the ext is empty, or Firefox in XHTML
         // mode will show an extra newline. A bit annoying.
         $wikitext .= "\n";
     }
     $attribs = $customAttribs + array('accesskey' => ',', 'id' => $name, 'cols' => $wgUser->getIntOption('cols'), 'rows' => $wgUser->getIntOption('rows'), 'style' => '');
     $pageLang = $this->mTitle->getPageLanguage();
     $attribs['lang'] = $pageLang->getCode();
     $attribs['dir'] = $pageLang->getDir();
     $wgOut->addHTML(Html::textarea($name, $wikitext, $attribs));
 }
 /**
  * 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);
 }
 /**
  * Get the rendered text for previewing.
  * @throws MWException
  * @return string
  */
 function getPreviewText()
 {
     global $wgOut, $wgUser, $wgRawHtml, $wgLang;
     wfProfileIn(__METHOD__);
     if ($wgRawHtml && !$this->mTokenOk) {
         // Could be an offsite preview attempt. This is very unsafe if
         // HTML is enabled, as it could be an attack.
         $parsedNote = '';
         if ($this->textbox1 !== '') {
             // Do not put big scary notice, if previewing the empty
             // string, which happens when you initially edit
             // a category page, due to automatic preview-on-open.
             $parsedNote = $wgOut->parse("<div class='previewnote'>" . wfMessage('session_fail_preview_html')->text() . "</div>", true, true);
         }
         wfProfileOut(__METHOD__);
         return $parsedNote;
     }
     $note = '';
     try {
         $content = $this->toEditContent($this->textbox1);
         $previewHTML = '';
         if (!wfRunHooks('AlternateEditPreview', array($this, &$content, &$previewHTML, &$this->mParserOutput))) {
             wfProfileOut(__METHOD__);
             return $previewHTML;
         }
         if ($this->mTriedSave && !$this->mTokenOk) {
             if ($this->mTokenOkExceptSuffix) {
                 $note = wfMessage('token_suffix_mismatch')->plain();
             } else {
                 $note = wfMessage('session_fail_preview')->plain();
             }
         } elseif ($this->incompleteForm) {
             $note = wfMessage('edit_form_incomplete')->plain();
         } else {
             $note = wfMessage('previewnote')->plain() . ' [[#' . self::EDITFORM_ID . '|' . $wgLang->getArrow() . ' ' . wfMessage('continue-editing')->text() . ']]';
         }
         $parserOptions = $this->mArticle->makeParserOptions($this->mArticle->getContext());
         $parserOptions->setEditSection(false);
         $parserOptions->setIsPreview(true);
         $parserOptions->setIsSectionPreview(!is_null($this->section) && $this->section !== '');
         # don't parse non-wikitext pages, show message about preview
         if ($this->mTitle->isCssJsSubpage() || $this->mTitle->isCssOrJsPage()) {
             if ($this->mTitle->isCssJsSubpage()) {
                 $level = 'user';
             } elseif ($this->mTitle->isCssOrJsPage()) {
                 $level = 'site';
             } else {
                 $level = false;
             }
             if ($content->getModel() == CONTENT_MODEL_CSS) {
                 $format = 'css';
             } elseif ($content->getModel() == CONTENT_MODEL_JAVASCRIPT) {
                 $format = 'js';
             } else {
                 $format = false;
             }
             # Used messages to make sure grep find them:
             # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
             if ($level && $format) {
                 $note = "<div id='mw-{$level}{$format}preview'>" . wfMessage("{$level}{$format}preview")->text() . "</div>";
             }
         }
         $rt = $content->getRedirectChain();
         if ($rt) {
             $previewHTML = $this->mArticle->viewRedirect($rt, false);
         } else {
             # If we're adding a comment, we need to show the
             # summary as the headline
             if ($this->section === "new" && $this->summary !== "") {
                 $content = $content->addSectionHeader($this->summary);
             }
             $hook_args = array($this, &$content);
             ContentHandler::runLegacyHooks('EditPageGetPreviewText', $hook_args);
             wfRunHooks('EditPageGetPreviewContent', $hook_args);
             $parserOptions->enableLimitReport();
             # For CSS/JS pages, we should have called the ShowRawCssJs hook here.
             # But it's now deprecated, so never mind
             $content = $content->preSaveTransform($this->mTitle, $wgUser, $parserOptions);
             $parserOutput = $content->getParserOutput($this->getArticle()->getTitle(), null, $parserOptions);
             $previewHTML = $parserOutput->getText();
             $this->mParserOutput = $parserOutput;
             $wgOut->addParserOutputNoText($parserOutput);
             if (count($parserOutput->getWarnings())) {
                 $note .= "\n\n" . implode("\n\n", $parserOutput->getWarnings());
             }
         }
     } catch (MWContentSerializationException $ex) {
         $m = wfMessage('content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage());
         $note .= "\n\n" . $m->parse();
         $previewHTML = '';
     }
     if ($this->isConflict) {
         $conflict = '<h2 id="mw-previewconflict">' . wfMessage('previewconflict')->escaped() . "</h2>\n";
     } else {
         $conflict = '<hr />';
     }
     $previewhead = "<div class='previewnote'>\n" . '<h2 id="mw-previewheader">' . wfMessage('preview')->escaped() . "</h2>" . $wgOut->parse($note, true, true) . $conflict . "</div>\n";
     $pageLang = $this->mTitle->getPageLanguage();
     $attribs = array('lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(), 'class' => 'mw-content-' . $pageLang->getDir());
     $previewHTML = Html::rawElement('div', $attribs, $previewHTML);
     wfProfileOut(__METHOD__);
     return $previewhead . $previewHTML . $this->previewTextAfterContent;
 }
Example #13
0
 protected function showTextbox($text, $name, $customAttribs = [])
 {
     global $wgOut, $wgUser;
     $wikitext = $this->safeUnicodeOutput($text);
     if (strval($wikitext) !== '') {
         // Ensure there's a newline at the end, otherwise adding lines
         // is awkward.
         // But don't add a newline if the ext is empty, or Firefox in XHTML
         // mode will show an extra newline. A bit annoying.
         $wikitext .= "\n";
     }
     $attribs = $customAttribs + ['accesskey' => ',', 'id' => $name, 'cols' => $wgUser->getIntOption('cols'), 'rows' => $wgUser->getIntOption('rows'), 'style' => ''];
     // The following classes can be used here:
     // * mw-editfont-default
     // * mw-editfont-monospace
     // * mw-editfont-sans-serif
     // * mw-editfont-serif
     $class = 'mw-editfont-' . $wgUser->getOption('editfont');
     if (isset($attribs['class'])) {
         if (is_string($attribs['class'])) {
             $attribs['class'] .= ' ' . $class;
         } elseif (is_array($attribs['class'])) {
             $attribs['class'][] = $class;
         }
     } else {
         $attribs['class'] = $class;
     }
     $pageLang = $this->mTitle->getPageLanguage();
     $attribs['lang'] = $pageLang->getHtmlCode();
     $attribs['dir'] = $pageLang->getDir();
     $wgOut->addHTML(Html::textarea($name, $wikitext, $attribs));
 }
 /**
  * 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;
 }