3 * Base class for template-based skins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Wrapper object for MediaWiki's localization functions,
25 * to be passed to the template engine.
31 private $context = array();
33 function set( $varName, $value ) {
34 $this->context
[$varName] = $value;
37 function translate( $value ) {
38 wfProfileIn( __METHOD__
);
40 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
41 $value = preg_replace( '/^string:/', '', $value );
43 $value = wfMessage( $value )->text();
44 // interpolate variables
46 while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
47 list( $src, $var ) = $m;
49 $varValue = $this->context
[$var];
51 $value = str_replace( $src, $varValue, $value );
53 wfProfileOut( __METHOD__
);
59 * Template-filler skin base class
60 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
61 * Based on Brion's smarty skin
62 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
64 * @todo Needs some serious refactoring into functions that correspond
65 * to the computations individual esi snippets need. Most importantly no body
66 * parsing for most of those of course.
70 class SkinTemplate
extends Skin
{
72 * @var string Name of our skin, it probably needs to be all lower case.
73 * Child classes should override the default.
75 public $skinname = 'monobook';
78 * @var string Stylesheets set to use. Subdirectory in skins/ where various
79 * stylesheets are located. Child classes should override the default.
81 public $stylename = 'monobook';
84 * @var string For QuickTemplate, the name of the subclass which will
85 * actually fill the template. Child classes should override the default.
87 public $template = 'QuickTemplate';
90 * Add specific styles for this skin
92 * @param OutputPage $out
94 function setupSkinUserCss( OutputPage
$out ) {
95 $out->addModuleStyles( array(
96 'mediawiki.legacy.shared',
97 'mediawiki.legacy.commonPrint',
103 * Create the template engine object; we feed it a bunch of data
104 * and eventually it spits out some HTML. Should have interface
105 * roughly equivalent to PHPTAL 0.7.
107 * @param string $classname
108 * @param bool|string $repository Subdirectory where we keep template files
109 * @param bool|string $cache_dir
110 * @return QuickTemplate
113 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
114 return new $classname();
118 * Generates array of language links for the current page
123 public function getLanguages() {
124 global $wgHideInterlanguageLinks;
125 if ( $wgHideInterlanguageLinks ) {
129 $userLang = $this->getLanguage();
130 $languageLinks = array();
132 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
133 $languageLinkParts = explode( ':', $languageLinkText, 2 );
134 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
135 unset( $languageLinkParts );
137 $languageLinkTitle = Title
::newFromText( $languageLinkText );
138 if ( $languageLinkTitle ) {
139 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
140 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
142 if ( strval( $ilLangName ) === '' ) {
143 $ilLangName = $languageLinkText;
145 $ilLangName = $this->formatLanguageName( $ilLangName );
148 // CLDR extension or similar is required to localize the language name;
149 // otherwise we'll end up with the autonym again.
150 $ilLangLocalName = Language
::fetchLanguageName(
155 $languageLinkTitleText = $languageLinkTitle->getText();
156 if ( $languageLinkTitleText === '' ) {
157 $ilTitle = wfMessage(
158 'interlanguage-link-title-langonly',
162 $ilTitle = wfMessage(
163 'interlanguage-link-title',
164 $languageLinkTitleText,
169 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
170 $languageLink = array(
171 'href' => $languageLinkTitle->getFullURL(),
172 'text' => $ilLangName,
175 'lang' => $ilInterwikiCodeBCP47,
176 'hreflang' => $ilInterwikiCodeBCP47,
179 'SkinTemplateGetLanguageLink',
180 array( &$languageLink, $languageLinkTitle, $this->getTitle() )
182 $languageLinks[] = $languageLink;
186 return $languageLinks;
189 protected function setupTemplateForOutput() {
190 wfProfileIn( __METHOD__
);
192 $request = $this->getRequest();
193 $user = $this->getUser();
194 $title = $this->getTitle();
196 wfProfileIn( __METHOD__
. '-init' );
197 $tpl = $this->setupTemplate( $this->template
, 'skins' );
198 wfProfileOut( __METHOD__
. '-init' );
200 wfProfileIn( __METHOD__
. '-stuff' );
201 $this->thispage
= $title->getPrefixedDBkey();
202 $this->titletxt
= $title->getPrefixedText();
203 $this->userpage
= $user->getUserPage()->getPrefixedText();
205 if ( !$request->wasPosted() ) {
206 $query = $request->getValues();
207 unset( $query['title'] );
208 unset( $query['returnto'] );
209 unset( $query['returntoquery'] );
211 $this->thisquery
= wfArrayToCgi( $query );
212 $this->loggedin
= $user->isLoggedIn();
213 $this->username
= $user->getName();
215 if ( $this->loggedin ||
$this->showIPinHeader() ) {
216 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
218 # This won't be used in the standard skins, but we define it to preserve the interface
219 # To save time, we check for existence
220 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
223 wfProfileOut( __METHOD__
. '-stuff' );
225 wfProfileOut( __METHOD__
);
231 * initialize various variables and generate the template
233 * @param OutputPage $out
235 function outputPage( OutputPage
$out = null ) {
236 wfProfileIn( __METHOD__
);
237 Profiler
::instance()->setTemplated( true );
240 if ( $out !== null ) {
241 // @todo Add wfDeprecated in 1.20
242 $oldContext = $this->getContext();
243 $this->setContext( $out->getContext() );
246 $out = $this->getOutput();
248 wfProfileIn( __METHOD__
. '-init' );
249 $this->initPage( $out );
250 wfProfileOut( __METHOD__
. '-init' );
251 $tpl = $this->prepareQuickTemplate( $out );
253 wfProfileIn( __METHOD__
. '-execute' );
254 $res = $tpl->execute();
255 wfProfileOut( __METHOD__
. '-execute' );
257 // result may be an error
258 $this->printOrError( $res );
261 $this->setContext( $oldContext );
264 wfProfileOut( __METHOD__
);
268 * initialize various variables and generate the template
271 * @return QuickTemplate The template to be executed by outputPage
273 protected function prepareQuickTemplate() {
274 global $wgContLang, $wgScript, $wgStylePath,
275 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
276 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
277 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
278 $wgScriptPath, $wgServer;
280 wfProfileIn( __METHOD__
);
282 $title = $this->getTitle();
283 $request = $this->getRequest();
284 $out = $this->getOutput();
285 $tpl = $this->setupTemplateForOutput();
287 wfProfileIn( __METHOD__
. '-stuff2' );
288 $tpl->set( 'title', $out->getPageTitle() );
289 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
290 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
292 $tpl->setRef( 'thispage', $this->thispage
);
293 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
294 $tpl->set( 'titletext', $title->getText() );
295 $tpl->set( 'articleid', $title->getArticleID() );
297 $tpl->set( 'isarticle', $out->isArticle() );
299 $subpagestr = $this->subPageSubtitle();
300 if ( $subpagestr !== '' ) {
301 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
303 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
305 $undelete = $this->getUndeleteLink();
306 if ( $undelete === '' ) {
307 $tpl->set( 'undelete', '' );
309 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
312 $tpl->set( 'catlinks', $this->getCategories() );
313 if ( $out->isSyndicated() ) {
315 foreach ( $out->getSyndicationLinks() as $format => $link ) {
316 $feeds[$format] = array(
317 // Messages: feed-atom, feed-rss
318 'text' => $this->msg( "feed-$format" )->text(),
322 $tpl->setRef( 'feeds', $feeds );
324 $tpl->set( 'feeds', false );
327 $tpl->setRef( 'mimetype', $wgMimeType );
328 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
329 $tpl->set( 'charset', 'UTF-8' );
330 $tpl->setRef( 'wgScript', $wgScript );
331 $tpl->setRef( 'skinname', $this->skinname
);
332 $tpl->set( 'skinclass', get_class( $this ) );
333 $tpl->setRef( 'skin', $this );
334 $tpl->setRef( 'stylename', $this->stylename
);
335 $tpl->set( 'printable', $out->isPrintable() );
336 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
337 $tpl->setRef( 'loggedin', $this->loggedin
);
338 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
339 /* XXX currently unused, might get useful later
340 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
341 $tpl->set( 'exists', $title->getArticleID() != 0 );
342 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
343 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
344 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
346 $tpl->set( 'searchaction', $this->escapeSearchLink() );
347 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
348 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
349 $tpl->setRef( 'stylepath', $wgStylePath );
350 $tpl->setRef( 'articlepath', $wgArticlePath );
351 $tpl->setRef( 'scriptpath', $wgScriptPath );
352 $tpl->setRef( 'serverurl', $wgServer );
353 $tpl->setRef( 'logopath', $wgLogo );
354 $tpl->setRef( 'sitename', $wgSitename );
356 $userLang = $this->getLanguage();
357 $userLangCode = $userLang->getHtmlCode();
358 $userLangDir = $userLang->getDir();
360 $tpl->set( 'lang', $userLangCode );
361 $tpl->set( 'dir', $userLangDir );
362 $tpl->set( 'rtl', $userLang->isRTL() );
364 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
365 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
366 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
367 $tpl->setRef( 'userpage', $this->userpage
);
368 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
369 $tpl->set( 'userlang', $userLangCode );
371 // Users can have their language set differently than the
372 // content of the wiki. For these users, tell the web browser
373 // that interface elements are in a different language.
374 $tpl->set( 'userlangattributes', '' );
375 $tpl->set( 'specialpageattributes', '' ); # obsolete
376 // Used by VectorBeta to insert HTML before content but after the
377 // heading for the page title. Defaults to empty string.
378 $tpl->set( 'prebodyhtml', '' );
380 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
381 $escUserlang = htmlspecialchars( $userLangCode );
382 $escUserdir = htmlspecialchars( $userLangDir );
383 // Attributes must be in double quotes because htmlspecialchars() doesn't
384 // escape single quotes
385 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
386 $tpl->set( 'userlangattributes', $attrs );
389 wfProfileOut( __METHOD__
. '-stuff2' );
391 wfProfileIn( __METHOD__
. '-stuff3' );
392 $tpl->set( 'newtalk', $this->getNewtalks() );
393 $tpl->set( 'logo', $this->logoText() );
395 $tpl->set( 'copyright', false );
396 $tpl->set( 'viewcount', false );
397 $tpl->set( 'lastmod', false );
398 $tpl->set( 'credits', false );
399 $tpl->set( 'numberofwatchingusers', false );
400 if ( $out->isArticle() && $title->exists() ) {
401 if ( $this->isRevisionCurrent() ) {
402 if ( !$wgDisableCounters ) {
403 $viewcount = $this->getWikiPage()->getCount();
405 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
409 if ( $wgPageShowWatchingUsers ) {
410 $dbr = wfGetDB( DB_SLAVE
);
411 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
412 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
416 $tpl->set( 'numberofwatchingusers',
417 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
422 if ( $wgMaxCredits != 0 ) {
423 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
424 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
426 $tpl->set( 'lastmod', $this->lastModified() );
429 $tpl->set( 'copyright', $this->getCopyright() );
431 wfProfileOut( __METHOD__
. '-stuff3' );
433 wfProfileIn( __METHOD__
. '-stuff4' );
434 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
435 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
436 $tpl->set( 'disclaimer', $this->disclaimerLink() );
437 $tpl->set( 'privacy', $this->privacyLink() );
438 $tpl->set( 'about', $this->aboutLink() );
440 $tpl->set( 'footerlinks', array(
444 'numberofwatchingusers',
455 global $wgFooterIcons;
456 $tpl->set( 'footericons', $wgFooterIcons );
457 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
458 if ( count( $footerIconsBlock ) > 0 ) {
459 foreach ( $footerIconsBlock as &$footerIcon ) {
460 if ( isset( $footerIcon['src'] ) ) {
461 if ( !isset( $footerIcon['width'] ) ) {
462 $footerIcon['width'] = 88;
464 if ( !isset( $footerIcon['height'] ) ) {
465 $footerIcon['height'] = 31;
470 unset( $tpl->data
['footericons'][$footerIconsKey] );
474 $tpl->set( 'sitenotice', $this->getSiteNotice() );
475 $tpl->set( 'bottomscripts', $this->bottomScripts() );
476 $tpl->set( 'printfooter', $this->printSource() );
478 # An ID that includes the actual body text; without categories, contentSub, ...
479 $realBodyAttribs = array( 'id' => 'mw-content-text' );
481 # Add a mw-content-ltr/rtl class to be able to style based on text direction
482 # when the content is different from the UI language, i.e.:
483 # not for special pages or file pages AND only when viewing AND if the page exists
484 # (or is in MW namespace, because that has default content)
485 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
486 Action
::getActionName( $this ) === 'view' &&
487 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
488 $pageLang = $title->getPageViewLanguage();
489 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
490 $realBodyAttribs['dir'] = $pageLang->getDir();
491 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
494 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
495 $tpl->setRef( 'bodytext', $out->mBodytext
);
497 $language_urls = $this->getLanguages();
498 if ( count( $language_urls ) ) {
499 $tpl->setRef( 'language_urls', $language_urls );
501 $tpl->set( 'language_urls', false );
503 wfProfileOut( __METHOD__
. '-stuff4' );
505 wfProfileIn( __METHOD__
. '-stuff5' );
507 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
508 $content_navigation = $this->buildContentNavigationUrls();
509 $content_actions = $this->buildContentActionUrls( $content_navigation );
510 $tpl->setRef( 'content_navigation', $content_navigation );
511 $tpl->setRef( 'content_actions', $content_actions );
513 $tpl->set( 'sidebar', $this->buildSidebar() );
514 $tpl->set( 'nav_urls', $this->buildNavUrls() );
516 // Set the head scripts near the end, in case the above actions resulted in added scripts
517 $tpl->set( 'headelement', $out->headElement( $this ) );
519 $tpl->set( 'debug', '' );
520 $tpl->set( 'debughtml', $this->generateDebugHTML() );
521 $tpl->set( 'reporttime', wfReportTime() );
523 // original version by hansm
524 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
525 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
528 // Set the bodytext to another key so that skins can just output it on it's own
529 // and output printfooter and debughtml separately
530 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
532 // Append printfooter and debughtml onto bodytext so that skins that
533 // were already using bodytext before they were split out don't suddenly
534 // start not outputting information.
535 $tpl->data
['bodytext'] .= Html
::rawElement(
537 array( 'class' => 'printfooter' ),
538 "\n{$tpl->data['printfooter']}"
540 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
542 // allow extensions adding stuff after the page content.
543 // See Skin::afterContentHook() for further documentation.
544 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
545 wfProfileOut( __METHOD__
. '-stuff5' );
547 wfProfileOut( __METHOD__
);
552 * Get the HTML for the p-personal list
555 public function getPersonalToolsList() {
556 $tpl = $this->setupTemplateForOutput();
557 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
559 foreach ( $tpl->getPersonalTools() as $key => $item ) {
560 $html .= $tpl->makeListItem( $key, $item );
566 * Format language name for use in sidebar interlanguage links list.
567 * By default it is capitalized.
569 * @param string $name Language name, e.g. "English" or "español"
573 function formatLanguageName( $name ) {
574 return $this->getLanguage()->ucfirst( $name );
578 * Output the string, or print error message if it's
579 * an error object of the appropriate type.
580 * For the base class, assume strings all around.
585 function printOrError( $str ) {
590 * Output a boolean indicating if buildPersonalUrls should output separate
591 * login and create account links or output a combined link
592 * By default we simply return a global config setting that affects most skins
593 * This is setup as a method so that like with $wgLogo and getLogo() a skin
594 * can override this setting and always output one or the other if it has
595 * a reason it can't output one of the two modes.
598 function useCombinedLoginLink() {
599 global $wgUseCombinedLoginLink;
600 return $wgUseCombinedLoginLink;
604 * build array of urls for personal toolbar
607 protected function buildPersonalUrls() {
608 $title = $this->getTitle();
609 $request = $this->getRequest();
610 $pageurl = $title->getLocalURL();
611 wfProfileIn( __METHOD__
);
613 /* set up the default links for the personal toolbar */
614 $personal_urls = array();
616 # Due to bug 32276, if a user does not have read permissions,
617 # $this->getTitle() will just give Special:Badtitle, which is
618 # not especially useful as a returnto parameter. Use the title
619 # from the request instead, if there was one.
620 if ( $this->getUser()->isAllowed( 'read' ) ) {
621 $page = $this->getTitle();
623 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
625 $page = $request->getVal( 'returnto', $page );
627 if ( strval( $page ) !== '' ) {
628 $a['returnto'] = $page;
629 $query = $request->getVal( 'returntoquery', $this->thisquery
);
630 if ( $query != '' ) {
631 $a['returntoquery'] = $query;
635 $returnto = wfArrayToCgi( $a );
636 if ( $this->loggedin
) {
637 $personal_urls['userpage'] = array(
638 'text' => $this->username
,
639 'href' => &$this->userpageUrlDetails
['href'],
640 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
641 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
644 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
645 $personal_urls['mytalk'] = array(
646 'text' => $this->msg( 'mytalk' )->text(),
647 'href' => &$usertalkUrlDetails['href'],
648 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
649 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
651 $href = self
::makeSpecialUrl( 'Preferences' );
652 $personal_urls['preferences'] = array(
653 'text' => $this->msg( 'mypreferences' )->text(),
655 'active' => ( $href == $pageurl )
658 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
659 $href = self
::makeSpecialUrl( 'Watchlist' );
660 $personal_urls['watchlist'] = array(
661 'text' => $this->msg( 'mywatchlist' )->text(),
663 'active' => ( $href == $pageurl )
667 # We need to do an explicit check for Special:Contributions, as we
668 # have to match both the title, and the target, which could come
669 # from request values (Special:Contributions?target=Jimbo_Wales)
670 # or be specified in "sub page" form
671 # (Special:Contributions/Jimbo_Wales). The plot
672 # thickens, because the Title object is altered for special pages,
673 # so it doesn't contain the original alias-with-subpage.
674 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
675 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
676 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
677 $active = $spName == 'Contributions'
678 && ( ( $spPar && $spPar == $this->username
)
679 ||
$request->getText( 'target' ) == $this->username
);
684 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
685 $personal_urls['mycontris'] = array(
686 'text' => $this->msg( 'mycontris' )->text(),
690 $personal_urls['logout'] = array(
691 'text' => $this->msg( 'pt-userlogout' )->text(),
692 'href' => self
::makeSpecialUrl( 'Userlogout',
693 // userlogout link must always contain an & character, otherwise we might not be able
694 // to detect a buggy precaching proxy (bug 17790)
695 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
700 $useCombinedLoginLink = $this->useCombinedLoginLink();
701 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
702 ?
'nav-login-createaccount'
704 $is_signup = $request->getText( 'type' ) == 'signup';
707 'text' => $this->msg( $loginlink )->text(),
708 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
709 'active' => $title->isSpecial( 'Userlogin' )
710 && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
712 $createaccount_url = array(
713 'text' => $this->msg( 'pt-createaccount' )->text(),
714 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
715 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
718 if ( $this->showIPinHeader() ) {
719 $href = &$this->userpageUrlDetails
['href'];
720 $personal_urls['anonuserpage'] = array(
721 'text' => $this->username
,
723 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
724 'active' => ( $pageurl == $href )
726 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
727 $href = &$usertalkUrlDetails['href'];
728 $personal_urls['anontalk'] = array(
729 'text' => $this->msg( 'anontalk' )->text(),
731 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
732 'active' => ( $pageurl == $href )
736 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
737 $personal_urls['createaccount'] = $createaccount_url;
740 $personal_urls['login'] = $login_url;
743 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
744 wfProfileOut( __METHOD__
);
745 return $personal_urls;
749 * Builds an array with tab definition
751 * @param Title $title page Where the tab links to
752 * @param string|array $message Message key or an array of message keys (will fall back)
753 * @param bool $selected Display the tab as selected
754 * @param string $query Query string attached to tab URL
755 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
759 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
762 $classes[] = 'selected';
764 if ( $checkEdit && !$title->isKnown() ) {
766 if ( $query !== '' ) {
767 $query = 'action=edit&redlink=1&' . $query;
769 $query = 'action=edit&redlink=1';
773 // wfMessageFallback will nicely accept $message as an array of fallbacks
774 // or just a single key
775 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
776 if ( is_array( $message ) ) {
777 // for hook compatibility just keep the last message name
778 $message = end( $message );
780 if ( $msg->exists() ) {
781 $text = $msg->text();
784 $text = $wgContLang->getFormattedNsText(
785 MWNamespace
::getSubject( $title->getNamespace() ) );
789 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
790 $title, $message, $selected, $checkEdit,
791 &$classes, &$query, &$text, &$result ) ) ) {
796 'class' => implode( ' ', $classes ),
798 'href' => $title->getLocalURL( $query ),
802 function makeTalkUrlDetails( $name, $urlaction = '' ) {
803 $title = Title
::newFromText( $name );
804 if ( !is_object( $title ) ) {
805 throw new MWException( __METHOD__
. " given invalid pagename $name" );
807 $title = $title->getTalkPage();
808 self
::checkTitle( $title, $name );
810 'href' => $title->getLocalURL( $urlaction ),
811 'exists' => $title->getArticleID() != 0,
815 function makeArticleUrlDetails( $name, $urlaction = '' ) {
816 $title = Title
::newFromText( $name );
817 $title = $title->getSubjectPage();
818 self
::checkTitle( $title, $name );
820 'href' => $title->getLocalURL( $urlaction ),
821 'exists' => $title->getArticleID() != 0,
826 * a structured array of links usually used for the tabs in a skin
828 * There are 4 standard sections
829 * namespaces: Used for namespace tabs like special, page, and talk namespaces
830 * views: Used for primary page views like read, edit, history
831 * actions: Used for most extra page actions like deletion, protection, etc...
832 * variants: Used to list the language variants for the page
834 * Each section's value is a key/value array of links for that section.
835 * The links themselves have these common keys:
836 * - class: The css classes to apply to the tab
837 * - text: The text to display on the tab
838 * - href: The href for the tab to point to
839 * - rel: An optional rel= for the tab's link
840 * - redundant: If true the tab will be dropped in skins using content_actions
841 * this is useful for tabs like "Read" which only have meaning in skins that
842 * take special meaning from the grouped structure of content_navigation
844 * Views also have an extra key which can be used:
845 * - primary: If this is not true skins like vector may try to hide the tab
846 * when the user has limited space in their browser window
848 * content_navigation using code also expects these ids to be present on the
849 * links, however these are usually automatically generated by SkinTemplate
850 * itself and are not necessary when using a hook. The only things these may
851 * matter to are people modifying content_navigation after it's initial creation:
852 * - id: A "preferred" id, most skins are best off outputting this preferred
853 * id for best compatibility.
854 * - tooltiponly: This is set to true for some tabs in cases where the system
855 * believes that the accesskey should not be added to the tab.
859 protected function buildContentNavigationUrls() {
860 global $wgDisableLangConversion;
862 wfProfileIn( __METHOD__
);
864 // Display tabs for the relevant title rather than always the title itself
865 $title = $this->getRelevantTitle();
866 $onPage = $title->equals( $this->getTitle() );
868 $out = $this->getOutput();
869 $request = $this->getRequest();
870 $user = $this->getUser();
872 $content_navigation = array(
873 'namespaces' => array(),
875 'actions' => array(),
876 'variants' => array()
880 $action = $request->getVal( 'action', 'view' );
882 $userCanRead = $title->quickUserCan( 'read', $user );
884 $preventActiveTabs = false;
885 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
887 // Checks if page is some kind of content
888 if ( $title->canExist() ) {
889 // Gets page objects for the related namespaces
890 $subjectPage = $title->getSubjectPage();
891 $talkPage = $title->getTalkPage();
893 // Determines if this is a talk page
894 $isTalk = $title->isTalkPage();
896 // Generates XML IDs from namespace names
897 $subjectId = $title->getNamespaceKey( '' );
899 if ( $subjectId == 'main' ) {
902 $talkId = "{$subjectId}_talk";
905 $skname = $this->skinname
;
907 // Adds namespace links
908 $subjectMsg = array( "nstab-$subjectId" );
909 if ( $subjectPage->isMainPage() ) {
910 array_unshift( $subjectMsg, 'mainpage-nstab' );
912 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
913 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
915 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
916 $content_navigation['namespaces'][$talkId] = $this->tabAction(
917 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
919 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
921 if ( $userCanRead ) {
922 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
923 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
925 // Adds view view link
926 if ( $title->exists() ||
$isForeignFile ) {
927 $content_navigation['views']['view'] = $this->tabAction(
928 $isTalk ?
$talkPage : $subjectPage,
929 array( "$skname-view-view", 'view' ),
930 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
932 // signal to hide this from simple content_actions
933 $content_navigation['views']['view']['redundant'] = true;
936 // If it is a non-local file, show a link to the file in its own repository
937 if ( $isForeignFile ) {
938 $file = $this->getWikiPage()->getFile();
939 $content_navigation['views']['view-foreign'] = array(
941 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
942 setContext( $this->getContext() )->
943 params( $file->getRepo()->getDisplayName() )->text(),
944 'href' => $file->getDescriptionUrl(),
949 wfProfileIn( __METHOD__
. '-edit' );
951 // Checks if user can edit the current page if it exists or create it otherwise
952 if ( $title->quickUserCan( 'edit', $user )
953 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
955 // Builds CSS class for talk page links
956 $isTalkClass = $isTalk ?
' istalk' : '';
957 // Whether the user is editing the page
958 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
959 // Whether to show the "Add a new section" tab
960 // Checks if this is a current rev of talk page and is not forced to be hidden
961 $showNewSection = !$out->forceHideNewSectionLink()
962 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
963 $section = $request->getVal( 'section' );
965 if ( $title->exists()
966 ||
( $title->getNamespace() == NS_MEDIAWIKI
967 && $title->getDefaultMessageText() !== false
970 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
972 $msgKey = $isForeignFile ?
'create-local' : 'create';
974 $content_navigation['views']['edit'] = array(
975 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
979 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
980 ->setContext( $this->getContext() )->text(),
981 'href' => $title->getLocalURL( $this->editUrlOptions() ),
982 'primary' => !$isForeignFile, // don't collapse this in vector
986 if ( $showNewSection ) {
987 // Adds new section link
988 //$content_navigation['actions']['addsection']
989 $content_navigation['views']['addsection'] = array(
990 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
991 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
992 ->setContext( $this->getContext() )->text(),
993 'href' => $title->getLocalURL( 'action=edit§ion=new' )
996 // Checks if the page has some kind of viewable content
997 } elseif ( $title->hasSourceText() ) {
998 // Adds view source view link
999 $content_navigation['views']['viewsource'] = array(
1000 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
1001 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1002 ->setContext( $this->getContext() )->text(),
1003 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1004 'primary' => true, // don't collapse this in vector
1007 wfProfileOut( __METHOD__
. '-edit' );
1009 wfProfileIn( __METHOD__
. '-live' );
1010 // Checks if the page exists
1011 if ( $title->exists() ) {
1012 // Adds history view link
1013 $content_navigation['views']['history'] = array(
1014 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1015 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1016 ->setContext( $this->getContext() )->text(),
1017 'href' => $title->getLocalURL( 'action=history' ),
1018 'rel' => 'archives',
1021 if ( $title->quickUserCan( 'delete', $user ) ) {
1022 $content_navigation['actions']['delete'] = array(
1023 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1024 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1025 ->setContext( $this->getContext() )->text(),
1026 'href' => $title->getLocalURL( 'action=delete' )
1030 if ( $title->quickUserCan( 'move', $user ) ) {
1031 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1032 $content_navigation['actions']['move'] = array(
1033 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1034 'text' => wfMessageFallback( "$skname-action-move", 'move' )
1035 ->setContext( $this->getContext() )->text(),
1036 'href' => $moveTitle->getLocalURL()
1040 // article doesn't exist or is deleted
1041 if ( $user->isAllowed( 'deletedhistory' ) ) {
1042 $n = $title->isDeleted();
1044 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1045 // If the user can't undelete but can view deleted
1046 // history show them a "View .. deleted" tab instead.
1047 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1048 $content_navigation['actions']['undelete'] = array(
1049 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1050 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1051 ->setContext( $this->getContext() )->numParams( $n )->text(),
1052 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1058 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1059 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1061 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1062 $content_navigation['actions'][$mode] = array(
1063 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1064 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1065 ->setContext( $this->getContext() )->text(),
1066 'href' => $title->getLocalURL( "action=$mode" )
1070 wfProfileOut( __METHOD__
. '-live' );
1072 // Checks if the user is logged in
1073 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1075 * The following actions use messages which, if made particular to
1076 * the any specific skins, would break the Ajax code which makes this
1077 * action happen entirely inline. Skin::makeGlobalVariablesScript
1078 * defines a set of messages in a javascript object - and these
1079 * messages are assumed to be global for all skins. Without making
1080 * a change to that procedure these messages will have to remain as
1081 * the global versions.
1083 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1084 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1085 $content_navigation['actions'][$mode] = array(
1086 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1087 // uses 'watch' or 'unwatch' message
1088 'text' => $this->msg( $mode )->text(),
1089 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1094 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1096 if ( $userCanRead && !$wgDisableLangConversion ) {
1097 $pageLang = $title->getPageLanguage();
1098 // Gets list of language variants
1099 $variants = $pageLang->getVariants();
1100 // Checks that language conversion is enabled and variants exist
1101 // And if it is not in the special namespace
1102 if ( count( $variants ) > 1 ) {
1103 // Gets preferred variant (note that user preference is
1104 // only possible for wiki content language variant)
1105 $preferred = $pageLang->getPreferredVariant();
1106 if ( Action
::getActionName( $this ) === 'view' ) {
1107 $params = $request->getQueryValues();
1108 unset( $params['title'] );
1112 // Loops over each variant
1113 foreach ( $variants as $code ) {
1114 // Gets variant name from language code
1115 $varname = $pageLang->getVariantname( $code );
1116 // Appends variant link
1117 $content_navigation['variants'][] = array(
1118 'class' => ( $code == $preferred ) ?
'selected' : false,
1120 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1121 'lang' => wfBCP47( $code ),
1122 'hreflang' => wfBCP47( $code ),
1128 // If it's not content, it's got to be a special page
1129 $content_navigation['namespaces']['special'] = array(
1130 'class' => 'selected',
1131 'text' => $this->msg( 'nstab-special' )->text(),
1132 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1133 'context' => 'subject'
1136 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1137 array( &$this, &$content_navigation ) );
1140 // Equiv to SkinTemplateContentActions
1141 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1143 // Setup xml ids and tooltip info
1144 foreach ( $content_navigation as $section => &$links ) {
1145 foreach ( $links as $key => &$link ) {
1147 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1148 $xmlID = 'ca-nstab-' . $xmlID;
1149 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1151 } elseif ( $section == 'variants' ) {
1152 $xmlID = 'ca-varlang-' . $xmlID;
1154 $xmlID = 'ca-' . $xmlID;
1156 $link['id'] = $xmlID;
1160 # We don't want to give the watch tab an accesskey if the
1161 # page is being edited, because that conflicts with the
1162 # accesskey on the watch checkbox. We also don't want to
1163 # give the edit tab an accesskey, because that's fairly
1164 # superfluous and conflicts with an accesskey (Ctrl-E) often
1165 # used for editing in Safari.
1166 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1167 if ( isset( $content_navigation['views']['edit'] ) ) {
1168 $content_navigation['views']['edit']['tooltiponly'] = true;
1170 if ( isset( $content_navigation['actions']['watch'] ) ) {
1171 $content_navigation['actions']['watch']['tooltiponly'] = true;
1173 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1174 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1178 wfProfileOut( __METHOD__
);
1180 return $content_navigation;
1184 * an array of edit links by default used for the tabs
1185 * @param $content_navigation
1188 private function buildContentActionUrls( $content_navigation ) {
1190 wfProfileIn( __METHOD__
);
1192 // content_actions has been replaced with content_navigation for backwards
1193 // compatibility and also for skins that just want simple tabs content_actions
1194 // is now built by flattening the content_navigation arrays into one
1196 $content_actions = array();
1198 foreach ( $content_navigation as $links ) {
1199 foreach ( $links as $key => $value ) {
1200 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1201 // Redundant tabs are dropped from content_actions
1205 // content_actions used to have ids built using the "ca-$key" pattern
1206 // so the xmlID based id is much closer to the actual $key that we want
1207 // for that reason we'll just strip out the ca- if present and use
1208 // the latter potion of the "id" as the $key
1209 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1210 $key = substr( $value['id'], 3 );
1213 if ( isset( $content_actions[$key] ) ) {
1214 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1215 "content_navigation into content_actions.\n" );
1219 $content_actions[$key] = $value;
1223 wfProfileOut( __METHOD__
);
1225 return $content_actions;
1229 * build array of common navigation links
1232 protected function buildNavUrls() {
1233 global $wgUploadNavigationUrl;
1235 wfProfileIn( __METHOD__
);
1237 $out = $this->getOutput();
1238 $request = $this->getRequest();
1240 $nav_urls = array();
1241 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1242 if ( $wgUploadNavigationUrl ) {
1243 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1244 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1245 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1247 $nav_urls['upload'] = false;
1249 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1251 $nav_urls['print'] = false;
1252 $nav_urls['permalink'] = false;
1253 $nav_urls['info'] = false;
1254 $nav_urls['whatlinkshere'] = false;
1255 $nav_urls['recentchangeslinked'] = false;
1256 $nav_urls['contributions'] = false;
1257 $nav_urls['log'] = false;
1258 $nav_urls['blockip'] = false;
1259 $nav_urls['emailuser'] = false;
1260 $nav_urls['userrights'] = false;
1262 // A print stylesheet is attached to all pages, but nobody ever
1263 // figures that out. :) Add a link...
1264 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1265 $nav_urls['print'] = array(
1266 'text' => $this->msg( 'printableversion' )->text(),
1267 'href' => $this->getTitle()->getLocalURL(
1268 $request->appendQueryValue( 'printable', 'yes', true ) )
1272 if ( $out->isArticle() ) {
1273 // Also add a "permalink" while we're at it
1274 $revid = $this->getRevisionId();
1276 $nav_urls['permalink'] = array(
1277 'text' => $this->msg( 'permalink' )->text(),
1278 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1282 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1283 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1284 array( &$this, &$nav_urls, &$revid, &$revid ) );
1287 if ( $out->isArticleRelated() ) {
1288 $nav_urls['whatlinkshere'] = array(
1289 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1292 $nav_urls['info'] = array(
1293 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1294 'href' => $this->getTitle()->getLocalURL( "action=info" )
1297 if ( $this->getTitle()->getArticleID() ) {
1298 $nav_urls['recentchangeslinked'] = array(
1299 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1304 $user = $this->getRelevantUser();
1306 $rootUser = $user->getName();
1308 $nav_urls['contributions'] = array(
1309 'text' => $this->msg( 'contributions', $rootUser )->text(),
1310 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1313 $nav_urls['log'] = array(
1314 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1317 if ( $this->getUser()->isAllowed( 'block' ) ) {
1318 $nav_urls['blockip'] = array(
1319 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1323 if ( $this->showEmailUser( $user ) ) {
1324 $nav_urls['emailuser'] = array(
1325 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1329 if ( !$user->isAnon() ) {
1330 $sur = new UserrightsPage
;
1331 $sur->setContext( $this->getContext() );
1332 if ( $sur->userCanExecute( $this->getUser() ) ) {
1333 $nav_urls['userrights'] = array(
1334 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1340 wfProfileOut( __METHOD__
);
1345 * Generate strings used for xml 'id' names
1348 protected function getNameSpaceKey() {
1349 return $this->getTitle()->getNamespaceKey();
1354 * Generic wrapper for template functions, with interface
1355 * compatible with what we use of PHPTAL 0.7.
1358 abstract class QuickTemplate
{
1362 function __construct() {
1363 $this->data
= array();
1364 $this->translator
= new MediaWikiI18N();
1368 * Sets the value $value to $name
1369 * @param string $name
1370 * @param mixed $value
1372 public function set( $name, $value ) {
1373 $this->data
[$name] = $value;
1377 * Gets the template data requested
1379 * @param string $name Key for the data
1380 * @param mixed $default Optional default (or null)
1381 * @return mixed The value of the data requested or the deafult
1383 public function get( $name, $default = null ) {
1384 if ( isset( $this->data
[$name] ) ) {
1385 return $this->data
[$name];
1392 * @param string $name
1393 * @param mixed $value
1395 public function setRef( $name, &$value ) {
1396 $this->data
[$name] =& $value;
1400 * @param MediaWikiI18N $t
1402 public function setTranslator( &$t ) {
1403 $this->translator
= &$t;
1407 * Main function, used by classes that subclass QuickTemplate
1408 * to show the actual HTML output
1410 abstract public function execute();
1414 * @param string $str
1417 function text( $str ) {
1418 echo htmlspecialchars( $this->data
[$str] );
1423 * @param string $str
1426 function html( $str ) {
1427 echo $this->data
[$str];
1432 * @param string $str
1435 function msg( $str ) {
1436 echo htmlspecialchars( $this->translator
->translate( $str ) );
1441 * @param string $str
1444 function msgHtml( $str ) {
1445 echo $this->translator
->translate( $str );
1449 * An ugly, ugly hack.
1451 * @param string $str
1454 function msgWiki( $str ) {
1457 $text = $this->translator
->translate( $str );
1458 echo $wgOut->parse( $text );
1463 * @param string $str
1466 function haveData( $str ) {
1467 return isset( $this->data
[$str] );
1473 * @param string $str
1476 function haveMsg( $str ) {
1477 $msg = $this->translator
->translate( $str );
1478 return ( $msg != '-' ) && ( $msg != '' ); # ????
1482 * Get the Skin object related to this object
1486 public function getSkin() {
1487 return $this->data
['skin'];
1491 * Fetch the output of a QuickTemplate and return it
1496 public function getHTML() {
1499 $html = ob_get_contents();
1506 * New base template for a skin's template extended from QuickTemplate
1507 * this class features helper methods that provide common ways of interacting
1508 * with the data stored in the QuickTemplate
1510 abstract class BaseTemplate
extends QuickTemplate
{
1513 * Get a Message object with its context set
1515 * @param string $name Message name
1518 public function getMsg( $name ) {
1519 return $this->getSkin()->msg( $name );
1522 function msg( $str ) {
1523 echo $this->getMsg( $str )->escaped();
1526 function msgHtml( $str ) {
1527 echo $this->getMsg( $str )->text();
1530 function msgWiki( $str ) {
1531 echo $this->getMsg( $str )->parseAsBlock();
1535 * Create an array of common toolbox items from the data in the quicktemplate
1536 * stored by SkinTemplate.
1537 * The resulting array is built according to a format intended to be passed
1538 * through makeListItem to generate the html.
1541 function getToolbox() {
1542 wfProfileIn( __METHOD__
);
1545 if ( isset( $this->data
['nav_urls']['whatlinkshere'] )
1546 && $this->data
['nav_urls']['whatlinkshere']
1548 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1549 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1551 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] )
1552 && $this->data
['nav_urls']['recentchangeslinked']
1554 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1555 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1556 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1558 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1559 $toolbox['feeds']['id'] = 'feedlinks';
1560 $toolbox['feeds']['links'] = array();
1561 foreach ( $this->data
['feeds'] as $key => $feed ) {
1562 $toolbox['feeds']['links'][$key] = $feed;
1563 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1564 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1565 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1566 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1569 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser',
1570 'userrights', 'upload', 'specialpages' ) as $special
1572 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1573 $toolbox[$special] = $this->data
['nav_urls'][$special];
1574 $toolbox[$special]['id'] = "t-$special";
1577 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1578 $toolbox['print'] = $this->data
['nav_urls']['print'];
1579 $toolbox['print']['id'] = 't-print';
1580 $toolbox['print']['rel'] = 'alternate';
1581 $toolbox['print']['msg'] = 'printableversion';
1583 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1584 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1585 if ( $toolbox['permalink']['href'] === '' ) {
1586 unset( $toolbox['permalink']['href'] );
1587 $toolbox['ispermalink']['tooltiponly'] = true;
1588 $toolbox['ispermalink']['id'] = 't-ispermalink';
1589 $toolbox['ispermalink']['msg'] = 'permalink';
1591 $toolbox['permalink']['id'] = 't-permalink';
1594 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1595 $toolbox['info'] = $this->data
['nav_urls']['info'];
1596 $toolbox['info']['id'] = 't-info';
1599 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1600 wfProfileOut( __METHOD__
);
1605 * Create an array of personal tools items from the data in the quicktemplate
1606 * stored by SkinTemplate.
1607 * The resulting array is built according to a format intended to be passed
1608 * through makeListItem to generate the html.
1609 * This is in reality the same list as already stored in personal_urls
1610 * however it is reformatted so that you can just pass the individual items
1611 * to makeListItem instead of hardcoding the element creation boilerplate.
1614 function getPersonalTools() {
1615 $personal_tools = array();
1616 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1617 # The class on a personal_urls item is meant to go on the <a> instead
1618 # of the <li> so we have to use a single item "links" array instead
1619 # of using most of the personal_url's keys directly.
1622 array( 'single-id' => "pt-$key" ),
1626 if ( isset( $plink['active'] ) ) {
1627 $ptool['active'] = $plink['active'];
1629 foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) {
1630 if ( isset( $plink[$k] ) ) {
1631 $ptool['links'][0][$k] = $plink[$k];
1634 $personal_tools[$key] = $ptool;
1636 return $personal_tools;
1639 function getSidebar( $options = array() ) {
1640 // Force the rendering of the following portals
1641 $sidebar = $this->data
['sidebar'];
1642 if ( !isset( $sidebar['SEARCH'] ) ) {
1643 $sidebar['SEARCH'] = true;
1645 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1646 $sidebar['TOOLBOX'] = true;
1648 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1649 $sidebar['LANGUAGES'] = true;
1652 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1653 unset( $sidebar['SEARCH'] );
1655 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1656 unset( $sidebar['TOOLBOX'] );
1658 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1659 unset( $sidebar['LANGUAGES'] );
1663 foreach ( $sidebar as $boxName => $content ) {
1664 if ( $content === false ) {
1667 switch ( $boxName ) {
1669 // Search is a special case, skins should custom implement this
1670 $boxes[$boxName] = array(
1672 'header' => $this->getMsg( 'search' )->text(),
1673 'generated' => false,
1678 $msgObj = $this->getMsg( 'toolbox' );
1679 $boxes[$boxName] = array(
1681 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1682 'generated' => false,
1683 'content' => $this->getToolbox(),
1687 if ( $this->data
['language_urls'] ) {
1688 $msgObj = $this->getMsg( 'otherlanguages' );
1689 $boxes[$boxName] = array(
1691 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1692 'generated' => false,
1693 'content' => $this->data
['language_urls'],
1698 $msgObj = $this->getMsg( $boxName );
1699 $boxes[$boxName] = array(
1700 'id' => "p-$boxName",
1701 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1702 'generated' => true,
1703 'content' => $content,
1709 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1710 $hookContents = null;
1711 if ( isset( $boxes['TOOLBOX'] ) ) {
1713 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1714 // can abort and avoid outputting double toolbox links
1715 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1716 $hookContents = ob_get_contents();
1718 if ( !trim( $hookContents ) ) {
1719 $hookContents = null;
1724 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1725 foreach ( $boxes as $boxName => $box ) {
1726 if ( is_array( $box['content'] ) ) {
1728 foreach ( $box['content'] as $key => $val ) {
1729 $content .= "\n " . $this->makeListItem( $key, $val );
1731 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1732 if ( $hookContents ) {
1733 $content .= "\n $hookContents";
1736 $content .= "\n</ul>\n";
1737 $boxes[$boxName]['content'] = $content;
1741 if ( $hookContents ) {
1742 $boxes['TOOLBOXEND'] = array(
1743 'id' => 'p-toolboxend',
1744 'header' => $boxes['TOOLBOX']['header'],
1745 'generated' => false,
1746 'content' => "<ul>{$hookContents}</ul>",
1748 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1750 foreach ( $boxes as $key => $box ) {
1751 if ( $key === 'TOOLBOXEND' ) {
1754 $boxes2[$key] = $box;
1755 if ( $key === 'TOOLBOX' ) {
1756 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1768 * @param string $name
1770 protected function renderAfterPortlet( $name ) {
1772 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
1774 if ( $content !== '' ) {
1775 echo "<div class='after-portlet after-portlet-$name'>$content</div>";
1781 * Makes a link, usually used by makeListItem to generate a link for an item
1782 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1784 * @param string $key usually a key from the list you are generating this
1786 * @param array $item contains some of a specific set of keys.
1788 * The text of the link will be generated either from the contents of the
1789 * "text" key in the $item array, if a "msg" key is present a message by
1790 * that name will be used, and if neither of those are set the $key will be
1791 * used as a message name.
1793 * If a "href" key is not present makeLink will just output htmlescaped text.
1794 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1795 * for the link if present.
1797 * If an "id" or "single-id" (if you don't want the actual id to be output
1798 * on the link) is present it will be used to generate a tooltip and
1799 * accesskey for the link.
1801 * The keys "context" and "primary" are ignored; these keys are used
1802 * internally by skins and are not supposed to be included in the HTML
1805 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1807 * @param array $options can be used to affect the output of a link.
1808 * Possible options are:
1809 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1810 * a link in. This should be an array of arrays containing a 'tag' and
1811 * optionally an 'attributes' key. If you only have one element you don't
1812 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1813 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1815 * - 'link-class' key can be used to specify additional classes to apply
1817 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1818 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1819 * any non-link will output a "<span>" instead of just text.
1823 function makeLink( $key, $item, $options = array() ) {
1824 if ( isset( $item['text'] ) ) {
1825 $text = $item['text'];
1827 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1830 $html = htmlspecialchars( $text );
1832 if ( isset( $options['text-wrapper'] ) ) {
1833 $wrapper = $options['text-wrapper'];
1834 if ( isset( $wrapper['tag'] ) ) {
1835 $wrapper = array( $wrapper );
1837 while ( count( $wrapper ) > 0 ) {
1838 $element = array_pop( $wrapper );
1839 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] )
1840 ?
$element['attributes']
1845 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1847 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1848 unset( $attrs[$k] );
1851 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1852 $item['single-id'] = $item['id'];
1854 if ( isset( $item['single-id'] ) ) {
1855 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1856 $title = Linker
::titleAttrib( $item['single-id'] );
1857 if ( $title !== false ) {
1858 $attrs['title'] = $title;
1861 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1862 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1863 $attrs['title'] = $tip['title'];
1865 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1866 $attrs['accesskey'] = $tip['accesskey'];
1870 if ( isset( $options['link-class'] ) ) {
1871 if ( isset( $attrs['class'] ) ) {
1872 $attrs['class'] .= " {$options['link-class']}";
1874 $attrs['class'] = $options['link-class'];
1877 $html = Html
::rawElement( isset( $attrs['href'] )
1879 : $options['link-fallback'], $attrs, $html );
1886 * Generates a list item for a navigation, portlet, portal, sidebar... list
1888 * @param string $key Usually a key from the list you are generating this link from.
1889 * @param array $item Array of list item data containing some of a specific set of keys.
1890 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
1891 * if "active" contains a value of true a "active" class will also be appended to class.
1893 * @param array $options
1895 * If you want something other than a "<li>" you can pass a tag name such as
1896 * "tag" => "span" in the $options array to change the tag used.
1897 * link/content data for the list item may come in one of two forms
1898 * A "links" key may be used, in which case it should contain an array with
1899 * a list of links to include inside the list item, see makeLink for the
1900 * format of individual links array items.
1902 * Otherwise the relevant keys from the list item $item array will be passed
1903 * to makeLink instead. Note however that "id" and "class" are used by the
1904 * list item directly so they will not be passed to makeLink
1905 * (however the link will still support a tooltip and accesskey from it)
1906 * If you need an id or class on a single link you should include a "links"
1907 * array with just one link item inside of it. If you want to add a title
1908 * to the list item itself, you can set "itemtitle" to the value.
1909 * $options is also passed on to makeLink calls
1913 function makeListItem( $key, $item, $options = array() ) {
1914 if ( isset( $item['links'] ) ) {
1916 foreach ( $item['links'] as $linkKey => $link ) {
1917 $links[] = $this->makeLink( $linkKey, $link, $options );
1919 $html = implode( ' ', $links );
1922 // These keys are used by makeListItem and shouldn't be passed on to the link
1923 foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) {
1926 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1927 // The id goes on the <li> not on the <a> for single links
1928 // but makeSidebarLink still needs to know what id to use when
1929 // generating tooltips and accesskeys.
1930 $link['single-id'] = $item['id'];
1932 $html = $this->makeLink( $key, $link, $options );
1936 foreach ( array( 'id', 'class' ) as $attr ) {
1937 if ( isset( $item[$attr] ) ) {
1938 $attrs[$attr] = $item[$attr];
1941 if ( isset( $item['active'] ) && $item['active'] ) {
1942 if ( !isset( $attrs['class'] ) ) {
1943 $attrs['class'] = '';
1945 $attrs['class'] .= ' active';
1946 $attrs['class'] = trim( $attrs['class'] );
1948 if ( isset( $item['itemtitle'] ) ) {
1949 $attrs['title'] = $item['itemtitle'];
1951 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1954 function makeSearchInput( $attrs = array() ) {
1958 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1959 'value' => $this->get( 'search', '' ),
1961 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1962 return Html
::element( 'input', $realAttrs );
1965 function makeSearchButton( $mode, $attrs = array() ) {
1972 'value' => $this->translator
->translate(
1973 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1975 $realAttrs = array_merge(
1977 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1980 return Html
::element( 'input', $realAttrs );
1982 $buttonAttrs = array(
1986 $buttonAttrs = array_merge(
1988 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1991 unset( $buttonAttrs['src'] );
1992 unset( $buttonAttrs['alt'] );
1993 unset( $buttonAttrs['width'] );
1994 unset( $buttonAttrs['height'] );
1996 'src' => $attrs['src'],
1997 'alt' => isset( $attrs['alt'] )
1999 : $this->translator
->translate( 'searchbutton' ),
2000 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
2001 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
2003 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
2005 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
2010 * Returns an array of footerlinks trimmed down to only those footer links that
2012 * If you pass "flat" as an option then the returned array will be a flat array
2013 * of footer icons instead of a key/value array of footerlinks arrays broken
2014 * up into categories.
2015 * @param string $option
2016 * @return array|mixed
2018 function getFooterLinks( $option = null ) {
2019 $footerlinks = $this->get( 'footerlinks' );
2021 // Reduce footer links down to only those which are being used
2022 $validFooterLinks = array();
2023 foreach ( $footerlinks as $category => $links ) {
2024 $validFooterLinks[$category] = array();
2025 foreach ( $links as $link ) {
2026 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
2027 $validFooterLinks[$category][] = $link;
2030 if ( count( $validFooterLinks[$category] ) <= 0 ) {
2031 unset( $validFooterLinks[$category] );
2035 if ( $option == 'flat' ) {
2036 // fold footerlinks into a single array using a bit of trickery
2037 $validFooterLinks = call_user_func_array(
2039 array_values( $validFooterLinks )
2043 return $validFooterLinks;
2047 * Returns an array of footer icons filtered down by options relevant to how
2048 * the skin wishes to display them.
2049 * If you pass "icononly" as the option all footer icons which do not have an
2050 * image icon set will be filtered out.
2051 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
2052 * in the list of footer icons. This is mostly useful for skins which only
2053 * display the text from footericons instead of the images and don't want a
2054 * duplicate copyright statement because footerlinks already rendered one.
2055 * @param string $option
2058 function getFooterIcons( $option = null ) {
2059 // Generate additional footer icons
2060 $footericons = $this->get( 'footericons' );
2062 if ( $option == 'icononly' ) {
2063 // Unset any icons which don't have an image
2064 foreach ( $footericons as &$footerIconsBlock ) {
2065 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2066 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2067 unset( $footerIconsBlock[$footerIconKey] );
2071 // Redo removal of any empty blocks
2072 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2073 if ( count( $footerIconsBlock ) <= 0 ) {
2074 unset( $footericons[$footerIconsKey] );
2077 } elseif ( $option == 'nocopyright' ) {
2078 unset( $footericons['copyright']['copyright'] );
2079 if ( count( $footericons['copyright'] ) <= 0 ) {
2080 unset( $footericons['copyright'] );
2084 return $footericons;
2088 * Output the basic end-page trail including bottomscripts, reporttime, and
2089 * debug stuff. This should be called right before outputting the closing
2090 * body and html tags.
2092 function printTrail() { ?
>
2093 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2094 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2095 <?php
$this->html( 'reporttime' ) ?
>