/** * Set the script tags in an OutputPage object * @param OutputPage $outputPage */ static function setHeaders(&$outputPage) { global $wgJsMimeType, $wgScriptPath, $wgContLang, $wgCategoryTreeExtPath, $wgCategoryTreeVersion; wfLoadExtensionMessages('CategoryTree'); # Register css file for CategoryTree $outputPage->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => "{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.css?{$wgCategoryTreeVersion}")); # Register css RTL file for CategoryTree if ($wgContLang->isRTL()) { $outputPage->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => "{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.rtl.css?{$wgCategoryTreeVersion}")); } # Register main js file for CategoryTree $outputPage->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js?{$wgCategoryTreeVersion}\">" . "</script>\n"); # Add messages $outputPage->addScript("\t<script type=\"{$wgJsMimeType}\">\n\t\t\tvar categoryTreeCollapseMsg = \"" . Xml::escapeJsString(self::msg('collapse')) . "\";\n\t\t\tvar categoryTreeExpandMsg = \"" . Xml::escapeJsString(self::msg('expand')) . "\";\n\t\t\tvar categoryTreeLoadMsg = \"" . Xml::escapeJsString(self::msg('load')) . "\";\n\t\t\tvar categoryTreeLoadingMsg = \"" . Xml::escapeJsString(self::msg('loading')) . "\";\n\t\t\tvar categoryTreeNothingFoundMsg = \"" . Xml::escapeJsString(self::msg('nothing-found')) . "\";\n\t\t\tvar categoryTreeNoSubcategoriesMsg = \"" . Xml::escapeJsString(self::msg('no-subcategories')) . "\";\n\t\t\tvar categoryTreeNoPagesMsg = \"" . Xml::escapeJsString(self::msg('no-pages')) . "\";\n\t\t\tvar categoryTreeErrorMsg = \"" . Xml::escapeJsString(self::msg('error')) . "\";\n\t\t\tvar categoryTreeRetryMsg = \"" . Xml::escapeJsString(self::msg('retry')) . "\";\n\t\t\t</script>\n"); }
function elmEasyRefOutput(OutputPage $outputPage, $skin) { global $wgScriptPath; // Options global $wgElmEasyRefAddCSS, $wgElmEasyRefDebugMode, $wgElmEasyRefBodyContentId, $wgElmEasyRefAnimation, $wgElmEasyRefMetrics, $wgElmEasyRefNum_rp, $wgElmEasyRefNum_mt; // Register css for popup field $outputPage->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $wgScriptPath . '/extensions/ElmEasyRef/css/referencefield.css')); // Additonal css if setted if ($wgElmEasyRefAddCSS) { $outputPage->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $wgElmEasyRefAddCSS)); } // Register js-script file $src = '/extensions/ElmEasyRef/js/elmEasyRef'; if (!$wgElmEasyRefDebugMode) { $src .= '-min'; } $outputPage->addScript(Html::linkedScript($wgScriptPath . $src . '.js')); // Settings $settings = ''; if ($wgElmEasyRefDebugMode) { $settings .= 'elmEasyRef.debug = true;'; } if ($wgElmEasyRefBodyContentId) { $settings .= 'elmEasyRef.bodyContentId = ' . Xml::encodeJsVar($wgElmEasyRefBodyContentId) . ';'; } if ($wgElmEasyRefNum_rp) { $settings .= 'elmEasyRef.regRefNum_rp = /' . $wgElmEasyRefNum_rp . '/;'; } if ($wgElmEasyRefNum_mt) { $settings .= 'elmEasyRef.regRefNum_mt = /' . $wgElmEasyRefNum_mt . '/;'; } if ($wgElmEasyRefAnimation) { foreach ($wgElmEasyRefAnimation as $prop => $val) { $settings .= 'elmEasyRef.animation.' . $prop . ' = ' . Xml::encodeJsVar($val) . ';'; } } if ($wgElmEasyRefMetrics) { foreach ($wgElmEasyRefMetrics as $prop => $val) { $settings .= 'elmEasyRef.fieldm.' . $prop . ' = ' . Xml::encodeJsVar($val) . ';'; } } $msg = wfMsgExt('elm-easyref-ref', 'parseinline'); $settings .= 'elmEasyRef.messages.elm_easyref_ref = ' . Xml::encodeJsVar($msg) . ';'; $msg = wfMsgExt('elm-easyref-close', 'parseinline'); $settings .= 'elmEasyRef.messages.elm_easyref_close = ' . Xml::encodeJsVar($msg) . ';'; $outputPage->addInlineScript('addOnloadHook( function() {' . $settings . 'elmEasyRef.prepare();' . '} );'); return true; }
static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { $languageLinks = $out->getLanguageLinks(); if (empty($languageLinks)) { return true; } // this is partly a ripoff from SkinTemplate::getLanguages() foreach ($languageLinks as $langLink) { $languageLinkTitle = Title::newFromText($langLink); $interwikiCode = $languageLinkTitle->getInterwiki(); $out->addLink(array('rel' => 'alternate', 'hreflang' => wfBCP47($interwikiCode), 'href' => wfExpandIRI($languageLinkTitle->getFullURL()))); } // We also must add the current language $currentPageLangCode = $out->getLanguage()->getCode(); $currentPageTitle = $out->getTitle(); $out->addLink(array('rel' => 'alternate', 'hreflang' => wfBCP47($currentPageLangCode), 'href' => wfExpandIRI($currentPageTitle->getFullURL()))); return true; }
/** * @author mech * @param OutputPage $out * @return bool true */ function onBeforePageDisplay($out) { if (!empty(F::app()->wg->SEOGoogleSiteVerification)) { $out->addMeta('google-site-verification', F::app()->wg->SEOGoogleSiteVerification); } if (!empty(F::app()->wg->SEOGooglePlusLink)) { $out->addLink(array('href' => F::app()->wg->SEOGooglePlusLink, 'rel' => 'publisher')); } return true; }
/** * @author mech * @param OutputPage $out * @return bool true */ static function onBeforePageDisplay($out) { global $wgSEOGoogleSiteVerification, $wgSEOGooglePlusLink; if (!empty($wgSEOGoogleSiteVerification)) { $out->addMeta('google-site-verification', $wgSEOGoogleSiteVerification); } if (!empty($wgSEOGooglePlusLink)) { $out->addLink(array('href' => $wgSEOGooglePlusLink, 'rel' => 'publisher')); } return true; }
/** * Adds feeds to the page header * * @param OutputPage $out * @return bool */ public static function beforePageDisplay(OutputPage &$out) { global $wgAdvertisedFeedTypes; if ($out->getTitle()->isMainPage()) { foreach (self::getFeeds($out->getLanguage()->getCode()) as $feed) { foreach ($wgAdvertisedFeedTypes as $type) { $out->addLink(array('rel' => 'alternate', 'type' => "application/{$type}+xml", 'title' => $feed->title, 'href' => $feed->getURL($type))); } } } return true; }
/** * @param OutputPage $out * @param $sk * @return bool */ function wfCanonicalHref(&$out, &$sk) { global $wgTitle; if (!$wgTitle instanceof Title) { return true; } $canonicalUrl = $wgTitle->getFullURL(); // Allow hooks to change the canonicalUrl that will be used in the page. wfRunHooks('WikiaCanonicalHref', array(&$canonicalUrl)); $out->addLink(array('rel' => 'canonical', 'href' => $canonicalUrl)); 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; }
function addMetadataLinks(OutputPage $out) { global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; global $wgRightsPage, $wgRightsUrl; if ($out->isArticleRelated()) { # note: buggy CC software only reads first "meta" link if ($wgEnableCreativeCommonsRdf) { $out->addMetadataLink(array('title' => 'Creative Commons', 'type' => 'application/rdf+xml', 'href' => $wgTitle->getLocalURL('action=creativecommons'))); } if ($wgEnableDublinCoreRdf) { $out->addMetadataLink(array('title' => 'Dublin Core', 'type' => 'application/rdf+xml', 'href' => $wgTitle->getLocalURL('action=dublincore'))); } } $copyright = ''; if ($wgRightsPage) { $copy = Title::newFromText($wgRightsPage); if ($copy) { $copyright = $copy->getLocalURL(); } } if (!$copyright && $wgRightsUrl) { $copyright = $wgRightsUrl; } if ($copyright) { $out->addLink(array('rel' => 'copyright', 'href' => $copyright)); } }
/** * 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; }
/** * Set the script tags in an OutputPage object * @param OutputPage $outputPage */ static function setHeaders(&$outputPage) { global $wgJsMimeType, $wgScriptPath, $wgContLang; global $wgCategoryTreeHijackPageCategories, $wgCategoryTreeExtPath, $wgCategoryTreeVersion; self::init(); # Register css file for CategoryTree $outputPage->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => "{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.css?{$wgCategoryTreeVersion}")); if ($wgCategoryTreeHijackPageCategories) { # Register MSIE quirks $outputPage->addScript("<!--[if IE]><link rel=\"stylesheet\" type=\"text/css\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTreeIE.css?{$wgCategoryTreeVersion}\"/><![endif]-->\r\n\t\n"); } # Register css RTL file for CategoryTree if ($wgContLang->isRTL()) { $outputPage->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => "{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.rtl.css?{$wgCategoryTreeVersion}")); } # Register main js file for CategoryTree $outputPage->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js?{$wgCategoryTreeVersion}\">" . "</script>\n"); # Add messages $outputPage->addScript("\t<script type=\"{$wgJsMimeType}\">\r\n\t\t\tvar categoryTreeCollapseMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-collapse')) . "\";\r\n\t\t\tvar categoryTreeExpandMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-expand')) . "\";\r\n\t\t\tvar categoryTreeCollapseBulletMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-collapse-bullet')) . "\";\r\n\t\t\tvar categoryTreeExpandBulletMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-expand-bullet')) . "\";\r\n\t\t\tvar categoryTreeLoadMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-load')) . "\";\r\n\t\t\tvar categoryTreeLoadingMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-loading')) . "\";\r\n\t\t\tvar categoryTreeNothingFoundMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-nothing-found')) . "\";\r\n\t\t\tvar categoryTreeNoSubcategoriesMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-no-subcategories')) . "\";\r\n\t\t\tvar categoryTreeNoParentCategoriesMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-no-parent-categories')) . "\";\r\n\t\t\tvar categoryTreeNoPagesMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-no-pages')) . "\";\r\n\t\t\tvar categoryTreeErrorMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-error')) . "\";\r\n\t\t\tvar categoryTreeRetryMsg = \"" . Xml::escapeJsString(wfMsgNoTrans('categorytree-retry')) . "\";\r\n\t\t\t</script>\n"); }
/** * Adds metadata links below to the HTML output. * <ol> * <li>Creative Commons * <br />See http://wiki.creativecommons.org/Extend_Metadata. * </li> * <li>Dublin Core</li> * <li>Use hreflang to specify canonical and alternate links * <br />See http://www.google.com/support/webmasters/bin/answer.py?answer=189077 * </li> * <li>Copyright</li> * <ol> * * @param $out Object: instance of OutputPage */ function addMetadataLinks(OutputPage $out) { global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang; global $wgRightsPage, $wgRightsUrl; if ($out->isArticleRelated()) { # note: buggy CC software only reads first "meta" link if ($wgEnableCreativeCommonsRdf) { $out->addMetadataLink(array('title' => 'Creative Commons', 'type' => 'application/rdf+xml', 'href' => $this->mTitle->getLocalURL('action=creativecommons'))); } if ($wgEnableDublinCoreRdf) { $out->addMetadataLink(array('title' => 'Dublin Core', 'type' => 'application/rdf+xml', 'href' => $this->mTitle->getLocalURL('action=dublincore'))); } } if (!$wgDisableLangConversion && $wgCanonicalLanguageLinks && $wgContLang->hasVariants()) { $urlvar = $wgContLang->getURLVariant(); if (!$urlvar) { $variants = $wgContLang->getVariants(); foreach ($variants as $_v) { $out->addLink(array('rel' => 'alternate', 'hreflang' => $_v, 'href' => $this->mTitle->getLocalURL('', $_v))); } } else { $out->addLink(array('rel' => 'canonical', 'href' => $this->mTitle->getFullURL())); } } $copyright = ''; if ($wgRightsPage) { $copy = Title::newFromText($wgRightsPage); if ($copy) { $copyright = $copy->getLocalURL(); } } if (!$copyright && $wgRightsUrl) { $copyright = $wgRightsUrl; } if ($copyright) { $out->addLink(array('rel' => 'copyright', 'href' => $copyright)); } }