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();
250 $user = $this->getUser();
252 wfProfileIn( __METHOD__
. '-init' );
253 $this->initPage( $out );
254 wfProfileOut( __METHOD__
. '-init' );
255 $tpl = $this->prepareQuickTemplate( $out );
257 wfProfileIn( __METHOD__
. '-execute' );
258 $res = $tpl->execute();
259 wfProfileOut( __METHOD__
. '-execute' );
261 // result may be an error
262 $this->printOrError( $res );
265 $this->setContext( $oldContext );
268 wfProfileOut( __METHOD__
);
272 * initialize various variables and generate the template
275 * @param $out OutputPage
276 * @return QuickTemplate the template to be executed by outputPage
278 protected function prepareQuickTemplate( OutputPage
$out = null ) {
279 global $wgContLang, $wgScript, $wgStylePath,
280 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
281 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
282 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
283 $wgScriptPath, $wgServer;
285 wfProfileIn( __METHOD__
);
287 $title = $this->getTitle();
288 $request = $this->getRequest();
289 $tpl = $this->setupTemplateForOutput();
291 wfProfileIn( __METHOD__
. '-stuff-head' );
292 if ( !$this->useHeadElement
) {
293 $tpl->set( 'pagecss', false );
294 $tpl->set( 'usercss', false );
296 $tpl->set( 'userjs', false );
297 $tpl->set( 'userjsprev', false );
299 $tpl->set( 'jsvarurl', false );
301 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
302 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
303 $tpl->set( 'html5version', $wgHtml5Version );
304 $tpl->set( 'headlinks', $out->getHeadLinks() );
305 $tpl->set( 'csslinks', $out->buildCssLinks() );
306 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
307 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
309 wfProfileOut( __METHOD__
. '-stuff-head' );
311 wfProfileIn( __METHOD__
. '-stuff2' );
312 $tpl->set( 'title', $out->getPageTitle() );
313 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
314 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
316 $tpl->setRef( 'thispage', $this->thispage
);
317 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
318 $tpl->set( 'titletext', $title->getText() );
319 $tpl->set( 'articleid', $title->getArticleID() );
321 $tpl->set( 'isarticle', $out->isArticle() );
323 $subpagestr = $this->subPageSubtitle();
324 if ( $subpagestr !== '' ) {
325 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
327 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
329 $undelete = $this->getUndeleteLink();
330 if ( $undelete === '' ) {
331 $tpl->set( 'undelete', '' );
333 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
336 $tpl->set( 'catlinks', $this->getCategories() );
337 if ( $out->isSyndicated() ) {
339 foreach ( $out->getSyndicationLinks() as $format => $link ) {
340 $feeds[$format] = array(
341 // Messages: feed-atom, feed-rss
342 'text' => $this->msg( "feed-$format" )->text(),
346 $tpl->setRef( 'feeds', $feeds );
348 $tpl->set( 'feeds', false );
351 $tpl->setRef( 'mimetype', $wgMimeType );
352 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
353 $tpl->set( 'charset', 'UTF-8' );
354 $tpl->setRef( 'wgScript', $wgScript );
355 $tpl->setRef( 'skinname', $this->skinname
);
356 $tpl->set( 'skinclass', get_class( $this ) );
357 $tpl->setRef( 'skin', $this );
358 $tpl->setRef( 'stylename', $this->stylename
);
359 $tpl->set( 'printable', $out->isPrintable() );
360 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
361 $tpl->setRef( 'loggedin', $this->loggedin
);
362 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
363 /* XXX currently unused, might get useful later
364 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
365 $tpl->set( 'exists', $title->getArticleID() != 0 );
366 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
367 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
368 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
370 $tpl->set( 'searchaction', $this->escapeSearchLink() );
371 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
372 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
373 $tpl->setRef( 'stylepath', $wgStylePath );
374 $tpl->setRef( 'articlepath', $wgArticlePath );
375 $tpl->setRef( 'scriptpath', $wgScriptPath );
376 $tpl->setRef( 'serverurl', $wgServer );
377 $tpl->setRef( 'logopath', $wgLogo );
378 $tpl->setRef( 'sitename', $wgSitename );
380 $userLang = $this->getLanguage();
381 $userLangCode = $userLang->getHtmlCode();
382 $userLangDir = $userLang->getDir();
384 $tpl->set( 'lang', $userLangCode );
385 $tpl->set( 'dir', $userLangDir );
386 $tpl->set( 'rtl', $userLang->isRTL() );
388 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
389 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
390 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
391 $tpl->setRef( 'userpage', $this->userpage
);
392 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
393 $tpl->set( 'userlang', $userLangCode );
395 // Users can have their language set differently than the
396 // content of the wiki. For these users, tell the web browser
397 // that interface elements are in a different language.
398 $tpl->set( 'userlangattributes', '' );
399 $tpl->set( 'specialpageattributes', '' ); # obsolete
401 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
402 $escUserlang = htmlspecialchars( $userLangCode );
403 $escUserdir = htmlspecialchars( $userLangDir );
404 // Attributes must be in double quotes because htmlspecialchars() doesn't
405 // escape single quotes
406 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
407 $tpl->set( 'userlangattributes', $attrs );
410 wfProfileOut( __METHOD__
. '-stuff2' );
412 wfProfileIn( __METHOD__
. '-stuff3' );
413 $tpl->set( 'newtalk', $this->getNewtalks() );
414 $tpl->set( 'logo', $this->logoText() );
416 $tpl->set( 'copyright', false );
417 $tpl->set( 'viewcount', false );
418 $tpl->set( 'lastmod', false );
419 $tpl->set( 'credits', false );
420 $tpl->set( 'numberofwatchingusers', false );
421 if ( $out->isArticle() && $title->exists() ) {
422 if ( $this->isRevisionCurrent() ) {
423 if ( !$wgDisableCounters ) {
424 $viewcount = $this->getWikiPage()->getCount();
426 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
430 if ( $wgPageShowWatchingUsers ) {
431 $dbr = wfGetDB( DB_SLAVE
);
432 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
433 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
437 $tpl->set( 'numberofwatchingusers',
438 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
443 if ( $wgMaxCredits != 0 ) {
444 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
445 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
447 $tpl->set( 'lastmod', $this->lastModified() );
450 $tpl->set( 'copyright', $this->getCopyright() );
452 wfProfileOut( __METHOD__
. '-stuff3' );
454 wfProfileIn( __METHOD__
. '-stuff4' );
455 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
456 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
457 $tpl->set( 'disclaimer', $this->disclaimerLink() );
458 $tpl->set( 'privacy', $this->privacyLink() );
459 $tpl->set( 'about', $this->aboutLink() );
461 $tpl->set( 'footerlinks', array(
465 'numberofwatchingusers',
476 global $wgFooterIcons;
477 $tpl->set( 'footericons', $wgFooterIcons );
478 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
479 if ( count( $footerIconsBlock ) > 0 ) {
480 foreach ( $footerIconsBlock as &$footerIcon ) {
481 if ( isset( $footerIcon['src'] ) ) {
482 if ( !isset( $footerIcon['width'] ) ) {
483 $footerIcon['width'] = 88;
485 if ( !isset( $footerIcon['height'] ) ) {
486 $footerIcon['height'] = 31;
491 unset( $tpl->data
['footericons'][$footerIconsKey] );
495 $tpl->set( 'sitenotice', $this->getSiteNotice() );
496 $tpl->set( 'bottomscripts', $this->bottomScripts() );
497 $tpl->set( 'printfooter', $this->printSource() );
499 # An ID that includes the actual body text; without categories, contentSub, ...
500 $realBodyAttribs = array( 'id' => 'mw-content-text' );
502 # Add a mw-content-ltr/rtl class to be able to style based on text direction
503 # when the content is different from the UI language, i.e.:
504 # not for special pages or file pages AND only when viewing AND if the page exists
505 # (or is in MW namespace, because that has default content)
506 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
507 Action
::getActionName( $this ) === 'view' &&
508 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
509 $pageLang = $title->getPageViewLanguage();
510 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
511 $realBodyAttribs['dir'] = $pageLang->getDir();
512 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
515 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
516 $tpl->setRef( 'bodytext', $out->mBodytext
);
518 $language_urls = $this->getLanguages();
519 if ( count( $language_urls ) ) {
520 $tpl->setRef( 'language_urls', $language_urls );
522 $tpl->set( 'language_urls', false );
524 wfProfileOut( __METHOD__
. '-stuff4' );
526 wfProfileIn( __METHOD__
. '-stuff5' );
528 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
529 $content_navigation = $this->buildContentNavigationUrls();
530 $content_actions = $this->buildContentActionUrls( $content_navigation );
531 $tpl->setRef( 'content_navigation', $content_navigation );
532 $tpl->setRef( 'content_actions', $content_actions );
534 $tpl->set( 'sidebar', $this->buildSidebar() );
535 $tpl->set( 'nav_urls', $this->buildNavUrls() );
537 // Set the head scripts near the end, in case the above actions resulted in added scripts
538 if ( $this->useHeadElement
) {
539 $tpl->set( 'headelement', $out->headElement( $this ) );
541 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
544 $tpl->set( 'debug', '' );
545 $tpl->set( 'debughtml', $this->generateDebugHTML() );
546 $tpl->set( 'reporttime', wfReportTime() );
548 // original version by hansm
549 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
550 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
553 // Set the bodytext to another key so that skins can just output it on it's own
554 // and output printfooter and debughtml separately
555 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
557 // Append printfooter and debughtml onto bodytext so that skins that were already
558 // using bodytext before they were split out don't suddenly start not outputting information
559 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
560 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
562 // allow extensions adding stuff after the page content.
563 // See Skin::afterContentHook() for further documentation.
564 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
565 wfProfileOut( __METHOD__
. '-stuff5' );
567 wfProfileOut( __METHOD__
);
572 * Get the HTML for the p-personal list
575 public function getPersonalToolsList() {
576 $tpl = $this->setupTemplateForOutput();
577 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
579 foreach ( $tpl->getPersonalTools() as $key => $item ) {
580 $html .= $tpl->makeListItem( $key, $item );
586 * Format language name for use in sidebar interlanguage links list.
587 * By default it is capitalized.
589 * @param string $name Language name, e.g. "English" or "español"
593 function formatLanguageName( $name ) {
594 return $this->getLanguage()->ucfirst( $name );
598 * Output the string, or print error message if it's
599 * an error object of the appropriate type.
600 * For the base class, assume strings all around.
605 function printOrError( $str ) {
610 * Output a boolean indicating if buildPersonalUrls should output separate
611 * login and create account links or output a combined link
612 * By default we simply return a global config setting that affects most skins
613 * This is setup as a method so that like with $wgLogo and getLogo() a skin
614 * can override this setting and always output one or the other if it has
615 * a reason it can't output one of the two modes.
618 function useCombinedLoginLink() {
619 global $wgUseCombinedLoginLink;
620 return $wgUseCombinedLoginLink;
624 * build array of urls for personal toolbar
627 protected function buildPersonalUrls() {
628 $title = $this->getTitle();
629 $request = $this->getRequest();
630 $pageurl = $title->getLocalURL();
631 wfProfileIn( __METHOD__
);
633 /* set up the default links for the personal toolbar */
634 $personal_urls = array();
636 # Due to bug 32276, if a user does not have read permissions,
637 # $this->getTitle() will just give Special:Badtitle, which is
638 # not especially useful as a returnto parameter. Use the title
639 # from the request instead, if there was one.
640 if ( $this->getUser()->isAllowed( 'read' ) ) {
641 $page = $this->getTitle();
643 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
645 $page = $request->getVal( 'returnto', $page );
647 if ( strval( $page ) !== '' ) {
648 $a['returnto'] = $page;
649 $query = $request->getVal( 'returntoquery', $this->thisquery
);
650 if ( $query != '' ) {
651 $a['returntoquery'] = $query;
655 $returnto = wfArrayToCgi( $a );
656 if ( $this->loggedin
) {
657 $personal_urls['userpage'] = array(
658 'text' => $this->username
,
659 'href' => &$this->userpageUrlDetails
['href'],
660 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
661 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
664 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
665 $personal_urls['mytalk'] = array(
666 'text' => $this->msg( 'mytalk' )->text(),
667 'href' => &$usertalkUrlDetails['href'],
668 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
669 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
671 $href = self
::makeSpecialUrl( 'Preferences' );
672 $personal_urls['preferences'] = array(
673 'text' => $this->msg( 'mypreferences' )->text(),
675 'active' => ( $href == $pageurl )
678 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
679 $href = self
::makeSpecialUrl( 'Watchlist' );
680 $personal_urls['watchlist'] = array(
681 'text' => $this->msg( 'mywatchlist' )->text(),
683 'active' => ( $href == $pageurl )
687 # We need to do an explicit check for Special:Contributions, as we
688 # have to match both the title, and the target, which could come
689 # from request values (Special:Contributions?target=Jimbo_Wales)
690 # or be specified in "sub page" form
691 # (Special:Contributions/Jimbo_Wales). The plot
692 # thickens, because the Title object is altered for special pages,
693 # so it doesn't contain the original alias-with-subpage.
694 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
695 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
696 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
697 $active = $spName == 'Contributions'
698 && ( ( $spPar && $spPar == $this->username
)
699 ||
$request->getText( 'target' ) == $this->username
);
704 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
705 $personal_urls['mycontris'] = array(
706 'text' => $this->msg( 'mycontris' )->text(),
710 $personal_urls['logout'] = array(
711 'text' => $this->msg( 'userlogout' )->text(),
712 'href' => self
::makeSpecialUrl( 'Userlogout',
713 // userlogout link must always contain an & character, otherwise we might not be able
714 // to detect a buggy precaching proxy (bug 17790)
715 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
720 $useCombinedLoginLink = $this->useCombinedLoginLink();
721 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
722 ?
'nav-login-createaccount'
724 $is_signup = $request->getText( 'type' ) == 'signup';
726 $login_id = $this->showIPinHeader() ?
'anonlogin' : 'login';
728 'text' => $this->msg( $loginlink )->text(),
729 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
730 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
732 $createaccount_url = array(
733 'text' => $this->msg( 'createaccount' )->text(),
734 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
735 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
738 if ( $this->showIPinHeader() ) {
739 $href = &$this->userpageUrlDetails
['href'];
740 $personal_urls['anonuserpage'] = array(
741 'text' => $this->username
,
743 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
744 'active' => ( $pageurl == $href )
746 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
747 $href = &$usertalkUrlDetails['href'];
748 $personal_urls['anontalk'] = array(
749 'text' => $this->msg( 'anontalk' )->text(),
751 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
752 'active' => ( $pageurl == $href )
756 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
757 $personal_urls['createaccount'] = $createaccount_url;
760 $personal_urls[$login_id] = $login_url;
763 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
764 wfProfileOut( __METHOD__
);
765 return $personal_urls;
769 * Builds an array with tab definition
771 * @param Title $title page where the tab links to
772 * @param string|array $message message key or an array of message keys (will fall back)
773 * @param boolean $selected display the tab as selected
774 * @param string $query query string attached to tab URL
775 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
779 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
782 $classes[] = 'selected';
784 if ( $checkEdit && !$title->isKnown() ) {
786 if ( $query !== '' ) {
787 $query = 'action=edit&redlink=1&' . $query;
789 $query = 'action=edit&redlink=1';
793 // wfMessageFallback will nicely accept $message as an array of fallbacks
794 // or just a single key
795 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
796 if ( is_array( $message ) ) {
797 // for hook compatibility just keep the last message name
798 $message = end( $message );
800 if ( $msg->exists() ) {
801 $text = $msg->text();
804 $text = $wgContLang->getFormattedNsText(
805 MWNamespace
::getSubject( $title->getNamespace() ) );
809 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
810 $title, $message, $selected, $checkEdit,
811 &$classes, &$query, &$text, &$result ) ) ) {
816 'class' => implode( ' ', $classes ),
818 'href' => $title->getLocalURL( $query ),
822 function makeTalkUrlDetails( $name, $urlaction = '' ) {
823 $title = Title
::newFromText( $name );
824 if ( !is_object( $title ) ) {
825 throw new MWException( __METHOD__
. " given invalid pagename $name" );
827 $title = $title->getTalkPage();
828 self
::checkTitle( $title, $name );
830 'href' => $title->getLocalURL( $urlaction ),
831 'exists' => $title->getArticleID() != 0,
835 function makeArticleUrlDetails( $name, $urlaction = '' ) {
836 $title = Title
::newFromText( $name );
837 $title = $title->getSubjectPage();
838 self
::checkTitle( $title, $name );
840 'href' => $title->getLocalURL( $urlaction ),
841 'exists' => $title->getArticleID() != 0,
846 * a structured array of links usually used for the tabs in a skin
848 * There are 4 standard sections
849 * namespaces: Used for namespace tabs like special, page, and talk namespaces
850 * views: Used for primary page views like read, edit, history
851 * actions: Used for most extra page actions like deletion, protection, etc...
852 * variants: Used to list the language variants for the page
854 * Each section's value is a key/value array of links for that section.
855 * The links themselves have these common keys:
856 * - class: The css classes to apply to the tab
857 * - text: The text to display on the tab
858 * - href: The href for the tab to point to
859 * - rel: An optional rel= for the tab's link
860 * - redundant: If true the tab will be dropped in skins using content_actions
861 * this is useful for tabs like "Read" which only have meaning in skins that
862 * take special meaning from the grouped structure of content_navigation
864 * Views also have an extra key which can be used:
865 * - primary: If this is not true skins like vector may try to hide the tab
866 * when the user has limited space in their browser window
868 * content_navigation using code also expects these ids to be present on the
869 * links, however these are usually automatically generated by SkinTemplate
870 * itself and are not necessary when using a hook. The only things these may
871 * matter to are people modifying content_navigation after it's initial creation:
872 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
873 * - tooltiponly: This is set to true for some tabs in cases where the system
874 * believes that the accesskey should not be added to the tab.
878 protected function buildContentNavigationUrls() {
879 global $wgDisableLangConversion;
881 wfProfileIn( __METHOD__
);
883 // Display tabs for the relevant title rather than always the title itself
884 $title = $this->getRelevantTitle();
885 $onPage = $title->equals( $this->getTitle() );
887 $out = $this->getOutput();
888 $request = $this->getRequest();
889 $user = $this->getUser();
891 $content_navigation = array(
892 'namespaces' => array(),
894 'actions' => array(),
895 'variants' => array()
899 $action = $request->getVal( 'action', 'view' );
901 $userCanRead = $title->quickUserCan( 'read', $user );
903 $preventActiveTabs = false;
904 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
906 // Checks if page is some kind of content
907 if ( $title->canExist() ) {
908 // Gets page objects for the related namespaces
909 $subjectPage = $title->getSubjectPage();
910 $talkPage = $title->getTalkPage();
912 // Determines if this is a talk page
913 $isTalk = $title->isTalkPage();
915 // Generates XML IDs from namespace names
916 $subjectId = $title->getNamespaceKey( '' );
918 if ( $subjectId == 'main' ) {
921 $talkId = "{$subjectId}_talk";
924 $skname = $this->skinname
;
926 // Adds namespace links
927 $subjectMsg = array( "nstab-$subjectId" );
928 if ( $subjectPage->isMainPage() ) {
929 array_unshift( $subjectMsg, 'mainpage-nstab' );
931 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
932 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
934 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
935 $content_navigation['namespaces'][$talkId] = $this->tabAction(
936 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
938 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
940 if ( $userCanRead ) {
941 // Adds view view link
942 if ( $title->exists() ) {
943 $content_navigation['views']['view'] = $this->tabAction(
944 $isTalk ?
$talkPage : $subjectPage,
945 array( "$skname-view-view", 'view' ),
946 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
948 // signal to hide this from simple content_actions
949 $content_navigation['views']['view']['redundant'] = true;
952 wfProfileIn( __METHOD__
. '-edit' );
954 // Checks if user can edit the current page if it exists or create it otherwise
955 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
956 // Builds CSS class for talk page links
957 $isTalkClass = $isTalk ?
' istalk' : '';
958 // Whether the user is editing the page
959 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
960 // Whether to show the "Add a new section" tab
961 // Checks if this is a current rev of talk page and is not forced to be hidden
962 $showNewSection = !$out->forceHideNewSectionLink()
963 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
964 $section = $request->getVal( 'section' );
966 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
968 $content_navigation['views']['edit'] = array(
969 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
970 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
971 'href' => $title->getLocalURL( $this->editUrlOptions() ),
972 'primary' => true, // don't collapse this in vector
976 if ( $showNewSection ) {
977 // Adds new section link
978 //$content_navigation['actions']['addsection']
979 $content_navigation['views']['addsection'] = array(
980 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
981 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
982 'href' => $title->getLocalURL( 'action=edit§ion=new' )
985 // Checks if the page has some kind of viewable content
986 } elseif ( $title->hasSourceText() ) {
987 // Adds view source view link
988 $content_navigation['views']['viewsource'] = array(
989 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
990 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
991 'href' => $title->getLocalURL( $this->editUrlOptions() ),
992 'primary' => true, // don't collapse this in vector
995 wfProfileOut( __METHOD__
. '-edit' );
997 wfProfileIn( __METHOD__
. '-live' );
998 // Checks if the page exists
999 if ( $title->exists() ) {
1000 // Adds history view link
1001 $content_navigation['views']['history'] = array(
1002 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1003 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
1004 'href' => $title->getLocalURL( 'action=history' ),
1005 'rel' => 'archives',
1008 if ( $title->quickUserCan( 'delete', $user ) ) {
1009 $content_navigation['actions']['delete'] = array(
1010 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1011 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
1012 'href' => $title->getLocalURL( 'action=delete' )
1016 if ( $title->quickUserCan( 'move', $user ) ) {
1017 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1018 $content_navigation['actions']['move'] = array(
1019 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1020 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
1021 'href' => $moveTitle->getLocalURL()
1025 // article doesn't exist or is deleted
1026 if ( $user->isAllowed( 'deletedhistory' ) ) {
1027 $n = $title->isDeleted();
1029 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1030 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1031 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1032 $content_navigation['actions']['undelete'] = array(
1033 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1034 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1035 ->setContext( $this->getContext() )->numParams( $n )->text(),
1036 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1042 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1043 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1045 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1046 $content_navigation['actions'][$mode] = array(
1047 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1048 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1049 'href' => $title->getLocalURL( "action=$mode" )
1053 wfProfileOut( __METHOD__
. '-live' );
1055 // Checks if the user is logged in
1056 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1058 * The following actions use messages which, if made particular to
1059 * the any specific skins, would break the Ajax code which makes this
1060 * action happen entirely inline. Skin::makeGlobalVariablesScript
1061 * defines a set of messages in a javascript object - and these
1062 * messages are assumed to be global for all skins. Without making
1063 * a change to that procedure these messages will have to remain as
1064 * the global versions.
1066 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1067 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1068 $content_navigation['actions'][$mode] = array(
1069 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1070 // uses 'watch' or 'unwatch' message
1071 'text' => $this->msg( $mode )->text(),
1072 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1077 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1079 if ( $userCanRead && !$wgDisableLangConversion ) {
1080 $pageLang = $title->getPageLanguage();
1081 // Gets list of language variants
1082 $variants = $pageLang->getVariants();
1083 // Checks that language conversion is enabled and variants exist
1084 // And if it is not in the special namespace
1085 if ( count( $variants ) > 1 ) {
1086 // Gets preferred variant (note that user preference is
1087 // only possible for wiki content language variant)
1088 $preferred = $pageLang->getPreferredVariant();
1089 if ( Action
::getActionName( $this ) === 'view' ) {
1090 $params = $request->getQueryValues();
1091 unset( $params['title'] );
1095 // Loops over each variant
1096 foreach ( $variants as $code ) {
1097 // Gets variant name from language code
1098 $varname = $pageLang->getVariantname( $code );
1099 // Appends variant link
1100 $content_navigation['variants'][] = array(
1101 'class' => ( $code == $preferred ) ?
'selected' : false,
1103 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1104 'lang' => wfBCP47( $code ),
1105 'hreflang' => wfBCP47( $code ),
1111 // If it's not content, it's got to be a special page
1112 $content_navigation['namespaces']['special'] = array(
1113 'class' => 'selected',
1114 'text' => $this->msg( 'nstab-special' )->text(),
1115 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1116 'context' => 'subject'
1119 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1120 array( &$this, &$content_navigation ) );
1123 // Equiv to SkinTemplateContentActions
1124 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1126 // Setup xml ids and tooltip info
1127 foreach ( $content_navigation as $section => &$links ) {
1128 foreach ( $links as $key => &$link ) {
1130 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1131 $xmlID = 'ca-nstab-' . $xmlID;
1132 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1134 } elseif ( $section == 'variants' ) {
1135 $xmlID = 'ca-varlang-' . $xmlID;
1137 $xmlID = 'ca-' . $xmlID;
1139 $link['id'] = $xmlID;
1143 # We don't want to give the watch tab an accesskey if the
1144 # page is being edited, because that conflicts with the
1145 # accesskey on the watch checkbox. We also don't want to
1146 # give the edit tab an accesskey, because that's fairly
1147 # superfluous and conflicts with an accesskey (Ctrl-E) often
1148 # used for editing in Safari.
1149 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1150 if ( isset( $content_navigation['views']['edit'] ) ) {
1151 $content_navigation['views']['edit']['tooltiponly'] = true;
1153 if ( isset( $content_navigation['actions']['watch'] ) ) {
1154 $content_navigation['actions']['watch']['tooltiponly'] = true;
1156 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1157 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1161 wfProfileOut( __METHOD__
);
1163 return $content_navigation;
1167 * an array of edit links by default used for the tabs
1171 function buildContentActionUrls( $content_navigation ) {
1173 wfProfileIn( __METHOD__
);
1175 // content_actions has been replaced with content_navigation for backwards
1176 // compatibility and also for skins that just want simple tabs content_actions
1177 // is now built by flattening the content_navigation arrays into one
1179 $content_actions = array();
1181 foreach ( $content_navigation as $links ) {
1183 foreach ( $links as $key => $value ) {
1185 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1186 // Redundant tabs are dropped from content_actions
1190 // content_actions used to have ids built using the "ca-$key" pattern
1191 // so the xmlID based id is much closer to the actual $key that we want
1192 // for that reason we'll just strip out the ca- if present and use
1193 // the latter potion of the "id" as the $key
1194 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1195 $key = substr( $value['id'], 3 );
1198 if ( isset( $content_actions[$key] ) ) {
1199 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1203 $content_actions[$key] = $value;
1209 wfProfileOut( __METHOD__
);
1211 return $content_actions;
1215 * build array of common navigation links
1219 protected function buildNavUrls() {
1220 global $wgUploadNavigationUrl;
1222 wfProfileIn( __METHOD__
);
1224 $out = $this->getOutput();
1225 $request = $this->getRequest();
1227 $nav_urls = array();
1228 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1229 if ( $wgUploadNavigationUrl ) {
1230 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1231 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1232 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1234 $nav_urls['upload'] = false;
1236 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1238 $nav_urls['print'] = false;
1239 $nav_urls['permalink'] = false;
1240 $nav_urls['info'] = false;
1241 $nav_urls['whatlinkshere'] = false;
1242 $nav_urls['recentchangeslinked'] = false;
1243 $nav_urls['contributions'] = false;
1244 $nav_urls['log'] = false;
1245 $nav_urls['blockip'] = false;
1246 $nav_urls['emailuser'] = false;
1247 $nav_urls['userrights'] = false;
1249 // A print stylesheet is attached to all pages, but nobody ever
1250 // figures that out. :) Add a link...
1251 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1252 $nav_urls['print'] = array(
1253 'text' => $this->msg( 'printableversion' )->text(),
1254 'href' => $this->getTitle()->getLocalURL(
1255 $request->appendQueryValue( 'printable', 'yes', true ) )
1259 if ( $out->isArticle() ) {
1260 // Also add a "permalink" while we're at it
1261 $revid = $this->getRevisionId();
1263 $nav_urls['permalink'] = array(
1264 'text' => $this->msg( 'permalink' )->text(),
1265 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1269 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1270 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1271 array( &$this, &$nav_urls, &$revid, &$revid ) );
1274 if ( $out->isArticleRelated() ) {
1275 $nav_urls['whatlinkshere'] = array(
1276 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1279 $nav_urls['info'] = array(
1280 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1281 'href' => $this->getTitle()->getLocalURL( "action=info" )
1284 if ( $this->getTitle()->getArticleID() ) {
1285 $nav_urls['recentchangeslinked'] = array(
1286 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1291 $user = $this->getRelevantUser();
1293 $rootUser = $user->getName();
1295 $nav_urls['contributions'] = array(
1296 'text' => $this->msg( 'contributions', $rootUser )->text(),
1297 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1300 $nav_urls['log'] = array(
1301 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1304 if ( $this->getUser()->isAllowed( 'block' ) ) {
1305 $nav_urls['blockip'] = array(
1306 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1310 if ( $this->showEmailUser( $user ) ) {
1311 $nav_urls['emailuser'] = array(
1312 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1316 if ( !$user->isAnon() ) {
1317 $sur = new UserrightsPage
;
1318 $sur->setContext( $this->getContext() );
1319 if ( $sur->userCanExecute( $this->getUser() ) ) {
1320 $nav_urls['userrights'] = array(
1321 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1327 wfProfileOut( __METHOD__
);
1332 * Generate strings used for xml 'id' names
1336 function getNameSpaceKey() {
1337 return $this->getTitle()->getNamespaceKey();
1342 * Generic wrapper for template functions, with interface
1343 * compatible with what we use of PHPTAL 0.7.
1346 abstract class QuickTemplate
{
1350 function __construct() {
1351 $this->data
= array();
1352 $this->translator
= new MediaWiki_I18N();
1356 * Sets the value $value to $name
1360 public function set( $name, $value ) {
1361 $this->data
[$name] = $value;
1365 * Gets the template data requested
1367 * @param string $name Key for the data
1368 * @param mixed $default Optional default (or null)
1369 * @return mixed The value of the data requested or the deafult
1371 public function get( $name, $default = null ) {
1372 if ( isset( $this->data
[$name] ) ) {
1373 return $this->data
[$name];
1383 public function setRef( $name, &$value ) {
1384 $this->data
[$name] =& $value;
1390 public function setTranslator( &$t ) {
1391 $this->translator
= &$t;
1395 * Main function, used by classes that subclass QuickTemplate
1396 * to show the actual HTML output
1398 abstract public function execute();
1403 function text( $str ) {
1404 echo htmlspecialchars( $this->data
[$str] );
1409 * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
1411 function jstext( $str ) {
1412 wfDeprecated( __METHOD__
, '1.21' );
1413 echo Xml
::escapeJsString( $this->data
[$str] );
1419 function html( $str ) {
1420 echo $this->data
[$str];
1426 function msg( $str ) {
1427 echo htmlspecialchars( $this->translator
->translate( $str ) );
1433 function msgHtml( $str ) {
1434 echo $this->translator
->translate( $str );
1438 * An ugly, ugly hack.
1441 function msgWiki( $str ) {
1444 $text = $this->translator
->translate( $str );
1445 echo $wgOut->parse( $text );
1452 function haveData( $str ) {
1453 return isset( $this->data
[$str] );
1461 function haveMsg( $str ) {
1462 $msg = $this->translator
->translate( $str );
1463 return ( $msg != '-' ) && ( $msg != '' ); # ????
1467 * Get the Skin object related to this object
1469 * @return Skin object
1471 public function getSkin() {
1472 return $this->data
['skin'];
1476 * Fetch the output of a QuickTemplate and return it
1481 public function getHTML() {
1484 $html = ob_get_contents();
1491 * New base template for a skin's template extended from QuickTemplate
1492 * this class features helper methods that provide common ways of interacting
1493 * with the data stored in the QuickTemplate
1495 abstract class BaseTemplate
extends QuickTemplate
{
1498 * Get a Message object with its context set
1500 * @param string $name message name
1503 public function getMsg( $name ) {
1504 return $this->getSkin()->msg( $name );
1507 function msg( $str ) {
1508 echo $this->getMsg( $str )->escaped();
1511 function msgHtml( $str ) {
1512 echo $this->getMsg( $str )->text();
1515 function msgWiki( $str ) {
1516 echo $this->getMsg( $str )->parseAsBlock();
1520 * Create an array of common toolbox items from the data in the quicktemplate
1521 * stored by SkinTemplate.
1522 * The resulting array is built according to a format intended to be passed
1523 * through makeListItem to generate the html.
1526 function getToolbox() {
1527 wfProfileIn( __METHOD__
);
1530 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1531 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1532 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1534 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1535 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1536 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1537 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1539 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1540 $toolbox['feeds']['id'] = 'feedlinks';
1541 $toolbox['feeds']['links'] = array();
1542 foreach ( $this->data
['feeds'] as $key => $feed ) {
1543 $toolbox['feeds']['links'][$key] = $feed;
1544 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1545 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1546 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1547 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1550 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1551 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1552 $toolbox[$special] = $this->data
['nav_urls'][$special];
1553 $toolbox[$special]['id'] = "t-$special";
1556 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1557 $toolbox['print'] = $this->data
['nav_urls']['print'];
1558 $toolbox['print']['id'] = 't-print';
1559 $toolbox['print']['rel'] = 'alternate';
1560 $toolbox['print']['msg'] = 'printableversion';
1562 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1563 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1564 if ( $toolbox['permalink']['href'] === '' ) {
1565 unset( $toolbox['permalink']['href'] );
1566 $toolbox['ispermalink']['tooltiponly'] = true;
1567 $toolbox['ispermalink']['id'] = 't-ispermalink';
1568 $toolbox['ispermalink']['msg'] = 'permalink';
1570 $toolbox['permalink']['id'] = 't-permalink';
1573 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1574 $toolbox['info'] = $this->data
['nav_urls']['info'];
1575 $toolbox['info']['id'] = 't-info';
1578 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1579 wfProfileOut( __METHOD__
);
1584 * Create an array of personal tools items from the data in the quicktemplate
1585 * stored by SkinTemplate.
1586 * The resulting array is built according to a format intended to be passed
1587 * through makeListItem to generate the html.
1588 * This is in reality the same list as already stored in personal_urls
1589 * however it is reformatted so that you can just pass the individual items
1590 * to makeListItem instead of hardcoding the element creation boilerplate.
1593 function getPersonalTools() {
1594 $personal_tools = array();
1595 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1596 # The class on a personal_urls item is meant to go on the <a> instead
1597 # of the <li> so we have to use a single item "links" array instead
1598 # of using most of the personal_url's keys directly.
1601 array( 'single-id' => "pt-$key" ),
1605 if ( isset( $plink['active'] ) ) {
1606 $ptool['active'] = $plink['active'];
1608 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1609 if ( isset( $plink[$k] ) ) {
1610 $ptool['links'][0][$k] = $plink[$k];
1613 $personal_tools[$key] = $ptool;
1615 return $personal_tools;
1618 function getSidebar( $options = array() ) {
1619 // Force the rendering of the following portals
1620 $sidebar = $this->data
['sidebar'];
1621 if ( !isset( $sidebar['SEARCH'] ) ) {
1622 $sidebar['SEARCH'] = true;
1624 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1625 $sidebar['TOOLBOX'] = true;
1627 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1628 $sidebar['LANGUAGES'] = true;
1631 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1632 unset( $sidebar['SEARCH'] );
1634 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1635 unset( $sidebar['TOOLBOX'] );
1637 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1638 unset( $sidebar['LANGUAGES'] );
1642 foreach ( $sidebar as $boxName => $content ) {
1643 if ( $content === false ) {
1646 switch ( $boxName ) {
1648 // Search is a special case, skins should custom implement this
1649 $boxes[$boxName] = array(
1651 'header' => $this->getMsg( 'search' )->text(),
1652 'generated' => false,
1657 $msgObj = $this->getMsg( 'toolbox' );
1658 $boxes[$boxName] = array(
1660 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1661 'generated' => false,
1662 'content' => $this->getToolbox(),
1666 if ( $this->data
['language_urls'] ) {
1667 $msgObj = $this->getMsg( 'otherlanguages' );
1668 $boxes[$boxName] = array(
1670 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1671 'generated' => false,
1672 'content' => $this->data
['language_urls'],
1677 $msgObj = $this->getMsg( $boxName );
1678 $boxes[$boxName] = array(
1679 'id' => "p-$boxName",
1680 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1681 'generated' => true,
1682 'content' => $content,
1688 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1689 $hookContents = null;
1690 if ( isset( $boxes['TOOLBOX'] ) ) {
1692 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1693 // can abort and avoid outputting double toolbox links
1694 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1695 $hookContents = ob_get_contents();
1697 if ( !trim( $hookContents ) ) {
1698 $hookContents = null;
1703 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1704 foreach ( $boxes as $boxName => $box ) {
1705 if ( is_array( $box['content'] ) ) {
1707 foreach ( $box['content'] as $key => $val ) {
1708 $content .= "\n " . $this->makeListItem( $key, $val );
1710 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1711 if ( $hookContents ) {
1712 $content .= "\n $hookContents";
1715 $content .= "\n</ul>\n";
1716 $boxes[$boxName]['content'] = $content;
1720 if ( $hookContents ) {
1721 $boxes['TOOLBOXEND'] = array(
1722 'id' => 'p-toolboxend',
1723 'header' => $boxes['TOOLBOX']['header'],
1724 'generated' => false,
1725 'content' => "<ul>{$hookContents}</ul>",
1727 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1729 foreach ( $boxes as $key => $box ) {
1730 if ( $key === 'TOOLBOXEND' ) {
1733 $boxes2[$key] = $box;
1734 if ( $key === 'TOOLBOX' ) {
1735 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1747 * Makes a link, usually used by makeListItem to generate a link for an item
1748 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1750 * @param string $key usually a key from the list you are generating this
1752 * @param array $item contains some of a specific set of keys.
1754 * The text of the link will be generated either from the contents of the
1755 * "text" key in the $item array, if a "msg" key is present a message by
1756 * that name will be used, and if neither of those are set the $key will be
1757 * used as a message name.
1759 * If a "href" key is not present makeLink will just output htmlescaped text.
1760 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1761 * for the link if present.
1763 * If an "id" or "single-id" (if you don't want the actual id to be output
1764 * on the link) is present it will be used to generate a tooltip and
1765 * accesskey for the link.
1767 * The keys "context" and "primary" are ignored; these keys are used
1768 * internally by skins and are not supposed to be included in the HTML
1771 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1773 * @param array $options can be used to affect the output of a link.
1774 * Possible options are:
1775 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1776 * a link in. This should be an array of arrays containing a 'tag' and
1777 * optionally an 'attributes' key. If you only have one element you don't
1778 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1779 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1781 * - 'link-class' key can be used to specify additional classes to apply
1783 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1784 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1785 * any non-link will output a "<span>" instead of just text.
1789 function makeLink( $key, $item, $options = array() ) {
1790 if ( isset( $item['text'] ) ) {
1791 $text = $item['text'];
1793 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1796 $html = htmlspecialchars( $text );
1798 if ( isset( $options['text-wrapper'] ) ) {
1799 $wrapper = $options['text-wrapper'];
1800 if ( isset( $wrapper['tag'] ) ) {
1801 $wrapper = array( $wrapper );
1803 while ( count( $wrapper ) > 0 ) {
1804 $element = array_pop( $wrapper );
1805 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1809 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1811 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1812 unset( $attrs[$k] );
1815 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1816 $item['single-id'] = $item['id'];
1818 if ( isset( $item['single-id'] ) ) {
1819 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1820 $title = Linker
::titleAttrib( $item['single-id'] );
1821 if ( $title !== false ) {
1822 $attrs['title'] = $title;
1825 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1826 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1827 $attrs['title'] = $tip['title'];
1829 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1830 $attrs['accesskey'] = $tip['accesskey'];
1834 if ( isset( $options['link-class'] ) ) {
1835 if ( isset( $attrs['class'] ) ) {
1836 $attrs['class'] .= " {$options['link-class']}";
1838 $attrs['class'] = $options['link-class'];
1841 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1848 * Generates a list item for a navigation, portlet, portal, sidebar... list
1850 * @param $key string, usually a key from the list you are generating this link from.
1851 * @param $item array, of list item data containing some of a specific set of keys.
1852 * The "id" and "class" keys will be used as attributes for the list item,
1853 * if "active" contains a value of true a "active" class will also be appended to class.
1855 * @param $options array
1857 * If you want something other than a "<li>" you can pass a tag name such as
1858 * "tag" => "span" in the $options array to change the tag used.
1859 * link/content data for the list item may come in one of two forms
1860 * A "links" key may be used, in which case it should contain an array with
1861 * a list of links to include inside the list item, see makeLink for the
1862 * format of individual links array items.
1864 * Otherwise the relevant keys from the list item $item array will be passed
1865 * to makeLink instead. Note however that "id" and "class" are used by the
1866 * list item directly so they will not be passed to makeLink
1867 * (however the link will still support a tooltip and accesskey from it)
1868 * If you need an id or class on a single link you should include a "links"
1869 * array with just one link item inside of it.
1870 * $options is also passed on to makeLink calls
1874 function makeListItem( $key, $item, $options = array() ) {
1875 if ( isset( $item['links'] ) ) {
1877 foreach ( $item['links'] as $linkKey => $link ) {
1878 $html .= $this->makeLink( $linkKey, $link, $options );
1882 // These keys are used by makeListItem and shouldn't be passed on to the link
1883 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1886 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1887 // The id goes on the <li> not on the <a> for single links
1888 // but makeSidebarLink still needs to know what id to use when
1889 // generating tooltips and accesskeys.
1890 $link['single-id'] = $item['id'];
1892 $html = $this->makeLink( $key, $link, $options );
1896 foreach ( array( 'id', 'class' ) as $attr ) {
1897 if ( isset( $item[$attr] ) ) {
1898 $attrs[$attr] = $item[$attr];
1901 if ( isset( $item['active'] ) && $item['active'] ) {
1902 if ( !isset( $attrs['class'] ) ) {
1903 $attrs['class'] = '';
1905 $attrs['class'] .= ' active';
1906 $attrs['class'] = trim( $attrs['class'] );
1908 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1911 function makeSearchInput( $attrs = array() ) {
1915 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1916 'value' => $this->get( 'search', '' ),
1918 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1919 return Html
::element( 'input', $realAttrs );
1922 function makeSearchButton( $mode, $attrs = array() ) {
1929 'value' => $this->translator
->translate(
1930 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1932 $realAttrs = array_merge(
1934 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1937 return Html
::element( 'input', $realAttrs );
1939 $buttonAttrs = array(
1943 $buttonAttrs = array_merge(
1945 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1948 unset( $buttonAttrs['src'] );
1949 unset( $buttonAttrs['alt'] );
1950 unset( $buttonAttrs['width'] );
1951 unset( $buttonAttrs['height'] );
1953 'src' => $attrs['src'],
1954 'alt' => isset( $attrs['alt'] )
1956 : $this->translator
->translate( 'searchbutton' ),
1957 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1958 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1960 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1962 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1967 * Returns an array of footerlinks trimmed down to only those footer links that
1969 * If you pass "flat" as an option then the returned array will be a flat array
1970 * of footer icons instead of a key/value array of footerlinks arrays broken
1971 * up into categories.
1972 * @return array|mixed
1974 function getFooterLinks( $option = null ) {
1975 $footerlinks = $this->get( 'footerlinks' );
1977 // Reduce footer links down to only those which are being used
1978 $validFooterLinks = array();
1979 foreach ( $footerlinks as $category => $links ) {
1980 $validFooterLinks[$category] = array();
1981 foreach ( $links as $link ) {
1982 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1983 $validFooterLinks[$category][] = $link;
1986 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1987 unset( $validFooterLinks[$category] );
1991 if ( $option == 'flat' ) {
1992 // fold footerlinks into a single array using a bit of trickery
1993 $validFooterLinks = call_user_func_array(
1995 array_values( $validFooterLinks )
1999 return $validFooterLinks;
2003 * Returns an array of footer icons filtered down by options relevant to how
2004 * the skin wishes to display them.
2005 * If you pass "icononly" as the option all footer icons which do not have an
2006 * image icon set will be filtered out.
2007 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
2008 * in the list of footer icons. This is mostly useful for skins which only
2009 * display the text from footericons instead of the images and don't want a
2010 * duplicate copyright statement because footerlinks already rendered one.
2013 function getFooterIcons( $option = null ) {
2014 // Generate additional footer icons
2015 $footericons = $this->get( 'footericons' );
2017 if ( $option == 'icononly' ) {
2018 // Unset any icons which don't have an image
2019 foreach ( $footericons as &$footerIconsBlock ) {
2020 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2021 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2022 unset( $footerIconsBlock[$footerIconKey] );
2026 // Redo removal of any empty blocks
2027 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2028 if ( count( $footerIconsBlock ) <= 0 ) {
2029 unset( $footericons[$footerIconsKey] );
2032 } elseif ( $option == 'nocopyright' ) {
2033 unset( $footericons['copyright']['copyright'] );
2034 if ( count( $footericons['copyright'] ) <= 0 ) {
2035 unset( $footericons['copyright'] );
2039 return $footericons;
2043 * Output the basic end-page trail including bottomscripts, reporttime, and
2044 * debug stuff. This should be called right before outputting the closing
2045 * body and html tags.
2047 function printTrail() { ?
>
2048 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2049 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2050 <?php
$this->html( 'reporttime' ) ?
>