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 if ( $wgHideInterlanguageLinks ) {
137 $userLang = $this->getLanguage();
138 $languageLinks = array();
140 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
141 $languageLinkParts = explode( ':', $languageLinkText, 2 );
142 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
143 unset( $languageLinkParts );
145 $languageLinkTitle = Title
::newFromText( $languageLinkText );
146 if ( $languageLinkTitle ) {
147 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
148 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
150 if ( strval( $ilLangName ) === '' ) {
151 $ilLangName = $languageLinkText;
153 $ilLangName = $this->formatLanguageName( $ilLangName );
156 // CLDR extension or similar is required to localize the language name;
157 // otherwise we'll end up with the autonym again.
158 $ilLangLocalName = Language
::fetchLanguageName(
163 $languageLinkTitleText = $languageLinkTitle->getText();
164 if ( $languageLinkTitleText === '' ) {
165 $ilTitle = wfMessage(
166 'interlanguage-link-title-langonly',
170 $ilTitle = wfMessage(
171 'interlanguage-link-title',
172 $languageLinkTitleText,
177 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
178 $languageLinks[] = array(
179 'href' => $languageLinkTitle->getFullURL(),
180 'text' => $ilLangName,
183 'lang' => $ilInterwikiCodeBCP47,
184 'hreflang' => $ilInterwikiCodeBCP47,
189 return $languageLinks;
192 protected function setupTemplateForOutput() {
193 wfProfileIn( __METHOD__
);
195 $request = $this->getRequest();
196 $user = $this->getUser();
197 $title = $this->getTitle();
199 wfProfileIn( __METHOD__
. '-init' );
200 $tpl = $this->setupTemplate( $this->template
, 'skins' );
201 wfProfileOut( __METHOD__
. '-init' );
203 wfProfileIn( __METHOD__
. '-stuff' );
204 $this->thispage
= $title->getPrefixedDBkey();
205 $this->titletxt
= $title->getPrefixedText();
206 $this->userpage
= $user->getUserPage()->getPrefixedText();
208 if ( !$request->wasPosted() ) {
209 $query = $request->getValues();
210 unset( $query['title'] );
211 unset( $query['returnto'] );
212 unset( $query['returntoquery'] );
214 $this->thisquery
= wfArrayToCgi( $query );
215 $this->loggedin
= $user->isLoggedIn();
216 $this->username
= $user->getName();
218 if ( $this->loggedin ||
$this->showIPinHeader() ) {
219 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
221 # This won't be used in the standard skins, but we define it to preserve the interface
222 # To save time, we check for existence
223 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
226 wfProfileOut( __METHOD__
. '-stuff' );
228 wfProfileOut( __METHOD__
);
234 * initialize various variables and generate the template
236 * @param $out OutputPage
238 function outputPage( OutputPage
$out = null ) {
239 wfProfileIn( __METHOD__
);
240 Profiler
::instance()->setTemplated( true );
243 if ( $out !== null ) {
244 // @todo Add wfDeprecated in 1.20
245 $oldContext = $this->getContext();
246 $this->setContext( $out->getContext() );
249 $out = $this->getOutput();
251 wfProfileIn( __METHOD__
. '-init' );
252 $this->initPage( $out );
253 wfProfileOut( __METHOD__
. '-init' );
254 $tpl = $this->prepareQuickTemplate( $out );
256 wfProfileIn( __METHOD__
. '-execute' );
257 $res = $tpl->execute();
258 wfProfileOut( __METHOD__
. '-execute' );
260 // result may be an error
261 $this->printOrError( $res );
264 $this->setContext( $oldContext );
267 wfProfileOut( __METHOD__
);
271 * initialize various variables and generate the template
274 * @return QuickTemplate the template to be executed by outputPage
276 protected function prepareQuickTemplate() {
277 global $wgContLang, $wgScript, $wgStylePath,
278 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
279 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
280 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
281 $wgScriptPath, $wgServer;
283 wfProfileIn( __METHOD__
);
285 $title = $this->getTitle();
286 $request = $this->getRequest();
287 $out = $this->getOutput();
288 $tpl = $this->setupTemplateForOutput();
290 wfProfileIn( __METHOD__
. '-stuff-head' );
291 if ( !$this->useHeadElement
) {
292 $tpl->set( 'pagecss', false );
293 $tpl->set( 'usercss', false );
295 $tpl->set( 'userjs', false );
296 $tpl->set( 'userjsprev', false );
298 $tpl->set( 'jsvarurl', false );
300 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
301 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
302 $tpl->set( 'html5version', $wgHtml5Version );
303 $tpl->set( 'headlinks', $out->getHeadLinks() );
304 $tpl->set( 'csslinks', $out->buildCssLinks() );
305 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
306 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
308 wfProfileOut( __METHOD__
. '-stuff-head' );
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 /* XXX currently unused, might get useful later
363 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
364 $tpl->set( 'exists', $title->getArticleID() != 0 );
365 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
366 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
367 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
369 $tpl->set( 'searchaction', $this->escapeSearchLink() );
370 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
371 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
372 $tpl->setRef( 'stylepath', $wgStylePath );
373 $tpl->setRef( 'articlepath', $wgArticlePath );
374 $tpl->setRef( 'scriptpath', $wgScriptPath );
375 $tpl->setRef( 'serverurl', $wgServer );
376 $tpl->setRef( 'logopath', $wgLogo );
377 $tpl->setRef( 'sitename', $wgSitename );
379 $userLang = $this->getLanguage();
380 $userLangCode = $userLang->getHtmlCode();
381 $userLangDir = $userLang->getDir();
383 $tpl->set( 'lang', $userLangCode );
384 $tpl->set( 'dir', $userLangDir );
385 $tpl->set( 'rtl', $userLang->isRTL() );
387 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
388 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
389 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
390 $tpl->setRef( 'userpage', $this->userpage
);
391 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
392 $tpl->set( 'userlang', $userLangCode );
394 // Users can have their language set differently than the
395 // content of the wiki. For these users, tell the web browser
396 // that interface elements are in a different language.
397 $tpl->set( 'userlangattributes', '' );
398 $tpl->set( 'specialpageattributes', '' ); # obsolete
400 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
401 $escUserlang = htmlspecialchars( $userLangCode );
402 $escUserdir = htmlspecialchars( $userLangDir );
403 // Attributes must be in double quotes because htmlspecialchars() doesn't
404 // escape single quotes
405 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
406 $tpl->set( 'userlangattributes', $attrs );
409 wfProfileOut( __METHOD__
. '-stuff2' );
411 wfProfileIn( __METHOD__
. '-stuff3' );
412 $tpl->set( 'newtalk', $this->getNewtalks() );
413 $tpl->set( 'logo', $this->logoText() );
415 $tpl->set( 'copyright', false );
416 $tpl->set( 'viewcount', false );
417 $tpl->set( 'lastmod', false );
418 $tpl->set( 'credits', false );
419 $tpl->set( 'numberofwatchingusers', false );
420 if ( $out->isArticle() && $title->exists() ) {
421 if ( $this->isRevisionCurrent() ) {
422 if ( !$wgDisableCounters ) {
423 $viewcount = $this->getWikiPage()->getCount();
425 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
429 if ( $wgPageShowWatchingUsers ) {
430 $dbr = wfGetDB( DB_SLAVE
);
431 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
432 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
436 $tpl->set( 'numberofwatchingusers',
437 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
442 if ( $wgMaxCredits != 0 ) {
443 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
444 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
446 $tpl->set( 'lastmod', $this->lastModified() );
449 $tpl->set( 'copyright', $this->getCopyright() );
451 wfProfileOut( __METHOD__
. '-stuff3' );
453 wfProfileIn( __METHOD__
. '-stuff4' );
454 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
455 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
456 $tpl->set( 'disclaimer', $this->disclaimerLink() );
457 $tpl->set( 'privacy', $this->privacyLink() );
458 $tpl->set( 'about', $this->aboutLink() );
460 $tpl->set( 'footerlinks', array(
464 'numberofwatchingusers',
475 global $wgFooterIcons;
476 $tpl->set( 'footericons', $wgFooterIcons );
477 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
478 if ( count( $footerIconsBlock ) > 0 ) {
479 foreach ( $footerIconsBlock as &$footerIcon ) {
480 if ( isset( $footerIcon['src'] ) ) {
481 if ( !isset( $footerIcon['width'] ) ) {
482 $footerIcon['width'] = 88;
484 if ( !isset( $footerIcon['height'] ) ) {
485 $footerIcon['height'] = 31;
490 unset( $tpl->data
['footericons'][$footerIconsKey] );
494 $tpl->set( 'sitenotice', $this->getSiteNotice() );
495 $tpl->set( 'bottomscripts', $this->bottomScripts() );
496 $tpl->set( 'printfooter', $this->printSource() );
498 # An ID that includes the actual body text; without categories, contentSub, ...
499 $realBodyAttribs = array( 'id' => 'mw-content-text' );
501 # Add a mw-content-ltr/rtl class to be able to style based on text direction
502 # when the content is different from the UI language, i.e.:
503 # not for special pages or file pages AND only when viewing AND if the page exists
504 # (or is in MW namespace, because that has default content)
505 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
506 Action
::getActionName( $this ) === 'view' &&
507 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
508 $pageLang = $title->getPageViewLanguage();
509 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
510 $realBodyAttribs['dir'] = $pageLang->getDir();
511 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
514 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
515 $tpl->setRef( 'bodytext', $out->mBodytext
);
517 $language_urls = $this->getLanguages();
518 if ( count( $language_urls ) ) {
519 $tpl->setRef( 'language_urls', $language_urls );
521 $tpl->set( 'language_urls', false );
523 wfProfileOut( __METHOD__
. '-stuff4' );
525 wfProfileIn( __METHOD__
. '-stuff5' );
527 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
528 $content_navigation = $this->buildContentNavigationUrls();
529 $content_actions = $this->buildContentActionUrls( $content_navigation );
530 $tpl->setRef( 'content_navigation', $content_navigation );
531 $tpl->setRef( 'content_actions', $content_actions );
533 $tpl->set( 'sidebar', $this->buildSidebar() );
534 $tpl->set( 'nav_urls', $this->buildNavUrls() );
536 // Set the head scripts near the end, in case the above actions resulted in added scripts
537 if ( $this->useHeadElement
) {
538 $tpl->set( 'headelement', $out->headElement( $this ) );
540 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
543 $tpl->set( 'debug', '' );
544 $tpl->set( 'debughtml', $this->generateDebugHTML() );
545 $tpl->set( 'reporttime', wfReportTime() );
547 // original version by hansm
548 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
549 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
552 // Set the bodytext to another key so that skins can just output it on it's own
553 // and output printfooter and debughtml separately
554 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
556 // Append printfooter and debughtml onto bodytext so that skins that were already
557 // using bodytext before they were split out don't suddenly start not outputting information
558 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
559 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
561 // allow extensions adding stuff after the page content.
562 // See Skin::afterContentHook() for further documentation.
563 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
564 wfProfileOut( __METHOD__
. '-stuff5' );
566 wfProfileOut( __METHOD__
);
571 * Get the HTML for the p-personal list
574 public function getPersonalToolsList() {
575 $tpl = $this->setupTemplateForOutput();
576 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
578 foreach ( $tpl->getPersonalTools() as $key => $item ) {
579 $html .= $tpl->makeListItem( $key, $item );
585 * Format language name for use in sidebar interlanguage links list.
586 * By default it is capitalized.
588 * @param string $name Language name, e.g. "English" or "español"
592 function formatLanguageName( $name ) {
593 return $this->getLanguage()->ucfirst( $name );
597 * Output the string, or print error message if it's
598 * an error object of the appropriate type.
599 * For the base class, assume strings all around.
604 function printOrError( $str ) {
609 * Output a boolean indicating if buildPersonalUrls should output separate
610 * login and create account links or output a combined link
611 * By default we simply return a global config setting that affects most skins
612 * This is setup as a method so that like with $wgLogo and getLogo() a skin
613 * can override this setting and always output one or the other if it has
614 * a reason it can't output one of the two modes.
617 function useCombinedLoginLink() {
618 global $wgUseCombinedLoginLink;
619 return $wgUseCombinedLoginLink;
623 * build array of urls for personal toolbar
626 protected function buildPersonalUrls() {
627 $title = $this->getTitle();
628 $request = $this->getRequest();
629 $pageurl = $title->getLocalURL();
630 wfProfileIn( __METHOD__
);
632 /* set up the default links for the personal toolbar */
633 $personal_urls = array();
635 # Due to bug 32276, if a user does not have read permissions,
636 # $this->getTitle() will just give Special:Badtitle, which is
637 # not especially useful as a returnto parameter. Use the title
638 # from the request instead, if there was one.
639 if ( $this->getUser()->isAllowed( 'read' ) ) {
640 $page = $this->getTitle();
642 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
644 $page = $request->getVal( 'returnto', $page );
646 if ( strval( $page ) !== '' ) {
647 $a['returnto'] = $page;
648 $query = $request->getVal( 'returntoquery', $this->thisquery
);
649 if ( $query != '' ) {
650 $a['returntoquery'] = $query;
654 $returnto = wfArrayToCgi( $a );
655 if ( $this->loggedin
) {
656 $personal_urls['userpage'] = array(
657 'text' => $this->username
,
658 'href' => &$this->userpageUrlDetails
['href'],
659 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
660 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
663 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
664 $personal_urls['mytalk'] = array(
665 'text' => $this->msg( 'mytalk' )->text(),
666 'href' => &$usertalkUrlDetails['href'],
667 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
668 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
670 $href = self
::makeSpecialUrl( 'Preferences' );
671 $personal_urls['preferences'] = array(
672 'text' => $this->msg( 'mypreferences' )->text(),
674 'active' => ( $href == $pageurl )
677 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
678 $href = self
::makeSpecialUrl( 'Watchlist' );
679 $personal_urls['watchlist'] = array(
680 'text' => $this->msg( 'mywatchlist' )->text(),
682 'active' => ( $href == $pageurl )
686 # We need to do an explicit check for Special:Contributions, as we
687 # have to match both the title, and the target, which could come
688 # from request values (Special:Contributions?target=Jimbo_Wales)
689 # or be specified in "sub page" form
690 # (Special:Contributions/Jimbo_Wales). The plot
691 # thickens, because the Title object is altered for special pages,
692 # so it doesn't contain the original alias-with-subpage.
693 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
694 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
695 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
696 $active = $spName == 'Contributions'
697 && ( ( $spPar && $spPar == $this->username
)
698 ||
$request->getText( 'target' ) == $this->username
);
703 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
704 $personal_urls['mycontris'] = array(
705 'text' => $this->msg( 'mycontris' )->text(),
709 $personal_urls['logout'] = array(
710 'text' => $this->msg( 'userlogout' )->text(),
711 'href' => self
::makeSpecialUrl( 'Userlogout',
712 // userlogout link must always contain an & character, otherwise we might not be able
713 // to detect a buggy precaching proxy (bug 17790)
714 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
719 $useCombinedLoginLink = $this->useCombinedLoginLink();
720 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
721 ?
'nav-login-createaccount'
723 $is_signup = $request->getText( 'type' ) == 'signup';
726 'text' => $this->msg( $loginlink )->text(),
727 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
728 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
730 $createaccount_url = array(
731 'text' => $this->msg( 'createaccount' )->text(),
732 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
733 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
736 if ( $this->showIPinHeader() ) {
737 $href = &$this->userpageUrlDetails
['href'];
738 $personal_urls['anonuserpage'] = array(
739 'text' => $this->username
,
741 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
742 'active' => ( $pageurl == $href )
744 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
745 $href = &$usertalkUrlDetails['href'];
746 $personal_urls['anontalk'] = array(
747 'text' => $this->msg( 'anontalk' )->text(),
749 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
750 'active' => ( $pageurl == $href )
754 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
755 $personal_urls['createaccount'] = $createaccount_url;
758 $personal_urls['login'] = $login_url;
761 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
762 wfProfileOut( __METHOD__
);
763 return $personal_urls;
767 * Builds an array with tab definition
769 * @param Title $title page where the tab links to
770 * @param string|array $message message key or an array of message keys (will fall back)
771 * @param boolean $selected display the tab as selected
772 * @param string $query query string attached to tab URL
773 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
777 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
780 $classes[] = 'selected';
782 if ( $checkEdit && !$title->isKnown() ) {
784 if ( $query !== '' ) {
785 $query = 'action=edit&redlink=1&' . $query;
787 $query = 'action=edit&redlink=1';
791 // wfMessageFallback will nicely accept $message as an array of fallbacks
792 // or just a single key
793 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
794 if ( is_array( $message ) ) {
795 // for hook compatibility just keep the last message name
796 $message = end( $message );
798 if ( $msg->exists() ) {
799 $text = $msg->text();
802 $text = $wgContLang->getFormattedNsText(
803 MWNamespace
::getSubject( $title->getNamespace() ) );
807 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
808 $title, $message, $selected, $checkEdit,
809 &$classes, &$query, &$text, &$result ) ) ) {
814 'class' => implode( ' ', $classes ),
816 'href' => $title->getLocalURL( $query ),
820 function makeTalkUrlDetails( $name, $urlaction = '' ) {
821 $title = Title
::newFromText( $name );
822 if ( !is_object( $title ) ) {
823 throw new MWException( __METHOD__
. " given invalid pagename $name" );
825 $title = $title->getTalkPage();
826 self
::checkTitle( $title, $name );
828 'href' => $title->getLocalURL( $urlaction ),
829 'exists' => $title->getArticleID() != 0,
833 function makeArticleUrlDetails( $name, $urlaction = '' ) {
834 $title = Title
::newFromText( $name );
835 $title = $title->getSubjectPage();
836 self
::checkTitle( $title, $name );
838 'href' => $title->getLocalURL( $urlaction ),
839 'exists' => $title->getArticleID() != 0,
844 * a structured array of links usually used for the tabs in a skin
846 * There are 4 standard sections
847 * namespaces: Used for namespace tabs like special, page, and talk namespaces
848 * views: Used for primary page views like read, edit, history
849 * actions: Used for most extra page actions like deletion, protection, etc...
850 * variants: Used to list the language variants for the page
852 * Each section's value is a key/value array of links for that section.
853 * The links themselves have these common keys:
854 * - class: The css classes to apply to the tab
855 * - text: The text to display on the tab
856 * - href: The href for the tab to point to
857 * - rel: An optional rel= for the tab's link
858 * - redundant: If true the tab will be dropped in skins using content_actions
859 * this is useful for tabs like "Read" which only have meaning in skins that
860 * take special meaning from the grouped structure of content_navigation
862 * Views also have an extra key which can be used:
863 * - primary: If this is not true skins like vector may try to hide the tab
864 * when the user has limited space in their browser window
866 * content_navigation using code also expects these ids to be present on the
867 * links, however these are usually automatically generated by SkinTemplate
868 * itself and are not necessary when using a hook. The only things these may
869 * matter to are people modifying content_navigation after it's initial creation:
870 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
871 * - tooltiponly: This is set to true for some tabs in cases where the system
872 * believes that the accesskey should not be added to the tab.
876 protected function buildContentNavigationUrls() {
877 global $wgDisableLangConversion;
879 wfProfileIn( __METHOD__
);
881 // Display tabs for the relevant title rather than always the title itself
882 $title = $this->getRelevantTitle();
883 $onPage = $title->equals( $this->getTitle() );
885 $out = $this->getOutput();
886 $request = $this->getRequest();
887 $user = $this->getUser();
889 $content_navigation = array(
890 'namespaces' => array(),
892 'actions' => array(),
893 'variants' => array()
897 $action = $request->getVal( 'action', 'view' );
899 $userCanRead = $title->quickUserCan( 'read', $user );
901 $preventActiveTabs = false;
902 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
904 // Checks if page is some kind of content
905 if ( $title->canExist() ) {
906 // Gets page objects for the related namespaces
907 $subjectPage = $title->getSubjectPage();
908 $talkPage = $title->getTalkPage();
910 // Determines if this is a talk page
911 $isTalk = $title->isTalkPage();
913 // Generates XML IDs from namespace names
914 $subjectId = $title->getNamespaceKey( '' );
916 if ( $subjectId == 'main' ) {
919 $talkId = "{$subjectId}_talk";
922 $skname = $this->skinname
;
924 // Adds namespace links
925 $subjectMsg = array( "nstab-$subjectId" );
926 if ( $subjectPage->isMainPage() ) {
927 array_unshift( $subjectMsg, 'mainpage-nstab' );
929 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
930 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
932 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
933 $content_navigation['namespaces'][$talkId] = $this->tabAction(
934 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
936 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
938 if ( $userCanRead ) {
939 // Adds view view link
940 if ( $title->exists() ) {
941 $content_navigation['views']['view'] = $this->tabAction(
942 $isTalk ?
$talkPage : $subjectPage,
943 array( "$skname-view-view", 'view' ),
944 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
946 // signal to hide this from simple content_actions
947 $content_navigation['views']['view']['redundant'] = true;
950 wfProfileIn( __METHOD__
. '-edit' );
952 // Checks if user can edit the current page if it exists or create it otherwise
953 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
954 // Builds CSS class for talk page links
955 $isTalkClass = $isTalk ?
' istalk' : '';
956 // Whether the user is editing the page
957 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
958 // Whether to show the "Add a new section" tab
959 // Checks if this is a current rev of talk page and is not forced to be hidden
960 $showNewSection = !$out->forceHideNewSectionLink()
961 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
962 $section = $request->getVal( 'section' );
964 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
966 $content_navigation['views']['edit'] = array(
967 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
968 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
969 'href' => $title->getLocalURL( $this->editUrlOptions() ),
970 'primary' => true, // don't collapse this in vector
974 if ( $showNewSection ) {
975 // Adds new section link
976 //$content_navigation['actions']['addsection']
977 $content_navigation['views']['addsection'] = array(
978 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
979 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
980 'href' => $title->getLocalURL( 'action=edit§ion=new' )
983 // Checks if the page has some kind of viewable content
984 } elseif ( $title->hasSourceText() ) {
985 // Adds view source view link
986 $content_navigation['views']['viewsource'] = array(
987 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
988 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
989 'href' => $title->getLocalURL( $this->editUrlOptions() ),
990 'primary' => true, // don't collapse this in vector
993 wfProfileOut( __METHOD__
. '-edit' );
995 wfProfileIn( __METHOD__
. '-live' );
996 // Checks if the page exists
997 if ( $title->exists() ) {
998 // Adds history view link
999 $content_navigation['views']['history'] = array(
1000 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1001 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
1002 'href' => $title->getLocalURL( 'action=history' ),
1003 'rel' => 'archives',
1006 if ( $title->quickUserCan( 'delete', $user ) ) {
1007 $content_navigation['actions']['delete'] = array(
1008 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1009 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
1010 'href' => $title->getLocalURL( 'action=delete' )
1014 if ( $title->quickUserCan( 'move', $user ) ) {
1015 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1016 $content_navigation['actions']['move'] = array(
1017 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1018 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
1019 'href' => $moveTitle->getLocalURL()
1023 // article doesn't exist or is deleted
1024 if ( $user->isAllowed( 'deletedhistory' ) ) {
1025 $n = $title->isDeleted();
1027 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1028 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1029 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1030 $content_navigation['actions']['undelete'] = array(
1031 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1032 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1033 ->setContext( $this->getContext() )->numParams( $n )->text(),
1034 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1040 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1041 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1043 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1044 $content_navigation['actions'][$mode] = array(
1045 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1046 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1047 'href' => $title->getLocalURL( "action=$mode" )
1051 wfProfileOut( __METHOD__
. '-live' );
1053 // Checks if the user is logged in
1054 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1056 * The following actions use messages which, if made particular to
1057 * the any specific skins, would break the Ajax code which makes this
1058 * action happen entirely inline. Skin::makeGlobalVariablesScript
1059 * defines a set of messages in a javascript object - and these
1060 * messages are assumed to be global for all skins. Without making
1061 * a change to that procedure these messages will have to remain as
1062 * the global versions.
1064 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1065 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1066 $content_navigation['actions'][$mode] = array(
1067 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1068 // uses 'watch' or 'unwatch' message
1069 'text' => $this->msg( $mode )->text(),
1070 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1075 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1077 if ( $userCanRead && !$wgDisableLangConversion ) {
1078 $pageLang = $title->getPageLanguage();
1079 // Gets list of language variants
1080 $variants = $pageLang->getVariants();
1081 // Checks that language conversion is enabled and variants exist
1082 // And if it is not in the special namespace
1083 if ( count( $variants ) > 1 ) {
1084 // Gets preferred variant (note that user preference is
1085 // only possible for wiki content language variant)
1086 $preferred = $pageLang->getPreferredVariant();
1087 if ( Action
::getActionName( $this ) === 'view' ) {
1088 $params = $request->getQueryValues();
1089 unset( $params['title'] );
1093 // Loops over each variant
1094 foreach ( $variants as $code ) {
1095 // Gets variant name from language code
1096 $varname = $pageLang->getVariantname( $code );
1097 // Appends variant link
1098 $content_navigation['variants'][] = array(
1099 'class' => ( $code == $preferred ) ?
'selected' : false,
1101 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1102 'lang' => wfBCP47( $code ),
1103 'hreflang' => wfBCP47( $code ),
1109 // If it's not content, it's got to be a special page
1110 $content_navigation['namespaces']['special'] = array(
1111 'class' => 'selected',
1112 'text' => $this->msg( 'nstab-special' )->text(),
1113 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1114 'context' => 'subject'
1117 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1118 array( &$this, &$content_navigation ) );
1121 // Equiv to SkinTemplateContentActions
1122 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1124 // Setup xml ids and tooltip info
1125 foreach ( $content_navigation as $section => &$links ) {
1126 foreach ( $links as $key => &$link ) {
1128 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1129 $xmlID = 'ca-nstab-' . $xmlID;
1130 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1132 } elseif ( $section == 'variants' ) {
1133 $xmlID = 'ca-varlang-' . $xmlID;
1135 $xmlID = 'ca-' . $xmlID;
1137 $link['id'] = $xmlID;
1141 # We don't want to give the watch tab an accesskey if the
1142 # page is being edited, because that conflicts with the
1143 # accesskey on the watch checkbox. We also don't want to
1144 # give the edit tab an accesskey, because that's fairly
1145 # superfluous and conflicts with an accesskey (Ctrl-E) often
1146 # used for editing in Safari.
1147 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1148 if ( isset( $content_navigation['views']['edit'] ) ) {
1149 $content_navigation['views']['edit']['tooltiponly'] = true;
1151 if ( isset( $content_navigation['actions']['watch'] ) ) {
1152 $content_navigation['actions']['watch']['tooltiponly'] = true;
1154 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1155 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1159 wfProfileOut( __METHOD__
);
1161 return $content_navigation;
1165 * an array of edit links by default used for the tabs
1169 function buildContentActionUrls( $content_navigation ) {
1171 wfProfileIn( __METHOD__
);
1173 // content_actions has been replaced with content_navigation for backwards
1174 // compatibility and also for skins that just want simple tabs content_actions
1175 // is now built by flattening the content_navigation arrays into one
1177 $content_actions = array();
1179 foreach ( $content_navigation as $links ) {
1181 foreach ( $links as $key => $value ) {
1183 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1184 // Redundant tabs are dropped from content_actions
1188 // content_actions used to have ids built using the "ca-$key" pattern
1189 // so the xmlID based id is much closer to the actual $key that we want
1190 // for that reason we'll just strip out the ca- if present and use
1191 // the latter potion of the "id" as the $key
1192 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1193 $key = substr( $value['id'], 3 );
1196 if ( isset( $content_actions[$key] ) ) {
1197 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1201 $content_actions[$key] = $value;
1207 wfProfileOut( __METHOD__
);
1209 return $content_actions;
1213 * build array of common navigation links
1217 protected function buildNavUrls() {
1218 global $wgUploadNavigationUrl;
1220 wfProfileIn( __METHOD__
);
1222 $out = $this->getOutput();
1223 $request = $this->getRequest();
1225 $nav_urls = array();
1226 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1227 if ( $wgUploadNavigationUrl ) {
1228 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1229 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1230 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1232 $nav_urls['upload'] = false;
1234 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1236 $nav_urls['print'] = false;
1237 $nav_urls['permalink'] = false;
1238 $nav_urls['info'] = false;
1239 $nav_urls['whatlinkshere'] = false;
1240 $nav_urls['recentchangeslinked'] = false;
1241 $nav_urls['contributions'] = false;
1242 $nav_urls['log'] = false;
1243 $nav_urls['blockip'] = false;
1244 $nav_urls['emailuser'] = false;
1245 $nav_urls['userrights'] = false;
1247 // A print stylesheet is attached to all pages, but nobody ever
1248 // figures that out. :) Add a link...
1249 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1250 $nav_urls['print'] = array(
1251 'text' => $this->msg( 'printableversion' )->text(),
1252 'href' => $this->getTitle()->getLocalURL(
1253 $request->appendQueryValue( 'printable', 'yes', true ) )
1257 if ( $out->isArticle() ) {
1258 // Also add a "permalink" while we're at it
1259 $revid = $this->getRevisionId();
1261 $nav_urls['permalink'] = array(
1262 'text' => $this->msg( 'permalink' )->text(),
1263 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1267 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1268 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1269 array( &$this, &$nav_urls, &$revid, &$revid ) );
1272 if ( $out->isArticleRelated() ) {
1273 $nav_urls['whatlinkshere'] = array(
1274 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1277 $nav_urls['info'] = array(
1278 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1279 'href' => $this->getTitle()->getLocalURL( "action=info" )
1282 if ( $this->getTitle()->getArticleID() ) {
1283 $nav_urls['recentchangeslinked'] = array(
1284 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1289 $user = $this->getRelevantUser();
1291 $rootUser = $user->getName();
1293 $nav_urls['contributions'] = array(
1294 'text' => $this->msg( 'contributions', $rootUser )->text(),
1295 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1298 $nav_urls['log'] = array(
1299 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1302 if ( $this->getUser()->isAllowed( 'block' ) ) {
1303 $nav_urls['blockip'] = array(
1304 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1308 if ( $this->showEmailUser( $user ) ) {
1309 $nav_urls['emailuser'] = array(
1310 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1314 if ( !$user->isAnon() ) {
1315 $sur = new UserrightsPage
;
1316 $sur->setContext( $this->getContext() );
1317 if ( $sur->userCanExecute( $this->getUser() ) ) {
1318 $nav_urls['userrights'] = array(
1319 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1325 wfProfileOut( __METHOD__
);
1330 * Generate strings used for xml 'id' names
1334 function getNameSpaceKey() {
1335 return $this->getTitle()->getNamespaceKey();
1340 * Generic wrapper for template functions, with interface
1341 * compatible with what we use of PHPTAL 0.7.
1344 abstract class QuickTemplate
{
1348 function __construct() {
1349 $this->data
= array();
1350 $this->translator
= new MediaWiki_I18N();
1354 * Sets the value $value to $name
1358 public function set( $name, $value ) {
1359 $this->data
[$name] = $value;
1363 * Gets the template data requested
1365 * @param string $name Key for the data
1366 * @param mixed $default Optional default (or null)
1367 * @return mixed The value of the data requested or the deafult
1369 public function get( $name, $default = null ) {
1370 if ( isset( $this->data
[$name] ) ) {
1371 return $this->data
[$name];
1381 public function setRef( $name, &$value ) {
1382 $this->data
[$name] =& $value;
1388 public function setTranslator( &$t ) {
1389 $this->translator
= &$t;
1393 * Main function, used by classes that subclass QuickTemplate
1394 * to show the actual HTML output
1396 abstract public function execute();
1401 function text( $str ) {
1402 echo htmlspecialchars( $this->data
[$str] );
1408 function html( $str ) {
1409 echo $this->data
[$str];
1415 function msg( $str ) {
1416 echo htmlspecialchars( $this->translator
->translate( $str ) );
1422 function msgHtml( $str ) {
1423 echo $this->translator
->translate( $str );
1427 * An ugly, ugly hack.
1430 function msgWiki( $str ) {
1433 $text = $this->translator
->translate( $str );
1434 echo $wgOut->parse( $text );
1441 function haveData( $str ) {
1442 return isset( $this->data
[$str] );
1450 function haveMsg( $str ) {
1451 $msg = $this->translator
->translate( $str );
1452 return ( $msg != '-' ) && ( $msg != '' ); # ????
1456 * Get the Skin object related to this object
1458 * @return Skin object
1460 public function getSkin() {
1461 return $this->data
['skin'];
1465 * Fetch the output of a QuickTemplate and return it
1470 public function getHTML() {
1473 $html = ob_get_contents();
1480 * New base template for a skin's template extended from QuickTemplate
1481 * this class features helper methods that provide common ways of interacting
1482 * with the data stored in the QuickTemplate
1484 abstract class BaseTemplate
extends QuickTemplate
{
1487 * Get a Message object with its context set
1489 * @param string $name message name
1492 public function getMsg( $name ) {
1493 return $this->getSkin()->msg( $name );
1496 function msg( $str ) {
1497 echo $this->getMsg( $str )->escaped();
1500 function msgHtml( $str ) {
1501 echo $this->getMsg( $str )->text();
1504 function msgWiki( $str ) {
1505 echo $this->getMsg( $str )->parseAsBlock();
1509 * Create an array of common toolbox items from the data in the quicktemplate
1510 * stored by SkinTemplate.
1511 * The resulting array is built according to a format intended to be passed
1512 * through makeListItem to generate the html.
1515 function getToolbox() {
1516 wfProfileIn( __METHOD__
);
1519 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1520 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1521 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1523 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1524 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1525 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1526 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1528 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1529 $toolbox['feeds']['id'] = 'feedlinks';
1530 $toolbox['feeds']['links'] = array();
1531 foreach ( $this->data
['feeds'] as $key => $feed ) {
1532 $toolbox['feeds']['links'][$key] = $feed;
1533 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1534 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1535 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1536 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1539 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1540 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1541 $toolbox[$special] = $this->data
['nav_urls'][$special];
1542 $toolbox[$special]['id'] = "t-$special";
1545 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1546 $toolbox['print'] = $this->data
['nav_urls']['print'];
1547 $toolbox['print']['id'] = 't-print';
1548 $toolbox['print']['rel'] = 'alternate';
1549 $toolbox['print']['msg'] = 'printableversion';
1551 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1552 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1553 if ( $toolbox['permalink']['href'] === '' ) {
1554 unset( $toolbox['permalink']['href'] );
1555 $toolbox['ispermalink']['tooltiponly'] = true;
1556 $toolbox['ispermalink']['id'] = 't-ispermalink';
1557 $toolbox['ispermalink']['msg'] = 'permalink';
1559 $toolbox['permalink']['id'] = 't-permalink';
1562 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1563 $toolbox['info'] = $this->data
['nav_urls']['info'];
1564 $toolbox['info']['id'] = 't-info';
1567 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1568 wfProfileOut( __METHOD__
);
1573 * Create an array of personal tools items from the data in the quicktemplate
1574 * stored by SkinTemplate.
1575 * The resulting array is built according to a format intended to be passed
1576 * through makeListItem to generate the html.
1577 * This is in reality the same list as already stored in personal_urls
1578 * however it is reformatted so that you can just pass the individual items
1579 * to makeListItem instead of hardcoding the element creation boilerplate.
1582 function getPersonalTools() {
1583 $personal_tools = array();
1584 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1585 # The class on a personal_urls item is meant to go on the <a> instead
1586 # of the <li> so we have to use a single item "links" array instead
1587 # of using most of the personal_url's keys directly.
1590 array( 'single-id' => "pt-$key" ),
1594 if ( isset( $plink['active'] ) ) {
1595 $ptool['active'] = $plink['active'];
1597 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1598 if ( isset( $plink[$k] ) ) {
1599 $ptool['links'][0][$k] = $plink[$k];
1602 $personal_tools[$key] = $ptool;
1604 return $personal_tools;
1607 function getSidebar( $options = array() ) {
1608 // Force the rendering of the following portals
1609 $sidebar = $this->data
['sidebar'];
1610 if ( !isset( $sidebar['SEARCH'] ) ) {
1611 $sidebar['SEARCH'] = true;
1613 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1614 $sidebar['TOOLBOX'] = true;
1616 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1617 $sidebar['LANGUAGES'] = true;
1620 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1621 unset( $sidebar['SEARCH'] );
1623 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1624 unset( $sidebar['TOOLBOX'] );
1626 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1627 unset( $sidebar['LANGUAGES'] );
1631 foreach ( $sidebar as $boxName => $content ) {
1632 if ( $content === false ) {
1635 switch ( $boxName ) {
1637 // Search is a special case, skins should custom implement this
1638 $boxes[$boxName] = array(
1640 'header' => $this->getMsg( 'search' )->text(),
1641 'generated' => false,
1646 $msgObj = $this->getMsg( 'toolbox' );
1647 $boxes[$boxName] = array(
1649 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1650 'generated' => false,
1651 'content' => $this->getToolbox(),
1655 if ( $this->data
['language_urls'] ) {
1656 $msgObj = $this->getMsg( 'otherlanguages' );
1657 $boxes[$boxName] = array(
1659 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1660 'generated' => false,
1661 'content' => $this->data
['language_urls'],
1666 $msgObj = $this->getMsg( $boxName );
1667 $boxes[$boxName] = array(
1668 'id' => "p-$boxName",
1669 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1670 'generated' => true,
1671 'content' => $content,
1677 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1678 $hookContents = null;
1679 if ( isset( $boxes['TOOLBOX'] ) ) {
1681 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1682 // can abort and avoid outputting double toolbox links
1683 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1684 $hookContents = ob_get_contents();
1686 if ( !trim( $hookContents ) ) {
1687 $hookContents = null;
1692 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1693 foreach ( $boxes as $boxName => $box ) {
1694 if ( is_array( $box['content'] ) ) {
1696 foreach ( $box['content'] as $key => $val ) {
1697 $content .= "\n " . $this->makeListItem( $key, $val );
1699 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1700 if ( $hookContents ) {
1701 $content .= "\n $hookContents";
1704 $content .= "\n</ul>\n";
1705 $boxes[$boxName]['content'] = $content;
1709 if ( $hookContents ) {
1710 $boxes['TOOLBOXEND'] = array(
1711 'id' => 'p-toolboxend',
1712 'header' => $boxes['TOOLBOX']['header'],
1713 'generated' => false,
1714 'content' => "<ul>{$hookContents}</ul>",
1716 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1718 foreach ( $boxes as $key => $box ) {
1719 if ( $key === 'TOOLBOXEND' ) {
1722 $boxes2[$key] = $box;
1723 if ( $key === 'TOOLBOX' ) {
1724 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1736 * Makes a link, usually used by makeListItem to generate a link for an item
1737 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1739 * @param string $key usually a key from the list you are generating this
1741 * @param array $item contains some of a specific set of keys.
1743 * The text of the link will be generated either from the contents of the
1744 * "text" key in the $item array, if a "msg" key is present a message by
1745 * that name will be used, and if neither of those are set the $key will be
1746 * used as a message name.
1748 * If a "href" key is not present makeLink will just output htmlescaped text.
1749 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1750 * for the link if present.
1752 * If an "id" or "single-id" (if you don't want the actual id to be output
1753 * on the link) is present it will be used to generate a tooltip and
1754 * accesskey for the link.
1756 * The keys "context" and "primary" are ignored; these keys are used
1757 * internally by skins and are not supposed to be included in the HTML
1760 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1762 * @param array $options can be used to affect the output of a link.
1763 * Possible options are:
1764 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1765 * a link in. This should be an array of arrays containing a 'tag' and
1766 * optionally an 'attributes' key. If you only have one element you don't
1767 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1768 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1770 * - 'link-class' key can be used to specify additional classes to apply
1772 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1773 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1774 * any non-link will output a "<span>" instead of just text.
1778 function makeLink( $key, $item, $options = array() ) {
1779 if ( isset( $item['text'] ) ) {
1780 $text = $item['text'];
1782 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1785 $html = htmlspecialchars( $text );
1787 if ( isset( $options['text-wrapper'] ) ) {
1788 $wrapper = $options['text-wrapper'];
1789 if ( isset( $wrapper['tag'] ) ) {
1790 $wrapper = array( $wrapper );
1792 while ( count( $wrapper ) > 0 ) {
1793 $element = array_pop( $wrapper );
1794 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1798 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1800 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1801 unset( $attrs[$k] );
1804 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1805 $item['single-id'] = $item['id'];
1807 if ( isset( $item['single-id'] ) ) {
1808 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1809 $title = Linker
::titleAttrib( $item['single-id'] );
1810 if ( $title !== false ) {
1811 $attrs['title'] = $title;
1814 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1815 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1816 $attrs['title'] = $tip['title'];
1818 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1819 $attrs['accesskey'] = $tip['accesskey'];
1823 if ( isset( $options['link-class'] ) ) {
1824 if ( isset( $attrs['class'] ) ) {
1825 $attrs['class'] .= " {$options['link-class']}";
1827 $attrs['class'] = $options['link-class'];
1830 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1837 * Generates a list item for a navigation, portlet, portal, sidebar... list
1839 * @param $key string, usually a key from the list you are generating this link from.
1840 * @param $item array, of list item data containing some of a specific set of keys.
1841 * The "id" and "class" keys will be used as attributes for the list item,
1842 * if "active" contains a value of true a "active" class will also be appended to class.
1844 * @param $options array
1846 * If you want something other than a "<li>" you can pass a tag name such as
1847 * "tag" => "span" in the $options array to change the tag used.
1848 * link/content data for the list item may come in one of two forms
1849 * A "links" key may be used, in which case it should contain an array with
1850 * a list of links to include inside the list item, see makeLink for the
1851 * format of individual links array items.
1853 * Otherwise the relevant keys from the list item $item array will be passed
1854 * to makeLink instead. Note however that "id" and "class" are used by the
1855 * list item directly so they will not be passed to makeLink
1856 * (however the link will still support a tooltip and accesskey from it)
1857 * If you need an id or class on a single link you should include a "links"
1858 * array with just one link item inside of it.
1859 * $options is also passed on to makeLink calls
1863 function makeListItem( $key, $item, $options = array() ) {
1864 if ( isset( $item['links'] ) ) {
1866 foreach ( $item['links'] as $linkKey => $link ) {
1867 $html .= $this->makeLink( $linkKey, $link, $options );
1871 // These keys are used by makeListItem and shouldn't be passed on to the link
1872 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1875 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1876 // The id goes on the <li> not on the <a> for single links
1877 // but makeSidebarLink still needs to know what id to use when
1878 // generating tooltips and accesskeys.
1879 $link['single-id'] = $item['id'];
1881 $html = $this->makeLink( $key, $link, $options );
1885 foreach ( array( 'id', 'class' ) as $attr ) {
1886 if ( isset( $item[$attr] ) ) {
1887 $attrs[$attr] = $item[$attr];
1890 if ( isset( $item['active'] ) && $item['active'] ) {
1891 if ( !isset( $attrs['class'] ) ) {
1892 $attrs['class'] = '';
1894 $attrs['class'] .= ' active';
1895 $attrs['class'] = trim( $attrs['class'] );
1897 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1900 function makeSearchInput( $attrs = array() ) {
1904 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1905 'value' => $this->get( 'search', '' ),
1907 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1908 return Html
::element( 'input', $realAttrs );
1911 function makeSearchButton( $mode, $attrs = array() ) {
1918 'value' => $this->translator
->translate(
1919 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1921 $realAttrs = array_merge(
1923 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1926 return Html
::element( 'input', $realAttrs );
1928 $buttonAttrs = array(
1932 $buttonAttrs = array_merge(
1934 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1937 unset( $buttonAttrs['src'] );
1938 unset( $buttonAttrs['alt'] );
1939 unset( $buttonAttrs['width'] );
1940 unset( $buttonAttrs['height'] );
1942 'src' => $attrs['src'],
1943 'alt' => isset( $attrs['alt'] )
1945 : $this->translator
->translate( 'searchbutton' ),
1946 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1947 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1949 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1951 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1956 * Returns an array of footerlinks trimmed down to only those footer links that
1958 * If you pass "flat" as an option then the returned array will be a flat array
1959 * of footer icons instead of a key/value array of footerlinks arrays broken
1960 * up into categories.
1961 * @return array|mixed
1963 function getFooterLinks( $option = null ) {
1964 $footerlinks = $this->get( 'footerlinks' );
1966 // Reduce footer links down to only those which are being used
1967 $validFooterLinks = array();
1968 foreach ( $footerlinks as $category => $links ) {
1969 $validFooterLinks[$category] = array();
1970 foreach ( $links as $link ) {
1971 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1972 $validFooterLinks[$category][] = $link;
1975 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1976 unset( $validFooterLinks[$category] );
1980 if ( $option == 'flat' ) {
1981 // fold footerlinks into a single array using a bit of trickery
1982 $validFooterLinks = call_user_func_array(
1984 array_values( $validFooterLinks )
1988 return $validFooterLinks;
1992 * Returns an array of footer icons filtered down by options relevant to how
1993 * the skin wishes to display them.
1994 * If you pass "icononly" as the option all footer icons which do not have an
1995 * image icon set will be filtered out.
1996 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1997 * in the list of footer icons. This is mostly useful for skins which only
1998 * display the text from footericons instead of the images and don't want a
1999 * duplicate copyright statement because footerlinks already rendered one.
2002 function getFooterIcons( $option = null ) {
2003 // Generate additional footer icons
2004 $footericons = $this->get( 'footericons' );
2006 if ( $option == 'icononly' ) {
2007 // Unset any icons which don't have an image
2008 foreach ( $footericons as &$footerIconsBlock ) {
2009 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2010 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2011 unset( $footerIconsBlock[$footerIconKey] );
2015 // Redo removal of any empty blocks
2016 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2017 if ( count( $footerIconsBlock ) <= 0 ) {
2018 unset( $footericons[$footerIconsKey] );
2021 } elseif ( $option == 'nocopyright' ) {
2022 unset( $footericons['copyright']['copyright'] );
2023 if ( count( $footericons['copyright'] ) <= 0 ) {
2024 unset( $footericons['copyright'] );
2028 return $footericons;
2032 * Output the basic end-page trail including bottomscripts, reporttime, and
2033 * debug stuff. This should be called right before outputting the closing
2034 * body and html tags.
2036 function printTrail() { ?
>
2037 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2038 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2039 <?php
$this->html( 'reporttime' ) ?
>