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.
30 class MediaWiki_I18N
{
31 var $_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
{
76 * Name of our skin, it probably needs to be all lower case. Child classes
77 * should override the default.
79 var $skinname = 'monobook';
82 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
83 * are located. Child classes should override the default.
85 var $stylename = 'monobook';
88 * For QuickTemplate, the name of the subclass which will actually fill the
89 * template. Child classes should override the default.
91 var $template = 'QuickTemplate';
94 * Whether this skin use OutputPage::headElement() to generate the "<head>"
97 var $useHeadElement = false;
102 * Add specific styles for this skin
104 * @param $out OutputPage
106 function setupSkinUserCss( OutputPage
$out ) {
107 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
115 * @param $classname String
116 * @param string $repository subdirectory where we keep template files
117 * @param $cache_dir string
118 * @return QuickTemplate
121 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
122 return new $classname();
126 * Generates array of language links for the current page
131 public function getLanguages() {
132 global $wgHideInterlanguageLinks;
133 $out = $this->getOutput();
134 $userLang = $this->getLanguage();
137 $language_urls = array();
139 if ( !$wgHideInterlanguageLinks ) {
140 foreach ( $out->getLanguageLinks() as $languageLinkText ) {
141 $languageLinkParts = explode( ':', $languageLinkText, 2 );
142 $class = 'interwiki-' . $languageLinkParts[0];
143 unset( $languageLinkParts );
144 $languageLinkTitle = Title
::newFromText( $languageLinkText );
145 if ( $languageLinkTitle ) {
146 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
147 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
149 if ( strval( $ilLangName ) === '' ) {
150 $ilLangName = $languageLinkText;
152 $ilLangName = $this->formatLanguageName( $ilLangName );
155 // CLDR extension or similar is required to localize the language name;
156 // otherwise we'll end up with the autonym again.
157 $ilLangLocalName = Language
::fetchLanguageName( $ilInterwikiCode, $userLang->getCode() );
159 $language_urls[] = array(
160 'href' => $languageLinkTitle->getFullURL(),
161 'text' => $ilLangName,
162 'title' => wfMessage( 'tooltip-iwiki', $languageLinkTitle->getText(), $ilLangLocalName )->escaped(),
164 'lang' => wfBCP47( $ilInterwikiCode ),
165 'hreflang' => wfBCP47( $ilInterwikiCode ),
170 return $language_urls;
173 protected function setupTemplateForOutput() {
174 wfProfileIn( __METHOD__
);
176 $request = $this->getRequest();
177 $user = $this->getUser();
178 $title = $this->getTitle();
180 wfProfileIn( __METHOD__
. '-init' );
181 $tpl = $this->setupTemplate( $this->template
, 'skins' );
182 wfProfileOut( __METHOD__
. '-init' );
184 wfProfileIn( __METHOD__
. '-stuff' );
185 $this->thispage
= $title->getPrefixedDBkey();
186 $this->titletxt
= $title->getPrefixedText();
187 $this->userpage
= $user->getUserPage()->getPrefixedText();
189 if ( !$request->wasPosted() ) {
190 $query = $request->getValues();
191 unset( $query['title'] );
192 unset( $query['returnto'] );
193 unset( $query['returntoquery'] );
195 $this->thisquery
= wfArrayToCgi( $query );
196 $this->loggedin
= $user->isLoggedIn();
197 $this->username
= $user->getName();
199 if ( $this->loggedin ||
$this->showIPinHeader() ) {
200 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
202 # This won't be used in the standard skins, but we define it to preserve the interface
203 # To save time, we check for existence
204 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
207 wfProfileOut( __METHOD__
. '-stuff' );
209 wfProfileOut( __METHOD__
);
215 * initialize various variables and generate the template
217 * @param $out OutputPage
219 function outputPage( OutputPage
$out = null ) {
221 global $wgScript, $wgStylePath;
222 global $wgMimeType, $wgJsMimeType;
223 global $wgXhtmlNamespaces, $wgHtml5Version;
224 global $wgDisableCounters, $wgSitename, $wgLogo;
225 global $wgMaxCredits, $wgShowCreditsIfMax;
226 global $wgPageShowWatchingUsers;
227 global $wgArticlePath, $wgScriptPath, $wgServer;
229 wfProfileIn( __METHOD__
);
230 Profiler
::instance()->setTemplated( true );
233 if ( $out !== null ) {
234 // @todo Add wfDeprecated in 1.20
235 $oldContext = $this->getContext();
236 $this->setContext( $out->getContext() );
239 $out = $this->getOutput();
240 $request = $this->getRequest();
241 $user = $this->getUser();
242 $title = $this->getTitle();
244 wfProfileIn( __METHOD__
. '-init' );
245 $this->initPage( $out );
246 wfProfileOut( __METHOD__
. '-init' );
248 $tpl = $this->setupTemplateForOutput();
250 wfProfileIn( __METHOD__
. '-stuff-head' );
251 if ( !$this->useHeadElement
) {
252 $tpl->set( 'pagecss', false );
253 $tpl->set( 'usercss', false );
255 $tpl->set( 'userjs', false );
256 $tpl->set( 'userjsprev', false );
258 $tpl->set( 'jsvarurl', false );
260 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
261 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
262 $tpl->set( 'html5version', $wgHtml5Version );
263 $tpl->set( 'headlinks', $out->getHeadLinks() );
264 $tpl->set( 'csslinks', $out->buildCssLinks() );
265 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
266 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
268 wfProfileOut( __METHOD__
. '-stuff-head' );
270 wfProfileIn( __METHOD__
. '-stuff2' );
271 $tpl->set( 'title', $out->getPageTitle() );
272 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
273 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
275 $tpl->setRef( 'thispage', $this->thispage
);
276 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
277 $tpl->set( 'titletext', $title->getText() );
278 $tpl->set( 'articleid', $title->getArticleID() );
280 $tpl->set( 'isarticle', $out->isArticle() );
282 $subpagestr = $this->subPageSubtitle();
283 if ( $subpagestr !== '' ) {
284 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
286 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
288 $undelete = $this->getUndeleteLink();
289 if ( $undelete === '' ) {
290 $tpl->set( 'undelete', '' );
292 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
295 $tpl->set( 'catlinks', $this->getCategories() );
296 if ( $out->isSyndicated() ) {
298 foreach ( $out->getSyndicationLinks() as $format => $link ) {
299 $feeds[$format] = array(
300 // Messages: feed-atom, feed-rss
301 'text' => $this->msg( "feed-$format" )->text(),
305 $tpl->setRef( 'feeds', $feeds );
307 $tpl->set( 'feeds', false );
310 $tpl->setRef( 'mimetype', $wgMimeType );
311 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
312 $tpl->set( 'charset', 'UTF-8' );
313 $tpl->setRef( 'wgScript', $wgScript );
314 $tpl->setRef( 'skinname', $this->skinname
);
315 $tpl->set( 'skinclass', get_class( $this ) );
316 $tpl->setRef( 'skin', $this );
317 $tpl->setRef( 'stylename', $this->stylename
);
318 $tpl->set( 'printable', $out->isPrintable() );
319 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
320 $tpl->setRef( 'loggedin', $this->loggedin
);
321 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
322 /* XXX currently unused, might get useful later
323 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
324 $tpl->set( 'exists', $title->getArticleID() != 0 );
325 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
326 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
327 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
329 $tpl->set( 'searchaction', $this->escapeSearchLink() );
330 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
331 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
332 $tpl->setRef( 'stylepath', $wgStylePath );
333 $tpl->setRef( 'articlepath', $wgArticlePath );
334 $tpl->setRef( 'scriptpath', $wgScriptPath );
335 $tpl->setRef( 'serverurl', $wgServer );
336 $tpl->setRef( 'logopath', $wgLogo );
337 $tpl->setRef( 'sitename', $wgSitename );
339 $userLang = $this->getLanguage();
340 $userLangCode = $userLang->getHtmlCode();
341 $userLangDir = $userLang->getDir();
343 $tpl->set( 'lang', $userLangCode );
344 $tpl->set( 'dir', $userLangDir );
345 $tpl->set( 'rtl', $userLang->isRTL() );
347 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
348 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
349 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
350 $tpl->setRef( 'userpage', $this->userpage
);
351 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
352 $tpl->set( 'userlang', $userLangCode );
354 // Users can have their language set differently than the
355 // content of the wiki. For these users, tell the web browser
356 // that interface elements are in a different language.
357 $tpl->set( 'userlangattributes', '' );
358 $tpl->set( 'specialpageattributes', '' ); # obsolete
360 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
361 $escUserlang = htmlspecialchars( $userLangCode );
362 $escUserdir = htmlspecialchars( $userLangDir );
363 // Attributes must be in double quotes because htmlspecialchars() doesn't
364 // escape single quotes
365 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
366 $tpl->set( 'userlangattributes', $attrs );
369 wfProfileOut( __METHOD__
. '-stuff2' );
371 wfProfileIn( __METHOD__
. '-stuff3' );
372 $tpl->set( 'newtalk', $this->getNewtalks() );
373 $tpl->set( 'logo', $this->logoText() );
375 $tpl->set( 'copyright', false );
376 $tpl->set( 'viewcount', false );
377 $tpl->set( 'lastmod', false );
378 $tpl->set( 'credits', false );
379 $tpl->set( 'numberofwatchingusers', false );
380 if ( $out->isArticle() && $title->exists() ) {
381 if ( $this->isRevisionCurrent() ) {
382 if ( !$wgDisableCounters ) {
383 $viewcount = $this->getWikiPage()->getCount();
385 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
389 if ( $wgPageShowWatchingUsers ) {
390 $dbr = wfGetDB( DB_SLAVE
);
391 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
392 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
396 $tpl->set( 'numberofwatchingusers',
397 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
402 if ( $wgMaxCredits != 0 ) {
403 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
404 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
406 $tpl->set( 'lastmod', $this->lastModified() );
409 $tpl->set( 'copyright', $this->getCopyright() );
411 wfProfileOut( __METHOD__
. '-stuff3' );
413 wfProfileIn( __METHOD__
. '-stuff4' );
414 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
415 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
416 $tpl->set( 'disclaimer', $this->disclaimerLink() );
417 $tpl->set( 'privacy', $this->privacyLink() );
418 $tpl->set( 'about', $this->aboutLink() );
420 $tpl->set( 'footerlinks', array(
424 'numberofwatchingusers',
435 global $wgFooterIcons;
436 $tpl->set( 'footericons', $wgFooterIcons );
437 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
438 if ( count( $footerIconsBlock ) > 0 ) {
439 foreach ( $footerIconsBlock as &$footerIcon ) {
440 if ( isset( $footerIcon['src'] ) ) {
441 if ( !isset( $footerIcon['width'] ) ) {
442 $footerIcon['width'] = 88;
444 if ( !isset( $footerIcon['height'] ) ) {
445 $footerIcon['height'] = 31;
450 unset( $tpl->data
['footericons'][$footerIconsKey] );
454 $tpl->set( 'sitenotice', $this->getSiteNotice() );
455 $tpl->set( 'bottomscripts', $this->bottomScripts() );
456 $tpl->set( 'printfooter', $this->printSource() );
458 # An ID that includes the actual body text; without categories, contentSub, ...
459 $realBodyAttribs = array( 'id' => 'mw-content-text' );
461 # Add a mw-content-ltr/rtl class to be able to style based on text direction
462 # when the content is different from the UI language, i.e.:
463 # not for special pages or file pages AND only when viewing AND if the page exists
464 # (or is in MW namespace, because that has default content)
465 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
466 Action
::getActionName( $this ) === 'view' &&
467 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
468 $pageLang = $title->getPageViewLanguage();
469 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
470 $realBodyAttribs['dir'] = $pageLang->getDir();
471 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
474 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
475 $tpl->setRef( 'bodytext', $out->mBodytext
);
477 $language_urls = $this->getLanguages();
478 if ( count( $language_urls ) ) {
479 $tpl->setRef( 'language_urls', $language_urls );
481 $tpl->set( 'language_urls', false );
483 wfProfileOut( __METHOD__
. '-stuff4' );
485 wfProfileIn( __METHOD__
. '-stuff5' );
487 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
488 $content_navigation = $this->buildContentNavigationUrls();
489 $content_actions = $this->buildContentActionUrls( $content_navigation );
490 $tpl->setRef( 'content_navigation', $content_navigation );
491 $tpl->setRef( 'content_actions', $content_actions );
493 $tpl->set( 'sidebar', $this->buildSidebar() );
494 $tpl->set( 'nav_urls', $this->buildNavUrls() );
496 // Set the head scripts near the end, in case the above actions resulted in added scripts
497 if ( $this->useHeadElement
) {
498 $tpl->set( 'headelement', $out->headElement( $this ) );
500 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
503 $tpl->set( 'debug', '' );
504 $tpl->set( 'debughtml', $this->generateDebugHTML() );
505 $tpl->set( 'reporttime', wfReportTime() );
507 // original version by hansm
508 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
509 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
512 // Set the bodytext to another key so that skins can just output it on it's own
513 // and output printfooter and debughtml separately
514 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
516 // Append printfooter and debughtml onto bodytext so that skins that were already
517 // using bodytext before they were split out don't suddenly start not outputting information
518 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
519 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
521 // allow extensions adding stuff after the page content.
522 // See Skin::afterContentHook() for further documentation.
523 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
524 wfProfileOut( __METHOD__
. '-stuff5' );
527 wfProfileIn( __METHOD__
. '-execute' );
528 $res = $tpl->execute();
529 wfProfileOut( __METHOD__
. '-execute' );
531 // result may be an error
532 $this->printOrError( $res );
535 $this->setContext( $oldContext );
537 wfProfileOut( __METHOD__
);
541 * Get the HTML for the p-personal list
544 public function getPersonalToolsList() {
545 $tpl = $this->setupTemplateForOutput();
546 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
548 foreach ( $tpl->getPersonalTools() as $key => $item ) {
549 $html .= $tpl->makeListItem( $key, $item );
555 * Format language name for use in sidebar interlanguage links list.
556 * By default it is capitalized.
558 * @param string $name Language name, e.g. "English" or "español"
562 function formatLanguageName( $name ) {
563 return $this->getLanguage()->ucfirst( $name );
567 * Output the string, or print error message if it's
568 * an error object of the appropriate type.
569 * For the base class, assume strings all around.
574 function printOrError( $str ) {
579 * Output a boolean indicating if buildPersonalUrls should output separate
580 * login and create account links or output a combined link
581 * By default we simply return a global config setting that affects most skins
582 * This is setup as a method so that like with $wgLogo and getLogo() a skin
583 * can override this setting and always output one or the other if it has
584 * a reason it can't output one of the two modes.
587 function useCombinedLoginLink() {
588 global $wgUseCombinedLoginLink;
589 return $wgUseCombinedLoginLink;
593 * build array of urls for personal toolbar
596 protected function buildPersonalUrls() {
597 $title = $this->getTitle();
598 $request = $this->getRequest();
599 $pageurl = $title->getLocalURL();
600 wfProfileIn( __METHOD__
);
602 /* set up the default links for the personal toolbar */
603 $personal_urls = array();
605 # Due to bug 32276, if a user does not have read permissions,
606 # $this->getTitle() will just give Special:Badtitle, which is
607 # not especially useful as a returnto parameter. Use the title
608 # from the request instead, if there was one.
609 if ( $this->getUser()->isAllowed( 'read' ) ) {
610 $page = $this->getTitle();
612 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
614 $page = $request->getVal( 'returnto', $page );
616 if ( strval( $page ) !== '' ) {
617 $a['returnto'] = $page;
618 $query = $request->getVal( 'returntoquery', $this->thisquery
);
619 if ( $query != '' ) {
620 $a['returntoquery'] = $query;
624 $returnto = wfArrayToCgi( $a );
625 if ( $this->loggedin
) {
626 $personal_urls['userpage'] = array(
627 'text' => $this->username
,
628 'href' => &$this->userpageUrlDetails
['href'],
629 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
630 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
633 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
634 $personal_urls['mytalk'] = array(
635 'text' => $this->msg( 'mytalk' )->text(),
636 'href' => &$usertalkUrlDetails['href'],
637 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
638 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
640 $href = self
::makeSpecialUrl( 'Preferences' );
641 $personal_urls['preferences'] = array(
642 'text' => $this->msg( 'mypreferences' )->text(),
644 'active' => ( $href == $pageurl )
647 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
648 $href = self
::makeSpecialUrl( 'Watchlist' );
649 $personal_urls['watchlist'] = array(
650 'text' => $this->msg( 'mywatchlist' )->text(),
652 'active' => ( $href == $pageurl )
656 # We need to do an explicit check for Special:Contributions, as we
657 # have to match both the title, and the target, which could come
658 # from request values (Special:Contributions?target=Jimbo_Wales)
659 # or be specified in "sub page" form
660 # (Special:Contributions/Jimbo_Wales). The plot
661 # thickens, because the Title object is altered for special pages,
662 # so it doesn't contain the original alias-with-subpage.
663 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
664 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
665 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
666 $active = $spName == 'Contributions'
667 && ( ( $spPar && $spPar == $this->username
)
668 ||
$request->getText( 'target' ) == $this->username
);
673 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
674 $personal_urls['mycontris'] = array(
675 'text' => $this->msg( 'mycontris' )->text(),
679 $personal_urls['logout'] = array(
680 'text' => $this->msg( 'userlogout' )->text(),
681 'href' => self
::makeSpecialUrl( 'Userlogout',
682 // userlogout link must always contain an & character, otherwise we might not be able
683 // to detect a buggy precaching proxy (bug 17790)
684 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
689 $useCombinedLoginLink = $this->useCombinedLoginLink();
690 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
691 ?
'nav-login-createaccount'
693 $is_signup = $request->getText( 'type' ) == 'signup';
695 $login_id = $this->showIPinHeader() ?
'anonlogin' : 'login';
697 'text' => $this->msg( $loginlink )->text(),
698 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
699 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
701 $createaccount_url = array(
702 'text' => $this->msg( 'createaccount' )->text(),
703 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
704 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
707 if ( $this->showIPinHeader() ) {
708 $href = &$this->userpageUrlDetails
['href'];
709 $personal_urls['anonuserpage'] = array(
710 'text' => $this->username
,
712 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
713 'active' => ( $pageurl == $href )
715 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
716 $href = &$usertalkUrlDetails['href'];
717 $personal_urls['anontalk'] = array(
718 'text' => $this->msg( 'anontalk' )->text(),
720 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
721 'active' => ( $pageurl == $href )
725 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
726 $personal_urls['createaccount'] = $createaccount_url;
729 $personal_urls[$login_id] = $login_url;
732 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
733 wfProfileOut( __METHOD__
);
734 return $personal_urls;
738 * Builds an array with tab definition
740 * @param Title $title page where the tab links to
741 * @param string|array $message message key or an array of message keys (will fall back)
742 * @param boolean $selected display the tab as selected
743 * @param string $query query string attached to tab URL
744 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
748 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
751 $classes[] = 'selected';
753 if ( $checkEdit && !$title->isKnown() ) {
755 if ( $query !== '' ) {
756 $query = 'action=edit&redlink=1&' . $query;
758 $query = 'action=edit&redlink=1';
762 // wfMessageFallback will nicely accept $message as an array of fallbacks
763 // or just a single key
764 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
765 if ( is_array( $message ) ) {
766 // for hook compatibility just keep the last message name
767 $message = end( $message );
769 if ( $msg->exists() ) {
770 $text = $msg->text();
773 $text = $wgContLang->getFormattedNsText(
774 MWNamespace
::getSubject( $title->getNamespace() ) );
778 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
779 $title, $message, $selected, $checkEdit,
780 &$classes, &$query, &$text, &$result ) ) ) {
785 'class' => implode( ' ', $classes ),
787 'href' => $title->getLocalURL( $query ),
791 function makeTalkUrlDetails( $name, $urlaction = '' ) {
792 $title = Title
::newFromText( $name );
793 if ( !is_object( $title ) ) {
794 throw new MWException( __METHOD__
. " given invalid pagename $name" );
796 $title = $title->getTalkPage();
797 self
::checkTitle( $title, $name );
799 'href' => $title->getLocalURL( $urlaction ),
800 'exists' => $title->getArticleID() != 0,
804 function makeArticleUrlDetails( $name, $urlaction = '' ) {
805 $title = Title
::newFromText( $name );
806 $title = $title->getSubjectPage();
807 self
::checkTitle( $title, $name );
809 'href' => $title->getLocalURL( $urlaction ),
810 'exists' => $title->getArticleID() != 0,
815 * a structured array of links usually used for the tabs in a skin
817 * There are 4 standard sections
818 * namespaces: Used for namespace tabs like special, page, and talk namespaces
819 * views: Used for primary page views like read, edit, history
820 * actions: Used for most extra page actions like deletion, protection, etc...
821 * variants: Used to list the language variants for the page
823 * Each section's value is a key/value array of links for that section.
824 * The links themselves have these common keys:
825 * - class: The css classes to apply to the tab
826 * - text: The text to display on the tab
827 * - href: The href for the tab to point to
828 * - rel: An optional rel= for the tab's link
829 * - redundant: If true the tab will be dropped in skins using content_actions
830 * this is useful for tabs like "Read" which only have meaning in skins that
831 * take special meaning from the grouped structure of content_navigation
833 * Views also have an extra key which can be used:
834 * - primary: If this is not true skins like vector may try to hide the tab
835 * when the user has limited space in their browser window
837 * content_navigation using code also expects these ids to be present on the
838 * links, however these are usually automatically generated by SkinTemplate
839 * itself and are not necessary when using a hook. The only things these may
840 * matter to are people modifying content_navigation after it's initial creation:
841 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
842 * - tooltiponly: This is set to true for some tabs in cases where the system
843 * believes that the accesskey should not be added to the tab.
847 protected function buildContentNavigationUrls() {
848 global $wgDisableLangConversion;
850 wfProfileIn( __METHOD__
);
852 // Display tabs for the relevant title rather than always the title itself
853 $title = $this->getRelevantTitle();
854 $onPage = $title->equals( $this->getTitle() );
856 $out = $this->getOutput();
857 $request = $this->getRequest();
858 $user = $this->getUser();
860 $content_navigation = array(
861 'namespaces' => array(),
863 'actions' => array(),
864 'variants' => array()
868 $action = $request->getVal( 'action', 'view' );
870 $userCanRead = $title->quickUserCan( 'read', $user );
872 $preventActiveTabs = false;
873 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
875 // Checks if page is some kind of content
876 if ( $title->canExist() ) {
877 // Gets page objects for the related namespaces
878 $subjectPage = $title->getSubjectPage();
879 $talkPage = $title->getTalkPage();
881 // Determines if this is a talk page
882 $isTalk = $title->isTalkPage();
884 // Generates XML IDs from namespace names
885 $subjectId = $title->getNamespaceKey( '' );
887 if ( $subjectId == 'main' ) {
890 $talkId = "{$subjectId}_talk";
893 $skname = $this->skinname
;
895 // Adds namespace links
896 $subjectMsg = array( "nstab-$subjectId" );
897 if ( $subjectPage->isMainPage() ) {
898 array_unshift( $subjectMsg, 'mainpage-nstab' );
900 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
901 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
903 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
904 $content_navigation['namespaces'][$talkId] = $this->tabAction(
905 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
907 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
909 if ( $userCanRead ) {
910 // Adds view view link
911 if ( $title->exists() ) {
912 $content_navigation['views']['view'] = $this->tabAction(
913 $isTalk ?
$talkPage : $subjectPage,
914 array( "$skname-view-view", 'view' ),
915 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
917 // signal to hide this from simple content_actions
918 $content_navigation['views']['view']['redundant'] = true;
921 wfProfileIn( __METHOD__
. '-edit' );
923 // Checks if user can edit the current page if it exists or create it otherwise
924 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
925 // Builds CSS class for talk page links
926 $isTalkClass = $isTalk ?
' istalk' : '';
927 // Whether the user is editing the page
928 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
929 // Whether to show the "Add a new section" tab
930 // Checks if this is a current rev of talk page and is not forced to be hidden
931 $showNewSection = !$out->forceHideNewSectionLink()
932 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
933 $section = $request->getVal( 'section' );
935 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
937 $content_navigation['views']['edit'] = array(
938 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
939 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
940 'href' => $title->getLocalURL( $this->editUrlOptions() ),
941 'primary' => true, // don't collapse this in vector
945 if ( $showNewSection ) {
946 // Adds new section link
947 //$content_navigation['actions']['addsection']
948 $content_navigation['views']['addsection'] = array(
949 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
950 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
951 'href' => $title->getLocalURL( 'action=edit§ion=new' )
954 // Checks if the page has some kind of viewable content
955 } elseif ( $title->hasSourceText() ) {
956 // Adds view source view link
957 $content_navigation['views']['viewsource'] = array(
958 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
959 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
960 'href' => $title->getLocalURL( $this->editUrlOptions() ),
961 'primary' => true, // don't collapse this in vector
964 wfProfileOut( __METHOD__
. '-edit' );
966 wfProfileIn( __METHOD__
. '-live' );
967 // Checks if the page exists
968 if ( $title->exists() ) {
969 // Adds history view link
970 $content_navigation['views']['history'] = array(
971 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
972 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
973 'href' => $title->getLocalURL( 'action=history' ),
977 if ( $title->quickUserCan( 'delete', $user ) ) {
978 $content_navigation['actions']['delete'] = array(
979 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
980 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
981 'href' => $title->getLocalURL( 'action=delete' )
985 if ( $title->quickUserCan( 'move', $user ) ) {
986 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
987 $content_navigation['actions']['move'] = array(
988 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
989 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
990 'href' => $moveTitle->getLocalURL()
994 // article doesn't exist or is deleted
995 if ( $user->isAllowed( 'deletedhistory' ) ) {
996 $n = $title->isDeleted();
998 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
999 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1000 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1001 $content_navigation['actions']['undelete'] = array(
1002 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1003 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1004 ->setContext( $this->getContext() )->numParams( $n )->text(),
1005 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1011 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
1012 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1013 $content_navigation['actions'][$mode] = array(
1014 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1015 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1016 'href' => $title->getLocalURL( "action=$mode" )
1020 wfProfileOut( __METHOD__
. '-live' );
1022 // Checks if the user is logged in
1023 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1025 * The following actions use messages which, if made particular to
1026 * the any specific skins, would break the Ajax code which makes this
1027 * action happen entirely inline. Skin::makeGlobalVariablesScript
1028 * defines a set of messages in a javascript object - and these
1029 * messages are assumed to be global for all skins. Without making
1030 * a change to that procedure these messages will have to remain as
1031 * the global versions.
1033 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1034 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1035 $content_navigation['actions'][$mode] = array(
1036 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1037 // uses 'watch' or 'unwatch' message
1038 'text' => $this->msg( $mode )->text(),
1039 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1044 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1046 if ( $userCanRead && !$wgDisableLangConversion ) {
1047 $pageLang = $title->getPageLanguage();
1048 // Gets list of language variants
1049 $variants = $pageLang->getVariants();
1050 // Checks that language conversion is enabled and variants exist
1051 // And if it is not in the special namespace
1052 if ( count( $variants ) > 1 ) {
1053 // Gets preferred variant (note that user preference is
1054 // only possible for wiki content language variant)
1055 $preferred = $pageLang->getPreferredVariant();
1056 if ( Action
::getActionName( $this ) === 'view' ) {
1057 $params = $request->getQueryValues();
1058 unset( $params['title'] );
1062 // Loops over each variant
1063 foreach ( $variants as $code ) {
1064 // Gets variant name from language code
1065 $varname = $pageLang->getVariantname( $code );
1066 // Appends variant link
1067 $content_navigation['variants'][] = array(
1068 'class' => ( $code == $preferred ) ?
'selected' : false,
1070 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1071 'lang' => wfBCP47( $code ),
1072 'hreflang' => wfBCP47( $code ),
1078 // If it's not content, it's got to be a special page
1079 $content_navigation['namespaces']['special'] = array(
1080 'class' => 'selected',
1081 'text' => $this->msg( 'nstab-special' )->text(),
1082 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1083 'context' => 'subject'
1086 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1087 array( &$this, &$content_navigation ) );
1090 // Equiv to SkinTemplateContentActions
1091 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1093 // Setup xml ids and tooltip info
1094 foreach ( $content_navigation as $section => &$links ) {
1095 foreach ( $links as $key => &$link ) {
1097 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1098 $xmlID = 'ca-nstab-' . $xmlID;
1099 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1101 } elseif ( $section == 'variants' ) {
1102 $xmlID = 'ca-varlang-' . $xmlID;
1104 $xmlID = 'ca-' . $xmlID;
1106 $link['id'] = $xmlID;
1110 # We don't want to give the watch tab an accesskey if the
1111 # page is being edited, because that conflicts with the
1112 # accesskey on the watch checkbox. We also don't want to
1113 # give the edit tab an accesskey, because that's fairly
1114 # superfluous and conflicts with an accesskey (Ctrl-E) often
1115 # used for editing in Safari.
1116 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1117 if ( isset( $content_navigation['views']['edit'] ) ) {
1118 $content_navigation['views']['edit']['tooltiponly'] = true;
1120 if ( isset( $content_navigation['actions']['watch'] ) ) {
1121 $content_navigation['actions']['watch']['tooltiponly'] = true;
1123 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1124 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1128 wfProfileOut( __METHOD__
);
1130 return $content_navigation;
1134 * an array of edit links by default used for the tabs
1138 function buildContentActionUrls( $content_navigation ) {
1140 wfProfileIn( __METHOD__
);
1142 // content_actions has been replaced with content_navigation for backwards
1143 // compatibility and also for skins that just want simple tabs content_actions
1144 // is now built by flattening the content_navigation arrays into one
1146 $content_actions = array();
1148 foreach ( $content_navigation as $links ) {
1150 foreach ( $links as $key => $value ) {
1152 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1153 // Redundant tabs are dropped from content_actions
1157 // content_actions used to have ids built using the "ca-$key" pattern
1158 // so the xmlID based id is much closer to the actual $key that we want
1159 // for that reason we'll just strip out the ca- if present and use
1160 // the latter potion of the "id" as the $key
1161 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1162 $key = substr( $value['id'], 3 );
1165 if ( isset( $content_actions[$key] ) ) {
1166 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1170 $content_actions[$key] = $value;
1176 wfProfileOut( __METHOD__
);
1178 return $content_actions;
1182 * build array of common navigation links
1186 protected function buildNavUrls() {
1187 global $wgUploadNavigationUrl;
1189 wfProfileIn( __METHOD__
);
1191 $out = $this->getOutput();
1192 $request = $this->getRequest();
1194 $nav_urls = array();
1195 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1196 if ( $wgUploadNavigationUrl ) {
1197 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1198 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1199 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1201 $nav_urls['upload'] = false;
1203 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1205 $nav_urls['print'] = false;
1206 $nav_urls['permalink'] = false;
1207 $nav_urls['info'] = false;
1208 $nav_urls['whatlinkshere'] = false;
1209 $nav_urls['recentchangeslinked'] = false;
1210 $nav_urls['contributions'] = false;
1211 $nav_urls['log'] = false;
1212 $nav_urls['blockip'] = false;
1213 $nav_urls['emailuser'] = false;
1214 $nav_urls['userrights'] = false;
1216 // A print stylesheet is attached to all pages, but nobody ever
1217 // figures that out. :) Add a link...
1218 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1219 $nav_urls['print'] = array(
1220 'text' => $this->msg( 'printableversion' )->text(),
1221 'href' => $this->getTitle()->getLocalURL(
1222 $request->appendQueryValue( 'printable', 'yes', true ) )
1226 if ( $out->isArticle() ) {
1227 // Also add a "permalink" while we're at it
1228 $revid = $this->getRevisionId();
1230 $nav_urls['permalink'] = array(
1231 'text' => $this->msg( 'permalink' )->text(),
1232 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1236 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1237 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1238 array( &$this, &$nav_urls, &$revid, &$revid ) );
1241 if ( $out->isArticleRelated() ) {
1242 $nav_urls['whatlinkshere'] = array(
1243 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1246 $nav_urls['info'] = array(
1247 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1248 'href' => $this->getTitle()->getLocalURL( "action=info" )
1251 if ( $this->getTitle()->getArticleID() ) {
1252 $nav_urls['recentchangeslinked'] = array(
1253 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1258 $user = $this->getRelevantUser();
1260 $rootUser = $user->getName();
1262 $nav_urls['contributions'] = array(
1263 'text' => $this->msg( 'contributions', $rootUser )->text(),
1264 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1267 $nav_urls['log'] = array(
1268 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1271 if ( $this->getUser()->isAllowed( 'block' ) ) {
1272 $nav_urls['blockip'] = array(
1273 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1277 if ( $this->showEmailUser( $user ) ) {
1278 $nav_urls['emailuser'] = array(
1279 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1283 if ( !$user->isAnon() ) {
1284 $sur = new UserrightsPage
;
1285 $sur->setContext( $this->getContext() );
1286 if ( $sur->userCanExecute( $this->getUser() ) ) {
1287 $nav_urls['userrights'] = array(
1288 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1294 wfProfileOut( __METHOD__
);
1299 * Generate strings used for xml 'id' names
1303 function getNameSpaceKey() {
1304 return $this->getTitle()->getNamespaceKey();
1309 * Generic wrapper for template functions, with interface
1310 * compatible with what we use of PHPTAL 0.7.
1313 abstract class QuickTemplate
{
1317 function __construct() {
1318 $this->data
= array();
1319 $this->translator
= new MediaWiki_I18N();
1323 * Sets the value $value to $name
1327 public function set( $name, $value ) {
1328 $this->data
[$name] = $value;
1332 * Gets the template data requested
1334 * @param string $name Key for the data
1335 * @param mixed $default Optional default (or null)
1336 * @return mixed The value of the data requested or the deafult
1338 public function get( $name, $default = null ) {
1339 if ( isset( $this->data
[$name] ) ) {
1340 return $this->data
[$name];
1350 public function setRef( $name, &$value ) {
1351 $this->data
[$name] =& $value;
1357 public function setTranslator( &$t ) {
1358 $this->translator
= &$t;
1362 * Main function, used by classes that subclass QuickTemplate
1363 * to show the actual HTML output
1365 abstract public function execute();
1370 function text( $str ) {
1371 echo htmlspecialchars( $this->data
[$str] );
1376 * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
1378 function jstext( $str ) {
1379 wfDeprecated( __METHOD__
, '1.21' );
1380 echo Xml
::escapeJsString( $this->data
[$str] );
1386 function html( $str ) {
1387 echo $this->data
[$str];
1393 function msg( $str ) {
1394 echo htmlspecialchars( $this->translator
->translate( $str ) );
1400 function msgHtml( $str ) {
1401 echo $this->translator
->translate( $str );
1405 * An ugly, ugly hack.
1408 function msgWiki( $str ) {
1411 $text = $this->translator
->translate( $str );
1412 echo $wgOut->parse( $text );
1419 function haveData( $str ) {
1420 return isset( $this->data
[$str] );
1428 function haveMsg( $str ) {
1429 $msg = $this->translator
->translate( $str );
1430 return ( $msg != '-' ) && ( $msg != '' ); # ????
1434 * Get the Skin object related to this object
1436 * @return Skin object
1438 public function getSkin() {
1439 return $this->data
['skin'];
1444 * New base template for a skin's template extended from QuickTemplate
1445 * this class features helper methods that provide common ways of interacting
1446 * with the data stored in the QuickTemplate
1448 abstract class BaseTemplate
extends QuickTemplate
{
1451 * Get a Message object with its context set
1453 * @param string $name message name
1456 public function getMsg( $name ) {
1457 return $this->getSkin()->msg( $name );
1460 function msg( $str ) {
1461 echo $this->getMsg( $str )->escaped();
1464 function msgHtml( $str ) {
1465 echo $this->getMsg( $str )->text();
1468 function msgWiki( $str ) {
1469 echo $this->getMsg( $str )->parseAsBlock();
1473 * Create an array of common toolbox items from the data in the quicktemplate
1474 * stored by SkinTemplate.
1475 * The resulting array is built according to a format intended to be passed
1476 * through makeListItem to generate the html.
1479 function getToolbox() {
1480 wfProfileIn( __METHOD__
);
1483 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1484 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1485 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1487 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1488 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1489 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1490 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1492 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1493 $toolbox['feeds']['id'] = 'feedlinks';
1494 $toolbox['feeds']['links'] = array();
1495 foreach ( $this->data
['feeds'] as $key => $feed ) {
1496 $toolbox['feeds']['links'][$key] = $feed;
1497 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1498 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1499 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1500 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1503 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1504 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1505 $toolbox[$special] = $this->data
['nav_urls'][$special];
1506 $toolbox[$special]['id'] = "t-$special";
1509 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1510 $toolbox['print'] = $this->data
['nav_urls']['print'];
1511 $toolbox['print']['id'] = 't-print';
1512 $toolbox['print']['rel'] = 'alternate';
1513 $toolbox['print']['msg'] = 'printableversion';
1515 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1516 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1517 if ( $toolbox['permalink']['href'] === '' ) {
1518 unset( $toolbox['permalink']['href'] );
1519 $toolbox['ispermalink']['tooltiponly'] = true;
1520 $toolbox['ispermalink']['id'] = 't-ispermalink';
1521 $toolbox['ispermalink']['msg'] = 'permalink';
1523 $toolbox['permalink']['id'] = 't-permalink';
1526 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1527 $toolbox['info'] = $this->data
['nav_urls']['info'];
1528 $toolbox['info']['id'] = 't-info';
1531 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1532 wfProfileOut( __METHOD__
);
1537 * Create an array of personal tools items from the data in the quicktemplate
1538 * stored by SkinTemplate.
1539 * The resulting array is built according to a format intended to be passed
1540 * through makeListItem to generate the html.
1541 * This is in reality the same list as already stored in personal_urls
1542 * however it is reformatted so that you can just pass the individual items
1543 * to makeListItem instead of hardcoding the element creation boilerplate.
1546 function getPersonalTools() {
1547 $personal_tools = array();
1548 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1549 # The class on a personal_urls item is meant to go on the <a> instead
1550 # of the <li> so we have to use a single item "links" array instead
1551 # of using most of the personal_url's keys directly.
1554 array( 'single-id' => "pt-$key" ),
1558 if ( isset( $plink['active'] ) ) {
1559 $ptool['active'] = $plink['active'];
1561 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1562 if ( isset( $plink[$k] ) ) {
1563 $ptool['links'][0][$k] = $plink[$k];
1566 $personal_tools[$key] = $ptool;
1568 return $personal_tools;
1571 function getSidebar( $options = array() ) {
1572 // Force the rendering of the following portals
1573 $sidebar = $this->data
['sidebar'];
1574 if ( !isset( $sidebar['SEARCH'] ) ) {
1575 $sidebar['SEARCH'] = true;
1577 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1578 $sidebar['TOOLBOX'] = true;
1580 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1581 $sidebar['LANGUAGES'] = true;
1584 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1585 unset( $sidebar['SEARCH'] );
1587 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1588 unset( $sidebar['TOOLBOX'] );
1590 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1591 unset( $sidebar['LANGUAGES'] );
1595 foreach ( $sidebar as $boxName => $content ) {
1596 if ( $content === false ) {
1599 switch ( $boxName ) {
1601 // Search is a special case, skins should custom implement this
1602 $boxes[$boxName] = array(
1604 'header' => $this->getMsg( 'search' )->text(),
1605 'generated' => false,
1610 $msgObj = $this->getMsg( 'toolbox' );
1611 $boxes[$boxName] = array(
1613 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1614 'generated' => false,
1615 'content' => $this->getToolbox(),
1619 if ( $this->data
['language_urls'] ) {
1620 $msgObj = $this->getMsg( 'otherlanguages' );
1621 $boxes[$boxName] = array(
1623 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1624 'generated' => false,
1625 'content' => $this->data
['language_urls'],
1630 $msgObj = $this->getMsg( $boxName );
1631 $boxes[$boxName] = array(
1632 'id' => "p-$boxName",
1633 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1634 'generated' => true,
1635 'content' => $content,
1641 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1642 $hookContents = null;
1643 if ( isset( $boxes['TOOLBOX'] ) ) {
1645 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1646 // can abort and avoid outputting double toolbox links
1647 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1648 $hookContents = ob_get_contents();
1650 if ( !trim( $hookContents ) ) {
1651 $hookContents = null;
1656 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1657 foreach ( $boxes as $boxName => $box ) {
1658 if ( is_array( $box['content'] ) ) {
1660 foreach ( $box['content'] as $key => $val ) {
1661 $content .= "\n " . $this->makeListItem( $key, $val );
1663 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1664 if ( $hookContents ) {
1665 $content .= "\n $hookContents";
1668 $content .= "\n</ul>\n";
1669 $boxes[$boxName]['content'] = $content;
1673 if ( $hookContents ) {
1674 $boxes['TOOLBOXEND'] = array(
1675 'id' => 'p-toolboxend',
1676 'header' => $boxes['TOOLBOX']['header'],
1677 'generated' => false,
1678 'content' => "<ul>{$hookContents}</ul>",
1680 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1682 foreach ( $boxes as $key => $box ) {
1683 if ( $key === 'TOOLBOXEND' ) {
1686 $boxes2[$key] = $box;
1687 if ( $key === 'TOOLBOX' ) {
1688 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1700 * Makes a link, usually used by makeListItem to generate a link for an item
1701 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1703 * @param string $key usually a key from the list you are generating this
1705 * @param array $item contains some of a specific set of keys.
1707 * The text of the link will be generated either from the contents of the
1708 * "text" key in the $item array, if a "msg" key is present a message by
1709 * that name will be used, and if neither of those are set the $key will be
1710 * used as a message name.
1712 * If a "href" key is not present makeLink will just output htmlescaped text.
1713 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1714 * for the link if present.
1716 * If an "id" or "single-id" (if you don't want the actual id to be output
1717 * on the link) is present it will be used to generate a tooltip and
1718 * accesskey for the link.
1720 * The keys "context" and "primary" are ignored; these keys are used
1721 * internally by skins and are not supposed to be included in the HTML
1724 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1726 * @param array $options can be used to affect the output of a link.
1727 * Possible options are:
1728 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1729 * a link in. This should be an array of arrays containing a 'tag' and
1730 * optionally an 'attributes' key. If you only have one element you don't
1731 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1732 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1734 * - 'link-class' key can be used to specify additional classes to apply
1736 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1737 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1738 * any non-link will output a "<span>" instead of just text.
1742 function makeLink( $key, $item, $options = array() ) {
1743 if ( isset( $item['text'] ) ) {
1744 $text = $item['text'];
1746 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1749 $html = htmlspecialchars( $text );
1751 if ( isset( $options['text-wrapper'] ) ) {
1752 $wrapper = $options['text-wrapper'];
1753 if ( isset( $wrapper['tag'] ) ) {
1754 $wrapper = array( $wrapper );
1756 while ( count( $wrapper ) > 0 ) {
1757 $element = array_pop( $wrapper );
1758 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1762 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1764 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1765 unset( $attrs[$k] );
1768 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1769 $item['single-id'] = $item['id'];
1771 if ( isset( $item['single-id'] ) ) {
1772 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1773 $title = Linker
::titleAttrib( $item['single-id'] );
1774 if ( $title !== false ) {
1775 $attrs['title'] = $title;
1778 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1779 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1780 $attrs['title'] = $tip['title'];
1782 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1783 $attrs['accesskey'] = $tip['accesskey'];
1787 if ( isset( $options['link-class'] ) ) {
1788 if ( isset( $attrs['class'] ) ) {
1789 $attrs['class'] .= " {$options['link-class']}";
1791 $attrs['class'] = $options['link-class'];
1794 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1801 * Generates a list item for a navigation, portlet, portal, sidebar... list
1803 * @param $key string, usually a key from the list you are generating this link from.
1804 * @param $item array, of list item data containing some of a specific set of keys.
1805 * The "id" and "class" keys will be used as attributes for the list item,
1806 * if "active" contains a value of true a "active" class will also be appended to class.
1808 * @param $options array
1810 * If you want something other than a "<li>" you can pass a tag name such as
1811 * "tag" => "span" in the $options array to change the tag used.
1812 * link/content data for the list item may come in one of two forms
1813 * A "links" key may be used, in which case it should contain an array with
1814 * a list of links to include inside the list item, see makeLink for the
1815 * format of individual links array items.
1817 * Otherwise the relevant keys from the list item $item array will be passed
1818 * to makeLink instead. Note however that "id" and "class" are used by the
1819 * list item directly so they will not be passed to makeLink
1820 * (however the link will still support a tooltip and accesskey from it)
1821 * If you need an id or class on a single link you should include a "links"
1822 * array with just one link item inside of it.
1823 * $options is also passed on to makeLink calls
1827 function makeListItem( $key, $item, $options = array() ) {
1828 if ( isset( $item['links'] ) ) {
1830 foreach ( $item['links'] as $linkKey => $link ) {
1831 $html .= $this->makeLink( $linkKey, $link, $options );
1835 // These keys are used by makeListItem and shouldn't be passed on to the link
1836 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1839 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1840 // The id goes on the <li> not on the <a> for single links
1841 // but makeSidebarLink still needs to know what id to use when
1842 // generating tooltips and accesskeys.
1843 $link['single-id'] = $item['id'];
1845 $html = $this->makeLink( $key, $link, $options );
1849 foreach ( array( 'id', 'class' ) as $attr ) {
1850 if ( isset( $item[$attr] ) ) {
1851 $attrs[$attr] = $item[$attr];
1854 if ( isset( $item['active'] ) && $item['active'] ) {
1855 if ( !isset( $attrs['class'] ) ) {
1856 $attrs['class'] = '';
1858 $attrs['class'] .= ' active';
1859 $attrs['class'] = trim( $attrs['class'] );
1861 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1864 function makeSearchInput( $attrs = array() ) {
1868 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1869 'value' => $this->get( 'search', '' ),
1871 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1872 return Html
::element( 'input', $realAttrs );
1875 function makeSearchButton( $mode, $attrs = array() ) {
1882 'value' => $this->translator
->translate(
1883 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1885 $realAttrs = array_merge(
1887 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1890 return Html
::element( 'input', $realAttrs );
1892 $buttonAttrs = array(
1896 $buttonAttrs = array_merge(
1898 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1901 unset( $buttonAttrs['src'] );
1902 unset( $buttonAttrs['alt'] );
1903 unset( $buttonAttrs['width'] );
1904 unset( $buttonAttrs['height'] );
1906 'src' => $attrs['src'],
1907 'alt' => isset( $attrs['alt'] )
1909 : $this->translator
->translate( 'searchbutton' ),
1910 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1911 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1913 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1915 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1920 * Returns an array of footerlinks trimmed down to only those footer links that
1922 * If you pass "flat" as an option then the returned array will be a flat array
1923 * of footer icons instead of a key/value array of footerlinks arrays broken
1924 * up into categories.
1925 * @return array|mixed
1927 function getFooterLinks( $option = null ) {
1928 $footerlinks = $this->get( 'footerlinks' );
1930 // Reduce footer links down to only those which are being used
1931 $validFooterLinks = array();
1932 foreach ( $footerlinks as $category => $links ) {
1933 $validFooterLinks[$category] = array();
1934 foreach ( $links as $link ) {
1935 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1936 $validFooterLinks[$category][] = $link;
1939 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1940 unset( $validFooterLinks[$category] );
1944 if ( $option == 'flat' ) {
1945 // fold footerlinks into a single array using a bit of trickery
1946 $validFooterLinks = call_user_func_array(
1948 array_values( $validFooterLinks )
1952 return $validFooterLinks;
1956 * Returns an array of footer icons filtered down by options relevant to how
1957 * the skin wishes to display them.
1958 * If you pass "icononly" as the option all footer icons which do not have an
1959 * image icon set will be filtered out.
1960 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1961 * in the list of footer icons. This is mostly useful for skins which only
1962 * display the text from footericons instead of the images and don't want a
1963 * duplicate copyright statement because footerlinks already rendered one.
1966 function getFooterIcons( $option = null ) {
1967 // Generate additional footer icons
1968 $footericons = $this->get( 'footericons' );
1970 if ( $option == 'icononly' ) {
1971 // Unset any icons which don't have an image
1972 foreach ( $footericons as &$footerIconsBlock ) {
1973 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1974 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1975 unset( $footerIconsBlock[$footerIconKey] );
1979 // Redo removal of any empty blocks
1980 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1981 if ( count( $footerIconsBlock ) <= 0 ) {
1982 unset( $footericons[$footerIconsKey] );
1985 } elseif ( $option == 'nocopyright' ) {
1986 unset( $footericons['copyright']['copyright'] );
1987 if ( count( $footericons['copyright'] ) <= 0 ) {
1988 unset( $footericons['copyright'] );
1992 return $footericons;
1996 * Output the basic end-page trail including bottomscripts, reporttime, and
1997 * debug stuff. This should be called right before outputting the closing
1998 * body and html tags.
2000 function printTrail() { ?
>
2001 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2002 <?php
$this->html( 'reporttime' ) ?
>
2003 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() );