/** * * @param OutputPage $oOutputPage * @param Skin $oSkin * @return boolean - always true */ public function onBeforePageDisplay(&$oOutputPage, &$oSkin) { if (!in_array($oOutputPage->getRequest()->getVal('action', 'view'), array('edit', 'submit'))) { return true; } $oOutputPage->addModules('bluespice.insertLink.interWikiLinks'); //TODO implement ow $oOutputPage->addJsConfigVars('BSInterWikiPrefixes', $this->getInterWikiLinkPrefixes()); return true; }
/** * Handler for the BeforePageDisplay hook, injects special behaviour * for PropertySuggestions in the EntitySuggester (if page is in EntityNamespace) * * * @param OutputPage $out * @param Skin $skin * @return bool */ public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { if ($out->getRequest()->getCheck('nosuggestions')) { return true; } $entityNamespaceLookup = WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup(); $itemNamespace = $entityNamespaceLookup->getEntityNamespace(CONTENT_MODEL_WIKIBASE_ITEM); if ($out->getTitle()->getNamespace() !== $itemNamespace) { return true; } $out->addModules('ext.PropertySuggester.EntitySelector'); return true; }
/** * BeforePageDisplay hook handler * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay * * @param OutputPage $out * @param Skin $sk * @return bool */ public static function onBeforePageDisplay(&$out, &$sk) { global $wgWPBSkinBlacklist, $wgWPBEnableDefaultBanner; $context = MobileContext::singleton(); $config = $context->getMFConfig(); $mfEnableXAnalyticsLogging = $config->get('MFEnableXAnalyticsLogging'); $mfAppPackageId = $config->get('MFAppPackageId'); $mfAppScheme = $config->get('MFAppScheme'); $mfNoIndexPages = $config->get('MFNoindexPages'); $mfMobileUrlTemplate = $context->getMobileUrlTemplate(); $tabletSize = $config->get('MFDeviceWidthTablet'); // show banners using WikidataPageBanner, if installed and all pre-conditions fulfilled if (ExtensionRegistry::getInstance()->isLoaded('WikidataPageBanner') && $context->isBetaGroupMember()) { // turn default banners on $wgWPBEnableDefaultBanner = true; // Turn on the banner experiment $needle = array_search('minerva', $wgWPBSkinBlacklist); if ($needle !== false) { unset($wgWPBSkinBlacklist[$needle]); } } $title = $sk->getTitle(); $request = $context->getRequest(); // Migrate prefixed disableImages cookie to unprefixed cookie. if (isset($_COOKIE[$config->get('CookiePrefix') . 'disableImages'])) { if ((bool) $request->getCookie('disableImages')) { $context->setDisableImagesCookie(true); } $request->response()->clearCookie('disableImages'); } # Add deep link to a mobile app specified by $wgMFAppScheme if ($mfAppPackageId !== false && $title->isContentPage() && $request->getRawQueryString() === '') { $fullUrl = $title->getFullURL(); $mobileUrl = $context->getMobileUrl($fullUrl); $path = preg_replace("/^([a-z]+:)?(\\/)*/", '', $mobileUrl, 1); $scheme = 'http'; if ($mfAppScheme !== false) { $scheme = $mfAppScheme; } else { $protocol = $request->getProtocol(); if ($protocol != '') { $scheme = $protocol; } } $hreflink = 'android-app://' . $mfAppPackageId . '/' . $scheme . '/' . $path; $out->addLink(array('rel' => 'alternate', 'href' => $hreflink)); } // an canonical/alternate link is only useful, if the mobile and desktop URL are different // and $wgMFNoindexPages needs to be true if ($mfMobileUrlTemplate && $mfNoIndexPages) { if (!$context->shouldDisplayMobileView()) { // add alternate link to desktop sites - bug T91183 $desktopUrl = $title->getFullUrl(); $link = array('rel' => 'alternate', 'media' => 'only screen and (max-width: ' . $tabletSize . 'px)', 'href' => $context->getMobileUrl($desktopUrl)); } else { // add canonical link to mobile pages, instead of noindex - bug T91183 $link = array('rel' => 'canonical', 'href' => $title->getFullUrl()); } $out->addLink($link); } // Set X-Analytics HTTP response header if necessary if ($context->shouldDisplayMobileView()) { $analyticsHeader = $mfEnableXAnalyticsLogging ? $context->getXAnalyticsHeader() : false; if ($analyticsHeader) { $resp = $out->getRequest()->response(); $resp->header($analyticsHeader); } // in mobile view: always add vary header $out->addVaryHeader('Cookie'); // Allow modifications in mobile only mode Hooks::run('BeforePageDisplayMobile', array(&$out, &$sk)); } return true; }
/** * Build a load.php URL using OutputPage instance to get most of the required information * * @param OutputPage $out * @param string|array $modules Module names * @param string $only * @param bool|string $user User name (true to get it from OutputPage) * @param string $version * @param array $extraQuery * @return string */ public static function makeCustomURL(OutputPage $out, $modules, $only = ResourceLoaderModule::TYPE_COMBINED, $user = null, $version = null, $extraQuery = array()) { if ($user === true) { $user = $out->getUser()->getName(); } else { if ($user === false || $user === null) { $user = null; } else { $user = (string) $user; } } $url = ResourceLoader::makeLoaderURL($modules, $out->getLanguage()->getCode(), $out->getSkin()->getSkinName(), $user, $version, ResourceLoader::inDebugMode(), $only === ResourceLoaderModule::TYPE_COMBINED ? null : $only, $out->isPrintable(), $out->getRequest()->getBool('handheld'), $extraQuery); return $url; }
/** * Add X-Served-By and X-Backend-Response-Time response headers to MediaWiki pages * * See BAC-550 for details * * @param OutputPage $out * @param Skin $sk * @return bool * @author macbre */ static function onBeforeSendCacheControl(OutputPage $out) { self::addExtraHeaders($out->getRequest()->response()); return true; }
/** * BeforePageDisplay hook handler * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay * * @param OutputPage $out * @param Skin $sk * @return bool */ public static function onBeforePageDisplay(&$out, &$sk) { $context = MobileContext::singleton(); $config = $context->getMFConfig(); $mfEnableXAnalyticsLogging = $config->get('MFEnableXAnalyticsLogging'); $mfAppPackageId = $config->get('MFAppPackageId'); $mfAppScheme = $config->get('MFAppScheme'); $mfNoIndexPages = $config->get('MFNoindexPages'); $mfMobileUrlTemplate = $context->getMobileUrlTemplate(); $tabletSize = $config->get('MFDeviceWidthTablet'); $title = $sk->getTitle(); $request = $context->getRequest(); # Add deep link to a mobile app specified by $wgMFAppScheme if ($mfAppPackageId !== false && $title->isContentPage() && $request->getRawQueryString() === '') { $fullUrl = $title->getFullURL(); $mobileUrl = $context->getMobileUrl($fullUrl); $path = preg_replace("/^([a-z]+:)?(\\/)*/", '', $mobileUrl, 1); $scheme = 'http'; if ($mfAppScheme !== false) { $scheme = $mfAppScheme; } else { $protocol = $request->getProtocol(); if ($protocol != '') { $scheme = $protocol; } } $hreflink = 'android-app://' . $mfAppPackageId . '/' . $scheme . '/' . $path; $out->addLink(array('rel' => 'alternate', 'href' => $hreflink)); } // an canonical/alternate link is only useful, if the mobile and desktop URL are different // and $wgMFNoindexPages needs to be true if ($mfMobileUrlTemplate && $mfNoIndexPages) { if (!$context->shouldDisplayMobileView()) { // add alternate link to desktop sites - bug T91183 $desktopUrl = $title->getFullUrl(); $link = array('rel' => 'alternate', 'media' => 'only screen and (max-width: ' . $tabletSize . 'px)', 'href' => $context->getMobileUrl($desktopUrl)); } else { // add canonical link to mobile pages, instead of noindex - bug T91183 $link = array('rel' => 'canonical', 'href' => $title->getFullUrl()); } $out->addLink($link); } // Set X-Analytics HTTP response header if necessary if ($context->shouldDisplayMobileView()) { $analyticsHeader = $mfEnableXAnalyticsLogging ? $context->getXAnalyticsHeader() : false; if ($analyticsHeader) { $resp = $out->getRequest()->response(); $resp->header($analyticsHeader); } // in mobile view: always add vary header $out->addVaryHeader('Cookie'); } return true; }
/** * Generate the HTML for the iframe */ private function getHTMLIframeForZoomviewer(OutputPage $out) { global $wgScriptPath, $wgLang; $viewer_type = $this->getViewerType($out->getRequest()); $viewer_path = $this->getViewerPath($viewer_type); $image_file_path = $this->constructImageFilePath(); $language = $wgLang->getCode(); $website_name = 'ManuscriptDesk'; return '<iframe id="zoomviewerframe" src="' . $wgScriptPath . '/extensions/NewManuscript/' . $viewer_path . '?image=' . $image_file_path . '&lang=' . $language . '&sitename=' . urlencode($website_name) . '"></iframe>'; }
/** * Hook: EditPage::showEditForm:initial */ public static function newArticleCampaign(EditPage $newPage, OutputPage $out) { global $wgContentTranslationCampaigns, $wgContentTranslationEventLogging; $user = $out->getUser(); if (!$wgContentTranslationCampaigns['newarticle'] || $out->getRequest()->getCookie('cx_campaign_newarticle_hide', '') || $newPage->mTitle->exists() || !$newPage->mTitle->inNamespace(NS_MAIN) || $user->isAnon() || BetaFeatures::isFeatureEnabled($user, 'cx')) { return true; } // If EventLogging integration is enabled, load the event logging functions module // to measure and analyse the usage of this entry point. if ($wgContentTranslationEventLogging) { $out->addModules('ext.cx.eventlogging'); } $out->addModules('ext.cx.campaigns.newarticle'); }
/** * Called when the normal wikitext editor is shown. * Inserts a 'veswitched' hidden field if requested by the client * * @param $editPage EditPage * @param $output OutputPage * @return boolean true */ public static function onEditPageShowEditFormFields(EditPage $editPage, OutputPage $output) { $request = $output->getRequest(); if ($request->getBool('veswitched')) { $output->addHTML(Xml::input('veswitched', false, '1', array('type' => 'hidden'))); } return true; }
/** * Display Related Discussion (Forum posts) in bottom of article * @param OutputPage $out * @param string $text article HTML * @return bool: true because it is a hook */ public static function onOutputPageBeforeHTML(OutputPage $out, &$text) { $app = F::app(); $title = $out->getTitle(); if ($out->isArticle() && $title->exists() && $title->getNamespace() == NS_MAIN && !Wikia::isMainPage() && $out->getRequest()->getVal('diff') === null && $out->getRequest()->getVal('action') !== 'render' && !$app->checkSkin('wikiamobile', $out->getSkin())) { // VOLDEV-46: Omit zero-state, only render if there are related forum threads $messages = RelatedForumDiscussionController::getData($title->getArticleId()); unset($messages['lastupdate']); if (!empty($messages)) { $text .= $app->renderView('RelatedForumDiscussionController', 'index', array('messages' => $messages)); } } return true; }
/** * Adds the 'ext.bluespice.responsibleeditors' module to the OutputPage * @param OutputPage $out * @param Skin $skin * @return boolean */ public function onBeforePageDisplay($out, $skin) { if ($out->getRequest()->getVal('action', 'view') == 'view' && !$out->getTitle()->isSpecialPage()) { $out->addModules('ext.bluespice.responsibleEditors'); $out->addModuleStyles('ext.bluespice.responsibleEditors.styles'); //Make information about current pages RespEds available on client side $iArticleId = $out->getTitle()->getArticleID(); $aResponsibleEditorIds = $this->getResponsibleEditorIdsByArticleId($iArticleId); $oData = new stdClass(); $oData->articleId = $iArticleId; $oData->editorIds = $aResponsibleEditorIds; $out->addJsConfigVars('bsResponsibleEditors', $oData); } if (BsExtensionManager::getExtension('Bookshelf') !== null) { //Attach Bookshelfs plugin if in context if (SpecialPage::getTitleFor('BookshelfBookManager')->equals($out->getTitle())) { $out->addModules('ext.bluespice.responsibleEditors.bookshelfPlugin'); } } if (BsExtensionManager::getExtension('SuperList') !== null) { //Attach SuperList plugin if in context if (SpecialPage::getTitleFor('SuperList')->equals($out->getTitle())) { $out->addModules('ext.bluespice.responsibleEditors.superList'); } } return true; }
public static function onBeforePageDisplay(OutputPage &$out, &$skin) { if (!$out->getTitle()->isSpecial('WikiAdmin')) { return true; } if (strtolower($out->getRequest()->getVal('mode')) != 'preferences') { return true; } $out->addInlineStyle('.bs-prefs legend{cursor:pointer;}'); return true; }
/** * Hook: MakeGlobalVariablesScript * * Adds $wgTranslateDocumentationLanguageCode to ResourceLoader configuration * when Special:Translate is shown. */ public static function addConfig(&$vars, OutputPage $out) { $request = $out->getRequest(); $title = $out->getTitle(); list($alias, ) = SpecialPageFactory::resolveAlias($title->getText()); if (SpecialTranslate::isBeta($request) && $title->isSpecialPage() && ($alias === 'Translate' || $alias === 'TranslationStash' || $alias === 'SearchTranslations')) { global $wgTranslateDocumentationLanguageCode, $wgTranslatePermissionUrl, $wgTranslateUseSandbox; $vars['TranslateRight'] = $out->getUser()->isAllowed('translate'); $vars['TranslateMessageReviewRight'] = $out->getUser()->isAllowed('translate-messagereview'); $vars['DeleteRight'] = $out->getUser()->isAllowed('delete'); $vars['wgTranslateDocumentationLanguageCode'] = $wgTranslateDocumentationLanguageCode; $vars['wgTranslatePermissionUrl'] = $wgTranslatePermissionUrl; $vars['wgTranslateUseSandbox'] = $wgTranslateUseSandbox; } return true; }