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 For QuickTemplate, the name of the subclass which will
79 * actually fill the template. Child classes should override the default.
81 public $template = 'QuickTemplate';
84 * Add specific styles for this skin
86 * @param OutputPage $out
88 function setupSkinUserCss( OutputPage
$out ) {
89 $out->addModuleStyles( array(
90 'mediawiki.legacy.shared',
91 'mediawiki.legacy.commonPrint',
97 * Create the template engine object; we feed it a bunch of data
98 * and eventually it spits out some HTML. Should have interface
99 * roughly equivalent to PHPTAL 0.7.
101 * @param string $classname
102 * @param bool|string $repository Subdirectory where we keep template files
103 * @param bool|string $cache_dir
104 * @return QuickTemplate
107 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
108 return new $classname();
112 * Generates array of language links for the current page
116 public function getLanguages() {
117 global $wgHideInterlanguageLinks;
118 if ( $wgHideInterlanguageLinks ) {
122 $userLang = $this->getLanguage();
123 $languageLinks = array();
125 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
126 $languageLinkParts = explode( ':', $languageLinkText, 2 );
127 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
128 unset( $languageLinkParts );
130 $languageLinkTitle = Title
::newFromText( $languageLinkText );
131 if ( $languageLinkTitle ) {
132 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
133 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
135 if ( strval( $ilLangName ) === '' ) {
136 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
137 if ( !$ilDisplayTextMsg->isDisabled() ) {
138 // Use custom MW message for the display text
139 $ilLangName = $ilDisplayTextMsg->text();
141 // Last resort: fallback to the language link target
142 $ilLangName = $languageLinkText;
145 // Use the language autonym as display text
146 $ilLangName = $this->formatLanguageName( $ilLangName );
149 // CLDR extension or similar is required to localize the language name;
150 // otherwise we'll end up with the autonym again.
151 $ilLangLocalName = Language
::fetchLanguageName(
156 $languageLinkTitleText = $languageLinkTitle->getText();
157 if ( $ilLangLocalName === '' ) {
158 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
159 if ( !$ilFriendlySiteName->isDisabled() ) {
160 if ( $languageLinkTitleText === '' ) {
161 $ilTitle = wfMessage(
162 'interlanguage-link-title-nonlangonly',
163 $ilFriendlySiteName->text()
166 $ilTitle = wfMessage(
167 'interlanguage-link-title-nonlang',
168 $languageLinkTitleText,
169 $ilFriendlySiteName->text()
173 // we have nothing friendly to put in the title, so fall back to
174 // displaying the interlanguage link itself in the title text
175 // (similar to what is done in page content)
176 $ilTitle = $languageLinkTitle->getInterwiki() .
177 ":$languageLinkTitleText";
179 } elseif ( $languageLinkTitleText === '' ) {
180 $ilTitle = wfMessage(
181 'interlanguage-link-title-langonly',
185 $ilTitle = wfMessage(
186 'interlanguage-link-title',
187 $languageLinkTitleText,
192 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
193 $languageLink = array(
194 'href' => $languageLinkTitle->getFullURL(),
195 'text' => $ilLangName,
198 'lang' => $ilInterwikiCodeBCP47,
199 'hreflang' => $ilInterwikiCodeBCP47,
202 'SkinTemplateGetLanguageLink',
203 array( &$languageLink, $languageLinkTitle, $this->getTitle() )
205 $languageLinks[] = $languageLink;
209 return $languageLinks;
212 protected function setupTemplateForOutput() {
213 wfProfileIn( __METHOD__
);
215 $request = $this->getRequest();
216 $user = $this->getUser();
217 $title = $this->getTitle();
219 wfProfileIn( __METHOD__
. '-init' );
220 $tpl = $this->setupTemplate( $this->template
, 'skins' );
221 wfProfileOut( __METHOD__
. '-init' );
223 wfProfileIn( __METHOD__
. '-stuff' );
224 $this->thispage
= $title->getPrefixedDBkey();
225 $this->titletxt
= $title->getPrefixedText();
226 $this->userpage
= $user->getUserPage()->getPrefixedText();
228 if ( !$request->wasPosted() ) {
229 $query = $request->getValues();
230 unset( $query['title'] );
231 unset( $query['returnto'] );
232 unset( $query['returntoquery'] );
234 $this->thisquery
= wfArrayToCgi( $query );
235 $this->loggedin
= $user->isLoggedIn();
236 $this->username
= $user->getName();
238 if ( $this->loggedin ||
$this->showIPinHeader() ) {
239 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
241 # This won't be used in the standard skins, but we define it to preserve the interface
242 # To save time, we check for existence
243 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
246 wfProfileOut( __METHOD__
. '-stuff' );
248 wfProfileOut( __METHOD__
);
254 * initialize various variables and generate the template
256 * @param OutputPage $out
258 function outputPage( OutputPage
$out = null ) {
259 wfProfileIn( __METHOD__
);
260 Profiler
::instance()->setTemplated( true );
263 if ( $out !== null ) {
264 // @todo Add wfDeprecated in 1.20
265 $oldContext = $this->getContext();
266 $this->setContext( $out->getContext() );
269 $out = $this->getOutput();
271 wfProfileIn( __METHOD__
. '-init' );
272 $this->initPage( $out );
273 wfProfileOut( __METHOD__
. '-init' );
274 $tpl = $this->prepareQuickTemplate( $out );
276 wfProfileIn( __METHOD__
. '-execute' );
277 $res = $tpl->execute();
278 wfProfileOut( __METHOD__
. '-execute' );
280 // result may be an error
281 $this->printOrError( $res );
284 $this->setContext( $oldContext );
287 wfProfileOut( __METHOD__
);
291 * initialize various variables and generate the template
294 * @return QuickTemplate The template to be executed by outputPage
296 protected function prepareQuickTemplate() {
297 global $wgContLang, $wgScript, $wgStylePath,
298 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
299 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
300 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
301 $wgScriptPath, $wgServer;
303 wfProfileIn( __METHOD__
);
305 $title = $this->getTitle();
306 $request = $this->getRequest();
307 $out = $this->getOutput();
308 $tpl = $this->setupTemplateForOutput();
310 wfProfileIn( __METHOD__
. '-stuff2' );
311 $tpl->set( 'title', $out->getPageTitle() );
312 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
313 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
315 $tpl->setRef( 'thispage', $this->thispage
);
316 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
317 $tpl->set( 'titletext', $title->getText() );
318 $tpl->set( 'articleid', $title->getArticleID() );
320 $tpl->set( 'isarticle', $out->isArticle() );
322 $subpagestr = $this->subPageSubtitle();
323 if ( $subpagestr !== '' ) {
324 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
326 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
328 $undelete = $this->getUndeleteLink();
329 if ( $undelete === '' ) {
330 $tpl->set( 'undelete', '' );
332 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
335 $tpl->set( 'catlinks', $this->getCategories() );
336 if ( $out->isSyndicated() ) {
338 foreach ( $out->getSyndicationLinks() as $format => $link ) {
339 $feeds[$format] = array(
340 // Messages: feed-atom, feed-rss
341 'text' => $this->msg( "feed-$format" )->text(),
345 $tpl->setRef( 'feeds', $feeds );
347 $tpl->set( 'feeds', false );
350 $tpl->setRef( 'mimetype', $wgMimeType );
351 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
352 $tpl->set( 'charset', 'UTF-8' );
353 $tpl->setRef( 'wgScript', $wgScript );
354 $tpl->setRef( 'skinname', $this->skinname
);
355 $tpl->set( 'skinclass', get_class( $this ) );
356 $tpl->setRef( 'skin', $this );
357 $tpl->setRef( 'stylename', $this->stylename
);
358 $tpl->set( 'printable', $out->isPrintable() );
359 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
360 $tpl->setRef( 'loggedin', $this->loggedin
);
361 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
362 $tpl->set( 'searchaction', $this->escapeSearchLink() );
363 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
364 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
365 $tpl->setRef( 'stylepath', $wgStylePath );
366 $tpl->setRef( 'articlepath', $wgArticlePath );
367 $tpl->setRef( 'scriptpath', $wgScriptPath );
368 $tpl->setRef( 'serverurl', $wgServer );
369 $tpl->setRef( 'logopath', $wgLogo );
370 $tpl->setRef( 'sitename', $wgSitename );
372 $userLang = $this->getLanguage();
373 $userLangCode = $userLang->getHtmlCode();
374 $userLangDir = $userLang->getDir();
376 $tpl->set( 'lang', $userLangCode );
377 $tpl->set( 'dir', $userLangDir );
378 $tpl->set( 'rtl', $userLang->isRTL() );
380 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
381 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
382 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
383 $tpl->setRef( 'userpage', $this->userpage
);
384 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
385 $tpl->set( 'userlang', $userLangCode );
387 // Users can have their language set differently than the
388 // content of the wiki. For these users, tell the web browser
389 // that interface elements are in a different language.
390 $tpl->set( 'userlangattributes', '' );
391 $tpl->set( 'specialpageattributes', '' ); # obsolete
392 // Used by VectorBeta to insert HTML before content but after the
393 // heading for the page title. Defaults to empty string.
394 $tpl->set( 'prebodyhtml', '' );
396 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
397 $escUserlang = htmlspecialchars( $userLangCode );
398 $escUserdir = htmlspecialchars( $userLangDir );
399 // Attributes must be in double quotes because htmlspecialchars() doesn't
400 // escape single quotes
401 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
402 $tpl->set( 'userlangattributes', $attrs );
405 wfProfileOut( __METHOD__
. '-stuff2' );
407 wfProfileIn( __METHOD__
. '-stuff3' );
408 $tpl->set( 'newtalk', $this->getNewtalks() );
409 $tpl->set( 'logo', $this->logoText() );
411 $tpl->set( 'copyright', false );
412 $tpl->set( 'viewcount', false );
413 $tpl->set( 'lastmod', false );
414 $tpl->set( 'credits', false );
415 $tpl->set( 'numberofwatchingusers', false );
416 if ( $out->isArticle() && $title->exists() ) {
417 if ( $this->isRevisionCurrent() ) {
418 if ( !$wgDisableCounters ) {
419 $viewcount = $this->getWikiPage()->getCount();
421 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
425 if ( $wgPageShowWatchingUsers ) {
426 $dbr = wfGetDB( DB_SLAVE
);
427 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
428 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
432 $tpl->set( 'numberofwatchingusers',
433 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
438 if ( $wgMaxCredits != 0 ) {
439 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
440 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
442 $tpl->set( 'lastmod', $this->lastModified() );
445 $tpl->set( 'copyright', $this->getCopyright() );
447 wfProfileOut( __METHOD__
. '-stuff3' );
449 wfProfileIn( __METHOD__
. '-stuff4' );
450 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
451 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
452 $tpl->set( 'disclaimer', $this->disclaimerLink() );
453 $tpl->set( 'privacy', $this->privacyLink() );
454 $tpl->set( 'about', $this->aboutLink() );
456 $tpl->set( 'footerlinks', array(
460 'numberofwatchingusers',
471 global $wgFooterIcons;
472 $tpl->set( 'footericons', $wgFooterIcons );
473 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
474 if ( count( $footerIconsBlock ) > 0 ) {
475 foreach ( $footerIconsBlock as &$footerIcon ) {
476 if ( isset( $footerIcon['src'] ) ) {
477 if ( !isset( $footerIcon['width'] ) ) {
478 $footerIcon['width'] = 88;
480 if ( !isset( $footerIcon['height'] ) ) {
481 $footerIcon['height'] = 31;
486 unset( $tpl->data
['footericons'][$footerIconsKey] );
490 $tpl->set( 'sitenotice', $this->getSiteNotice() );
491 $tpl->set( 'bottomscripts', $this->bottomScripts() );
492 $tpl->set( 'printfooter', $this->printSource() );
494 # An ID that includes the actual body text; without categories, contentSub, ...
495 $realBodyAttribs = array( 'id' => 'mw-content-text' );
497 # Add a mw-content-ltr/rtl class to be able to style based on text direction
498 # when the content is different from the UI language, i.e.:
499 # not for special pages or file pages AND only when viewing AND if the page exists
500 # (or is in MW namespace, because that has default content)
501 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
502 Action
::getActionName( $this ) === 'view' &&
503 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
504 $pageLang = $title->getPageViewLanguage();
505 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
506 $realBodyAttribs['dir'] = $pageLang->getDir();
507 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
510 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
511 $tpl->setRef( 'bodytext', $out->mBodytext
);
513 $language_urls = $this->getLanguages();
514 if ( count( $language_urls ) ) {
515 $tpl->setRef( 'language_urls', $language_urls );
517 $tpl->set( 'language_urls', false );
519 wfProfileOut( __METHOD__
. '-stuff4' );
521 wfProfileIn( __METHOD__
. '-stuff5' );
523 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
524 $content_navigation = $this->buildContentNavigationUrls();
525 $content_actions = $this->buildContentActionUrls( $content_navigation );
526 $tpl->setRef( 'content_navigation', $content_navigation );
527 $tpl->setRef( 'content_actions', $content_actions );
529 $tpl->set( 'sidebar', $this->buildSidebar() );
530 $tpl->set( 'nav_urls', $this->buildNavUrls() );
532 // Set the head scripts near the end, in case the above actions resulted in added scripts
533 $tpl->set( 'headelement', $out->headElement( $this ) );
535 $tpl->set( 'debug', '' );
536 $tpl->set( 'debughtml', $this->generateDebugHTML() );
537 $tpl->set( 'reporttime', wfReportTime() );
539 // original version by hansm
540 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
541 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
544 // Set the bodytext to another key so that skins can just output it on it's own
545 // and output printfooter and debughtml separately
546 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
548 // Append printfooter and debughtml onto bodytext so that skins that
549 // were already using bodytext before they were split out don't suddenly
550 // start not outputting information.
551 $tpl->data
['bodytext'] .= Html
::rawElement(
553 array( 'class' => 'printfooter' ),
554 "\n{$tpl->data['printfooter']}"
556 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
558 // allow extensions adding stuff after the page content.
559 // See Skin::afterContentHook() for further documentation.
560 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
561 wfProfileOut( __METHOD__
. '-stuff5' );
563 wfProfileOut( __METHOD__
);
568 * Get the HTML for the p-personal list
571 public function getPersonalToolsList() {
572 $tpl = $this->setupTemplateForOutput();
573 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
575 foreach ( $tpl->getPersonalTools() as $key => $item ) {
576 $html .= $tpl->makeListItem( $key, $item );
582 * Format language name for use in sidebar interlanguage links list.
583 * By default it is capitalized.
585 * @param string $name Language name, e.g. "English" or "español"
589 function formatLanguageName( $name ) {
590 return $this->getLanguage()->ucfirst( $name );
594 * Output the string, or print error message if it's
595 * an error object of the appropriate type.
596 * For the base class, assume strings all around.
601 function printOrError( $str ) {
606 * Output a boolean indicating if buildPersonalUrls should output separate
607 * login and create account links or output a combined link
608 * By default we simply return a global config setting that affects most skins
609 * This is setup as a method so that like with $wgLogo and getLogo() a skin
610 * can override this setting and always output one or the other if it has
611 * a reason it can't output one of the two modes.
614 function useCombinedLoginLink() {
615 global $wgUseCombinedLoginLink;
616 return $wgUseCombinedLoginLink;
620 * build array of urls for personal toolbar
623 protected function buildPersonalUrls() {
624 $title = $this->getTitle();
625 $request = $this->getRequest();
626 $pageurl = $title->getLocalURL();
627 wfProfileIn( __METHOD__
);
629 /* set up the default links for the personal toolbar */
630 $personal_urls = array();
632 # Due to bug 32276, if a user does not have read permissions,
633 # $this->getTitle() will just give Special:Badtitle, which is
634 # not especially useful as a returnto parameter. Use the title
635 # from the request instead, if there was one.
636 if ( $this->getUser()->isAllowed( 'read' ) ) {
637 $page = $this->getTitle();
639 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
641 $page = $request->getVal( 'returnto', $page );
643 if ( strval( $page ) !== '' ) {
644 $a['returnto'] = $page;
645 $query = $request->getVal( 'returntoquery', $this->thisquery
);
646 if ( $query != '' ) {
647 $a['returntoquery'] = $query;
651 $returnto = wfArrayToCgi( $a );
652 if ( $this->loggedin
) {
653 $personal_urls['userpage'] = array(
654 'text' => $this->username
,
655 'href' => &$this->userpageUrlDetails
['href'],
656 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
657 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
660 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
661 $personal_urls['mytalk'] = array(
662 'text' => $this->msg( 'mytalk' )->text(),
663 'href' => &$usertalkUrlDetails['href'],
664 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
665 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
667 $href = self
::makeSpecialUrl( 'Preferences' );
668 $personal_urls['preferences'] = array(
669 'text' => $this->msg( 'mypreferences' )->text(),
671 'active' => ( $href == $pageurl )
674 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
675 $href = self
::makeSpecialUrl( 'Watchlist' );
676 $personal_urls['watchlist'] = array(
677 'text' => $this->msg( 'mywatchlist' )->text(),
679 'active' => ( $href == $pageurl )
683 # We need to do an explicit check for Special:Contributions, as we
684 # have to match both the title, and the target, which could come
685 # from request values (Special:Contributions?target=Jimbo_Wales)
686 # or be specified in "sub page" form
687 # (Special:Contributions/Jimbo_Wales). The plot
688 # thickens, because the Title object is altered for special pages,
689 # so it doesn't contain the original alias-with-subpage.
690 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
691 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
692 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
693 $active = $spName == 'Contributions'
694 && ( ( $spPar && $spPar == $this->username
)
695 ||
$request->getText( 'target' ) == $this->username
);
700 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
701 $personal_urls['mycontris'] = array(
702 'text' => $this->msg( 'mycontris' )->text(),
706 $personal_urls['logout'] = array(
707 'text' => $this->msg( 'pt-userlogout' )->text(),
708 'href' => self
::makeSpecialUrl( 'Userlogout',
709 // userlogout link must always contain an & character, otherwise we might not be able
710 // to detect a buggy precaching proxy (bug 17790)
711 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
716 $useCombinedLoginLink = $this->useCombinedLoginLink();
717 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
718 ?
'nav-login-createaccount'
720 $is_signup = $request->getText( 'type' ) == 'signup';
723 'text' => $this->msg( $loginlink )->text(),
724 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
725 'active' => $title->isSpecial( 'Userlogin' )
726 && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
728 $createaccount_url = array(
729 'text' => $this->msg( 'pt-createaccount' )->text(),
730 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
731 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
734 if ( $this->showIPinHeader() ) {
735 $href = &$this->userpageUrlDetails
['href'];
736 $personal_urls['anonuserpage'] = array(
737 'text' => $this->username
,
739 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
740 'active' => ( $pageurl == $href )
742 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
743 $href = &$usertalkUrlDetails['href'];
744 $personal_urls['anontalk'] = array(
745 'text' => $this->msg( 'anontalk' )->text(),
747 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
748 'active' => ( $pageurl == $href )
752 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
753 $personal_urls['createaccount'] = $createaccount_url;
756 $personal_urls['login'] = $login_url;
759 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
760 wfProfileOut( __METHOD__
);
761 return $personal_urls;
765 * Builds an array with tab definition
767 * @param Title $title page Where the tab links to
768 * @param string|array $message Message key or an array of message keys (will fall back)
769 * @param bool $selected Display the tab as selected
770 * @param string $query Query string attached to tab URL
771 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
775 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
778 $classes[] = 'selected';
780 if ( $checkEdit && !$title->isKnown() ) {
782 if ( $query !== '' ) {
783 $query = 'action=edit&redlink=1&' . $query;
785 $query = 'action=edit&redlink=1';
789 // wfMessageFallback will nicely accept $message as an array of fallbacks
790 // or just a single key
791 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
792 if ( is_array( $message ) ) {
793 // for hook compatibility just keep the last message name
794 $message = end( $message );
796 if ( $msg->exists() ) {
797 $text = $msg->text();
800 $text = $wgContLang->getFormattedNsText(
801 MWNamespace
::getSubject( $title->getNamespace() ) );
805 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
806 $title, $message, $selected, $checkEdit,
807 &$classes, &$query, &$text, &$result ) ) ) {
812 'class' => implode( ' ', $classes ),
814 'href' => $title->getLocalURL( $query ),
818 function makeTalkUrlDetails( $name, $urlaction = '' ) {
819 $title = Title
::newFromText( $name );
820 if ( !is_object( $title ) ) {
821 throw new MWException( __METHOD__
. " given invalid pagename $name" );
823 $title = $title->getTalkPage();
824 self
::checkTitle( $title, $name );
826 'href' => $title->getLocalURL( $urlaction ),
827 'exists' => $title->getArticleID() != 0,
831 function makeArticleUrlDetails( $name, $urlaction = '' ) {
832 $title = Title
::newFromText( $name );
833 $title = $title->getSubjectPage();
834 self
::checkTitle( $title, $name );
836 'href' => $title->getLocalURL( $urlaction ),
837 'exists' => $title->getArticleID() != 0,
842 * a structured array of links usually used for the tabs in a skin
844 * There are 4 standard sections
845 * namespaces: Used for namespace tabs like special, page, and talk namespaces
846 * views: Used for primary page views like read, edit, history
847 * actions: Used for most extra page actions like deletion, protection, etc...
848 * variants: Used to list the language variants for the page
850 * Each section's value is a key/value array of links for that section.
851 * The links themselves have these common keys:
852 * - class: The css classes to apply to the tab
853 * - text: The text to display on the tab
854 * - href: The href for the tab to point to
855 * - rel: An optional rel= for the tab's link
856 * - redundant: If true the tab will be dropped in skins using content_actions
857 * this is useful for tabs like "Read" which only have meaning in skins that
858 * take special meaning from the grouped structure of content_navigation
860 * Views also have an extra key which can be used:
861 * - primary: If this is not true skins like vector may try to hide the tab
862 * when the user has limited space in their browser window
864 * content_navigation using code also expects these ids to be present on the
865 * links, however these are usually automatically generated by SkinTemplate
866 * itself and are not necessary when using a hook. The only things these may
867 * matter to are people modifying content_navigation after it's initial creation:
868 * - id: A "preferred" id, most skins are best off outputting this preferred
869 * id for best compatibility.
870 * - tooltiponly: This is set to true for some tabs in cases where the system
871 * believes that the accesskey should not be added to the tab.
875 protected function buildContentNavigationUrls() {
876 global $wgDisableLangConversion;
878 wfProfileIn( __METHOD__
);
880 // Display tabs for the relevant title rather than always the title itself
881 $title = $this->getRelevantTitle();
882 $onPage = $title->equals( $this->getTitle() );
884 $out = $this->getOutput();
885 $request = $this->getRequest();
886 $user = $this->getUser();
888 $content_navigation = array(
889 'namespaces' => array(),
891 'actions' => array(),
892 'variants' => array()
896 $action = $request->getVal( 'action', 'view' );
898 $userCanRead = $title->quickUserCan( 'read', $user );
900 $preventActiveTabs = false;
901 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
903 // Checks if page is some kind of content
904 if ( $title->canExist() ) {
905 // Gets page objects for the related namespaces
906 $subjectPage = $title->getSubjectPage();
907 $talkPage = $title->getTalkPage();
909 // Determines if this is a talk page
910 $isTalk = $title->isTalkPage();
912 // Generates XML IDs from namespace names
913 $subjectId = $title->getNamespaceKey( '' );
915 if ( $subjectId == 'main' ) {
918 $talkId = "{$subjectId}_talk";
921 $skname = $this->skinname
;
923 // Adds namespace links
924 $subjectMsg = array( "nstab-$subjectId" );
925 if ( $subjectPage->isMainPage() ) {
926 array_unshift( $subjectMsg, 'mainpage-nstab' );
928 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
929 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
931 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
932 $content_navigation['namespaces'][$talkId] = $this->tabAction(
933 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
935 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
937 if ( $userCanRead ) {
938 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
939 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
941 // Adds view view link
942 if ( $title->exists() ||
$isForeignFile ) {
943 $content_navigation['views']['view'] = $this->tabAction(
944 $isTalk ?
$talkPage : $subjectPage,
945 array( "$skname-view-view", 'view' ),
946 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
948 // signal to hide this from simple content_actions
949 $content_navigation['views']['view']['redundant'] = true;
952 // If it is a non-local file, show a link to the file in its own repository
953 if ( $isForeignFile ) {
954 $file = $this->getWikiPage()->getFile();
955 $content_navigation['views']['view-foreign'] = array(
957 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
958 setContext( $this->getContext() )->
959 params( $file->getRepo()->getDisplayName() )->text(),
960 'href' => $file->getDescriptionUrl(),
965 wfProfileIn( __METHOD__
. '-edit' );
967 // Checks if user can edit the current page if it exists or create it otherwise
968 if ( $title->quickUserCan( 'edit', $user )
969 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
971 // Builds CSS class for talk page links
972 $isTalkClass = $isTalk ?
' istalk' : '';
973 // Whether the user is editing the page
974 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
975 // Whether to show the "Add a new section" tab
976 // Checks if this is a current rev of talk page and is not forced to be hidden
977 $showNewSection = !$out->forceHideNewSectionLink()
978 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
979 $section = $request->getVal( 'section' );
981 if ( $title->exists()
982 ||
( $title->getNamespace() == NS_MEDIAWIKI
983 && $title->getDefaultMessageText() !== false
986 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
988 $msgKey = $isForeignFile ?
'create-local' : 'create';
990 $content_navigation['views']['edit'] = array(
991 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
995 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
996 ->setContext( $this->getContext() )->text(),
997 'href' => $title->getLocalURL( $this->editUrlOptions() ),
998 'primary' => !$isForeignFile, // don't collapse this in vector
1002 if ( $showNewSection ) {
1003 // Adds new section link
1004 //$content_navigation['actions']['addsection']
1005 $content_navigation['views']['addsection'] = array(
1006 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
1007 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
1008 ->setContext( $this->getContext() )->text(),
1009 'href' => $title->getLocalURL( 'action=edit§ion=new' )
1012 // Checks if the page has some kind of viewable content
1013 } elseif ( $title->hasSourceText() ) {
1014 // Adds view source view link
1015 $content_navigation['views']['viewsource'] = array(
1016 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
1017 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1018 ->setContext( $this->getContext() )->text(),
1019 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1020 'primary' => true, // don't collapse this in vector
1023 wfProfileOut( __METHOD__
. '-edit' );
1025 wfProfileIn( __METHOD__
. '-live' );
1026 // Checks if the page exists
1027 if ( $title->exists() ) {
1028 // Adds history view link
1029 $content_navigation['views']['history'] = array(
1030 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1031 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1032 ->setContext( $this->getContext() )->text(),
1033 'href' => $title->getLocalURL( 'action=history' ),
1034 'rel' => 'archives',
1037 if ( $title->quickUserCan( 'delete', $user ) ) {
1038 $content_navigation['actions']['delete'] = array(
1039 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1040 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1041 ->setContext( $this->getContext() )->text(),
1042 'href' => $title->getLocalURL( 'action=delete' )
1046 if ( $title->quickUserCan( 'move', $user ) ) {
1047 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1048 $content_navigation['actions']['move'] = array(
1049 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1050 'text' => wfMessageFallback( "$skname-action-move", 'move' )
1051 ->setContext( $this->getContext() )->text(),
1052 'href' => $moveTitle->getLocalURL()
1056 // article doesn't exist or is deleted
1057 if ( $user->isAllowed( 'deletedhistory' ) ) {
1058 $n = $title->isDeleted();
1060 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1061 // If the user can't undelete but can view deleted
1062 // history show them a "View .. deleted" tab instead.
1063 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1064 $content_navigation['actions']['undelete'] = array(
1065 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1066 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1067 ->setContext( $this->getContext() )->numParams( $n )->text(),
1068 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1074 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1075 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1077 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1078 $content_navigation['actions'][$mode] = array(
1079 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1080 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1081 ->setContext( $this->getContext() )->text(),
1082 'href' => $title->getLocalURL( "action=$mode" )
1086 wfProfileOut( __METHOD__
. '-live' );
1088 // Checks if the user is logged in
1089 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1091 * The following actions use messages which, if made particular to
1092 * the any specific skins, would break the Ajax code which makes this
1093 * action happen entirely inline. OutputPage::getJSVars
1094 * defines a set of messages in a javascript object - and these
1095 * messages are assumed to be global for all skins. Without making
1096 * a change to that procedure these messages will have to remain as
1097 * the global versions.
1099 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1100 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1101 $content_navigation['actions'][$mode] = array(
1102 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1103 // uses 'watch' or 'unwatch' message
1104 'text' => $this->msg( $mode )->text(),
1105 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1110 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1112 if ( $userCanRead && !$wgDisableLangConversion ) {
1113 $pageLang = $title->getPageLanguage();
1114 // Gets list of language variants
1115 $variants = $pageLang->getVariants();
1116 // Checks that language conversion is enabled and variants exist
1117 // And if it is not in the special namespace
1118 if ( count( $variants ) > 1 ) {
1119 // Gets preferred variant (note that user preference is
1120 // only possible for wiki content language variant)
1121 $preferred = $pageLang->getPreferredVariant();
1122 if ( Action
::getActionName( $this ) === 'view' ) {
1123 $params = $request->getQueryValues();
1124 unset( $params['title'] );
1128 // Loops over each variant
1129 foreach ( $variants as $code ) {
1130 // Gets variant name from language code
1131 $varname = $pageLang->getVariantname( $code );
1132 // Appends variant link
1133 $content_navigation['variants'][] = array(
1134 'class' => ( $code == $preferred ) ?
'selected' : false,
1136 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1137 'lang' => wfBCP47( $code ),
1138 'hreflang' => wfBCP47( $code ),
1144 // If it's not content, it's got to be a special page
1145 $content_navigation['namespaces']['special'] = array(
1146 'class' => 'selected',
1147 'text' => $this->msg( 'nstab-special' )->text(),
1148 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1149 'context' => 'subject'
1152 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1153 array( &$this, &$content_navigation ) );
1156 // Equiv to SkinTemplateContentActions
1157 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1159 // Setup xml ids and tooltip info
1160 foreach ( $content_navigation as $section => &$links ) {
1161 foreach ( $links as $key => &$link ) {
1163 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1164 $xmlID = 'ca-nstab-' . $xmlID;
1165 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1167 } elseif ( $section == 'variants' ) {
1168 $xmlID = 'ca-varlang-' . $xmlID;
1170 $xmlID = 'ca-' . $xmlID;
1172 $link['id'] = $xmlID;
1176 # We don't want to give the watch tab an accesskey if the
1177 # page is being edited, because that conflicts with the
1178 # accesskey on the watch checkbox. We also don't want to
1179 # give the edit tab an accesskey, because that's fairly
1180 # superfluous and conflicts with an accesskey (Ctrl-E) often
1181 # used for editing in Safari.
1182 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1183 if ( isset( $content_navigation['views']['edit'] ) ) {
1184 $content_navigation['views']['edit']['tooltiponly'] = true;
1186 if ( isset( $content_navigation['actions']['watch'] ) ) {
1187 $content_navigation['actions']['watch']['tooltiponly'] = true;
1189 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1190 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1194 wfProfileOut( __METHOD__
);
1196 return $content_navigation;
1200 * an array of edit links by default used for the tabs
1201 * @param $content_navigation
1204 private function buildContentActionUrls( $content_navigation ) {
1206 wfProfileIn( __METHOD__
);
1208 // content_actions has been replaced with content_navigation for backwards
1209 // compatibility and also for skins that just want simple tabs content_actions
1210 // is now built by flattening the content_navigation arrays into one
1212 $content_actions = array();
1214 foreach ( $content_navigation as $links ) {
1215 foreach ( $links as $key => $value ) {
1216 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1217 // Redundant tabs are dropped from content_actions
1221 // content_actions used to have ids built using the "ca-$key" pattern
1222 // so the xmlID based id is much closer to the actual $key that we want
1223 // for that reason we'll just strip out the ca- if present and use
1224 // the latter potion of the "id" as the $key
1225 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1226 $key = substr( $value['id'], 3 );
1229 if ( isset( $content_actions[$key] ) ) {
1230 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1231 "content_navigation into content_actions.\n" );
1235 $content_actions[$key] = $value;
1239 wfProfileOut( __METHOD__
);
1241 return $content_actions;
1245 * build array of common navigation links
1248 protected function buildNavUrls() {
1249 global $wgUploadNavigationUrl;
1251 wfProfileIn( __METHOD__
);
1253 $out = $this->getOutput();
1254 $request = $this->getRequest();
1256 $nav_urls = array();
1257 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1258 if ( $wgUploadNavigationUrl ) {
1259 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1260 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1261 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1263 $nav_urls['upload'] = false;
1265 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1267 $nav_urls['print'] = false;
1268 $nav_urls['permalink'] = false;
1269 $nav_urls['info'] = false;
1270 $nav_urls['whatlinkshere'] = false;
1271 $nav_urls['recentchangeslinked'] = false;
1272 $nav_urls['contributions'] = false;
1273 $nav_urls['log'] = false;
1274 $nav_urls['blockip'] = false;
1275 $nav_urls['emailuser'] = false;
1276 $nav_urls['userrights'] = false;
1278 // A print stylesheet is attached to all pages, but nobody ever
1279 // figures that out. :) Add a link...
1280 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1281 $nav_urls['print'] = array(
1282 'text' => $this->msg( 'printableversion' )->text(),
1283 'href' => $this->getTitle()->getLocalURL(
1284 $request->appendQueryValue( 'printable', 'yes', true ) )
1288 if ( $out->isArticle() ) {
1289 // Also add a "permalink" while we're at it
1290 $revid = $this->getRevisionId();
1292 $nav_urls['permalink'] = array(
1293 'text' => $this->msg( 'permalink' )->text(),
1294 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1298 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1299 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1300 array( &$this, &$nav_urls, &$revid, &$revid ) );
1303 if ( $out->isArticleRelated() ) {
1304 $nav_urls['whatlinkshere'] = array(
1305 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1308 $nav_urls['info'] = array(
1309 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1310 'href' => $this->getTitle()->getLocalURL( "action=info" )
1313 if ( $this->getTitle()->getArticleID() ) {
1314 $nav_urls['recentchangeslinked'] = array(
1315 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1320 $user = $this->getRelevantUser();
1322 $rootUser = $user->getName();
1324 $nav_urls['contributions'] = array(
1325 'text' => $this->msg( 'contributions', $rootUser )->text(),
1326 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1329 $nav_urls['log'] = array(
1330 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1333 if ( $this->getUser()->isAllowed( 'block' ) ) {
1334 $nav_urls['blockip'] = array(
1335 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1339 if ( $this->showEmailUser( $user ) ) {
1340 $nav_urls['emailuser'] = array(
1341 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1345 if ( !$user->isAnon() ) {
1346 $sur = new UserrightsPage
;
1347 $sur->setContext( $this->getContext() );
1348 if ( $sur->userCanExecute( $this->getUser() ) ) {
1349 $nav_urls['userrights'] = array(
1350 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1356 wfProfileOut( __METHOD__
);
1361 * Generate strings used for xml 'id' names
1364 protected function getNameSpaceKey() {
1365 return $this->getTitle()->getNamespaceKey();
1370 * Generic wrapper for template functions, with interface
1371 * compatible with what we use of PHPTAL 0.7.
1374 abstract class QuickTemplate
{
1378 function __construct() {
1379 $this->data
= array();
1380 $this->translator
= new MediaWikiI18N();
1384 * Sets the value $value to $name
1385 * @param string $name
1386 * @param mixed $value
1388 public function set( $name, $value ) {
1389 $this->data
[$name] = $value;
1393 * Gets the template data requested
1395 * @param string $name Key for the data
1396 * @param mixed $default Optional default (or null)
1397 * @return mixed The value of the data requested or the deafult
1399 public function get( $name, $default = null ) {
1400 if ( isset( $this->data
[$name] ) ) {
1401 return $this->data
[$name];
1408 * @param string $name
1409 * @param mixed $value
1411 public function setRef( $name, &$value ) {
1412 $this->data
[$name] =& $value;
1416 * @param MediaWikiI18N $t
1418 public function setTranslator( &$t ) {
1419 $this->translator
= &$t;
1423 * Main function, used by classes that subclass QuickTemplate
1424 * to show the actual HTML output
1426 abstract public function execute();
1430 * @param string $str
1433 function text( $str ) {
1434 echo htmlspecialchars( $this->data
[$str] );
1439 * @param string $str
1442 function html( $str ) {
1443 echo $this->data
[$str];
1448 * @param string $str
1451 function msg( $str ) {
1452 echo htmlspecialchars( $this->translator
->translate( $str ) );
1457 * @param string $str
1460 function msgHtml( $str ) {
1461 echo $this->translator
->translate( $str );
1465 * An ugly, ugly hack.
1467 * @param string $str
1470 function msgWiki( $str ) {
1473 $text = $this->translator
->translate( $str );
1474 echo $wgOut->parse( $text );
1479 * @param string $str
1482 function haveData( $str ) {
1483 return isset( $this->data
[$str] );
1489 * @param string $str
1492 function haveMsg( $str ) {
1493 $msg = $this->translator
->translate( $str );
1494 return ( $msg != '-' ) && ( $msg != '' ); # ????
1498 * Get the Skin object related to this object
1502 public function getSkin() {
1503 return $this->data
['skin'];
1507 * Fetch the output of a QuickTemplate and return it
1512 public function getHTML() {
1515 $html = ob_get_contents();
1522 * New base template for a skin's template extended from QuickTemplate
1523 * this class features helper methods that provide common ways of interacting
1524 * with the data stored in the QuickTemplate
1526 abstract class BaseTemplate
extends QuickTemplate
{
1529 * Get a Message object with its context set
1531 * @param string $name Message name
1534 public function getMsg( $name ) {
1535 return $this->getSkin()->msg( $name );
1538 function msg( $str ) {
1539 echo $this->getMsg( $str )->escaped();
1542 function msgHtml( $str ) {
1543 echo $this->getMsg( $str )->text();
1546 function msgWiki( $str ) {
1547 echo $this->getMsg( $str )->parseAsBlock();
1551 * Create an array of common toolbox items from the data in the quicktemplate
1552 * stored by SkinTemplate.
1553 * The resulting array is built according to a format intended to be passed
1554 * through makeListItem to generate the html.
1557 function getToolbox() {
1558 wfProfileIn( __METHOD__
);
1561 if ( isset( $this->data
['nav_urls']['whatlinkshere'] )
1562 && $this->data
['nav_urls']['whatlinkshere']
1564 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1565 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1567 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] )
1568 && $this->data
['nav_urls']['recentchangeslinked']
1570 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1571 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1572 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1574 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1575 $toolbox['feeds']['id'] = 'feedlinks';
1576 $toolbox['feeds']['links'] = array();
1577 foreach ( $this->data
['feeds'] as $key => $feed ) {
1578 $toolbox['feeds']['links'][$key] = $feed;
1579 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1580 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1581 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1582 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1585 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser',
1586 'userrights', 'upload', 'specialpages' ) as $special
1588 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1589 $toolbox[$special] = $this->data
['nav_urls'][$special];
1590 $toolbox[$special]['id'] = "t-$special";
1593 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1594 $toolbox['print'] = $this->data
['nav_urls']['print'];
1595 $toolbox['print']['id'] = 't-print';
1596 $toolbox['print']['rel'] = 'alternate';
1597 $toolbox['print']['msg'] = 'printableversion';
1599 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1600 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1601 if ( $toolbox['permalink']['href'] === '' ) {
1602 unset( $toolbox['permalink']['href'] );
1603 $toolbox['ispermalink']['tooltiponly'] = true;
1604 $toolbox['ispermalink']['id'] = 't-ispermalink';
1605 $toolbox['ispermalink']['msg'] = 'permalink';
1607 $toolbox['permalink']['id'] = 't-permalink';
1610 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1611 $toolbox['info'] = $this->data
['nav_urls']['info'];
1612 $toolbox['info']['id'] = 't-info';
1615 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1616 wfProfileOut( __METHOD__
);
1621 * Create an array of personal tools items from the data in the quicktemplate
1622 * stored by SkinTemplate.
1623 * The resulting array is built according to a format intended to be passed
1624 * through makeListItem to generate the html.
1625 * This is in reality the same list as already stored in personal_urls
1626 * however it is reformatted so that you can just pass the individual items
1627 * to makeListItem instead of hardcoding the element creation boilerplate.
1630 function getPersonalTools() {
1631 $personal_tools = array();
1632 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1633 # The class on a personal_urls item is meant to go on the <a> instead
1634 # of the <li> so we have to use a single item "links" array instead
1635 # of using most of the personal_url's keys directly.
1638 array( 'single-id' => "pt-$key" ),
1642 if ( isset( $plink['active'] ) ) {
1643 $ptool['active'] = $plink['active'];
1645 foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) {
1646 if ( isset( $plink[$k] ) ) {
1647 $ptool['links'][0][$k] = $plink[$k];
1650 $personal_tools[$key] = $ptool;
1652 return $personal_tools;
1655 function getSidebar( $options = array() ) {
1656 // Force the rendering of the following portals
1657 $sidebar = $this->data
['sidebar'];
1658 if ( !isset( $sidebar['SEARCH'] ) ) {
1659 $sidebar['SEARCH'] = true;
1661 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1662 $sidebar['TOOLBOX'] = true;
1664 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1665 $sidebar['LANGUAGES'] = true;
1668 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1669 unset( $sidebar['SEARCH'] );
1671 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1672 unset( $sidebar['TOOLBOX'] );
1674 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1675 unset( $sidebar['LANGUAGES'] );
1679 foreach ( $sidebar as $boxName => $content ) {
1680 if ( $content === false ) {
1683 switch ( $boxName ) {
1685 // Search is a special case, skins should custom implement this
1686 $boxes[$boxName] = array(
1688 'header' => $this->getMsg( 'search' )->text(),
1689 'generated' => false,
1694 $msgObj = $this->getMsg( 'toolbox' );
1695 $boxes[$boxName] = array(
1697 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1698 'generated' => false,
1699 'content' => $this->getToolbox(),
1703 if ( $this->data
['language_urls'] ) {
1704 $msgObj = $this->getMsg( 'otherlanguages' );
1705 $boxes[$boxName] = array(
1707 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1708 'generated' => false,
1709 'content' => $this->data
['language_urls'],
1714 $msgObj = $this->getMsg( $boxName );
1715 $boxes[$boxName] = array(
1716 'id' => "p-$boxName",
1717 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1718 'generated' => true,
1719 'content' => $content,
1725 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1726 $hookContents = null;
1727 if ( isset( $boxes['TOOLBOX'] ) ) {
1729 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1730 // can abort and avoid outputting double toolbox links
1731 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1732 $hookContents = ob_get_contents();
1734 if ( !trim( $hookContents ) ) {
1735 $hookContents = null;
1740 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1741 foreach ( $boxes as $boxName => $box ) {
1742 if ( is_array( $box['content'] ) ) {
1744 foreach ( $box['content'] as $key => $val ) {
1745 $content .= "\n " . $this->makeListItem( $key, $val );
1747 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1748 if ( $hookContents ) {
1749 $content .= "\n $hookContents";
1752 $content .= "\n</ul>\n";
1753 $boxes[$boxName]['content'] = $content;
1757 if ( $hookContents ) {
1758 $boxes['TOOLBOXEND'] = array(
1759 'id' => 'p-toolboxend',
1760 'header' => $boxes['TOOLBOX']['header'],
1761 'generated' => false,
1762 'content' => "<ul>{$hookContents}</ul>",
1764 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1766 foreach ( $boxes as $key => $box ) {
1767 if ( $key === 'TOOLBOXEND' ) {
1770 $boxes2[$key] = $box;
1771 if ( $key === 'TOOLBOX' ) {
1772 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1784 * @param string $name
1786 protected function renderAfterPortlet( $name ) {
1788 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
1790 if ( $content !== '' ) {
1791 echo "<div class='after-portlet after-portlet-$name'>$content</div>";
1797 * Makes a link, usually used by makeListItem to generate a link for an item
1798 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1800 * @param string $key usually a key from the list you are generating this
1802 * @param array $item contains some of a specific set of keys.
1804 * The text of the link will be generated either from the contents of the
1805 * "text" key in the $item array, if a "msg" key is present a message by
1806 * that name will be used, and if neither of those are set the $key will be
1807 * used as a message name.
1809 * If a "href" key is not present makeLink will just output htmlescaped text.
1810 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1811 * for the link if present.
1813 * If an "id" or "single-id" (if you don't want the actual id to be output
1814 * on the link) is present it will be used to generate a tooltip and
1815 * accesskey for the link.
1817 * The keys "context" and "primary" are ignored; these keys are used
1818 * internally by skins and are not supposed to be included in the HTML
1821 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1823 * @param array $options can be used to affect the output of a link.
1824 * Possible options are:
1825 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1826 * a link in. This should be an array of arrays containing a 'tag' and
1827 * optionally an 'attributes' key. If you only have one element you don't
1828 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1829 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1831 * - 'link-class' key can be used to specify additional classes to apply
1833 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1834 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1835 * any non-link will output a "<span>" instead of just text.
1839 function makeLink( $key, $item, $options = array() ) {
1840 if ( isset( $item['text'] ) ) {
1841 $text = $item['text'];
1843 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1846 $html = htmlspecialchars( $text );
1848 if ( isset( $options['text-wrapper'] ) ) {
1849 $wrapper = $options['text-wrapper'];
1850 if ( isset( $wrapper['tag'] ) ) {
1851 $wrapper = array( $wrapper );
1853 while ( count( $wrapper ) > 0 ) {
1854 $element = array_pop( $wrapper );
1855 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] )
1856 ?
$element['attributes']
1861 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1863 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1864 unset( $attrs[$k] );
1867 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1868 $item['single-id'] = $item['id'];
1870 if ( isset( $item['single-id'] ) ) {
1871 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1872 $title = Linker
::titleAttrib( $item['single-id'] );
1873 if ( $title !== false ) {
1874 $attrs['title'] = $title;
1877 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1878 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1879 $attrs['title'] = $tip['title'];
1881 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1882 $attrs['accesskey'] = $tip['accesskey'];
1886 if ( isset( $options['link-class'] ) ) {
1887 if ( isset( $attrs['class'] ) ) {
1888 $attrs['class'] .= " {$options['link-class']}";
1890 $attrs['class'] = $options['link-class'];
1893 $html = Html
::rawElement( isset( $attrs['href'] )
1895 : $options['link-fallback'], $attrs, $html );
1902 * Generates a list item for a navigation, portlet, portal, sidebar... list
1904 * @param string $key Usually a key from the list you are generating this link from.
1905 * @param array $item Array of list item data containing some of a specific set of keys.
1906 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
1907 * if "active" contains a value of true a "active" class will also be appended to class.
1909 * @param array $options
1911 * If you want something other than a "<li>" you can pass a tag name such as
1912 * "tag" => "span" in the $options array to change the tag used.
1913 * link/content data for the list item may come in one of two forms
1914 * A "links" key may be used, in which case it should contain an array with
1915 * a list of links to include inside the list item, see makeLink for the
1916 * format of individual links array items.
1918 * Otherwise the relevant keys from the list item $item array will be passed
1919 * to makeLink instead. Note however that "id" and "class" are used by the
1920 * list item directly so they will not be passed to makeLink
1921 * (however the link will still support a tooltip and accesskey from it)
1922 * If you need an id or class on a single link you should include a "links"
1923 * array with just one link item inside of it. If you want to add a title
1924 * to the list item itself, you can set "itemtitle" to the value.
1925 * $options is also passed on to makeLink calls
1929 function makeListItem( $key, $item, $options = array() ) {
1930 if ( isset( $item['links'] ) ) {
1932 foreach ( $item['links'] as $linkKey => $link ) {
1933 $links[] = $this->makeLink( $linkKey, $link, $options );
1935 $html = implode( ' ', $links );
1938 // These keys are used by makeListItem and shouldn't be passed on to the link
1939 foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) {
1942 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1943 // The id goes on the <li> not on the <a> for single links
1944 // but makeSidebarLink still needs to know what id to use when
1945 // generating tooltips and accesskeys.
1946 $link['single-id'] = $item['id'];
1948 $html = $this->makeLink( $key, $link, $options );
1952 foreach ( array( 'id', 'class' ) as $attr ) {
1953 if ( isset( $item[$attr] ) ) {
1954 $attrs[$attr] = $item[$attr];
1957 if ( isset( $item['active'] ) && $item['active'] ) {
1958 if ( !isset( $attrs['class'] ) ) {
1959 $attrs['class'] = '';
1961 $attrs['class'] .= ' active';
1962 $attrs['class'] = trim( $attrs['class'] );
1964 if ( isset( $item['itemtitle'] ) ) {
1965 $attrs['title'] = $item['itemtitle'];
1967 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1970 function makeSearchInput( $attrs = array() ) {
1974 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1975 'value' => $this->get( 'search', '' ),
1977 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1978 return Html
::element( 'input', $realAttrs );
1981 function makeSearchButton( $mode, $attrs = array() ) {
1988 'value' => $this->translator
->translate(
1989 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1991 $realAttrs = array_merge(
1993 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1996 return Html
::element( 'input', $realAttrs );
1998 $buttonAttrs = array(
2002 $buttonAttrs = array_merge(
2004 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
2007 unset( $buttonAttrs['src'] );
2008 unset( $buttonAttrs['alt'] );
2009 unset( $buttonAttrs['width'] );
2010 unset( $buttonAttrs['height'] );
2012 'src' => $attrs['src'],
2013 'alt' => isset( $attrs['alt'] )
2015 : $this->translator
->translate( 'searchbutton' ),
2016 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
2017 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
2019 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
2021 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
2026 * Returns an array of footerlinks trimmed down to only those footer links that
2028 * If you pass "flat" as an option then the returned array will be a flat array
2029 * of footer icons instead of a key/value array of footerlinks arrays broken
2030 * up into categories.
2031 * @param string $option
2032 * @return array|mixed
2034 function getFooterLinks( $option = null ) {
2035 $footerlinks = $this->get( 'footerlinks' );
2037 // Reduce footer links down to only those which are being used
2038 $validFooterLinks = array();
2039 foreach ( $footerlinks as $category => $links ) {
2040 $validFooterLinks[$category] = array();
2041 foreach ( $links as $link ) {
2042 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
2043 $validFooterLinks[$category][] = $link;
2046 if ( count( $validFooterLinks[$category] ) <= 0 ) {
2047 unset( $validFooterLinks[$category] );
2051 if ( $option == 'flat' ) {
2052 // fold footerlinks into a single array using a bit of trickery
2053 $validFooterLinks = call_user_func_array(
2055 array_values( $validFooterLinks )
2059 return $validFooterLinks;
2063 * Returns an array of footer icons filtered down by options relevant to how
2064 * the skin wishes to display them.
2065 * If you pass "icononly" as the option all footer icons which do not have an
2066 * image icon set will be filtered out.
2067 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
2068 * in the list of footer icons. This is mostly useful for skins which only
2069 * display the text from footericons instead of the images and don't want a
2070 * duplicate copyright statement because footerlinks already rendered one.
2071 * @param string $option
2074 function getFooterIcons( $option = null ) {
2075 // Generate additional footer icons
2076 $footericons = $this->get( 'footericons' );
2078 if ( $option == 'icononly' ) {
2079 // Unset any icons which don't have an image
2080 foreach ( $footericons as &$footerIconsBlock ) {
2081 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2082 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2083 unset( $footerIconsBlock[$footerIconKey] );
2087 // Redo removal of any empty blocks
2088 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2089 if ( count( $footerIconsBlock ) <= 0 ) {
2090 unset( $footericons[$footerIconsKey] );
2093 } elseif ( $option == 'nocopyright' ) {
2094 unset( $footericons['copyright']['copyright'] );
2095 if ( count( $footericons['copyright'] ) <= 0 ) {
2096 unset( $footericons['copyright'] );
2100 return $footericons;
2104 * Output the basic end-page trail including bottomscripts, reporttime, and
2105 * debug stuff. This should be called right before outputting the closing
2106 * body and html tags.
2108 function printTrail() { ?
>
2109 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2110 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2111 <?php
$this->html( 'reporttime' ) ?
>