3 * Base class for template-based skins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Wrapper object for MediaWiki's localization functions,
25 * to be passed to the template engine.
30 class MediaWiki_I18N
{
31 var $_context = array();
33 function set( $varName, $value ) {
34 $this->_context
[$varName] = $value;
37 function translate( $value ) {
38 wfProfileIn( __METHOD__
);
40 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
41 $value = preg_replace( '/^string:/', '', $value );
43 $value = wfMessage( $value )->text();
44 // interpolate variables
46 while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
47 list( $src, $var ) = $m;
49 $varValue = $this->_context
[$var];
51 $value = str_replace( $src, $varValue, $value );
53 wfProfileOut( __METHOD__
);
59 * Template-filler skin base class
60 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
61 * Based on Brion's smarty skin
62 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
64 * @todo Needs some serious refactoring into functions that correspond
65 * to the computations individual esi snippets need. Most importantly no body
66 * parsing for most of those of course.
70 class SkinTemplate
extends Skin
{
76 * Name of our skin, it probably needs to be all lower case. Child classes
77 * should override the default.
79 var $skinname = 'monobook';
82 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
83 * are located. Child classes should override the default.
85 var $stylename = 'monobook';
88 * For QuickTemplate, the name of the subclass which will actually fill the
89 * template. Child classes should override the default.
91 var $template = 'QuickTemplate';
94 * Whether this skin use OutputPage::headElement() to generate the "<head>"
97 var $useHeadElement = false;
102 * Add specific styles for this skin
104 * @param $out OutputPage
106 function setupSkinUserCss( OutputPage
$out ) {
107 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
115 * @param $classname String
116 * @param string $repository subdirectory where we keep template files
117 * @param $cache_dir string
118 * @return QuickTemplate
121 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
122 return new $classname();
126 * Generates array of language links for the current page
131 public function getLanguages() {
132 global $wgHideInterlanguageLinks;
133 $out = $this->getOutput();
134 $userLang = $this->getLanguage();
137 $language_urls = array();
139 if ( !$wgHideInterlanguageLinks ) {
140 foreach ( $out->getLanguageLinks() as $languageLinkText ) {
141 $languageLinkParts = explode( ':', $languageLinkText, 2 );
142 $class = 'interwiki-' . $languageLinkParts[0];
143 unset( $languageLinkParts );
144 $languageLinkTitle = Title
::newFromText( $languageLinkText );
145 if ( $languageLinkTitle ) {
146 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
147 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
149 if ( strval( $ilLangName ) === '' ) {
150 $ilLangName = $languageLinkText;
152 $ilLangName = $this->formatLanguageName( $ilLangName );
155 // CLDR extension or similar is required to localize the language name;
156 // otherwise we'll end up with the autonym again.
157 $ilLangLocalName = Language
::fetchLanguageName( $ilInterwikiCode, $userLang->getCode() );
159 $language_urls[] = array(
160 'href' => $languageLinkTitle->getFullURL(),
161 'text' => $ilLangName,
162 'title' => wfMessage( 'tooltip-iwiki', $languageLinkTitle->getText(), $ilLangLocalName )->escaped(),
164 'lang' => wfBCP47( $ilInterwikiCode ),
165 'hreflang' => wfBCP47( $ilInterwikiCode ),
170 return $language_urls;
173 protected function setupTemplateForOutput() {
174 wfProfileIn( __METHOD__
);
176 $request = $this->getRequest();
177 $user = $this->getUser();
178 $title = $this->getTitle();
180 wfProfileIn( __METHOD__
. '-init' );
181 $tpl = $this->setupTemplate( $this->template
, 'skins' );
182 wfProfileOut( __METHOD__
. '-init' );
184 wfProfileIn( __METHOD__
. '-stuff' );
185 $this->thispage
= $title->getPrefixedDBkey();
186 $this->titletxt
= $title->getPrefixedText();
187 $this->userpage
= $user->getUserPage()->getPrefixedText();
189 if ( !$request->wasPosted() ) {
190 $query = $request->getValues();
191 unset( $query['title'] );
192 unset( $query['returnto'] );
193 unset( $query['returntoquery'] );
195 $this->thisquery
= wfArrayToCgi( $query );
196 $this->loggedin
= $user->isLoggedIn();
197 $this->username
= $user->getName();
199 if ( $this->loggedin ||
$this->showIPinHeader() ) {
200 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
202 # This won't be used in the standard skins, but we define it to preserve the interface
203 # To save time, we check for existence
204 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
207 wfProfileOut( __METHOD__
. '-stuff' );
209 wfProfileOut( __METHOD__
);
215 * initialize various variables and generate the template
217 * @param $out OutputPage
219 function outputPage( OutputPage
$out = null ) {
220 wfProfileIn( __METHOD__
);
221 Profiler
::instance()->setTemplated( true );
224 if ( $out !== null ) {
225 // @todo Add wfDeprecated in 1.20
226 $oldContext = $this->getContext();
227 $this->setContext( $out->getContext() );
230 $out = $this->getOutput();
231 $user = $this->getUser();
233 wfProfileIn( __METHOD__
. '-init' );
234 $this->initPage( $out );
235 wfProfileOut( __METHOD__
. '-init' );
236 $tpl = $this->prepareQuickTemplate( $out );
238 wfProfileIn( __METHOD__
. '-execute' );
239 $res = $tpl->execute();
240 wfProfileOut( __METHOD__
. '-execute' );
242 // result may be an error
243 $this->printOrError( $res );
246 $this->setContext( $oldContext );
251 * initialize various variables and generate the template
254 * @param $out OutputPage
255 * @return QuickTemplate the template to be executed by outputPage
257 protected function prepareQuickTemplate( OutputPage
$out = null ) {
258 global $wgContLang, $wgScript, $wgStylePath,
259 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
260 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
261 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
262 $wgScriptPath, $wgServer;
264 $title = $this->getTitle();
265 $request = $this->getRequest();
266 $tpl = $this->setupTemplateForOutput();
268 wfProfileIn( __METHOD__
. '-stuff-head' );
269 if ( !$this->useHeadElement
) {
270 $tpl->set( 'pagecss', false );
271 $tpl->set( 'usercss', false );
273 $tpl->set( 'userjs', false );
274 $tpl->set( 'userjsprev', false );
276 $tpl->set( 'jsvarurl', false );
278 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
279 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
280 $tpl->set( 'html5version', $wgHtml5Version );
281 $tpl->set( 'headlinks', $out->getHeadLinks() );
282 $tpl->set( 'csslinks', $out->buildCssLinks() );
283 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
284 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
286 wfProfileOut( __METHOD__
. '-stuff-head' );
288 wfProfileIn( __METHOD__
. '-stuff2' );
289 $tpl->set( 'title', $out->getPageTitle() );
290 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
291 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
293 $tpl->setRef( 'thispage', $this->thispage
);
294 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
295 $tpl->set( 'titletext', $title->getText() );
296 $tpl->set( 'articleid', $title->getArticleID() );
298 $tpl->set( 'isarticle', $out->isArticle() );
300 $subpagestr = $this->subPageSubtitle();
301 if ( $subpagestr !== '' ) {
302 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
304 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
306 $undelete = $this->getUndeleteLink();
307 if ( $undelete === '' ) {
308 $tpl->set( 'undelete', '' );
310 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
313 $tpl->set( 'catlinks', $this->getCategories() );
314 if ( $out->isSyndicated() ) {
316 foreach ( $out->getSyndicationLinks() as $format => $link ) {
317 $feeds[$format] = array(
318 // Messages: feed-atom, feed-rss
319 'text' => $this->msg( "feed-$format" )->text(),
323 $tpl->setRef( 'feeds', $feeds );
325 $tpl->set( 'feeds', false );
328 $tpl->setRef( 'mimetype', $wgMimeType );
329 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
330 $tpl->set( 'charset', 'UTF-8' );
331 $tpl->setRef( 'wgScript', $wgScript );
332 $tpl->setRef( 'skinname', $this->skinname
);
333 $tpl->set( 'skinclass', get_class( $this ) );
334 $tpl->setRef( 'skin', $this );
335 $tpl->setRef( 'stylename', $this->stylename
);
336 $tpl->set( 'printable', $out->isPrintable() );
337 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
338 $tpl->setRef( 'loggedin', $this->loggedin
);
339 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
340 /* XXX currently unused, might get useful later
341 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
342 $tpl->set( 'exists', $title->getArticleID() != 0 );
343 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
344 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
345 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
347 $tpl->set( 'searchaction', $this->escapeSearchLink() );
348 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
349 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
350 $tpl->setRef( 'stylepath', $wgStylePath );
351 $tpl->setRef( 'articlepath', $wgArticlePath );
352 $tpl->setRef( 'scriptpath', $wgScriptPath );
353 $tpl->setRef( 'serverurl', $wgServer );
354 $tpl->setRef( 'logopath', $wgLogo );
355 $tpl->setRef( 'sitename', $wgSitename );
357 $userLang = $this->getLanguage();
358 $userLangCode = $userLang->getHtmlCode();
359 $userLangDir = $userLang->getDir();
361 $tpl->set( 'lang', $userLangCode );
362 $tpl->set( 'dir', $userLangDir );
363 $tpl->set( 'rtl', $userLang->isRTL() );
365 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
366 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
367 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
368 $tpl->setRef( 'userpage', $this->userpage
);
369 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
370 $tpl->set( 'userlang', $userLangCode );
372 // Users can have their language set differently than the
373 // content of the wiki. For these users, tell the web browser
374 // that interface elements are in a different language.
375 $tpl->set( 'userlangattributes', '' );
376 $tpl->set( 'specialpageattributes', '' ); # obsolete
378 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
379 $escUserlang = htmlspecialchars( $userLangCode );
380 $escUserdir = htmlspecialchars( $userLangDir );
381 // Attributes must be in double quotes because htmlspecialchars() doesn't
382 // escape single quotes
383 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
384 $tpl->set( 'userlangattributes', $attrs );
387 wfProfileOut( __METHOD__
. '-stuff2' );
389 wfProfileIn( __METHOD__
. '-stuff3' );
390 $tpl->set( 'newtalk', $this->getNewtalks() );
391 $tpl->set( 'logo', $this->logoText() );
393 $tpl->set( 'copyright', false );
394 $tpl->set( 'viewcount', false );
395 $tpl->set( 'lastmod', false );
396 $tpl->set( 'credits', false );
397 $tpl->set( 'numberofwatchingusers', false );
398 if ( $out->isArticle() && $title->exists() ) {
399 if ( $this->isRevisionCurrent() ) {
400 if ( !$wgDisableCounters ) {
401 $viewcount = $this->getWikiPage()->getCount();
403 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
407 if ( $wgPageShowWatchingUsers ) {
408 $dbr = wfGetDB( DB_SLAVE
);
409 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
410 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
414 $tpl->set( 'numberofwatchingusers',
415 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
420 if ( $wgMaxCredits != 0 ) {
421 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
422 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
424 $tpl->set( 'lastmod', $this->lastModified() );
427 $tpl->set( 'copyright', $this->getCopyright() );
429 wfProfileOut( __METHOD__
. '-stuff3' );
431 wfProfileIn( __METHOD__
. '-stuff4' );
432 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
433 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
434 $tpl->set( 'disclaimer', $this->disclaimerLink() );
435 $tpl->set( 'privacy', $this->privacyLink() );
436 $tpl->set( 'about', $this->aboutLink() );
438 $tpl->set( 'footerlinks', array(
442 'numberofwatchingusers',
453 global $wgFooterIcons;
454 $tpl->set( 'footericons', $wgFooterIcons );
455 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
456 if ( count( $footerIconsBlock ) > 0 ) {
457 foreach ( $footerIconsBlock as &$footerIcon ) {
458 if ( isset( $footerIcon['src'] ) ) {
459 if ( !isset( $footerIcon['width'] ) ) {
460 $footerIcon['width'] = 88;
462 if ( !isset( $footerIcon['height'] ) ) {
463 $footerIcon['height'] = 31;
468 unset( $tpl->data
['footericons'][$footerIconsKey] );
472 $tpl->set( 'sitenotice', $this->getSiteNotice() );
473 $tpl->set( 'bottomscripts', $this->bottomScripts() );
474 $tpl->set( 'printfooter', $this->printSource() );
476 # An ID that includes the actual body text; without categories, contentSub, ...
477 $realBodyAttribs = array( 'id' => 'mw-content-text' );
479 # Add a mw-content-ltr/rtl class to be able to style based on text direction
480 # when the content is different from the UI language, i.e.:
481 # not for special pages or file pages AND only when viewing AND if the page exists
482 # (or is in MW namespace, because that has default content)
483 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
484 Action
::getActionName( $this ) === 'view' &&
485 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
486 $pageLang = $title->getPageViewLanguage();
487 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
488 $realBodyAttribs['dir'] = $pageLang->getDir();
489 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
492 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
493 $tpl->setRef( 'bodytext', $out->mBodytext
);
495 $language_urls = $this->getLanguages();
496 if ( count( $language_urls ) ) {
497 $tpl->setRef( 'language_urls', $language_urls );
499 $tpl->set( 'language_urls', false );
501 wfProfileOut( __METHOD__
. '-stuff4' );
503 wfProfileIn( __METHOD__
. '-stuff5' );
505 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
506 $content_navigation = $this->buildContentNavigationUrls();
507 $content_actions = $this->buildContentActionUrls( $content_navigation );
508 $tpl->setRef( 'content_navigation', $content_navigation );
509 $tpl->setRef( 'content_actions', $content_actions );
511 $tpl->set( 'sidebar', $this->buildSidebar() );
512 $tpl->set( 'nav_urls', $this->buildNavUrls() );
514 // Set the head scripts near the end, in case the above actions resulted in added scripts
515 if ( $this->useHeadElement
) {
516 $tpl->set( 'headelement', $out->headElement( $this ) );
518 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
521 $tpl->set( 'debug', '' );
522 $tpl->set( 'debughtml', $this->generateDebugHTML() );
523 $tpl->set( 'reporttime', wfReportTime() );
525 // original version by hansm
526 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
527 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
530 // Set the bodytext to another key so that skins can just output it on it's own
531 // and output printfooter and debughtml separately
532 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
534 // Append printfooter and debughtml onto bodytext so that skins that were already
535 // using bodytext before they were split out don't suddenly start not outputting information
536 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
537 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
539 // allow extensions adding stuff after the page content.
540 // See Skin::afterContentHook() for further documentation.
541 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
542 wfProfileOut( __METHOD__
. '-stuff5' );
544 wfProfileOut( __METHOD__
);
549 * Get the HTML for the p-personal list
552 public function getPersonalToolsList() {
553 $tpl = $this->setupTemplateForOutput();
554 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
556 foreach ( $tpl->getPersonalTools() as $key => $item ) {
557 $html .= $tpl->makeListItem( $key, $item );
563 * Format language name for use in sidebar interlanguage links list.
564 * By default it is capitalized.
566 * @param string $name Language name, e.g. "English" or "español"
570 function formatLanguageName( $name ) {
571 return $this->getLanguage()->ucfirst( $name );
575 * Output the string, or print error message if it's
576 * an error object of the appropriate type.
577 * For the base class, assume strings all around.
582 function printOrError( $str ) {
587 * Output a boolean indicating if buildPersonalUrls should output separate
588 * login and create account links or output a combined link
589 * By default we simply return a global config setting that affects most skins
590 * This is setup as a method so that like with $wgLogo and getLogo() a skin
591 * can override this setting and always output one or the other if it has
592 * a reason it can't output one of the two modes.
595 function useCombinedLoginLink() {
596 global $wgUseCombinedLoginLink;
597 return $wgUseCombinedLoginLink;
601 * build array of urls for personal toolbar
604 protected function buildPersonalUrls() {
605 $title = $this->getTitle();
606 $request = $this->getRequest();
607 $pageurl = $title->getLocalURL();
608 wfProfileIn( __METHOD__
);
610 /* set up the default links for the personal toolbar */
611 $personal_urls = array();
613 # Due to bug 32276, if a user does not have read permissions,
614 # $this->getTitle() will just give Special:Badtitle, which is
615 # not especially useful as a returnto parameter. Use the title
616 # from the request instead, if there was one.
617 if ( $this->getUser()->isAllowed( 'read' ) ) {
618 $page = $this->getTitle();
620 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
622 $page = $request->getVal( 'returnto', $page );
624 if ( strval( $page ) !== '' ) {
625 $a['returnto'] = $page;
626 $query = $request->getVal( 'returntoquery', $this->thisquery
);
627 if ( $query != '' ) {
628 $a['returntoquery'] = $query;
632 $returnto = wfArrayToCgi( $a );
633 if ( $this->loggedin
) {
634 $personal_urls['userpage'] = array(
635 'text' => $this->username
,
636 'href' => &$this->userpageUrlDetails
['href'],
637 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
638 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
641 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
642 $personal_urls['mytalk'] = array(
643 'text' => $this->msg( 'mytalk' )->text(),
644 'href' => &$usertalkUrlDetails['href'],
645 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
646 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
648 $href = self
::makeSpecialUrl( 'Preferences' );
649 $personal_urls['preferences'] = array(
650 'text' => $this->msg( 'mypreferences' )->text(),
652 'active' => ( $href == $pageurl )
655 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
656 $href = self
::makeSpecialUrl( 'Watchlist' );
657 $personal_urls['watchlist'] = array(
658 'text' => $this->msg( 'mywatchlist' )->text(),
660 'active' => ( $href == $pageurl )
664 # We need to do an explicit check for Special:Contributions, as we
665 # have to match both the title, and the target, which could come
666 # from request values (Special:Contributions?target=Jimbo_Wales)
667 # or be specified in "sub page" form
668 # (Special:Contributions/Jimbo_Wales). The plot
669 # thickens, because the Title object is altered for special pages,
670 # so it doesn't contain the original alias-with-subpage.
671 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
672 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
673 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
674 $active = $spName == 'Contributions'
675 && ( ( $spPar && $spPar == $this->username
)
676 ||
$request->getText( 'target' ) == $this->username
);
681 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
682 $personal_urls['mycontris'] = array(
683 'text' => $this->msg( 'mycontris' )->text(),
687 $personal_urls['logout'] = array(
688 'text' => $this->msg( 'userlogout' )->text(),
689 'href' => self
::makeSpecialUrl( 'Userlogout',
690 // userlogout link must always contain an & character, otherwise we might not be able
691 // to detect a buggy precaching proxy (bug 17790)
692 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
697 $useCombinedLoginLink = $this->useCombinedLoginLink();
698 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
699 ?
'nav-login-createaccount'
701 $is_signup = $request->getText( 'type' ) == 'signup';
703 $login_id = $this->showIPinHeader() ?
'anonlogin' : 'login';
705 'text' => $this->msg( $loginlink )->text(),
706 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
707 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
709 $createaccount_url = array(
710 'text' => $this->msg( 'createaccount' )->text(),
711 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
712 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
715 if ( $this->showIPinHeader() ) {
716 $href = &$this->userpageUrlDetails
['href'];
717 $personal_urls['anonuserpage'] = array(
718 'text' => $this->username
,
720 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
721 'active' => ( $pageurl == $href )
723 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
724 $href = &$usertalkUrlDetails['href'];
725 $personal_urls['anontalk'] = array(
726 'text' => $this->msg( 'anontalk' )->text(),
728 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
729 'active' => ( $pageurl == $href )
733 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
734 $personal_urls['createaccount'] = $createaccount_url;
737 $personal_urls[$login_id] = $login_url;
740 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
741 wfProfileOut( __METHOD__
);
742 return $personal_urls;
746 * Builds an array with tab definition
748 * @param Title $title page where the tab links to
749 * @param string|array $message message key or an array of message keys (will fall back)
750 * @param boolean $selected display the tab as selected
751 * @param string $query query string attached to tab URL
752 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
756 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
759 $classes[] = 'selected';
761 if ( $checkEdit && !$title->isKnown() ) {
763 if ( $query !== '' ) {
764 $query = 'action=edit&redlink=1&' . $query;
766 $query = 'action=edit&redlink=1';
770 // wfMessageFallback will nicely accept $message as an array of fallbacks
771 // or just a single key
772 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
773 if ( is_array( $message ) ) {
774 // for hook compatibility just keep the last message name
775 $message = end( $message );
777 if ( $msg->exists() ) {
778 $text = $msg->text();
781 $text = $wgContLang->getFormattedNsText(
782 MWNamespace
::getSubject( $title->getNamespace() ) );
786 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
787 $title, $message, $selected, $checkEdit,
788 &$classes, &$query, &$text, &$result ) ) ) {
793 'class' => implode( ' ', $classes ),
795 'href' => $title->getLocalURL( $query ),
799 function makeTalkUrlDetails( $name, $urlaction = '' ) {
800 $title = Title
::newFromText( $name );
801 if ( !is_object( $title ) ) {
802 throw new MWException( __METHOD__
. " given invalid pagename $name" );
804 $title = $title->getTalkPage();
805 self
::checkTitle( $title, $name );
807 'href' => $title->getLocalURL( $urlaction ),
808 'exists' => $title->getArticleID() != 0,
812 function makeArticleUrlDetails( $name, $urlaction = '' ) {
813 $title = Title
::newFromText( $name );
814 $title = $title->getSubjectPage();
815 self
::checkTitle( $title, $name );
817 'href' => $title->getLocalURL( $urlaction ),
818 'exists' => $title->getArticleID() != 0,
823 * a structured array of links usually used for the tabs in a skin
825 * There are 4 standard sections
826 * namespaces: Used for namespace tabs like special, page, and talk namespaces
827 * views: Used for primary page views like read, edit, history
828 * actions: Used for most extra page actions like deletion, protection, etc...
829 * variants: Used to list the language variants for the page
831 * Each section's value is a key/value array of links for that section.
832 * The links themselves have these common keys:
833 * - class: The css classes to apply to the tab
834 * - text: The text to display on the tab
835 * - href: The href for the tab to point to
836 * - rel: An optional rel= for the tab's link
837 * - redundant: If true the tab will be dropped in skins using content_actions
838 * this is useful for tabs like "Read" which only have meaning in skins that
839 * take special meaning from the grouped structure of content_navigation
841 * Views also have an extra key which can be used:
842 * - primary: If this is not true skins like vector may try to hide the tab
843 * when the user has limited space in their browser window
845 * content_navigation using code also expects these ids to be present on the
846 * links, however these are usually automatically generated by SkinTemplate
847 * itself and are not necessary when using a hook. The only things these may
848 * matter to are people modifying content_navigation after it's initial creation:
849 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
850 * - tooltiponly: This is set to true for some tabs in cases where the system
851 * believes that the accesskey should not be added to the tab.
855 protected function buildContentNavigationUrls() {
856 global $wgDisableLangConversion;
858 wfProfileIn( __METHOD__
);
860 // Display tabs for the relevant title rather than always the title itself
861 $title = $this->getRelevantTitle();
862 $onPage = $title->equals( $this->getTitle() );
864 $out = $this->getOutput();
865 $request = $this->getRequest();
866 $user = $this->getUser();
868 $content_navigation = array(
869 'namespaces' => array(),
871 'actions' => array(),
872 'variants' => array()
876 $action = $request->getVal( 'action', 'view' );
878 $userCanRead = $title->quickUserCan( 'read', $user );
880 $preventActiveTabs = false;
881 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
883 // Checks if page is some kind of content
884 if ( $title->canExist() ) {
885 // Gets page objects for the related namespaces
886 $subjectPage = $title->getSubjectPage();
887 $talkPage = $title->getTalkPage();
889 // Determines if this is a talk page
890 $isTalk = $title->isTalkPage();
892 // Generates XML IDs from namespace names
893 $subjectId = $title->getNamespaceKey( '' );
895 if ( $subjectId == 'main' ) {
898 $talkId = "{$subjectId}_talk";
901 $skname = $this->skinname
;
903 // Adds namespace links
904 $subjectMsg = array( "nstab-$subjectId" );
905 if ( $subjectPage->isMainPage() ) {
906 array_unshift( $subjectMsg, 'mainpage-nstab' );
908 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
909 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
911 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
912 $content_navigation['namespaces'][$talkId] = $this->tabAction(
913 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
915 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
917 if ( $userCanRead ) {
918 // Adds view view link
919 if ( $title->exists() ) {
920 $content_navigation['views']['view'] = $this->tabAction(
921 $isTalk ?
$talkPage : $subjectPage,
922 array( "$skname-view-view", 'view' ),
923 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
925 // signal to hide this from simple content_actions
926 $content_navigation['views']['view']['redundant'] = true;
929 wfProfileIn( __METHOD__
. '-edit' );
931 // Checks if user can edit the current page if it exists or create it otherwise
932 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
933 // Builds CSS class for talk page links
934 $isTalkClass = $isTalk ?
' istalk' : '';
935 // Whether the user is editing the page
936 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
937 // Whether to show the "Add a new section" tab
938 // Checks if this is a current rev of talk page and is not forced to be hidden
939 $showNewSection = !$out->forceHideNewSectionLink()
940 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
941 $section = $request->getVal( 'section' );
943 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
945 $content_navigation['views']['edit'] = array(
946 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
947 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
948 'href' => $title->getLocalURL( $this->editUrlOptions() ),
949 'primary' => true, // don't collapse this in vector
953 if ( $showNewSection ) {
954 // Adds new section link
955 //$content_navigation['actions']['addsection']
956 $content_navigation['views']['addsection'] = array(
957 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
958 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
959 'href' => $title->getLocalURL( 'action=edit§ion=new' )
962 // Checks if the page has some kind of viewable content
963 } elseif ( $title->hasSourceText() ) {
964 // Adds view source view link
965 $content_navigation['views']['viewsource'] = array(
966 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
967 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
968 'href' => $title->getLocalURL( $this->editUrlOptions() ),
969 'primary' => true, // don't collapse this in vector
972 wfProfileOut( __METHOD__
. '-edit' );
974 wfProfileIn( __METHOD__
. '-live' );
975 // Checks if the page exists
976 if ( $title->exists() ) {
977 // Adds history view link
978 $content_navigation['views']['history'] = array(
979 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
980 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
981 'href' => $title->getLocalURL( 'action=history' ),
985 if ( $title->quickUserCan( 'delete', $user ) ) {
986 $content_navigation['actions']['delete'] = array(
987 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
988 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
989 'href' => $title->getLocalURL( 'action=delete' )
993 if ( $title->quickUserCan( 'move', $user ) ) {
994 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
995 $content_navigation['actions']['move'] = array(
996 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
997 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
998 'href' => $moveTitle->getLocalURL()
1002 // article doesn't exist or is deleted
1003 if ( $user->isAllowed( 'deletedhistory' ) ) {
1004 $n = $title->isDeleted();
1006 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1007 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1008 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1009 $content_navigation['actions']['undelete'] = array(
1010 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1011 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1012 ->setContext( $this->getContext() )->numParams( $n )->text(),
1013 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1019 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
1020 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1021 $content_navigation['actions'][$mode] = array(
1022 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1023 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1024 'href' => $title->getLocalURL( "action=$mode" )
1028 wfProfileOut( __METHOD__
. '-live' );
1030 // Checks if the user is logged in
1031 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1033 * The following actions use messages which, if made particular to
1034 * the any specific skins, would break the Ajax code which makes this
1035 * action happen entirely inline. Skin::makeGlobalVariablesScript
1036 * defines a set of messages in a javascript object - and these
1037 * messages are assumed to be global for all skins. Without making
1038 * a change to that procedure these messages will have to remain as
1039 * the global versions.
1041 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1042 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1043 $content_navigation['actions'][$mode] = array(
1044 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1045 // uses 'watch' or 'unwatch' message
1046 'text' => $this->msg( $mode )->text(),
1047 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1052 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1054 if ( $userCanRead && !$wgDisableLangConversion ) {
1055 $pageLang = $title->getPageLanguage();
1056 // Gets list of language variants
1057 $variants = $pageLang->getVariants();
1058 // Checks that language conversion is enabled and variants exist
1059 // And if it is not in the special namespace
1060 if ( count( $variants ) > 1 ) {
1061 // Gets preferred variant (note that user preference is
1062 // only possible for wiki content language variant)
1063 $preferred = $pageLang->getPreferredVariant();
1064 if ( Action
::getActionName( $this ) === 'view' ) {
1065 $params = $request->getQueryValues();
1066 unset( $params['title'] );
1070 // Loops over each variant
1071 foreach ( $variants as $code ) {
1072 // Gets variant name from language code
1073 $varname = $pageLang->getVariantname( $code );
1074 // Appends variant link
1075 $content_navigation['variants'][] = array(
1076 'class' => ( $code == $preferred ) ?
'selected' : false,
1078 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1079 'lang' => wfBCP47( $code ),
1080 'hreflang' => wfBCP47( $code ),
1086 // If it's not content, it's got to be a special page
1087 $content_navigation['namespaces']['special'] = array(
1088 'class' => 'selected',
1089 'text' => $this->msg( 'nstab-special' )->text(),
1090 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1091 'context' => 'subject'
1094 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1095 array( &$this, &$content_navigation ) );
1098 // Equiv to SkinTemplateContentActions
1099 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1101 // Setup xml ids and tooltip info
1102 foreach ( $content_navigation as $section => &$links ) {
1103 foreach ( $links as $key => &$link ) {
1105 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1106 $xmlID = 'ca-nstab-' . $xmlID;
1107 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1109 } elseif ( $section == 'variants' ) {
1110 $xmlID = 'ca-varlang-' . $xmlID;
1112 $xmlID = 'ca-' . $xmlID;
1114 $link['id'] = $xmlID;
1118 # We don't want to give the watch tab an accesskey if the
1119 # page is being edited, because that conflicts with the
1120 # accesskey on the watch checkbox. We also don't want to
1121 # give the edit tab an accesskey, because that's fairly
1122 # superfluous and conflicts with an accesskey (Ctrl-E) often
1123 # used for editing in Safari.
1124 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1125 if ( isset( $content_navigation['views']['edit'] ) ) {
1126 $content_navigation['views']['edit']['tooltiponly'] = true;
1128 if ( isset( $content_navigation['actions']['watch'] ) ) {
1129 $content_navigation['actions']['watch']['tooltiponly'] = true;
1131 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1132 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1136 wfProfileOut( __METHOD__
);
1138 return $content_navigation;
1142 * an array of edit links by default used for the tabs
1146 function buildContentActionUrls( $content_navigation ) {
1148 wfProfileIn( __METHOD__
);
1150 // content_actions has been replaced with content_navigation for backwards
1151 // compatibility and also for skins that just want simple tabs content_actions
1152 // is now built by flattening the content_navigation arrays into one
1154 $content_actions = array();
1156 foreach ( $content_navigation as $links ) {
1158 foreach ( $links as $key => $value ) {
1160 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1161 // Redundant tabs are dropped from content_actions
1165 // content_actions used to have ids built using the "ca-$key" pattern
1166 // so the xmlID based id is much closer to the actual $key that we want
1167 // for that reason we'll just strip out the ca- if present and use
1168 // the latter potion of the "id" as the $key
1169 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1170 $key = substr( $value['id'], 3 );
1173 if ( isset( $content_actions[$key] ) ) {
1174 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1178 $content_actions[$key] = $value;
1184 wfProfileOut( __METHOD__
);
1186 return $content_actions;
1190 * build array of common navigation links
1194 protected function buildNavUrls() {
1195 global $wgUploadNavigationUrl;
1197 wfProfileIn( __METHOD__
);
1199 $out = $this->getOutput();
1200 $request = $this->getRequest();
1202 $nav_urls = array();
1203 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1204 if ( $wgUploadNavigationUrl ) {
1205 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1206 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1207 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1209 $nav_urls['upload'] = false;
1211 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1213 $nav_urls['print'] = false;
1214 $nav_urls['permalink'] = false;
1215 $nav_urls['info'] = false;
1216 $nav_urls['whatlinkshere'] = false;
1217 $nav_urls['recentchangeslinked'] = false;
1218 $nav_urls['contributions'] = false;
1219 $nav_urls['log'] = false;
1220 $nav_urls['blockip'] = false;
1221 $nav_urls['emailuser'] = false;
1222 $nav_urls['userrights'] = false;
1224 // A print stylesheet is attached to all pages, but nobody ever
1225 // figures that out. :) Add a link...
1226 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1227 $nav_urls['print'] = array(
1228 'text' => $this->msg( 'printableversion' )->text(),
1229 'href' => $this->getTitle()->getLocalURL(
1230 $request->appendQueryValue( 'printable', 'yes', true ) )
1234 if ( $out->isArticle() ) {
1235 // Also add a "permalink" while we're at it
1236 $revid = $this->getRevisionId();
1238 $nav_urls['permalink'] = array(
1239 'text' => $this->msg( 'permalink' )->text(),
1240 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1244 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1245 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1246 array( &$this, &$nav_urls, &$revid, &$revid ) );
1249 if ( $out->isArticleRelated() ) {
1250 $nav_urls['whatlinkshere'] = array(
1251 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1254 $nav_urls['info'] = array(
1255 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1256 'href' => $this->getTitle()->getLocalURL( "action=info" )
1259 if ( $this->getTitle()->getArticleID() ) {
1260 $nav_urls['recentchangeslinked'] = array(
1261 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1266 $user = $this->getRelevantUser();
1268 $rootUser = $user->getName();
1270 $nav_urls['contributions'] = array(
1271 'text' => $this->msg( 'contributions', $rootUser )->text(),
1272 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1275 $nav_urls['log'] = array(
1276 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1279 if ( $this->getUser()->isAllowed( 'block' ) ) {
1280 $nav_urls['blockip'] = array(
1281 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1285 if ( $this->showEmailUser( $user ) ) {
1286 $nav_urls['emailuser'] = array(
1287 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1291 if ( !$user->isAnon() ) {
1292 $sur = new UserrightsPage
;
1293 $sur->setContext( $this->getContext() );
1294 if ( $sur->userCanExecute( $this->getUser() ) ) {
1295 $nav_urls['userrights'] = array(
1296 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1302 wfProfileOut( __METHOD__
);
1307 * Generate strings used for xml 'id' names
1311 function getNameSpaceKey() {
1312 return $this->getTitle()->getNamespaceKey();
1317 * Generic wrapper for template functions, with interface
1318 * compatible with what we use of PHPTAL 0.7.
1321 abstract class QuickTemplate
{
1325 function __construct() {
1326 $this->data
= array();
1327 $this->translator
= new MediaWiki_I18N();
1331 * Sets the value $value to $name
1335 public function set( $name, $value ) {
1336 $this->data
[$name] = $value;
1340 * Gets the template data requested
1342 * @param string $name Key for the data
1343 * @param mixed $default Optional default (or null)
1344 * @return mixed The value of the data requested or the deafult
1346 public function get( $name, $default = null ) {
1347 if ( isset( $this->data
[$name] ) ) {
1348 return $this->data
[$name];
1358 public function setRef( $name, &$value ) {
1359 $this->data
[$name] =& $value;
1365 public function setTranslator( &$t ) {
1366 $this->translator
= &$t;
1370 * Main function, used by classes that subclass QuickTemplate
1371 * to show the actual HTML output
1373 abstract public function execute();
1378 function text( $str ) {
1379 echo htmlspecialchars( $this->data
[$str] );
1384 * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
1386 function jstext( $str ) {
1387 wfDeprecated( __METHOD__
, '1.21' );
1388 echo Xml
::escapeJsString( $this->data
[$str] );
1394 function html( $str ) {
1395 echo $this->data
[$str];
1401 function msg( $str ) {
1402 echo htmlspecialchars( $this->translator
->translate( $str ) );
1408 function msgHtml( $str ) {
1409 echo $this->translator
->translate( $str );
1413 * An ugly, ugly hack.
1416 function msgWiki( $str ) {
1419 $text = $this->translator
->translate( $str );
1420 echo $wgOut->parse( $text );
1427 function haveData( $str ) {
1428 return isset( $this->data
[$str] );
1436 function haveMsg( $str ) {
1437 $msg = $this->translator
->translate( $str );
1438 return ( $msg != '-' ) && ( $msg != '' ); # ????
1442 * Get the Skin object related to this object
1444 * @return Skin object
1446 public function getSkin() {
1447 return $this->data
['skin'];
1452 * New base template for a skin's template extended from QuickTemplate
1453 * this class features helper methods that provide common ways of interacting
1454 * with the data stored in the QuickTemplate
1456 abstract class BaseTemplate
extends QuickTemplate
{
1459 * Get a Message object with its context set
1461 * @param string $name message name
1464 public function getMsg( $name ) {
1465 return $this->getSkin()->msg( $name );
1468 function msg( $str ) {
1469 echo $this->getMsg( $str )->escaped();
1472 function msgHtml( $str ) {
1473 echo $this->getMsg( $str )->text();
1476 function msgWiki( $str ) {
1477 echo $this->getMsg( $str )->parseAsBlock();
1481 * Create an array of common toolbox items from the data in the quicktemplate
1482 * stored by SkinTemplate.
1483 * The resulting array is built according to a format intended to be passed
1484 * through makeListItem to generate the html.
1487 function getToolbox() {
1488 wfProfileIn( __METHOD__
);
1491 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1492 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1493 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1495 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1496 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1497 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1498 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1500 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1501 $toolbox['feeds']['id'] = 'feedlinks';
1502 $toolbox['feeds']['links'] = array();
1503 foreach ( $this->data
['feeds'] as $key => $feed ) {
1504 $toolbox['feeds']['links'][$key] = $feed;
1505 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1506 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1507 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1508 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1511 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1512 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1513 $toolbox[$special] = $this->data
['nav_urls'][$special];
1514 $toolbox[$special]['id'] = "t-$special";
1517 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1518 $toolbox['print'] = $this->data
['nav_urls']['print'];
1519 $toolbox['print']['id'] = 't-print';
1520 $toolbox['print']['rel'] = 'alternate';
1521 $toolbox['print']['msg'] = 'printableversion';
1523 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1524 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1525 if ( $toolbox['permalink']['href'] === '' ) {
1526 unset( $toolbox['permalink']['href'] );
1527 $toolbox['ispermalink']['tooltiponly'] = true;
1528 $toolbox['ispermalink']['id'] = 't-ispermalink';
1529 $toolbox['ispermalink']['msg'] = 'permalink';
1531 $toolbox['permalink']['id'] = 't-permalink';
1534 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1535 $toolbox['info'] = $this->data
['nav_urls']['info'];
1536 $toolbox['info']['id'] = 't-info';
1539 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1540 wfProfileOut( __METHOD__
);
1545 * Create an array of personal tools items from the data in the quicktemplate
1546 * stored by SkinTemplate.
1547 * The resulting array is built according to a format intended to be passed
1548 * through makeListItem to generate the html.
1549 * This is in reality the same list as already stored in personal_urls
1550 * however it is reformatted so that you can just pass the individual items
1551 * to makeListItem instead of hardcoding the element creation boilerplate.
1554 function getPersonalTools() {
1555 $personal_tools = array();
1556 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1557 # The class on a personal_urls item is meant to go on the <a> instead
1558 # of the <li> so we have to use a single item "links" array instead
1559 # of using most of the personal_url's keys directly.
1562 array( 'single-id' => "pt-$key" ),
1566 if ( isset( $plink['active'] ) ) {
1567 $ptool['active'] = $plink['active'];
1569 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1570 if ( isset( $plink[$k] ) ) {
1571 $ptool['links'][0][$k] = $plink[$k];
1574 $personal_tools[$key] = $ptool;
1576 return $personal_tools;
1579 function getSidebar( $options = array() ) {
1580 // Force the rendering of the following portals
1581 $sidebar = $this->data
['sidebar'];
1582 if ( !isset( $sidebar['SEARCH'] ) ) {
1583 $sidebar['SEARCH'] = true;
1585 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1586 $sidebar['TOOLBOX'] = true;
1588 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1589 $sidebar['LANGUAGES'] = true;
1592 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1593 unset( $sidebar['SEARCH'] );
1595 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1596 unset( $sidebar['TOOLBOX'] );
1598 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1599 unset( $sidebar['LANGUAGES'] );
1603 foreach ( $sidebar as $boxName => $content ) {
1604 if ( $content === false ) {
1607 switch ( $boxName ) {
1609 // Search is a special case, skins should custom implement this
1610 $boxes[$boxName] = array(
1612 'header' => $this->getMsg( 'search' )->text(),
1613 'generated' => false,
1618 $msgObj = $this->getMsg( 'toolbox' );
1619 $boxes[$boxName] = array(
1621 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1622 'generated' => false,
1623 'content' => $this->getToolbox(),
1627 if ( $this->data
['language_urls'] ) {
1628 $msgObj = $this->getMsg( 'otherlanguages' );
1629 $boxes[$boxName] = array(
1631 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1632 'generated' => false,
1633 'content' => $this->data
['language_urls'],
1638 $msgObj = $this->getMsg( $boxName );
1639 $boxes[$boxName] = array(
1640 'id' => "p-$boxName",
1641 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1642 'generated' => true,
1643 'content' => $content,
1649 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1650 $hookContents = null;
1651 if ( isset( $boxes['TOOLBOX'] ) ) {
1653 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1654 // can abort and avoid outputting double toolbox links
1655 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1656 $hookContents = ob_get_contents();
1658 if ( !trim( $hookContents ) ) {
1659 $hookContents = null;
1664 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1665 foreach ( $boxes as $boxName => $box ) {
1666 if ( is_array( $box['content'] ) ) {
1668 foreach ( $box['content'] as $key => $val ) {
1669 $content .= "\n " . $this->makeListItem( $key, $val );
1671 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1672 if ( $hookContents ) {
1673 $content .= "\n $hookContents";
1676 $content .= "\n</ul>\n";
1677 $boxes[$boxName]['content'] = $content;
1681 if ( $hookContents ) {
1682 $boxes['TOOLBOXEND'] = array(
1683 'id' => 'p-toolboxend',
1684 'header' => $boxes['TOOLBOX']['header'],
1685 'generated' => false,
1686 'content' => "<ul>{$hookContents}</ul>",
1688 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1690 foreach ( $boxes as $key => $box ) {
1691 if ( $key === 'TOOLBOXEND' ) {
1694 $boxes2[$key] = $box;
1695 if ( $key === 'TOOLBOX' ) {
1696 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1708 * Makes a link, usually used by makeListItem to generate a link for an item
1709 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1711 * @param string $key usually a key from the list you are generating this
1713 * @param array $item contains some of a specific set of keys.
1715 * The text of the link will be generated either from the contents of the
1716 * "text" key in the $item array, if a "msg" key is present a message by
1717 * that name will be used, and if neither of those are set the $key will be
1718 * used as a message name.
1720 * If a "href" key is not present makeLink will just output htmlescaped text.
1721 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1722 * for the link if present.
1724 * If an "id" or "single-id" (if you don't want the actual id to be output
1725 * on the link) is present it will be used to generate a tooltip and
1726 * accesskey for the link.
1728 * The keys "context" and "primary" are ignored; these keys are used
1729 * internally by skins and are not supposed to be included in the HTML
1732 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1734 * @param array $options can be used to affect the output of a link.
1735 * Possible options are:
1736 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1737 * a link in. This should be an array of arrays containing a 'tag' and
1738 * optionally an 'attributes' key. If you only have one element you don't
1739 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1740 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1742 * - 'link-class' key can be used to specify additional classes to apply
1744 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1745 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1746 * any non-link will output a "<span>" instead of just text.
1750 function makeLink( $key, $item, $options = array() ) {
1751 if ( isset( $item['text'] ) ) {
1752 $text = $item['text'];
1754 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1757 $html = htmlspecialchars( $text );
1759 if ( isset( $options['text-wrapper'] ) ) {
1760 $wrapper = $options['text-wrapper'];
1761 if ( isset( $wrapper['tag'] ) ) {
1762 $wrapper = array( $wrapper );
1764 while ( count( $wrapper ) > 0 ) {
1765 $element = array_pop( $wrapper );
1766 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1770 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1772 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1773 unset( $attrs[$k] );
1776 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1777 $item['single-id'] = $item['id'];
1779 if ( isset( $item['single-id'] ) ) {
1780 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1781 $title = Linker
::titleAttrib( $item['single-id'] );
1782 if ( $title !== false ) {
1783 $attrs['title'] = $title;
1786 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1787 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1788 $attrs['title'] = $tip['title'];
1790 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1791 $attrs['accesskey'] = $tip['accesskey'];
1795 if ( isset( $options['link-class'] ) ) {
1796 if ( isset( $attrs['class'] ) ) {
1797 $attrs['class'] .= " {$options['link-class']}";
1799 $attrs['class'] = $options['link-class'];
1802 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1809 * Generates a list item for a navigation, portlet, portal, sidebar... list
1811 * @param $key string, usually a key from the list you are generating this link from.
1812 * @param $item array, of list item data containing some of a specific set of keys.
1813 * The "id" and "class" keys will be used as attributes for the list item,
1814 * if "active" contains a value of true a "active" class will also be appended to class.
1816 * @param $options array
1818 * If you want something other than a "<li>" you can pass a tag name such as
1819 * "tag" => "span" in the $options array to change the tag used.
1820 * link/content data for the list item may come in one of two forms
1821 * A "links" key may be used, in which case it should contain an array with
1822 * a list of links to include inside the list item, see makeLink for the
1823 * format of individual links array items.
1825 * Otherwise the relevant keys from the list item $item array will be passed
1826 * to makeLink instead. Note however that "id" and "class" are used by the
1827 * list item directly so they will not be passed to makeLink
1828 * (however the link will still support a tooltip and accesskey from it)
1829 * If you need an id or class on a single link you should include a "links"
1830 * array with just one link item inside of it.
1831 * $options is also passed on to makeLink calls
1835 function makeListItem( $key, $item, $options = array() ) {
1836 if ( isset( $item['links'] ) ) {
1838 foreach ( $item['links'] as $linkKey => $link ) {
1839 $html .= $this->makeLink( $linkKey, $link, $options );
1843 // These keys are used by makeListItem and shouldn't be passed on to the link
1844 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1847 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1848 // The id goes on the <li> not on the <a> for single links
1849 // but makeSidebarLink still needs to know what id to use when
1850 // generating tooltips and accesskeys.
1851 $link['single-id'] = $item['id'];
1853 $html = $this->makeLink( $key, $link, $options );
1857 foreach ( array( 'id', 'class' ) as $attr ) {
1858 if ( isset( $item[$attr] ) ) {
1859 $attrs[$attr] = $item[$attr];
1862 if ( isset( $item['active'] ) && $item['active'] ) {
1863 if ( !isset( $attrs['class'] ) ) {
1864 $attrs['class'] = '';
1866 $attrs['class'] .= ' active';
1867 $attrs['class'] = trim( $attrs['class'] );
1869 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1872 function makeSearchInput( $attrs = array() ) {
1876 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1877 'value' => $this->get( 'search', '' ),
1879 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1880 return Html
::element( 'input', $realAttrs );
1883 function makeSearchButton( $mode, $attrs = array() ) {
1890 'value' => $this->translator
->translate(
1891 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1893 $realAttrs = array_merge(
1895 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1898 return Html
::element( 'input', $realAttrs );
1900 $buttonAttrs = array(
1904 $buttonAttrs = array_merge(
1906 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1909 unset( $buttonAttrs['src'] );
1910 unset( $buttonAttrs['alt'] );
1911 unset( $buttonAttrs['width'] );
1912 unset( $buttonAttrs['height'] );
1914 'src' => $attrs['src'],
1915 'alt' => isset( $attrs['alt'] )
1917 : $this->translator
->translate( 'searchbutton' ),
1918 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1919 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1921 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1923 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1928 * Returns an array of footerlinks trimmed down to only those footer links that
1930 * If you pass "flat" as an option then the returned array will be a flat array
1931 * of footer icons instead of a key/value array of footerlinks arrays broken
1932 * up into categories.
1933 * @return array|mixed
1935 function getFooterLinks( $option = null ) {
1936 $footerlinks = $this->get( 'footerlinks' );
1938 // Reduce footer links down to only those which are being used
1939 $validFooterLinks = array();
1940 foreach ( $footerlinks as $category => $links ) {
1941 $validFooterLinks[$category] = array();
1942 foreach ( $links as $link ) {
1943 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1944 $validFooterLinks[$category][] = $link;
1947 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1948 unset( $validFooterLinks[$category] );
1952 if ( $option == 'flat' ) {
1953 // fold footerlinks into a single array using a bit of trickery
1954 $validFooterLinks = call_user_func_array(
1956 array_values( $validFooterLinks )
1960 return $validFooterLinks;
1964 * Returns an array of footer icons filtered down by options relevant to how
1965 * the skin wishes to display them.
1966 * If you pass "icononly" as the option all footer icons which do not have an
1967 * image icon set will be filtered out.
1968 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1969 * in the list of footer icons. This is mostly useful for skins which only
1970 * display the text from footericons instead of the images and don't want a
1971 * duplicate copyright statement because footerlinks already rendered one.
1974 function getFooterIcons( $option = null ) {
1975 // Generate additional footer icons
1976 $footericons = $this->get( 'footericons' );
1978 if ( $option == 'icononly' ) {
1979 // Unset any icons which don't have an image
1980 foreach ( $footericons as &$footerIconsBlock ) {
1981 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1982 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1983 unset( $footerIconsBlock[$footerIconKey] );
1987 // Redo removal of any empty blocks
1988 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1989 if ( count( $footerIconsBlock ) <= 0 ) {
1990 unset( $footericons[$footerIconsKey] );
1993 } elseif ( $option == 'nocopyright' ) {
1994 unset( $footericons['copyright']['copyright'] );
1995 if ( count( $footericons['copyright'] ) <= 0 ) {
1996 unset( $footericons['copyright'] );
2000 return $footericons;
2004 * Output the basic end-page trail including bottomscripts, reporttime, and
2005 * debug stuff. This should be called right before outputting the closing
2006 * body and html tags.
2008 function printTrail() { ?
>
2009 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2010 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2011 <?php
$this->html( 'reporttime' ) ?
>