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();
136 $language_urls = array();
138 if ( !$wgHideInterlanguageLinks ) {
139 foreach ( $out->getLanguageLinks() as $languageLinkText ) {
140 $languageLinkParts = explode( ':', $languageLinkText, 2 );
141 $class = 'interwiki-' . $languageLinkParts[0];
142 unset( $languageLinkParts );
143 $languageLinkTitle = Title
::newFromText( $languageLinkText );
144 if ( $languageLinkTitle ) {
145 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
146 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
148 if ( strval( $ilLangName ) === '' ) {
149 $ilLangName = $languageLinkText;
151 $ilLangName = $this->formatLanguageName( $ilLangName );
154 $language_urls[] = array(
155 'href' => $languageLinkTitle->getFullURL(),
156 'text' => $ilLangName,
157 'title' => $languageLinkTitle->getText(),
159 'lang' => wfBCP47( $ilInterwikiCode ),
160 'hreflang' => wfBCP47( $ilInterwikiCode ),
165 return $language_urls;
168 protected function setupTemplateForOutput() {
169 wfProfileIn( __METHOD__
);
171 $request = $this->getRequest();
172 $user = $this->getUser();
173 $title = $this->getTitle();
175 wfProfileIn( __METHOD__
. '-init' );
176 $tpl = $this->setupTemplate( $this->template
, 'skins' );
177 wfProfileOut( __METHOD__
. '-init' );
179 wfProfileIn( __METHOD__
. '-stuff' );
180 $this->thispage
= $title->getPrefixedDBkey();
181 $this->titletxt
= $title->getPrefixedText();
182 $this->userpage
= $user->getUserPage()->getPrefixedText();
184 if ( !$request->wasPosted() ) {
185 $query = $request->getValues();
186 unset( $query['title'] );
187 unset( $query['returnto'] );
188 unset( $query['returntoquery'] );
190 $this->thisquery
= wfArrayToCgi( $query );
191 $this->loggedin
= $user->isLoggedIn();
192 $this->username
= $user->getName();
194 if ( $this->loggedin ||
$this->showIPinHeader() ) {
195 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
197 # This won't be used in the standard skins, but we define it to preserve the interface
198 # To save time, we check for existence
199 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
202 wfProfileOut( __METHOD__
. '-stuff' );
204 wfProfileOut( __METHOD__
);
210 * initialize various variables and generate the template
212 * @param $out OutputPage
214 function outputPage( OutputPage
$out = null ) {
216 global $wgScript, $wgStylePath;
217 global $wgMimeType, $wgJsMimeType;
218 global $wgXhtmlNamespaces, $wgHtml5Version;
219 global $wgDisableCounters, $wgSitename, $wgLogo;
220 global $wgMaxCredits, $wgShowCreditsIfMax;
221 global $wgPageShowWatchingUsers;
222 global $wgArticlePath, $wgScriptPath, $wgServer;
224 wfProfileIn( __METHOD__
);
225 Profiler
::instance()->setTemplated( true );
228 if ( $out !== null ) {
229 // @todo Add wfDeprecated in 1.20
230 $oldContext = $this->getContext();
231 $this->setContext( $out->getContext() );
234 $out = $this->getOutput();
235 $request = $this->getRequest();
236 $user = $this->getUser();
237 $title = $this->getTitle();
239 wfProfileIn( __METHOD__
. '-init' );
240 $this->initPage( $out );
241 wfProfileOut( __METHOD__
. '-init' );
243 $tpl = $this->setupTemplateForOutput();
245 wfProfileIn( __METHOD__
. '-stuff-head' );
246 if ( !$this->useHeadElement
) {
247 $tpl->set( 'pagecss', false );
248 $tpl->set( 'usercss', false );
250 $tpl->set( 'userjs', false );
251 $tpl->set( 'userjsprev', false );
253 $tpl->set( 'jsvarurl', false );
255 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
256 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
257 $tpl->set( 'html5version', $wgHtml5Version );
258 $tpl->set( 'headlinks', $out->getHeadLinks() );
259 $tpl->set( 'csslinks', $out->buildCssLinks() );
260 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
261 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
263 wfProfileOut( __METHOD__
. '-stuff-head' );
265 wfProfileIn( __METHOD__
. '-stuff2' );
266 $tpl->set( 'title', $out->getPageTitle() );
267 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
268 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
270 $tpl->setRef( 'thispage', $this->thispage
);
271 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
272 $tpl->set( 'titletext', $title->getText() );
273 $tpl->set( 'articleid', $title->getArticleID() );
275 $tpl->set( 'isarticle', $out->isArticle() );
277 $subpagestr = $this->subPageSubtitle();
278 if ( $subpagestr !== '' ) {
279 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
281 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
283 $undelete = $this->getUndeleteLink();
284 if ( $undelete === '' ) {
285 $tpl->set( 'undelete', '' );
287 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
290 $tpl->set( 'catlinks', $this->getCategories() );
291 if ( $out->isSyndicated() ) {
293 foreach ( $out->getSyndicationLinks() as $format => $link ) {
294 // Give grep a chance to find the usages: feed-atom, feed-rss
295 $feeds[$format] = array(
296 'text' => $this->msg( "feed-$format" )->text(),
300 $tpl->setRef( 'feeds', $feeds );
302 $tpl->set( 'feeds', false );
305 $tpl->setRef( 'mimetype', $wgMimeType );
306 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
307 $tpl->set( 'charset', 'UTF-8' );
308 $tpl->setRef( 'wgScript', $wgScript );
309 $tpl->setRef( 'skinname', $this->skinname
);
310 $tpl->set( 'skinclass', get_class( $this ) );
311 $tpl->setRef( 'skin', $this );
312 $tpl->setRef( 'stylename', $this->stylename
);
313 $tpl->set( 'printable', $out->isPrintable() );
314 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
315 $tpl->setRef( 'loggedin', $this->loggedin
);
316 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
317 /* XXX currently unused, might get useful later
318 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
319 $tpl->set( 'exists', $title->getArticleID() != 0 );
320 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
321 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
322 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
324 $tpl->set( 'searchaction', $this->escapeSearchLink() );
325 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
326 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
327 $tpl->setRef( 'stylepath', $wgStylePath );
328 $tpl->setRef( 'articlepath', $wgArticlePath );
329 $tpl->setRef( 'scriptpath', $wgScriptPath );
330 $tpl->setRef( 'serverurl', $wgServer );
331 $tpl->setRef( 'logopath', $wgLogo );
332 $tpl->setRef( 'sitename', $wgSitename );
334 $userLang = $this->getLanguage();
335 $userLangCode = $userLang->getHtmlCode();
336 $userLangDir = $userLang->getDir();
338 $tpl->set( 'lang', $userLangCode );
339 $tpl->set( 'dir', $userLangDir );
340 $tpl->set( 'rtl', $userLang->isRTL() );
342 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
343 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
344 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
345 $tpl->setRef( 'userpage', $this->userpage
);
346 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
347 $tpl->set( 'userlang', $userLangCode );
349 // Users can have their language set differently than the
350 // content of the wiki. For these users, tell the web browser
351 // that interface elements are in a different language.
352 $tpl->set( 'userlangattributes', '' );
353 $tpl->set( 'specialpageattributes', '' ); # obsolete
355 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
356 $escUserlang = htmlspecialchars( $userLangCode );
357 $escUserdir = htmlspecialchars( $userLangDir );
358 // Attributes must be in double quotes because htmlspecialchars() doesn't
359 // escape single quotes
360 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
361 $tpl->set( 'userlangattributes', $attrs );
364 wfProfileOut( __METHOD__
. '-stuff2' );
366 wfProfileIn( __METHOD__
. '-stuff3' );
367 $tpl->set( 'newtalk', $this->getNewtalks() );
368 $tpl->set( 'logo', $this->logoText() );
370 $tpl->set( 'copyright', false );
371 $tpl->set( 'viewcount', false );
372 $tpl->set( 'lastmod', false );
373 $tpl->set( 'credits', false );
374 $tpl->set( 'numberofwatchingusers', false );
375 if ( $out->isArticle() && $title->exists() ) {
376 if ( $this->isRevisionCurrent() ) {
377 if ( !$wgDisableCounters ) {
378 $viewcount = $this->getWikiPage()->getCount();
380 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
384 if ( $wgPageShowWatchingUsers ) {
385 $dbr = wfGetDB( DB_SLAVE
);
386 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
387 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
391 $tpl->set( 'numberofwatchingusers',
392 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
397 if ( $wgMaxCredits != 0 ) {
398 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
399 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
401 $tpl->set( 'lastmod', $this->lastModified() );
404 $tpl->set( 'copyright', $this->getCopyright() );
406 wfProfileOut( __METHOD__
. '-stuff3' );
408 wfProfileIn( __METHOD__
. '-stuff4' );
409 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
410 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
411 $tpl->set( 'disclaimer', $this->disclaimerLink() );
412 $tpl->set( 'privacy', $this->privacyLink() );
413 $tpl->set( 'about', $this->aboutLink() );
415 $tpl->set( 'footerlinks', array(
419 'numberofwatchingusers',
430 global $wgFooterIcons;
431 $tpl->set( 'footericons', $wgFooterIcons );
432 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
433 if ( count( $footerIconsBlock ) > 0 ) {
434 foreach ( $footerIconsBlock as &$footerIcon ) {
435 if ( isset( $footerIcon['src'] ) ) {
436 if ( !isset( $footerIcon['width'] ) ) {
437 $footerIcon['width'] = 88;
439 if ( !isset( $footerIcon['height'] ) ) {
440 $footerIcon['height'] = 31;
445 unset( $tpl->data
['footericons'][$footerIconsKey] );
449 $tpl->set( 'sitenotice', $this->getSiteNotice() );
450 $tpl->set( 'bottomscripts', $this->bottomScripts() );
451 $tpl->set( 'printfooter', $this->printSource() );
453 # An ID that includes the actual body text; without categories, contentSub, ...
454 $realBodyAttribs = array( 'id' => 'mw-content-text' );
456 # Add a mw-content-ltr/rtl class to be able to style based on text direction
457 # when the content is different from the UI language, i.e.:
458 # not for special pages or file pages AND only when viewing AND if the page exists
459 # (or is in MW namespace, because that has default content)
460 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
461 Action
::getActionName( $this ) === 'view' &&
462 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
463 $pageLang = $title->getPageViewLanguage();
464 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
465 $realBodyAttribs['dir'] = $pageLang->getDir();
466 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
469 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
470 $tpl->setRef( 'bodytext', $out->mBodytext
);
472 $language_urls = $this->getLanguages();
473 if ( count( $language_urls ) ) {
474 $tpl->setRef( 'language_urls', $language_urls );
476 $tpl->set( 'language_urls', false );
478 wfProfileOut( __METHOD__
. '-stuff4' );
480 wfProfileIn( __METHOD__
. '-stuff5' );
482 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
483 $content_navigation = $this->buildContentNavigationUrls();
484 $content_actions = $this->buildContentActionUrls( $content_navigation );
485 $tpl->setRef( 'content_navigation', $content_navigation );
486 $tpl->setRef( 'content_actions', $content_actions );
488 $tpl->set( 'sidebar', $this->buildSidebar() );
489 $tpl->set( 'nav_urls', $this->buildNavUrls() );
491 // Set the head scripts near the end, in case the above actions resulted in added scripts
492 if ( $this->useHeadElement
) {
493 $tpl->set( 'headelement', $out->headElement( $this ) );
495 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
498 $tpl->set( 'debug', '' );
499 $tpl->set( 'debughtml', $this->generateDebugHTML() );
500 $tpl->set( 'reporttime', wfReportTime() );
502 // original version by hansm
503 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
504 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
507 // Set the bodytext to another key so that skins can just output it on it's own
508 // and output printfooter and debughtml separately
509 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
511 // Append printfooter and debughtml onto bodytext so that skins that were already
512 // using bodytext before they were split out don't suddenly start not outputting information
513 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
514 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
516 // allow extensions adding stuff after the page content.
517 // See Skin::afterContentHook() for further documentation.
518 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
519 wfProfileOut( __METHOD__
. '-stuff5' );
522 wfProfileIn( __METHOD__
. '-execute' );
523 $res = $tpl->execute();
524 wfProfileOut( __METHOD__
. '-execute' );
526 // result may be an error
527 $this->printOrError( $res );
530 $this->setContext( $oldContext );
532 wfProfileOut( __METHOD__
);
536 * Get the HTML for the p-personal list
539 public function getPersonalToolsList() {
540 $tpl = $this->setupTemplateForOutput();
541 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
543 foreach ( $tpl->getPersonalTools() as $key => $item ) {
544 $html .= $tpl->makeListItem( $key, $item );
550 * Format language name for use in sidebar interlanguage links list.
551 * By default it is capitalized.
553 * @param string $name Language name, e.g. "English" or "español"
557 function formatLanguageName( $name ) {
558 return $this->getLanguage()->ucfirst( $name );
562 * Output the string, or print error message if it's
563 * an error object of the appropriate type.
564 * For the base class, assume strings all around.
569 function printOrError( $str ) {
574 * Output a boolean indicating if buildPersonalUrls should output separate
575 * login and create account links or output a combined link
576 * By default we simply return a global config setting that affects most skins
577 * This is setup as a method so that like with $wgLogo and getLogo() a skin
578 * can override this setting and always output one or the other if it has
579 * a reason it can't output one of the two modes.
582 function useCombinedLoginLink() {
583 global $wgUseCombinedLoginLink;
584 return $wgUseCombinedLoginLink;
588 * build array of urls for personal toolbar
591 protected function buildPersonalUrls() {
592 global $wgSecureLogin;
594 $title = $this->getTitle();
595 $request = $this->getRequest();
596 $pageurl = $title->getLocalURL();
597 wfProfileIn( __METHOD__
);
599 /* set up the default links for the personal toolbar */
600 $personal_urls = array();
602 # Due to bug 32276, if a user does not have read permissions,
603 # $this->getTitle() will just give Special:Badtitle, which is
604 # not especially useful as a returnto parameter. Use the title
605 # from the request instead, if there was one.
606 if ( $this->getUser()->isAllowed( 'read' ) ) {
607 $page = $this->getTitle();
609 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
611 $page = $request->getVal( 'returnto', $page );
613 if ( strval( $page ) !== '' ) {
614 $a['returnto'] = $page;
615 $query = $request->getVal( 'returntoquery', $this->thisquery
);
616 if ( $query != '' ) {
617 $a['returntoquery'] = $query;
621 if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) {
622 $a['wpStickHTTPS'] = true;
625 $returnto = wfArrayToCgi( $a );
626 if ( $this->loggedin
) {
627 $personal_urls['userpage'] = array(
628 'text' => $this->username
,
629 'href' => &$this->userpageUrlDetails
['href'],
630 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
631 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
634 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
635 $personal_urls['mytalk'] = array(
636 'text' => $this->msg( 'mytalk' )->text(),
637 'href' => &$usertalkUrlDetails['href'],
638 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
639 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
641 $href = self
::makeSpecialUrl( 'Preferences' );
642 $personal_urls['preferences'] = array(
643 'text' => $this->msg( 'mypreferences' )->text(),
645 'active' => ( $href == $pageurl )
648 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
649 $href = self
::makeSpecialUrl( 'Watchlist' );
650 $personal_urls['watchlist'] = array(
651 'text' => $this->msg( 'mywatchlist' )->text(),
653 'active' => ( $href == $pageurl )
657 # We need to do an explicit check for Special:Contributions, as we
658 # have to match both the title, and the target, which could come
659 # from request values (Special:Contributions?target=Jimbo_Wales)
660 # or be specified in "sub page" form
661 # (Special:Contributions/Jimbo_Wales). The plot
662 # thickens, because the Title object is altered for special pages,
663 # so it doesn't contain the original alias-with-subpage.
664 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
665 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
666 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
667 $active = $spName == 'Contributions'
668 && ( ( $spPar && $spPar == $this->username
)
669 ||
$request->getText( 'target' ) == $this->username
);
674 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
675 $personal_urls['mycontris'] = array(
676 'text' => $this->msg( 'mycontris' )->text(),
680 $personal_urls['logout'] = array(
681 'text' => $this->msg( 'userlogout' )->text(),
682 'href' => self
::makeSpecialUrl( 'Userlogout',
683 // userlogout link must always contain an & character, otherwise we might not be able
684 // to detect a buggy precaching proxy (bug 17790)
685 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
690 $useCombinedLoginLink = $this->useCombinedLoginLink();
691 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
692 ?
'nav-login-createaccount'
694 $is_signup = $request->getText( 'type' ) == 'signup';
696 # anonlogin & login are the same
697 $proto = $wgSecureLogin ? PROTO_HTTPS
: null;
699 $login_id = $this->showIPinHeader() ?
'anonlogin' : 'login';
701 'text' => $this->msg( $loginlink )->text(),
702 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
703 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
705 $createaccount_url = array(
706 'text' => $this->msg( 'createaccount' )->text(),
707 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
708 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
711 if ( $this->showIPinHeader() ) {
712 $href = &$this->userpageUrlDetails
['href'];
713 $personal_urls['anonuserpage'] = array(
714 'text' => $this->username
,
716 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
717 'active' => ( $pageurl == $href )
719 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
720 $href = &$usertalkUrlDetails['href'];
721 $personal_urls['anontalk'] = array(
722 'text' => $this->msg( 'anontalk' )->text(),
724 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
725 'active' => ( $pageurl == $href )
729 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
730 $personal_urls['createaccount'] = $createaccount_url;
733 $personal_urls[$login_id] = $login_url;
736 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
737 wfProfileOut( __METHOD__
);
738 return $personal_urls;
742 * Builds an array with tab definition
744 * @param Title $title page where the tab links to
745 * @param string|array $message message key or an array of message keys (will fall back)
746 * @param boolean $selected display the tab as selected
747 * @param string $query query string attached to tab URL
748 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
752 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
755 $classes[] = 'selected';
757 if ( $checkEdit && !$title->isKnown() ) {
759 if ( $query !== '' ) {
760 $query = 'action=edit&redlink=1&' . $query;
762 $query = 'action=edit&redlink=1';
766 // wfMessageFallback will nicely accept $message as an array of fallbacks
767 // or just a single key
768 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
769 if ( is_array( $message ) ) {
770 // for hook compatibility just keep the last message name
771 $message = end( $message );
773 if ( $msg->exists() ) {
774 $text = $msg->text();
777 $text = $wgContLang->getFormattedNsText(
778 MWNamespace
::getSubject( $title->getNamespace() ) );
782 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
783 $title, $message, $selected, $checkEdit,
784 &$classes, &$query, &$text, &$result ) ) ) {
789 'class' => implode( ' ', $classes ),
791 'href' => $title->getLocalURL( $query ),
795 function makeTalkUrlDetails( $name, $urlaction = '' ) {
796 $title = Title
::newFromText( $name );
797 if ( !is_object( $title ) ) {
798 throw new MWException( __METHOD__
. " given invalid pagename $name" );
800 $title = $title->getTalkPage();
801 self
::checkTitle( $title, $name );
803 'href' => $title->getLocalURL( $urlaction ),
804 'exists' => $title->getArticleID() != 0,
808 function makeArticleUrlDetails( $name, $urlaction = '' ) {
809 $title = Title
::newFromText( $name );
810 $title = $title->getSubjectPage();
811 self
::checkTitle( $title, $name );
813 'href' => $title->getLocalURL( $urlaction ),
814 'exists' => $title->getArticleID() != 0,
819 * a structured array of links usually used for the tabs in a skin
821 * There are 4 standard sections
822 * namespaces: Used for namespace tabs like special, page, and talk namespaces
823 * views: Used for primary page views like read, edit, history
824 * actions: Used for most extra page actions like deletion, protection, etc...
825 * variants: Used to list the language variants for the page
827 * Each section's value is a key/value array of links for that section.
828 * The links themselves have these common keys:
829 * - class: The css classes to apply to the tab
830 * - text: The text to display on the tab
831 * - href: The href for the tab to point to
832 * - rel: An optional rel= for the tab's link
833 * - redundant: If true the tab will be dropped in skins using content_actions
834 * this is useful for tabs like "Read" which only have meaning in skins that
835 * take special meaning from the grouped structure of content_navigation
837 * Views also have an extra key which can be used:
838 * - primary: If this is not true skins like vector may try to hide the tab
839 * when the user has limited space in their browser window
841 * content_navigation using code also expects these ids to be present on the
842 * links, however these are usually automatically generated by SkinTemplate
843 * itself and are not necessary when using a hook. The only things these may
844 * matter to are people modifying content_navigation after it's initial creation:
845 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
846 * - tooltiponly: This is set to true for some tabs in cases where the system
847 * believes that the accesskey should not be added to the tab.
851 protected function buildContentNavigationUrls() {
852 global $wgDisableLangConversion;
854 wfProfileIn( __METHOD__
);
856 // Display tabs for the relevant title rather than always the title itself
857 $title = $this->getRelevantTitle();
858 $onPage = $title->equals( $this->getTitle() );
860 $out = $this->getOutput();
861 $request = $this->getRequest();
862 $user = $this->getUser();
864 $content_navigation = array(
865 'namespaces' => array(),
867 'actions' => array(),
868 'variants' => array()
872 $action = $request->getVal( 'action', 'view' );
874 $userCanRead = $title->quickUserCan( 'read', $user );
876 $preventActiveTabs = false;
877 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
879 // Checks if page is some kind of content
880 if ( $title->canExist() ) {
881 // Gets page objects for the related namespaces
882 $subjectPage = $title->getSubjectPage();
883 $talkPage = $title->getTalkPage();
885 // Determines if this is a talk page
886 $isTalk = $title->isTalkPage();
888 // Generates XML IDs from namespace names
889 $subjectId = $title->getNamespaceKey( '' );
891 if ( $subjectId == 'main' ) {
894 $talkId = "{$subjectId}_talk";
897 $skname = $this->skinname
;
899 // Adds namespace links
900 $subjectMsg = array( "nstab-$subjectId" );
901 if ( $subjectPage->isMainPage() ) {
902 array_unshift( $subjectMsg, 'mainpage-nstab' );
904 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
905 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
907 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
908 $content_navigation['namespaces'][$talkId] = $this->tabAction(
909 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
911 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
913 if ( $userCanRead ) {
914 // Adds view view link
915 if ( $title->exists() ) {
916 $content_navigation['views']['view'] = $this->tabAction(
917 $isTalk ?
$talkPage : $subjectPage,
918 array( "$skname-view-view", 'view' ),
919 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
921 // signal to hide this from simple content_actions
922 $content_navigation['views']['view']['redundant'] = true;
925 wfProfileIn( __METHOD__
. '-edit' );
927 // Checks if user can edit the current page if it exists or create it otherwise
928 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
929 // Builds CSS class for talk page links
930 $isTalkClass = $isTalk ?
' istalk' : '';
931 // Whether the user is editing the page
932 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
933 // Whether to show the "Add a new section" tab
934 // Checks if this is a current rev of talk page and is not forced to be hidden
935 $showNewSection = !$out->forceHideNewSectionLink()
936 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
937 $section = $request->getVal( 'section' );
939 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
941 $content_navigation['views']['edit'] = array(
942 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
943 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
944 'href' => $title->getLocalURL( $this->editUrlOptions() ),
945 'primary' => true, // don't collapse this in vector
949 if ( $showNewSection ) {
950 // Adds new section link
951 //$content_navigation['actions']['addsection']
952 $content_navigation['views']['addsection'] = array(
953 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
954 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
955 'href' => $title->getLocalURL( 'action=edit§ion=new' )
958 // Checks if the page has some kind of viewable content
959 } elseif ( $title->hasSourceText() ) {
960 // Adds view source view link
961 $content_navigation['views']['viewsource'] = array(
962 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
963 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
964 'href' => $title->getLocalURL( $this->editUrlOptions() ),
965 'primary' => true, // don't collapse this in vector
968 wfProfileOut( __METHOD__
. '-edit' );
970 wfProfileIn( __METHOD__
. '-live' );
971 // Checks if the page exists
972 if ( $title->exists() ) {
973 // Adds history view link
974 $content_navigation['views']['history'] = array(
975 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
976 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
977 'href' => $title->getLocalURL( 'action=history' ),
981 if ( $title->quickUserCan( 'delete', $user ) ) {
982 $content_navigation['actions']['delete'] = array(
983 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
984 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
985 'href' => $title->getLocalURL( 'action=delete' )
989 if ( $title->quickUserCan( 'move', $user ) ) {
990 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
991 $content_navigation['actions']['move'] = array(
992 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
993 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
994 'href' => $moveTitle->getLocalURL()
998 // article doesn't exist or is deleted
999 if ( $user->isAllowed( 'deletedhistory' ) ) {
1000 $n = $title->isDeleted();
1002 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1003 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1004 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1005 $content_navigation['actions']['undelete'] = array(
1006 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1007 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1008 ->setContext( $this->getContext() )->numParams( $n )->text(),
1009 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1015 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
1016 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1017 $content_navigation['actions'][$mode] = array(
1018 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1019 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1020 'href' => $title->getLocalURL( "action=$mode" )
1024 wfProfileOut( __METHOD__
. '-live' );
1026 // Checks if the user is logged in
1027 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1029 * The following actions use messages which, if made particular to
1030 * the any specific skins, would break the Ajax code which makes this
1031 * action happen entirely inline. Skin::makeGlobalVariablesScript
1032 * defines a set of messages in a javascript object - and these
1033 * messages are assumed to be global for all skins. Without making
1034 * a change to that procedure these messages will have to remain as
1035 * the global versions.
1037 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1038 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1039 $content_navigation['actions'][$mode] = array(
1040 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1041 // uses 'watch' or 'unwatch' message
1042 'text' => $this->msg( $mode )->text(),
1043 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1048 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1050 if ( $userCanRead && !$wgDisableLangConversion ) {
1051 $pageLang = $title->getPageLanguage();
1052 // Gets list of language variants
1053 $variants = $pageLang->getVariants();
1054 // Checks that language conversion is enabled and variants exist
1055 // And if it is not in the special namespace
1056 if ( count( $variants ) > 1 ) {
1057 // Gets preferred variant (note that user preference is
1058 // only possible for wiki content language variant)
1059 $preferred = $pageLang->getPreferredVariant();
1060 if ( Action
::getActionName( $this ) === 'view' ) {
1061 $params = $request->getQueryValues();
1062 unset( $params['title'] );
1066 // Loops over each variant
1067 foreach ( $variants as $code ) {
1068 // Gets variant name from language code
1069 $varname = $pageLang->getVariantname( $code );
1070 // Appends variant link
1071 $content_navigation['variants'][] = array(
1072 'class' => ( $code == $preferred ) ?
'selected' : false,
1074 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1075 'lang' => wfBCP47( $code ),
1076 'hreflang' => wfBCP47( $code ),
1082 // If it's not content, it's got to be a special page
1083 $content_navigation['namespaces']['special'] = array(
1084 'class' => 'selected',
1085 'text' => $this->msg( 'nstab-special' )->text(),
1086 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1087 'context' => 'subject'
1090 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1091 array( &$this, &$content_navigation ) );
1094 // Equiv to SkinTemplateContentActions
1095 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1097 // Setup xml ids and tooltip info
1098 foreach ( $content_navigation as $section => &$links ) {
1099 foreach ( $links as $key => &$link ) {
1101 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1102 $xmlID = 'ca-nstab-' . $xmlID;
1103 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1105 } elseif ( $section == 'variants' ) {
1106 $xmlID = 'ca-varlang-' . $xmlID;
1108 $xmlID = 'ca-' . $xmlID;
1110 $link['id'] = $xmlID;
1114 # We don't want to give the watch tab an accesskey if the
1115 # page is being edited, because that conflicts with the
1116 # accesskey on the watch checkbox. We also don't want to
1117 # give the edit tab an accesskey, because that's fairly
1118 # superfluous and conflicts with an accesskey (Ctrl-E) often
1119 # used for editing in Safari.
1120 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1121 if ( isset( $content_navigation['views']['edit'] ) ) {
1122 $content_navigation['views']['edit']['tooltiponly'] = true;
1124 if ( isset( $content_navigation['actions']['watch'] ) ) {
1125 $content_navigation['actions']['watch']['tooltiponly'] = true;
1127 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1128 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1132 wfProfileOut( __METHOD__
);
1134 return $content_navigation;
1138 * an array of edit links by default used for the tabs
1142 function buildContentActionUrls( $content_navigation ) {
1144 wfProfileIn( __METHOD__
);
1146 // content_actions has been replaced with content_navigation for backwards
1147 // compatibility and also for skins that just want simple tabs content_actions
1148 // is now built by flattening the content_navigation arrays into one
1150 $content_actions = array();
1152 foreach ( $content_navigation as $links ) {
1154 foreach ( $links as $key => $value ) {
1156 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1157 // Redundant tabs are dropped from content_actions
1161 // content_actions used to have ids built using the "ca-$key" pattern
1162 // so the xmlID based id is much closer to the actual $key that we want
1163 // for that reason we'll just strip out the ca- if present and use
1164 // the latter potion of the "id" as the $key
1165 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1166 $key = substr( $value['id'], 3 );
1169 if ( isset( $content_actions[$key] ) ) {
1170 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1174 $content_actions[$key] = $value;
1180 wfProfileOut( __METHOD__
);
1182 return $content_actions;
1186 * build array of common navigation links
1190 protected function buildNavUrls() {
1191 global $wgUploadNavigationUrl;
1193 wfProfileIn( __METHOD__
);
1195 $out = $this->getOutput();
1196 $request = $this->getRequest();
1198 $nav_urls = array();
1199 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1200 if ( $wgUploadNavigationUrl ) {
1201 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1202 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1203 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1205 $nav_urls['upload'] = false;
1207 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1209 $nav_urls['print'] = false;
1210 $nav_urls['permalink'] = false;
1211 $nav_urls['info'] = false;
1212 $nav_urls['whatlinkshere'] = false;
1213 $nav_urls['recentchangeslinked'] = false;
1214 $nav_urls['contributions'] = false;
1215 $nav_urls['log'] = false;
1216 $nav_urls['blockip'] = false;
1217 $nav_urls['emailuser'] = false;
1218 $nav_urls['userrights'] = false;
1220 // A print stylesheet is attached to all pages, but nobody ever
1221 // figures that out. :) Add a link...
1222 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1223 $nav_urls['print'] = array(
1224 'text' => $this->msg( 'printableversion' )->text(),
1225 'href' => $this->getTitle()->getLocalURL(
1226 $request->appendQueryValue( 'printable', 'yes', true ) )
1230 if ( $out->isArticle() ) {
1231 // Also add a "permalink" while we're at it
1232 $revid = $this->getRevisionId();
1234 $nav_urls['permalink'] = array(
1235 'text' => $this->msg( 'permalink' )->text(),
1236 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1240 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1241 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1242 array( &$this, &$nav_urls, &$revid, &$revid ) );
1245 if ( $out->isArticleRelated() ) {
1246 $nav_urls['whatlinkshere'] = array(
1247 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1250 $nav_urls['info'] = array(
1251 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1252 'href' => $this->getTitle()->getLocalURL( "action=info" )
1255 if ( $this->getTitle()->getArticleID() ) {
1256 $nav_urls['recentchangeslinked'] = array(
1257 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1262 $user = $this->getRelevantUser();
1264 $rootUser = $user->getName();
1266 $nav_urls['contributions'] = array(
1267 'text' => $this->msg( 'contributions', $rootUser )->text(),
1268 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1271 $nav_urls['log'] = array(
1272 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1275 if ( $this->getUser()->isAllowed( 'block' ) ) {
1276 $nav_urls['blockip'] = array(
1277 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1281 if ( $this->showEmailUser( $user ) ) {
1282 $nav_urls['emailuser'] = array(
1283 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1287 $sur = new UserrightsPage
;
1288 $sur->setContext( $this->getContext() );
1289 if ( $sur->userCanExecute( $this->getUser() ) ) {
1290 $nav_urls['userrights'] = array(
1291 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1296 wfProfileOut( __METHOD__
);
1301 * Generate strings used for xml 'id' names
1305 function getNameSpaceKey() {
1306 return $this->getTitle()->getNamespaceKey();
1309 public function commonPrintStylesheet() {
1315 * Generic wrapper for template functions, with interface
1316 * compatible with what we use of PHPTAL 0.7.
1319 abstract class QuickTemplate
{
1323 function __construct() {
1324 $this->data
= array();
1325 $this->translator
= new MediaWiki_I18N();
1329 * Sets the value $value to $name
1333 public function set( $name, $value ) {
1334 $this->data
[$name] = $value;
1338 * Gets the template data requested
1340 * @param string $name Key for the data
1341 * @param mixed $default Optional default (or null)
1342 * @return mixed The value of the data requested or the deafult
1344 public function get( $name, $default = null ) {
1345 if ( isset( $this->data
[$name] ) ) {
1346 return $this->data
[$name];
1356 public function setRef( $name, &$value ) {
1357 $this->data
[$name] =& $value;
1363 public function setTranslator( &$t ) {
1364 $this->translator
= &$t;
1368 * Main function, used by classes that subclass QuickTemplate
1369 * to show the actual HTML output
1371 abstract public function execute();
1376 function text( $str ) {
1377 echo htmlspecialchars( $this->data
[$str] );
1382 * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
1384 function jstext( $str ) {
1385 wfDeprecated( __METHOD__
, '1.21' );
1386 echo Xml
::escapeJsString( $this->data
[$str] );
1392 function html( $str ) {
1393 echo $this->data
[$str];
1399 function msg( $str ) {
1400 echo htmlspecialchars( $this->translator
->translate( $str ) );
1406 function msgHtml( $str ) {
1407 echo $this->translator
->translate( $str );
1411 * An ugly, ugly hack.
1414 function msgWiki( $str ) {
1417 $text = $this->translator
->translate( $str );
1418 echo $wgOut->parse( $text );
1425 function haveData( $str ) {
1426 return isset( $this->data
[$str] );
1434 function haveMsg( $str ) {
1435 $msg = $this->translator
->translate( $str );
1436 return ( $msg != '-' ) && ( $msg != '' ); # ????
1440 * Get the Skin object related to this object
1442 * @return Skin object
1444 public function getSkin() {
1445 return $this->data
['skin'];
1450 * New base template for a skin's template extended from QuickTemplate
1451 * this class features helper methods that provide common ways of interacting
1452 * with the data stored in the QuickTemplate
1454 abstract class BaseTemplate
extends QuickTemplate
{
1457 * Get a Message object with its context set
1459 * @param string $name message name
1462 public function getMsg( $name ) {
1463 return $this->getSkin()->msg( $name );
1466 function msg( $str ) {
1467 echo $this->getMsg( $str )->escaped();
1470 function msgHtml( $str ) {
1471 echo $this->getMsg( $str )->text();
1474 function msgWiki( $str ) {
1475 echo $this->getMsg( $str )->parseAsBlock();
1479 * Create an array of common toolbox items from the data in the quicktemplate
1480 * stored by SkinTemplate.
1481 * The resulting array is built according to a format intended to be passed
1482 * through makeListItem to generate the html.
1485 function getToolbox() {
1486 wfProfileIn( __METHOD__
);
1489 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1490 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1491 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1493 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1494 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1495 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1496 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1498 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1499 $toolbox['feeds']['id'] = 'feedlinks';
1500 $toolbox['feeds']['links'] = array();
1501 foreach ( $this->data
['feeds'] as $key => $feed ) {
1502 $toolbox['feeds']['links'][$key] = $feed;
1503 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1504 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1505 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1506 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1509 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1510 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1511 $toolbox[$special] = $this->data
['nav_urls'][$special];
1512 $toolbox[$special]['id'] = "t-$special";
1515 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1516 $toolbox['print'] = $this->data
['nav_urls']['print'];
1517 $toolbox['print']['id'] = 't-print';
1518 $toolbox['print']['rel'] = 'alternate';
1519 $toolbox['print']['msg'] = 'printableversion';
1521 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1522 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1523 if ( $toolbox['permalink']['href'] === '' ) {
1524 unset( $toolbox['permalink']['href'] );
1525 $toolbox['ispermalink']['tooltiponly'] = true;
1526 $toolbox['ispermalink']['id'] = 't-ispermalink';
1527 $toolbox['ispermalink']['msg'] = 'permalink';
1529 $toolbox['permalink']['id'] = 't-permalink';
1532 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1533 $toolbox['info'] = $this->data
['nav_urls']['info'];
1534 $toolbox['info']['id'] = 't-info';
1537 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1538 wfProfileOut( __METHOD__
);
1543 * Create an array of personal tools items from the data in the quicktemplate
1544 * stored by SkinTemplate.
1545 * The resulting array is built according to a format intended to be passed
1546 * through makeListItem to generate the html.
1547 * This is in reality the same list as already stored in personal_urls
1548 * however it is reformatted so that you can just pass the individual items
1549 * to makeListItem instead of hardcoding the element creation boilerplate.
1552 function getPersonalTools() {
1553 $personal_tools = array();
1554 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1555 # The class on a personal_urls item is meant to go on the <a> instead
1556 # of the <li> so we have to use a single item "links" array instead
1557 # of using most of the personal_url's keys directly.
1560 array( 'single-id' => "pt-$key" ),
1564 if ( isset( $plink['active'] ) ) {
1565 $ptool['active'] = $plink['active'];
1567 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1568 if ( isset( $plink[$k] ) ) {
1569 $ptool['links'][0][$k] = $plink[$k];
1572 $personal_tools[$key] = $ptool;
1574 return $personal_tools;
1577 function getSidebar( $options = array() ) {
1578 // Force the rendering of the following portals
1579 $sidebar = $this->data
['sidebar'];
1580 if ( !isset( $sidebar['SEARCH'] ) ) {
1581 $sidebar['SEARCH'] = true;
1583 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1584 $sidebar['TOOLBOX'] = true;
1586 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1587 $sidebar['LANGUAGES'] = true;
1590 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1591 unset( $sidebar['SEARCH'] );
1593 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1594 unset( $sidebar['TOOLBOX'] );
1596 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1597 unset( $sidebar['LANGUAGES'] );
1601 foreach ( $sidebar as $boxName => $content ) {
1602 if ( $content === false ) {
1605 switch ( $boxName ) {
1607 // Search is a special case, skins should custom implement this
1608 $boxes[$boxName] = array(
1610 'header' => $this->getMsg( 'search' )->text(),
1611 'generated' => false,
1616 $msgObj = $this->getMsg( 'toolbox' );
1617 $boxes[$boxName] = array(
1619 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1620 'generated' => false,
1621 'content' => $this->getToolbox(),
1625 if ( $this->data
['language_urls'] ) {
1626 $msgObj = $this->getMsg( 'otherlanguages' );
1627 $boxes[$boxName] = array(
1629 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1630 'generated' => false,
1631 'content' => $this->data
['language_urls'],
1636 $msgObj = $this->getMsg( $boxName );
1637 $boxes[$boxName] = array(
1638 'id' => "p-$boxName",
1639 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1640 'generated' => true,
1641 'content' => $content,
1647 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1648 $hookContents = null;
1649 if ( isset( $boxes['TOOLBOX'] ) ) {
1651 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1652 // can abort and avoid outputting double toolbox links
1653 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1654 $hookContents = ob_get_contents();
1656 if ( !trim( $hookContents ) ) {
1657 $hookContents = null;
1662 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1663 foreach ( $boxes as $boxName => $box ) {
1664 if ( is_array( $box['content'] ) ) {
1666 foreach ( $box['content'] as $key => $val ) {
1667 $content .= "\n " . $this->makeListItem( $key, $val );
1669 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1670 if ( $hookContents ) {
1671 $content .= "\n $hookContents";
1674 $content .= "\n</ul>\n";
1675 $boxes[$boxName]['content'] = $content;
1679 if ( $hookContents ) {
1680 $boxes['TOOLBOXEND'] = array(
1681 'id' => 'p-toolboxend',
1682 'header' => $boxes['TOOLBOX']['header'],
1683 'generated' => false,
1684 'content' => "<ul>{$hookContents}</ul>",
1686 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1688 foreach ( $boxes as $key => $box ) {
1689 if ( $key === 'TOOLBOXEND' ) {
1692 $boxes2[$key] = $box;
1693 if ( $key === 'TOOLBOX' ) {
1694 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1706 * Makes a link, usually used by makeListItem to generate a link for an item
1707 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1709 * @param string $key usually a key from the list you are generating this
1711 * @param array $item contains some of a specific set of keys.
1713 * The text of the link will be generated either from the contents of the
1714 * "text" key in the $item array, if a "msg" key is present a message by
1715 * that name will be used, and if neither of those are set the $key will be
1716 * used as a message name.
1718 * If a "href" key is not present makeLink will just output htmlescaped text.
1719 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1720 * for the link if present.
1722 * If an "id" or "single-id" (if you don't want the actual id to be output
1723 * on the link) is present it will be used to generate a tooltip and
1724 * accesskey for the link.
1726 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1728 * @param array $options can be used to affect the output of a link.
1729 * Possible options are:
1730 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1731 * a link in. This should be an array of arrays containing a 'tag' and
1732 * optionally an 'attributes' key. If you only have one element you don't
1733 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1734 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1736 * - 'link-class' key can be used to specify additional classes to apply
1738 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1739 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1740 * any non-link will output a "<span>" instead of just text.
1744 function makeLink( $key, $item, $options = array() ) {
1745 if ( isset( $item['text'] ) ) {
1746 $text = $item['text'];
1748 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1751 $html = htmlspecialchars( $text );
1753 if ( isset( $options['text-wrapper'] ) ) {
1754 $wrapper = $options['text-wrapper'];
1755 if ( isset( $wrapper['tag'] ) ) {
1756 $wrapper = array( $wrapper );
1758 while ( count( $wrapper ) > 0 ) {
1759 $element = array_pop( $wrapper );
1760 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1764 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1766 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1767 unset( $attrs[$k] );
1770 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1771 $item['single-id'] = $item['id'];
1773 if ( isset( $item['single-id'] ) ) {
1774 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1775 $title = Linker
::titleAttrib( $item['single-id'] );
1776 if ( $title !== false ) {
1777 $attrs['title'] = $title;
1780 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1781 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1782 $attrs['title'] = $tip['title'];
1784 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1785 $attrs['accesskey'] = $tip['accesskey'];
1789 if ( isset( $options['link-class'] ) ) {
1790 if ( isset( $attrs['class'] ) ) {
1791 $attrs['class'] .= " {$options['link-class']}";
1793 $attrs['class'] = $options['link-class'];
1796 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1803 * Generates a list item for a navigation, portlet, portal, sidebar... list
1805 * @param $key string, usually a key from the list you are generating this link from.
1806 * @param $item array, of list item data containing some of a specific set of keys.
1807 * The "id" and "class" keys will be used as attributes for the list item,
1808 * if "active" contains a value of true a "active" class will also be appended to class.
1810 * @param $options array
1812 * If you want something other than a "<li>" you can pass a tag name such as
1813 * "tag" => "span" in the $options array to change the tag used.
1814 * link/content data for the list item may come in one of two forms
1815 * A "links" key may be used, in which case it should contain an array with
1816 * a list of links to include inside the list item, see makeLink for the
1817 * format of individual links array items.
1819 * Otherwise the relevant keys from the list item $item array will be passed
1820 * to makeLink instead. Note however that "id" and "class" are used by the
1821 * list item directly so they will not be passed to makeLink
1822 * (however the link will still support a tooltip and accesskey from it)
1823 * If you need an id or class on a single link you should include a "links"
1824 * array with just one link item inside of it.
1825 * $options is also passed on to makeLink calls
1829 function makeListItem( $key, $item, $options = array() ) {
1830 if ( isset( $item['links'] ) ) {
1832 foreach ( $item['links'] as $linkKey => $link ) {
1833 $html .= $this->makeLink( $linkKey, $link, $options );
1837 // These keys are used by makeListItem and shouldn't be passed on to the link
1838 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1841 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1842 // The id goes on the <li> not on the <a> for single links
1843 // but makeSidebarLink still needs to know what id to use when
1844 // generating tooltips and accesskeys.
1845 $link['single-id'] = $item['id'];
1847 $html = $this->makeLink( $key, $link, $options );
1851 foreach ( array( 'id', 'class' ) as $attr ) {
1852 if ( isset( $item[$attr] ) ) {
1853 $attrs[$attr] = $item[$attr];
1856 if ( isset( $item['active'] ) && $item['active'] ) {
1857 if ( !isset( $attrs['class'] ) ) {
1858 $attrs['class'] = '';
1860 $attrs['class'] .= ' active';
1861 $attrs['class'] = trim( $attrs['class'] );
1863 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1866 function makeSearchInput( $attrs = array() ) {
1870 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1871 'value' => $this->get( 'search', '' ),
1873 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1874 return Html
::element( 'input', $realAttrs );
1877 function makeSearchButton( $mode, $attrs = array() ) {
1884 'value' => $this->translator
->translate(
1885 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1887 $realAttrs = array_merge(
1889 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1892 return Html
::element( 'input', $realAttrs );
1894 $buttonAttrs = array(
1898 $buttonAttrs = array_merge(
1900 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1903 unset( $buttonAttrs['src'] );
1904 unset( $buttonAttrs['alt'] );
1905 unset( $buttonAttrs['width'] );
1906 unset( $buttonAttrs['height'] );
1908 'src' => $attrs['src'],
1909 'alt' => isset( $attrs['alt'] )
1911 : $this->translator
->translate( 'searchbutton' ),
1912 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1913 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1915 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1917 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1922 * Returns an array of footerlinks trimmed down to only those footer links that
1924 * If you pass "flat" as an option then the returned array will be a flat array
1925 * of footer icons instead of a key/value array of footerlinks arrays broken
1926 * up into categories.
1927 * @return array|mixed
1929 function getFooterLinks( $option = null ) {
1930 $footerlinks = $this->get( 'footerlinks' );
1932 // Reduce footer links down to only those which are being used
1933 $validFooterLinks = array();
1934 foreach ( $footerlinks as $category => $links ) {
1935 $validFooterLinks[$category] = array();
1936 foreach ( $links as $link ) {
1937 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1938 $validFooterLinks[$category][] = $link;
1941 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1942 unset( $validFooterLinks[$category] );
1946 if ( $option == 'flat' ) {
1947 // fold footerlinks into a single array using a bit of trickery
1948 $validFooterLinks = call_user_func_array(
1950 array_values( $validFooterLinks )
1954 return $validFooterLinks;
1958 * Returns an array of footer icons filtered down by options relevant to how
1959 * the skin wishes to display them.
1960 * If you pass "icononly" as the option all footer icons which do not have an
1961 * image icon set will be filtered out.
1962 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1963 * in the list of footer icons. This is mostly useful for skins which only
1964 * display the text from footericons instead of the images and don't want a
1965 * duplicate copyright statement because footerlinks already rendered one.
1968 function getFooterIcons( $option = null ) {
1969 // Generate additional footer icons
1970 $footericons = $this->get( 'footericons' );
1972 if ( $option == 'icononly' ) {
1973 // Unset any icons which don't have an image
1974 foreach ( $footericons as &$footerIconsBlock ) {
1975 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1976 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1977 unset( $footerIconsBlock[$footerIconKey] );
1981 // Redo removal of any empty blocks
1982 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1983 if ( count( $footerIconsBlock ) <= 0 ) {
1984 unset( $footericons[$footerIconsKey] );
1987 } elseif ( $option == 'nocopyright' ) {
1988 unset( $footericons['copyright']['copyright'] );
1989 if ( count( $footericons['copyright'] ) <= 0 ) {
1990 unset( $footericons['copyright'] );
1994 return $footericons;
1998 * Output the basic end-page trail including bottomscripts, reporttime, and
1999 * debug stuff. This should be called right before outputting the closing
2000 * body and html tags.
2002 function printTrail() { ?
>
2003 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2004 <?php
$this->html( 'reporttime' ) ?
>
2005 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() );