当前位置: 首页>>代码示例>>PHP>>正文


PHP OutputPage::addVaryHeader方法代码示例

本文整理汇总了PHP中OutputPage::addVaryHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP OutputPage::addVaryHeader方法的具体用法?PHP OutputPage::addVaryHeader怎么用?PHP OutputPage::addVaryHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OutputPage的用法示例。


在下文中一共展示了OutputPage::addVaryHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onBeforePageDisplay

 /**
  * 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;
 }
开发者ID:micha6554,项目名称:mediawiki-extensions-MobileFrontend,代码行数:82,代码来源:MobileFrontend.hooks.php

示例2: onBeforePageDisplay

 /**
  * 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;
 }
开发者ID:GoProjectOwner,项目名称:mediawiki-extensions-MobileFrontend,代码行数:62,代码来源:MobileFrontend.hooks.php


注:本文中的OutputPage::addVaryHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。