3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\Auth\AuthManager
;
22 use MediaWiki\MediaWikiServices
;
25 * Base class for template-based skins.
27 * Template-filler skin base class
28 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
29 * Based on Brion's smarty skin
30 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
32 * @todo Needs some serious refactoring into functions that correspond
33 * to the computations individual esi snippets need. Most importantly no body
34 * parsing for most of those of course.
38 class SkinTemplate
extends Skin
{
40 * @var string Name of our skin, it probably needs to be all lower case.
41 * Child classes should override the default.
43 public $skinname = 'monobook';
46 * @var string For QuickTemplate, the name of the subclass which will
47 * actually fill the template. Child classes should override the default.
49 public $template = QuickTemplate
::class;
57 public $userpageUrlDetails;
60 * Create the template engine object; we feed it a bunch of data
61 * and eventually it spits out some HTML. Should have interface
62 * roughly equivalent to PHPTAL 0.7.
64 * @param string $classname
65 * @param bool|string $repository Subdirectory where we keep template files
66 * @param bool|string $cache_dir
67 * @return QuickTemplate
70 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
71 return new $classname( $this->getConfig() );
75 * Generates array of language links for the current page
79 public function getLanguages() {
80 global $wgHideInterlanguageLinks;
81 if ( $wgHideInterlanguageLinks ) {
85 $userLang = $this->getLanguage();
88 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
89 $class = 'interlanguage-link interwiki-' . explode( ':', $languageLinkText, 2 )[0];
91 $languageLinkTitle = Title
::newFromText( $languageLinkText );
92 if ( $languageLinkTitle ) {
93 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
94 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
96 if ( strval( $ilLangName ) === '' ) {
97 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
98 if ( !$ilDisplayTextMsg->isDisabled() ) {
99 // Use custom MW message for the display text
100 $ilLangName = $ilDisplayTextMsg->text();
102 // Last resort: fallback to the language link target
103 $ilLangName = $languageLinkText;
106 // Use the language autonym as display text
107 $ilLangName = $this->formatLanguageName( $ilLangName );
110 // CLDR extension or similar is required to localize the language name;
111 // otherwise we'll end up with the autonym again.
112 $ilLangLocalName = Language
::fetchLanguageName(
117 $languageLinkTitleText = $languageLinkTitle->getText();
118 if ( $ilLangLocalName === '' ) {
119 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
120 if ( !$ilFriendlySiteName->isDisabled() ) {
121 if ( $languageLinkTitleText === '' ) {
122 $ilTitle = wfMessage(
123 'interlanguage-link-title-nonlangonly',
124 $ilFriendlySiteName->text()
127 $ilTitle = wfMessage(
128 'interlanguage-link-title-nonlang',
129 $languageLinkTitleText,
130 $ilFriendlySiteName->text()
134 // we have nothing friendly to put in the title, so fall back to
135 // displaying the interlanguage link itself in the title text
136 // (similar to what is done in page content)
137 $ilTitle = $languageLinkTitle->getInterwiki() .
138 ":$languageLinkTitleText";
140 } elseif ( $languageLinkTitleText === '' ) {
141 $ilTitle = wfMessage(
142 'interlanguage-link-title-langonly',
146 $ilTitle = wfMessage(
147 'interlanguage-link-title',
148 $languageLinkTitleText,
153 $ilInterwikiCodeBCP47 = LanguageCode
::bcp47( $ilInterwikiCode );
155 'href' => $languageLinkTitle->getFullURL(),
156 'text' => $ilLangName,
159 'link-class' => 'interlanguage-link-target',
160 'lang' => $ilInterwikiCodeBCP47,
161 'hreflang' => $ilInterwikiCodeBCP47,
164 'SkinTemplateGetLanguageLink',
165 [ &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() ]
167 $languageLinks[] = $languageLink;
171 return $languageLinks;
174 protected function setupTemplateForOutput() {
175 $request = $this->getRequest();
176 $user = $this->getUser();
177 $title = $this->getTitle();
179 $tpl = $this->setupTemplate( $this->template
, 'skins' );
181 $this->thispage
= $title->getPrefixedDBkey();
182 $this->titletxt
= $title->getPrefixedText();
183 $this->userpage
= $user->getUserPage()->getPrefixedText();
185 if ( !$request->wasPosted() ) {
186 $query = $request->getValues();
187 unset( $query['title'] );
188 unset( $query['returnto'] );
189 unset( $query['returntoquery'] );
191 $this->thisquery
= wfArrayToCgi( $query );
192 $this->loggedin
= $user->isLoggedIn();
193 $this->username
= $user->getName();
195 if ( $this->loggedin
) {
196 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
198 # This won't be used in the standard skins, but we define it to preserve the interface
199 # To save time, we check for existence
200 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
207 * initialize various variables and generate the template
209 * @param OutputPage|null $out
211 function outputPage( OutputPage
$out = null ) {
212 Profiler
::instance()->setTemplated( true );
215 if ( $out !== null ) {
216 // Deprecated since 1.20, note added in 1.25
217 wfDeprecated( __METHOD__
, '1.25' );
218 $oldContext = $this->getContext();
219 $this->setContext( $out->getContext() );
222 $out = $this->getOutput();
224 $this->initPage( $out );
225 $tpl = $this->prepareQuickTemplate();
227 $res = $tpl->execute();
229 // result may be an error
230 $this->printOrError( $res );
233 $this->setContext( $oldContext );
238 * Wrap the body text with language information and identifiable element
240 * @param Title $title
241 * @param string $html body text
242 * @return string html
244 protected function wrapHTML( $title, $html ) {
245 # An ID that includes the actual body text; without categories, contentSub, ...
246 $realBodyAttribs = [ 'id' => 'mw-content-text' ];
248 # Add a mw-content-ltr/rtl class to be able to style based on text
249 # direction when the content is different from the UI language (only
251 # Most information on special pages and file pages is in user language,
252 # rather than content language, so those will not get this
253 if ( Action
::getActionName( $this ) === 'view' &&
254 ( !$title->inNamespaces( NS_SPECIAL
, NS_FILE
) ||
$title->isRedirect() ) ) {
255 $pageLang = $title->getPageViewLanguage();
256 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
257 $realBodyAttribs['dir'] = $pageLang->getDir();
258 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
261 return Html
::rawElement( 'div', $realBodyAttribs, $html );
265 * initialize various variables and generate the template
268 * @return QuickTemplate The template to be executed by outputPage
270 protected function prepareQuickTemplate() {
271 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
272 $wgSitename, $wgLogo, $wgMaxCredits,
273 $wgShowCreditsIfMax, $wgArticlePath,
274 $wgScriptPath, $wgServer;
276 $title = $this->getTitle();
277 $request = $this->getRequest();
278 $out = $this->getOutput();
279 $tpl = $this->setupTemplateForOutput();
281 $tpl->set( 'title', $out->getPageTitle() );
282 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
283 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
285 $tpl->set( 'thispage', $this->thispage
);
286 $tpl->set( 'titleprefixeddbkey', $this->thispage
);
287 $tpl->set( 'titletext', $title->getText() );
288 $tpl->set( 'articleid', $title->getArticleID() );
290 $tpl->set( 'isarticle', $out->isArticle() );
292 $subpagestr = $this->subPageSubtitle();
293 if ( $subpagestr !== '' ) {
294 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
296 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
298 $undelete = $this->getUndeleteLink();
299 if ( $undelete === '' ) {
300 $tpl->set( 'undelete', '' );
302 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
305 $tpl->set( 'catlinks', $this->getCategories() );
306 if ( $out->isSyndicated() ) {
308 foreach ( $out->getSyndicationLinks() as $format => $link ) {
310 // Messages: feed-atom, feed-rss
311 'text' => $this->msg( "feed-$format" )->text(),
315 $tpl->set( 'feeds', $feeds );
317 $tpl->set( 'feeds', false );
320 $tpl->set( 'mimetype', $wgMimeType );
321 $tpl->set( 'jsmimetype', $wgJsMimeType );
322 $tpl->set( 'charset', 'UTF-8' );
323 $tpl->set( 'wgScript', $wgScript );
324 $tpl->set( 'skinname', $this->skinname
);
325 $tpl->set( 'skinclass', static::class );
326 $tpl->set( 'skin', $this );
327 $tpl->set( 'stylename', $this->stylename
);
328 $tpl->set( 'printable', $out->isPrintable() );
329 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
330 $tpl->set( 'loggedin', $this->loggedin
);
331 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
332 $tpl->set( 'searchaction', $this->escapeSearchLink() );
333 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
334 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
335 $tpl->set( 'stylepath', $wgStylePath );
336 $tpl->set( 'articlepath', $wgArticlePath );
337 $tpl->set( 'scriptpath', $wgScriptPath );
338 $tpl->set( 'serverurl', $wgServer );
339 $tpl->set( 'logopath', $wgLogo );
340 $tpl->set( 'sitename', $wgSitename );
342 $userLang = $this->getLanguage();
343 $userLangCode = $userLang->getHtmlCode();
344 $userLangDir = $userLang->getDir();
346 $tpl->set( 'lang', $userLangCode );
347 $tpl->set( 'dir', $userLangDir );
348 $tpl->set( 'rtl', $userLang->isRTL() );
350 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
351 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
352 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
353 $tpl->set( 'userpage', $this->userpage
);
354 $tpl->set( 'userpageurl', $this->userpageUrlDetails
['href'] );
355 $tpl->set( 'userlang', $userLangCode );
357 // Users can have their language set differently than the
358 // content of the wiki. For these users, tell the web browser
359 // that interface elements are in a different language.
360 $tpl->set( 'userlangattributes', '' );
361 $tpl->set( 'specialpageattributes', '' ); # obsolete
362 // Used by VectorBeta to insert HTML before content but after the
363 // heading for the page title. Defaults to empty string.
364 $tpl->set( 'prebodyhtml', '' );
366 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
367 $escUserlang = htmlspecialchars( $userLangCode );
368 $escUserdir = htmlspecialchars( $userLangDir );
369 // Attributes must be in double quotes because htmlspecialchars() doesn't
370 // escape single quotes
371 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
372 $tpl->set( 'userlangattributes', $attrs );
375 $tpl->set( 'newtalk', $this->getNewtalks() );
376 $tpl->set( 'logo', $this->logoText() );
378 $tpl->set( 'copyright', false );
380 $tpl->set( 'viewcount', false );
381 $tpl->set( 'lastmod', false );
382 $tpl->set( 'credits', false );
383 $tpl->set( 'numberofwatchingusers', false );
384 if ( $out->isArticle() && $title->exists() ) {
385 if ( $this->isRevisionCurrent() ) {
386 if ( $wgMaxCredits != 0 ) {
387 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
388 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
390 $tpl->set( 'lastmod', $this->lastModified() );
393 $tpl->set( 'copyright', $this->getCopyright() );
396 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
397 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
398 $tpl->set( 'disclaimer', $this->disclaimerLink() );
399 $tpl->set( 'privacy', $this->privacyLink() );
400 $tpl->set( 'about', $this->aboutLink() );
402 $tpl->set( 'footerlinks', [
405 'numberofwatchingusers',
416 global $wgFooterIcons;
417 $tpl->set( 'footericons', $wgFooterIcons );
418 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
419 if ( count( $footerIconsBlock ) > 0 ) {
420 foreach ( $footerIconsBlock as &$footerIcon ) {
421 if ( isset( $footerIcon['src'] ) ) {
422 if ( !isset( $footerIcon['width'] ) ) {
423 $footerIcon['width'] = 88;
425 if ( !isset( $footerIcon['height'] ) ) {
426 $footerIcon['height'] = 31;
431 unset( $tpl->data
['footericons'][$footerIconsKey] );
435 $tpl->set( 'indicators', $out->getIndicators() );
437 $tpl->set( 'sitenotice', $this->getSiteNotice() );
438 $tpl->set( 'printfooter', $this->printSource() );
439 // Wrap the bodyText with #mw-content-text element
440 $out->mBodytext
= $this->wrapHTML( $title, $out->mBodytext
);
441 $tpl->set( 'bodytext', $out->mBodytext
);
443 $language_urls = $this->getLanguages();
444 if ( count( $language_urls ) ) {
445 $tpl->set( 'language_urls', $language_urls );
447 $tpl->set( 'language_urls', false );
451 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
452 $content_navigation = $this->buildContentNavigationUrls();
453 $content_actions = $this->buildContentActionUrls( $content_navigation );
454 $tpl->set( 'content_navigation', $content_navigation );
455 $tpl->set( 'content_actions', $content_actions );
457 $tpl->set( 'sidebar', $this->buildSidebar() );
458 $tpl->set( 'nav_urls', $this->buildNavUrls() );
460 // Do this last in case hooks above add bottom scripts
461 $tpl->set( 'bottomscripts', $this->bottomScripts() );
463 // Set the head scripts near the end, in case the above actions resulted in added scripts
464 $tpl->set( 'headelement', $out->headElement( $this ) );
466 $tpl->set( 'debug', '' );
467 $tpl->set( 'debughtml', $this->generateDebugHTML() );
468 $tpl->set( 'reporttime', wfReportTime( $out->getCSPNonce() ) );
470 // Avoid PHP 7.1 warning of passing $this by reference
471 $skinTemplate = $this;
472 // original version by hansm
473 if ( !Hooks
::run( 'SkinTemplateOutputPageBeforeExec', [ &$skinTemplate, &$tpl ] ) ) {
474 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
477 // Set the bodytext to another key so that skins can just output it on its own
478 // and output printfooter and debughtml separately
479 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
481 // Append printfooter and debughtml onto bodytext so that skins that
482 // were already using bodytext before they were split out don't suddenly
483 // start not outputting information.
484 $tpl->data
['bodytext'] .= Html
::rawElement(
486 [ 'class' => 'printfooter' ],
487 "\n{$tpl->data['printfooter']}"
489 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
491 // allow extensions adding stuff after the page content.
492 // See Skin::afterContentHook() for further documentation.
493 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
499 * Get the HTML for the p-personal list
502 public function getPersonalToolsList() {
503 return $this->makePersonalToolsList();
507 * Get the HTML for the personal tools list
511 * @param array|null $personalTools
512 * @param array $options
515 public function makePersonalToolsList( $personalTools = null, $options = [] ) {
516 $tpl = $this->setupTemplateForOutput();
517 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
520 if ( $personalTools === null ) {
521 $personalTools = $tpl->getPersonalTools();
524 foreach ( $personalTools as $key => $item ) {
525 $html .= $tpl->makeListItem( $key, $item, $options );
532 * Get personal tools for the user
536 * @return array Array of personal tools
538 public function getStructuredPersonalTools() {
539 $tpl = $this->setupTemplateForOutput();
540 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
542 return $tpl->getPersonalTools();
546 * Format language name for use in sidebar interlanguage links list.
547 * By default it is capitalized.
549 * @param string $name Language name, e.g. "English" or "español"
553 function formatLanguageName( $name ) {
554 return $this->getLanguage()->ucfirst( $name );
558 * Output the string, or print error message if it's
559 * an error object of the appropriate type.
560 * For the base class, assume strings all around.
565 function printOrError( $str ) {
570 * Output a boolean indicating if buildPersonalUrls should output separate
571 * login and create account links or output a combined link
572 * By default we simply return a global config setting that affects most skins
573 * This is setup as a method so that like with $wgLogo and getLogo() a skin
574 * can override this setting and always output one or the other if it has
575 * a reason it can't output one of the two modes.
578 function useCombinedLoginLink() {
579 global $wgUseCombinedLoginLink;
580 return $wgUseCombinedLoginLink;
584 * build array of urls for personal toolbar
587 protected function buildPersonalUrls() {
588 $title = $this->getTitle();
589 $request = $this->getRequest();
590 $pageurl = $title->getLocalURL();
591 $authManager = AuthManager
::singleton();
593 /* set up the default links for the personal toolbar */
596 # Due to T34276, if a user does not have read permissions,
597 # $this->getTitle() will just give Special:Badtitle, which is
598 # not especially useful as a returnto parameter. Use the title
599 # from the request instead, if there was one.
600 if ( $this->getUser()->isAllowed( 'read' ) ) {
601 $page = $this->getTitle();
603 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
605 $page = $request->getVal( 'returnto', $page );
607 if ( strval( $page ) !== '' ) {
608 $a['returnto'] = $page;
609 $query = $request->getVal( 'returntoquery', $this->thisquery
);
610 if ( $query != '' ) {
611 $a['returntoquery'] = $query;
615 $returnto = wfArrayToCgi( $a );
616 if ( $this->loggedin
) {
617 $personal_urls['userpage'] = [
618 'text' => $this->username
,
619 'href' => &$this->userpageUrlDetails
['href'],
620 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
621 'exists' => $this->userpageUrlDetails
['exists'],
622 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
625 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
626 $personal_urls['mytalk'] = [
627 'text' => $this->msg( 'mytalk' )->text(),
628 'href' => &$usertalkUrlDetails['href'],
629 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
630 'exists' => $usertalkUrlDetails['exists'],
631 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
633 $href = self
::makeSpecialUrl( 'Preferences' );
634 $personal_urls['preferences'] = [
635 'text' => $this->msg( 'mypreferences' )->text(),
637 'active' => ( $href == $pageurl )
640 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
641 $href = self
::makeSpecialUrl( 'Watchlist' );
642 $personal_urls['watchlist'] = [
643 'text' => $this->msg( 'mywatchlist' )->text(),
645 'active' => ( $href == $pageurl )
649 # We need to do an explicit check for Special:Contributions, as we
650 # have to match both the title, and the target, which could come
651 # from request values (Special:Contributions?target=Jimbo_Wales)
652 # or be specified in "sub page" form
653 # (Special:Contributions/Jimbo_Wales). The plot
654 # thickens, because the Title object is altered for special pages,
655 # so it doesn't contain the original alias-with-subpage.
656 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
657 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
658 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
659 $active = $spName == 'Contributions'
660 && ( ( $spPar && $spPar == $this->username
)
661 ||
$request->getText( 'target' ) == $this->username
);
666 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
667 $personal_urls['mycontris'] = [
668 'text' => $this->msg( 'mycontris' )->text(),
673 // if we can't set the user, we can't unset it either
674 if ( $request->getSession()->canSetUser() ) {
675 $personal_urls['logout'] = [
676 'text' => $this->msg( 'pt-userlogout' )->text(),
677 'href' => self
::makeSpecialUrl( 'Userlogout',
678 // userlogout link must always contain an & character, otherwise we might not be able
679 // to detect a buggy precaching proxy (T19790)
680 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto ),
685 $useCombinedLoginLink = $this->useCombinedLoginLink();
686 if ( !$authManager->canCreateAccounts() ||
!$authManager->canAuthenticateNow() ) {
687 // don't show combined login/signup link if one of those is actually not available
688 $useCombinedLoginLink = false;
691 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
692 ?
'nav-login-createaccount'
696 'text' => $this->msg( $loginlink )->text(),
697 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
698 'active' => $title->isSpecial( 'Userlogin' )
699 ||
$title->isSpecial( 'CreateAccount' ) && $useCombinedLoginLink,
701 $createaccount_url = [
702 'text' => $this->msg( 'pt-createaccount' )->text(),
703 'href' => self
::makeSpecialUrl( 'CreateAccount', $returnto ),
704 'active' => $title->isSpecial( 'CreateAccount' ),
707 // No need to show Talk and Contributions to anons if they can't contribute!
708 if ( User
::groupHasPermission( '*', 'edit' ) ) {
709 // Because of caching, we can't link directly to the IP talk and
710 // contributions pages. Instead we use the special page shortcuts
711 // (which work correctly regardless of caching). This means we can't
712 // determine whether these links are active or not, but since major
713 // skins (MonoBook, Vector) don't use this information, it's not a
715 $personal_urls['anontalk'] = [
716 'text' => $this->msg( 'anontalk' )->text(),
717 'href' => self
::makeSpecialUrlSubpage( 'Mytalk', false ),
720 $personal_urls['anoncontribs'] = [
721 'text' => $this->msg( 'anoncontribs' )->text(),
722 'href' => self
::makeSpecialUrlSubpage( 'Mycontributions', false ),
728 $authManager->canCreateAccounts()
729 && $this->getUser()->isAllowed( 'createaccount' )
730 && !$useCombinedLoginLink
732 $personal_urls['createaccount'] = $createaccount_url;
735 if ( $authManager->canAuthenticateNow() ) {
736 $key = User
::groupHasPermission( '*', 'read' )
739 $personal_urls[$key] = $login_url;
743 Hooks
::runWithoutAbort( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
744 return $personal_urls;
748 * Builds an array with tab definition
750 * @param Title $title Page Where the tab links to
751 * @param string|array $message Message key or an array of message keys (will fall back)
752 * @param bool $selected Display the tab as selected
753 * @param string $query Query string attached to tab URL
754 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
758 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
761 $classes[] = 'selected';
764 if ( $checkEdit && !$title->isKnown() ) {
767 if ( $query !== '' ) {
768 $query = 'action=edit&redlink=1&' . $query;
770 $query = 'action=edit&redlink=1';
774 $linkClass = MediaWikiServices
::getInstance()->getLinkRenderer()->getLinkClasses( $title );
776 // wfMessageFallback will nicely accept $message as an array of fallbacks
777 // or just a single key
778 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
779 if ( is_array( $message ) ) {
780 // for hook compatibility just keep the last message name
781 $message = end( $message );
783 if ( $msg->exists() ) {
784 $text = $msg->text();
787 $text = $wgContLang->getConverter()->convertNamespace(
788 MWNamespace
::getSubject( $title->getNamespace() ) );
791 // Avoid PHP 7.1 warning of passing $this by reference
792 $skinTemplate = $this;
794 if ( !Hooks
::run( 'SkinTemplateTabAction', [ &$skinTemplate,
795 $title, $message, $selected, $checkEdit,
796 &$classes, &$query, &$text, &$result ] ) ) {
801 'class' => implode( ' ', $classes ),
803 'href' => $title->getLocalURL( $query ),
806 if ( $linkClass !== '' ) {
807 $result['link-class'] = $linkClass;
813 function makeTalkUrlDetails( $name, $urlaction = '' ) {
814 $title = Title
::newFromText( $name );
815 if ( !is_object( $title ) ) {
816 throw new MWException( __METHOD__
. " given invalid pagename $name" );
818 $title = $title->getTalkPage();
819 self
::checkTitle( $title, $name );
821 'href' => $title->getLocalURL( $urlaction ),
822 'exists' => $title->isKnown(),
827 * @todo is this even used?
828 * @param string $name
829 * @param string $urlaction
832 function makeArticleUrlDetails( $name, $urlaction = '' ) {
833 $title = Title
::newFromText( $name );
834 $title = $title->getSubjectPage();
835 self
::checkTitle( $title, $name );
837 'href' => $title->getLocalURL( $urlaction ),
838 'exists' => $title->exists(),
843 * a structured array of links usually used for the tabs in a skin
845 * There are 4 standard sections
846 * namespaces: Used for namespace tabs like special, page, and talk namespaces
847 * views: Used for primary page views like read, edit, history
848 * actions: Used for most extra page actions like deletion, protection, etc...
849 * variants: Used to list the language variants for the page
851 * Each section's value is a key/value array of links for that section.
852 * The links themselves have these common keys:
853 * - class: The css classes to apply to the tab
854 * - text: The text to display on the tab
855 * - href: The href for the tab to point to
856 * - rel: An optional rel= for the tab's link
857 * - redundant: If true the tab will be dropped in skins using content_actions
858 * this is useful for tabs like "Read" which only have meaning in skins that
859 * take special meaning from the grouped structure of content_navigation
861 * Views also have an extra key which can be used:
862 * - primary: If this is not true skins like vector may try to hide the tab
863 * when the user has limited space in their browser window
865 * content_navigation using code also expects these ids to be present on the
866 * links, however these are usually automatically generated by SkinTemplate
867 * itself and are not necessary when using a hook. The only things these may
868 * matter to are people modifying content_navigation after it's initial creation:
869 * - id: A "preferred" id, most skins are best off outputting this preferred
870 * id for best compatibility.
871 * - tooltiponly: This is set to true for some tabs in cases where the system
872 * believes that the accesskey should not be added to the tab.
876 protected function buildContentNavigationUrls() {
877 global $wgDisableLangConversion;
879 // Display tabs for the relevant title rather than always the title itself
880 $title = $this->getRelevantTitle();
881 $onPage = $title->equals( $this->getTitle() );
883 $out = $this->getOutput();
884 $request = $this->getRequest();
885 $user = $this->getUser();
887 $content_navigation = [
895 $action = $request->getVal( 'action', 'view' );
897 $userCanRead = $title->quickUserCan( 'read', $user );
899 // Avoid PHP 7.1 warning of passing $this by reference
900 $skinTemplate = $this;
901 $preventActiveTabs = false;
902 Hooks
::run( 'SkinTemplatePreventOtherActiveTabs', [ &$skinTemplate, &$preventActiveTabs ] );
904 // Checks if page is some kind of content
905 if ( $title->canExist() ) {
906 // Gets page objects for the related namespaces
907 $subjectPage = $title->getSubjectPage();
908 $talkPage = $title->getTalkPage();
910 // Determines if this is a talk page
911 $isTalk = $title->isTalkPage();
913 // Generates XML IDs from namespace names
914 $subjectId = $title->getNamespaceKey( '' );
916 if ( $subjectId == 'main' ) {
919 $talkId = "{$subjectId}_talk";
922 $skname = $this->skinname
;
924 // Adds namespace links
925 $subjectMsg = [ "nstab-$subjectId" ];
926 if ( $subjectPage->isMainPage() ) {
927 array_unshift( $subjectMsg, 'mainpage-nstab' );
929 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
930 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
932 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
933 $content_navigation['namespaces'][$talkId] = $this->tabAction(
934 $talkPage, [ "nstab-$talkId", 'talk' ], $isTalk && !$preventActiveTabs, '', $userCanRead
936 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
938 if ( $userCanRead ) {
939 // Adds "view" view link
940 if ( $title->isKnown() ) {
941 $content_navigation['views']['view'] = $this->tabAction(
942 $isTalk ?
$talkPage : $subjectPage,
943 [ "$skname-view-view", 'view' ],
944 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
946 // signal to hide this from simple content_actions
947 $content_navigation['views']['view']['redundant'] = true;
950 $page = $this->canUseWikiPage() ?
$this->getWikiPage() : false;
951 $isRemoteContent = $page && !$page->isLocal();
953 // If it is a non-local file, show a link to the file in its own repository
954 // @todo abstract this for remote content that isn't a file
955 if ( $isRemoteContent ) {
956 $content_navigation['views']['view-foreign'] = [
958 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
959 setContext( $this->getContext() )->
960 params( $page->getWikiDisplayName() )->text(),
961 'href' => $page->getSourceURL(),
966 // Checks if user can edit the current page if it exists or create it otherwise
967 if ( $title->quickUserCan( 'edit', $user )
968 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
970 // Builds CSS class for talk page links
971 $isTalkClass = $isTalk ?
' istalk' : '';
972 // Whether the user is editing the page
973 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
974 // Whether to show the "Add a new section" tab
975 // Checks if this is a current rev of talk page and is not forced to be hidden
976 $showNewSection = !$out->forceHideNewSectionLink()
977 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
978 $section = $request->getVal( 'section' );
980 if ( $title->exists()
981 ||
( $title->getNamespace() == NS_MEDIAWIKI
982 && $title->getDefaultMessageText() !== false
985 $msgKey = $isRemoteContent ?
'edit-local' : 'edit';
987 $msgKey = $isRemoteContent ?
'create-local' : 'create';
989 $content_navigation['views']['edit'] = [
990 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
994 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
995 ->setContext( $this->getContext() )->text(),
996 'href' => $title->getLocalURL( $this->editUrlOptions() ),
997 'primary' => !$isRemoteContent, // don't collapse this in vector
1001 if ( $showNewSection ) {
1002 // Adds new section link
1003 // $content_navigation['actions']['addsection']
1004 $content_navigation['views']['addsection'] = [
1005 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
1006 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
1007 ->setContext( $this->getContext() )->text(),
1008 'href' => $title->getLocalURL( 'action=edit§ion=new' )
1011 // Checks if the page has some kind of viewable source content
1012 } elseif ( $title->hasSourceText() ) {
1013 // Adds view source view link
1014 $content_navigation['views']['viewsource'] = [
1015 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
1016 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1017 ->setContext( $this->getContext() )->text(),
1018 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1019 'primary' => true, // don't collapse this in vector
1023 // Checks if the page exists
1024 if ( $title->exists() ) {
1025 // Adds history view link
1026 $content_navigation['views']['history'] = [
1027 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1028 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1029 ->setContext( $this->getContext() )->text(),
1030 'href' => $title->getLocalURL( 'action=history' ),
1033 if ( $title->quickUserCan( 'delete', $user ) ) {
1034 $content_navigation['actions']['delete'] = [
1035 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1036 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1037 ->setContext( $this->getContext() )->text(),
1038 'href' => $title->getLocalURL( 'action=delete' )
1042 if ( $title->quickUserCan( 'move', $user ) ) {
1043 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1044 $content_navigation['actions']['move'] = [
1045 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1046 'text' => wfMessageFallback( "$skname-action-move", 'move' )
1047 ->setContext( $this->getContext() )->text(),
1048 'href' => $moveTitle->getLocalURL()
1052 // article doesn't exist or is deleted
1053 if ( $user->isAllowed( 'deletedhistory' ) ) {
1054 $n = $title->isDeleted();
1056 $undelTitle = SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
1057 // If the user can't undelete but can view deleted
1058 // history show them a "View .. deleted" tab instead.
1059 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1060 $content_navigation['actions']['undelete'] = [
1061 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1062 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1063 ->setContext( $this->getContext() )->numParams( $n )->text(),
1064 'href' => $undelTitle->getLocalURL()
1070 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1071 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
1073 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1074 $content_navigation['actions'][$mode] = [
1075 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1076 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1077 ->setContext( $this->getContext() )->text(),
1078 'href' => $title->getLocalURL( "action=$mode" )
1082 // Checks if the user is logged in
1083 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1085 * The following actions use messages which, if made particular to
1086 * the any specific skins, would break the Ajax code which makes this
1087 * action happen entirely inline. OutputPage::getJSVars
1088 * defines a set of messages in a javascript object - and these
1089 * messages are assumed to be global for all skins. Without making
1090 * a change to that procedure these messages will have to remain as
1091 * the global versions.
1093 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1094 $content_navigation['actions'][$mode] = [
1095 'class' => 'mw-watchlink ' . (
1096 $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : ''
1098 // uses 'watch' or 'unwatch' message
1099 'text' => $this->msg( $mode )->text(),
1100 'href' => $title->getLocalURL( [ 'action' => $mode ] ),
1101 // Set a data-mw=interface attribute, which the mediawiki.page.ajax
1102 // module will look for to make sure it's a trusted link
1104 'mw' => 'interface',
1110 // Avoid PHP 7.1 warning of passing $this by reference
1111 $skinTemplate = $this;
1112 Hooks
::runWithoutAbort(
1113 'SkinTemplateNavigation',
1114 [ &$skinTemplate, &$content_navigation ]
1117 if ( $userCanRead && !$wgDisableLangConversion ) {
1118 $pageLang = $title->getPageLanguage();
1119 // Gets list of language variants
1120 $variants = $pageLang->getVariants();
1121 // Checks that language conversion is enabled and variants exist
1122 // And if it is not in the special namespace
1123 if ( count( $variants ) > 1 ) {
1124 // Gets preferred variant (note that user preference is
1125 // only possible for wiki content language variant)
1126 $preferred = $pageLang->getPreferredVariant();
1127 if ( Action
::getActionName( $this ) === 'view' ) {
1128 $params = $request->getQueryValues();
1129 unset( $params['title'] );
1133 // Loops over each variant
1134 foreach ( $variants as $code ) {
1135 // Gets variant name from language code
1136 $varname = $pageLang->getVariantname( $code );
1137 // Appends variant link
1138 $content_navigation['variants'][] = [
1139 'class' => ( $code == $preferred ) ?
'selected' : false,
1141 'href' => $title->getLocalURL( [ 'variant' => $code ] +
$params ),
1142 'lang' => LanguageCode
::bcp47( $code ),
1143 'hreflang' => LanguageCode
::bcp47( $code ),
1149 // If it's not content, it's got to be a special page
1150 $content_navigation['namespaces']['special'] = [
1151 'class' => 'selected',
1152 'text' => $this->msg( 'nstab-special' )->text(),
1153 'href' => $request->getRequestURL(), // @see: T4457, T4510
1154 'context' => 'subject'
1157 // Avoid PHP 7.1 warning of passing $this by reference
1158 $skinTemplate = $this;
1159 Hooks
::runWithoutAbort( 'SkinTemplateNavigation::SpecialPage',
1160 [ &$skinTemplate, &$content_navigation ] );
1163 // Avoid PHP 7.1 warning of passing $this by reference
1164 $skinTemplate = $this;
1165 // Equiv to SkinTemplateContentActions
1166 Hooks
::runWithoutAbort( 'SkinTemplateNavigation::Universal',
1167 [ &$skinTemplate, &$content_navigation ] );
1169 // Setup xml ids and tooltip info
1170 foreach ( $content_navigation as $section => &$links ) {
1171 foreach ( $links as $key => &$link ) {
1173 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1174 $xmlID = 'ca-nstab-' . $xmlID;
1175 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1177 $link['rel'] = 'discussion';
1178 } elseif ( $section == 'variants' ) {
1179 $xmlID = 'ca-varlang-' . $xmlID;
1181 $xmlID = 'ca-' . $xmlID;
1183 $link['id'] = $xmlID;
1187 # We don't want to give the watch tab an accesskey if the
1188 # page is being edited, because that conflicts with the
1189 # accesskey on the watch checkbox. We also don't want to
1190 # give the edit tab an accesskey, because that's fairly
1191 # superfluous and conflicts with an accesskey (Ctrl-E) often
1192 # used for editing in Safari.
1193 if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
1194 if ( isset( $content_navigation['views']['edit'] ) ) {
1195 $content_navigation['views']['edit']['tooltiponly'] = true;
1197 if ( isset( $content_navigation['actions']['watch'] ) ) {
1198 $content_navigation['actions']['watch']['tooltiponly'] = true;
1200 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1201 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1205 return $content_navigation;
1209 * an array of edit links by default used for the tabs
1210 * @param array $content_navigation
1213 private function buildContentActionUrls( $content_navigation ) {
1214 // content_actions has been replaced with content_navigation for backwards
1215 // compatibility and also for skins that just want simple tabs content_actions
1216 // is now built by flattening the content_navigation arrays into one
1218 $content_actions = [];
1220 foreach ( $content_navigation as $links ) {
1221 foreach ( $links as $key => $value ) {
1222 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1223 // Redundant tabs are dropped from content_actions
1227 // content_actions used to have ids built using the "ca-$key" pattern
1228 // so the xmlID based id is much closer to the actual $key that we want
1229 // for that reason we'll just strip out the ca- if present and use
1230 // the latter potion of the "id" as the $key
1231 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1232 $key = substr( $value['id'], 3 );
1235 if ( isset( $content_actions[$key] ) ) {
1236 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1237 "content_navigation into content_actions.\n" );
1241 $content_actions[$key] = $value;
1245 return $content_actions;
1249 * build array of common navigation links
1252 protected function buildNavUrls() {
1253 global $wgUploadNavigationUrl;
1255 $out = $this->getOutput();
1256 $request = $this->getRequest();
1259 $nav_urls['mainpage'] = [ 'href' => self
::makeMainPageUrl() ];
1260 if ( $wgUploadNavigationUrl ) {
1261 $nav_urls['upload'] = [ 'href' => $wgUploadNavigationUrl ];
1262 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1263 $nav_urls['upload'] = [ 'href' => self
::makeSpecialUrl( 'Upload' ) ];
1265 $nav_urls['upload'] = false;
1267 $nav_urls['specialpages'] = [ 'href' => self
::makeSpecialUrl( 'Specialpages' ) ];
1269 $nav_urls['print'] = false;
1270 $nav_urls['permalink'] = false;
1271 $nav_urls['info'] = false;
1272 $nav_urls['whatlinkshere'] = false;
1273 $nav_urls['recentchangeslinked'] = false;
1274 $nav_urls['contributions'] = false;
1275 $nav_urls['log'] = false;
1276 $nav_urls['blockip'] = false;
1277 $nav_urls['emailuser'] = false;
1278 $nav_urls['userrights'] = false;
1280 // A print stylesheet is attached to all pages, but nobody ever
1281 // figures that out. :) Add a link...
1282 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1283 $nav_urls['print'] = [
1284 'text' => $this->msg( 'printableversion' )->text(),
1285 'href' => $this->getTitle()->getLocalURL(
1286 $request->appendQueryValue( 'printable', 'yes' ) )
1290 if ( $out->isArticle() ) {
1291 // Also add a "permalink" while we're at it
1292 $revid = $this->getRevisionId();
1294 $nav_urls['permalink'] = [
1295 'text' => $this->msg( 'permalink' )->text(),
1296 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1300 // Avoid PHP 7.1 warning of passing $this by reference
1301 $skinTemplate = $this;
1302 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1303 Hooks
::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1304 [ &$skinTemplate, &$nav_urls, &$revid, &$revid ] );
1307 if ( $out->isArticleRelated() ) {
1308 $nav_urls['whatlinkshere'] = [
1309 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1312 $nav_urls['info'] = [
1313 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1314 'href' => $this->getTitle()->getLocalURL( "action=info" )
1317 if ( $this->getTitle()->exists() ||
$this->getTitle()->inNamespace( NS_CATEGORY
) ) {
1318 $nav_urls['recentchangeslinked'] = [
1319 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1324 $user = $this->getRelevantUser();
1326 $rootUser = $user->getName();
1328 $nav_urls['contributions'] = [
1329 'text' => $this->msg( 'contributions', $rootUser )->text(),
1330 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1331 'tooltip-params' => [ $rootUser ],
1334 $nav_urls['log'] = [
1335 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1338 if ( $this->getUser()->isAllowed( 'block' ) ) {
1339 $nav_urls['blockip'] = [
1340 'text' => $this->msg( 'blockip', $rootUser )->text(),
1341 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1345 if ( $this->showEmailUser( $user ) ) {
1346 $nav_urls['emailuser'] = [
1347 'text' => $this->msg( 'tool-link-emailuser', $rootUser )->text(),
1348 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1349 'tooltip-params' => [ $rootUser ],
1353 if ( !$user->isAnon() ) {
1354 $sur = new UserrightsPage
;
1355 $sur->setContext( $this->getContext() );
1356 $canChange = $sur->userCanChangeRights( $user );
1357 $nav_urls['userrights'] = [
1358 'text' => $this->msg(
1359 $canChange ?
'tool-link-userrights' : 'tool-link-userrights-readonly',
1362 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1371 * Generate strings used for xml 'id' names
1374 protected function getNameSpaceKey() {
1375 return $this->getTitle()->getNamespaceKey();