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
22 * Base class for template-based skins.
24 * Template-filler skin base class
25 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
26 * Based on Brion's smarty skin
27 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
29 * @todo Needs some serious refactoring into functions that correspond
30 * to the computations individual esi snippets need. Most importantly no body
31 * parsing for most of those of course.
35 class SkinTemplate
extends Skin
{
37 * @var string Name of our skin, it probably needs to be all lower case.
38 * Child classes should override the default.
40 public $skinname = 'monobook';
43 * @var string For QuickTemplate, the name of the subclass which will
44 * actually fill the template. Child classes should override the default.
46 public $template = 'QuickTemplate';
49 * Add specific styles for this skin
51 * @param OutputPage $out
53 function setupSkinUserCss( OutputPage
$out ) {
55 'mediawiki.legacy.shared',
56 'mediawiki.legacy.commonPrint',
57 'mediawiki.sectionAnchor'
59 if ( $out->isSyndicated() ) {
60 $moduleStyles[] = 'mediawiki.feedlink';
63 // Deprecated since 1.26: Unconditional loading of mediawiki.ui.button
64 // on every page is deprecated. Express a dependency instead.
65 if ( strpos( $out->getHTML(), 'mw-ui-button' ) !== false ) {
66 $moduleStyles[] = 'mediawiki.ui.button';
69 $out->addModuleStyles( $moduleStyles );
73 * Create the template engine object; we feed it a bunch of data
74 * and eventually it spits out some HTML. Should have interface
75 * roughly equivalent to PHPTAL 0.7.
77 * @param string $classname
78 * @param bool|string $repository Subdirectory where we keep template files
79 * @param bool|string $cache_dir
80 * @return QuickTemplate
83 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
84 return new $classname( $this->getConfig() );
88 * Generates array of language links for the current page
92 public function getLanguages() {
93 global $wgHideInterlanguageLinks;
94 if ( $wgHideInterlanguageLinks ) {
98 $userLang = $this->getLanguage();
101 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
102 $class = 'interlanguage-link interwiki-' . explode( ':', $languageLinkText, 2 )[0];
104 $languageLinkTitle = Title
::newFromText( $languageLinkText );
105 if ( $languageLinkTitle ) {
106 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
107 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
109 if ( strval( $ilLangName ) === '' ) {
110 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
111 if ( !$ilDisplayTextMsg->isDisabled() ) {
112 // Use custom MW message for the display text
113 $ilLangName = $ilDisplayTextMsg->text();
115 // Last resort: fallback to the language link target
116 $ilLangName = $languageLinkText;
119 // Use the language autonym as display text
120 $ilLangName = $this->formatLanguageName( $ilLangName );
123 // CLDR extension or similar is required to localize the language name;
124 // otherwise we'll end up with the autonym again.
125 $ilLangLocalName = Language
::fetchLanguageName(
130 $languageLinkTitleText = $languageLinkTitle->getText();
131 if ( $ilLangLocalName === '' ) {
132 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
133 if ( !$ilFriendlySiteName->isDisabled() ) {
134 if ( $languageLinkTitleText === '' ) {
135 $ilTitle = wfMessage(
136 'interlanguage-link-title-nonlangonly',
137 $ilFriendlySiteName->text()
140 $ilTitle = wfMessage(
141 'interlanguage-link-title-nonlang',
142 $languageLinkTitleText,
143 $ilFriendlySiteName->text()
147 // we have nothing friendly to put in the title, so fall back to
148 // displaying the interlanguage link itself in the title text
149 // (similar to what is done in page content)
150 $ilTitle = $languageLinkTitle->getInterwiki() .
151 ":$languageLinkTitleText";
153 } elseif ( $languageLinkTitleText === '' ) {
154 $ilTitle = wfMessage(
155 'interlanguage-link-title-langonly',
159 $ilTitle = wfMessage(
160 'interlanguage-link-title',
161 $languageLinkTitleText,
166 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
168 'href' => $languageLinkTitle->getFullURL(),
169 'text' => $ilLangName,
172 'lang' => $ilInterwikiCodeBCP47,
173 'hreflang' => $ilInterwikiCodeBCP47,
176 'SkinTemplateGetLanguageLink',
177 [ &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() ]
179 $languageLinks[] = $languageLink;
183 return $languageLinks;
186 protected function setupTemplateForOutput() {
188 $request = $this->getRequest();
189 $user = $this->getUser();
190 $title = $this->getTitle();
192 $tpl = $this->setupTemplate( $this->template
, 'skins' );
194 $this->thispage
= $title->getPrefixedDBkey();
195 $this->titletxt
= $title->getPrefixedText();
196 $this->userpage
= $user->getUserPage()->getPrefixedText();
198 if ( !$request->wasPosted() ) {
199 $query = $request->getValues();
200 unset( $query['title'] );
201 unset( $query['returnto'] );
202 unset( $query['returntoquery'] );
204 $this->thisquery
= wfArrayToCgi( $query );
205 $this->loggedin
= $user->isLoggedIn();
206 $this->username
= $user->getName();
208 if ( $this->loggedin
) {
209 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
211 # This won't be used in the standard skins, but we define it to preserve the interface
212 # To save time, we check for existence
213 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
220 * initialize various variables and generate the template
222 * @param OutputPage $out
224 function outputPage( OutputPage
$out = null ) {
225 Profiler
::instance()->setTemplated( true );
228 if ( $out !== null ) {
229 // Deprecated since 1.20, note added in 1.25
230 wfDeprecated( __METHOD__
, '1.25' );
231 $oldContext = $this->getContext();
232 $this->setContext( $out->getContext() );
235 $out = $this->getOutput();
237 $this->initPage( $out );
238 $tpl = $this->prepareQuickTemplate( $out );
240 $res = $tpl->execute();
242 // result may be an error
243 $this->printOrError( $res );
246 $this->setContext( $oldContext );
252 * Wrap the body text with language information and identifiable element
254 * @param Title $title
255 * @return string html
257 protected function wrapHTML( $title, $html ) {
258 # An ID that includes the actual body text; without categories, contentSub, ...
259 $realBodyAttribs = [ 'id' => 'mw-content-text' ];
261 # Add a mw-content-ltr/rtl class to be able to style based on text direction
262 # when the content is different from the UI language, i.e.:
263 # not for special pages or file pages AND only when viewing
264 if ( !in_array( $title->getNamespace(), [ NS_SPECIAL
, NS_FILE
] ) &&
265 Action
::getActionName( $this ) === 'view' ) {
266 $pageLang = $title->getPageViewLanguage();
267 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
268 $realBodyAttribs['dir'] = $pageLang->getDir();
269 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
272 return Html
::rawElement( 'div', $realBodyAttribs, $html );
276 * initialize various variables and generate the template
279 * @return QuickTemplate The template to be executed by outputPage
281 protected function prepareQuickTemplate() {
282 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
283 $wgSitename, $wgLogo, $wgMaxCredits,
284 $wgShowCreditsIfMax, $wgArticlePath,
285 $wgScriptPath, $wgServer;
287 $title = $this->getTitle();
288 $request = $this->getRequest();
289 $out = $this->getOutput();
290 $tpl = $this->setupTemplateForOutput();
292 $tpl->set( 'title', $out->getPageTitle() );
293 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
294 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
296 $tpl->setRef( 'thispage', $this->thispage
);
297 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
298 $tpl->set( 'titletext', $title->getText() );
299 $tpl->set( 'articleid', $title->getArticleID() );
301 $tpl->set( 'isarticle', $out->isArticle() );
303 $subpagestr = $this->subPageSubtitle();
304 if ( $subpagestr !== '' ) {
305 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
307 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
309 $undelete = $this->getUndeleteLink();
310 if ( $undelete === '' ) {
311 $tpl->set( 'undelete', '' );
313 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
316 $tpl->set( 'catlinks', $this->getCategories() );
317 if ( $out->isSyndicated() ) {
319 foreach ( $out->getSyndicationLinks() as $format => $link ) {
321 // Messages: feed-atom, feed-rss
322 'text' => $this->msg( "feed-$format" )->text(),
326 $tpl->setRef( 'feeds', $feeds );
328 $tpl->set( 'feeds', false );
331 $tpl->setRef( 'mimetype', $wgMimeType );
332 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
333 $tpl->set( 'charset', 'UTF-8' );
334 $tpl->setRef( 'wgScript', $wgScript );
335 $tpl->setRef( 'skinname', $this->skinname
);
336 $tpl->set( 'skinclass', get_class( $this ) );
337 $tpl->setRef( 'skin', $this );
338 $tpl->setRef( 'stylename', $this->stylename
);
339 $tpl->set( 'printable', $out->isPrintable() );
340 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
341 $tpl->setRef( 'loggedin', $this->loggedin
);
342 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
343 $tpl->set( 'searchaction', $this->escapeSearchLink() );
344 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
345 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
346 $tpl->setRef( 'stylepath', $wgStylePath );
347 $tpl->setRef( 'articlepath', $wgArticlePath );
348 $tpl->setRef( 'scriptpath', $wgScriptPath );
349 $tpl->setRef( 'serverurl', $wgServer );
350 $tpl->setRef( 'logopath', $wgLogo );
351 $tpl->setRef( 'sitename', $wgSitename );
353 $userLang = $this->getLanguage();
354 $userLangCode = $userLang->getHtmlCode();
355 $userLangDir = $userLang->getDir();
357 $tpl->set( 'lang', $userLangCode );
358 $tpl->set( 'dir', $userLangDir );
359 $tpl->set( 'rtl', $userLang->isRTL() );
361 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
362 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
363 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
364 $tpl->setRef( 'userpage', $this->userpage
);
365 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
366 $tpl->set( 'userlang', $userLangCode );
368 // Users can have their language set differently than the
369 // content of the wiki. For these users, tell the web browser
370 // that interface elements are in a different language.
371 $tpl->set( 'userlangattributes', '' );
372 $tpl->set( 'specialpageattributes', '' ); # obsolete
373 // Used by VectorBeta to insert HTML before content but after the
374 // heading for the page title. Defaults to empty string.
375 $tpl->set( 'prebodyhtml', '' );
377 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
378 $escUserlang = htmlspecialchars( $userLangCode );
379 $escUserdir = htmlspecialchars( $userLangDir );
380 // Attributes must be in double quotes because htmlspecialchars() doesn't
381 // escape single quotes
382 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
383 $tpl->set( 'userlangattributes', $attrs );
386 $tpl->set( 'newtalk', $this->getNewtalks() );
387 $tpl->set( 'logo', $this->logoText() );
389 $tpl->set( 'copyright', false );
391 $tpl->set( 'viewcount', false );
392 $tpl->set( 'lastmod', false );
393 $tpl->set( 'credits', false );
394 $tpl->set( 'numberofwatchingusers', false );
395 if ( $out->isArticle() && $title->exists() ) {
396 if ( $this->isRevisionCurrent() ) {
397 if ( $wgMaxCredits != 0 ) {
398 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
399 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
401 $tpl->set( 'lastmod', $this->lastModified() );
404 $tpl->set( 'copyright', $this->getCopyright() );
407 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
408 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
409 $tpl->set( 'disclaimer', $this->disclaimerLink() );
410 $tpl->set( 'privacy', $this->privacyLink() );
411 $tpl->set( 'about', $this->aboutLink() );
413 $tpl->set( 'footerlinks', [
416 'numberofwatchingusers',
427 global $wgFooterIcons;
428 $tpl->set( 'footericons', $wgFooterIcons );
429 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
430 if ( count( $footerIconsBlock ) > 0 ) {
431 foreach ( $footerIconsBlock as &$footerIcon ) {
432 if ( isset( $footerIcon['src'] ) ) {
433 if ( !isset( $footerIcon['width'] ) ) {
434 $footerIcon['width'] = 88;
436 if ( !isset( $footerIcon['height'] ) ) {
437 $footerIcon['height'] = 31;
442 unset( $tpl->data
['footericons'][$footerIconsKey] );
446 $tpl->set( 'indicators', $out->getIndicators() );
448 $tpl->set( 'sitenotice', $this->getSiteNotice() );
449 $tpl->set( 'bottomscripts', $this->bottomScripts() );
450 $tpl->set( 'printfooter', $this->printSource() );
451 // Wrap the bodyText with #mw-content-text element
452 $out->mBodytext
= $this->wrapHTML( $title, $out->mBodytext
);
453 $tpl->setRef( 'bodytext', $out->mBodytext
);
455 $language_urls = $this->getLanguages();
456 if ( count( $language_urls ) ) {
457 $tpl->setRef( 'language_urls', $language_urls );
459 $tpl->set( 'language_urls', false );
463 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
464 $content_navigation = $this->buildContentNavigationUrls();
465 $content_actions = $this->buildContentActionUrls( $content_navigation );
466 $tpl->setRef( 'content_navigation', $content_navigation );
467 $tpl->setRef( 'content_actions', $content_actions );
469 $tpl->set( 'sidebar', $this->buildSidebar() );
470 $tpl->set( 'nav_urls', $this->buildNavUrls() );
472 // Set the head scripts near the end, in case the above actions resulted in added scripts
473 $tpl->set( 'headelement', $out->headElement( $this ) );
475 $tpl->set( 'debug', '' );
476 $tpl->set( 'debughtml', $this->generateDebugHTML() );
477 $tpl->set( 'reporttime', wfReportTime() );
479 // original version by hansm
480 if ( !Hooks
::run( 'SkinTemplateOutputPageBeforeExec', [ &$this, &$tpl ] ) ) {
481 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
484 // Set the bodytext to another key so that skins can just output it on its own
485 // and output printfooter and debughtml separately
486 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
488 // Append printfooter and debughtml onto bodytext so that skins that
489 // were already using bodytext before they were split out don't suddenly
490 // start not outputting information.
491 $tpl->data
['bodytext'] .= Html
::rawElement(
493 [ 'class' => 'printfooter' ],
494 "\n{$tpl->data['printfooter']}"
496 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
498 // allow extensions adding stuff after the page content.
499 // See Skin::afterContentHook() for further documentation.
500 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
506 * Get the HTML for the p-personal list
509 public function getPersonalToolsList() {
510 $tpl = $this->setupTemplateForOutput();
511 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
513 foreach ( $tpl->getPersonalTools() as $key => $item ) {
514 $html .= $tpl->makeListItem( $key, $item );
520 * Format language name for use in sidebar interlanguage links list.
521 * By default it is capitalized.
523 * @param string $name Language name, e.g. "English" or "español"
527 function formatLanguageName( $name ) {
528 return $this->getLanguage()->ucfirst( $name );
532 * Output the string, or print error message if it's
533 * an error object of the appropriate type.
534 * For the base class, assume strings all around.
539 function printOrError( $str ) {
544 * Output a boolean indicating if buildPersonalUrls should output separate
545 * login and create account links or output a combined link
546 * By default we simply return a global config setting that affects most skins
547 * This is setup as a method so that like with $wgLogo and getLogo() a skin
548 * can override this setting and always output one or the other if it has
549 * a reason it can't output one of the two modes.
552 function useCombinedLoginLink() {
553 global $wgUseCombinedLoginLink;
554 return $wgUseCombinedLoginLink;
558 * build array of urls for personal toolbar
561 protected function buildPersonalUrls() {
562 $title = $this->getTitle();
563 $request = $this->getRequest();
564 $pageurl = $title->getLocalURL();
566 /* set up the default links for the personal toolbar */
569 # Due to bug 32276, if a user does not have read permissions,
570 # $this->getTitle() will just give Special:Badtitle, which is
571 # not especially useful as a returnto parameter. Use the title
572 # from the request instead, if there was one.
573 if ( $this->getUser()->isAllowed( 'read' ) ) {
574 $page = $this->getTitle();
576 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
578 $page = $request->getVal( 'returnto', $page );
580 if ( strval( $page ) !== '' ) {
581 $a['returnto'] = $page;
582 $query = $request->getVal( 'returntoquery', $this->thisquery
);
583 if ( $query != '' ) {
584 $a['returntoquery'] = $query;
588 $returnto = wfArrayToCgi( $a );
589 if ( $this->loggedin
) {
590 $personal_urls['userpage'] = [
591 'text' => $this->username
,
592 'href' => &$this->userpageUrlDetails
['href'],
593 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
594 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
597 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
598 $personal_urls['mytalk'] = [
599 'text' => $this->msg( 'mytalk' )->text(),
600 'href' => &$usertalkUrlDetails['href'],
601 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
602 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
604 $href = self
::makeSpecialUrl( 'Preferences' );
605 $personal_urls['preferences'] = [
606 'text' => $this->msg( 'mypreferences' )->text(),
608 'active' => ( $href == $pageurl )
611 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
612 $href = self
::makeSpecialUrl( 'Watchlist' );
613 $personal_urls['watchlist'] = [
614 'text' => $this->msg( 'mywatchlist' )->text(),
616 'active' => ( $href == $pageurl )
620 # We need to do an explicit check for Special:Contributions, as we
621 # have to match both the title, and the target, which could come
622 # from request values (Special:Contributions?target=Jimbo_Wales)
623 # or be specified in "sub page" form
624 # (Special:Contributions/Jimbo_Wales). The plot
625 # thickens, because the Title object is altered for special pages,
626 # so it doesn't contain the original alias-with-subpage.
627 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
628 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
629 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
630 $active = $spName == 'Contributions'
631 && ( ( $spPar && $spPar == $this->username
)
632 ||
$request->getText( 'target' ) == $this->username
);
637 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
638 $personal_urls['mycontris'] = [
639 'text' => $this->msg( 'mycontris' )->text(),
643 $personal_urls['logout'] = [
644 'text' => $this->msg( 'pt-userlogout' )->text(),
645 'href' => self
::makeSpecialUrl( 'Userlogout',
646 // userlogout link must always contain an & character, otherwise we might not be able
647 // to detect a buggy precaching proxy (bug 17790)
648 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
653 // No need to show Talk and Contributions to anons if they can't contribute!
654 if ( User
::groupHasPermission( '*', 'edit' ) ) {
656 // Because of caching, we can't link directly to the anonymous
657 // user page (for example [[User:127.0.0.1]]), talk page, and
658 // contributions pages. Instead we use the special page
659 // shortcuts (which work correctly regardless of caching). This
660 // means we can't determine whether these links are active or
661 // not, but since major skins (MonoBook, Vector) don't use this
662 // information, it's not a huge loss.
664 // Only show (red) link to anon user page if anon users are
665 // allowed to create that page
666 if ( User
::groupHasPermission( '*', 'createpage' ) ) {
667 $personal_urls[ 'anonuserpage' ] = [
668 'text' => $this->msg( 'anonuserpage' )->text(),
669 'href' => self
::makeSpecialUrlSubpage( 'Mypage', false ),
674 $personal_urls['anontalk'] = [
675 'text' => $this->msg( 'anontalk' )->text(),
676 'href' => self
::makeSpecialUrlSubpage( 'Mytalk', false ),
680 $personal_urls['anoncontribs'] = [
681 'text' => $this->msg( 'anoncontribs' )->text(),
682 'href' => self
::makeSpecialUrlSubpage( 'Mycontributions', false ),
687 $is_signup = $request->getText( 'type' ) === 'signup';
689 if ( $this->getUser()->isAllowed( 'createaccount' ) && !( $this->useCombinedLoginLink() ) ) {
690 $personal_urls[ 'createaccount' ] = [
691 'text' => $this->msg( 'pt-createaccount' )->text(),
692 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
693 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
697 $personal_urls['login'] = [
698 'text' => $this->msg( 'pt-login' )->text(),
699 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
700 'active' => $title->isSpecial( 'Userlogin' ) && !$is_signup,
704 Hooks
::run( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
705 return $personal_urls;
709 * Builds an array with tab definition
711 * @param Title $title Page Where the tab links to
712 * @param string|array $message Message key or an array of message keys (will fall back)
713 * @param bool $selected Display the tab as selected
714 * @param string $query Query string attached to tab URL
715 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
719 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
722 $classes[] = 'selected';
724 if ( $checkEdit && !$title->isKnown() ) {
726 if ( $query !== '' ) {
727 $query = 'action=edit&redlink=1&' . $query;
729 $query = 'action=edit&redlink=1';
733 // wfMessageFallback will nicely accept $message as an array of fallbacks
734 // or just a single key
735 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
736 if ( is_array( $message ) ) {
737 // for hook compatibility just keep the last message name
738 $message = end( $message );
740 if ( $msg->exists() ) {
741 $text = $msg->text();
744 $text = $wgContLang->getConverter()->convertNamespace(
745 MWNamespace
::getSubject( $title->getNamespace() ) );
749 if ( !Hooks
::run( 'SkinTemplateTabAction', [ &$this,
750 $title, $message, $selected, $checkEdit,
751 &$classes, &$query, &$text, &$result ] ) ) {
756 'class' => implode( ' ', $classes ),
758 'href' => $title->getLocalURL( $query ),
762 function makeTalkUrlDetails( $name, $urlaction = '' ) {
763 $title = Title
::newFromText( $name );
764 if ( !is_object( $title ) ) {
765 throw new MWException( __METHOD__
. " given invalid pagename $name" );
767 $title = $title->getTalkPage();
768 self
::checkTitle( $title, $name );
770 'href' => $title->getLocalURL( $urlaction ),
771 'exists' => $title->isKnown(),
776 * @todo is this even used?
778 function makeArticleUrlDetails( $name, $urlaction = '' ) {
779 $title = Title
::newFromText( $name );
780 $title = $title->getSubjectPage();
781 self
::checkTitle( $title, $name );
783 'href' => $title->getLocalURL( $urlaction ),
784 'exists' => $title->exists(),
789 * a structured array of links usually used for the tabs in a skin
791 * There are 4 standard sections
792 * namespaces: Used for namespace tabs like special, page, and talk namespaces
793 * views: Used for primary page views like read, edit, history
794 * actions: Used for most extra page actions like deletion, protection, etc...
795 * variants: Used to list the language variants for the page
797 * Each section's value is a key/value array of links for that section.
798 * The links themselves have these common keys:
799 * - class: The css classes to apply to the tab
800 * - text: The text to display on the tab
801 * - href: The href for the tab to point to
802 * - rel: An optional rel= for the tab's link
803 * - redundant: If true the tab will be dropped in skins using content_actions
804 * this is useful for tabs like "Read" which only have meaning in skins that
805 * take special meaning from the grouped structure of content_navigation
807 * Views also have an extra key which can be used:
808 * - primary: If this is not true skins like vector may try to hide the tab
809 * when the user has limited space in their browser window
811 * content_navigation using code also expects these ids to be present on the
812 * links, however these are usually automatically generated by SkinTemplate
813 * itself and are not necessary when using a hook. The only things these may
814 * matter to are people modifying content_navigation after it's initial creation:
815 * - id: A "preferred" id, most skins are best off outputting this preferred
816 * id for best compatibility.
817 * - tooltiponly: This is set to true for some tabs in cases where the system
818 * believes that the accesskey should not be added to the tab.
822 protected function buildContentNavigationUrls() {
823 global $wgDisableLangConversion;
825 // Display tabs for the relevant title rather than always the title itself
826 $title = $this->getRelevantTitle();
827 $onPage = $title->equals( $this->getTitle() );
829 $out = $this->getOutput();
830 $request = $this->getRequest();
831 $user = $this->getUser();
833 $content_navigation = [
841 $action = $request->getVal( 'action', 'view' );
843 $userCanRead = $title->quickUserCan( 'read', $user );
845 $preventActiveTabs = false;
846 Hooks
::run( 'SkinTemplatePreventOtherActiveTabs', [ &$this, &$preventActiveTabs ] );
848 // Checks if page is some kind of content
849 if ( $title->canExist() ) {
850 // Gets page objects for the related namespaces
851 $subjectPage = $title->getSubjectPage();
852 $talkPage = $title->getTalkPage();
854 // Determines if this is a talk page
855 $isTalk = $title->isTalkPage();
857 // Generates XML IDs from namespace names
858 $subjectId = $title->getNamespaceKey( '' );
860 if ( $subjectId == 'main' ) {
863 $talkId = "{$subjectId}_talk";
866 $skname = $this->skinname
;
868 // Adds namespace links
869 $subjectMsg = [ "nstab-$subjectId" ];
870 if ( $subjectPage->isMainPage() ) {
871 array_unshift( $subjectMsg, 'mainpage-nstab' );
873 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
874 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
876 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
877 $content_navigation['namespaces'][$talkId] = $this->tabAction(
878 $talkPage, [ "nstab-$talkId", 'talk' ], $isTalk && !$preventActiveTabs, '', $userCanRead
880 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
882 if ( $userCanRead ) {
883 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
884 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
886 // Adds view view link
887 if ( $title->exists() ||
$isForeignFile ) {
888 $content_navigation['views']['view'] = $this->tabAction(
889 $isTalk ?
$talkPage : $subjectPage,
890 [ "$skname-view-view", 'view' ],
891 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
893 // signal to hide this from simple content_actions
894 $content_navigation['views']['view']['redundant'] = true;
897 // If it is a non-local file, show a link to the file in its own repository
898 if ( $isForeignFile ) {
899 $file = $this->getWikiPage()->getFile();
900 $content_navigation['views']['view-foreign'] = [
902 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
903 setContext( $this->getContext() )->
904 params( $file->getRepo()->getDisplayName() )->text(),
905 'href' => $file->getDescriptionUrl(),
910 // Checks if user can edit the current page if it exists or create it otherwise
911 if ( $title->quickUserCan( 'edit', $user )
912 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
914 // Builds CSS class for talk page links
915 $isTalkClass = $isTalk ?
' istalk' : '';
916 // Whether the user is editing the page
917 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
918 // Whether to show the "Add a new section" tab
919 // Checks if this is a current rev of talk page and is not forced to be hidden
920 $showNewSection = !$out->forceHideNewSectionLink()
921 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
922 $section = $request->getVal( 'section' );
924 if ( $title->exists()
925 ||
( $title->getNamespace() == NS_MEDIAWIKI
926 && $title->getDefaultMessageText() !== false
929 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
931 $msgKey = $isForeignFile ?
'create-local' : 'create';
933 $content_navigation['views']['edit'] = [
934 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
938 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
939 ->setContext( $this->getContext() )->text(),
940 'href' => $title->getLocalURL( $this->editUrlOptions() ),
941 'primary' => !$isForeignFile, // don't collapse this in vector
945 if ( $showNewSection ) {
946 // Adds new section link
947 // $content_navigation['actions']['addsection']
948 $content_navigation['views']['addsection'] = [
949 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
950 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
951 ->setContext( $this->getContext() )->text(),
952 'href' => $title->getLocalURL( 'action=edit§ion=new' )
955 // Checks if the page has some kind of viewable content
956 } elseif ( $title->hasSourceText() ) {
957 // Adds view source view link
958 $content_navigation['views']['viewsource'] = [
959 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
960 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
961 ->setContext( $this->getContext() )->text(),
962 'href' => $title->getLocalURL( $this->editUrlOptions() ),
963 'primary' => true, // don't collapse this in vector
967 // Checks if the page exists
968 if ( $title->exists() ) {
969 // Adds history view link
970 $content_navigation['views']['history'] = [
971 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
972 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
973 ->setContext( $this->getContext() )->text(),
974 'href' => $title->getLocalURL( 'action=history' ),
977 if ( $title->quickUserCan( 'delete', $user ) ) {
978 $content_navigation['actions']['delete'] = [
979 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
980 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
981 ->setContext( $this->getContext() )->text(),
982 'href' => $title->getLocalURL( 'action=delete' )
986 if ( $title->quickUserCan( 'move', $user ) ) {
987 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
988 $content_navigation['actions']['move'] = [
989 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
990 'text' => wfMessageFallback( "$skname-action-move", 'move' )
991 ->setContext( $this->getContext() )->text(),
992 'href' => $moveTitle->getLocalURL()
996 // article doesn't exist or is deleted
997 if ( $user->isAllowed( 'deletedhistory' ) ) {
998 $n = $title->isDeleted();
1000 $undelTitle = SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
1001 // If the user can't undelete but can view deleted
1002 // history show them a "View .. deleted" tab instead.
1003 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1004 $content_navigation['actions']['undelete'] = [
1005 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1006 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1007 ->setContext( $this->getContext() )->numParams( $n )->text(),
1008 'href' => $undelTitle->getLocalURL()
1014 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1015 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
1017 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1018 $content_navigation['actions'][$mode] = [
1019 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1020 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1021 ->setContext( $this->getContext() )->text(),
1022 'href' => $title->getLocalURL( "action=$mode" )
1026 // Checks if the user is logged in
1027 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1029 * The following actions use messages which, if made particular to
1030 * the any specific skins, would break the Ajax code which makes this
1031 * action happen entirely inline. OutputPage::getJSVars
1032 * defines a set of messages in a javascript object - and these
1033 * messages are assumed to be global for all skins. Without making
1034 * a change to that procedure these messages will have to remain as
1035 * the global versions.
1037 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1038 $content_navigation['actions'][$mode] = [
1039 'class' => 'mw-watchlink ' . (
1040 $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : ''
1042 // uses 'watch' or 'unwatch' message
1043 'text' => $this->msg( $mode )->text(),
1044 'href' => $title->getLocalURL( [ 'action' => $mode ] )
1049 Hooks
::run( 'SkinTemplateNavigation', [ &$this, &$content_navigation ] );
1051 if ( $userCanRead && !$wgDisableLangConversion ) {
1052 $pageLang = $title->getPageLanguage();
1053 // Gets list of language variants
1054 $variants = $pageLang->getVariants();
1055 // Checks that language conversion is enabled and variants exist
1056 // And if it is not in the special namespace
1057 if ( count( $variants ) > 1 ) {
1058 // Gets preferred variant (note that user preference is
1059 // only possible for wiki content language variant)
1060 $preferred = $pageLang->getPreferredVariant();
1061 if ( Action
::getActionName( $this ) === 'view' ) {
1062 $params = $request->getQueryValues();
1063 unset( $params['title'] );
1067 // Loops over each variant
1068 foreach ( $variants as $code ) {
1069 // Gets variant name from language code
1070 $varname = $pageLang->getVariantname( $code );
1071 // Appends variant link
1072 $content_navigation['variants'][] = [
1073 'class' => ( $code == $preferred ) ?
'selected' : false,
1075 'href' => $title->getLocalURL( [ 'variant' => $code ] +
$params ),
1076 'lang' => wfBCP47( $code ),
1077 'hreflang' => wfBCP47( $code ),
1083 // If it's not content, it's got to be a special page
1084 $content_navigation['namespaces']['special'] = [
1085 'class' => 'selected',
1086 'text' => $this->msg( 'nstab-special' )->text(),
1087 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1088 'context' => 'subject'
1091 Hooks
::run( 'SkinTemplateNavigation::SpecialPage',
1092 [ &$this, &$content_navigation ] );
1095 // Equiv to SkinTemplateContentActions
1096 Hooks
::run( 'SkinTemplateNavigation::Universal', [ &$this, &$content_navigation ] );
1098 // Setup xml ids and tooltip info
1099 foreach ( $content_navigation as $section => &$links ) {
1100 foreach ( $links as $key => &$link ) {
1102 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1103 $xmlID = 'ca-nstab-' . $xmlID;
1104 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1106 $link['rel'] = 'discussion';
1107 } elseif ( $section == 'variants' ) {
1108 $xmlID = 'ca-varlang-' . $xmlID;
1110 $xmlID = 'ca-' . $xmlID;
1112 $link['id'] = $xmlID;
1116 # We don't want to give the watch tab an accesskey if the
1117 # page is being edited, because that conflicts with the
1118 # accesskey on the watch checkbox. We also don't want to
1119 # give the edit tab an accesskey, because that's fairly
1120 # superfluous and conflicts with an accesskey (Ctrl-E) often
1121 # used for editing in Safari.
1122 if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
1123 if ( isset( $content_navigation['views']['edit'] ) ) {
1124 $content_navigation['views']['edit']['tooltiponly'] = true;
1126 if ( isset( $content_navigation['actions']['watch'] ) ) {
1127 $content_navigation['actions']['watch']['tooltiponly'] = true;
1129 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1130 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1134 return $content_navigation;
1138 * an array of edit links by default used for the tabs
1139 * @param array $content_navigation
1142 private function buildContentActionUrls( $content_navigation ) {
1144 // content_actions has been replaced with content_navigation for backwards
1145 // compatibility and also for skins that just want simple tabs content_actions
1146 // is now built by flattening the content_navigation arrays into one
1148 $content_actions = [];
1150 foreach ( $content_navigation as $links ) {
1151 foreach ( $links as $key => $value ) {
1152 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1153 // Redundant tabs are dropped from content_actions
1157 // content_actions used to have ids built using the "ca-$key" pattern
1158 // so the xmlID based id is much closer to the actual $key that we want
1159 // for that reason we'll just strip out the ca- if present and use
1160 // the latter potion of the "id" as the $key
1161 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1162 $key = substr( $value['id'], 3 );
1165 if ( isset( $content_actions[$key] ) ) {
1166 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1167 "content_navigation into content_actions.\n" );
1171 $content_actions[$key] = $value;
1175 return $content_actions;
1179 * build array of common navigation links
1182 protected function buildNavUrls() {
1183 global $wgUploadNavigationUrl;
1185 $out = $this->getOutput();
1186 $request = $this->getRequest();
1189 $nav_urls['mainpage'] = [ 'href' => self
::makeMainPageUrl() ];
1190 if ( $wgUploadNavigationUrl ) {
1191 $nav_urls['upload'] = [ 'href' => $wgUploadNavigationUrl ];
1192 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1193 $nav_urls['upload'] = [ 'href' => self
::makeSpecialUrl( 'Upload' ) ];
1195 $nav_urls['upload'] = false;
1197 $nav_urls['specialpages'] = [ 'href' => self
::makeSpecialUrl( 'Specialpages' ) ];
1199 $nav_urls['print'] = false;
1200 $nav_urls['permalink'] = false;
1201 $nav_urls['info'] = false;
1202 $nav_urls['whatlinkshere'] = false;
1203 $nav_urls['recentchangeslinked'] = false;
1204 $nav_urls['contributions'] = false;
1205 $nav_urls['log'] = false;
1206 $nav_urls['blockip'] = false;
1207 $nav_urls['emailuser'] = false;
1208 $nav_urls['userrights'] = false;
1210 // A print stylesheet is attached to all pages, but nobody ever
1211 // figures that out. :) Add a link...
1212 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1213 $nav_urls['print'] = [
1214 'text' => $this->msg( 'printableversion' )->text(),
1215 'href' => $this->getTitle()->getLocalURL(
1216 $request->appendQueryValue( 'printable', 'yes' ) )
1220 if ( $out->isArticle() ) {
1221 // Also add a "permalink" while we're at it
1222 $revid = $this->getRevisionId();
1224 $nav_urls['permalink'] = [
1225 'text' => $this->msg( 'permalink' )->text(),
1226 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1230 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1231 Hooks
::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1232 [ &$this, &$nav_urls, &$revid, &$revid ] );
1235 if ( $out->isArticleRelated() ) {
1236 $nav_urls['whatlinkshere'] = [
1237 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1240 $nav_urls['info'] = [
1241 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1242 'href' => $this->getTitle()->getLocalURL( "action=info" )
1245 if ( $this->getTitle()->exists() ) {
1246 $nav_urls['recentchangeslinked'] = [
1247 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1252 $user = $this->getRelevantUser();
1254 $rootUser = $user->getName();
1256 $nav_urls['contributions'] = [
1257 'text' => $this->msg( 'contributions', $rootUser )->text(),
1258 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1259 'tooltip-params' => [ $rootUser ],
1262 $nav_urls['log'] = [
1263 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1266 if ( $this->getUser()->isAllowed( 'block' ) ) {
1267 $nav_urls['blockip'] = [
1268 'text' => $this->msg( 'blockip', $rootUser )->text(),
1269 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1273 if ( $this->showEmailUser( $user ) ) {
1274 $nav_urls['emailuser'] = [
1275 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1276 'tooltip-params' => [ $rootUser ],
1280 if ( !$user->isAnon() ) {
1281 $sur = new UserrightsPage
;
1282 $sur->setContext( $this->getContext() );
1283 if ( $sur->userCanExecute( $this->getUser() ) ) {
1284 $nav_urls['userrights'] = [
1285 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1295 * Generate strings used for xml 'id' names
1298 protected function getNameSpaceKey() {
1299 return $this->getTitle()->getNamespaceKey();