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(
108 'mediawiki.legacy.shared',
109 'mediawiki.legacy.commonPrint',
110 'mediawiki.ui.button'
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
119 * @param $classname String
120 * @param string $repository subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return QuickTemplate
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
130 * Generates array of language links for the current page
135 public function getLanguages() {
136 global $wgHideInterlanguageLinks;
137 if ( $wgHideInterlanguageLinks ) {
141 $userLang = $this->getLanguage();
142 $languageLinks = array();
144 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
145 $languageLinkParts = explode( ':', $languageLinkText, 2 );
146 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
147 unset( $languageLinkParts );
149 $languageLinkTitle = Title
::newFromText( $languageLinkText );
150 if ( $languageLinkTitle ) {
151 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
152 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
154 if ( strval( $ilLangName ) === '' ) {
155 $ilLangName = $languageLinkText;
157 $ilLangName = $this->formatLanguageName( $ilLangName );
160 // CLDR extension or similar is required to localize the language name;
161 // otherwise we'll end up with the autonym again.
162 $ilLangLocalName = Language
::fetchLanguageName(
167 $languageLinkTitleText = $languageLinkTitle->getText();
168 if ( $languageLinkTitleText === '' ) {
169 $ilTitle = wfMessage(
170 'interlanguage-link-title-langonly',
174 $ilTitle = wfMessage(
175 'interlanguage-link-title',
176 $languageLinkTitleText,
181 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
182 $languageLink = array(
183 'href' => $languageLinkTitle->getFullURL(),
184 'text' => $ilLangName,
187 'lang' => $ilInterwikiCodeBCP47,
188 'hreflang' => $ilInterwikiCodeBCP47,
190 wfRunHooks( 'SkinTemplateGetLanguageLink', array( &$languageLink, $languageLinkTitle, $this->getTitle() ) );
191 $languageLinks[] = $languageLink;
195 return $languageLinks;
198 protected function setupTemplateForOutput() {
199 wfProfileIn( __METHOD__
);
201 $request = $this->getRequest();
202 $user = $this->getUser();
203 $title = $this->getTitle();
205 wfProfileIn( __METHOD__
. '-init' );
206 $tpl = $this->setupTemplate( $this->template
, 'skins' );
207 wfProfileOut( __METHOD__
. '-init' );
209 wfProfileIn( __METHOD__
. '-stuff' );
210 $this->thispage
= $title->getPrefixedDBkey();
211 $this->titletxt
= $title->getPrefixedText();
212 $this->userpage
= $user->getUserPage()->getPrefixedText();
214 if ( !$request->wasPosted() ) {
215 $query = $request->getValues();
216 unset( $query['title'] );
217 unset( $query['returnto'] );
218 unset( $query['returntoquery'] );
220 $this->thisquery
= wfArrayToCgi( $query );
221 $this->loggedin
= $user->isLoggedIn();
222 $this->username
= $user->getName();
224 if ( $this->loggedin ||
$this->showIPinHeader() ) {
225 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
227 # This won't be used in the standard skins, but we define it to preserve the interface
228 # To save time, we check for existence
229 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
232 wfProfileOut( __METHOD__
. '-stuff' );
234 wfProfileOut( __METHOD__
);
240 * initialize various variables and generate the template
242 * @param $out OutputPage
244 function outputPage( OutputPage
$out = null ) {
245 wfProfileIn( __METHOD__
);
246 Profiler
::instance()->setTemplated( true );
249 if ( $out !== null ) {
250 // @todo Add wfDeprecated in 1.20
251 $oldContext = $this->getContext();
252 $this->setContext( $out->getContext() );
255 $out = $this->getOutput();
257 wfProfileIn( __METHOD__
. '-init' );
258 $this->initPage( $out );
259 wfProfileOut( __METHOD__
. '-init' );
260 $tpl = $this->prepareQuickTemplate( $out );
262 wfProfileIn( __METHOD__
. '-execute' );
263 $res = $tpl->execute();
264 wfProfileOut( __METHOD__
. '-execute' );
266 // result may be an error
267 $this->printOrError( $res );
270 $this->setContext( $oldContext );
273 wfProfileOut( __METHOD__
);
277 * initialize various variables and generate the template
280 * @return QuickTemplate the template to be executed by outputPage
282 protected function prepareQuickTemplate() {
283 global $wgContLang, $wgScript, $wgStylePath,
284 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
285 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
286 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
287 $wgScriptPath, $wgServer;
289 wfProfileIn( __METHOD__
);
291 $title = $this->getTitle();
292 $request = $this->getRequest();
293 $out = $this->getOutput();
294 $tpl = $this->setupTemplateForOutput();
296 wfProfileIn( __METHOD__
. '-stuff-head' );
297 if ( !$this->useHeadElement
) {
298 $tpl->set( 'pagecss', false );
299 $tpl->set( 'usercss', false );
301 $tpl->set( 'userjs', false );
302 $tpl->set( 'userjsprev', false );
304 $tpl->set( 'jsvarurl', false );
306 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
307 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
308 $tpl->set( 'html5version', $wgHtml5Version );
309 $tpl->set( 'headlinks', $out->getHeadLinks() );
310 $tpl->set( 'csslinks', $out->buildCssLinks() );
311 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
312 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
314 wfProfileOut( __METHOD__
. '-stuff-head' );
316 wfProfileIn( __METHOD__
. '-stuff2' );
317 $tpl->set( 'title', $out->getPageTitle() );
318 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
319 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
321 $tpl->setRef( 'thispage', $this->thispage
);
322 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
323 $tpl->set( 'titletext', $title->getText() );
324 $tpl->set( 'articleid', $title->getArticleID() );
326 $tpl->set( 'isarticle', $out->isArticle() );
328 $subpagestr = $this->subPageSubtitle();
329 if ( $subpagestr !== '' ) {
330 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
332 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
334 $undelete = $this->getUndeleteLink();
335 if ( $undelete === '' ) {
336 $tpl->set( 'undelete', '' );
338 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
341 $tpl->set( 'catlinks', $this->getCategories() );
342 if ( $out->isSyndicated() ) {
344 foreach ( $out->getSyndicationLinks() as $format => $link ) {
345 $feeds[$format] = array(
346 // Messages: feed-atom, feed-rss
347 'text' => $this->msg( "feed-$format" )->text(),
351 $tpl->setRef( 'feeds', $feeds );
353 $tpl->set( 'feeds', false );
356 $tpl->setRef( 'mimetype', $wgMimeType );
357 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
358 $tpl->set( 'charset', 'UTF-8' );
359 $tpl->setRef( 'wgScript', $wgScript );
360 $tpl->setRef( 'skinname', $this->skinname
);
361 $tpl->set( 'skinclass', get_class( $this ) );
362 $tpl->setRef( 'skin', $this );
363 $tpl->setRef( 'stylename', $this->stylename
);
364 $tpl->set( 'printable', $out->isPrintable() );
365 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
366 $tpl->setRef( 'loggedin', $this->loggedin
);
367 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
368 /* XXX currently unused, might get useful later
369 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
370 $tpl->set( 'exists', $title->getArticleID() != 0 );
371 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
372 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
373 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
375 $tpl->set( 'searchaction', $this->escapeSearchLink() );
376 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
377 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
378 $tpl->setRef( 'stylepath', $wgStylePath );
379 $tpl->setRef( 'articlepath', $wgArticlePath );
380 $tpl->setRef( 'scriptpath', $wgScriptPath );
381 $tpl->setRef( 'serverurl', $wgServer );
382 $tpl->setRef( 'logopath', $wgLogo );
383 $tpl->setRef( 'sitename', $wgSitename );
385 $userLang = $this->getLanguage();
386 $userLangCode = $userLang->getHtmlCode();
387 $userLangDir = $userLang->getDir();
389 $tpl->set( 'lang', $userLangCode );
390 $tpl->set( 'dir', $userLangDir );
391 $tpl->set( 'rtl', $userLang->isRTL() );
393 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
394 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
395 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
396 $tpl->setRef( 'userpage', $this->userpage
);
397 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
398 $tpl->set( 'userlang', $userLangCode );
400 // Users can have their language set differently than the
401 // content of the wiki. For these users, tell the web browser
402 // that interface elements are in a different language.
403 $tpl->set( 'userlangattributes', '' );
404 $tpl->set( 'specialpageattributes', '' ); # obsolete
406 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
407 $escUserlang = htmlspecialchars( $userLangCode );
408 $escUserdir = htmlspecialchars( $userLangDir );
409 // Attributes must be in double quotes because htmlspecialchars() doesn't
410 // escape single quotes
411 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
412 $tpl->set( 'userlangattributes', $attrs );
415 wfProfileOut( __METHOD__
. '-stuff2' );
417 wfProfileIn( __METHOD__
. '-stuff3' );
418 $tpl->set( 'newtalk', $this->getNewtalks() );
419 $tpl->set( 'logo', $this->logoText() );
421 $tpl->set( 'copyright', false );
422 $tpl->set( 'viewcount', false );
423 $tpl->set( 'lastmod', false );
424 $tpl->set( 'credits', false );
425 $tpl->set( 'numberofwatchingusers', false );
426 if ( $out->isArticle() && $title->exists() ) {
427 if ( $this->isRevisionCurrent() ) {
428 if ( !$wgDisableCounters ) {
429 $viewcount = $this->getWikiPage()->getCount();
431 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
435 if ( $wgPageShowWatchingUsers ) {
436 $dbr = wfGetDB( DB_SLAVE
);
437 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
438 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
442 $tpl->set( 'numberofwatchingusers',
443 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
448 if ( $wgMaxCredits != 0 ) {
449 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
450 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
452 $tpl->set( 'lastmod', $this->lastModified() );
455 $tpl->set( 'copyright', $this->getCopyright() );
457 wfProfileOut( __METHOD__
. '-stuff3' );
459 wfProfileIn( __METHOD__
. '-stuff4' );
460 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
461 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
462 $tpl->set( 'disclaimer', $this->disclaimerLink() );
463 $tpl->set( 'privacy', $this->privacyLink() );
464 $tpl->set( 'about', $this->aboutLink() );
466 $tpl->set( 'footerlinks', array(
470 'numberofwatchingusers',
481 global $wgFooterIcons;
482 $tpl->set( 'footericons', $wgFooterIcons );
483 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
484 if ( count( $footerIconsBlock ) > 0 ) {
485 foreach ( $footerIconsBlock as &$footerIcon ) {
486 if ( isset( $footerIcon['src'] ) ) {
487 if ( !isset( $footerIcon['width'] ) ) {
488 $footerIcon['width'] = 88;
490 if ( !isset( $footerIcon['height'] ) ) {
491 $footerIcon['height'] = 31;
496 unset( $tpl->data
['footericons'][$footerIconsKey] );
500 $tpl->set( 'sitenotice', $this->getSiteNotice() );
501 $tpl->set( 'bottomscripts', $this->bottomScripts() );
502 $tpl->set( 'printfooter', $this->printSource() );
504 # An ID that includes the actual body text; without categories, contentSub, ...
505 $realBodyAttribs = array( 'id' => 'mw-content-text' );
507 # Add a mw-content-ltr/rtl class to be able to style based on text direction
508 # when the content is different from the UI language, i.e.:
509 # not for special pages or file pages AND only when viewing AND if the page exists
510 # (or is in MW namespace, because that has default content)
511 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
512 Action
::getActionName( $this ) === 'view' &&
513 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
514 $pageLang = $title->getPageViewLanguage();
515 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
516 $realBodyAttribs['dir'] = $pageLang->getDir();
517 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
520 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
521 $tpl->setRef( 'bodytext', $out->mBodytext
);
523 $language_urls = $this->getLanguages();
524 if ( count( $language_urls ) ) {
525 $tpl->setRef( 'language_urls', $language_urls );
527 $tpl->set( 'language_urls', false );
529 wfProfileOut( __METHOD__
. '-stuff4' );
531 wfProfileIn( __METHOD__
. '-stuff5' );
533 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
534 $content_navigation = $this->buildContentNavigationUrls();
535 $content_actions = $this->buildContentActionUrls( $content_navigation );
536 $tpl->setRef( 'content_navigation', $content_navigation );
537 $tpl->setRef( 'content_actions', $content_actions );
539 $tpl->set( 'sidebar', $this->buildSidebar() );
540 $tpl->set( 'nav_urls', $this->buildNavUrls() );
542 // Set the head scripts near the end, in case the above actions resulted in added scripts
543 if ( $this->useHeadElement
) {
544 $tpl->set( 'headelement', $out->headElement( $this ) );
546 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
549 $tpl->set( 'debug', '' );
550 $tpl->set( 'debughtml', $this->generateDebugHTML() );
551 $tpl->set( 'reporttime', wfReportTime() );
553 // original version by hansm
554 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
555 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
558 // Set the bodytext to another key so that skins can just output it on it's own
559 // and output printfooter and debughtml separately
560 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
562 // Append printfooter and debughtml onto bodytext so that skins that were already
563 // using bodytext before they were split out don't suddenly start not outputting information
564 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
565 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
567 // allow extensions adding stuff after the page content.
568 // See Skin::afterContentHook() for further documentation.
569 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
570 wfProfileOut( __METHOD__
. '-stuff5' );
572 wfProfileOut( __METHOD__
);
577 * Get the HTML for the p-personal list
580 public function getPersonalToolsList() {
581 $tpl = $this->setupTemplateForOutput();
582 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
584 foreach ( $tpl->getPersonalTools() as $key => $item ) {
585 $html .= $tpl->makeListItem( $key, $item );
591 * Format language name for use in sidebar interlanguage links list.
592 * By default it is capitalized.
594 * @param string $name Language name, e.g. "English" or "español"
598 function formatLanguageName( $name ) {
599 return $this->getLanguage()->ucfirst( $name );
603 * Output the string, or print error message if it's
604 * an error object of the appropriate type.
605 * For the base class, assume strings all around.
610 function printOrError( $str ) {
615 * Output a boolean indicating if buildPersonalUrls should output separate
616 * login and create account links or output a combined link
617 * By default we simply return a global config setting that affects most skins
618 * This is setup as a method so that like with $wgLogo and getLogo() a skin
619 * can override this setting and always output one or the other if it has
620 * a reason it can't output one of the two modes.
623 function useCombinedLoginLink() {
624 global $wgUseCombinedLoginLink;
625 return $wgUseCombinedLoginLink;
629 * build array of urls for personal toolbar
632 protected function buildPersonalUrls() {
633 $title = $this->getTitle();
634 $request = $this->getRequest();
635 $pageurl = $title->getLocalURL();
636 wfProfileIn( __METHOD__
);
638 /* set up the default links for the personal toolbar */
639 $personal_urls = array();
641 # Due to bug 32276, if a user does not have read permissions,
642 # $this->getTitle() will just give Special:Badtitle, which is
643 # not especially useful as a returnto parameter. Use the title
644 # from the request instead, if there was one.
645 if ( $this->getUser()->isAllowed( 'read' ) ) {
646 $page = $this->getTitle();
648 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
650 $page = $request->getVal( 'returnto', $page );
652 if ( strval( $page ) !== '' ) {
653 $a['returnto'] = $page;
654 $query = $request->getVal( 'returntoquery', $this->thisquery
);
655 if ( $query != '' ) {
656 $a['returntoquery'] = $query;
660 $returnto = wfArrayToCgi( $a );
661 if ( $this->loggedin
) {
662 $personal_urls['userpage'] = array(
663 'text' => $this->username
,
664 'href' => &$this->userpageUrlDetails
['href'],
665 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
666 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
669 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
670 $personal_urls['mytalk'] = array(
671 'text' => $this->msg( 'mytalk' )->text(),
672 'href' => &$usertalkUrlDetails['href'],
673 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
674 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
676 $href = self
::makeSpecialUrl( 'Preferences' );
677 $personal_urls['preferences'] = array(
678 'text' => $this->msg( 'mypreferences' )->text(),
680 'active' => ( $href == $pageurl )
683 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
684 $href = self
::makeSpecialUrl( 'Watchlist' );
685 $personal_urls['watchlist'] = array(
686 'text' => $this->msg( 'mywatchlist' )->text(),
688 'active' => ( $href == $pageurl )
692 # We need to do an explicit check for Special:Contributions, as we
693 # have to match both the title, and the target, which could come
694 # from request values (Special:Contributions?target=Jimbo_Wales)
695 # or be specified in "sub page" form
696 # (Special:Contributions/Jimbo_Wales). The plot
697 # thickens, because the Title object is altered for special pages,
698 # so it doesn't contain the original alias-with-subpage.
699 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
700 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
701 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
702 $active = $spName == 'Contributions'
703 && ( ( $spPar && $spPar == $this->username
)
704 ||
$request->getText( 'target' ) == $this->username
);
709 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
710 $personal_urls['mycontris'] = array(
711 'text' => $this->msg( 'mycontris' )->text(),
715 $personal_urls['logout'] = array(
716 'text' => $this->msg( 'pt-userlogout' )->text(),
717 'href' => self
::makeSpecialUrl( 'Userlogout',
718 // userlogout link must always contain an & character, otherwise we might not be able
719 // to detect a buggy precaching proxy (bug 17790)
720 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
725 $useCombinedLoginLink = $this->useCombinedLoginLink();
726 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
727 ?
'nav-login-createaccount'
729 $is_signup = $request->getText( 'type' ) == 'signup';
732 'text' => $this->msg( $loginlink )->text(),
733 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
734 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
736 $createaccount_url = array(
737 'text' => $this->msg( 'pt-createaccount' )->text(),
738 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
739 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
742 if ( $this->showIPinHeader() ) {
743 $href = &$this->userpageUrlDetails
['href'];
744 $personal_urls['anonuserpage'] = array(
745 'text' => $this->username
,
747 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
748 'active' => ( $pageurl == $href )
750 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
751 $href = &$usertalkUrlDetails['href'];
752 $personal_urls['anontalk'] = array(
753 'text' => $this->msg( 'anontalk' )->text(),
755 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
756 'active' => ( $pageurl == $href )
760 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
761 $personal_urls['createaccount'] = $createaccount_url;
764 $personal_urls['login'] = $login_url;
767 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
768 wfProfileOut( __METHOD__
);
769 return $personal_urls;
773 * Builds an array with tab definition
775 * @param Title $title page where the tab links to
776 * @param string|array $message message key or an array of message keys (will fall back)
777 * @param boolean $selected display the tab as selected
778 * @param string $query query string attached to tab URL
779 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
783 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
786 $classes[] = 'selected';
788 if ( $checkEdit && !$title->isKnown() ) {
790 if ( $query !== '' ) {
791 $query = 'action=edit&redlink=1&' . $query;
793 $query = 'action=edit&redlink=1';
797 // wfMessageFallback will nicely accept $message as an array of fallbacks
798 // or just a single key
799 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
800 if ( is_array( $message ) ) {
801 // for hook compatibility just keep the last message name
802 $message = end( $message );
804 if ( $msg->exists() ) {
805 $text = $msg->text();
808 $text = $wgContLang->getFormattedNsText(
809 MWNamespace
::getSubject( $title->getNamespace() ) );
813 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
814 $title, $message, $selected, $checkEdit,
815 &$classes, &$query, &$text, &$result ) ) ) {
820 'class' => implode( ' ', $classes ),
822 'href' => $title->getLocalURL( $query ),
826 function makeTalkUrlDetails( $name, $urlaction = '' ) {
827 $title = Title
::newFromText( $name );
828 if ( !is_object( $title ) ) {
829 throw new MWException( __METHOD__
. " given invalid pagename $name" );
831 $title = $title->getTalkPage();
832 self
::checkTitle( $title, $name );
834 'href' => $title->getLocalURL( $urlaction ),
835 'exists' => $title->getArticleID() != 0,
839 function makeArticleUrlDetails( $name, $urlaction = '' ) {
840 $title = Title
::newFromText( $name );
841 $title = $title->getSubjectPage();
842 self
::checkTitle( $title, $name );
844 'href' => $title->getLocalURL( $urlaction ),
845 'exists' => $title->getArticleID() != 0,
850 * a structured array of links usually used for the tabs in a skin
852 * There are 4 standard sections
853 * namespaces: Used for namespace tabs like special, page, and talk namespaces
854 * views: Used for primary page views like read, edit, history
855 * actions: Used for most extra page actions like deletion, protection, etc...
856 * variants: Used to list the language variants for the page
858 * Each section's value is a key/value array of links for that section.
859 * The links themselves have these common keys:
860 * - class: The css classes to apply to the tab
861 * - text: The text to display on the tab
862 * - href: The href for the tab to point to
863 * - rel: An optional rel= for the tab's link
864 * - redundant: If true the tab will be dropped in skins using content_actions
865 * this is useful for tabs like "Read" which only have meaning in skins that
866 * take special meaning from the grouped structure of content_navigation
868 * Views also have an extra key which can be used:
869 * - primary: If this is not true skins like vector may try to hide the tab
870 * when the user has limited space in their browser window
872 * content_navigation using code also expects these ids to be present on the
873 * links, however these are usually automatically generated by SkinTemplate
874 * itself and are not necessary when using a hook. The only things these may
875 * matter to are people modifying content_navigation after it's initial creation:
876 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
877 * - tooltiponly: This is set to true for some tabs in cases where the system
878 * believes that the accesskey should not be added to the tab.
882 protected function buildContentNavigationUrls() {
883 global $wgDisableLangConversion;
885 wfProfileIn( __METHOD__
);
887 // Display tabs for the relevant title rather than always the title itself
888 $title = $this->getRelevantTitle();
889 $onPage = $title->equals( $this->getTitle() );
891 $out = $this->getOutput();
892 $request = $this->getRequest();
893 $user = $this->getUser();
895 $content_navigation = array(
896 'namespaces' => array(),
898 'actions' => array(),
899 'variants' => array()
903 $action = $request->getVal( 'action', 'view' );
905 $userCanRead = $title->quickUserCan( 'read', $user );
907 $preventActiveTabs = false;
908 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
910 // Checks if page is some kind of content
911 if ( $title->canExist() ) {
912 // Gets page objects for the related namespaces
913 $subjectPage = $title->getSubjectPage();
914 $talkPage = $title->getTalkPage();
916 // Determines if this is a talk page
917 $isTalk = $title->isTalkPage();
919 // Generates XML IDs from namespace names
920 $subjectId = $title->getNamespaceKey( '' );
922 if ( $subjectId == 'main' ) {
925 $talkId = "{$subjectId}_talk";
928 $skname = $this->skinname
;
930 // Adds namespace links
931 $subjectMsg = array( "nstab-$subjectId" );
932 if ( $subjectPage->isMainPage() ) {
933 array_unshift( $subjectMsg, 'mainpage-nstab' );
935 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
936 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
938 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
939 $content_navigation['namespaces'][$talkId] = $this->tabAction(
940 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
942 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
944 if ( $userCanRead ) {
945 // Adds view view link
946 if ( $title->exists() ) {
947 $content_navigation['views']['view'] = $this->tabAction(
948 $isTalk ?
$talkPage : $subjectPage,
949 array( "$skname-view-view", 'view' ),
950 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
952 // signal to hide this from simple content_actions
953 $content_navigation['views']['view']['redundant'] = true;
956 wfProfileIn( __METHOD__
. '-edit' );
958 // Checks if user can edit the current page if it exists or create it otherwise
959 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
960 // Builds CSS class for talk page links
961 $isTalkClass = $isTalk ?
' istalk' : '';
962 // Whether the user is editing the page
963 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
964 // Whether to show the "Add a new section" tab
965 // Checks if this is a current rev of talk page and is not forced to be hidden
966 $showNewSection = !$out->forceHideNewSectionLink()
967 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
968 $section = $request->getVal( 'section' );
970 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
972 $content_navigation['views']['edit'] = array(
973 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
974 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
975 'href' => $title->getLocalURL( $this->editUrlOptions() ),
976 'primary' => true, // don't collapse this in vector
980 if ( $showNewSection ) {
981 // Adds new section link
982 //$content_navigation['actions']['addsection']
983 $content_navigation['views']['addsection'] = array(
984 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
985 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
986 'href' => $title->getLocalURL( 'action=edit§ion=new' )
989 // Checks if the page has some kind of viewable content
990 } elseif ( $title->hasSourceText() ) {
991 // Adds view source view link
992 $content_navigation['views']['viewsource'] = array(
993 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
994 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
995 'href' => $title->getLocalURL( $this->editUrlOptions() ),
996 'primary' => true, // don't collapse this in vector
999 wfProfileOut( __METHOD__
. '-edit' );
1001 wfProfileIn( __METHOD__
. '-live' );
1002 // Checks if the page exists
1003 if ( $title->exists() ) {
1004 // Adds history view link
1005 $content_navigation['views']['history'] = array(
1006 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1007 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
1008 'href' => $title->getLocalURL( 'action=history' ),
1009 'rel' => 'archives',
1012 if ( $title->quickUserCan( 'delete', $user ) ) {
1013 $content_navigation['actions']['delete'] = array(
1014 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1015 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
1016 'href' => $title->getLocalURL( 'action=delete' )
1020 if ( $title->quickUserCan( 'move', $user ) ) {
1021 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1022 $content_navigation['actions']['move'] = array(
1023 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1024 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
1025 'href' => $moveTitle->getLocalURL()
1029 // article doesn't exist or is deleted
1030 if ( $user->isAllowed( 'deletedhistory' ) ) {
1031 $n = $title->isDeleted();
1033 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1034 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1035 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1036 $content_navigation['actions']['undelete'] = array(
1037 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1038 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1039 ->setContext( $this->getContext() )->numParams( $n )->text(),
1040 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1046 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1047 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1049 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1050 $content_navigation['actions'][$mode] = array(
1051 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1052 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1053 'href' => $title->getLocalURL( "action=$mode" )
1057 wfProfileOut( __METHOD__
. '-live' );
1059 // Checks if the user is logged in
1060 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1062 * The following actions use messages which, if made particular to
1063 * the any specific skins, would break the Ajax code which makes this
1064 * action happen entirely inline. Skin::makeGlobalVariablesScript
1065 * defines a set of messages in a javascript object - and these
1066 * messages are assumed to be global for all skins. Without making
1067 * a change to that procedure these messages will have to remain as
1068 * the global versions.
1070 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1071 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1072 $content_navigation['actions'][$mode] = array(
1073 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1074 // uses 'watch' or 'unwatch' message
1075 'text' => $this->msg( $mode )->text(),
1076 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1081 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1083 if ( $userCanRead && !$wgDisableLangConversion ) {
1084 $pageLang = $title->getPageLanguage();
1085 // Gets list of language variants
1086 $variants = $pageLang->getVariants();
1087 // Checks that language conversion is enabled and variants exist
1088 // And if it is not in the special namespace
1089 if ( count( $variants ) > 1 ) {
1090 // Gets preferred variant (note that user preference is
1091 // only possible for wiki content language variant)
1092 $preferred = $pageLang->getPreferredVariant();
1093 if ( Action
::getActionName( $this ) === 'view' ) {
1094 $params = $request->getQueryValues();
1095 unset( $params['title'] );
1099 // Loops over each variant
1100 foreach ( $variants as $code ) {
1101 // Gets variant name from language code
1102 $varname = $pageLang->getVariantname( $code );
1103 // Appends variant link
1104 $content_navigation['variants'][] = array(
1105 'class' => ( $code == $preferred ) ?
'selected' : false,
1107 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1108 'lang' => wfBCP47( $code ),
1109 'hreflang' => wfBCP47( $code ),
1115 // If it's not content, it's got to be a special page
1116 $content_navigation['namespaces']['special'] = array(
1117 'class' => 'selected',
1118 'text' => $this->msg( 'nstab-special' )->text(),
1119 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1120 'context' => 'subject'
1123 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1124 array( &$this, &$content_navigation ) );
1127 // Equiv to SkinTemplateContentActions
1128 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1130 // Setup xml ids and tooltip info
1131 foreach ( $content_navigation as $section => &$links ) {
1132 foreach ( $links as $key => &$link ) {
1134 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1135 $xmlID = 'ca-nstab-' . $xmlID;
1136 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1138 } elseif ( $section == 'variants' ) {
1139 $xmlID = 'ca-varlang-' . $xmlID;
1141 $xmlID = 'ca-' . $xmlID;
1143 $link['id'] = $xmlID;
1147 # We don't want to give the watch tab an accesskey if the
1148 # page is being edited, because that conflicts with the
1149 # accesskey on the watch checkbox. We also don't want to
1150 # give the edit tab an accesskey, because that's fairly
1151 # superfluous and conflicts with an accesskey (Ctrl-E) often
1152 # used for editing in Safari.
1153 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1154 if ( isset( $content_navigation['views']['edit'] ) ) {
1155 $content_navigation['views']['edit']['tooltiponly'] = true;
1157 if ( isset( $content_navigation['actions']['watch'] ) ) {
1158 $content_navigation['actions']['watch']['tooltiponly'] = true;
1160 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1161 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1165 wfProfileOut( __METHOD__
);
1167 return $content_navigation;
1171 * an array of edit links by default used for the tabs
1175 function buildContentActionUrls( $content_navigation ) {
1177 wfProfileIn( __METHOD__
);
1179 // content_actions has been replaced with content_navigation for backwards
1180 // compatibility and also for skins that just want simple tabs content_actions
1181 // is now built by flattening the content_navigation arrays into one
1183 $content_actions = array();
1185 foreach ( $content_navigation as $links ) {
1187 foreach ( $links as $key => $value ) {
1189 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1190 // Redundant tabs are dropped from content_actions
1194 // content_actions used to have ids built using the "ca-$key" pattern
1195 // so the xmlID based id is much closer to the actual $key that we want
1196 // for that reason we'll just strip out the ca- if present and use
1197 // the latter potion of the "id" as the $key
1198 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1199 $key = substr( $value['id'], 3 );
1202 if ( isset( $content_actions[$key] ) ) {
1203 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1207 $content_actions[$key] = $value;
1213 wfProfileOut( __METHOD__
);
1215 return $content_actions;
1219 * build array of common navigation links
1223 protected function buildNavUrls() {
1224 global $wgUploadNavigationUrl;
1226 wfProfileIn( __METHOD__
);
1228 $out = $this->getOutput();
1229 $request = $this->getRequest();
1231 $nav_urls = array();
1232 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1233 if ( $wgUploadNavigationUrl ) {
1234 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1235 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1236 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1238 $nav_urls['upload'] = false;
1240 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1242 $nav_urls['print'] = false;
1243 $nav_urls['permalink'] = false;
1244 $nav_urls['info'] = false;
1245 $nav_urls['whatlinkshere'] = false;
1246 $nav_urls['recentchangeslinked'] = false;
1247 $nav_urls['contributions'] = false;
1248 $nav_urls['log'] = false;
1249 $nav_urls['blockip'] = false;
1250 $nav_urls['emailuser'] = false;
1251 $nav_urls['userrights'] = false;
1253 // A print stylesheet is attached to all pages, but nobody ever
1254 // figures that out. :) Add a link...
1255 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1256 $nav_urls['print'] = array(
1257 'text' => $this->msg( 'printableversion' )->text(),
1258 'href' => $this->getTitle()->getLocalURL(
1259 $request->appendQueryValue( 'printable', 'yes', true ) )
1263 if ( $out->isArticle() ) {
1264 // Also add a "permalink" while we're at it
1265 $revid = $this->getRevisionId();
1267 $nav_urls['permalink'] = array(
1268 'text' => $this->msg( 'permalink' )->text(),
1269 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1273 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1274 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1275 array( &$this, &$nav_urls, &$revid, &$revid ) );
1278 if ( $out->isArticleRelated() ) {
1279 $nav_urls['whatlinkshere'] = array(
1280 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1283 $nav_urls['info'] = array(
1284 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1285 'href' => $this->getTitle()->getLocalURL( "action=info" )
1288 if ( $this->getTitle()->getArticleID() ) {
1289 $nav_urls['recentchangeslinked'] = array(
1290 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1295 $user = $this->getRelevantUser();
1297 $rootUser = $user->getName();
1299 $nav_urls['contributions'] = array(
1300 'text' => $this->msg( 'contributions', $rootUser )->text(),
1301 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1304 $nav_urls['log'] = array(
1305 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1308 if ( $this->getUser()->isAllowed( 'block' ) ) {
1309 $nav_urls['blockip'] = array(
1310 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1314 if ( $this->showEmailUser( $user ) ) {
1315 $nav_urls['emailuser'] = array(
1316 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1320 if ( !$user->isAnon() ) {
1321 $sur = new UserrightsPage
;
1322 $sur->setContext( $this->getContext() );
1323 if ( $sur->userCanExecute( $this->getUser() ) ) {
1324 $nav_urls['userrights'] = array(
1325 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1331 wfProfileOut( __METHOD__
);
1336 * Generate strings used for xml 'id' names
1340 function getNameSpaceKey() {
1341 return $this->getTitle()->getNamespaceKey();
1346 * Generic wrapper for template functions, with interface
1347 * compatible with what we use of PHPTAL 0.7.
1350 abstract class QuickTemplate
{
1354 function __construct() {
1355 $this->data
= array();
1356 $this->translator
= new MediaWiki_I18N();
1360 * Sets the value $value to $name
1364 public function set( $name, $value ) {
1365 $this->data
[$name] = $value;
1369 * Gets the template data requested
1371 * @param string $name Key for the data
1372 * @param mixed $default Optional default (or null)
1373 * @return mixed The value of the data requested or the deafult
1375 public function get( $name, $default = null ) {
1376 if ( isset( $this->data
[$name] ) ) {
1377 return $this->data
[$name];
1387 public function setRef( $name, &$value ) {
1388 $this->data
[$name] =& $value;
1394 public function setTranslator( &$t ) {
1395 $this->translator
= &$t;
1399 * Main function, used by classes that subclass QuickTemplate
1400 * to show the actual HTML output
1402 abstract public function execute();
1407 function text( $str ) {
1408 echo htmlspecialchars( $this->data
[$str] );
1414 function html( $str ) {
1415 echo $this->data
[$str];
1421 function msg( $str ) {
1422 echo htmlspecialchars( $this->translator
->translate( $str ) );
1428 function msgHtml( $str ) {
1429 echo $this->translator
->translate( $str );
1433 * An ugly, ugly hack.
1436 function msgWiki( $str ) {
1439 $text = $this->translator
->translate( $str );
1440 echo $wgOut->parse( $text );
1447 function haveData( $str ) {
1448 return isset( $this->data
[$str] );
1456 function haveMsg( $str ) {
1457 $msg = $this->translator
->translate( $str );
1458 return ( $msg != '-' ) && ( $msg != '' ); # ????
1462 * Get the Skin object related to this object
1464 * @return Skin object
1466 public function getSkin() {
1467 return $this->data
['skin'];
1471 * Fetch the output of a QuickTemplate and return it
1476 public function getHTML() {
1479 $html = ob_get_contents();
1486 * New base template for a skin's template extended from QuickTemplate
1487 * this class features helper methods that provide common ways of interacting
1488 * with the data stored in the QuickTemplate
1490 abstract class BaseTemplate
extends QuickTemplate
{
1493 * Get a Message object with its context set
1495 * @param string $name message name
1498 public function getMsg( $name ) {
1499 return $this->getSkin()->msg( $name );
1502 function msg( $str ) {
1503 echo $this->getMsg( $str )->escaped();
1506 function msgHtml( $str ) {
1507 echo $this->getMsg( $str )->text();
1510 function msgWiki( $str ) {
1511 echo $this->getMsg( $str )->parseAsBlock();
1515 * Create an array of common toolbox items from the data in the quicktemplate
1516 * stored by SkinTemplate.
1517 * The resulting array is built according to a format intended to be passed
1518 * through makeListItem to generate the html.
1521 function getToolbox() {
1522 wfProfileIn( __METHOD__
);
1525 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1526 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1527 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1529 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1530 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1531 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1532 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1534 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1535 $toolbox['feeds']['id'] = 'feedlinks';
1536 $toolbox['feeds']['links'] = array();
1537 foreach ( $this->data
['feeds'] as $key => $feed ) {
1538 $toolbox['feeds']['links'][$key] = $feed;
1539 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1540 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1541 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1542 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1545 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1546 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1547 $toolbox[$special] = $this->data
['nav_urls'][$special];
1548 $toolbox[$special]['id'] = "t-$special";
1551 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1552 $toolbox['print'] = $this->data
['nav_urls']['print'];
1553 $toolbox['print']['id'] = 't-print';
1554 $toolbox['print']['rel'] = 'alternate';
1555 $toolbox['print']['msg'] = 'printableversion';
1557 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1558 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1559 if ( $toolbox['permalink']['href'] === '' ) {
1560 unset( $toolbox['permalink']['href'] );
1561 $toolbox['ispermalink']['tooltiponly'] = true;
1562 $toolbox['ispermalink']['id'] = 't-ispermalink';
1563 $toolbox['ispermalink']['msg'] = 'permalink';
1565 $toolbox['permalink']['id'] = 't-permalink';
1568 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1569 $toolbox['info'] = $this->data
['nav_urls']['info'];
1570 $toolbox['info']['id'] = 't-info';
1573 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1574 wfProfileOut( __METHOD__
);
1579 * Create an array of personal tools items from the data in the quicktemplate
1580 * stored by SkinTemplate.
1581 * The resulting array is built according to a format intended to be passed
1582 * through makeListItem to generate the html.
1583 * This is in reality the same list as already stored in personal_urls
1584 * however it is reformatted so that you can just pass the individual items
1585 * to makeListItem instead of hardcoding the element creation boilerplate.
1588 function getPersonalTools() {
1589 $personal_tools = array();
1590 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1591 # The class on a personal_urls item is meant to go on the <a> instead
1592 # of the <li> so we have to use a single item "links" array instead
1593 # of using most of the personal_url's keys directly.
1596 array( 'single-id' => "pt-$key" ),
1600 if ( isset( $plink['active'] ) ) {
1601 $ptool['active'] = $plink['active'];
1603 foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) {
1604 if ( isset( $plink[$k] ) ) {
1605 $ptool['links'][0][$k] = $plink[$k];
1608 $personal_tools[$key] = $ptool;
1610 return $personal_tools;
1613 function getSidebar( $options = array() ) {
1614 // Force the rendering of the following portals
1615 $sidebar = $this->data
['sidebar'];
1616 if ( !isset( $sidebar['SEARCH'] ) ) {
1617 $sidebar['SEARCH'] = true;
1619 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1620 $sidebar['TOOLBOX'] = true;
1622 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1623 $sidebar['LANGUAGES'] = true;
1626 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1627 unset( $sidebar['SEARCH'] );
1629 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1630 unset( $sidebar['TOOLBOX'] );
1632 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1633 unset( $sidebar['LANGUAGES'] );
1637 foreach ( $sidebar as $boxName => $content ) {
1638 if ( $content === false ) {
1641 switch ( $boxName ) {
1643 // Search is a special case, skins should custom implement this
1644 $boxes[$boxName] = array(
1646 'header' => $this->getMsg( 'search' )->text(),
1647 'generated' => false,
1652 $msgObj = $this->getMsg( 'toolbox' );
1653 $boxes[$boxName] = array(
1655 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1656 'generated' => false,
1657 'content' => $this->getToolbox(),
1661 if ( $this->data
['language_urls'] ) {
1662 $msgObj = $this->getMsg( 'otherlanguages' );
1663 $boxes[$boxName] = array(
1665 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1666 'generated' => false,
1667 'content' => $this->data
['language_urls'],
1672 $msgObj = $this->getMsg( $boxName );
1673 $boxes[$boxName] = array(
1674 'id' => "p-$boxName",
1675 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1676 'generated' => true,
1677 'content' => $content,
1683 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1684 $hookContents = null;
1685 if ( isset( $boxes['TOOLBOX'] ) ) {
1687 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1688 // can abort and avoid outputting double toolbox links
1689 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1690 $hookContents = ob_get_contents();
1692 if ( !trim( $hookContents ) ) {
1693 $hookContents = null;
1698 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1699 foreach ( $boxes as $boxName => $box ) {
1700 if ( is_array( $box['content'] ) ) {
1702 foreach ( $box['content'] as $key => $val ) {
1703 $content .= "\n " . $this->makeListItem( $key, $val );
1705 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1706 if ( $hookContents ) {
1707 $content .= "\n $hookContents";
1710 $content .= "\n</ul>\n";
1711 $boxes[$boxName]['content'] = $content;
1715 if ( $hookContents ) {
1716 $boxes['TOOLBOXEND'] = array(
1717 'id' => 'p-toolboxend',
1718 'header' => $boxes['TOOLBOX']['header'],
1719 'generated' => false,
1720 'content' => "<ul>{$hookContents}</ul>",
1722 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1724 foreach ( $boxes as $key => $box ) {
1725 if ( $key === 'TOOLBOXEND' ) {
1728 $boxes2[$key] = $box;
1729 if ( $key === 'TOOLBOX' ) {
1730 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1742 * Makes a link, usually used by makeListItem to generate a link for an item
1743 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1745 * @param string $key usually a key from the list you are generating this
1747 * @param array $item contains some of a specific set of keys.
1749 * The text of the link will be generated either from the contents of the
1750 * "text" key in the $item array, if a "msg" key is present a message by
1751 * that name will be used, and if neither of those are set the $key will be
1752 * used as a message name.
1754 * If a "href" key is not present makeLink will just output htmlescaped text.
1755 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1756 * for the link if present.
1758 * If an "id" or "single-id" (if you don't want the actual id to be output
1759 * on the link) is present it will be used to generate a tooltip and
1760 * accesskey for the link.
1762 * The keys "context" and "primary" are ignored; these keys are used
1763 * internally by skins and are not supposed to be included in the HTML
1766 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1768 * @param array $options can be used to affect the output of a link.
1769 * Possible options are:
1770 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1771 * a link in. This should be an array of arrays containing a 'tag' and
1772 * optionally an 'attributes' key. If you only have one element you don't
1773 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1774 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1776 * - 'link-class' key can be used to specify additional classes to apply
1778 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1779 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1780 * any non-link will output a "<span>" instead of just text.
1784 function makeLink( $key, $item, $options = array() ) {
1785 if ( isset( $item['text'] ) ) {
1786 $text = $item['text'];
1788 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1791 $html = htmlspecialchars( $text );
1793 if ( isset( $options['text-wrapper'] ) ) {
1794 $wrapper = $options['text-wrapper'];
1795 if ( isset( $wrapper['tag'] ) ) {
1796 $wrapper = array( $wrapper );
1798 while ( count( $wrapper ) > 0 ) {
1799 $element = array_pop( $wrapper );
1800 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1804 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1806 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1807 unset( $attrs[$k] );
1810 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1811 $item['single-id'] = $item['id'];
1813 if ( isset( $item['single-id'] ) ) {
1814 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1815 $title = Linker
::titleAttrib( $item['single-id'] );
1816 if ( $title !== false ) {
1817 $attrs['title'] = $title;
1820 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1821 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1822 $attrs['title'] = $tip['title'];
1824 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1825 $attrs['accesskey'] = $tip['accesskey'];
1829 if ( isset( $options['link-class'] ) ) {
1830 if ( isset( $attrs['class'] ) ) {
1831 $attrs['class'] .= " {$options['link-class']}";
1833 $attrs['class'] = $options['link-class'];
1836 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1843 * Generates a list item for a navigation, portlet, portal, sidebar... list
1845 * @param $key string, usually a key from the list you are generating this link from.
1846 * @param $item array, of list item data containing some of a specific set of keys.
1847 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
1848 * if "active" contains a value of true a "active" class will also be appended to class.
1850 * @param $options array
1852 * If you want something other than a "<li>" you can pass a tag name such as
1853 * "tag" => "span" in the $options array to change the tag used.
1854 * link/content data for the list item may come in one of two forms
1855 * A "links" key may be used, in which case it should contain an array with
1856 * a list of links to include inside the list item, see makeLink for the
1857 * format of individual links array items.
1859 * Otherwise the relevant keys from the list item $item array will be passed
1860 * to makeLink instead. Note however that "id" and "class" are used by the
1861 * list item directly so they will not be passed to makeLink
1862 * (however the link will still support a tooltip and accesskey from it)
1863 * If you need an id or class on a single link you should include a "links"
1864 * array with just one link item inside of it. If you want to add a title
1865 * to the list item itself, you can set "itemtitle" to the value.
1866 * $options is also passed on to makeLink calls
1870 function makeListItem( $key, $item, $options = array() ) {
1871 if ( isset( $item['links'] ) ) {
1873 foreach ( $item['links'] as $linkKey => $link ) {
1874 $html .= $this->makeLink( $linkKey, $link, $options );
1878 // These keys are used by makeListItem and shouldn't be passed on to the link
1879 foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) {
1882 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1883 // The id goes on the <li> not on the <a> for single links
1884 // but makeSidebarLink still needs to know what id to use when
1885 // generating tooltips and accesskeys.
1886 $link['single-id'] = $item['id'];
1888 $html = $this->makeLink( $key, $link, $options );
1892 foreach ( array( 'id', 'class' ) as $attr ) {
1893 if ( isset( $item[$attr] ) ) {
1894 $attrs[$attr] = $item[$attr];
1897 if ( isset( $item['active'] ) && $item['active'] ) {
1898 if ( !isset( $attrs['class'] ) ) {
1899 $attrs['class'] = '';
1901 $attrs['class'] .= ' active';
1902 $attrs['class'] = trim( $attrs['class'] );
1904 if ( isset( $item['itemtitle'] ) ) {
1905 $attrs['title'] = $item['itemtitle'];
1907 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1910 function makeSearchInput( $attrs = array() ) {
1914 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1915 'value' => $this->get( 'search', '' ),
1917 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1918 return Html
::element( 'input', $realAttrs );
1921 function makeSearchButton( $mode, $attrs = array() ) {
1928 'value' => $this->translator
->translate(
1929 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1931 $realAttrs = array_merge(
1933 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1936 return Html
::element( 'input', $realAttrs );
1938 $buttonAttrs = array(
1942 $buttonAttrs = array_merge(
1944 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1947 unset( $buttonAttrs['src'] );
1948 unset( $buttonAttrs['alt'] );
1949 unset( $buttonAttrs['width'] );
1950 unset( $buttonAttrs['height'] );
1952 'src' => $attrs['src'],
1953 'alt' => isset( $attrs['alt'] )
1955 : $this->translator
->translate( 'searchbutton' ),
1956 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1957 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1959 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1961 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1966 * Returns an array of footerlinks trimmed down to only those footer links that
1968 * If you pass "flat" as an option then the returned array will be a flat array
1969 * of footer icons instead of a key/value array of footerlinks arrays broken
1970 * up into categories.
1971 * @return array|mixed
1973 function getFooterLinks( $option = null ) {
1974 $footerlinks = $this->get( 'footerlinks' );
1976 // Reduce footer links down to only those which are being used
1977 $validFooterLinks = array();
1978 foreach ( $footerlinks as $category => $links ) {
1979 $validFooterLinks[$category] = array();
1980 foreach ( $links as $link ) {
1981 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1982 $validFooterLinks[$category][] = $link;
1985 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1986 unset( $validFooterLinks[$category] );
1990 if ( $option == 'flat' ) {
1991 // fold footerlinks into a single array using a bit of trickery
1992 $validFooterLinks = call_user_func_array(
1994 array_values( $validFooterLinks )
1998 return $validFooterLinks;
2002 * Returns an array of footer icons filtered down by options relevant to how
2003 * the skin wishes to display them.
2004 * If you pass "icononly" as the option all footer icons which do not have an
2005 * image icon set will be filtered out.
2006 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
2007 * in the list of footer icons. This is mostly useful for skins which only
2008 * display the text from footericons instead of the images and don't want a
2009 * duplicate copyright statement because footerlinks already rendered one.
2012 function getFooterIcons( $option = null ) {
2013 // Generate additional footer icons
2014 $footericons = $this->get( 'footericons' );
2016 if ( $option == 'icononly' ) {
2017 // Unset any icons which don't have an image
2018 foreach ( $footericons as &$footerIconsBlock ) {
2019 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2020 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2021 unset( $footerIconsBlock[$footerIconKey] );
2025 // Redo removal of any empty blocks
2026 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2027 if ( count( $footerIconsBlock ) <= 0 ) {
2028 unset( $footericons[$footerIconsKey] );
2031 } elseif ( $option == 'nocopyright' ) {
2032 unset( $footericons['copyright']['copyright'] );
2033 if ( count( $footericons['copyright'] ) <= 0 ) {
2034 unset( $footericons['copyright'] );
2038 return $footericons;
2042 * Output the basic end-page trail including bottomscripts, reporttime, and
2043 * debug stuff. This should be called right before outputting the closing
2044 * body and html tags.
2046 function printTrail() { ?
>
2047 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2048 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2049 <?php
$this->html( 'reporttime' ) ?
>