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 * @return QuickTemplate
68 function setupTemplate( $classname ) {
69 return new $classname( $this->getConfig() );
73 * Generates array of language links for the current page
77 public function getLanguages() {
78 global $wgHideInterlanguageLinks;
79 if ( $wgHideInterlanguageLinks ) {
83 $userLang = $this->getLanguage();
86 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
87 $class = 'interlanguage-link interwiki-' . explode( ':', $languageLinkText, 2 )[0];
89 $languageLinkTitle = Title
::newFromText( $languageLinkText );
90 if ( $languageLinkTitle ) {
91 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
92 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
94 if ( strval( $ilLangName ) === '' ) {
95 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
96 if ( !$ilDisplayTextMsg->isDisabled() ) {
97 // Use custom MW message for the display text
98 $ilLangName = $ilDisplayTextMsg->text();
100 // Last resort: fallback to the language link target
101 $ilLangName = $languageLinkText;
104 // Use the language autonym as display text
105 $ilLangName = $this->formatLanguageName( $ilLangName );
108 // CLDR extension or similar is required to localize the language name;
109 // otherwise we'll end up with the autonym again.
110 $ilLangLocalName = Language
::fetchLanguageName(
115 $languageLinkTitleText = $languageLinkTitle->getText();
116 if ( $ilLangLocalName === '' ) {
117 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
118 if ( !$ilFriendlySiteName->isDisabled() ) {
119 if ( $languageLinkTitleText === '' ) {
120 $ilTitle = wfMessage(
121 'interlanguage-link-title-nonlangonly',
122 $ilFriendlySiteName->text()
125 $ilTitle = wfMessage(
126 'interlanguage-link-title-nonlang',
127 $languageLinkTitleText,
128 $ilFriendlySiteName->text()
132 // we have nothing friendly to put in the title, so fall back to
133 // displaying the interlanguage link itself in the title text
134 // (similar to what is done in page content)
135 $ilTitle = $languageLinkTitle->getInterwiki() .
136 ":$languageLinkTitleText";
138 } elseif ( $languageLinkTitleText === '' ) {
139 $ilTitle = wfMessage(
140 'interlanguage-link-title-langonly',
144 $ilTitle = wfMessage(
145 'interlanguage-link-title',
146 $languageLinkTitleText,
151 $ilInterwikiCodeBCP47 = LanguageCode
::bcp47( $ilInterwikiCode );
153 'href' => $languageLinkTitle->getFullURL(),
154 'text' => $ilLangName,
157 'link-class' => 'interlanguage-link-target',
158 'lang' => $ilInterwikiCodeBCP47,
159 'hreflang' => $ilInterwikiCodeBCP47,
162 'SkinTemplateGetLanguageLink',
163 [ &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() ]
165 $languageLinks[] = $languageLink;
169 return $languageLinks;
173 * @return QuickTemplate
175 protected function setupTemplateForOutput() {
176 $request = $this->getRequest();
177 $user = $this->getUser();
178 $title = $this->getTitle();
180 $tpl = $this->setupTemplate( $this->template
);
182 $this->thispage
= $title->getPrefixedDBkey();
183 $this->titletxt
= $title->getPrefixedText();
184 $this->userpage
= $user->getUserPage()->getPrefixedText();
186 if ( !$request->wasPosted() ) {
187 $query = $request->getValues();
188 unset( $query['title'] );
189 unset( $query['returnto'] );
190 unset( $query['returntoquery'] );
192 $this->thisquery
= wfArrayToCgi( $query );
193 $this->loggedin
= $user->isLoggedIn();
194 $this->username
= $user->getName();
196 if ( $this->loggedin
) {
197 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
199 # This won't be used in the standard skins, but we define it to preserve the interface
200 # To save time, we check for existence
201 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
208 * Initialize various variables and generate the template
210 function outputPage() {
211 Profiler
::instance()->setTemplated( true );
212 $out = $this->getOutput();
214 $this->initPage( $out );
215 $tpl = $this->prepareQuickTemplate();
217 $res = $tpl->execute();
219 // result may be an error
220 $this->printOrError( $res );
224 * Wrap the body text with language information and identifiable element
226 * @param Title $title
227 * @param string $html body text
228 * @return string html
230 protected function wrapHTML( $title, $html ) {
231 # An ID that includes the actual body text; without categories, contentSub, ...
232 $realBodyAttribs = [ 'id' => 'mw-content-text' ];
234 # Add a mw-content-ltr/rtl class to be able to style based on text
235 # direction when the content is different from the UI language (only
237 # Most information on special pages and file pages is in user language,
238 # rather than content language, so those will not get this
239 if ( Action
::getActionName( $this ) === 'view' &&
240 ( !$title->inNamespaces( NS_SPECIAL
, NS_FILE
) ||
$title->isRedirect() ) ) {
241 $pageLang = $title->getPageViewLanguage();
242 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
243 $realBodyAttribs['dir'] = $pageLang->getDir();
244 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
247 return Html
::rawElement( 'div', $realBodyAttribs, $html );
251 * initialize various variables and generate the template
254 * @return QuickTemplate The template to be executed by outputPage
256 protected function prepareQuickTemplate() {
257 global $wgScript, $wgStylePath, $wgMimeType,
258 $wgSitename, $wgLogo, $wgMaxCredits,
259 $wgShowCreditsIfMax, $wgArticlePath,
260 $wgScriptPath, $wgServer;
262 $title = $this->getTitle();
263 $request = $this->getRequest();
264 $out = $this->getOutput();
265 $tpl = $this->setupTemplateForOutput();
267 $tpl->set( 'title', $out->getPageTitle() );
268 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
269 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
271 $tpl->set( 'thispage', $this->thispage
);
272 $tpl->set( 'titleprefixeddbkey', $this->thispage
);
273 $tpl->set( 'titletext', $title->getText() );
274 $tpl->set( 'articleid', $title->getArticleID() );
276 $tpl->set( 'isarticle', $out->isArticle() );
278 $subpagestr = $this->subPageSubtitle();
279 if ( $subpagestr !== '' ) {
280 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
282 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
284 $undelete = $this->getUndeleteLink();
285 if ( $undelete === '' ) {
286 $tpl->set( 'undelete', '' );
288 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
291 $tpl->set( 'catlinks', $this->getCategories() );
292 if ( $out->isSyndicated() ) {
294 foreach ( $out->getSyndicationLinks() as $format => $link ) {
296 // Messages: feed-atom, feed-rss
297 'text' => $this->msg( "feed-$format" )->text(),
301 $tpl->set( 'feeds', $feeds );
303 $tpl->set( 'feeds', false );
306 $tpl->set( 'mimetype', $wgMimeType );
307 $tpl->set( 'charset', 'UTF-8' );
308 $tpl->set( 'wgScript', $wgScript );
309 $tpl->set( 'skinname', $this->skinname
);
310 $tpl->set( 'skinclass', static::class );
311 $tpl->set( 'skin', $this );
312 $tpl->set( 'stylename', $this->stylename
);
313 $tpl->set( 'printable', $out->isPrintable() );
314 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
315 $tpl->set( 'loggedin', $this->loggedin
);
316 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
317 $tpl->set( 'searchaction', $this->getSearchLink() );
318 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
319 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
320 $tpl->set( 'stylepath', $wgStylePath );
321 $tpl->set( 'articlepath', $wgArticlePath );
322 $tpl->set( 'scriptpath', $wgScriptPath );
323 $tpl->set( 'serverurl', $wgServer );
324 $tpl->set( 'logopath', $wgLogo );
325 $tpl->set( 'sitename', $wgSitename );
327 $userLang = $this->getLanguage();
328 $userLangCode = $userLang->getHtmlCode();
329 $userLangDir = $userLang->getDir();
331 $tpl->set( 'lang', $userLangCode );
332 $tpl->set( 'dir', $userLangDir );
333 $tpl->set( 'rtl', $userLang->isRTL() );
335 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
336 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
337 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
338 $tpl->set( 'userpage', $this->userpage
);
339 $tpl->set( 'userpageurl', $this->userpageUrlDetails
['href'] );
340 $tpl->set( 'userlang', $userLangCode );
342 // Users can have their language set differently than the
343 // content of the wiki. For these users, tell the web browser
344 // that interface elements are in a different language.
345 $tpl->set( 'userlangattributes', '' );
346 $tpl->set( 'specialpageattributes', '' ); # obsolete
347 // Used by VectorBeta to insert HTML before content but after the
348 // heading for the page title. Defaults to empty string.
349 $tpl->set( 'prebodyhtml', '' );
351 $contLang = MediaWikiServices
::getInstance()->getContentLanguage();
353 $userLangCode !== $contLang->getHtmlCode() ||
354 $userLangDir !== $contLang->getDir()
356 $escUserlang = htmlspecialchars( $userLangCode );
357 $escUserdir = htmlspecialchars( $userLangDir );
358 // Attributes must be in double quotes because htmlspecialchars() doesn't
359 // escape single quotes
360 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
361 $tpl->set( 'userlangattributes', $attrs );
364 $tpl->set( 'newtalk', $this->getNewtalks() );
365 $tpl->set( 'logo', $this->logoText() );
367 $tpl->set( 'copyright', false );
369 $tpl->set( 'viewcount', false );
370 $tpl->set( 'lastmod', false );
371 $tpl->set( 'credits', false );
372 $tpl->set( 'numberofwatchingusers', false );
373 if ( $title->exists() ) {
374 if ( $out->isArticle() && $out->isRevisionCurrent() ) {
375 if ( $wgMaxCredits != 0 ) {
376 /** @var CreditsAction $action */
377 $action = Action
::factory(
378 'credits', $this->getWikiPage(), $this->getContext() );
379 $tpl->set( 'credits',
380 $action->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
382 $tpl->set( 'lastmod', $this->lastModified() );
385 if ( $out->showsCopyright() ) {
386 $tpl->set( 'copyright', $this->getCopyright() );
390 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
391 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
392 $tpl->set( 'disclaimer', $this->disclaimerLink() );
393 $tpl->set( 'privacy', $this->privacyLink() );
394 $tpl->set( 'about', $this->aboutLink() );
396 $tpl->set( 'footerlinks', [
399 'numberofwatchingusers',
410 global $wgFooterIcons;
411 $tpl->set( 'footericons', $wgFooterIcons );
412 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
413 if ( count( $footerIconsBlock ) > 0 ) {
414 foreach ( $footerIconsBlock as &$footerIcon ) {
415 if ( isset( $footerIcon['src'] ) ) {
416 if ( !isset( $footerIcon['width'] ) ) {
417 $footerIcon['width'] = 88;
419 if ( !isset( $footerIcon['height'] ) ) {
420 $footerIcon['height'] = 31;
425 unset( $tpl->data
['footericons'][$footerIconsKey] );
429 $tpl->set( 'indicators', $out->getIndicators() );
431 $tpl->set( 'sitenotice', $this->getSiteNotice() );
432 $tpl->set( 'printfooter', $this->printSource() );
433 // Wrap the bodyText with #mw-content-text element
434 $out->mBodytext
= $this->wrapHTML( $title, $out->mBodytext
);
435 $tpl->set( 'bodytext', $out->mBodytext
);
437 $language_urls = $this->getLanguages();
438 if ( count( $language_urls ) ) {
439 $tpl->set( 'language_urls', $language_urls );
441 $tpl->set( 'language_urls', false );
445 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
446 $content_navigation = $this->buildContentNavigationUrls();
447 $content_actions = $this->buildContentActionUrls( $content_navigation );
448 $tpl->set( 'content_navigation', $content_navigation );
449 $tpl->set( 'content_actions', $content_actions );
451 $tpl->set( 'sidebar', $this->buildSidebar() );
452 $tpl->set( 'nav_urls', $this->buildNavUrls() );
454 // Do this last in case hooks above add bottom scripts
455 $tpl->set( 'bottomscripts', $this->bottomScripts() );
457 // Set the head scripts near the end, in case the above actions resulted in added scripts
458 $tpl->set( 'headelement', $out->headElement( $this ) );
460 $tpl->set( 'debug', '' );
461 $tpl->set( 'debughtml', $this->generateDebugHTML() );
462 $tpl->set( 'reporttime', wfReportTime( $out->getCSPNonce() ) );
464 // Avoid PHP 7.1 warning of passing $this by reference
465 $skinTemplate = $this;
466 // original version by hansm
467 if ( !Hooks
::run( 'SkinTemplateOutputPageBeforeExec', [ &$skinTemplate, &$tpl ] ) ) {
468 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
471 // Set the bodytext to another key so that skins can just output it on its own
472 // and output printfooter and debughtml separately
473 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
475 // Append printfooter and debughtml onto bodytext so that skins that
476 // were already using bodytext before they were split out don't suddenly
477 // start not outputting information.
478 $tpl->data
['bodytext'] .= Html
::rawElement(
480 [ 'class' => 'printfooter' ],
481 "\n{$tpl->data['printfooter']}"
483 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
485 // allow extensions adding stuff after the page content.
486 // See Skin::afterContentHook() for further documentation.
487 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
493 * Get the HTML for the p-personal list
496 public function getPersonalToolsList() {
497 return $this->makePersonalToolsList();
501 * Get the HTML for the personal tools list
505 * @param array|null $personalTools
506 * @param array $options
509 public function makePersonalToolsList( $personalTools = null, $options = [] ) {
510 $tpl = $this->setupTemplateForOutput();
511 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
514 if ( $personalTools === null ) {
515 $personalTools = ( $tpl instanceof BaseTemplate
)
516 ?
$tpl->getPersonalTools()
520 foreach ( $personalTools as $key => $item ) {
521 $html .= $tpl->makeListItem( $key, $item, $options );
528 * Get personal tools for the user
532 * @return array Array of personal tools
534 public function getStructuredPersonalTools() {
535 $tpl = $this->setupTemplateForOutput();
536 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
538 return ( $tpl instanceof BaseTemplate
) ?
$tpl->getPersonalTools() : [];
542 * Format language name for use in sidebar interlanguage links list.
543 * By default it is capitalized.
545 * @param string $name Language name, e.g. "English" or "español"
549 function formatLanguageName( $name ) {
550 return $this->getLanguage()->ucfirst( $name );
554 * Output the string, or print error message if it's
555 * an error object of the appropriate type.
556 * For the base class, assume strings all around.
561 function printOrError( $str ) {
566 * Output a boolean indicating if buildPersonalUrls should output separate
567 * login and create account links or output a combined link
568 * By default we simply return a global config setting that affects most skins
569 * This is setup as a method so that like with $wgLogo and getLogo() a skin
570 * can override this setting and always output one or the other if it has
571 * a reason it can't output one of the two modes.
574 function useCombinedLoginLink() {
575 global $wgUseCombinedLoginLink;
576 return $wgUseCombinedLoginLink;
580 * build array of urls for personal toolbar
583 protected function buildPersonalUrls() {
584 $title = $this->getTitle();
585 $request = $this->getRequest();
586 $pageurl = $title->getLocalURL();
587 $authManager = AuthManager
::singleton();
588 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
590 /* set up the default links for the personal toolbar */
593 # Due to T34276, if a user does not have read permissions,
594 # $this->getTitle() will just give Special:Badtitle, which is
595 # not especially useful as a returnto parameter. Use the title
596 # from the request instead, if there was one.
597 if ( $this->getUser()->isAllowed( 'read' ) ) {
598 $page = $this->getTitle();
600 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
602 $page = $request->getVal( 'returnto', $page );
604 if ( strval( $page ) !== '' ) {
605 $returnto['returnto'] = $page;
606 $query = $request->getVal( 'returntoquery', $this->thisquery
);
607 $paramsArray = wfCgiToArray( $query );
608 $query = wfArrayToCgi( $paramsArray );
609 if ( $query != '' ) {
610 $returnto['returntoquery'] = $query;
614 if ( $this->loggedin
) {
615 $personal_urls['userpage'] = [
616 'text' => $this->username
,
617 'href' => &$this->userpageUrlDetails
['href'],
618 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
619 'exists' => $this->userpageUrlDetails
['exists'],
620 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
623 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
624 $personal_urls['mytalk'] = [
625 'text' => $this->msg( 'mytalk' )->text(),
626 'href' => &$usertalkUrlDetails['href'],
627 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
628 'exists' => $usertalkUrlDetails['exists'],
629 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
631 $href = self
::makeSpecialUrl( 'Preferences' );
632 $personal_urls['preferences'] = [
633 'text' => $this->msg( 'mypreferences' )->text(),
635 'active' => ( $href == $pageurl )
638 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
639 $href = self
::makeSpecialUrl( 'Watchlist' );
640 $personal_urls['watchlist'] = [
641 'text' => $this->msg( 'mywatchlist' )->text(),
643 'active' => ( $href == $pageurl )
647 # We need to do an explicit check for Special:Contributions, as we
648 # have to match both the title, and the target, which could come
649 # from request values (Special:Contributions?target=Jimbo_Wales)
650 # or be specified in "sub page" form
651 # (Special:Contributions/Jimbo_Wales). The plot
652 # thickens, because the Title object is altered for special pages,
653 # so it doesn't contain the original alias-with-subpage.
654 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
655 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
656 list( $spName, $spPar ) =
657 MediaWikiServices
::getInstance()->getSpecialPageFactory()->
658 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 // Note: 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' ) ?
[] : $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 ( $permissionManager->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 = $permissionManager->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 $services = MediaWikiServices
::getInstance();
775 $linkClass = $services->getLinkRenderer()->getLinkClasses( $title );
777 // wfMessageFallback will nicely accept $message as an array of fallbacks
778 // or just a single key
779 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
780 if ( is_array( $message ) ) {
781 // for hook compatibility just keep the last message name
782 $message = end( $message );
784 if ( $msg->exists() ) {
785 $text = $msg->text();
787 $text = $services->getContentLanguage()->getConverter()->
788 convertNamespace( $services->getNamespaceInfo()->
789 getSubject( $title->getNamespace() ) );
792 // Avoid PHP 7.1 warning of passing $this by reference
793 $skinTemplate = $this;
795 if ( !Hooks
::run( 'SkinTemplateTabAction', [ &$skinTemplate,
796 $title, $message, $selected, $checkEdit,
797 &$classes, &$query, &$text, &$result ] ) ) {
802 'class' => implode( ' ', $classes ),
804 'href' => $title->getLocalURL( $query ),
807 if ( $linkClass !== '' ) {
808 $result['link-class'] = $linkClass;
814 function makeTalkUrlDetails( $name, $urlaction = '' ) {
815 $title = Title
::newFromText( $name );
816 if ( !is_object( $title ) ) {
817 throw new MWException( __METHOD__
. " given invalid pagename $name" );
819 $title = $title->getTalkPage();
820 self
::checkTitle( $title, $name );
822 'href' => $title->getLocalURL( $urlaction ),
823 'exists' => $title->isKnown(),
828 * @todo is this even used?
829 * @param string $name
830 * @param string $urlaction
833 function makeArticleUrlDetails( $name, $urlaction = '' ) {
834 $title = Title
::newFromText( $name );
835 $title = $title->getSubjectPage();
836 self
::checkTitle( $title, $name );
838 'href' => $title->getLocalURL( $urlaction ),
839 'exists' => $title->exists(),
844 * a structured array of links usually used for the tabs in a skin
846 * There are 4 standard sections
847 * namespaces: Used for namespace tabs like special, page, and talk namespaces
848 * views: Used for primary page views like read, edit, history
849 * actions: Used for most extra page actions like deletion, protection, etc...
850 * variants: Used to list the language variants for the page
852 * Each section's value is a key/value array of links for that section.
853 * The links themselves have these common keys:
854 * - class: The css classes to apply to the tab
855 * - text: The text to display on the tab
856 * - href: The href for the tab to point to
857 * - rel: An optional rel= for the tab's link
858 * - redundant: If true the tab will be dropped in skins using content_actions
859 * this is useful for tabs like "Read" which only have meaning in skins that
860 * take special meaning from the grouped structure of content_navigation
862 * Views also have an extra key which can be used:
863 * - primary: If this is not true skins like vector may try to hide the tab
864 * when the user has limited space in their browser window
866 * content_navigation using code also expects these ids to be present on the
867 * links, however these are usually automatically generated by SkinTemplate
868 * itself and are not necessary when using a hook. The only things these may
869 * matter to are people modifying content_navigation after it's initial creation:
870 * - id: A "preferred" id, most skins are best off outputting this preferred
871 * id for best compatibility.
872 * - tooltiponly: This is set to true for some tabs in cases where the system
873 * believes that the accesskey should not be added to the tab.
877 protected function buildContentNavigationUrls() {
878 global $wgDisableLangConversion;
880 // Display tabs for the relevant title rather than always the title itself
881 $title = $this->getRelevantTitle();
882 $onPage = $title->equals( $this->getTitle() );
884 $out = $this->getOutput();
885 $request = $this->getRequest();
886 $user = $this->getUser();
888 $content_navigation = [
896 $action = $request->getVal( 'action', 'view' );
898 $userCanRead = $title->quickUserCan( 'read', $user );
900 // Avoid PHP 7.1 warning of passing $this by reference
901 $skinTemplate = $this;
902 $preventActiveTabs = false;
903 Hooks
::run( 'SkinTemplatePreventOtherActiveTabs', [ &$skinTemplate, &$preventActiveTabs ] );
905 // Checks if page is some kind of content
906 if ( $title->canExist() ) {
907 // Gets page objects for the related namespaces
908 $subjectPage = $title->getSubjectPage();
909 $talkPage = $title->getTalkPage();
911 // Determines if this is a talk page
912 $isTalk = $title->isTalkPage();
914 // Generates XML IDs from namespace names
915 $subjectId = $title->getNamespaceKey( '' );
917 if ( $subjectId == 'main' ) {
920 $talkId = "{$subjectId}_talk";
923 $skname = $this->skinname
;
925 // Adds namespace links
926 $subjectMsg = [ "nstab-$subjectId" ];
927 if ( $subjectPage->isMainPage() ) {
928 array_unshift( $subjectMsg, 'mainpage-nstab' );
930 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
931 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
933 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
934 $content_navigation['namespaces'][$talkId] = $this->tabAction(
935 $talkPage, [ "nstab-$talkId", 'talk' ], $isTalk && !$preventActiveTabs, '', $userCanRead
937 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
939 if ( $userCanRead ) {
940 // Adds "view" view link
941 if ( $title->isKnown() ) {
942 $content_navigation['views']['view'] = $this->tabAction(
943 $isTalk ?
$talkPage : $subjectPage,
944 [ "$skname-view-view", 'view' ],
945 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
947 // signal to hide this from simple content_actions
948 $content_navigation['views']['view']['redundant'] = true;
951 $page = $this->canUseWikiPage() ?
$this->getWikiPage() : false;
952 $isRemoteContent = $page && !$page->isLocal();
954 // If it is a non-local file, show a link to the file in its own repository
955 // @todo abstract this for remote content that isn't a file
956 if ( $isRemoteContent ) {
957 $content_navigation['views']['view-foreign'] = [
959 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
960 setContext( $this->getContext() )->
961 params( $page->getWikiDisplayName() )->text(),
962 'href' => $page->getSourceURL(),
967 // Checks if user can edit the current page if it exists or create it otherwise
968 if ( $title->quickUserCan( 'edit', $user )
969 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
971 // Builds CSS class for talk page links
972 $isTalkClass = $isTalk ?
' istalk' : '';
973 // Whether the user is editing the page
974 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
975 // Whether to show the "Add a new section" tab
976 // Checks if this is a current rev of talk page and is not forced to be hidden
977 $showNewSection = !$out->forceHideNewSectionLink()
978 && ( ( $isTalk && $out->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
979 $section = $request->getVal( 'section' );
981 if ( $title->exists()
982 ||
( $title->getNamespace() == NS_MEDIAWIKI
983 && $title->getDefaultMessageText() !== false
986 $msgKey = $isRemoteContent ?
'edit-local' : 'edit';
988 $msgKey = $isRemoteContent ?
'create-local' : 'create';
990 $content_navigation['views']['edit'] = [
991 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
995 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
996 ->setContext( $this->getContext() )->text(),
997 'href' => $title->getLocalURL( $this->editUrlOptions() ),
998 'primary' => !$isRemoteContent, // don't collapse this in vector
1002 if ( $showNewSection ) {
1003 // Adds new section link
1004 // $content_navigation['actions']['addsection']
1005 $content_navigation['views']['addsection'] = [
1006 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
1007 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
1008 ->setContext( $this->getContext() )->text(),
1009 'href' => $title->getLocalURL( 'action=edit§ion=new' )
1012 // Checks if the page has some kind of viewable source content
1013 } elseif ( $title->hasSourceText() ) {
1014 // Adds view source view link
1015 $content_navigation['views']['viewsource'] = [
1016 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
1017 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1018 ->setContext( $this->getContext() )->text(),
1019 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1020 'primary' => true, // don't collapse this in vector
1024 // Checks if the page exists
1025 if ( $title->exists() ) {
1026 // Adds history view link
1027 $content_navigation['views']['history'] = [
1028 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1029 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1030 ->setContext( $this->getContext() )->text(),
1031 'href' => $title->getLocalURL( 'action=history' ),
1034 if ( $title->quickUserCan( 'delete', $user ) ) {
1035 $content_navigation['actions']['delete'] = [
1036 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1037 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1038 ->setContext( $this->getContext() )->text(),
1039 'href' => $title->getLocalURL( 'action=delete' )
1043 if ( $title->quickUserCan( 'move', $user ) ) {
1044 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1045 $content_navigation['actions']['move'] = [
1046 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1047 'text' => wfMessageFallback( "$skname-action-move", 'move' )
1048 ->setContext( $this->getContext() )->text(),
1049 'href' => $moveTitle->getLocalURL()
1053 // article doesn't exist or is deleted
1054 if ( $title->quickUserCan( 'deletedhistory', $user ) ) {
1055 $n = $title->isDeleted();
1057 $undelTitle = SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
1058 // If the user can't undelete but can view deleted
1059 // history show them a "View .. deleted" tab instead.
1060 $msgKey = $title->quickUserCan( 'undelete', $user ) ?
'undelete' : 'viewdeleted';
1061 $content_navigation['actions']['undelete'] = [
1062 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1063 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1064 ->setContext( $this->getContext() )->numParams( $n )->text(),
1065 'href' => $undelTitle->getLocalURL()
1071 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1072 MediaWikiServices
::getInstance()->getPermissionManager()
1073 ->getNamespaceRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
1075 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1076 $content_navigation['actions'][$mode] = [
1077 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1078 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1079 ->setContext( $this->getContext() )->text(),
1080 'href' => $title->getLocalURL( "action=$mode" )
1084 // Checks if the user is logged in
1085 if ( $this->loggedin
&& MediaWikiServices
::getInstance()
1086 ->getPermissionManager()
1087 ->userHasAllRights( $user, 'viewmywatchlist', 'editmywatchlist' )
1090 * The following actions use messages which, if made particular to
1091 * the any specific skins, would break the Ajax code which makes this
1092 * action happen entirely inline. OutputPage::getJSVars
1093 * defines a set of messages in a javascript object - and these
1094 * messages are assumed to be global for all skins. Without making
1095 * a change to that procedure these messages will have to remain as
1096 * the global versions.
1098 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1099 $content_navigation['actions'][$mode] = [
1100 'class' => 'mw-watchlink ' . (
1101 $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : ''
1103 // uses 'watch' or 'unwatch' message
1104 'text' => $this->msg( $mode )->text(),
1105 'href' => $title->getLocalURL( [ 'action' => $mode ] ),
1106 // Set a data-mw=interface attribute, which the mediawiki.page.ajax
1107 // module will look for to make sure it's a trusted link
1109 'mw' => 'interface',
1115 // Avoid PHP 7.1 warning of passing $this by reference
1116 $skinTemplate = $this;
1117 Hooks
::runWithoutAbort(
1118 'SkinTemplateNavigation',
1119 [ &$skinTemplate, &$content_navigation ]
1122 if ( $userCanRead && !$wgDisableLangConversion ) {
1123 $pageLang = $title->getPageLanguage();
1124 // Checks that language conversion is enabled and variants exist
1125 // And if it is not in the special namespace
1126 if ( $pageLang->hasVariants() ) {
1127 // Gets list of language variants
1128 $variants = $pageLang->getVariants();
1129 // Gets preferred variant (note that user preference is
1130 // only possible for wiki content language variant)
1131 $preferred = $pageLang->getPreferredVariant();
1132 if ( Action
::getActionName( $this ) === 'view' ) {
1133 $params = $request->getQueryValues();
1134 unset( $params['title'] );
1138 // Loops over each variant
1139 foreach ( $variants as $code ) {
1140 // Gets variant name from language code
1141 $varname = $pageLang->getVariantname( $code );
1142 // Appends variant link
1143 $content_navigation['variants'][] = [
1144 'class' => ( $code == $preferred ) ?
'selected' : false,
1146 'href' => $title->getLocalURL( [ 'variant' => $code ] +
$params ),
1147 'lang' => LanguageCode
::bcp47( $code ),
1148 'hreflang' => LanguageCode
::bcp47( $code ),
1154 // If it's not content, it's got to be a special page
1155 $content_navigation['namespaces']['special'] = [
1156 'class' => 'selected',
1157 'text' => $this->msg( 'nstab-special' )->text(),
1158 'href' => $request->getRequestURL(), // @see: T4457, T4510
1159 'context' => 'subject'
1162 // Avoid PHP 7.1 warning of passing $this by reference
1163 $skinTemplate = $this;
1164 Hooks
::runWithoutAbort( 'SkinTemplateNavigation::SpecialPage',
1165 [ &$skinTemplate, &$content_navigation ] );
1168 // Avoid PHP 7.1 warning of passing $this by reference
1169 $skinTemplate = $this;
1170 // Equiv to SkinTemplateContentActions
1171 Hooks
::runWithoutAbort( 'SkinTemplateNavigation::Universal',
1172 [ &$skinTemplate, &$content_navigation ] );
1174 // Setup xml ids and tooltip info
1175 foreach ( $content_navigation as $section => &$links ) {
1176 foreach ( $links as $key => &$link ) {
1178 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1179 $xmlID = 'ca-nstab-' . $xmlID;
1180 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1182 $link['rel'] = 'discussion';
1183 } elseif ( $section == 'variants' ) {
1184 $xmlID = 'ca-varlang-' . $xmlID;
1186 $xmlID = 'ca-' . $xmlID;
1188 $link['id'] = $xmlID;
1192 # We don't want to give the watch tab an accesskey if the
1193 # page is being edited, because that conflicts with the
1194 # accesskey on the watch checkbox. We also don't want to
1195 # give the edit tab an accesskey, because that's fairly
1196 # superfluous and conflicts with an accesskey (Ctrl-E) often
1197 # used for editing in Safari.
1198 if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
1199 if ( isset( $content_navigation['views']['edit'] ) ) {
1200 $content_navigation['views']['edit']['tooltiponly'] = true;
1202 if ( isset( $content_navigation['actions']['watch'] ) ) {
1203 $content_navigation['actions']['watch']['tooltiponly'] = true;
1205 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1206 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1210 return $content_navigation;
1214 * an array of edit links by default used for the tabs
1215 * @param array $content_navigation
1218 private function buildContentActionUrls( $content_navigation ) {
1219 // content_actions has been replaced with content_navigation for backwards
1220 // compatibility and also for skins that just want simple tabs content_actions
1221 // is now built by flattening the content_navigation arrays into one
1223 $content_actions = [];
1225 foreach ( $content_navigation as $links ) {
1226 foreach ( $links as $key => $value ) {
1227 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1228 // Redundant tabs are dropped from content_actions
1232 // content_actions used to have ids built using the "ca-$key" pattern
1233 // so the xmlID based id is much closer to the actual $key that we want
1234 // for that reason we'll just strip out the ca- if present and use
1235 // the latter potion of the "id" as the $key
1236 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1237 $key = substr( $value['id'], 3 );
1240 if ( isset( $content_actions[$key] ) ) {
1241 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1242 "content_navigation into content_actions.\n" );
1246 $content_actions[$key] = $value;
1250 return $content_actions;
1254 * build array of common navigation links
1257 protected function buildNavUrls() {
1258 global $wgUploadNavigationUrl;
1260 $out = $this->getOutput();
1261 $request = $this->getRequest();
1264 $nav_urls['mainpage'] = [ 'href' => self
::makeMainPageUrl() ];
1265 if ( $wgUploadNavigationUrl ) {
1266 $nav_urls['upload'] = [ 'href' => $wgUploadNavigationUrl ];
1267 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1268 $nav_urls['upload'] = [ 'href' => self
::makeSpecialUrl( 'Upload' ) ];
1270 $nav_urls['upload'] = false;
1272 $nav_urls['specialpages'] = [ 'href' => self
::makeSpecialUrl( 'Specialpages' ) ];
1274 $nav_urls['print'] = false;
1275 $nav_urls['permalink'] = false;
1276 $nav_urls['info'] = false;
1277 $nav_urls['whatlinkshere'] = false;
1278 $nav_urls['recentchangeslinked'] = false;
1279 $nav_urls['contributions'] = false;
1280 $nav_urls['log'] = false;
1281 $nav_urls['blockip'] = false;
1282 $nav_urls['mute'] = false;
1283 $nav_urls['emailuser'] = false;
1284 $nav_urls['userrights'] = false;
1286 // A print stylesheet is attached to all pages, but nobody ever
1287 // figures that out. :) Add a link...
1288 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1289 $nav_urls['print'] = [
1290 'text' => $this->msg( 'printableversion' )->text(),
1291 'href' => $this->getTitle()->getLocalURL(
1292 $request->appendQueryValue( 'printable', 'yes' ) )
1296 if ( $out->isArticle() ) {
1297 // Also add a "permalink" while we're at it
1298 $revid = $this->getOutput()->getRevisionId();
1300 $nav_urls['permalink'] = [
1301 'text' => $this->msg( 'permalink' )->text(),
1302 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1306 // Avoid PHP 7.1 warning of passing $this by reference
1307 $skinTemplate = $this;
1308 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1309 Hooks
::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1310 [ &$skinTemplate, &$nav_urls, &$revid, &$revid ] );
1313 if ( $out->isArticleRelated() ) {
1314 $nav_urls['whatlinkshere'] = [
1315 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1318 $nav_urls['info'] = [
1319 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1320 'href' => $this->getTitle()->getLocalURL( "action=info" )
1323 if ( $this->getTitle()->exists() ||
$this->getTitle()->inNamespace( NS_CATEGORY
) ) {
1324 $nav_urls['recentchangeslinked'] = [
1325 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1330 $user = $this->getRelevantUser();
1332 $rootUser = $user->getName();
1334 $nav_urls['contributions'] = [
1335 'text' => $this->msg( 'contributions', $rootUser )->text(),
1336 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1337 'tooltip-params' => [ $rootUser ],
1340 $nav_urls['log'] = [
1341 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1344 if ( $this->getUser()->isAllowed( 'block' ) ) {
1345 $nav_urls['blockip'] = [
1346 'text' => $this->msg( 'blockip', $rootUser )->text(),
1347 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1351 if ( $this->showEmailUser( $user ) ) {
1352 $nav_urls['emailuser'] = [
1353 'text' => $this->msg( 'tool-link-emailuser', $rootUser )->text(),
1354 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1355 'tooltip-params' => [ $rootUser ],
1359 if ( !$user->isAnon() ) {
1360 if ( $this->getUser()->isRegistered() && $this->getConfig()->get( 'EnableSpecialMute' ) ) {
1361 $nav_urls['mute'] = [
1362 'text' => $this->msg( 'mute-preferences' )->text(),
1363 'href' => self
::makeSpecialUrlSubpage( 'Mute', $rootUser )
1367 $sur = new UserrightsPage
;
1368 $sur->setContext( $this->getContext() );
1369 $canChange = $sur->userCanChangeRights( $user );
1370 $nav_urls['userrights'] = [
1371 'text' => $this->msg(
1372 $canChange ?
'tool-link-userrights' : 'tool-link-userrights-readonly',
1375 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1384 * Generate strings used for xml 'id' names
1387 protected function getNameSpaceKey() {
1388 return $this->getTitle()->getNamespaceKey();