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 ) {
54 $out->addModuleStyles( array(
55 'mediawiki.legacy.shared',
56 'mediawiki.legacy.commonPrint',
57 'mediawiki.ui.button',
58 'mediawiki.sectionAnchor'
63 * Create the template engine object; we feed it a bunch of data
64 * and eventually it spits out some HTML. Should have interface
65 * roughly equivalent to PHPTAL 0.7.
67 * @param string $classname
68 * @param bool|string $repository Subdirectory where we keep template files
69 * @param bool|string $cache_dir
70 * @return QuickTemplate
73 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
74 return new $classname( $this->getConfig() );
78 * Generates array of language links for the current page
82 public function getLanguages() {
83 global $wgHideInterlanguageLinks;
84 if ( $wgHideInterlanguageLinks ) {
88 $userLang = $this->getLanguage();
89 $languageLinks = array();
91 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
92 $languageLinkParts = explode( ':', $languageLinkText, 2 );
93 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
94 unset( $languageLinkParts );
96 $languageLinkTitle = Title
::newFromText( $languageLinkText );
97 if ( $languageLinkTitle ) {
98 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
99 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
101 if ( strval( $ilLangName ) === '' ) {
102 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
103 if ( !$ilDisplayTextMsg->isDisabled() ) {
104 // Use custom MW message for the display text
105 $ilLangName = $ilDisplayTextMsg->text();
107 // Last resort: fallback to the language link target
108 $ilLangName = $languageLinkText;
111 // Use the language autonym as display text
112 $ilLangName = $this->formatLanguageName( $ilLangName );
115 // CLDR extension or similar is required to localize the language name;
116 // otherwise we'll end up with the autonym again.
117 $ilLangLocalName = Language
::fetchLanguageName(
122 $languageLinkTitleText = $languageLinkTitle->getText();
123 if ( $ilLangLocalName === '' ) {
124 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
125 if ( !$ilFriendlySiteName->isDisabled() ) {
126 if ( $languageLinkTitleText === '' ) {
127 $ilTitle = wfMessage(
128 'interlanguage-link-title-nonlangonly',
129 $ilFriendlySiteName->text()
132 $ilTitle = wfMessage(
133 'interlanguage-link-title-nonlang',
134 $languageLinkTitleText,
135 $ilFriendlySiteName->text()
139 // we have nothing friendly to put in the title, so fall back to
140 // displaying the interlanguage link itself in the title text
141 // (similar to what is done in page content)
142 $ilTitle = $languageLinkTitle->getInterwiki() .
143 ":$languageLinkTitleText";
145 } elseif ( $languageLinkTitleText === '' ) {
146 $ilTitle = wfMessage(
147 'interlanguage-link-title-langonly',
151 $ilTitle = wfMessage(
152 'interlanguage-link-title',
153 $languageLinkTitleText,
158 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
159 $languageLink = array(
160 'href' => $languageLinkTitle->getFullURL(),
161 'text' => $ilLangName,
164 'lang' => $ilInterwikiCodeBCP47,
165 'hreflang' => $ilInterwikiCodeBCP47,
168 'SkinTemplateGetLanguageLink',
169 array( &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() )
171 $languageLinks[] = $languageLink;
175 return $languageLinks;
178 protected function setupTemplateForOutput() {
180 $request = $this->getRequest();
181 $user = $this->getUser();
182 $title = $this->getTitle();
184 $tpl = $this->setupTemplate( $this->template
, 'skins' );
186 $this->thispage
= $title->getPrefixedDBkey();
187 $this->titletxt
= $title->getPrefixedText();
188 $this->userpage
= $user->getUserPage()->getPrefixedText();
190 if ( !$request->wasPosted() ) {
191 $query = $request->getValues();
192 unset( $query['title'] );
193 unset( $query['returnto'] );
194 unset( $query['returntoquery'] );
196 $this->thisquery
= wfArrayToCgi( $query );
197 $this->loggedin
= $user->isLoggedIn();
198 $this->username
= $user->getName();
200 if ( $this->loggedin ||
$this->showIPinHeader() ) {
201 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
203 # This won't be used in the standard skins, but we define it to preserve the interface
204 # To save time, we check for existence
205 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
212 * initialize various variables and generate the template
214 * @param OutputPage $out
216 function outputPage( OutputPage
$out = null ) {
217 Profiler
::instance()->setTemplated( true );
220 if ( $out !== null ) {
221 // Deprecated since 1.20, note added in 1.25
222 wfDeprecated( __METHOD__
, '1.25' );
223 $oldContext = $this->getContext();
224 $this->setContext( $out->getContext() );
227 $out = $this->getOutput();
229 $this->initPage( $out );
230 $tpl = $this->prepareQuickTemplate( $out );
232 $res = $tpl->execute();
234 // result may be an error
235 $this->printOrError( $res );
238 $this->setContext( $oldContext );
244 * initialize various variables and generate the template
247 * @return QuickTemplate The template to be executed by outputPage
249 protected function prepareQuickTemplate() {
250 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
251 $wgSitename, $wgLogo, $wgMaxCredits,
252 $wgShowCreditsIfMax, $wgArticlePath,
253 $wgScriptPath, $wgServer;
255 $title = $this->getTitle();
256 $request = $this->getRequest();
257 $out = $this->getOutput();
258 $tpl = $this->setupTemplateForOutput();
260 $tpl->set( 'title', $out->getPageTitle() );
261 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
262 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
264 $tpl->setRef( 'thispage', $this->thispage
);
265 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
266 $tpl->set( 'titletext', $title->getText() );
267 $tpl->set( 'articleid', $title->getArticleID() );
269 $tpl->set( 'isarticle', $out->isArticle() );
271 $subpagestr = $this->subPageSubtitle();
272 if ( $subpagestr !== '' ) {
273 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
275 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
277 $undelete = $this->getUndeleteLink();
278 if ( $undelete === '' ) {
279 $tpl->set( 'undelete', '' );
281 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
284 $tpl->set( 'catlinks', $this->getCategories() );
285 if ( $out->isSyndicated() ) {
287 foreach ( $out->getSyndicationLinks() as $format => $link ) {
288 $feeds[$format] = array(
289 // Messages: feed-atom, feed-rss
290 'text' => $this->msg( "feed-$format" )->text(),
294 $tpl->setRef( 'feeds', $feeds );
296 $tpl->set( 'feeds', false );
299 $tpl->setRef( 'mimetype', $wgMimeType );
300 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
301 $tpl->set( 'charset', 'UTF-8' );
302 $tpl->setRef( 'wgScript', $wgScript );
303 $tpl->setRef( 'skinname', $this->skinname
);
304 $tpl->set( 'skinclass', get_class( $this ) );
305 $tpl->setRef( 'skin', $this );
306 $tpl->setRef( 'stylename', $this->stylename
);
307 $tpl->set( 'printable', $out->isPrintable() );
308 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
309 $tpl->setRef( 'loggedin', $this->loggedin
);
310 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
311 $tpl->set( 'searchaction', $this->escapeSearchLink() );
312 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
313 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
314 $tpl->setRef( 'stylepath', $wgStylePath );
315 $tpl->setRef( 'articlepath', $wgArticlePath );
316 $tpl->setRef( 'scriptpath', $wgScriptPath );
317 $tpl->setRef( 'serverurl', $wgServer );
318 $tpl->setRef( 'logopath', $wgLogo );
319 $tpl->setRef( 'sitename', $wgSitename );
321 $userLang = $this->getLanguage();
322 $userLangCode = $userLang->getHtmlCode();
323 $userLangDir = $userLang->getDir();
325 $tpl->set( 'lang', $userLangCode );
326 $tpl->set( 'dir', $userLangDir );
327 $tpl->set( 'rtl', $userLang->isRTL() );
329 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
330 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
331 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
332 $tpl->setRef( 'userpage', $this->userpage
);
333 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
334 $tpl->set( 'userlang', $userLangCode );
336 // Users can have their language set differently than the
337 // content of the wiki. For these users, tell the web browser
338 // that interface elements are in a different language.
339 $tpl->set( 'userlangattributes', '' );
340 $tpl->set( 'specialpageattributes', '' ); # obsolete
341 // Used by VectorBeta to insert HTML before content but after the
342 // heading for the page title. Defaults to empty string.
343 $tpl->set( 'prebodyhtml', '' );
345 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
346 $escUserlang = htmlspecialchars( $userLangCode );
347 $escUserdir = htmlspecialchars( $userLangDir );
348 // Attributes must be in double quotes because htmlspecialchars() doesn't
349 // escape single quotes
350 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
351 $tpl->set( 'userlangattributes', $attrs );
354 $tpl->set( 'newtalk', $this->getNewtalks() );
355 $tpl->set( 'logo', $this->logoText() );
357 $tpl->set( 'copyright', false );
359 $tpl->set( 'viewcount', false );
360 $tpl->set( 'lastmod', false );
361 $tpl->set( 'credits', false );
362 $tpl->set( 'numberofwatchingusers', false );
363 if ( $out->isArticle() && $title->exists() ) {
364 if ( $this->isRevisionCurrent() ) {
365 if ( $wgMaxCredits != 0 ) {
366 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
367 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
369 $tpl->set( 'lastmod', $this->lastModified() );
372 $tpl->set( 'copyright', $this->getCopyright() );
375 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
376 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
377 $tpl->set( 'disclaimer', $this->disclaimerLink() );
378 $tpl->set( 'privacy', $this->privacyLink() );
379 $tpl->set( 'about', $this->aboutLink() );
381 $tpl->set( 'footerlinks', array(
384 'numberofwatchingusers',
395 global $wgFooterIcons;
396 $tpl->set( 'footericons', $wgFooterIcons );
397 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
398 if ( count( $footerIconsBlock ) > 0 ) {
399 foreach ( $footerIconsBlock as &$footerIcon ) {
400 if ( isset( $footerIcon['src'] ) ) {
401 if ( !isset( $footerIcon['width'] ) ) {
402 $footerIcon['width'] = 88;
404 if ( !isset( $footerIcon['height'] ) ) {
405 $footerIcon['height'] = 31;
410 unset( $tpl->data
['footericons'][$footerIconsKey] );
414 $tpl->set( 'indicators', $out->getIndicators() );
416 $tpl->set( 'sitenotice', $this->getSiteNotice() );
417 $tpl->set( 'bottomscripts', $this->bottomScripts() );
418 $tpl->set( 'printfooter', $this->printSource() );
420 # An ID that includes the actual body text; without categories, contentSub, ...
421 $realBodyAttribs = array( 'id' => 'mw-content-text' );
423 # Add a mw-content-ltr/rtl class to be able to style based on text direction
424 # when the content is different from the UI language, i.e.:
425 # not for special pages or file pages AND only when viewing AND if the page exists
426 # (or is in MW namespace, because that has default content)
427 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
428 Action
::getActionName( $this ) === 'view' &&
429 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
430 $pageLang = $title->getPageViewLanguage();
431 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
432 $realBodyAttribs['dir'] = $pageLang->getDir();
433 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
436 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
437 $tpl->setRef( 'bodytext', $out->mBodytext
);
439 $language_urls = $this->getLanguages();
440 if ( count( $language_urls ) ) {
441 $tpl->setRef( 'language_urls', $language_urls );
443 $tpl->set( 'language_urls', false );
447 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
448 $content_navigation = $this->buildContentNavigationUrls();
449 $content_actions = $this->buildContentActionUrls( $content_navigation );
450 $tpl->setRef( 'content_navigation', $content_navigation );
451 $tpl->setRef( 'content_actions', $content_actions );
453 $tpl->set( 'sidebar', $this->buildSidebar() );
454 $tpl->set( 'nav_urls', $this->buildNavUrls() );
456 // Set the head scripts near the end, in case the above actions resulted in added scripts
457 $tpl->set( 'headelement', $out->headElement( $this ) );
459 $tpl->set( 'debug', '' );
460 $tpl->set( 'debughtml', $this->generateDebugHTML() );
461 $tpl->set( 'reporttime', wfReportTime() );
463 // original version by hansm
464 if ( !Hooks
::run( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
465 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
468 // Set the bodytext to another key so that skins can just output it on its own
469 // and output printfooter and debughtml separately
470 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
472 // Append printfooter and debughtml onto bodytext so that skins that
473 // were already using bodytext before they were split out don't suddenly
474 // start not outputting information.
475 $tpl->data
['bodytext'] .= Html
::rawElement(
477 array( 'class' => 'printfooter' ),
478 "\n{$tpl->data['printfooter']}"
480 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
482 // allow extensions adding stuff after the page content.
483 // See Skin::afterContentHook() for further documentation.
484 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
490 * Get the HTML for the p-personal list
493 public function getPersonalToolsList() {
494 $tpl = $this->setupTemplateForOutput();
495 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
497 foreach ( $tpl->getPersonalTools() as $key => $item ) {
498 $html .= $tpl->makeListItem( $key, $item );
504 * Format language name for use in sidebar interlanguage links list.
505 * By default it is capitalized.
507 * @param string $name Language name, e.g. "English" or "español"
511 function formatLanguageName( $name ) {
512 return $this->getLanguage()->ucfirst( $name );
516 * Output the string, or print error message if it's
517 * an error object of the appropriate type.
518 * For the base class, assume strings all around.
523 function printOrError( $str ) {
528 * Output a boolean indicating if buildPersonalUrls should output separate
529 * login and create account links or output a combined link
530 * By default we simply return a global config setting that affects most skins
531 * This is setup as a method so that like with $wgLogo and getLogo() a skin
532 * can override this setting and always output one or the other if it has
533 * a reason it can't output one of the two modes.
536 function useCombinedLoginLink() {
537 global $wgUseCombinedLoginLink;
538 return $wgUseCombinedLoginLink;
542 * build array of urls for personal toolbar
545 protected function buildPersonalUrls() {
546 $title = $this->getTitle();
547 $request = $this->getRequest();
548 $pageurl = $title->getLocalURL();
550 /* set up the default links for the personal toolbar */
551 $personal_urls = array();
553 # Due to bug 32276, if a user does not have read permissions,
554 # $this->getTitle() will just give Special:Badtitle, which is
555 # not especially useful as a returnto parameter. Use the title
556 # from the request instead, if there was one.
557 if ( $this->getUser()->isAllowed( 'read' ) ) {
558 $page = $this->getTitle();
560 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
562 $page = $request->getVal( 'returnto', $page );
564 if ( strval( $page ) !== '' ) {
565 $a['returnto'] = $page;
566 $query = $request->getVal( 'returntoquery', $this->thisquery
);
567 if ( $query != '' ) {
568 $a['returntoquery'] = $query;
572 $returnto = wfArrayToCgi( $a );
573 if ( $this->loggedin
) {
574 $personal_urls['userpage'] = array(
575 'text' => $this->username
,
576 'href' => &$this->userpageUrlDetails
['href'],
577 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
578 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
581 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
582 $personal_urls['mytalk'] = array(
583 'text' => $this->msg( 'mytalk' )->text(),
584 'href' => &$usertalkUrlDetails['href'],
585 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
586 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
588 $href = self
::makeSpecialUrl( 'Preferences' );
589 $personal_urls['preferences'] = array(
590 'text' => $this->msg( 'mypreferences' )->text(),
592 'active' => ( $href == $pageurl )
595 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
596 $href = self
::makeSpecialUrl( 'Watchlist' );
597 $personal_urls['watchlist'] = array(
598 'text' => $this->msg( 'mywatchlist' )->text(),
600 'active' => ( $href == $pageurl )
604 # We need to do an explicit check for Special:Contributions, as we
605 # have to match both the title, and the target, which could come
606 # from request values (Special:Contributions?target=Jimbo_Wales)
607 # or be specified in "sub page" form
608 # (Special:Contributions/Jimbo_Wales). The plot
609 # thickens, because the Title object is altered for special pages,
610 # so it doesn't contain the original alias-with-subpage.
611 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
612 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
613 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
614 $active = $spName == 'Contributions'
615 && ( ( $spPar && $spPar == $this->username
)
616 ||
$request->getText( 'target' ) == $this->username
);
621 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
622 $personal_urls['mycontris'] = array(
623 'text' => $this->msg( 'mycontris' )->text(),
627 $personal_urls['logout'] = array(
628 'text' => $this->msg( 'pt-userlogout' )->text(),
629 'href' => self
::makeSpecialUrl( 'Userlogout',
630 // userlogout link must always contain an & character, otherwise we might not be able
631 // to detect a buggy precaching proxy (bug 17790)
632 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
637 $useCombinedLoginLink = $this->useCombinedLoginLink();
638 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
639 ?
'nav-login-createaccount'
641 $is_signup = $request->getText( 'type' ) == 'signup';
644 'text' => $this->msg( $loginlink )->text(),
645 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
646 'active' => $title->isSpecial( 'Userlogin' )
647 && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
649 $createaccount_url = array(
650 'text' => $this->msg( 'pt-createaccount' )->text(),
651 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
652 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
655 if ( $this->showIPinHeader() ) {
656 $href = &$this->userpageUrlDetails
['href'];
657 $personal_urls['anonuserpage'] = array(
658 'text' => $this->username
,
660 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
661 'active' => ( $pageurl == $href )
663 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
664 $href = &$usertalkUrlDetails['href'];
665 $personal_urls['anontalk'] = array(
666 'text' => $this->msg( 'anontalk' )->text(),
668 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
669 'active' => ( $pageurl == $href )
673 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
674 $personal_urls['createaccount'] = $createaccount_url;
677 $personal_urls['login'] = $login_url;
680 Hooks
::run( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
681 return $personal_urls;
685 * Builds an array with tab definition
687 * @param Title $title Page Where the tab links to
688 * @param string|array $message Message key or an array of message keys (will fall back)
689 * @param bool $selected Display the tab as selected
690 * @param string $query Query string attached to tab URL
691 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
695 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
698 $classes[] = 'selected';
700 if ( $checkEdit && !$title->isKnown() ) {
702 if ( $query !== '' ) {
703 $query = 'action=edit&redlink=1&' . $query;
705 $query = 'action=edit&redlink=1';
709 // wfMessageFallback will nicely accept $message as an array of fallbacks
710 // or just a single key
711 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
712 if ( is_array( $message ) ) {
713 // for hook compatibility just keep the last message name
714 $message = end( $message );
716 if ( $msg->exists() ) {
717 $text = $msg->text();
720 $text = $wgContLang->getFormattedNsText(
721 MWNamespace
::getSubject( $title->getNamespace() ) );
725 if ( !Hooks
::run( 'SkinTemplateTabAction', array( &$this,
726 $title, $message, $selected, $checkEdit,
727 &$classes, &$query, &$text, &$result ) ) ) {
732 'class' => implode( ' ', $classes ),
734 'href' => $title->getLocalURL( $query ),
738 function makeTalkUrlDetails( $name, $urlaction = '' ) {
739 $title = Title
::newFromText( $name );
740 if ( !is_object( $title ) ) {
741 throw new MWException( __METHOD__
. " given invalid pagename $name" );
743 $title = $title->getTalkPage();
744 self
::checkTitle( $title, $name );
746 'href' => $title->getLocalURL( $urlaction ),
747 'exists' => $title->isKnown(),
752 * @todo is this even used?
754 function makeArticleUrlDetails( $name, $urlaction = '' ) {
755 $title = Title
::newFromText( $name );
756 $title = $title->getSubjectPage();
757 self
::checkTitle( $title, $name );
759 'href' => $title->getLocalURL( $urlaction ),
760 'exists' => $title->exists(),
765 * a structured array of links usually used for the tabs in a skin
767 * There are 4 standard sections
768 * namespaces: Used for namespace tabs like special, page, and talk namespaces
769 * views: Used for primary page views like read, edit, history
770 * actions: Used for most extra page actions like deletion, protection, etc...
771 * variants: Used to list the language variants for the page
773 * Each section's value is a key/value array of links for that section.
774 * The links themselves have these common keys:
775 * - class: The css classes to apply to the tab
776 * - text: The text to display on the tab
777 * - href: The href for the tab to point to
778 * - rel: An optional rel= for the tab's link
779 * - redundant: If true the tab will be dropped in skins using content_actions
780 * this is useful for tabs like "Read" which only have meaning in skins that
781 * take special meaning from the grouped structure of content_navigation
783 * Views also have an extra key which can be used:
784 * - primary: If this is not true skins like vector may try to hide the tab
785 * when the user has limited space in their browser window
787 * content_navigation using code also expects these ids to be present on the
788 * links, however these are usually automatically generated by SkinTemplate
789 * itself and are not necessary when using a hook. The only things these may
790 * matter to are people modifying content_navigation after it's initial creation:
791 * - id: A "preferred" id, most skins are best off outputting this preferred
792 * id for best compatibility.
793 * - tooltiponly: This is set to true for some tabs in cases where the system
794 * believes that the accesskey should not be added to the tab.
798 protected function buildContentNavigationUrls() {
799 global $wgDisableLangConversion;
801 // Display tabs for the relevant title rather than always the title itself
802 $title = $this->getRelevantTitle();
803 $onPage = $title->equals( $this->getTitle() );
805 $out = $this->getOutput();
806 $request = $this->getRequest();
807 $user = $this->getUser();
809 $content_navigation = array(
810 'namespaces' => array(),
812 'actions' => array(),
813 'variants' => array()
817 $action = $request->getVal( 'action', 'view' );
819 $userCanRead = $title->quickUserCan( 'read', $user );
821 $preventActiveTabs = false;
822 Hooks
::run( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
824 // Checks if page is some kind of content
825 if ( $title->canExist() ) {
826 // Gets page objects for the related namespaces
827 $subjectPage = $title->getSubjectPage();
828 $talkPage = $title->getTalkPage();
830 // Determines if this is a talk page
831 $isTalk = $title->isTalkPage();
833 // Generates XML IDs from namespace names
834 $subjectId = $title->getNamespaceKey( '' );
836 if ( $subjectId == 'main' ) {
839 $talkId = "{$subjectId}_talk";
842 $skname = $this->skinname
;
844 // Adds namespace links
845 $subjectMsg = array( "nstab-$subjectId" );
846 if ( $subjectPage->isMainPage() ) {
847 array_unshift( $subjectMsg, 'mainpage-nstab' );
849 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
850 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
852 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
853 $content_navigation['namespaces'][$talkId] = $this->tabAction(
854 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
856 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
858 if ( $userCanRead ) {
859 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
860 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
862 // Adds view view link
863 if ( $title->exists() ||
$isForeignFile ) {
864 $content_navigation['views']['view'] = $this->tabAction(
865 $isTalk ?
$talkPage : $subjectPage,
866 array( "$skname-view-view", 'view' ),
867 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
869 // signal to hide this from simple content_actions
870 $content_navigation['views']['view']['redundant'] = true;
873 // If it is a non-local file, show a link to the file in its own repository
874 if ( $isForeignFile ) {
875 $file = $this->getWikiPage()->getFile();
876 $content_navigation['views']['view-foreign'] = array(
878 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
879 setContext( $this->getContext() )->
880 params( $file->getRepo()->getDisplayName() )->text(),
881 'href' => $file->getDescriptionUrl(),
886 // Checks if user can edit the current page if it exists or create it otherwise
887 if ( $title->quickUserCan( 'edit', $user )
888 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
890 // Builds CSS class for talk page links
891 $isTalkClass = $isTalk ?
' istalk' : '';
892 // Whether the user is editing the page
893 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
894 // Whether to show the "Add a new section" tab
895 // Checks if this is a current rev of talk page and is not forced to be hidden
896 $showNewSection = !$out->forceHideNewSectionLink()
897 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
898 $section = $request->getVal( 'section' );
900 if ( $title->exists()
901 ||
( $title->getNamespace() == NS_MEDIAWIKI
902 && $title->getDefaultMessageText() !== false
905 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
907 $msgKey = $isForeignFile ?
'create-local' : 'create';
909 $content_navigation['views']['edit'] = array(
910 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
914 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
915 ->setContext( $this->getContext() )->text(),
916 'href' => $title->getLocalURL( $this->editUrlOptions() ),
917 'primary' => !$isForeignFile, // don't collapse this in vector
921 if ( $showNewSection ) {
922 // Adds new section link
923 //$content_navigation['actions']['addsection']
924 $content_navigation['views']['addsection'] = array(
925 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
926 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
927 ->setContext( $this->getContext() )->text(),
928 'href' => $title->getLocalURL( 'action=edit§ion=new' )
931 // Checks if the page has some kind of viewable content
932 } elseif ( $title->hasSourceText() ) {
933 // Adds view source view link
934 $content_navigation['views']['viewsource'] = array(
935 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
936 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
937 ->setContext( $this->getContext() )->text(),
938 'href' => $title->getLocalURL( $this->editUrlOptions() ),
939 'primary' => true, // don't collapse this in vector
943 // Checks if the page exists
944 if ( $title->exists() ) {
945 // Adds history view link
946 $content_navigation['views']['history'] = array(
947 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
948 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
949 ->setContext( $this->getContext() )->text(),
950 'href' => $title->getLocalURL( 'action=history' ),
954 if ( $title->quickUserCan( 'delete', $user ) ) {
955 $content_navigation['actions']['delete'] = array(
956 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
957 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
958 ->setContext( $this->getContext() )->text(),
959 'href' => $title->getLocalURL( 'action=delete' )
963 if ( $title->quickUserCan( 'move', $user ) ) {
964 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
965 $content_navigation['actions']['move'] = array(
966 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
967 'text' => wfMessageFallback( "$skname-action-move", 'move' )
968 ->setContext( $this->getContext() )->text(),
969 'href' => $moveTitle->getLocalURL()
973 // article doesn't exist or is deleted
974 if ( $user->isAllowed( 'deletedhistory' ) ) {
975 $n = $title->isDeleted();
977 $undelTitle = SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
978 // If the user can't undelete but can view deleted
979 // history show them a "View .. deleted" tab instead.
980 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
981 $content_navigation['actions']['undelete'] = array(
982 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
983 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
984 ->setContext( $this->getContext() )->numParams( $n )->text(),
985 'href' => $undelTitle->getLocalURL()
991 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
992 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
994 $mode = $title->isProtected() ?
'unprotect' : 'protect';
995 $content_navigation['actions'][$mode] = array(
996 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
997 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
998 ->setContext( $this->getContext() )->text(),
999 'href' => $title->getLocalURL( "action=$mode" )
1003 // Checks if the user is logged in
1004 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1006 * The following actions use messages which, if made particular to
1007 * the any specific skins, would break the Ajax code which makes this
1008 * action happen entirely inline. OutputPage::getJSVars
1009 * defines a set of messages in a javascript object - and these
1010 * messages are assumed to be global for all skins. Without making
1011 * a change to that procedure these messages will have to remain as
1012 * the global versions.
1014 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1015 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1016 $content_navigation['actions'][$mode] = array(
1017 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1018 // uses 'watch' or 'unwatch' message
1019 'text' => $this->msg( $mode )->text(),
1020 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1025 Hooks
::run( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1027 if ( $userCanRead && !$wgDisableLangConversion ) {
1028 $pageLang = $title->getPageLanguage();
1029 // Gets list of language variants
1030 $variants = $pageLang->getVariants();
1031 // Checks that language conversion is enabled and variants exist
1032 // And if it is not in the special namespace
1033 if ( count( $variants ) > 1 ) {
1034 // Gets preferred variant (note that user preference is
1035 // only possible for wiki content language variant)
1036 $preferred = $pageLang->getPreferredVariant();
1037 if ( Action
::getActionName( $this ) === 'view' ) {
1038 $params = $request->getQueryValues();
1039 unset( $params['title'] );
1043 // Loops over each variant
1044 foreach ( $variants as $code ) {
1045 // Gets variant name from language code
1046 $varname = $pageLang->getVariantname( $code );
1047 // Appends variant link
1048 $content_navigation['variants'][] = array(
1049 'class' => ( $code == $preferred ) ?
'selected' : false,
1051 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1052 'lang' => wfBCP47( $code ),
1053 'hreflang' => wfBCP47( $code ),
1059 // If it's not content, it's got to be a special page
1060 $content_navigation['namespaces']['special'] = array(
1061 'class' => 'selected',
1062 'text' => $this->msg( 'nstab-special' )->text(),
1063 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1064 'context' => 'subject'
1067 Hooks
::run( 'SkinTemplateNavigation::SpecialPage',
1068 array( &$this, &$content_navigation ) );
1071 // Equiv to SkinTemplateContentActions
1072 Hooks
::run( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1074 // Setup xml ids and tooltip info
1075 foreach ( $content_navigation as $section => &$links ) {
1076 foreach ( $links as $key => &$link ) {
1078 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1079 $xmlID = 'ca-nstab-' . $xmlID;
1080 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1082 } elseif ( $section == 'variants' ) {
1083 $xmlID = 'ca-varlang-' . $xmlID;
1085 $xmlID = 'ca-' . $xmlID;
1087 $link['id'] = $xmlID;
1091 # We don't want to give the watch tab an accesskey if the
1092 # page is being edited, because that conflicts with the
1093 # accesskey on the watch checkbox. We also don't want to
1094 # give the edit tab an accesskey, because that's fairly
1095 # superfluous and conflicts with an accesskey (Ctrl-E) often
1096 # used for editing in Safari.
1097 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1098 if ( isset( $content_navigation['views']['edit'] ) ) {
1099 $content_navigation['views']['edit']['tooltiponly'] = true;
1101 if ( isset( $content_navigation['actions']['watch'] ) ) {
1102 $content_navigation['actions']['watch']['tooltiponly'] = true;
1104 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1105 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1109 return $content_navigation;
1113 * an array of edit links by default used for the tabs
1114 * @param array $content_navigation
1117 private function buildContentActionUrls( $content_navigation ) {
1119 // content_actions has been replaced with content_navigation for backwards
1120 // compatibility and also for skins that just want simple tabs content_actions
1121 // is now built by flattening the content_navigation arrays into one
1123 $content_actions = array();
1125 foreach ( $content_navigation as $links ) {
1126 foreach ( $links as $key => $value ) {
1127 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1128 // Redundant tabs are dropped from content_actions
1132 // content_actions used to have ids built using the "ca-$key" pattern
1133 // so the xmlID based id is much closer to the actual $key that we want
1134 // for that reason we'll just strip out the ca- if present and use
1135 // the latter potion of the "id" as the $key
1136 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1137 $key = substr( $value['id'], 3 );
1140 if ( isset( $content_actions[$key] ) ) {
1141 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1142 "content_navigation into content_actions.\n" );
1146 $content_actions[$key] = $value;
1150 return $content_actions;
1154 * build array of common navigation links
1157 protected function buildNavUrls() {
1158 global $wgUploadNavigationUrl;
1160 $out = $this->getOutput();
1161 $request = $this->getRequest();
1163 $nav_urls = array();
1164 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1165 if ( $wgUploadNavigationUrl ) {
1166 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1167 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1168 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1170 $nav_urls['upload'] = false;
1172 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1174 $nav_urls['print'] = false;
1175 $nav_urls['permalink'] = false;
1176 $nav_urls['info'] = false;
1177 $nav_urls['whatlinkshere'] = false;
1178 $nav_urls['recentchangeslinked'] = false;
1179 $nav_urls['contributions'] = false;
1180 $nav_urls['log'] = false;
1181 $nav_urls['blockip'] = false;
1182 $nav_urls['emailuser'] = false;
1183 $nav_urls['userrights'] = false;
1185 // A print stylesheet is attached to all pages, but nobody ever
1186 // figures that out. :) Add a link...
1187 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1188 $nav_urls['print'] = array(
1189 'text' => $this->msg( 'printableversion' )->text(),
1190 'href' => $this->getTitle()->getLocalURL(
1191 $request->appendQueryValue( 'printable', 'yes', true ) )
1195 if ( $out->isArticle() ) {
1196 // Also add a "permalink" while we're at it
1197 $revid = $this->getRevisionId();
1199 $nav_urls['permalink'] = array(
1200 'text' => $this->msg( 'permalink' )->text(),
1201 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1205 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1206 Hooks
::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1207 array( &$this, &$nav_urls, &$revid, &$revid ) );
1210 if ( $out->isArticleRelated() ) {
1211 $nav_urls['whatlinkshere'] = array(
1212 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1215 $nav_urls['info'] = array(
1216 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1217 'href' => $this->getTitle()->getLocalURL( "action=info" )
1220 if ( $this->getTitle()->exists() ) {
1221 $nav_urls['recentchangeslinked'] = array(
1222 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1227 $user = $this->getRelevantUser();
1229 $rootUser = $user->getName();
1231 $nav_urls['contributions'] = array(
1232 'text' => $this->msg( 'contributions', $rootUser )->text(),
1233 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1236 $nav_urls['log'] = array(
1237 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1240 if ( $this->getUser()->isAllowed( 'block' ) ) {
1241 $nav_urls['blockip'] = array(
1242 'text' => $this->msg( 'blockip', $rootUser )->text(),
1243 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1247 if ( $this->showEmailUser( $user ) ) {
1248 $nav_urls['emailuser'] = array(
1249 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1253 if ( !$user->isAnon() ) {
1254 $sur = new UserrightsPage
;
1255 $sur->setContext( $this->getContext() );
1256 if ( $sur->userCanExecute( $this->getUser() ) ) {
1257 $nav_urls['userrights'] = array(
1258 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1268 * Generate strings used for xml 'id' names
1271 protected function getNameSpaceKey() {
1272 return $this->getTitle()->getNamespaceKey();