public static function onBeforePageDisplay(OutputPage &$output, Skin &$skin) { $title = $output->getTitle(); // Disallow commenting on pages without article id if ($title->getArticleID() == 0) { return true; } if ($title->isSpecialPage()) { return true; } // These could be explicitly allowed in later version if (!$title->canTalk()) { return true; } if ($title->isTalkPage()) { return true; } // No commenting on main page if ($title->isMainPage()) { return true; } // Do not display when printing if ($output->isPrintable()) { return true; } // Disable if not viewing if ($skin->getRequest()->getVal('action', 'view') != 'view') { return true; } // Blacklist several namespace if (in_array($title->getNamespace(), self::getFilteredNamespace())) { return true; } if ($output->getUser()->isAllowed('commentadmin-restricted')) { $output->addJsConfigVars(array('commentadmin' => '')); } global $wgFlowThreadConfig; $config = array('Avatar' => $wgFlowThreadConfig['Avatar'], 'AnonymousAvatar' => $wgFlowThreadConfig['AnonymousAvatar']); if (\FlowThread\Post::canPost($output->getUser())) { $output->addJsConfigVars(array('canpost' => '')); } else { $config['CantPostNotice'] = wfMessage('flowthread-ui-cantpost')->toString(); } global $wgFlowThreadConfig; $output->addJsConfigVars(array('wgFlowThreadConfig' => $config)); $output->addModules('ext.flowthread'); return true; }
/** * @param \EditPage $editPage * @param \OutputPage $output * * @return bool */ public function onShowEditForm($editPage, $output) { if (!$output->getUser()->isEmailConfirmed()) { $editPage->editFormTextBeforeContent .= $this->installHtml(); } return true; }
/** * Adds module * @param OutputPage $out * @param SkinTemplate $skin * @return boolean */ public static function onBeforePageDisplay(&$out, &$skin) { if (!$out->getTitle()->equals($out->getUser()->getUserPage())) { return true; } $out->addModules("ext.bluespice.avatars.js"); return true; }
/** * Generate user page content for non-existent user pages * * @param OutputPage $output * @param User $pageUser owner of the user page * @return string */ public static function getUserPageContent($output, $pageUser) { $context = MobileContext::singleton(); $pageUsername = $pageUser->getName(); // Is the current user viewing their own page? $isCurrentUser = $output->getUser()->getName() === $pageUsername; $data['ctaHeading'] = $isCurrentUser ? $context->msg('mobile-frontend-user-page-no-owner-page-yet')->text() : $context->msg('mobile-frontend-user-page-no-page-yet', $pageUsername)->parse(); $data['ctaDescription'] = $isCurrentUser ? $context->msg('mobile-frontend-user-page-describe-yourself', $context->msg('mobile-frontend-user-page-describe-yourself-editors')->text())->text() : $context->msg('mobile-frontend-user-page-desired-action', $pageUsername)->parse(); $data['createPageLinkLabel'] = $isCurrentUser ? $context->msg('mobile-frontend-user-page-create-owner-page-link-label')->text() : $context->msg('mobile-frontend-user-page-create-user-page-link-label', $pageUser->getUserPage()->getBaseTitle())->parse(); $data['createPageLinkAdditionalClasses'] = $isCurrentUser ? 'mw-ui-button' : ''; $templateParser = new TemplateParser(__DIR__); return $templateParser->processTemplate('user_page_cta', $data); }
/** * 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; }
/** * 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'); }
/** * 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 $wgGatherEnableBetaFeature; $desktopBetaFeatureEnabled = class_exists('BetaFeatures') && BetaFeatures::isFeatureEnabled($out->getUser(), 'betafeatures-gather') && $wgGatherEnableBetaFeature; if ($desktopBetaFeatureEnabled) { $out->addModules('ext.gather.desktop'); $out->addModuleStyles(array('mediawiki.ui.input', 'mediawiki.ui.icon')); } }
public static function addGoogleAnalytics(OutputPage &$out) { global $wgGoogleUniversalAnalyticsAccount, $wgGoogleUniversalAnalyticsAnonymizeIP, $wgGoogleUniversalAnalyticsTrackExtLinks, $wgGoogleUniversalAnalyticsSegmentByGroup, $wgGoogleUniversalAnalyticsSegmentByGroupDimension, $wgGoogleUniversalAnalyticsCookiePath, $wgGoogleUniversalAnalyticsDomainName, $wgGoogleUniversalAnalyticsPageGrouping, $wgGoogleUniversalAnalyticsEnahncedLinkAttribution, $wgGoogleUniversalAnalyticsRemarketing; if (is_null($wgGoogleUniversalAnalyticsAccount)) { $msg = self::messageToComment('googleuniversalanalytics-error-not-configured'); return $msg; } if ($out->getUser()->isAllowed('noanalytics')) { return self::messageToComment('googleuniversalanalytics-disabled-for-user'); } if (self::isIgnoredPage($out->getTitle())) { return self::messageToComment('googleuniversalanalytics-disabled-for-page'); } /* Else: we load the script */ $script = '<!-- Begin Google Analytics -->' . PHP_EOL; $script .= '<script>' . PHP_EOL . self::getBasicSnippet(); $extraCreateParams = ''; if (!empty($wgGoogleUniversalAnalyticsCookiePath)) { $extraCreateParams = ", {'cookiePath': '{$wgGoogleUniversalAnalyticsCookiePath}'}"; } $cookieDomain = $wgGoogleUniversalAnalyticsDomainName ?: 'auto'; $script .= "ga('create', '{$wgGoogleUniversalAnalyticsAccount}', '{$cookieDomain}'" . $extraCreateParams . ");" . PHP_EOL; if ($wgGoogleUniversalAnalyticsSegmentByGroup === true && is_int($wgGoogleUniversalAnalyticsSegmentByGroupDimension)) { // The following should be fine with caching, and simply always get "*" for anon users $userGroups = implode(',', $out->getUser()->getEffectiveGroups()); $dimension = 'dimension' . $wgGoogleUniversalAnalyticsSegmentByGroupDimension; $script .= "ga('set', '{$dimension}', '{$userGroups}');" . PHP_EOL; } if (isset($wgGoogleUniversalAnalyticsPageGrouping) && $wgGoogleUniversalAnalyticsPageGrouping === true) { $title = $out->getTitle(); $ns = $title->getNamespace(); if (isset($ns) && in_array($ns, self::$ignoredPageGroupingNamespaces)) { $script .= PHP_EOL . "/* Namespace excluded from page grouping */" . PHP_EOL; } else { $normalCats = self::$normalCats; if (count($normalCats) > 1) { $normalCats[0] = Title::makeTitleSafe(NS_CATEGORY, $normalCats[0])->getText(); $normalCats[1] = Title::makeTitleSafe(NS_CATEGORY, $normalCats[1])->getText(); $script .= "ga('set', 'contentGroup2', '{$normalCats[1]}');" . PHP_EOL . "ga('set', 'contentGroup3', '{$normalCats[0]}');" . PHP_EOL; } } } if (isset($wgGoogleUniversalAnalyticsRemarketing) && $wgGoogleUniversalAnalyticsRemarketing === true) { $script .= "ga('require', 'displayfeatures');" . PHP_EOL; } if (isset($wgGoogleUniversalAnalyticsEnahncedLinkAttribution) && $wgGoogleUniversalAnalyticsEnahncedLinkAttribution == true) { $script .= "ga('require', 'linkid', 'linkid.js');" . PHP_EOL; } if ($wgGoogleUniversalAnalyticsAnonymizeIP === true) { $script .= "ga('set', 'anonymizeIp', true);" . PHP_EOL; } // And finally... send the pageview $script .= "ga('send', 'pageview');" . PHP_EOL; // And end the script $script .= "</script>" . PHP_EOL; $script .= '<!-- End Google Analytics -->' . PHP_EOL; // Add module for tracking external links using events if (isset($wgGoogleUniversalAnalyticsTrackExtLinks) && $wgGoogleUniversalAnalyticsTrackExtLinks === true) { $out->addModules('ext.googleUniversalAnalytics.externalLinks'); } return $script; }
/** Load the RL module */ static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { global $wgWRGoogleSearchOnly; $user = $out->getUser(); if ($wgWRGoogleSearchOnly && !WRGoogleSearch::isUserExempt($user)) { $out->addModules('ext.wrGoogleSearch.general'); } return true; }
/** * Export variables which depend on the current user * @param $vars * @param OutputPage $out */ public static function makeGlobalVariablesScript(&$vars, OutputPage $out) { global $wgDefaultUserOptions; $user = $out->getUser(); $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks($user); // needed because of bug 69942; could be different for anon and logged-in $vars['wgMediaViewerEnabledByDefault'] = !empty($wgDefaultUserOptions['multimediaviewer-enable']); }
/** * Handler for MakeGlobalVariablesScript hook. * @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript * @param &$vars array Variables to be added into the output * @param $outputPage OutputPage instance calling the hook * @return bool true in all cases */ public static function makeGlobalVariablesScript(&$vars, OutputPage $outputPage) { global $wgEchoHelpPage, $wgEchoMaxNotificationCount, $wgEchoConfig; $user = $outputPage->getUser(); // Provide info for the Overlay $timestamp = new MWTimestamp(wfTimestampNow()); //XXCHANGEDXX - allow anons [sc|rs] if (!$user->isAnon() || $user->hasCookies()) { $vars['wgEchoOverlayConfiguration'] = array('notification-count' => MWEchoNotifUser::newFromUser($user)->getFormattedNotificationCount(), 'max-notification-count' => $wgEchoMaxNotificationCount); $vars['wgEchoHelpPage'] = $wgEchoHelpPage; $vars['wgEchoConfig'] = $wgEchoConfig; } return true; }
/** * Adds extra variables to the page config. */ public static function onMakeGlobalVariablesScript(array &$vars, OutputPage $out) { global $wgSVGMaxSize, $wgNamespacesWithSubpages; $pageLanguage = $out->getTitle()->getPageLanguage(); $vars['wgVisualEditor'] = array('isPageWatched' => $out->getUser()->isWatched($out->getTitle()), 'pageLanguageCode' => $pageLanguage->getHtmlCode(), 'pageLanguageDir' => $pageLanguage->getDir(), 'svgMaxSize' => $wgSVGMaxSize, 'namespacesWithSubpages' => $wgNamespacesWithSubpages); return true; }
/** * Adds extra variables to the page config. */ public static function onMakeGlobalVariablesScript(array &$vars, OutputPage $out) { global $wgStylePath, $wgSVGMaxSize, $wgNamespacesWithSubpages; $pageLanguage = $out->getTitle()->getPageLanguage(); $vars['wgVisualEditor'] = array('isPageWatched' => $out->getUser()->isWatched($out->getTitle()), 'magnifyClipIconURL' => $wgStylePath . '/common/images/magnify-clip' . ($pageLanguage->isRTL() ? '-rtl' : '') . '.png', 'pageLanguageCode' => $pageLanguage->getHtmlCode(), 'pageLanguageDir' => $pageLanguage->getDir(), 'svgMaxSize' => $wgSVGMaxSize, 'namespacesWithSubpages' => $wgNamespacesWithSubpages); return true; }
/** * Export variables which depend on the current user * @param $vars * @param OutputPage $out */ public static function makeGlobalVariablesScript(&$vars, OutputPage $out) { $user = $out->getUser(); $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks($user); }
static function addGoogleAnalytics(OutputPage &$out) { global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsSegmentByGroup, $wgGoogleAnalyticsTrackExtLinks, $wgGoogleAnalyticsDomainName, $wgGoogleAnalyticsCookiePath, $wgGoogleAnalyticsEnahncedLinkAttribution, $wgGoogleAnalyticsPageGrouping, $wgGoogleAnalyticsDemographics; if (is_null($wgGoogleAnalyticsAccount)) { $msg = self::messageToComment('googleanalytics-error-not-configured'); return $msg; } if ($out->getUser()->isAllowed('noanalytics')) { return self::messageToComment('googleanalytics-disabled-for-user'); } if (self::isIgnoredPage($out->getTitle())) { return self::messageToComment('googleanalytics-disabled-for-page'); } /* Else: we load the script */ /* Starts with regular GA.js queue initializing, but adds * custom code to make sure '_setAccount' is always first (using 'unshift'). * This allows other extensions to shove things in the queue * without knowing anything about it, by doing something like (don't forget ResourceLoader encapsulation!): * var _gaq = _gaq || []; _gaq.push(cmd); */ $script = <<<JS <script> \tvar _gaq = _gaq || []; \tvar cmd = ['_setAccount', '{$wgGoogleAnalyticsAccount}']; \tif (!_gaq.unshift){ \t\t_gaq.push(cmd); \t} else { \t _gaq.unshift(cmd); \t} JS; if (!empty($wgGoogleAnalyticsDomainName)) { $script .= "\n\t_gaq.push(['_setDomainName', '{$wgGoogleAnalyticsDomainName}']);"; } if (!empty($wgGoogleAnalyticsCookiePath)) { $script .= "\n\t_gaq.push(['_setCookiePath', '{$wgGoogleAnalyticsCookiePath}']);"; } if (isset($wgGoogleAnalyticsSegmentByGroup) && $wgGoogleAnalyticsSegmentByGroup === true) { $script .= "\n\twindow.RLQ.push( function () {\n\t\t_gaq.push(['_setCustomVar',\n\t\t\t1,\t\t\t\t\t\t\t\t// first slot\n\t\t\t'User Groups',\t\t\t\t\t// custom variable name\n\t\t\tmw.config.get( 'wgUserGroups' ).toString(),\t// custom variable filtered in GA\n\t\t\t2\t\t\t\t\t\t// custom variable scope - session-level\n\t\t]);\n\t});"; } if (isset($wgGoogleAnalyticsPageGrouping) && $wgGoogleAnalyticsPageGrouping === true) { $title = $out->getTitle(); $ns = $title->getNamespace(); if (isset($ns) && in_array($ns, array(NS_CATEGORY, NS_FILE, NS_SPECIAL, NS_MEDIAWIKI))) { $script .= PHP_EOL . "/* Namespace excluded from page grouping */" . PHP_EOL; } else { $normalCats = self::$normalCats; if (count($normalCats) > 1) { $normalCats[0] = Title::makeTitleSafe(NS_CATEGORY, $normalCats[0])->getText(); $normalCats[1] = Title::makeTitleSafe(NS_CATEGORY, $normalCats[1])->getText(); $grouping = $normalCats[1] . '/' . $normalCats[0]; $script .= "\n\t _gaq.push(['_setPageGroup', '1', '{$grouping}']);\n\t _gaq.push(['_setPageGroup', '2', '{$normalCats[1]}']);\n\t _gaq.push(['_setPageGroup', '3', '{$normalCats[0]}']);\n\t"; } } } $script .= "\n\t_gaq.push(['_trackPageview']);"; if (isset($wgGoogleAnalyticsDemographics) && $wgGoogleAnalyticsDemographics === true) { $gaSource = "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'"; } else { $gaSource = "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'"; } $script .= "\n\t(function() {\n\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\tga.src = {$gaSource};\n\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n\t})();"; if (isset($wgGoogleAnalyticsEnahncedLinkAttribution) && $wgGoogleAnalyticsEnahncedLinkAttribution === true) { $script .= "\n\tvar pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';\n\t_gaq.push(['_require', 'inpage_linkid', pluginUrl]);"; } if (isset($wgGoogleAnalyticsTrackExtLinks) && $wgGoogleAnalyticsTrackExtLinks === true) { $script .= <<<JS \tfunction trackEvent(category, action, label, value, noninteraction) { \t\ttry { \t\t _gaq.push(['_trackEvent', category , action, label, value, noninteraction ]); \t\t} catch(err) { } \t} \twindow.RLQ.push( function () { \t\t\$( 'body' ).on( 'click', 'a.external, a.extiw, .interlanguage-link > a', function( e ) { \t\t\tvar url = \$( this ).attr( 'href' ); \t\t\tvar host = e.currentTarget.host.replace( ':80', '' ); \t\t\tvar category = ''; \t\t\tif( \$(this).hasClass( 'external' ) ) { category = 'Outbound Links'; } \t\t\telse if( \$(this).hasClass( 'extiw' ) ) { category = 'Outbound Interwiki'; } \t\t\telse { category = 'Language Links'; } \t\t\ttrackEvent( category, host, url, undefined, true ); \t\t}); \t}); JS; } // And finally... $script .= PHP_EOL . "</script>" . PHP_EOL; return $script; }
/** * 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; }