3 * Copyright © Gabriel Wicke -- http://www.aulinx.de/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 use MediaWiki\Debug\MWDebug
;
24 use MediaWiki\Html\Html
;
25 use MediaWiki\Language\LanguageCode
;
26 use MediaWiki\Linker\Linker
;
27 use MediaWiki\MainConfigNames
;
28 use MediaWiki\MediaWikiServices
;
29 use MediaWiki\Message\Message
;
30 use MediaWiki\Permissions\Authority
;
31 use MediaWiki\ResourceLoader
as RL
;
32 use MediaWiki\Skin\SkinComponentUtils
;
33 use MediaWiki\SpecialPage\SpecialPage
;
34 use MediaWiki\Specials\Contribute\ContributeFactory
;
35 use MediaWiki\Title\Title
;
36 use Wikimedia\Message\MessageParam
;
37 use Wikimedia\Message\MessageSpecifier
;
40 * Base class for QuickTemplate-based skins.
42 * The template data is filled in SkinTemplate::prepareQuickTemplate.
47 class SkinTemplate
extends Skin
{
49 * @var string For QuickTemplate, the name of the subclass which will
50 * actually fill the template.
60 /** @var bool TODO: Rename this to $isRegistered (but that's a breaking change) */
65 public $userpageUrlDetails;
77 private $templateContextSet = false;
78 /** @var array|null */
79 private $contentNavigationCached;
80 /** @var array|null */
81 private $portletsCached;
84 * Create the template engine object; we feed it a bunch of data
85 * and eventually it spits out some HTML. Should have interface
86 * roughly equivalent to PHPTAL 0.7.
88 * @param string $classname
89 * @return QuickTemplate
91 protected function setupTemplate( $classname ) {
92 return new $classname( $this->getConfig() );
96 * @return QuickTemplate
98 protected function setupTemplateForOutput() {
99 $this->setupTemplateContext();
100 $template = $this->options
['template'] ??
$this->template
;
102 throw new RuntimeException(
103 'SkinTemplate skins must define a `template` either as a public'
104 . ' property of by passing in a`template` option to the constructor.'
107 $tpl = $this->setupTemplate( $template );
112 * Setup class properties that are necessary prior to calling
113 * setupTemplateForOutput. It must be called inside
114 * prepareQuickTemplate.
115 * This function may set local class properties that will be used
116 * by other methods, but should not make assumptions about the
117 * implementation of setupTemplateForOutput
120 final protected function setupTemplateContext() {
121 if ( $this->templateContextSet
) {
125 $request = $this->getRequest();
126 $user = $this->getUser();
127 $title = $this->getTitle();
128 $this->thispage
= $title->getPrefixedDBkey();
129 $this->titletxt
= $title->getPrefixedText();
130 $userpageTitle = $user->getUserPage();
131 $this->userpage
= $userpageTitle->getPrefixedText();
132 $this->loggedin
= $user->isRegistered();
133 $this->username
= $user->getName();
134 $this->isTempUser
= $user->isTemp();
135 $this->isNamedUser
= $this->loggedin
&& !$this->isTempUser
;
136 $this->isAnonUser
= $user->isAnon();
138 if ( $this->isNamedUser
) {
139 $this->userpageUrlDetails
= self
::makeUrlDetails( $userpageTitle );
141 # This won't be used in the standard skins, but we define it to preserve the interface
142 # To save time, we check for existence
143 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $userpageTitle );
146 $this->templateContextSet
= true;
150 * Subclasses not wishing to use the QuickTemplate
151 * render method can rewrite this method, for example to use
152 * TemplateParser::processTemplate
154 * @return string HTML is the contents of the body tag e.g. <body>...</body>
156 public function generateHTML() {
157 $tpl = $this->prepareQuickTemplate();
158 $options = $this->getOptions();
159 $out = $this->getOutput();
163 $html = ob_get_contents();
170 * Initialize various variables and generate the template
171 * @stable to override
173 public function outputPage() {
174 Profiler
::instance()->setAllowOutput();
175 $out = $this->getOutput();
177 $this->initPage( $out );
178 $out->addJsConfigVars( $this->getJsConfigVars() );
180 // result may be an error
181 echo $this->generateHTML();
187 public function getTemplateData() {
188 return parent
::getTemplateData() +
$this->getPortletsTemplateData();
192 * initialize various variables and generate the template
195 * @return QuickTemplate The template to be executed by outputPage
197 protected function prepareQuickTemplate() {
198 $title = $this->getTitle();
199 $request = $this->getRequest();
200 $out = $this->getOutput();
201 $config = $this->getConfig();
202 $tpl = $this->setupTemplateForOutput();
204 $tpl->set( 'title', $out->getPageTitle() );
205 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
207 $tpl->set( 'thispage', $this->thispage
);
208 $tpl->set( 'titleprefixeddbkey', $this->thispage
);
209 $tpl->set( 'titletext', $title->getText() );
210 $tpl->set( 'articleid', $title->getArticleID() );
212 $tpl->set( 'isarticle', $out->isArticle() );
214 $tpl->set( 'subtitle', $this->prepareSubtitle() );
215 $tpl->set( 'undelete', $this->prepareUndeleteLink() );
217 $tpl->set( 'catlinks', $this->getCategories() );
218 $feeds = $this->buildFeedUrls();
219 $tpl->set( 'feeds', count( $feeds ) ?
$feeds : false );
221 $tpl->set( 'mimetype', $config->get( MainConfigNames
::MimeType
) );
222 $tpl->set( 'charset', 'UTF-8' );
223 $tpl->set( 'wgScript', $config->get( MainConfigNames
::Script
) );
224 $tpl->set( 'skinname', $this->skinname
);
225 $tpl->set( 'skinclass', static::class );
226 $tpl->set( 'skin', $this );
227 $tpl->set( 'printable', $out->isPrintable() );
228 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
229 $tpl->set( 'loggedin', $this->loggedin
);
230 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
232 $searchTitle = SpecialPage
::newSearchPage( $this->getUser() );
233 $searchLink = $searchTitle->getLocalURL();
234 $tpl->set( 'searchaction', $searchLink );
235 $tpl->deprecate( 'searchaction', '1.36' );
237 $tpl->set( 'searchtitle', $searchTitle->getPrefixedDBkey() );
238 $tpl->set( 'search', trim( $request->getVal( 'search', '' ) ) );
239 $tpl->set( 'stylepath', $config->get( MainConfigNames
::StylePath
) );
240 $tpl->set( 'articlepath', $config->get( MainConfigNames
::ArticlePath
) );
241 $tpl->set( 'scriptpath', $config->get( MainConfigNames
::ScriptPath
) );
242 $tpl->set( 'serverurl', $config->get( MainConfigNames
::Server
) );
243 $tpl->set( 'sitename', $config->get( MainConfigNames
::Sitename
) );
245 $userLang = $this->getLanguage();
246 $userLangCode = $userLang->getHtmlCode();
247 $userLangDir = $userLang->getDir();
249 $tpl->set( 'lang', $userLangCode );
250 $tpl->set( 'dir', $userLangDir );
251 $tpl->set( 'rtl', $userLang->isRTL() );
253 $logos = RL\SkinModule
::getAvailableLogos( $config, $userLangCode );
254 $tpl->set( 'logopath', $logos['1x'] );
256 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
257 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
258 $tpl->set( 'userpage', $this->userpage
);
259 $tpl->set( 'userpageurl', $this->userpageUrlDetails
['href'] );
260 $tpl->set( 'userlang', $userLangCode );
262 // Users can have their language set differently than the
263 // content of the wiki. For these users, tell the web browser
264 // that interface elements are in a different language.
265 $tpl->set( 'userlangattributes', $this->prepareUserLanguageAttributes() );
266 $tpl->set( 'specialpageattributes', '' ); # obsolete
267 // Used by VectorBeta to insert HTML before content but after the
268 // heading for the page title. Defaults to empty string.
269 $tpl->set( 'prebodyhtml', '' );
271 $tpl->set( 'newtalk', $this->getNewtalks() );
272 $tpl->set( 'logo', $this->logoText() );
274 $footerData = $this->getComponent( 'footer' )->getTemplateData();
275 $tpl->set( 'copyright', $footerData['info']['copyright'] ??
false );
277 $tpl->set( 'viewcount', false );
278 $tpl->set( 'lastmod', $footerData['info']['lastmod'] ??
false );
279 $tpl->set( 'credits', $footerData['info']['credits'] ??
false );
280 $tpl->set( 'numberofwatchingusers', false );
282 $tpl->set( 'disclaimer', $footerData['places']['disclaimer'] ??
false );
283 $tpl->set( 'privacy', $footerData['places']['privacy'] ??
false );
284 $tpl->set( 'about', $footerData['places']['about'] ??
false );
286 // Flatten for compat with the 'footerlinks' key in QuickTemplate-based skins.
287 $flattenedfooterlinks = [];
288 foreach ( $footerData as $category => $data ) {
289 if ( $category !== 'data-icons' ) {
290 foreach ( $data['array-items'] as $item ) {
291 $key = str_replace( 'data-', '', $category );
292 $flattenedfooterlinks[$key][] = $item['name'];
293 // For full support with BaseTemplate we also need to
294 // copy over the keys.
295 $tpl->set( $item['name'], $item['html'] );
299 $tpl->set( 'footerlinks', $flattenedfooterlinks );
300 $tpl->set( 'footericons', $this->getFooterIcons() );
302 $tpl->set( 'indicators', $out->getIndicators() );
304 $tpl->set( 'sitenotice', $this->getSiteNotice() );
305 $tpl->set( 'printfooter', $this->printSource() );
306 // Wrap the bodyText with #mw-content-text element
307 $tpl->set( 'bodytext', $this->wrapHTML( $title, $out->getHTML() ) );
309 $tpl->set( 'language_urls', $this->getLanguages() ?
: false );
311 $content_navigation = $this->buildContentNavigationUrlsInternal();
313 $tpl->set( 'personal_urls', $this->makeSkinTemplatePersonalUrls( $content_navigation ) );
314 // The user-menu, notifications, and user-interface-preferences are new content navigation entries which aren't
315 // expected to be part of content_navigation or content_actions. Adding them in there breaks skins that do not
316 // expect it. (See T316196)
318 $content_navigation['user-menu'],
319 $content_navigation['notifications'],
320 $content_navigation['user-page'],
321 $content_navigation['user-interface-preferences'],
322 $content_navigation['category-normal'],
323 $content_navigation['category-hidden'],
324 $content_navigation['associated-pages']
326 $content_actions = $this->buildContentActionUrls( $content_navigation );
327 $tpl->set( 'content_navigation', $content_navigation );
328 $tpl->set( 'content_actions', $content_actions );
330 $tpl->set( 'sidebar', $this->buildSidebar() );
331 $tpl->set( 'nav_urls', $this->buildNavUrls() );
333 $tpl->set( 'debug', '' );
334 $tpl->set( 'debughtml', MWDebug
::getHTMLDebugLog() );
336 // Set the bodytext to another key so that skins can just output it on its own
337 // and output printfooter and debughtml separately
338 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
340 // Append printfooter and debughtml onto bodytext so that skins that
341 // were already using bodytext before they were split out don't suddenly
342 // start not outputting information.
343 $tpl->data
['bodytext'] .= Html
::rawElement(
345 [ 'class' => 'printfooter' ],
346 "\n{$tpl->data['printfooter']}"
348 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
350 // allow extensions adding stuff after the page content.
351 // See Skin::afterContentHook() for further documentation.
352 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
358 * Get the HTML for the personal tools list
361 * @param array|null $personalTools
362 * @param array $options
365 public function makePersonalToolsList( $personalTools = null, $options = [] ) {
366 $personalTools ??
= $this->getPersonalToolsForMakeListItem(
367 $this->buildPersonalUrls()
371 foreach ( $personalTools as $key => $item ) {
372 $html .= $this->makeListItem( $key, $item, $options );
378 * Get personal tools for the user
384 public function getStructuredPersonalTools() {
385 return $this->getPersonalToolsForMakeListItem(
386 $this->buildPersonalUrls()
391 * Build array of urls for personal toolbar
393 * @param bool $includeNotifications Since 1.36, notifications are optional
396 protected function buildPersonalUrls( bool $includeNotifications = true ) {
397 $this->setupTemplateContext();
398 $title = $this->getTitle();
399 $authority = $this->getAuthority();
400 $request = $this->getRequest();
401 $pageurl = $title->getLocalURL();
402 $services = MediaWikiServices
::getInstance();
403 $authManager = $services->getAuthManager();
404 $groupPermissionsLookup = $services->getGroupPermissionsLookup();
405 $tempUserConfig = $services->getTempUserConfig();
406 $returnto = SkinComponentUtils
::getReturnToParam( $title, $request, $authority );
407 $shouldHideUserLinks = $this->isAnonUser
&& $tempUserConfig->isKnown();
409 /* set up the default links for the personal toolbar */
412 if ( $this->loggedin
) {
413 $this->addPersonalPageItem( $personal_urls, '' );
415 // Merge notifications into the personal menu for older skins.
416 if ( $includeNotifications ) {
417 $contentNavigation = $this->buildContentNavigationUrlsInternal();
419 $personal_urls +
= $contentNavigation['notifications'];
422 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
423 $personal_urls['mytalk'] = [
424 'text' => $this->msg( 'mytalk' )->text(),
425 'href' => &$usertalkUrlDetails['href'],
426 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
427 'exists' => $usertalkUrlDetails['exists'],
428 'active' => ( $usertalkUrlDetails['href'] == $pageurl ),
431 if ( !$this->isTempUser
) {
432 $href = SkinComponentUtils
::makeSpecialUrl( 'Preferences' );
433 $personal_urls['preferences'] = [
434 'text' => $this->msg( 'mypreferences' )->text(),
436 'active' => ( $href == $pageurl ),
437 'icon' => 'settings',
441 if ( $authority->isAllowed( 'viewmywatchlist' ) ) {
442 $personal_urls['watchlist'] = self
::buildWatchlistData();
445 # We need to do an explicit check for Special:Contributions, as we
446 # have to match both the title, and the target, which could come
447 # from request values (Special:Contributions?target=Jimbo_Wales)
448 # or be specified in "subpage" form
449 # (Special:Contributions/Jimbo_Wales). The plot
450 # thickens, because the Title object is altered for special pages,
451 # so it doesn't contain the original alias-with-subpage.
452 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
453 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
454 [ $spName, $spPar ] =
455 MediaWikiServices
::getInstance()->getSpecialPageFactory()->
456 resolveAlias( $origTitle->getText() );
457 $active = $spName == 'Contributions'
458 && ( ( $spPar && $spPar == $this->username
)
459 ||
$request->getText( 'target' ) == $this->username
);
464 $personal_urls = $this->makeContributionsLink( $personal_urls, 'mycontris', $this->username
, $active );
466 // if we can't set the user, we can't unset it either
467 if ( $request->getSession()->canSetUser() ) {
468 $personal_urls['logout'] = $this->buildLogoutLinkData();
470 } elseif ( !$shouldHideUserLinks ) {
471 $canEdit = $authority->isAllowed( 'edit' );
472 $canEditWithTemp = $tempUserConfig->isAutoCreateAction( 'edit' );
473 // No need to show Talk and Contributions to anons if they can't contribute!
474 if ( $canEdit ||
$canEditWithTemp ) {
475 // Non interactive placeholder for anonymous users.
476 // It's unstyled by default (black color). Skin that
477 // needs it, can style it using the 'pt-anonuserpage' id.
478 // Skin that does not need it should unset it.
479 $personal_urls['anonuserpage'] = [
480 'text' => $this->msg( 'notloggedin' )->text(),
484 // Because of caching, we can't link directly to the IP talk and
485 // contributions pages. Instead we use the special page shortcuts
486 // (which work correctly regardless of caching). This means we can't
487 // determine whether these links are active or not, but since major
488 // skins (MonoBook, Vector) don't use this information, it's not a
490 $personal_urls['anontalk'] = [
491 'text' => $this->msg( 'anontalk' )->text(),
492 'href' => SkinComponentUtils
::makeSpecialUrlSubpage( 'Mytalk', false ),
494 'icon' => 'userTalk',
496 $personal_urls = $this->makeContributionsLink( $personal_urls, 'anoncontribs', null, false );
500 if ( !$this->loggedin
) {
501 $useCombinedLoginLink = $this->useCombinedLoginLink();
502 $login_url = $this->buildLoginData( $returnto, $useCombinedLoginLink );
503 $createaccount_url = $this->buildCreateAccountData( $returnto );
506 $authManager->canCreateAccounts()
507 && $authority->isAllowed( 'createaccount' )
508 && !$useCombinedLoginLink
510 $personal_urls['createaccount'] = $createaccount_url;
513 if ( $authManager->canAuthenticateNow() ) {
514 // TODO: easy way to get anon authority
515 $key = $groupPermissionsLookup->groupHasPermission( '*', 'read' )
518 $personal_urls[$key] = $login_url;
522 return $personal_urls;
526 * Returns if a combined login/signup link will be used
531 protected function useCombinedLoginLink() {
532 $services = MediaWikiServices
::getInstance();
533 $authManager = $services->getAuthManager();
534 $useCombinedLoginLink = $this->getConfig()->get( MainConfigNames
::UseCombinedLoginLink
);
535 if ( !$authManager->canCreateAccounts() ||
!$authManager->canAuthenticateNow() ) {
536 // don't show combined login/signup link if one of those is actually not available
537 $useCombinedLoginLink = false;
540 return $useCombinedLoginLink;
547 * @param string[] $returnto query params for the page to return to
548 * @param bool $useCombinedLoginLink when set a single link to login form will be created
549 * with alternative label.
552 protected function buildLoginData( $returnto, $useCombinedLoginLink ) {
553 $title = $this->getTitle();
555 $loginlink = $this->getAuthority()->isAllowed( 'createaccount' )
556 && $useCombinedLoginLink ?
'nav-login-createaccount' : 'pt-login';
559 'single-id' => 'pt-login',
560 'text' => $this->msg( $loginlink )->text(),
561 'href' => SkinComponentUtils
::makeSpecialUrl( 'Userlogin', $returnto ),
562 'active' => $title->isSpecial( 'Userlogin' )
563 ||
( $title->isSpecial( 'CreateAccount' ) && $useCombinedLoginLink ),
571 * @param array $links return value from OutputPage::getCategoryLinks
572 * @return array of data
574 private function getCategoryPortletsData( array $links ): array {
576 foreach ( $links as $group => $groupLinks ) {
578 $groupName = 'category-' . $group;
579 foreach ( $groupLinks as $i => $link ) {
580 $allLinks[$groupName . '-' . $i] = [
584 $categories[ $groupName ] = $allLinks;
590 * Extends category links with Skin::getAfterPortlet functionality.
591 * @return string HTML
593 public function getCategoryLinks() {
594 $afterPortlet = $this->getPortletsTemplateData()['data-portlets']['data-category-normal']['html-after-portal']
596 return parent
::getCategoryLinks() . $afterPortlet;
600 * @return array of portlet data for all portlets
602 private function getPortletsTemplateData() {
603 if ( $this->portletsCached
) {
604 return $this->portletsCached
;
607 $contentNavigation = $this->buildContentNavigationUrlsInternal();
609 $sidebarData = $this->buildSidebar();
610 foreach ( $sidebarData as $name => $items ) {
611 if ( is_array( $items ) ) {
612 // Numeric strings gets an integer when set as key, cast back - T73639
613 $name = (string)$name;
618 // Map toolbox to `tb` id.
620 $sidebar[] = $this->getPortletData( 'tb', $items );
622 // Languages is no longer be tied to sidebar
624 // The language portal will be added provided either
625 // languages exist or there is a value in html-after-portal
626 // for example to show the add language wikidata link (T252800)
627 $portal = $this->getPortletData( 'lang', $items );
628 if ( count( $items ) ||
$portal['html-after-portal'] ) {
629 $portlets['data-languages'] = $portal;
633 $sidebar[] = $this->getPortletData( $name, $items );
639 foreach ( $contentNavigation as $name => $items ) {
640 if ( $name === 'user-menu' ) {
641 $items = $this->getPersonalToolsForMakeListItem( $items, true );
644 $portlets['data-' . $name] = $this->getPortletData( $name, $items );
647 // A menu that includes the notifications. This will be deprecated in future versions
648 // of the skin API spec.
649 $portlets['data-personal'] = $this->getPortletData(
651 $this->getPersonalToolsForMakeListItem(
652 $this->injectLegacyMenusIntoPersonalTools( $contentNavigation )
656 $this->portletsCached
= [
657 'data-portlets' => $portlets,
658 'data-portlets-sidebar' => [
659 'data-portlets-first' => $sidebar[0] ??
null,
660 'array-portlets-rest' => array_slice( $sidebar, 1 ),
663 return $this->portletsCached
;
667 * Build data required for "Logout" link.
673 * @return array Array of data required to create a logout link.
675 final protected function buildLogoutLinkData() {
676 $title = $this->getTitle();
677 $request = $this->getRequest();
678 $authority = $this->getAuthority();
679 $returnto = SkinComponentUtils
::getReturnToParam( $title, $request, $authority );
680 $isTemp = $this->isTempUser
;
681 $msg = $isTemp ?
'templogout' : 'pt-userlogout';
684 'single-id' => 'pt-logout',
685 'text' => $this->msg( $msg )->text(),
686 'data-mw' => 'interface',
687 'href' => SkinComponentUtils
::makeSpecialUrl( 'Userlogout', $returnto ),
694 * Build "Create Account" link data.
697 * @param string[] $returnto query params for the page to return to
700 protected function buildCreateAccountData( $returnto ) {
701 $title = $this->getTitle();
704 'single-id' => 'pt-createaccount',
705 'text' => $this->msg( 'pt-createaccount' )->text(),
706 'href' => SkinComponentUtils
::makeSpecialUrl( 'CreateAccount', $returnto ),
707 'active' => $title->isSpecial( 'CreateAccount' ),
713 * Add the userpage link to the array
715 * @param array &$links Links array to append to
716 * @param string $idSuffix Something to add to the IDs to make them unique
718 private function addPersonalPageItem( &$links, $idSuffix ) {
719 if ( $this->isNamedUser
) { // T340152
720 $links['userpage'] = $this->buildPersonalPageItem( 'pt-userpage' . $idSuffix );
725 * Build a user page link data.
727 * @param string $id of user page item to be output in HTML attribute (optional)
730 protected function buildPersonalPageItem( $id = 'pt-userpage' ): array {
731 $linkClasses = $this->userpageUrlDetails
['exists'] ?
[] : [ 'new' ];
732 // T335440 Temp accounts dont show a user page link
733 // But we still need to update the user icon, as its used by other UI elements
734 $icon = $this->isTempUser ?
'userTemporary' : 'userAvatar';
735 $href = &$this->userpageUrlDetails
['href'];
738 'single-id' => 'pt-userpage',
739 'text' => $this->username
,
741 'link-class' => $linkClasses,
742 'exists' => $this->userpageUrlDetails
['exists'],
743 'active' => ( $this->userpageUrlDetails
['href'] == $this->getTitle()->getLocalURL() ),
749 * Build a watchlist link data.
751 * @return array Array of data required to create a watchlist link.
753 private function buildWatchlistData() {
754 $href = SkinComponentUtils
::makeSpecialUrl( 'Watchlist' );
755 $pageurl = $this->getTitle()->getLocalURL();
758 'single-id' => 'pt-watchlist',
759 'text' => $this->msg( 'mywatchlist' )->text(),
761 'active' => ( $href == $pageurl ),
762 'icon' => 'watchlist'
767 * Builds an array with tab definition
769 * @param Title $title Page Where the tab links to
770 * @param string|string[]|MessageSpecifier $message Message or an array of message keys
772 * @param bool $selected Display the tab as selected
773 * @param string $query Query string attached to tab URL
774 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
777 * @param-taint $message tainted
779 public function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
782 $classes[] = 'selected';
785 $services = MediaWikiServices
::getInstance();
786 $linkClass = $services->getLinkRenderer()->getLinkClasses( $title );
787 if ( $checkEdit && !$title->isKnown() ) {
788 // Selected tabs should not show as red link. It doesn't make sense
789 // to show a red link on a page the user has already navigated to.
790 // https://phabricator.wikimedia.org/T294129#7451549
792 // For historic reasons we add to the LI element
794 // but adding the class to the A element is more appropriate.
795 $linkClass .= ' new';
798 if ( $query !== '' ) {
799 $query = 'action=edit&redlink=1&' . $query;
801 $query = 'action=edit&redlink=1';
805 if ( $message instanceof MessageSpecifier
) {
806 $msg = new Message( $message );
808 // wfMessageFallback will nicely accept $message as an array of fallbacks
809 // or just a single key
810 $msg = wfMessageFallback( $message );
812 $msg->setContext( $this->getContext() );
813 if ( !$msg->isDisabled() ) {
814 $text = $msg->text();
816 $text = $services->getLanguageConverterFactory()
817 ->getLanguageConverter( $services->getContentLanguage() )
819 $services->getNamespaceInfo()
820 ->getSubject( $title->getNamespace() )
825 'class' => implode( ' ', $classes ),
827 'href' => $title->getLocalURL( $query ),
830 if ( $linkClass !== '' ) {
831 $result['link-class'] = trim( $linkClass );
838 * Get a message label that skins can override.
840 * @param string $labelMessageKey
841 * @param MessageParam|MessageSpecifier|string|int|float|null $param for the message
844 private function getSkinNavOverrideableLabel( $labelMessageKey, $param = null ) {
845 $skname = $this->skinname
;
846 // The following messages can be used here:
847 // * skin-action-addsection
848 // * skin-action-delete
849 // * skin-action-move
850 // * skin-action-protect
851 // * skin-action-undelete
852 // * skin-action-unprotect
853 // * skin-action-viewdeleted
854 // * skin-action-viewsource
855 // * skin-view-create
856 // * skin-view-create-local
858 // * skin-view-edit-local
859 // * skin-view-foreign
860 // * skin-view-history
862 $msg = wfMessageFallback(
863 "$skname-$labelMessageKey",
864 "skin-$labelMessageKey"
865 )->setContext( $this->getContext() );
868 if ( is_numeric( $param ) ) {
869 $msg->numParams( $param );
871 $msg->params( $param );
878 * @param string $name
879 * @param string|array $urlaction
882 private function makeTalkUrlDetails( $name, $urlaction = '' ) {
883 $title = Title
::newFromTextThrow( $name )->getTalkPage();
885 'href' => $title->getLocalURL( $urlaction ),
886 'exists' => $title->isKnown(),
891 * Get the attributes for the watch link.
892 * @param string $mode Either 'watch' or 'unwatch'
893 * @param Authority $performer
894 * @param Title $title
895 * @param string|null $action
896 * @param bool $onPage
899 private function getWatchLinkAttrs(
900 string $mode, Authority
$performer, Title
$title, ?
string $action, bool $onPage
902 $isWatchMode = $action == 'watch';
903 $class = 'mw-watchlink ' . (
904 $onPage && ( $isWatchMode ||
$action == 'unwatch' ) ?
'selected' : ''
907 $services = MediaWikiServices
::getInstance();
908 $watchlistManager = $services->getWatchlistManager();
909 $watchIcon = $watchlistManager->isWatched( $performer, $title ) ?
'unStar' : 'star';
911 // Modify tooltip and add class identifying the page is temporarily watched, if applicable.
912 if ( $this->getConfig()->get( MainConfigNames
::WatchlistExpiry
) &&
913 $watchlistManager->isTempWatched( $performer, $title )
915 $class .= ' mw-watchlink-temp';
916 $watchIcon = 'halfStar';
918 $watchStore = $services->getWatchedItemStore();
919 $watchedItem = $watchStore->getWatchedItem( $performer->getUser(), $title );
920 $diffInDays = $watchedItem->getExpiryInDays();
921 $watchExpiry = $watchedItem->getExpiry( TS_ISO_8601
);
923 $msgParams = [ $diffInDays ];
924 // Resolves to tooltip-ca-unwatch-expiring message
925 $tooltip = 'ca-unwatch-expiring';
927 // Resolves to tooltip-ca-unwatch-expiring-hours message
928 $tooltip = 'ca-unwatch-expiring-hours';
934 'icon' => $watchIcon,
935 // uses 'watch' or 'unwatch' message
936 'text' => $this->msg( $mode )->text(),
937 'single-id' => $tooltip ??
null,
938 'tooltip-params' => $msgParams ??
null,
939 'href' => $title->getLocalURL( [ 'action' => $mode ] ),
940 // Set a data-mw=interface attribute, which the mediawiki.page.ajax
941 // module will look for to make sure it's a trusted link
944 'mw-expiry' => $watchExpiry,
950 * Run hooks relating to navigation menu data.
951 * Skins should extend this if they want to run opinionated transformations to the data after all
952 * hooks have been run. Note hooks are run in an arbitrary order.
954 * @param SkinTemplate $skin
955 * @param array &$content_navigation representing all menus.
958 protected function runOnSkinTemplateNavigationHooks( SkinTemplate
$skin, &$content_navigation ) {
959 $beforeHookAssociatedPages = array_keys( $content_navigation['associated-pages'] );
960 $beforeHookNamespaces = array_keys( $content_navigation['namespaces'] );
962 // Equiv to SkinTemplateContentActions, run
963 $this->getHookRunner()->onSkinTemplateNavigation__Universal(
964 $skin, $content_navigation );
965 // The new `associatedPages` menu (added in 1.39)
966 // should be backwards compatibile with `namespaces`.
967 // To do this we look for hook modifications to both keys. If modifications are not
968 // made the new key, but are made to the old key, associatedPages reverts back to the
969 // links in the namespaces menu.
970 // It's expected in future that `namespaces` menu will become an alias for `associatedPages`
971 // at which point this code can be removed.
972 $afterHookNamespaces = array_keys( $content_navigation[ 'namespaces' ] );
973 $afterHookAssociatedPages = array_keys( $content_navigation[ 'associated-pages' ] );
974 $associatedPagesChanged = count( array_diff( $afterHookAssociatedPages, $beforeHookAssociatedPages ) ) > 0;
975 $namespacesChanged = count( array_diff( $afterHookNamespaces, $beforeHookNamespaces ) ) > 0;
976 // If some change occurred to namespaces via the hook, revert back to namespaces.
977 if ( !$associatedPagesChanged && $namespacesChanged ) {
978 $content_navigation['associated-pages'] = $content_navigation['namespaces'];
983 * a structured array of links usually used for the tabs in a skin
985 * There are 4 standard sections
986 * namespaces: Used for namespace tabs like special, page, and talk namespaces
987 * views: Used for primary page views like read, edit, history
988 * actions: Used for most extra page actions like deletion, protection, etc...
989 * variants: Used to list the language variants for the page
991 * Each section's value is a key/value array of links for that section.
992 * The links themselves have these common keys:
993 * - class: The css classes to apply to the tab
994 * - text: The text to display on the tab
995 * - href: The href for the tab to point to
996 * - rel: An optional rel= for the tab's link
997 * - redundant: If true the tab will be dropped in skins using content_actions
998 * this is useful for tabs like "Read" which only have meaning in skins that
999 * take special meaning from the grouped structure of content_navigation
1001 * Views also have an extra key which can be used:
1002 * - primary: If this is not true skins like vector may try to hide the tab
1003 * when the user has limited space in their browser window
1005 * content_navigation using code also expects these ids to be present on the
1006 * links, however these are usually automatically generated by SkinTemplate
1007 * itself and are not necessary when using a hook. The only things these may
1008 * matter to are people modifying content_navigation after it's initial creation:
1009 * - id: A "preferred" id, most skins are best off outputting this preferred
1010 * id for best compatibility.
1011 * - tooltiponly: This is set to true for some tabs in cases where the system
1012 * believes that the accesskey should not be added to the tab.
1016 private function buildContentNavigationUrlsInternal() {
1017 if ( $this->contentNavigationCached
) {
1018 return $this->contentNavigationCached
;
1020 // Display tabs for the relevant title rather than always the title itself
1021 $title = $this->getRelevantTitle();
1022 $onPage = $title->equals( $this->getTitle() );
1024 $out = $this->getOutput();
1025 $request = $this->getRequest();
1026 $performer = $this->getAuthority();
1027 $action = $this->getContext()->getActionName();
1028 $services = MediaWikiServices
::getInstance();
1029 $permissionManager = $services->getPermissionManager();
1030 $categoriesData = $this->getCategoryPortletsData( $this->getOutput()->getCategoryLinks() );
1032 $this->addPersonalPageItem( $userPageLink, '-2' );
1034 $content_navigation = $categoriesData +
[
1035 // Modern keys: Please ensure these get unset inside Skin::prepareQuickTemplate
1036 'user-interface-preferences' => [],
1037 'user-page' => $userPageLink,
1038 'user-menu' => $this->buildPersonalUrls( false ),
1039 'notifications' => [],
1040 'associated-pages' => [],
1048 $associatedPages = [];
1050 $userCanRead = $this->getAuthority()->probablyCan( 'read', $title );
1052 // Checks if page is some kind of content
1053 if ( $title->canExist() ) {
1054 // Gets page objects for the associatedPages namespaces
1055 $subjectPage = $title->getSubjectPage();
1056 $talkPage = $title->getTalkPage();
1058 // Determines if this is a talk page
1059 $isTalk = $title->isTalkPage();
1061 // Generates XML IDs from namespace names
1062 $subjectId = $title->getNamespaceKey( '' );
1064 if ( $subjectId == 'main' ) {
1067 $talkId = "{$subjectId}_talk";
1070 // Adds namespace links
1071 if ( $subjectId === 'user' ) {
1072 $subjectMsg = $this->msg( 'nstab-user', $subjectPage->getRootText() );
1074 // The following messages are used here:
1080 // * nstab-mediawiki
1084 // * nstab-<subject namespace key>
1085 $subjectMsg = [ "nstab-$subjectId" ];
1087 if ( $subjectPage->isMainPage() ) {
1088 array_unshift( $subjectMsg, 'nstab-mainpage' );
1092 $associatedPages[$subjectId] = $this->tabAction(
1093 $subjectPage, $subjectMsg, !$isTalk, '', $userCanRead
1095 $associatedPages[$subjectId]['context'] = 'subject';
1096 // Use the following messages if defined or talk if not:
1097 // * nstab-talk, nstab-user_talk, nstab-media_talk, nstab-project_talk
1098 // * nstab-image_talk, nstab-mediawiki_talk, nstab-template_talk
1099 // * nstab-help_talk, nstab-category_talk,
1100 // * nstab-<subject namespace key>_talk
1101 $associatedPages[$talkId] = $this->tabAction(
1102 $talkPage, [ "nstab-$talkId", "talk" ], $isTalk, '', $userCanRead
1104 $associatedPages[$talkId]['context'] = 'talk';
1106 if ( $userCanRead ) {
1107 // Adds "view" view link
1108 if ( $title->isKnown() ) {
1109 $content_navigation['views']['view'] = $this->tabAction(
1110 $isTalk ?
$talkPage : $subjectPage,
1112 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
1114 $content_navigation['views']['view']['text'] = $this->getSkinNavOverrideableLabel(
1117 // signal to hide this from simple content_actions
1118 $content_navigation['views']['view']['redundant'] = true;
1121 $page = $this->canUseWikiPage() ?
$this->getWikiPage() : false;
1122 $isRemoteContent = $page && !$page->isLocal();
1124 // If it is a non-local file, show a link to the file in its own repository
1125 // @todo abstract this for remote content that isn't a file
1126 if ( $isRemoteContent ) {
1127 $content_navigation['views']['view-foreign'] = [
1129 'text' => $this->getSkinNavOverrideableLabel(
1130 'view-foreign', $page->getWikiDisplayName()
1132 'href' => $page->getSourceURL(),
1137 // Checks if user can edit the current page if it exists or create it otherwise
1138 if ( $this->getAuthority()->probablyCan( 'edit', $title ) ) {
1139 // Builds CSS class for talk page links
1140 $isTalkClass = $isTalk ?
' istalk' : '';
1141 // Whether the user is editing the page
1142 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
1143 $isRedirect = $page && $page->isRedirect();
1144 // Whether to show the "Add a new section" tab
1145 // Checks if this is a current rev of talk page and is not forced to be hidden
1146 $showNewSection = !$out->forceHideNewSectionLink()
1147 && ( ( $isTalk && !$isRedirect && $out->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
1148 $section = $request->getVal( 'section' );
1150 if ( $title->exists()
1151 ||
( $title->inNamespace( NS_MEDIAWIKI
)
1152 && $title->getDefaultMessageText() !== false
1155 $msgKey = $isRemoteContent ?
'edit-local' : 'edit';
1157 $msgKey = $isRemoteContent ?
'create-local' : 'create';
1159 $content_navigation['views']['edit'] = [
1160 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
1164 'text' => $this->getSkinNavOverrideableLabel(
1167 'single-id' => "ca-$msgKey",
1168 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1169 'primary' => !$isRemoteContent, // don't collapse this in vector
1173 if ( $showNewSection ) {
1174 // Adds new section link
1175 // $content_navigation['actions']['addsection']
1176 $content_navigation['views']['addsection'] = [
1177 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
1178 'text' => $this->getSkinNavOverrideableLabel(
1181 'href' => $title->getLocalURL( 'action=edit§ion=new' )
1184 // Checks if the page has some kind of viewable source content
1185 } elseif ( $title->hasSourceText() ) {
1186 // Adds view source view link
1187 $content_navigation['views']['viewsource'] = [
1188 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
1189 'text' => $this->getSkinNavOverrideableLabel(
1192 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1193 'primary' => true, // don't collapse this in vector
1197 // Checks if the page exists
1198 if ( $title->exists() ) {
1199 // Adds history view link
1200 $content_navigation['views']['history'] = [
1201 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1202 'text' => $this->getSkinNavOverrideableLabel(
1205 'href' => $title->getLocalURL( 'action=history' ),
1208 if ( $this->getAuthority()->probablyCan( 'delete', $title ) ) {
1209 $content_navigation['actions']['delete'] = [
1211 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1212 'text' => $this->getSkinNavOverrideableLabel(
1215 'href' => $title->getLocalURL( [
1216 'action' => 'delete',
1217 'oldid' => $out->getRevisionId(),
1222 if ( $this->getAuthority()->probablyCan( 'move', $title ) ) {
1223 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1224 $content_navigation['actions']['move'] = [
1225 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1226 'text' => $this->getSkinNavOverrideableLabel(
1230 'href' => $moveTitle->getLocalURL()
1234 // article doesn't exist or is deleted
1235 if ( $this->getAuthority()->probablyCan( 'deletedhistory', $title ) ) {
1236 $n = $title->getDeletedEditsCount();
1238 $undelTitle = SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
1239 // If the user can't undelete but can view deleted
1240 // history show them a "View .. deleted" tab instead.
1241 $msgKey = $this->getAuthority()->probablyCan( 'undelete', $title ) ?
1242 'undelete' : 'viewdeleted';
1243 $content_navigation['actions']['undelete'] = [
1244 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1245 'text' => $this->getSkinNavOverrideableLabel(
1246 "action-$msgKey", $n
1249 'href' => $undelTitle->getLocalURL()
1255 $restrictionStore = $services->getRestrictionStore();
1256 if ( $this->getAuthority()->probablyCan( 'protect', $title ) &&
1257 $restrictionStore->listApplicableRestrictionTypes( $title ) &&
1258 $permissionManager->getNamespaceRestrictionLevels(
1259 $title->getNamespace(),
1260 $performer->getUser()
1263 $isProtected = $restrictionStore->isProtected( $title );
1264 $mode = $isProtected ?
'unprotect' : 'protect';
1265 $content_navigation['actions'][$mode] = [
1266 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1267 'text' => $this->getSkinNavOverrideableLabel(
1270 'icon' => $isProtected ?
'unLock' : 'lock',
1271 'href' => $title->getLocalURL( "action=$mode" )
1275 if ( $this->loggedin
&& $this->getAuthority()
1276 ->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' )
1279 * The following actions use messages which, if made particular to
1280 * the any specific skins, would break the Ajax code which makes this
1281 * action happen entirely inline. OutputPage::getJSVars
1282 * defines a set of messages in a javascript object - and these
1283 * messages are assumed to be global for all skins. Without making
1284 * a change to that procedure these messages will have to remain as
1285 * the global versions.
1287 $mode = MediaWikiServices
::getInstance()->getWatchlistManager()
1288 ->isWatched( $performer, $title ) ?
'unwatch' : 'watch';
1290 // Add the watch/unwatch link.
1291 $content_navigation['actions'][$mode] = $this->getWatchLinkAttrs(
1301 // Add language variants
1302 $languageConverterFactory = MediaWikiServices
::getInstance()->getLanguageConverterFactory();
1304 if ( $userCanRead && !$languageConverterFactory->isConversionDisabled() ) {
1305 $pageLang = $title->getPageLanguage();
1306 $converter = $languageConverterFactory
1307 ->getLanguageConverter( $pageLang );
1308 // Checks that language conversion is enabled and variants exist
1309 // And if it is not in the special namespace
1310 if ( $converter->hasVariants() ) {
1311 // Gets list of language variants
1312 $variants = $converter->getVariants();
1313 // Gets preferred variant (note that user preference is
1314 // only possible for wiki content language variant)
1315 $preferred = $converter->getPreferredVariant();
1316 if ( $action === 'view' ) {
1317 $params = $request->getQueryValues();
1318 unset( $params['title'] );
1322 // Loops over each variant
1323 foreach ( $variants as $code ) {
1324 // Gets variant name from language code
1325 $varname = $pageLang->getVariantname( $code );
1326 // Appends variant link
1327 $content_navigation['variants'][] = [
1328 'class' => ( $code == $preferred ) ?
'selected' : false,
1330 'href' => $title->getLocalURL( [ 'variant' => $code ] +
$params ),
1331 'lang' => LanguageCode
::bcp47( $code ),
1332 'hreflang' => LanguageCode
::bcp47( $code ),
1337 $namespaces = $associatedPages;
1339 // If it's not content, and a request URL is set it's got to be a special page
1341 $url = $request->getRequestURL();
1342 } catch ( MWException
$e ) {
1345 $namespaces['special'] = [
1346 'class' => 'selected',
1347 'text' => $this->msg( 'nstab-special' )->text(),
1348 'href' => $url, // @see: T4457, T4510
1349 'context' => 'subject'
1351 $associatedPages +
= $this->getSpecialPageAssociatedNavigationLinks( $title );
1354 $content_navigation['namespaces'] = $namespaces;
1355 $content_navigation['associated-pages'] = $associatedPages;
1356 $this->runOnSkinTemplateNavigationHooks( $this, $content_navigation );
1358 // Setup xml ids and tooltip info
1359 foreach ( $content_navigation as $section => &$links ) {
1360 foreach ( $links as $key => &$link ) {
1361 // Allow links to set their own id for backwards compatibility reasons.
1362 if ( isset( $link['id'] ) ||
isset( $link['html' ] ) ) {
1366 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1367 $xmlID = 'ca-nstab-' . $xmlID;
1368 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1370 $link['rel'] = 'discussion';
1371 } elseif ( $section == 'variants' ) {
1372 $xmlID = 'ca-varlang-' . $xmlID;
1373 // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
1374 $link['class'] .= ' ca-variants-' . $link['lang'];
1376 $xmlID = 'ca-' . $xmlID;
1378 $link['id'] = $xmlID;
1382 # We don't want to give the watch tab an accesskey if the
1383 # page is being edited, because that conflicts with the
1384 # accesskey on the watch checkbox. We also don't want to
1385 # give the edit tab an accesskey, because that's fairly
1386 # superfluous and conflicts with an accesskey (Ctrl-E) often
1387 # used for editing in Safari.
1388 if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
1389 if ( isset( $content_navigation['views']['edit'] ) ) {
1390 $content_navigation['views']['edit']['tooltiponly'] = true;
1392 if ( isset( $content_navigation['actions']['watch'] ) ) {
1393 $content_navigation['actions']['watch']['tooltiponly'] = true;
1395 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1396 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1400 $this->contentNavigationCached
= $content_navigation;
1401 return $content_navigation;
1405 * Return a list of pages that have been marked as related to/associated with
1406 * the special page for display.
1408 * @param Title $title
1411 private function getSpecialPageAssociatedNavigationLinks( Title
$title ): array {
1412 $specialAssociatedNavigationLinks = [];
1413 $specialFactory = MediaWikiServices
::getInstance()->getSpecialPageFactory();
1414 $special = $specialFactory->getPage( $title->getText() );
1415 if ( $special === null ) {
1416 // not a valid special page
1419 $special->setContext( $this );
1420 $associatedNavigationLinks = $special->getAssociatedNavigationLinks();
1421 // If there are no subpages, we should not render
1422 if ( count( $associatedNavigationLinks ) === 0 ) {
1426 foreach ( $associatedNavigationLinks as $i => $relatedTitleText ) {
1427 $relatedTitle = Title
::newFromText( $relatedTitleText );
1428 $special = $specialFactory->getPage( $relatedTitle->getText() );
1429 if ( $special === null ) {
1430 $text = $relatedTitle->getText();
1432 $text = $special->getShortDescription( $relatedTitle->getSubpageText() );
1434 $specialAssociatedNavigationLinks['special-specialAssociatedNavigationLinks-link-' . $i ] = [
1436 'href' => $relatedTitle->getLocalURL(),
1437 'class' => $relatedTitle->fixSpecialName()->equals( $title->fixSpecialName() ) ?
'selected' : '',
1440 return $specialAssociatedNavigationLinks;
1444 * an array of edit links by default used for the tabs
1445 * @param array $content_navigation
1448 private function buildContentActionUrls( $content_navigation ) {
1449 // content_actions has been replaced with content_navigation for backwards
1450 // compatibility and also for skins that just want simple tabs content_actions
1451 // is now built by flattening the content_navigation arrays into one
1453 $content_actions = [];
1455 foreach ( $content_navigation as $links ) {
1456 foreach ( $links as $key => $value ) {
1457 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1458 // Redundant tabs are dropped from content_actions
1462 // content_actions used to have ids built using the "ca-$key" pattern
1463 // so the xmlID based id is much closer to the actual $key that we want
1464 // for that reason we'll just strip out the ca- if present and use
1465 // the latter potion of the "id" as the $key
1466 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1467 $key = substr( $value['id'], 3 );
1470 if ( isset( $content_actions[$key] ) ) {
1471 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1472 "content_navigation into content_actions." );
1476 $content_actions[$key] = $value;
1480 return $content_actions;
1484 * Insert legacy menu items from content navigation into the personal toolbar.
1488 * @param array $contentNavigation
1491 final protected function injectLegacyMenusIntoPersonalTools(
1492 array $contentNavigation
1494 $userMenu = $contentNavigation['user-menu'] ??
[];
1495 // userpage is only defined for logged-in users, and wfArrayInsertAfter requires the
1496 // $after parameter to be a known key in the array.
1497 if ( isset( $contentNavigation['user-menu']['userpage'] ) && isset( $contentNavigation['notifications'] ) ) {
1498 $userMenu = wfArrayInsertAfter(
1500 $contentNavigation['notifications'],
1504 if ( isset( $contentNavigation['user-interface-preferences'] ) ) {
1506 $contentNavigation['user-interface-preferences'],
1514 * Build the personal urls array.
1518 * @param array $contentNavigation
1521 private function makeSkinTemplatePersonalUrls(
1522 array $contentNavigation
1524 if ( isset( $contentNavigation['user-menu'] ) ) {
1525 return $this->injectLegacyMenusIntoPersonalTools( $contentNavigation );
1532 * @param array $attrs (optional) will be passed to tooltipAndAccesskeyAttribs
1533 * and decorate the resulting input
1534 * @return string of HTML input
1536 public function makeSearchInput( $attrs = [] ) {
1537 // It's possible that getTemplateData might be calling
1538 // Skin::makeSearchInput. To avoid infinite recursion create a
1539 // new instance of the search component here.
1540 $searchBox = $this->getComponent( 'search-box' );
1541 $data = $searchBox->getTemplateData();
1543 return Html
::element( 'input',
1544 $data[ 'array-input-attributes' ] +
$attrs
1550 * @param string $mode representing the type of button wanted
1551 * either `go`, `fulltext` or `image`
1552 * @param array $attrs (optional)
1553 * @return string of HTML button
1555 final public function makeSearchButton( $mode, $attrs = [] ) {
1556 // It's possible that getTemplateData might be calling
1557 // Skin::makeSearchInput. To avoid infinite recursion create a
1558 // new instance of the search component here.
1559 $searchBox = $this->getComponent( 'search-box' );
1560 $searchData = $searchBox->getTemplateData();
1564 $attrs['value'] ??
= $this->msg( 'searcharticle' )->text();
1565 return Html
::element(
1568 $searchData[ 'array-button-go-attributes' ], $attrs
1572 $attrs['value'] ??
= $this->msg( 'searchbutton' )->text();
1573 return Html
::element(
1576 $searchData[ 'array-button-fulltext-attributes' ], $attrs
1584 $buttonAttrs = array_merge(
1586 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1589 unset( $buttonAttrs['src'] );
1590 unset( $buttonAttrs['alt'] );
1591 unset( $buttonAttrs['width'] );
1592 unset( $buttonAttrs['height'] );
1594 'src' => $attrs['src'],
1595 'alt' => $attrs['alt'] ??
$this->msg( 'searchbutton' )->text(),
1596 'width' => $attrs['width'] ??
null,
1597 'height' => $attrs['height'] ??
null,
1599 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1601 throw new InvalidArgumentException( 'Unknown mode passed to ' . __METHOD__
);
1608 private function isSpecialContributeShowable(): bool {
1609 return ContributeFactory
::isEnabledOnCurrentSkin(
1611 $this->getConfig()->get( MainConfigNames
::SpecialContributeSkinsEnabled
)
1616 * @param array &$personal_urls
1617 * @param string $key
1618 * @param string|null $userName
1619 * @param bool $active
1623 private function makeContributionsLink(
1624 array &$personal_urls,
1626 ?
string $userName = null,
1627 bool $active = false
1629 $isSpecialContributeShowable = $this->isSpecialContributeShowable();
1630 $subpage = $userName ??
false;
1631 $user = $this->getUser();
1632 // If the "Contribute" page is showable and the user is anon. or has no edit count,
1633 // direct them to the "Contribute" page instead of the "Contributions" or "Mycontributions" pages.
1635 // a. For logged-in users: In wikis where the "Contribute" page is enabled, we only want
1636 // to navigate logged-in users to the "Contribute", when they have done no edits. Otherwise, we
1637 // want to navigate them to the "Mycontributions" page to easily access their edits/contributions.
1638 // Currently, the "Contribute" page is used as target for all logged-in users.
1639 // b. For anon. users: In wikis where the "Contribute" page is enabled, we still navigate the
1640 // anonymous users to the "Contribute" page.
1642 if ( $isSpecialContributeShowable && (int)$user->getEditCount() === 0 ) {
1643 $href = SkinComponentUtils
::makeSpecialUrlSubpage(
1647 $personal_urls['contribute'] = [
1648 'text' => $this->msg( 'contribute' )->text(),
1650 'active' => $href == $this->getTitle()->getLocalURL(),
1654 $href = SkinComponentUtils
::makeSpecialUrlSubpage(
1655 $subpage !== false ?
'Contributions' : 'Mycontributions',
1658 $personal_urls[$key] = [
1659 'text' => $this->msg( $key )->text(),
1661 'active' => $active,
1662 'icon' => 'userContributions'
1665 return $personal_urls;