private static function getFbPixelScript(Skin $skin)
    {
        global $egFacebookConversionPixelId;
        if (empty($egFacebookConversionPixelId)) {
            throw new MWException("You must set \$egFacebookConversionPixelId to the Pixel ID supplied by Facebook");
        }
        if ($skin->getUser()->isAllowed('noanalytics')) {
            return "\n<!-- Facebook Conversion Pixel tracking is disabled for this user -->\n";
        }
        $script = <<<SCRIPT
‪<script>(function() {
  var _fbq = window._fbq || (window._fbq = []);
  if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
  }
  _fbq.push(['addPixelId', '{$egFacebookConversionPixelId}']);
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'PixelInitialized', {}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id={$egFacebookConversionPixelId}&amp;ev=PixelInitialized" /></noscript>‬
SCRIPT;
        return $script;
    }
    /**
     * @param Skin $skin
     * @param string $text
     * @return bool
     */
    public static function hookAnalyticsInsideHead(OutputPage &$out, Skin &$skin, &$text = '')
    {
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAnonymizeIP, $wgGoogleAnalyticsOtherCode, $wgGoogleAnalyticsIgnoreNsIDs, $wgGoogleAnalyticsIgnorePages, $wgGoogleAnalyticsIgnoreSpecials;
        if ($skin->getUser()->isAllowed('noanalytics')) {
            $text .= "<!-- Web analytics code inclusion is disabled for this user. -->\r\n";
            return true;
        }
        if (count(array_filter($wgGoogleAnalyticsIgnoreSpecials, function ($v) use($skin) {
            return $skin->getTitle()->isSpecial($v);
        })) > 0 || in_array($skin->getTitle()->getNamespace(), $wgGoogleAnalyticsIgnoreNsIDs, true) || in_array($skin->getTitle()->getPrefixedText(), $wgGoogleAnalyticsIgnorePages, true)) {
            $text .= "<!-- Web analytics code inclusion is disabled for this page. -->\r\n";
            return true;
        }
        $appended = false;
        if ($wgGoogleAnalyticsAccount !== '') {
            $text .= <<<EOD
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', '
EOD
 . $wgGoogleAnalyticsAccount . <<<EOD
', 'auto');

EOD
 . ($wgGoogleAnalyticsAnonymizeIP ? "  ga('set', 'anonymizeIp', true);\r\n" : "") . <<<EOD
  ga('send', 'pageview');

</script>

EOD;
            $appended = true;
        }
        if ($wgGoogleAnalyticsOtherCode !== '') {
            $text .= $wgGoogleAnalyticsOtherCode . "\r\n";
            $appended = true;
        }
        if (!$appended) {
            $text .= "<!-- No web analytics configured. -->\r\n";
        }
        $out->addHeadItem("analytics script", $text);
        return true;
    }
 public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin)
 {
     // Enable only if the user has turned it on in Beta Preferences, or BetaFeatures is not installed.
     // Will only be loaded if PageImages & TextExtracts extensions are installed.
     $registry = ExtensionRegistry::getInstance();
     if (!$registry->isLoaded('TextExtracts') || !class_exists('ApiQueryPageImages')) {
         $logger = LoggerFactory::getInstance('popups');
         $logger->error('Popups requires the PageImages and TextExtracts extensions.');
         return true;
     }
     if (self::getConfig()->get('PopupsBetaFeature') === true) {
         if (!class_exists('BetaFeatures')) {
             $logger = LoggerFactory::getInstance('popups');
             $logger->error('PopupsMode cannot be used as a beta feature unless ' . 'the BetaFeatures extension is present.');
             return true;
         }
         if (!BetaFeatures::isFeatureEnabled($skin->getUser(), 'popups')) {
             return true;
         }
     }
     $out->addModules(array('ext.popups', 'schema.Popups'));
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Changes the section edit links to add a VE edit link.
  *
  * This is attached to the MediaWiki 'SkinEditSectionLinks' hook.
  *
  * @param $skin Skin
  * @param $title Title
  * @param $section string
  * @param $tooltip string
  * @param $result array
  * @param $lang Language
  * @return bool true
  */
 public static function onSkinEditSectionLinks(Skin $skin, Title $title, $section, $tooltip, &$result, $lang)
 {
     // Only do this if the user has VE enabled
     // (and we're not in parserTests)
     // (and we're not on a foreign file description page)
     if (isset($GLOBALS['wgVisualEditorInParserTests']) || !$skin->getUser()->getOption('visualeditor-enable') || $skin->getUser()->getOption('visualeditor-betatempdisable') || $title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) {
         return true;
     }
     $config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
     $tabMessages = $config->get('VisualEditorTabMessages');
     $veEditSection = $tabMessages['editsection'] !== null ? $tabMessages['editsection'] : 'editsection';
     $sourceEditSection = $tabMessages['editsectionsource'] !== null ? $tabMessages['editsectionsource'] : 'editsection';
     $result['editsection']['text'] = $skin->msg($sourceEditSection)->inLanguage($lang)->text();
     $veLink = array('text' => $skin->msg($veEditSection)->inLanguage($lang)->text(), 'targetTitle' => $title, 'attribs' => $result['editsection']['attribs'] + array('class' => 'mw-editsection-visualeditor'), 'query' => array('veaction' => 'edit', 'vesection' => $section), 'options' => array('noclasses', 'known'));
     $result['veeditsection'] = $veLink;
     if ($config->get('VisualEditorTabPosition') === 'before') {
         krsort($result);
         // TODO: This will probably cause weird ordering if any other extensions added something already.
         // ... wfArrayInsertBefore?
     }
     return true;
 }
 public static function onSkinAfterBottomScripts(Skin $skin, &$text = '')
 {
     global $wgGoogleUniversalAnalyticsOtherCode;
     if ($wgGoogleUniversalAnalyticsOtherCode === null || $skin->getUser()->isAllowed('noanalytics') || self::isIgnoredPage($skin->getTitle())) {
         return true;
     }
     $text .= $wgGoogleUniversalAnalyticsOtherCode . PHP_EOL;
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Changes the section edit links to add a VE edit link.
  *
  * This is attached to the MediaWiki 'SkinEditSectionLinks' hook.
  *
  * @param $skin Skin
  * @param $title Title
  * @param $section string
  * @param $tooltip string
  * @param $result array
  * @param $lang Language
  * @return bool true
  */
 public static function onSkinEditSectionLinks(Skin $skin, Title $title, $section, $tooltip, &$result, $lang)
 {
     $config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
     // Exit if we're using the single edit tab.
     if ($config->get('VisualEditorUseSingleEditTab') && $skin->getUser()->getOption('visualeditor-tabs') !== 'multi-tab') {
         return true;
     }
     // Exit if we're in parserTests
     if (isset($GLOBALS['wgVisualEditorInParserTests'])) {
         return true;
     }
     // Exit if the user doesn't have VE enabled
     if (!$skin->getUser()->getOption('visualeditor-enable') || $skin->getUser()->getOption('visualeditor-betatempdisable') || $skin->getUser()->getOption('visualeditor-autodisable') || $config->get('VisualEditorDisableForAnons') && $skin->getUser()->isAnon()) {
         return true;
     }
     // Exit if we're on a foreign file description page
     if ($title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) {
         return true;
     }
     $tabMessages = $config->get('VisualEditorTabMessages');
     $sourceEditSection = $tabMessages['editsectionsource'] !== null ? $tabMessages['editsectionsource'] : 'editsection';
     $result['editsection']['text'] = $skin->msg($sourceEditSection)->inLanguage($lang)->text();
     $availableNamespaces = $config->get('VisualEditorAvailableNamespaces');
     // add VE edit section in VE available namespaces
     if ($title->inNamespaces(array_keys(array_filter($availableNamespaces)))) {
         $veEditSection = $tabMessages['editsection'] !== null ? $tabMessages['editsection'] : 'editsection';
         $veLink = array('text' => $skin->msg($veEditSection)->inLanguage($lang)->text(), 'targetTitle' => $title, 'attribs' => $result['editsection']['attribs'] + array('class' => 'mw-editsection-visualeditor'), 'query' => array('veaction' => 'edit', 'vesection' => $section), 'options' => array('noclasses', 'known'));
         $result['veeditsection'] = $veLink;
         if ($config->get('VisualEditorTabPosition') === 'before') {
             krsort($result);
             // TODO: This will probably cause weird ordering if any other extensions added something
             // already.
             // ... wfArrayInsertBefore?
         }
     }
     return true;
 }