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 $moduleStyles = array(
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();
99 $languageLinks = array();
101 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
102 $languageLinkParts = explode( ':', $languageLinkText, 2 );
103 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
104 unset( $languageLinkParts );
106 $languageLinkTitle = Title
::newFromText( $languageLinkText );
107 if ( $languageLinkTitle ) {
108 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
109 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
111 if ( strval( $ilLangName ) === '' ) {
112 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
113 if ( !$ilDisplayTextMsg->isDisabled() ) {
114 // Use custom MW message for the display text
115 $ilLangName = $ilDisplayTextMsg->text();
117 // Last resort: fallback to the language link target
118 $ilLangName = $languageLinkText;
121 // Use the language autonym as display text
122 $ilLangName = $this->formatLanguageName( $ilLangName );
125 // CLDR extension or similar is required to localize the language name;
126 // otherwise we'll end up with the autonym again.
127 $ilLangLocalName = Language
::fetchLanguageName(
132 $languageLinkTitleText = $languageLinkTitle->getText();
133 if ( $ilLangLocalName === '' ) {
134 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
135 if ( !$ilFriendlySiteName->isDisabled() ) {
136 if ( $languageLinkTitleText === '' ) {
137 $ilTitle = wfMessage(
138 'interlanguage-link-title-nonlangonly',
139 $ilFriendlySiteName->text()
142 $ilTitle = wfMessage(
143 'interlanguage-link-title-nonlang',
144 $languageLinkTitleText,
145 $ilFriendlySiteName->text()
149 // we have nothing friendly to put in the title, so fall back to
150 // displaying the interlanguage link itself in the title text
151 // (similar to what is done in page content)
152 $ilTitle = $languageLinkTitle->getInterwiki() .
153 ":$languageLinkTitleText";
155 } elseif ( $languageLinkTitleText === '' ) {
156 $ilTitle = wfMessage(
157 'interlanguage-link-title-langonly',
161 $ilTitle = wfMessage(
162 'interlanguage-link-title',
163 $languageLinkTitleText,
168 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
169 $languageLink = array(
170 'href' => $languageLinkTitle->getFullURL(),
171 'text' => $ilLangName,
174 'lang' => $ilInterwikiCodeBCP47,
175 'hreflang' => $ilInterwikiCodeBCP47,
178 'SkinTemplateGetLanguageLink',
179 array( &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() )
181 $languageLinks[] = $languageLink;
185 return $languageLinks;
188 protected function setupTemplateForOutput() {
190 $request = $this->getRequest();
191 $user = $this->getUser();
192 $title = $this->getTitle();
194 $tpl = $this->setupTemplate( $this->template
, 'skins' );
196 $this->thispage
= $title->getPrefixedDBkey();
197 $this->titletxt
= $title->getPrefixedText();
198 $this->userpage
= $user->getUserPage()->getPrefixedText();
200 if ( !$request->wasPosted() ) {
201 $query = $request->getValues();
202 unset( $query['title'] );
203 unset( $query['returnto'] );
204 unset( $query['returntoquery'] );
206 $this->thisquery
= wfArrayToCgi( $query );
207 $this->loggedin
= $user->isLoggedIn();
208 $this->username
= $user->getName();
210 if ( $this->loggedin
) {
211 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
213 # This won't be used in the standard skins, but we define it to preserve the interface
214 # To save time, we check for existence
215 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
222 * initialize various variables and generate the template
224 * @param OutputPage $out
226 function outputPage( OutputPage
$out = null ) {
227 Profiler
::instance()->setTemplated( true );
230 if ( $out !== null ) {
231 // Deprecated since 1.20, note added in 1.25
232 wfDeprecated( __METHOD__
, '1.25' );
233 $oldContext = $this->getContext();
234 $this->setContext( $out->getContext() );
237 $out = $this->getOutput();
239 $this->initPage( $out );
240 $tpl = $this->prepareQuickTemplate( $out );
242 $res = $tpl->execute();
244 // result may be an error
245 $this->printOrError( $res );
248 $this->setContext( $oldContext );
254 * initialize various variables and generate the template
257 * @return QuickTemplate The template to be executed by outputPage
259 protected function prepareQuickTemplate() {
260 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
261 $wgSitename, $wgLogo, $wgMaxCredits,
262 $wgShowCreditsIfMax, $wgArticlePath,
263 $wgScriptPath, $wgServer;
265 $title = $this->getTitle();
266 $request = $this->getRequest();
267 $out = $this->getOutput();
268 $tpl = $this->setupTemplateForOutput();
270 $tpl->set( 'title', $out->getPageTitle() );
271 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
272 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
274 $tpl->setRef( 'thispage', $this->thispage
);
275 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
276 $tpl->set( 'titletext', $title->getText() );
277 $tpl->set( 'articleid', $title->getArticleID() );
279 $tpl->set( 'isarticle', $out->isArticle() );
281 $subpagestr = $this->subPageSubtitle();
282 if ( $subpagestr !== '' ) {
283 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
285 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
287 $undelete = $this->getUndeleteLink();
288 if ( $undelete === '' ) {
289 $tpl->set( 'undelete', '' );
291 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
294 $tpl->set( 'catlinks', $this->getCategories() );
295 if ( $out->isSyndicated() ) {
297 foreach ( $out->getSyndicationLinks() as $format => $link ) {
298 $feeds[$format] = array(
299 // Messages: feed-atom, feed-rss
300 'text' => $this->msg( "feed-$format" )->text(),
304 $tpl->setRef( 'feeds', $feeds );
306 $tpl->set( 'feeds', false );
309 $tpl->setRef( 'mimetype', $wgMimeType );
310 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
311 $tpl->set( 'charset', 'UTF-8' );
312 $tpl->setRef( 'wgScript', $wgScript );
313 $tpl->setRef( 'skinname', $this->skinname
);
314 $tpl->set( 'skinclass', get_class( $this ) );
315 $tpl->setRef( 'skin', $this );
316 $tpl->setRef( 'stylename', $this->stylename
);
317 $tpl->set( 'printable', $out->isPrintable() );
318 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
319 $tpl->setRef( 'loggedin', $this->loggedin
);
320 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
321 $tpl->set( 'searchaction', $this->escapeSearchLink() );
322 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
323 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
324 $tpl->setRef( 'stylepath', $wgStylePath );
325 $tpl->setRef( 'articlepath', $wgArticlePath );
326 $tpl->setRef( 'scriptpath', $wgScriptPath );
327 $tpl->setRef( 'serverurl', $wgServer );
328 $tpl->setRef( 'logopath', $wgLogo );
329 $tpl->setRef( 'sitename', $wgSitename );
331 $userLang = $this->getLanguage();
332 $userLangCode = $userLang->getHtmlCode();
333 $userLangDir = $userLang->getDir();
335 $tpl->set( 'lang', $userLangCode );
336 $tpl->set( 'dir', $userLangDir );
337 $tpl->set( 'rtl', $userLang->isRTL() );
339 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
340 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
341 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
342 $tpl->setRef( 'userpage', $this->userpage
);
343 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
344 $tpl->set( 'userlang', $userLangCode );
346 // Users can have their language set differently than the
347 // content of the wiki. For these users, tell the web browser
348 // that interface elements are in a different language.
349 $tpl->set( 'userlangattributes', '' );
350 $tpl->set( 'specialpageattributes', '' ); # obsolete
351 // Used by VectorBeta to insert HTML before content but after the
352 // heading for the page title. Defaults to empty string.
353 $tpl->set( 'prebodyhtml', '' );
355 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->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 ( $out->isArticle() && $title->exists() ) {
374 if ( $this->isRevisionCurrent() ) {
375 if ( $wgMaxCredits != 0 ) {
376 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
377 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
379 $tpl->set( 'lastmod', $this->lastModified() );
382 $tpl->set( 'copyright', $this->getCopyright() );
385 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
386 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
387 $tpl->set( 'disclaimer', $this->disclaimerLink() );
388 $tpl->set( 'privacy', $this->privacyLink() );
389 $tpl->set( 'about', $this->aboutLink() );
391 $tpl->set( 'footerlinks', array(
394 'numberofwatchingusers',
405 global $wgFooterIcons;
406 $tpl->set( 'footericons', $wgFooterIcons );
407 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
408 if ( count( $footerIconsBlock ) > 0 ) {
409 foreach ( $footerIconsBlock as &$footerIcon ) {
410 if ( isset( $footerIcon['src'] ) ) {
411 if ( !isset( $footerIcon['width'] ) ) {
412 $footerIcon['width'] = 88;
414 if ( !isset( $footerIcon['height'] ) ) {
415 $footerIcon['height'] = 31;
420 unset( $tpl->data
['footericons'][$footerIconsKey] );
424 $tpl->set( 'indicators', $out->getIndicators() );
426 $tpl->set( 'sitenotice', $this->getSiteNotice() );
427 $tpl->set( 'bottomscripts', $this->bottomScripts() );
428 $tpl->set( 'printfooter', $this->printSource() );
430 # An ID that includes the actual body text; without categories, contentSub, ...
431 $realBodyAttribs = array( 'id' => 'mw-content-text' );
433 # Add a mw-content-ltr/rtl class to be able to style based on text direction
434 # when the content is different from the UI language, i.e.:
435 # not for special pages or file pages AND only when viewing
436 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
437 Action
::getActionName( $this ) === 'view' ) {
438 $pageLang = $title->getPageViewLanguage();
439 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
440 $realBodyAttribs['dir'] = $pageLang->getDir();
441 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
444 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
445 $tpl->setRef( 'bodytext', $out->mBodytext
);
447 $language_urls = $this->getLanguages();
448 if ( count( $language_urls ) ) {
449 $tpl->setRef( 'language_urls', $language_urls );
451 $tpl->set( 'language_urls', false );
455 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
456 $content_navigation = $this->buildContentNavigationUrls();
457 $content_actions = $this->buildContentActionUrls( $content_navigation );
458 $tpl->setRef( 'content_navigation', $content_navigation );
459 $tpl->setRef( 'content_actions', $content_actions );
461 $tpl->set( 'sidebar', $this->buildSidebar() );
462 $tpl->set( 'nav_urls', $this->buildNavUrls() );
464 // Set the head scripts near the end, in case the above actions resulted in added scripts
465 $tpl->set( 'headelement', $out->headElement( $this ) );
467 $tpl->set( 'debug', '' );
468 $tpl->set( 'debughtml', $this->generateDebugHTML() );
469 $tpl->set( 'reporttime', wfReportTime() );
471 // original version by hansm
472 if ( !Hooks
::run( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
473 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
476 // Set the bodytext to another key so that skins can just output it on its own
477 // and output printfooter and debughtml separately
478 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
480 // Append printfooter and debughtml onto bodytext so that skins that
481 // were already using bodytext before they were split out don't suddenly
482 // start not outputting information.
483 $tpl->data
['bodytext'] .= Html
::rawElement(
485 array( 'class' => 'printfooter' ),
486 "\n{$tpl->data['printfooter']}"
488 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
490 // allow extensions adding stuff after the page content.
491 // See Skin::afterContentHook() for further documentation.
492 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
498 * Get the HTML for the p-personal list
501 public function getPersonalToolsList() {
502 $tpl = $this->setupTemplateForOutput();
503 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
505 foreach ( $tpl->getPersonalTools() as $key => $item ) {
506 $html .= $tpl->makeListItem( $key, $item );
512 * Format language name for use in sidebar interlanguage links list.
513 * By default it is capitalized.
515 * @param string $name Language name, e.g. "English" or "español"
519 function formatLanguageName( $name ) {
520 return $this->getLanguage()->ucfirst( $name );
524 * Output the string, or print error message if it's
525 * an error object of the appropriate type.
526 * For the base class, assume strings all around.
531 function printOrError( $str ) {
536 * Output a boolean indicating if buildPersonalUrls should output separate
537 * login and create account links or output a combined link
538 * By default we simply return a global config setting that affects most skins
539 * This is setup as a method so that like with $wgLogo and getLogo() a skin
540 * can override this setting and always output one or the other if it has
541 * a reason it can't output one of the two modes.
544 function useCombinedLoginLink() {
545 global $wgUseCombinedLoginLink;
546 return $wgUseCombinedLoginLink;
550 * build array of urls for personal toolbar
553 protected function buildPersonalUrls() {
554 $title = $this->getTitle();
555 $request = $this->getRequest();
556 $pageurl = $title->getLocalURL();
558 /* set up the default links for the personal toolbar */
559 $personal_urls = array();
561 # Due to bug 32276, if a user does not have read permissions,
562 # $this->getTitle() will just give Special:Badtitle, which is
563 # not especially useful as a returnto parameter. Use the title
564 # from the request instead, if there was one.
565 if ( $this->getUser()->isAllowed( 'read' ) ) {
566 $page = $this->getTitle();
568 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
570 $page = $request->getVal( 'returnto', $page );
572 if ( strval( $page ) !== '' ) {
573 $a['returnto'] = $page;
574 $query = $request->getVal( 'returntoquery', $this->thisquery
);
575 if ( $query != '' ) {
576 $a['returntoquery'] = $query;
580 $returnto = wfArrayToCgi( $a );
581 if ( $this->loggedin
) {
582 $personal_urls['userpage'] = array(
583 'text' => $this->username
,
584 'href' => &$this->userpageUrlDetails
['href'],
585 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
586 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
589 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
590 $personal_urls['mytalk'] = array(
591 'text' => $this->msg( 'mytalk' )->text(),
592 'href' => &$usertalkUrlDetails['href'],
593 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
594 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
596 $href = self
::makeSpecialUrl( 'Preferences' );
597 $personal_urls['preferences'] = array(
598 'text' => $this->msg( 'mypreferences' )->text(),
600 'active' => ( $href == $pageurl )
603 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
604 $href = self
::makeSpecialUrl( 'Watchlist' );
605 $personal_urls['watchlist'] = array(
606 'text' => $this->msg( 'mywatchlist' )->text(),
608 'active' => ( $href == $pageurl )
612 # We need to do an explicit check for Special:Contributions, as we
613 # have to match both the title, and the target, which could come
614 # from request values (Special:Contributions?target=Jimbo_Wales)
615 # or be specified in "sub page" form
616 # (Special:Contributions/Jimbo_Wales). The plot
617 # thickens, because the Title object is altered for special pages,
618 # so it doesn't contain the original alias-with-subpage.
619 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
620 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
621 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
622 $active = $spName == 'Contributions'
623 && ( ( $spPar && $spPar == $this->username
)
624 ||
$request->getText( 'target' ) == $this->username
);
629 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
630 $personal_urls['mycontris'] = array(
631 'text' => $this->msg( 'mycontris' )->text(),
635 $personal_urls['logout'] = array(
636 'text' => $this->msg( 'pt-userlogout' )->text(),
637 'href' => self
::makeSpecialUrl( 'Userlogout',
638 // userlogout link must always contain an & character, otherwise we might not be able
639 // to detect a buggy precaching proxy (bug 17790)
640 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
645 $useCombinedLoginLink = $this->useCombinedLoginLink();
646 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
647 ?
'nav-login-createaccount'
649 $is_signup = $request->getText( 'type' ) == 'signup';
652 'text' => $this->msg( $loginlink )->text(),
653 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
654 'active' => $title->isSpecial( 'Userlogin' )
655 && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
657 $createaccount_url = array(
658 'text' => $this->msg( 'pt-createaccount' )->text(),
659 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
660 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
663 // No need to show Talk and Contributions to anons if they can't contribute!
664 if ( User
::groupHasPermission( '*', 'edit' ) ) {
665 // Show the text "Not logged in"
666 $personal_urls['anonuserpage'] = array(
667 'text' => $this->msg( 'notloggedin' )->text()
670 // Because of caching, we can't link directly to the IP talk and
671 // contributions pages. Instead we use the special page shortcuts
672 // (which work correctly regardless of caching). This means we can't
673 // determine whether these links are active or not, but since major
674 // skins (MonoBook, Vector) don't use this information, it's not a
676 $personal_urls['anontalk'] = array(
677 'text' => $this->msg( 'anontalk' )->text(),
678 'href' => self
::makeSpecialUrlSubpage( 'Mytalk', false ),
681 $personal_urls['anoncontribs'] = array(
682 'text' => $this->msg( 'anoncontribs' )->text(),
683 'href' => self
::makeSpecialUrlSubpage( 'Mycontributions', false ),
688 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
689 $personal_urls['createaccount'] = $createaccount_url;
692 $personal_urls['login'] = $login_url;
695 Hooks
::run( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
696 return $personal_urls;
700 * Builds an array with tab definition
702 * @param Title $title Page Where the tab links to
703 * @param string|array $message Message key or an array of message keys (will fall back)
704 * @param bool $selected Display the tab as selected
705 * @param string $query Query string attached to tab URL
706 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
710 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
713 $classes[] = 'selected';
715 if ( $checkEdit && !$title->isKnown() ) {
717 if ( $query !== '' ) {
718 $query = 'action=edit&redlink=1&' . $query;
720 $query = 'action=edit&redlink=1';
724 // wfMessageFallback will nicely accept $message as an array of fallbacks
725 // or just a single key
726 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
727 if ( is_array( $message ) ) {
728 // for hook compatibility just keep the last message name
729 $message = end( $message );
731 if ( $msg->exists() ) {
732 $text = $msg->text();
735 $text = $wgContLang->getConverter()->convertNamespace(
736 MWNamespace
::getSubject( $title->getNamespace() ) );
740 if ( !Hooks
::run( 'SkinTemplateTabAction', array( &$this,
741 $title, $message, $selected, $checkEdit,
742 &$classes, &$query, &$text, &$result ) ) ) {
747 'class' => implode( ' ', $classes ),
749 'href' => $title->getLocalURL( $query ),
753 function makeTalkUrlDetails( $name, $urlaction = '' ) {
754 $title = Title
::newFromText( $name );
755 if ( !is_object( $title ) ) {
756 throw new MWException( __METHOD__
. " given invalid pagename $name" );
758 $title = $title->getTalkPage();
759 self
::checkTitle( $title, $name );
761 'href' => $title->getLocalURL( $urlaction ),
762 'exists' => $title->isKnown(),
767 * @todo is this even used?
769 function makeArticleUrlDetails( $name, $urlaction = '' ) {
770 $title = Title
::newFromText( $name );
771 $title = $title->getSubjectPage();
772 self
::checkTitle( $title, $name );
774 'href' => $title->getLocalURL( $urlaction ),
775 'exists' => $title->exists(),
780 * a structured array of links usually used for the tabs in a skin
782 * There are 4 standard sections
783 * namespaces: Used for namespace tabs like special, page, and talk namespaces
784 * views: Used for primary page views like read, edit, history
785 * actions: Used for most extra page actions like deletion, protection, etc...
786 * variants: Used to list the language variants for the page
788 * Each section's value is a key/value array of links for that section.
789 * The links themselves have these common keys:
790 * - class: The css classes to apply to the tab
791 * - text: The text to display on the tab
792 * - href: The href for the tab to point to
793 * - rel: An optional rel= for the tab's link
794 * - redundant: If true the tab will be dropped in skins using content_actions
795 * this is useful for tabs like "Read" which only have meaning in skins that
796 * take special meaning from the grouped structure of content_navigation
798 * Views also have an extra key which can be used:
799 * - primary: If this is not true skins like vector may try to hide the tab
800 * when the user has limited space in their browser window
802 * content_navigation using code also expects these ids to be present on the
803 * links, however these are usually automatically generated by SkinTemplate
804 * itself and are not necessary when using a hook. The only things these may
805 * matter to are people modifying content_navigation after it's initial creation:
806 * - id: A "preferred" id, most skins are best off outputting this preferred
807 * id for best compatibility.
808 * - tooltiponly: This is set to true for some tabs in cases where the system
809 * believes that the accesskey should not be added to the tab.
813 protected function buildContentNavigationUrls() {
814 global $wgDisableLangConversion;
816 // Display tabs for the relevant title rather than always the title itself
817 $title = $this->getRelevantTitle();
818 $onPage = $title->equals( $this->getTitle() );
820 $out = $this->getOutput();
821 $request = $this->getRequest();
822 $user = $this->getUser();
824 $content_navigation = array(
825 'namespaces' => array(),
827 'actions' => array(),
828 'variants' => array()
832 $action = $request->getVal( 'action', 'view' );
834 $userCanRead = $title->quickUserCan( 'read', $user );
836 $preventActiveTabs = false;
837 Hooks
::run( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
839 // Checks if page is some kind of content
840 if ( $title->canExist() ) {
841 // Gets page objects for the related namespaces
842 $subjectPage = $title->getSubjectPage();
843 $talkPage = $title->getTalkPage();
845 // Determines if this is a talk page
846 $isTalk = $title->isTalkPage();
848 // Generates XML IDs from namespace names
849 $subjectId = $title->getNamespaceKey( '' );
851 if ( $subjectId == 'main' ) {
854 $talkId = "{$subjectId}_talk";
857 $skname = $this->skinname
;
859 // Adds namespace links
860 $subjectMsg = array( "nstab-$subjectId" );
861 if ( $subjectPage->isMainPage() ) {
862 array_unshift( $subjectMsg, 'mainpage-nstab' );
864 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
865 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
867 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
868 $content_navigation['namespaces'][$talkId] = $this->tabAction(
869 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
871 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
873 if ( $userCanRead ) {
874 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
875 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
877 // Adds view view link
878 if ( $title->exists() ||
$isForeignFile ) {
879 $content_navigation['views']['view'] = $this->tabAction(
880 $isTalk ?
$talkPage : $subjectPage,
881 array( "$skname-view-view", 'view' ),
882 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
884 // signal to hide this from simple content_actions
885 $content_navigation['views']['view']['redundant'] = true;
888 // If it is a non-local file, show a link to the file in its own repository
889 if ( $isForeignFile ) {
890 $file = $this->getWikiPage()->getFile();
891 $content_navigation['views']['view-foreign'] = array(
893 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
894 setContext( $this->getContext() )->
895 params( $file->getRepo()->getDisplayName() )->text(),
896 'href' => $file->getDescriptionUrl(),
901 // Checks if user can edit the current page if it exists or create it otherwise
902 if ( $title->quickUserCan( 'edit', $user )
903 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
905 // Builds CSS class for talk page links
906 $isTalkClass = $isTalk ?
' istalk' : '';
907 // Whether the user is editing the page
908 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
909 // Whether to show the "Add a new section" tab
910 // Checks if this is a current rev of talk page and is not forced to be hidden
911 $showNewSection = !$out->forceHideNewSectionLink()
912 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
913 $section = $request->getVal( 'section' );
915 if ( $title->exists()
916 ||
( $title->getNamespace() == NS_MEDIAWIKI
917 && $title->getDefaultMessageText() !== false
920 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
922 $msgKey = $isForeignFile ?
'create-local' : 'create';
924 $content_navigation['views']['edit'] = array(
925 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
929 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
930 ->setContext( $this->getContext() )->text(),
931 'href' => $title->getLocalURL( $this->editUrlOptions() ),
932 'primary' => !$isForeignFile, // don't collapse this in vector
936 if ( $showNewSection ) {
937 // Adds new section link
938 // $content_navigation['actions']['addsection']
939 $content_navigation['views']['addsection'] = array(
940 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
941 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
942 ->setContext( $this->getContext() )->text(),
943 'href' => $title->getLocalURL( 'action=edit§ion=new' )
946 // Checks if the page has some kind of viewable content
947 } elseif ( $title->hasSourceText() ) {
948 // Adds view source view link
949 $content_navigation['views']['viewsource'] = array(
950 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
951 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
952 ->setContext( $this->getContext() )->text(),
953 'href' => $title->getLocalURL( $this->editUrlOptions() ),
954 'primary' => true, // don't collapse this in vector
958 // Checks if the page exists
959 if ( $title->exists() ) {
960 // Adds history view link
961 $content_navigation['views']['history'] = array(
962 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
963 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
964 ->setContext( $this->getContext() )->text(),
965 'href' => $title->getLocalURL( 'action=history' ),
968 if ( $title->quickUserCan( 'delete', $user ) ) {
969 $content_navigation['actions']['delete'] = array(
970 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
971 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
972 ->setContext( $this->getContext() )->text(),
973 'href' => $title->getLocalURL( 'action=delete' )
977 if ( $title->quickUserCan( 'move', $user ) ) {
978 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
979 $content_navigation['actions']['move'] = array(
980 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
981 'text' => wfMessageFallback( "$skname-action-move", 'move' )
982 ->setContext( $this->getContext() )->text(),
983 'href' => $moveTitle->getLocalURL()
987 // article doesn't exist or is deleted
988 if ( $user->isAllowed( 'deletedhistory' ) ) {
989 $n = $title->isDeleted();
991 $undelTitle = SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
992 // If the user can't undelete but can view deleted
993 // history show them a "View .. deleted" tab instead.
994 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
995 $content_navigation['actions']['undelete'] = array(
996 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
997 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
998 ->setContext( $this->getContext() )->numParams( $n )->text(),
999 'href' => $undelTitle->getLocalURL()
1005 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1006 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1008 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1009 $content_navigation['actions'][$mode] = array(
1010 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1011 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1012 ->setContext( $this->getContext() )->text(),
1013 'href' => $title->getLocalURL( "action=$mode" )
1017 // Checks if the user is logged in
1018 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1020 * The following actions use messages which, if made particular to
1021 * the any specific skins, would break the Ajax code which makes this
1022 * action happen entirely inline. OutputPage::getJSVars
1023 * defines a set of messages in a javascript object - and these
1024 * messages are assumed to be global for all skins. Without making
1025 * a change to that procedure these messages will have to remain as
1026 * the global versions.
1028 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1029 $content_navigation['actions'][$mode] = array(
1030 'class' => 'mw-watchlink ' . (
1031 $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : ''
1033 // uses 'watch' or 'unwatch' message
1034 'text' => $this->msg( $mode )->text(),
1035 'href' => $title->getLocalURL( array( 'action' => $mode ) )
1040 Hooks
::run( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1042 if ( $userCanRead && !$wgDisableLangConversion ) {
1043 $pageLang = $title->getPageLanguage();
1044 // Gets list of language variants
1045 $variants = $pageLang->getVariants();
1046 // Checks that language conversion is enabled and variants exist
1047 // And if it is not in the special namespace
1048 if ( count( $variants ) > 1 ) {
1049 // Gets preferred variant (note that user preference is
1050 // only possible for wiki content language variant)
1051 $preferred = $pageLang->getPreferredVariant();
1052 if ( Action
::getActionName( $this ) === 'view' ) {
1053 $params = $request->getQueryValues();
1054 unset( $params['title'] );
1058 // Loops over each variant
1059 foreach ( $variants as $code ) {
1060 // Gets variant name from language code
1061 $varname = $pageLang->getVariantname( $code );
1062 // Appends variant link
1063 $content_navigation['variants'][] = array(
1064 'class' => ( $code == $preferred ) ?
'selected' : false,
1066 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1067 'lang' => wfBCP47( $code ),
1068 'hreflang' => wfBCP47( $code ),
1074 // If it's not content, it's got to be a special page
1075 $content_navigation['namespaces']['special'] = array(
1076 'class' => 'selected',
1077 'text' => $this->msg( 'nstab-special' )->text(),
1078 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1079 'context' => 'subject'
1082 Hooks
::run( 'SkinTemplateNavigation::SpecialPage',
1083 array( &$this, &$content_navigation ) );
1086 // Equiv to SkinTemplateContentActions
1087 Hooks
::run( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1089 // Setup xml ids and tooltip info
1090 foreach ( $content_navigation as $section => &$links ) {
1091 foreach ( $links as $key => &$link ) {
1093 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1094 $xmlID = 'ca-nstab-' . $xmlID;
1095 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1097 $link['rel'] = 'discussion';
1098 } elseif ( $section == 'variants' ) {
1099 $xmlID = 'ca-varlang-' . $xmlID;
1101 $xmlID = 'ca-' . $xmlID;
1103 $link['id'] = $xmlID;
1107 # We don't want to give the watch tab an accesskey if the
1108 # page is being edited, because that conflicts with the
1109 # accesskey on the watch checkbox. We also don't want to
1110 # give the edit tab an accesskey, because that's fairly
1111 # superfluous and conflicts with an accesskey (Ctrl-E) often
1112 # used for editing in Safari.
1113 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1114 if ( isset( $content_navigation['views']['edit'] ) ) {
1115 $content_navigation['views']['edit']['tooltiponly'] = true;
1117 if ( isset( $content_navigation['actions']['watch'] ) ) {
1118 $content_navigation['actions']['watch']['tooltiponly'] = true;
1120 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1121 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1125 return $content_navigation;
1129 * an array of edit links by default used for the tabs
1130 * @param array $content_navigation
1133 private function buildContentActionUrls( $content_navigation ) {
1135 // content_actions has been replaced with content_navigation for backwards
1136 // compatibility and also for skins that just want simple tabs content_actions
1137 // is now built by flattening the content_navigation arrays into one
1139 $content_actions = array();
1141 foreach ( $content_navigation as $links ) {
1142 foreach ( $links as $key => $value ) {
1143 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1144 // Redundant tabs are dropped from content_actions
1148 // content_actions used to have ids built using the "ca-$key" pattern
1149 // so the xmlID based id is much closer to the actual $key that we want
1150 // for that reason we'll just strip out the ca- if present and use
1151 // the latter potion of the "id" as the $key
1152 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1153 $key = substr( $value['id'], 3 );
1156 if ( isset( $content_actions[$key] ) ) {
1157 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1158 "content_navigation into content_actions.\n" );
1162 $content_actions[$key] = $value;
1166 return $content_actions;
1170 * build array of common navigation links
1173 protected function buildNavUrls() {
1174 global $wgUploadNavigationUrl;
1176 $out = $this->getOutput();
1177 $request = $this->getRequest();
1179 $nav_urls = array();
1180 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1181 if ( $wgUploadNavigationUrl ) {
1182 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1183 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1184 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1186 $nav_urls['upload'] = false;
1188 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1190 $nav_urls['print'] = false;
1191 $nav_urls['permalink'] = false;
1192 $nav_urls['info'] = false;
1193 $nav_urls['whatlinkshere'] = false;
1194 $nav_urls['recentchangeslinked'] = false;
1195 $nav_urls['contributions'] = false;
1196 $nav_urls['log'] = false;
1197 $nav_urls['blockip'] = false;
1198 $nav_urls['emailuser'] = false;
1199 $nav_urls['userrights'] = false;
1201 // A print stylesheet is attached to all pages, but nobody ever
1202 // figures that out. :) Add a link...
1203 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1204 $nav_urls['print'] = array(
1205 'text' => $this->msg( 'printableversion' )->text(),
1206 'href' => $this->getTitle()->getLocalURL(
1207 $request->appendQueryValue( 'printable', 'yes' ) )
1211 if ( $out->isArticle() ) {
1212 // Also add a "permalink" while we're at it
1213 $revid = $this->getRevisionId();
1215 $nav_urls['permalink'] = array(
1216 'text' => $this->msg( 'permalink' )->text(),
1217 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1221 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1222 Hooks
::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1223 array( &$this, &$nav_urls, &$revid, &$revid ) );
1226 if ( $out->isArticleRelated() ) {
1227 $nav_urls['whatlinkshere'] = array(
1228 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1231 $nav_urls['info'] = array(
1232 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1233 'href' => $this->getTitle()->getLocalURL( "action=info" )
1236 if ( $this->getTitle()->exists() ) {
1237 $nav_urls['recentchangeslinked'] = array(
1238 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1243 $user = $this->getRelevantUser();
1245 $rootUser = $user->getName();
1247 $nav_urls['contributions'] = array(
1248 'text' => $this->msg( 'contributions', $rootUser )->text(),
1249 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1250 'tooltip-params' => array( $rootUser ),
1253 $nav_urls['log'] = array(
1254 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1257 if ( $this->getUser()->isAllowed( 'block' ) ) {
1258 $nav_urls['blockip'] = array(
1259 'text' => $this->msg( 'blockip', $rootUser )->text(),
1260 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1264 if ( $this->showEmailUser( $user ) ) {
1265 $nav_urls['emailuser'] = array(
1266 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1267 'tooltip-params' => array( $rootUser ),
1271 if ( !$user->isAnon() ) {
1272 $sur = new UserrightsPage
;
1273 $sur->setContext( $this->getContext() );
1274 if ( $sur->userCanExecute( $this->getUser() ) ) {
1275 $nav_urls['userrights'] = array(
1276 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1286 * Generate strings used for xml 'id' names
1289 protected function getNameSpaceKey() {
1290 return $this->getTitle()->getNamespaceKey();