/** * Hook: BeforePageDisplay */ public static function addModules(OutputPage $out, Skin $skin) { global $wgContentTranslationEventLogging, $wgContentTranslationCampaigns; $title = $out->getTitle(); $user = $out->getUser(); // Check if CX is available for current user. if (!self::isEnabledForUser($user)) { if (!$title->exists() && $wgContentTranslationCampaigns['newarticle'] && !$out->getRequest()->getCookie('cx_campaign_newarticle_hide', '') && !$user->isAnon()) { $out->addModules('ext.cx.campaigns.newarticle.veloader'); if ($wgContentTranslationEventLogging) { $out->addModules('ext.cx.eventlogging'); } } return; } // If EventLogging integration is enabled, load the event logging functions module if ($wgContentTranslationEventLogging) { $out->addModules('ext.cx.eventlogging'); } if ($title->inNamespace(NS_MAIN) && Action::getActionName($out->getContext()) === 'view' && $title->exists()) { $out->addModules('ext.cx.interlanguagelink'); } // Add a hover menu for the contributions link in personal toolbar $out->addModules('ext.cx.campaigns.contributionsmenu'); // The current guided tours are only for the user namespace, // so load the module only there. // In the future there may be guided tours in other namespaces, // and then this condition should be changed. if (class_exists('GuidedTourHooks') && $title->inNamespace(NS_USER)) { $out->addModules('ext.guidedTour'); } }
public function onEndShowHeadElements(Action $action) { switch ($action->getActionName()) { case 'attachment': $action->element('link', array('rel' => 'alternate', 'type' => 'application/json+oembed', 'href' => common_local_url('oembed', array(), array('format' => 'json', 'url' => common_local_url('attachment', array('attachment' => $action->attachment->id)))), 'title' => 'oEmbed'), null); $action->element('link', array('rel' => 'alternate', 'type' => 'text/xml+oembed', 'href' => common_local_url('oembed', array(), array('format' => 'xml', 'url' => common_local_url('attachment', array('attachment' => $action->attachment->id)))), 'title' => 'oEmbed'), null); break; case 'shownotice': try { $action->element('link', array('rel' => 'alternate', 'type' => 'application/json+oembed', 'href' => common_local_url('oembed', array(), array('format' => 'json', 'url' => $action->notice->getUrl())), 'title' => 'oEmbed'), null); $action->element('link', array('rel' => 'alternate', 'type' => 'text/xml+oembed', 'href' => common_local_url('oembed', array(), array('format' => 'xml', 'url' => $action->notice->getUrl())), 'title' => 'oEmbed'), null); } catch (InvalidUrlException $e) { // The notice is probably a share or similar, which don't // have a representational URL of their own. } break; } return true; }
/** * @return array Array in format "link name or number => 'link html'". */ public function getHeadLinksArray() { global $wgVersion; $tags = array(); $config = $this->getConfig(); $canonicalUrl = $this->mCanonicalUrl; $tags['meta-generator'] = Html::element('meta', array('name' => 'generator', 'content' => "MediaWiki {$wgVersion}")); if ($config->get('ReferrerPolicy') !== false) { $tags['meta-referrer'] = Html::element('meta', array('name' => 'referrer', 'content' => $config->get('ReferrerPolicy'))); } $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}"; if ($p !== 'index,follow') { // http://www.robotstxt.org/wc/meta-user.html // Only show if it's different from the default robots policy $tags['meta-robots'] = Html::element('meta', array('name' => 'robots', 'content' => $p)); } foreach ($this->mMetatags as $tag) { if (0 == strcasecmp('http:', substr($tag[0], 0, 5))) { $a = 'http-equiv'; $tag[0] = substr($tag[0], 5); } else { $a = 'name'; } $tagName = "meta-{$tag[0]}"; if (isset($tags[$tagName])) { $tagName .= $tag[1]; } $tags[$tagName] = Html::element('meta', array($a => $tag[0], 'content' => $tag[1])); } foreach ($this->mLinktags as $tag) { $tags[] = Html::element('link', $tag); } # Universal edit button if ($config->get('UniversalEditButton') && $this->isArticleRelated()) { $user = $this->getUser(); if ($this->getTitle()->quickUserCan('edit', $user) && ($this->getTitle()->exists() || $this->getTitle()->quickUserCan('create', $user))) { // Original UniversalEditButton $msg = $this->msg('edit')->text(); $tags['universal-edit-button'] = Html::element('link', array('rel' => 'alternate', 'type' => 'application/x-wiki', 'title' => $msg, 'href' => $this->getTitle()->getEditURL())); // Alternate edit link $tags['alternative-edit'] = Html::element('link', array('rel' => 'edit', 'title' => $msg, 'href' => $this->getTitle()->getEditURL())); } } # Generally the order of the favicon and apple-touch-icon links # should not matter, but Konqueror (3.5.9 at least) incorrectly # uses whichever one appears later in the HTML source. Make sure # apple-touch-icon is specified first to avoid this. if ($config->get('AppleTouchIcon') !== false) { $tags['apple-touch-icon'] = Html::element('link', array('rel' => 'apple-touch-icon', 'href' => $config->get('AppleTouchIcon'))); } if ($config->get('Favicon') !== false) { $tags['favicon'] = Html::element('link', array('rel' => 'shortcut icon', 'href' => $config->get('Favicon'))); } # OpenSearch description link $tags['opensearch'] = Html::element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', 'href' => wfScript('opensearch_desc'), 'title' => $this->msg('opensearch-desc')->inContentLanguage()->text())); if ($config->get('EnableAPI')) { # Real Simple Discovery link, provides auto-discovery information # for the MediaWiki API (and potentially additional custom API # support such as WordPress or Twitter-compatible APIs for a # blogging extension, etc) $tags['rsd'] = Html::element('link', array('rel' => 'EditURI', 'type' => 'application/rsd+xml', 'href' => wfExpandUrl(wfAppendQuery(wfScript('api'), array('action' => 'rsd')), PROTO_RELATIVE))); } # Language variants if (!$config->get('DisableLangConversion')) { $lang = $this->getTitle()->getPageLanguage(); if ($lang->hasVariants()) { $variants = $lang->getVariants(); foreach ($variants as $_v) { $tags["variant-{$_v}"] = Html::element('link', array('rel' => 'alternate', 'hreflang' => wfBCP47($_v), 'href' => $this->getTitle()->getLocalURL(array('variant' => $_v)))); } } # x-default link per https://support.google.com/webmasters/answer/189077?hl=en $tags["variant-x-default"] = Html::element('link', array('rel' => 'alternate', 'hreflang' => 'x-default', 'href' => $this->getTitle()->getLocalURL())); } # Copyright if ($this->copyrightUrl !== null) { $copyright = $this->copyrightUrl; } else { $copyright = ''; if ($config->get('RightsPage')) { $copy = Title::newFromText($config->get('RightsPage')); if ($copy) { $copyright = $copy->getLocalURL(); } } if (!$copyright && $config->get('RightsUrl')) { $copyright = $config->get('RightsUrl'); } } if ($copyright) { $tags['copyright'] = Html::element('link', array('rel' => 'copyright', 'href' => $copyright)); } # Feeds if ($config->get('Feed')) { foreach ($this->getSyndicationLinks() as $format => $link) { # Use the page name for the title. In principle, this could # lead to issues with having the same name for different feeds # corresponding to the same page, but we can't avoid that at # this low a level. $tags[] = $this->feedLink($format, $link, $this->msg("page-{$format}-feed", $this->getTitle()->getPrefixedText())->text()); } # Recent changes feed should appear on every page (except recentchanges, # that would be redundant). Put it after the per-page feed to avoid # changing existing behavior. It's still available, probably via a # menu in your browser. Some sites might have a different feed they'd # like to promote instead of the RC feed (maybe like a "Recent New Articles" # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined. # If so, use it instead. $sitename = $config->get('Sitename'); if ($config->get('OverrideSiteFeed')) { foreach ($config->get('OverrideSiteFeed') as $type => $feedUrl) { // Note, this->feedLink escapes the url. $tags[] = $this->feedLink($type, $feedUrl, $this->msg("site-{$type}-feed", $sitename)->text()); } } elseif (!$this->getTitle()->isSpecial('Recentchanges')) { $rctitle = SpecialPage::getTitleFor('Recentchanges'); foreach ($config->get('AdvertisedFeedTypes') as $format) { $tags[] = $this->feedLink($format, $rctitle->getLocalURL(array('feed' => $format)), $this->msg("site-{$format}-feed", $sitename)->text()); } } } # Canonical URL if ($config->get('EnableCanonicalServerLink')) { if ($canonicalUrl !== false) { $canonicalUrl = wfExpandUrl($canonicalUrl, PROTO_CANONICAL); } else { if ($this->isArticleRelated()) { // This affects all requests where "setArticleRelated" is true. This is // typically all requests that show content (query title, curid, oldid, diff), // and all wikipage actions (edit, delete, purge, info, history etc.). // It does not apply to File pages and Special pages. // 'history' and 'info' actions address page metadata rather than the page // content itself, so they may not be canonicalized to the view page url. // TODO: this ought to be better encapsulated in the Action class. $action = Action::getActionName($this->getContext()); if (in_array($action, array('history', 'info'))) { $query = "action={$action}"; } else { $query = ''; } $canonicalUrl = $this->getTitle()->getCanonicalURL($query); } else { $reqUrl = $this->getRequest()->getRequestURL(); $canonicalUrl = wfExpandUrl($reqUrl, PROTO_CANONICAL); } } } if ($canonicalUrl !== false) { $tags[] = Html::element('link', array('rel' => 'canonical', 'href' => $canonicalUrl)); } return $tags; }
/** * Get an array containing the variables to be set in mw.config in JavaScript. * * DO NOT CALL THIS FROM OUTSIDE OF THIS CLASS OR Skin::makeGlobalVariablesScript(). * This is only public until that function is removed. You have been warned. * * Do not add things here which can be evaluated in ResourceLoaderStartUpModule * - in other words, page-independent/site-wide variables (without state). * You will only be adding bloat to the html page and causing page caches to * have to be purged on configuration changes. * @return array */ public function getJSVars() { global $wgContLang; $curRevisionId = 0; $articleId = 0; $canonicalSpecialPageName = false; # bug 21115 $title = $this->getTitle(); $ns = $title->getNamespace(); $canonicalNamespace = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $title->getNsText(); $sk = $this->getSkin(); // Get the relevant title so that AJAX features can use the correct page name // when making API requests from certain special pages (bug 34972). $relevantTitle = $sk->getRelevantTitle(); $relevantUser = $sk->getRelevantUser(); if ($ns == NS_SPECIAL) { list($canonicalSpecialPageName, ) = SpecialPageFactory::resolveAlias($title->getDBkey()); } elseif ($this->canUseWikiPage()) { $wikiPage = $this->getWikiPage(); $curRevisionId = $wikiPage->getLatest(); $articleId = $wikiPage->getId(); } $lang = $title->getPageLanguage(); // Pre-process information $separatorTransTable = $lang->separatorTransformTable(); $separatorTransTable = $separatorTransTable ? $separatorTransTable : array(); $compactSeparatorTransTable = array(implode("\t", array_keys($separatorTransTable)), implode("\t", $separatorTransTable)); $digitTransTable = $lang->digitTransformTable(); $digitTransTable = $digitTransTable ? $digitTransTable : array(); $compactDigitTransTable = array(implode("\t", array_keys($digitTransTable)), implode("\t", $digitTransTable)); $user = $this->getUser(); $vars = array('wgCanonicalNamespace' => $canonicalNamespace, 'wgCanonicalSpecialPageName' => $canonicalSpecialPageName, 'wgNamespaceNumber' => $title->getNamespace(), 'wgPageName' => $title->getPrefixedDBkey(), 'wgTitle' => $title->getText(), 'wgCurRevisionId' => $curRevisionId, 'wgRevisionId' => (int) $this->getRevisionId(), 'wgArticleId' => $articleId, 'wgIsArticle' => $this->isArticle(), 'wgIsRedirect' => $title->isRedirect(), 'wgAction' => Action::getActionName($this->getContext()), 'wgUserName' => $user->isAnon() ? null : $user->getName(), 'wgUserGroups' => $user->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', 'wgPageContentLanguage' => $lang->getCode(), 'wgPageContentModel' => $title->getContentModel(), 'wgSeparatorTransformTable' => $compactSeparatorTransTable, 'wgDigitTransformTable' => $compactDigitTransTable, 'wgDefaultDateFormat' => $lang->getDefaultDateFormat(), 'wgMonthNames' => $lang->getMonthNamesArray(), 'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(), 'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey()); if ($user->isLoggedIn()) { $vars['wgUserId'] = $user->getId(); $vars['wgUserEditCount'] = $user->getEditCount(); $userReg = wfTimestampOrNull(TS_UNIX, $user->getRegistration()); $vars['wgUserRegistration'] = $userReg !== null ? $userReg * 1000 : null; // Get the revision ID of the oldest new message on the user's talk // page. This can be used for constructing new message alerts on // the client side. $vars['wgUserNewMsgRevisionId'] = $user->getNewMessageRevisionId(); } if ($wgContLang->hasVariants()) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); } // Same test as SkinTemplate $vars['wgIsProbablyEditable'] = $title->quickUserCan('edit', $user) && ($title->exists() || $title->quickUserCan('create', $user)); foreach ($title->getRestrictionTypes() as $type) { $vars['wgRestriction' . ucfirst($type)] = $title->getRestrictions($type); } if ($title->isMainPage()) { $vars['wgIsMainPage'] = true; } if ($this->mRedirectedFrom) { $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBkey(); } if ($relevantUser) { $vars['wgRelevantUserName'] = $relevantUser->getName(); } // Allow extensions to add their custom variables to the mw.config map. // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not // page-dependant but site-wide (without state). // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. wfRunHooks('MakeGlobalVariablesScript', array(&$vars, $this)); // Merge in variables from addJsConfigVars last return array_merge($vars, $this->getJsConfigVars()); }
/** * Returns the name of the action that will be executed. * * @return string: action */ public function getAction() { static $action = null; if ($action === null) { $action = Action::getActionName($this->context); } return $action; }
/** * a structured array of links usually used for the tabs in a skin * * There are 4 standard sections * namespaces: Used for namespace tabs like special, page, and talk namespaces * views: Used for primary page views like read, edit, history * actions: Used for most extra page actions like deletion, protection, etc... * variants: Used to list the language variants for the page * * Each section's value is a key/value array of links for that section. * The links themselves have these common keys: * - class: The css classes to apply to the tab * - text: The text to display on the tab * - href: The href for the tab to point to * - rel: An optional rel= for the tab's link * - redundant: If true the tab will be dropped in skins using content_actions * this is useful for tabs like "Read" which only have meaning in skins that * take special meaning from the grouped structure of content_navigation * * Views also have an extra key which can be used: * - primary: If this is not true skins like vector may try to hide the tab * when the user has limited space in their browser window * * content_navigation using code also expects these ids to be present on the * links, however these are usually automatically generated by SkinTemplate * itself and are not necessary when using a hook. The only things these may * matter to are people modifying content_navigation after it's initial creation: * - id: A "preferred" id, most skins are best off outputting this preferred * id for best compatibility. * - tooltiponly: This is set to true for some tabs in cases where the system * believes that the accesskey should not be added to the tab. * * @return array */ protected function buildContentNavigationUrls() { global $wgDisableLangConversion; // Display tabs for the relevant title rather than always the title itself $title = $this->getRelevantTitle(); $onPage = $title->equals($this->getTitle()); $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); $content_navigation = array('namespaces' => array(), 'views' => array(), 'actions' => array(), 'variants' => array()); // parameters $action = $request->getVal('action', 'view'); $userCanRead = $title->quickUserCan('read', $user); $preventActiveTabs = false; Hooks::run('SkinTemplatePreventOtherActiveTabs', array(&$this, &$preventActiveTabs)); // Checks if page is some kind of content if ($title->canExist()) { // Gets page objects for the related namespaces $subjectPage = $title->getSubjectPage(); $talkPage = $title->getTalkPage(); // Determines if this is a talk page $isTalk = $title->isTalkPage(); // Generates XML IDs from namespace names $subjectId = $title->getNamespaceKey(''); if ($subjectId == 'main') { $talkId = 'talk'; } else { $talkId = "{$subjectId}_talk"; } $skname = $this->skinname; // Adds namespace links $subjectMsg = array("nstab-{$subjectId}"); if ($subjectPage->isMainPage()) { array_unshift($subjectMsg, 'mainpage-nstab'); } $content_navigation['namespaces'][$subjectId] = $this->tabAction($subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead); $content_navigation['namespaces'][$subjectId]['context'] = 'subject'; $content_navigation['namespaces'][$talkId] = $this->tabAction($talkPage, array("nstab-{$talkId}", 'talk'), $isTalk && !$preventActiveTabs, '', $userCanRead); $content_navigation['namespaces'][$talkId]['context'] = 'talk'; if ($userCanRead) { $isForeignFile = $title->inNamespace(NS_FILE) && $this->canUseWikiPage() && $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal(); // Adds view view link if ($title->exists() || $isForeignFile) { $content_navigation['views']['view'] = $this->tabAction($isTalk ? $talkPage : $subjectPage, array("{$skname}-view-view", 'view'), $onPage && ($action == 'view' || $action == 'purge'), '', true); // signal to hide this from simple content_actions $content_navigation['views']['view']['redundant'] = true; } // If it is a non-local file, show a link to the file in its own repository if ($isForeignFile) { $file = $this->getWikiPage()->getFile(); $content_navigation['views']['view-foreign'] = array('class' => '', 'text' => wfMessageFallback("{$skname}-view-foreign", 'view-foreign')->setContext($this->getContext())->params($file->getRepo()->getDisplayName())->text(), 'href' => $file->getDescriptionUrl(), 'primary' => false); } // Checks if user can edit the current page if it exists or create it otherwise if ($title->quickUserCan('edit', $user) && ($title->exists() || $title->quickUserCan('create', $user))) { // Builds CSS class for talk page links $isTalkClass = $isTalk ? ' istalk' : ''; // Whether the user is editing the page $isEditing = $onPage && ($action == 'edit' || $action == 'submit'); // Whether to show the "Add a new section" tab // Checks if this is a current rev of talk page and is not forced to be hidden $showNewSection = !$out->forceHideNewSectionLink() && ($isTalk && $this->isRevisionCurrent() || $out->showNewSectionLink()); $section = $request->getVal('section'); if ($title->exists() || $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false) { $msgKey = $isForeignFile ? 'edit-local' : 'edit'; } else { $msgKey = $isForeignFile ? 'create-local' : 'create'; } $content_navigation['views']['edit'] = array('class' => ($isEditing && ($section !== 'new' || !$showNewSection) ? 'selected' : '') . $isTalkClass, 'text' => wfMessageFallback("{$skname}-view-{$msgKey}", $msgKey)->setContext($this->getContext())->text(), 'href' => $title->getLocalURL($this->editUrlOptions()), 'primary' => !$isForeignFile); // section link if ($showNewSection) { // Adds new section link //$content_navigation['actions']['addsection'] $content_navigation['views']['addsection'] = array('class' => $isEditing && $section == 'new' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-addsection", 'addsection')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL('action=edit§ion=new')); } // Checks if the page has some kind of viewable content } elseif ($title->hasSourceText()) { // Adds view source view link $content_navigation['views']['viewsource'] = array('class' => $onPage && $action == 'edit' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-viewsource", 'viewsource')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL($this->editUrlOptions()), 'primary' => true); } // Checks if the page exists if ($title->exists()) { // Adds history view link $content_navigation['views']['history'] = array('class' => $onPage && $action == 'history' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-view-history", 'history_short')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL('action=history')); if ($title->quickUserCan('delete', $user)) { $content_navigation['actions']['delete'] = array('class' => $onPage && $action == 'delete' ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-delete", 'delete')->setContext($this->getContext())->text(), 'href' => $title->getLocalURL('action=delete')); } if ($title->quickUserCan('move', $user)) { $moveTitle = SpecialPage::getTitleFor('Movepage', $title->getPrefixedDBkey()); $content_navigation['actions']['move'] = array('class' => $this->getTitle()->isSpecial('Movepage') ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-move", 'move')->setContext($this->getContext())->text(), 'href' => $moveTitle->getLocalURL()); } } else { // article doesn't exist or is deleted if ($user->isAllowed('deletedhistory')) { $n = $title->isDeleted(); if ($n) { $undelTitle = SpecialPage::getTitleFor('Undelete', $title->getPrefixedDBkey()); // If the user can't undelete but can view deleted // history show them a "View .. deleted" tab instead. $msgKey = $user->isAllowed('undelete') ? 'undelete' : 'viewdeleted'; $content_navigation['actions']['undelete'] = array('class' => $this->getTitle()->isSpecial('Undelete') ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-{$msgKey}", "{$msgKey}_short")->setContext($this->getContext())->numParams($n)->text(), 'href' => $undelTitle->getLocalURL()); } } } if ($title->quickUserCan('protect', $user) && $title->getRestrictionTypes() && MWNamespace::getRestrictionLevels($title->getNamespace(), $user) !== array('')) { $mode = $title->isProtected() ? 'unprotect' : 'protect'; $content_navigation['actions'][$mode] = array('class' => $onPage && $action == $mode ? 'selected' : false, 'text' => wfMessageFallback("{$skname}-action-{$mode}", $mode)->setContext($this->getContext())->text(), 'href' => $title->getLocalURL("action={$mode}")); } // Checks if the user is logged in if ($this->loggedin && $user->isAllowedAll('viewmywatchlist', 'editmywatchlist')) { /** * The following actions use messages which, if made particular to * the any specific skins, would break the Ajax code which makes this * action happen entirely inline. OutputPage::getJSVars * defines a set of messages in a javascript object - and these * messages are assumed to be global for all skins. Without making * a change to that procedure these messages will have to remain as * the global versions. */ $mode = $user->isWatched($title) ? 'unwatch' : 'watch'; $token = WatchAction::getWatchToken($title, $user, $mode); $content_navigation['actions'][$mode] = array('class' => $onPage && ($action == 'watch' || $action == 'unwatch') ? 'selected' : false, 'text' => $this->msg($mode)->text(), 'href' => $title->getLocalURL(array('action' => $mode, 'token' => $token))); } } Hooks::run('SkinTemplateNavigation', array(&$this, &$content_navigation)); if ($userCanRead && !$wgDisableLangConversion) { $pageLang = $title->getPageLanguage(); // Gets list of language variants $variants = $pageLang->getVariants(); // Checks that language conversion is enabled and variants exist // And if it is not in the special namespace if (count($variants) > 1) { // Gets preferred variant (note that user preference is // only possible for wiki content language variant) $preferred = $pageLang->getPreferredVariant(); if (Action::getActionName($this) === 'view') { $params = $request->getQueryValues(); unset($params['title']); } else { $params = array(); } // Loops over each variant foreach ($variants as $code) { // Gets variant name from language code $varname = $pageLang->getVariantname($code); // Appends variant link $content_navigation['variants'][] = array('class' => $code == $preferred ? 'selected' : false, 'text' => $varname, 'href' => $title->getLocalURL(array('variant' => $code) + $params), 'lang' => wfBCP47($code), 'hreflang' => wfBCP47($code)); } } } } else { // If it's not content, it's got to be a special page $content_navigation['namespaces']['special'] = array('class' => 'selected', 'text' => $this->msg('nstab-special')->text(), 'href' => $request->getRequestURL(), 'context' => 'subject'); Hooks::run('SkinTemplateNavigation::SpecialPage', array(&$this, &$content_navigation)); } // Equiv to SkinTemplateContentActions Hooks::run('SkinTemplateNavigation::Universal', array(&$this, &$content_navigation)); // Setup xml ids and tooltip info foreach ($content_navigation as $section => &$links) { foreach ($links as $key => &$link) { $xmlID = $key; if (isset($link['context']) && $link['context'] == 'subject') { $xmlID = 'ca-nstab-' . $xmlID; } elseif (isset($link['context']) && $link['context'] == 'talk') { $xmlID = 'ca-talk'; } elseif ($section == 'variants') { $xmlID = 'ca-varlang-' . $xmlID; } else { $xmlID = 'ca-' . $xmlID; } $link['id'] = $xmlID; } } # We don't want to give the watch tab an accesskey if the # page is being edited, because that conflicts with the # accesskey on the watch checkbox. We also don't want to # give the edit tab an accesskey, because that's fairly # superfluous and conflicts with an accesskey (Ctrl-E) often # used for editing in Safari. if (in_array($action, array('edit', 'submit'))) { if (isset($content_navigation['views']['edit'])) { $content_navigation['views']['edit']['tooltiponly'] = true; } if (isset($content_navigation['actions']['watch'])) { $content_navigation['actions']['watch']['tooltiponly'] = true; } if (isset($content_navigation['actions']['unwatch'])) { $content_navigation['actions']['unwatch']['tooltiponly'] = true; } } return $content_navigation; }
/** * Adds help link with an icon via page indicators. * Link target can be overridden by a local message containing a wikilink: * the message key is: lowercase action name + '-helppage'. * @param string $to Target MediaWiki.org page title or encoded URL. * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o. * @since 1.25 */ public function addHelpLink($to, $overrideBaseUrl = false) { global $wgContLang; $msg = wfMessage($wgContLang->lc(Action::getActionName($this->getContext())) . '-helppage'); if (!$msg->isDisabled()) { $helpUrl = Skin::makeUrl($msg->plain()); $this->getOutput()->addHelpLink($helpUrl, true); } else { $this->getOutput()->addHelpLink($to, $overrideBaseUrl); } }
/** * Returns the name of the action that will be executed. * * @return string Action */ public function getAction() { if ($this->action === null) { $this->action = Action::getActionName($this->context); } return $this->action; }
/** * Returns the 'Last edited' message, e.g. 'Last edited on...' * @param array $data Data used to build the page * @return string */ protected function getHistoryLinkHtml($data) { $action = Action::getActionName(RequestContext::getMain()); if (isset($data['historyLink']) && $action === 'view') { $historyLink = $data['historyLink']; $args = array('isMainPage' => $this->getSkin()->getTitle()->isMainPage(), 'link' => $historyLink['href'], 'text' => $historyLink['text'], 'username' => $historyLink['data-user-name'], 'userGender' => $historyLink['data-user-gender'], 'timestamp' => $historyLink['data-timestamp']); $templateParser = new TemplateParser(__DIR__); return $templateParser->processTemplate('history', $args); } else { return ''; } }
public function testDisabledAction_isNotResolved() { $context = $this->getContext('disabled'); $actionName = Action::getActionName($context); $this->assertEquals('nosuchaction', $actionName); }
private function manuscriptIsInViewMode(OutputPage $out) { $context = $out->getContext(); if (Action::getActionName($context) !== 'view') { return false; } return true; }
/** * Get an array containing the variables to be set in mw.config in JavaScript. * * DO NOT CALL THIS FROM OUTSIDE OF THIS CLASS OR Skin::makeGlobalVariablesScript(). * This is only public until that function is removed. You have been warned. * * Do not add things here which can be evaluated in ResourceLoaderStartupScript * - in other words, page-independent/site-wide variables (without state). * You will only be adding bloat to the html page and causing page caches to * have to be purged on configuration changes. * @return array */ public function getJSVars() { global $wgUseAjax, $wgEnableMWSuggest; $latestRevID = 0; $pageID = 0; $canonicalName = false; # bug 21115 $title = $this->getTitle(); $ns = $title->getNamespace(); $nsname = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $title->getNsText(); // Get the relevant title so that AJAX features can use the correct page name // when making API requests from certain special pages (bug 34972). $relevantTitle = $this->getSkin()->getRelevantTitle(); if ($ns == NS_SPECIAL) { list($canonicalName, ) = SpecialPageFactory::resolveAlias($title->getDBkey()); } elseif ($this->canUseWikiPage()) { $wikiPage = $this->getWikiPage(); $latestRevID = $wikiPage->getLatest(); $pageID = $wikiPage->getId(); } $lang = $title->getPageLanguage(); // Pre-process information $separatorTransTable = $lang->separatorTransformTable(); $separatorTransTable = $separatorTransTable ? $separatorTransTable : array(); $compactSeparatorTransTable = array(implode("\t", array_keys($separatorTransTable)), implode("\t", $separatorTransTable)); $digitTransTable = $lang->digitTransformTable(); $digitTransTable = $digitTransTable ? $digitTransTable : array(); $compactDigitTransTable = array(implode("\t", array_keys($digitTransTable)), implode("\t", $digitTransTable)); $vars = array('wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => $canonicalName, 'wgNamespaceNumber' => $title->getNamespace(), 'wgPageName' => $title->getPrefixedDBKey(), 'wgTitle' => $title->getText(), 'wgCurRevisionId' => $latestRevID, 'wgArticleId' => $pageID, 'wgIsArticle' => $this->isArticle(), 'wgAction' => Action::getActionName($this->getContext()), 'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(), 'wgUserGroups' => $this->getUser()->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', 'wgPageContentLanguage' => $lang->getCode(), 'wgSeparatorTransformTable' => $compactSeparatorTransTable, 'wgDigitTransformTable' => $compactDigitTransTable, 'wgRelevantPageName' => $relevantTitle->getPrefixedDBKey()); if ($lang->hasVariants()) { $vars['wgUserVariant'] = $lang->getPreferredVariant(); } foreach ($title->getRestrictionTypes() as $type) { $vars['wgRestriction' . ucfirst($type)] = $title->getRestrictions($type); } if ($wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption('disablesuggest', false)) { $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces($this->getUser()); } if ($title->isMainPage()) { $vars['wgIsMainPage'] = true; } if ($this->mRedirectedFrom) { $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBKey(); } // Allow extensions to add their custom variables to the mw.config map. // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not // page-dependant but site-wide (without state). // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. wfRunHooks('MakeGlobalVariablesScript', array(&$vars, $this)); // Merge in variables from addJsConfigVars last return array_merge($vars, $this->mJsConfigVars); }
/** * Returns the name of the action that will be executed. * * @return string: action */ public function getAction() { static $action = null; if ($action === null) { // Wikia change - begin // @author macbre wfRunHooks('MediaWikiGetAction', array($this, $this->context)); // Wikia change - end $action = Action::getActionName($this->context); } return $action; }
/** * Menu item for ChooseTheme * * @param Action $action action being executed * * @return boolean hook return */ function onEndAccountSettingsNav(Action $action) { $action_name = $action->getActionName(); $action->menuItem(common_local_url('choosethemesettings'), _m('MENU', 'Theme'), _m('Choose Theme'), $action_name === 'themesettings'); return true; }
protected function renderApiResponse(array $apiResponse) { // Render the flow-component wrapper if (empty($apiResponse['blocks'])) { return array(); } $out = $this->getOutput(); // Add JSON blob for OOUI widgets $out->addHTML(Html::inlineScript('mw.flow = mw.flow || {}; mw.flow.data = ' . FormatJson::encode($apiResponse) . ';')); $renderedBlocks = array(); foreach ($apiResponse['blocks'] as $block) { // @todo find a better way to do this; potentially make all blocks their own components switch ($block['type']) { case 'board-history': $flowComponent = 'boardHistory'; $page = 'history'; break; case 'topic': if ($block['submitted']['action'] === 'history') { $page = 'history'; $flowComponent = 'boardHistory'; } else { $page = 'topic'; $flowComponent = 'board'; } break; default: $flowComponent = 'board'; $page = 'board'; } // Don't re-render a block type twice in one page if (isset($renderedBlocks[$flowComponent])) { continue; } $renderedBlocks[$flowComponent] = true; // Get the block loop template $template = $this->lightncandy->getTemplate('flow_block_loop'); $classes = array('flow-component', "{$page}-page"); // Add mw-content-{ltr,rtl} text if necessary (MW core doesn't add it for non-view actions if (\Action::getActionName($this) !== 'view') { $title = Title::newFromText($apiResponse['title']); $classes[] = 'mw-content-' . $title->getPageViewLanguage()->getDir(); } // Output the component, with the rendered blocks inside it $out->addHTML(Html::rawElement('div', array('class' => implode(' ', $classes), 'data-flow-component' => $flowComponent, 'data-flow-id' => $apiResponse['workflow']), $template($apiResponse))); } }