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',
62 * Create the template engine object; we feed it a bunch of data
63 * and eventually it spits out some HTML. Should have interface
64 * roughly equivalent to PHPTAL 0.7.
66 * @param string $classname
67 * @param bool|string $repository Subdirectory where we keep template files
68 * @param bool|string $cache_dir
69 * @return QuickTemplate
72 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
73 return new $classname( $this->getConfig() );
77 * Generates array of language links for the current page
81 public function getLanguages() {
82 global $wgHideInterlanguageLinks;
83 if ( $wgHideInterlanguageLinks ) {
87 $userLang = $this->getLanguage();
88 $languageLinks = array();
90 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
91 $languageLinkParts = explode( ':', $languageLinkText, 2 );
92 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
93 unset( $languageLinkParts );
95 $languageLinkTitle = Title
::newFromText( $languageLinkText );
96 if ( $languageLinkTitle ) {
97 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
98 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
100 if ( strval( $ilLangName ) === '' ) {
101 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
102 if ( !$ilDisplayTextMsg->isDisabled() ) {
103 // Use custom MW message for the display text
104 $ilLangName = $ilDisplayTextMsg->text();
106 // Last resort: fallback to the language link target
107 $ilLangName = $languageLinkText;
110 // Use the language autonym as display text
111 $ilLangName = $this->formatLanguageName( $ilLangName );
114 // CLDR extension or similar is required to localize the language name;
115 // otherwise we'll end up with the autonym again.
116 $ilLangLocalName = Language
::fetchLanguageName(
121 $languageLinkTitleText = $languageLinkTitle->getText();
122 if ( $ilLangLocalName === '' ) {
123 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
124 if ( !$ilFriendlySiteName->isDisabled() ) {
125 if ( $languageLinkTitleText === '' ) {
126 $ilTitle = wfMessage(
127 'interlanguage-link-title-nonlangonly',
128 $ilFriendlySiteName->text()
131 $ilTitle = wfMessage(
132 'interlanguage-link-title-nonlang',
133 $languageLinkTitleText,
134 $ilFriendlySiteName->text()
138 // we have nothing friendly to put in the title, so fall back to
139 // displaying the interlanguage link itself in the title text
140 // (similar to what is done in page content)
141 $ilTitle = $languageLinkTitle->getInterwiki() .
142 ":$languageLinkTitleText";
144 } elseif ( $languageLinkTitleText === '' ) {
145 $ilTitle = wfMessage(
146 'interlanguage-link-title-langonly',
150 $ilTitle = wfMessage(
151 'interlanguage-link-title',
152 $languageLinkTitleText,
157 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
158 $languageLink = array(
159 'href' => $languageLinkTitle->getFullURL(),
160 'text' => $ilLangName,
163 'lang' => $ilInterwikiCodeBCP47,
164 'hreflang' => $ilInterwikiCodeBCP47,
167 'SkinTemplateGetLanguageLink',
168 array( &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() )
170 $languageLinks[] = $languageLink;
174 return $languageLinks;
177 protected function setupTemplateForOutput() {
178 wfProfileIn( __METHOD__
);
180 $request = $this->getRequest();
181 $user = $this->getUser();
182 $title = $this->getTitle();
184 wfProfileIn( __METHOD__
. '-init' );
185 $tpl = $this->setupTemplate( $this->template
, 'skins' );
186 wfProfileOut( __METHOD__
. '-init' );
188 wfProfileIn( __METHOD__
. '-stuff' );
189 $this->thispage
= $title->getPrefixedDBkey();
190 $this->titletxt
= $title->getPrefixedText();
191 $this->userpage
= $user->getUserPage()->getPrefixedText();
193 if ( !$request->wasPosted() ) {
194 $query = $request->getValues();
195 unset( $query['title'] );
196 unset( $query['returnto'] );
197 unset( $query['returntoquery'] );
199 $this->thisquery
= wfArrayToCgi( $query );
200 $this->loggedin
= $user->isLoggedIn();
201 $this->username
= $user->getName();
203 if ( $this->loggedin ||
$this->showIPinHeader() ) {
204 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
206 # This won't be used in the standard skins, but we define it to preserve the interface
207 # To save time, we check for existence
208 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
211 wfProfileOut( __METHOD__
. '-stuff' );
213 wfProfileOut( __METHOD__
);
219 * initialize various variables and generate the template
221 * @param OutputPage $out
223 function outputPage( OutputPage
$out = null ) {
224 wfProfileIn( __METHOD__
);
225 Profiler
::instance()->setTemplated( true );
228 if ( $out !== null ) {
229 // @todo Add wfDeprecated in 1.20
230 $oldContext = $this->getContext();
231 $this->setContext( $out->getContext() );
234 $out = $this->getOutput();
236 wfProfileIn( __METHOD__
. '-init' );
237 $this->initPage( $out );
238 wfProfileOut( __METHOD__
. '-init' );
239 $tpl = $this->prepareQuickTemplate( $out );
241 wfProfileIn( __METHOD__
. '-execute' );
242 $res = $tpl->execute();
243 wfProfileOut( __METHOD__
. '-execute' );
245 // result may be an error
246 $this->printOrError( $res );
249 $this->setContext( $oldContext );
252 wfProfileOut( __METHOD__
);
256 * initialize various variables and generate the template
259 * @return QuickTemplate The template to be executed by outputPage
261 protected function prepareQuickTemplate() {
262 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
263 $wgSitename, $wgLogo, $wgMaxCredits,
264 $wgShowCreditsIfMax, $wgArticlePath,
265 $wgScriptPath, $wgServer;
267 wfProfileIn( __METHOD__
);
269 $title = $this->getTitle();
270 $request = $this->getRequest();
271 $out = $this->getOutput();
272 $tpl = $this->setupTemplateForOutput();
274 wfProfileIn( __METHOD__
. '-stuff2' );
275 $tpl->set( 'title', $out->getPageTitle() );
276 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
277 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
279 $tpl->setRef( 'thispage', $this->thispage
);
280 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
281 $tpl->set( 'titletext', $title->getText() );
282 $tpl->set( 'articleid', $title->getArticleID() );
284 $tpl->set( 'isarticle', $out->isArticle() );
286 $subpagestr = $this->subPageSubtitle();
287 if ( $subpagestr !== '' ) {
288 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
290 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
292 $undelete = $this->getUndeleteLink();
293 if ( $undelete === '' ) {
294 $tpl->set( 'undelete', '' );
296 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
299 $tpl->set( 'catlinks', $this->getCategories() );
300 if ( $out->isSyndicated() ) {
302 foreach ( $out->getSyndicationLinks() as $format => $link ) {
303 $feeds[$format] = array(
304 // Messages: feed-atom, feed-rss
305 'text' => $this->msg( "feed-$format" )->text(),
309 $tpl->setRef( 'feeds', $feeds );
311 $tpl->set( 'feeds', false );
314 $tpl->setRef( 'mimetype', $wgMimeType );
315 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
316 $tpl->set( 'charset', 'UTF-8' );
317 $tpl->setRef( 'wgScript', $wgScript );
318 $tpl->setRef( 'skinname', $this->skinname
);
319 $tpl->set( 'skinclass', get_class( $this ) );
320 $tpl->setRef( 'skin', $this );
321 $tpl->setRef( 'stylename', $this->stylename
);
322 $tpl->set( 'printable', $out->isPrintable() );
323 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
324 $tpl->setRef( 'loggedin', $this->loggedin
);
325 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
326 $tpl->set( 'searchaction', $this->escapeSearchLink() );
327 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
328 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
329 $tpl->setRef( 'stylepath', $wgStylePath );
330 $tpl->setRef( 'articlepath', $wgArticlePath );
331 $tpl->setRef( 'scriptpath', $wgScriptPath );
332 $tpl->setRef( 'serverurl', $wgServer );
333 $tpl->setRef( 'logopath', $wgLogo );
334 $tpl->setRef( 'sitename', $wgSitename );
336 $userLang = $this->getLanguage();
337 $userLangCode = $userLang->getHtmlCode();
338 $userLangDir = $userLang->getDir();
340 $tpl->set( 'lang', $userLangCode );
341 $tpl->set( 'dir', $userLangDir );
342 $tpl->set( 'rtl', $userLang->isRTL() );
344 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
345 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
346 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
347 $tpl->setRef( 'userpage', $this->userpage
);
348 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
349 $tpl->set( 'userlang', $userLangCode );
351 // Users can have their language set differently than the
352 // content of the wiki. For these users, tell the web browser
353 // that interface elements are in a different language.
354 $tpl->set( 'userlangattributes', '' );
355 $tpl->set( 'specialpageattributes', '' ); # obsolete
356 // Used by VectorBeta to insert HTML before content but after the
357 // heading for the page title. Defaults to empty string.
358 $tpl->set( 'prebodyhtml', '' );
360 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
361 $escUserlang = htmlspecialchars( $userLangCode );
362 $escUserdir = htmlspecialchars( $userLangDir );
363 // Attributes must be in double quotes because htmlspecialchars() doesn't
364 // escape single quotes
365 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
366 $tpl->set( 'userlangattributes', $attrs );
369 wfProfileOut( __METHOD__
. '-stuff2' );
371 wfProfileIn( __METHOD__
. '-stuff3' );
372 $tpl->set( 'newtalk', $this->getNewtalks() );
373 $tpl->set( 'logo', $this->logoText() );
375 $tpl->set( 'copyright', false );
377 $tpl->set( 'viewcount', false );
378 $tpl->set( 'lastmod', false );
379 $tpl->set( 'credits', false );
380 $tpl->set( 'numberofwatchingusers', false );
381 if ( $out->isArticle() && $title->exists() ) {
382 if ( $this->isRevisionCurrent() ) {
383 if ( $wgMaxCredits != 0 ) {
384 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
385 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
387 $tpl->set( 'lastmod', $this->lastModified() );
390 $tpl->set( 'copyright', $this->getCopyright() );
392 wfProfileOut( __METHOD__
. '-stuff3' );
394 wfProfileIn( __METHOD__
. '-stuff4' );
395 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
396 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
397 $tpl->set( 'disclaimer', $this->disclaimerLink() );
398 $tpl->set( 'privacy', $this->privacyLink() );
399 $tpl->set( 'about', $this->aboutLink() );
401 $tpl->set( 'footerlinks', array(
404 'numberofwatchingusers',
415 global $wgFooterIcons;
416 $tpl->set( 'footericons', $wgFooterIcons );
417 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
418 if ( count( $footerIconsBlock ) > 0 ) {
419 foreach ( $footerIconsBlock as &$footerIcon ) {
420 if ( isset( $footerIcon['src'] ) ) {
421 if ( !isset( $footerIcon['width'] ) ) {
422 $footerIcon['width'] = 88;
424 if ( !isset( $footerIcon['height'] ) ) {
425 $footerIcon['height'] = 31;
430 unset( $tpl->data
['footericons'][$footerIconsKey] );
434 $tpl->set( 'sitenotice', $this->getSiteNotice() );
435 $tpl->set( 'bottomscripts', $this->bottomScripts() );
436 $tpl->set( 'printfooter', $this->printSource() );
438 # An ID that includes the actual body text; without categories, contentSub, ...
439 $realBodyAttribs = array( 'id' => 'mw-content-text' );
441 # Add a mw-content-ltr/rtl class to be able to style based on text direction
442 # when the content is different from the UI language, i.e.:
443 # not for special pages or file pages AND only when viewing AND if the page exists
444 # (or is in MW namespace, because that has default content)
445 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
446 Action
::getActionName( $this ) === 'view' &&
447 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
448 $pageLang = $title->getPageViewLanguage();
449 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
450 $realBodyAttribs['dir'] = $pageLang->getDir();
451 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
454 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
455 $tpl->setRef( 'bodytext', $out->mBodytext
);
457 $language_urls = $this->getLanguages();
458 if ( count( $language_urls ) ) {
459 $tpl->setRef( 'language_urls', $language_urls );
461 $tpl->set( 'language_urls', false );
463 wfProfileOut( __METHOD__
. '-stuff4' );
465 wfProfileIn( __METHOD__
. '-stuff5' );
467 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
468 $content_navigation = $this->buildContentNavigationUrls();
469 $content_actions = $this->buildContentActionUrls( $content_navigation );
470 $tpl->setRef( 'content_navigation', $content_navigation );
471 $tpl->setRef( 'content_actions', $content_actions );
473 $tpl->set( 'sidebar', $this->buildSidebar() );
474 $tpl->set( 'nav_urls', $this->buildNavUrls() );
476 // Set the head scripts near the end, in case the above actions resulted in added scripts
477 $tpl->set( 'headelement', $out->headElement( $this ) );
479 $tpl->set( 'debug', '' );
480 $tpl->set( 'debughtml', $this->generateDebugHTML() );
481 $tpl->set( 'reporttime', wfReportTime() );
483 // original version by hansm
484 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
485 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
488 // Set the bodytext to another key so that skins can just output it on it's own
489 // and output printfooter and debughtml separately
490 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
492 // Append printfooter and debughtml onto bodytext so that skins that
493 // were already using bodytext before they were split out don't suddenly
494 // start not outputting information.
495 $tpl->data
['bodytext'] .= Html
::rawElement(
497 array( 'class' => 'printfooter' ),
498 "\n{$tpl->data['printfooter']}"
500 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
502 // allow extensions adding stuff after the page content.
503 // See Skin::afterContentHook() for further documentation.
504 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
505 wfProfileOut( __METHOD__
. '-stuff5' );
507 wfProfileOut( __METHOD__
);
512 * Get the HTML for the p-personal list
515 public function getPersonalToolsList() {
516 $tpl = $this->setupTemplateForOutput();
517 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
519 foreach ( $tpl->getPersonalTools() as $key => $item ) {
520 $html .= $tpl->makeListItem( $key, $item );
526 * Format language name for use in sidebar interlanguage links list.
527 * By default it is capitalized.
529 * @param string $name Language name, e.g. "English" or "español"
533 function formatLanguageName( $name ) {
534 return $this->getLanguage()->ucfirst( $name );
538 * Output the string, or print error message if it's
539 * an error object of the appropriate type.
540 * For the base class, assume strings all around.
545 function printOrError( $str ) {
550 * Output a boolean indicating if buildPersonalUrls should output separate
551 * login and create account links or output a combined link
552 * By default we simply return a global config setting that affects most skins
553 * This is setup as a method so that like with $wgLogo and getLogo() a skin
554 * can override this setting and always output one or the other if it has
555 * a reason it can't output one of the two modes.
558 function useCombinedLoginLink() {
559 global $wgUseCombinedLoginLink;
560 return $wgUseCombinedLoginLink;
564 * build array of urls for personal toolbar
567 protected function buildPersonalUrls() {
568 $title = $this->getTitle();
569 $request = $this->getRequest();
570 $pageurl = $title->getLocalURL();
571 wfProfileIn( __METHOD__
);
573 /* set up the default links for the personal toolbar */
574 $personal_urls = array();
576 # Due to bug 32276, if a user does not have read permissions,
577 # $this->getTitle() will just give Special:Badtitle, which is
578 # not especially useful as a returnto parameter. Use the title
579 # from the request instead, if there was one.
580 if ( $this->getUser()->isAllowed( 'read' ) ) {
581 $page = $this->getTitle();
583 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
585 $page = $request->getVal( 'returnto', $page );
587 if ( strval( $page ) !== '' ) {
588 $a['returnto'] = $page;
589 $query = $request->getVal( 'returntoquery', $this->thisquery
);
590 if ( $query != '' ) {
591 $a['returntoquery'] = $query;
595 $returnto = wfArrayToCgi( $a );
596 if ( $this->loggedin
) {
597 $personal_urls['userpage'] = array(
598 'text' => $this->username
,
599 'href' => &$this->userpageUrlDetails
['href'],
600 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
601 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
604 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
605 $personal_urls['mytalk'] = array(
606 'text' => $this->msg( 'mytalk' )->text(),
607 'href' => &$usertalkUrlDetails['href'],
608 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
609 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
611 $href = self
::makeSpecialUrl( 'Preferences' );
612 $personal_urls['preferences'] = array(
613 'text' => $this->msg( 'mypreferences' )->text(),
615 'active' => ( $href == $pageurl )
618 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
619 $href = self
::makeSpecialUrl( 'Watchlist' );
620 $personal_urls['watchlist'] = array(
621 'text' => $this->msg( 'mywatchlist' )->text(),
623 'active' => ( $href == $pageurl )
627 # We need to do an explicit check for Special:Contributions, as we
628 # have to match both the title, and the target, which could come
629 # from request values (Special:Contributions?target=Jimbo_Wales)
630 # or be specified in "sub page" form
631 # (Special:Contributions/Jimbo_Wales). The plot
632 # thickens, because the Title object is altered for special pages,
633 # so it doesn't contain the original alias-with-subpage.
634 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
635 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
636 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
637 $active = $spName == 'Contributions'
638 && ( ( $spPar && $spPar == $this->username
)
639 ||
$request->getText( 'target' ) == $this->username
);
644 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
645 $personal_urls['mycontris'] = array(
646 'text' => $this->msg( 'mycontris' )->text(),
650 $personal_urls['logout'] = array(
651 'text' => $this->msg( 'pt-userlogout' )->text(),
652 'href' => self
::makeSpecialUrl( 'Userlogout',
653 // userlogout link must always contain an & character, otherwise we might not be able
654 // to detect a buggy precaching proxy (bug 17790)
655 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
660 $useCombinedLoginLink = $this->useCombinedLoginLink();
661 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
662 ?
'nav-login-createaccount'
664 $is_signup = $request->getText( 'type' ) == 'signup';
667 'text' => $this->msg( $loginlink )->text(),
668 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
669 'active' => $title->isSpecial( 'Userlogin' )
670 && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
672 $createaccount_url = array(
673 'text' => $this->msg( 'pt-createaccount' )->text(),
674 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
675 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
678 if ( $this->showIPinHeader() ) {
679 $href = &$this->userpageUrlDetails
['href'];
680 $personal_urls['anonuserpage'] = array(
681 'text' => $this->username
,
683 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
684 'active' => ( $pageurl == $href )
686 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
687 $href = &$usertalkUrlDetails['href'];
688 $personal_urls['anontalk'] = array(
689 'text' => $this->msg( 'anontalk' )->text(),
691 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
692 'active' => ( $pageurl == $href )
696 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
697 $personal_urls['createaccount'] = $createaccount_url;
700 $personal_urls['login'] = $login_url;
703 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
704 wfProfileOut( __METHOD__
);
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->getFormattedNsText(
745 MWNamespace
::getSubject( $title->getNamespace() ) );
749 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$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->getArticleID() != 0,
775 function makeArticleUrlDetails( $name, $urlaction = '' ) {
776 $title = Title
::newFromText( $name );
777 $title = $title->getSubjectPage();
778 self
::checkTitle( $title, $name );
780 'href' => $title->getLocalURL( $urlaction ),
781 'exists' => $title->getArticleID() != 0,
786 * a structured array of links usually used for the tabs in a skin
788 * There are 4 standard sections
789 * namespaces: Used for namespace tabs like special, page, and talk namespaces
790 * views: Used for primary page views like read, edit, history
791 * actions: Used for most extra page actions like deletion, protection, etc...
792 * variants: Used to list the language variants for the page
794 * Each section's value is a key/value array of links for that section.
795 * The links themselves have these common keys:
796 * - class: The css classes to apply to the tab
797 * - text: The text to display on the tab
798 * - href: The href for the tab to point to
799 * - rel: An optional rel= for the tab's link
800 * - redundant: If true the tab will be dropped in skins using content_actions
801 * this is useful for tabs like "Read" which only have meaning in skins that
802 * take special meaning from the grouped structure of content_navigation
804 * Views also have an extra key which can be used:
805 * - primary: If this is not true skins like vector may try to hide the tab
806 * when the user has limited space in their browser window
808 * content_navigation using code also expects these ids to be present on the
809 * links, however these are usually automatically generated by SkinTemplate
810 * itself and are not necessary when using a hook. The only things these may
811 * matter to are people modifying content_navigation after it's initial creation:
812 * - id: A "preferred" id, most skins are best off outputting this preferred
813 * id for best compatibility.
814 * - tooltiponly: This is set to true for some tabs in cases where the system
815 * believes that the accesskey should not be added to the tab.
819 protected function buildContentNavigationUrls() {
820 global $wgDisableLangConversion;
822 wfProfileIn( __METHOD__
);
824 // Display tabs for the relevant title rather than always the title itself
825 $title = $this->getRelevantTitle();
826 $onPage = $title->equals( $this->getTitle() );
828 $out = $this->getOutput();
829 $request = $this->getRequest();
830 $user = $this->getUser();
832 $content_navigation = array(
833 'namespaces' => array(),
835 'actions' => array(),
836 'variants' => array()
840 $action = $request->getVal( 'action', 'view' );
842 $userCanRead = $title->quickUserCan( 'read', $user );
844 $preventActiveTabs = false;
845 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
847 // Checks if page is some kind of content
848 if ( $title->canExist() ) {
849 // Gets page objects for the related namespaces
850 $subjectPage = $title->getSubjectPage();
851 $talkPage = $title->getTalkPage();
853 // Determines if this is a talk page
854 $isTalk = $title->isTalkPage();
856 // Generates XML IDs from namespace names
857 $subjectId = $title->getNamespaceKey( '' );
859 if ( $subjectId == 'main' ) {
862 $talkId = "{$subjectId}_talk";
865 $skname = $this->skinname
;
867 // Adds namespace links
868 $subjectMsg = array( "nstab-$subjectId" );
869 if ( $subjectPage->isMainPage() ) {
870 array_unshift( $subjectMsg, 'mainpage-nstab' );
872 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
873 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
875 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
876 $content_navigation['namespaces'][$talkId] = $this->tabAction(
877 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
879 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
881 if ( $userCanRead ) {
882 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
883 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
885 // Adds view view link
886 if ( $title->exists() ||
$isForeignFile ) {
887 $content_navigation['views']['view'] = $this->tabAction(
888 $isTalk ?
$talkPage : $subjectPage,
889 array( "$skname-view-view", 'view' ),
890 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
892 // signal to hide this from simple content_actions
893 $content_navigation['views']['view']['redundant'] = true;
896 // If it is a non-local file, show a link to the file in its own repository
897 if ( $isForeignFile ) {
898 $file = $this->getWikiPage()->getFile();
899 $content_navigation['views']['view-foreign'] = array(
901 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
902 setContext( $this->getContext() )->
903 params( $file->getRepo()->getDisplayName() )->text(),
904 'href' => $file->getDescriptionUrl(),
909 wfProfileIn( __METHOD__
. '-edit' );
911 // Checks if user can edit the current page if it exists or create it otherwise
912 if ( $title->quickUserCan( 'edit', $user )
913 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
915 // Builds CSS class for talk page links
916 $isTalkClass = $isTalk ?
' istalk' : '';
917 // Whether the user is editing the page
918 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
919 // Whether to show the "Add a new section" tab
920 // Checks if this is a current rev of talk page and is not forced to be hidden
921 $showNewSection = !$out->forceHideNewSectionLink()
922 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
923 $section = $request->getVal( 'section' );
925 if ( $title->exists()
926 ||
( $title->getNamespace() == NS_MEDIAWIKI
927 && $title->getDefaultMessageText() !== false
930 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
932 $msgKey = $isForeignFile ?
'create-local' : 'create';
934 $content_navigation['views']['edit'] = array(
935 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
939 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
940 ->setContext( $this->getContext() )->text(),
941 'href' => $title->getLocalURL( $this->editUrlOptions() ),
942 'primary' => !$isForeignFile, // don't collapse this in vector
946 if ( $showNewSection ) {
947 // Adds new section link
948 //$content_navigation['actions']['addsection']
949 $content_navigation['views']['addsection'] = array(
950 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
951 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
952 ->setContext( $this->getContext() )->text(),
953 'href' => $title->getLocalURL( 'action=edit§ion=new' )
956 // Checks if the page has some kind of viewable content
957 } elseif ( $title->hasSourceText() ) {
958 // Adds view source view link
959 $content_navigation['views']['viewsource'] = array(
960 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
961 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
962 ->setContext( $this->getContext() )->text(),
963 'href' => $title->getLocalURL( $this->editUrlOptions() ),
964 'primary' => true, // don't collapse this in vector
967 wfProfileOut( __METHOD__
. '-edit' );
969 wfProfileIn( __METHOD__
. '-live' );
970 // Checks if the page exists
971 if ( $title->exists() ) {
972 // Adds history view link
973 $content_navigation['views']['history'] = array(
974 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
975 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
976 ->setContext( $this->getContext() )->text(),
977 'href' => $title->getLocalURL( 'action=history' ),
981 if ( $title->quickUserCan( 'delete', $user ) ) {
982 $content_navigation['actions']['delete'] = array(
983 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
984 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
985 ->setContext( $this->getContext() )->text(),
986 'href' => $title->getLocalURL( 'action=delete' )
990 if ( $title->quickUserCan( 'move', $user ) ) {
991 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
992 $content_navigation['actions']['move'] = array(
993 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
994 'text' => wfMessageFallback( "$skname-action-move", 'move' )
995 ->setContext( $this->getContext() )->text(),
996 'href' => $moveTitle->getLocalURL()
1000 // article doesn't exist or is deleted
1001 if ( $user->isAllowed( 'deletedhistory' ) ) {
1002 $n = $title->isDeleted();
1004 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1005 // If the user can't undelete but can view deleted
1006 // history show them a "View .. deleted" tab instead.
1007 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1008 $content_navigation['actions']['undelete'] = array(
1009 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1010 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1011 ->setContext( $this->getContext() )->numParams( $n )->text(),
1012 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1018 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1019 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1021 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1022 $content_navigation['actions'][$mode] = array(
1023 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1024 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1025 ->setContext( $this->getContext() )->text(),
1026 'href' => $title->getLocalURL( "action=$mode" )
1030 wfProfileOut( __METHOD__
. '-live' );
1032 // Checks if the user is logged in
1033 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1035 * The following actions use messages which, if made particular to
1036 * the any specific skins, would break the Ajax code which makes this
1037 * action happen entirely inline. OutputPage::getJSVars
1038 * defines a set of messages in a javascript object - and these
1039 * messages are assumed to be global for all skins. Without making
1040 * a change to that procedure these messages will have to remain as
1041 * the global versions.
1043 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1044 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1045 $content_navigation['actions'][$mode] = array(
1046 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1047 // uses 'watch' or 'unwatch' message
1048 'text' => $this->msg( $mode )->text(),
1049 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1054 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1056 if ( $userCanRead && !$wgDisableLangConversion ) {
1057 $pageLang = $title->getPageLanguage();
1058 // Gets list of language variants
1059 $variants = $pageLang->getVariants();
1060 // Checks that language conversion is enabled and variants exist
1061 // And if it is not in the special namespace
1062 if ( count( $variants ) > 1 ) {
1063 // Gets preferred variant (note that user preference is
1064 // only possible for wiki content language variant)
1065 $preferred = $pageLang->getPreferredVariant();
1066 if ( Action
::getActionName( $this ) === 'view' ) {
1067 $params = $request->getQueryValues();
1068 unset( $params['title'] );
1072 // Loops over each variant
1073 foreach ( $variants as $code ) {
1074 // Gets variant name from language code
1075 $varname = $pageLang->getVariantname( $code );
1076 // Appends variant link
1077 $content_navigation['variants'][] = array(
1078 'class' => ( $code == $preferred ) ?
'selected' : false,
1080 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1081 'lang' => wfBCP47( $code ),
1082 'hreflang' => wfBCP47( $code ),
1088 // If it's not content, it's got to be a special page
1089 $content_navigation['namespaces']['special'] = array(
1090 'class' => 'selected',
1091 'text' => $this->msg( 'nstab-special' )->text(),
1092 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1093 'context' => 'subject'
1096 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1097 array( &$this, &$content_navigation ) );
1100 // Equiv to SkinTemplateContentActions
1101 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1103 // Setup xml ids and tooltip info
1104 foreach ( $content_navigation as $section => &$links ) {
1105 foreach ( $links as $key => &$link ) {
1107 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1108 $xmlID = 'ca-nstab-' . $xmlID;
1109 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1111 } elseif ( $section == 'variants' ) {
1112 $xmlID = 'ca-varlang-' . $xmlID;
1114 $xmlID = 'ca-' . $xmlID;
1116 $link['id'] = $xmlID;
1120 # We don't want to give the watch tab an accesskey if the
1121 # page is being edited, because that conflicts with the
1122 # accesskey on the watch checkbox. We also don't want to
1123 # give the edit tab an accesskey, because that's fairly
1124 # superfluous and conflicts with an accesskey (Ctrl-E) often
1125 # used for editing in Safari.
1126 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1127 if ( isset( $content_navigation['views']['edit'] ) ) {
1128 $content_navigation['views']['edit']['tooltiponly'] = true;
1130 if ( isset( $content_navigation['actions']['watch'] ) ) {
1131 $content_navigation['actions']['watch']['tooltiponly'] = true;
1133 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1134 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1138 wfProfileOut( __METHOD__
);
1140 return $content_navigation;
1144 * an array of edit links by default used for the tabs
1145 * @param array $content_navigation
1148 private function buildContentActionUrls( $content_navigation ) {
1150 wfProfileIn( __METHOD__
);
1152 // content_actions has been replaced with content_navigation for backwards
1153 // compatibility and also for skins that just want simple tabs content_actions
1154 // is now built by flattening the content_navigation arrays into one
1156 $content_actions = array();
1158 foreach ( $content_navigation as $links ) {
1159 foreach ( $links as $key => $value ) {
1160 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1161 // Redundant tabs are dropped from content_actions
1165 // content_actions used to have ids built using the "ca-$key" pattern
1166 // so the xmlID based id is much closer to the actual $key that we want
1167 // for that reason we'll just strip out the ca- if present and use
1168 // the latter potion of the "id" as the $key
1169 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1170 $key = substr( $value['id'], 3 );
1173 if ( isset( $content_actions[$key] ) ) {
1174 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1175 "content_navigation into content_actions.\n" );
1179 $content_actions[$key] = $value;
1183 wfProfileOut( __METHOD__
);
1185 return $content_actions;
1189 * build array of common navigation links
1192 protected function buildNavUrls() {
1193 global $wgUploadNavigationUrl;
1195 wfProfileIn( __METHOD__
);
1197 $out = $this->getOutput();
1198 $request = $this->getRequest();
1200 $nav_urls = array();
1201 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1202 if ( $wgUploadNavigationUrl ) {
1203 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1204 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1205 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1207 $nav_urls['upload'] = false;
1209 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1211 $nav_urls['print'] = false;
1212 $nav_urls['permalink'] = false;
1213 $nav_urls['info'] = false;
1214 $nav_urls['whatlinkshere'] = false;
1215 $nav_urls['recentchangeslinked'] = false;
1216 $nav_urls['contributions'] = false;
1217 $nav_urls['log'] = false;
1218 $nav_urls['blockip'] = false;
1219 $nav_urls['emailuser'] = false;
1220 $nav_urls['userrights'] = false;
1222 // A print stylesheet is attached to all pages, but nobody ever
1223 // figures that out. :) Add a link...
1224 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1225 $nav_urls['print'] = array(
1226 'text' => $this->msg( 'printableversion' )->text(),
1227 'href' => $this->getTitle()->getLocalURL(
1228 $request->appendQueryValue( 'printable', 'yes', true ) )
1232 if ( $out->isArticle() ) {
1233 // Also add a "permalink" while we're at it
1234 $revid = $this->getRevisionId();
1236 $nav_urls['permalink'] = array(
1237 'text' => $this->msg( 'permalink' )->text(),
1238 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1242 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1243 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1244 array( &$this, &$nav_urls, &$revid, &$revid ) );
1247 if ( $out->isArticleRelated() ) {
1248 $nav_urls['whatlinkshere'] = array(
1249 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1252 $nav_urls['info'] = array(
1253 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1254 'href' => $this->getTitle()->getLocalURL( "action=info" )
1257 if ( $this->getTitle()->getArticleID() ) {
1258 $nav_urls['recentchangeslinked'] = array(
1259 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1264 $user = $this->getRelevantUser();
1266 $rootUser = $user->getName();
1268 $nav_urls['contributions'] = array(
1269 'text' => $this->msg( 'contributions', $rootUser )->text(),
1270 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1273 $nav_urls['log'] = array(
1274 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1277 if ( $this->getUser()->isAllowed( 'block' ) ) {
1278 $nav_urls['blockip'] = array(
1279 'text' => $this->msg( 'blockip', $rootUser )->text(),
1280 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1284 if ( $this->showEmailUser( $user ) ) {
1285 $nav_urls['emailuser'] = array(
1286 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1290 if ( !$user->isAnon() ) {
1291 $sur = new UserrightsPage
;
1292 $sur->setContext( $this->getContext() );
1293 if ( $sur->userCanExecute( $this->getUser() ) ) {
1294 $nav_urls['userrights'] = array(
1295 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1301 wfProfileOut( __METHOD__
);
1306 * Generate strings used for xml 'id' names
1309 protected function getNameSpaceKey() {
1310 return $this->getTitle()->getNamespaceKey();