Introduce a new hook that allows extensions to add to My Contributions
[mediawiki.git] / includes / SkinTemplate.php
blob4028e78b70e2d646ae160f233a29d0305ddbf8bf
1 <?php
2 /**
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
20 * @file
23 /**
24 * Wrapper object for MediaWiki's localization functions,
25 * to be passed to the template engine.
27 * @private
28 * @ingroup Skins
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 = wfMsg( $value );
44 // interpolate variables
45 $m = array();
46 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
47 list( $src, $var ) = $m;
48 wfSuppressWarnings();
49 $varValue = $this->_context[$var];
50 wfRestoreWarnings();
51 $value = str_replace( $src, $varValue, $value );
53 wfProfileOut( __METHOD__ );
54 return $value;
58 /**
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.
68 * @ingroup Skins
70 class SkinTemplate extends Skin {
71 /**#@+
72 * @private
75 /**
76 * Name of our skin, it probably needs to be all lower case. Child classes
77 * should override the default.
79 var $skinname = 'monobook';
81 /**
82 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
83 * are located. Child classes should override the default.
85 var $stylename = 'monobook';
87 /**
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';
93 /**
94 * Whether this skin use OutputPage::headElement() to generate the <head>
95 * tag
97 var $useHeadElement = false;
99 /**#@-*/
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 $repository string: subdirectory where we keep template files
117 * @param $cache_dir string
118 * @return QuickTemplate
119 * @private
121 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
122 return new $classname();
126 * initialize various variables and generate the template
128 * @param $out OutputPage
130 function outputPage( OutputPage $out=null ) {
131 global $wgContLang;
132 global $wgScript, $wgStylePath;
133 global $wgMimeType, $wgJsMimeType;
134 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
135 global $wgDisableCounters, $wgSitename, $wgLogo, $wgHideInterlanguageLinks;
136 global $wgMaxCredits, $wgShowCreditsIfMax;
137 global $wgPageShowWatchingUsers;
138 global $wgDebugComments;
139 global $wgArticlePath, $wgScriptPath, $wgServer;
141 wfProfileIn( __METHOD__ );
142 Profiler::instance()->setTemplated( true );
144 $oldContext = null;
145 if ( $out !== null ) {
146 // @todo Add wfDeprecated in 1.20
147 $oldContext = $this->getContext();
148 $this->setContext( $out->getContext() );
151 $out = $this->getOutput();
152 $request = $this->getRequest();
153 $user = $this->getUser();
154 $title = $this->getTitle();
156 wfProfileIn( __METHOD__ . '-init' );
157 $this->initPage( $out );
159 $tpl = $this->setupTemplate( $this->template, 'skins' );
160 wfProfileOut( __METHOD__ . '-init' );
162 wfProfileIn( __METHOD__ . '-stuff' );
163 $this->thispage = $title->getPrefixedDBkey();
164 $this->titletxt = $title->getPrefixedText();
165 $this->userpage = $user->getUserPage()->getPrefixedText();
166 $query = array();
167 if ( !$request->wasPosted() ) {
168 $query = $request->getValues();
169 unset( $query['title'] );
170 unset( $query['returnto'] );
171 unset( $query['returntoquery'] );
173 $this->thisquery = wfArrayToCGI( $query );
174 $this->loggedin = $user->isLoggedIn();
175 $this->username = $user->getName();
177 if ( $this->loggedin || $this->showIPinHeader() ) {
178 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
179 } else {
180 # This won't be used in the standard skins, but we define it to preserve the interface
181 # To save time, we check for existence
182 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
185 wfProfileOut( __METHOD__ . '-stuff' );
187 wfProfileIn( __METHOD__ . '-stuff-head' );
188 if ( !$this->useHeadElement ) {
189 $tpl->set( 'pagecss', false );
190 $tpl->set( 'usercss', false );
192 $tpl->set( 'userjs', false );
193 $tpl->set( 'userjsprev', false );
195 $tpl->set( 'jsvarurl', false );
197 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
198 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
199 $tpl->set( 'html5version', $wgHtml5Version );
200 $tpl->set( 'headlinks', $out->getHeadLinks() );
201 $tpl->set( 'csslinks', $out->buildCssLinks() );
202 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
203 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
205 wfProfileOut( __METHOD__ . '-stuff-head' );
207 wfProfileIn( __METHOD__ . '-stuff2' );
208 $tpl->set( 'title', $out->getPageTitle() );
209 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
210 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
212 $tpl->setRef( 'thispage', $this->thispage );
213 $tpl->setRef( 'titleprefixeddbkey', $this->thispage );
214 $tpl->set( 'titletext', $title->getText() );
215 $tpl->set( 'articleid', $title->getArticleID() );
217 $tpl->set( 'isarticle', $out->isArticle() );
219 $subpagestr = $this->subPageSubtitle();
220 if ( $subpagestr !== '' ) {
221 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
223 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
225 $undelete = $this->getUndeleteLink();
226 if ( $undelete === '' ) {
227 $tpl->set( 'undelete', '' );
228 } else {
229 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
232 $tpl->set( 'catlinks', $this->getCategories() );
233 if( $out->isSyndicated() ) {
234 $feeds = array();
235 foreach( $out->getSyndicationLinks() as $format => $link ) {
236 $feeds[$format] = array(
237 'text' => $this->msg( "feed-$format" )->text(),
238 'href' => $link
241 $tpl->setRef( 'feeds', $feeds );
242 } else {
243 $tpl->set( 'feeds', false );
246 $tpl->setRef( 'mimetype', $wgMimeType );
247 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
248 $tpl->set( 'charset', 'UTF-8' );
249 $tpl->setRef( 'wgScript', $wgScript );
250 $tpl->setRef( 'skinname', $this->skinname );
251 $tpl->set( 'skinclass', get_class( $this ) );
252 $tpl->setRef( 'skin', $this );
253 $tpl->setRef( 'stylename', $this->stylename );
254 $tpl->set( 'printable', $out->isPrintable() );
255 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
256 $tpl->setRef( 'loggedin', $this->loggedin );
257 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
258 /* XXX currently unused, might get useful later
259 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
260 $tpl->set( 'exists', $title->getArticleID() != 0 );
261 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
262 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
263 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
265 $tpl->set( 'searchaction', $this->escapeSearchLink() );
266 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
267 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
268 $tpl->setRef( 'stylepath', $wgStylePath );
269 $tpl->setRef( 'articlepath', $wgArticlePath );
270 $tpl->setRef( 'scriptpath', $wgScriptPath );
271 $tpl->setRef( 'serverurl', $wgServer );
272 $tpl->setRef( 'logopath', $wgLogo );
273 $tpl->setRef( 'sitename', $wgSitename );
275 $userLang = $this->getLanguage();
276 $userLangCode = $userLang->getHtmlCode();
277 $userLangDir = $userLang->getDir();
279 $tpl->set( 'lang', $userLangCode );
280 $tpl->set( 'dir', $userLangDir );
281 $tpl->set( 'rtl', $userLang->isRTL() );
283 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
284 $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) );
285 $tpl->set( 'username', $this->loggedin ? $this->username : null );
286 $tpl->setRef( 'userpage', $this->userpage );
287 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
288 $tpl->set( 'userlang', $userLangCode );
290 // Users can have their language set differently than the
291 // content of the wiki. For these users, tell the web browser
292 // that interface elements are in a different language.
293 $tpl->set( 'userlangattributes', '' );
294 $tpl->set( 'specialpageattributes', '' ); # obsolete
296 if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
297 $escUserlang = htmlspecialchars( $userLangCode );
298 $escUserdir = htmlspecialchars( $userLangDir );
299 // Attributes must be in double quotes because htmlspecialchars() doesn't
300 // escape single quotes
301 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
302 $tpl->set( 'userlangattributes', $attrs );
305 wfProfileOut( __METHOD__ . '-stuff2' );
307 wfProfileIn( __METHOD__ . '-stuff3' );
308 $tpl->set( 'newtalk', $this->getNewtalks() );
309 $tpl->set( 'logo', $this->logoText() );
311 $tpl->set( 'copyright', false );
312 $tpl->set( 'viewcount', false );
313 $tpl->set( 'lastmod', false );
314 $tpl->set( 'credits', false );
315 $tpl->set( 'numberofwatchingusers', false );
316 if ( $out->isArticle() && $title->exists() ) {
317 if ( $this->isRevisionCurrent() ) {
318 if ( !$wgDisableCounters ) {
319 $viewcount = $this->getWikiPage()->getCount();
320 if ( $viewcount ) {
321 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
325 if ( $wgPageShowWatchingUsers ) {
326 $dbr = wfGetDB( DB_SLAVE );
327 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
328 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
329 __METHOD__
331 if ( $num > 0 ) {
332 $tpl->set( 'numberofwatchingusers',
333 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
338 if ( $wgMaxCredits != 0 ) {
339 $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
340 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
341 } else {
342 $tpl->set( 'lastmod', $this->lastModified() );
345 $tpl->set( 'copyright', $this->getCopyright() );
347 wfProfileOut( __METHOD__ . '-stuff3' );
349 wfProfileIn( __METHOD__ . '-stuff4' );
350 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
351 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
352 $tpl->set( 'disclaimer', $this->disclaimerLink() );
353 $tpl->set( 'privacy', $this->privacyLink() );
354 $tpl->set( 'about', $this->aboutLink() );
356 $tpl->set( 'footerlinks', array(
357 'info' => array(
358 'lastmod',
359 'viewcount',
360 'numberofwatchingusers',
361 'credits',
362 'copyright',
364 'places' => array(
365 'privacy',
366 'about',
367 'disclaimer',
369 ) );
371 global $wgFooterIcons;
372 $tpl->set( 'footericons', $wgFooterIcons );
373 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
374 if ( count( $footerIconsBlock ) > 0 ) {
375 foreach ( $footerIconsBlock as &$footerIcon ) {
376 if ( isset( $footerIcon['src'] ) ) {
377 if ( !isset( $footerIcon['width'] ) ) {
378 $footerIcon['width'] = 88;
380 if ( !isset( $footerIcon['height'] ) ) {
381 $footerIcon['height'] = 31;
385 } else {
386 unset( $tpl->data['footericons'][$footerIconsKey] );
390 if ( $wgDebugComments ) {
391 $tpl->setRef( 'debug', $out->mDebugtext );
392 } else {
393 $tpl->set( 'debug', '' );
396 $tpl->set( 'sitenotice', $this->getSiteNotice() );
397 $tpl->set( 'bottomscripts', $this->bottomScripts() );
398 $tpl->set( 'printfooter', $this->printSource() );
400 # An ID that includes the actual body text; without categories, contentSub, ...
401 $realBodyAttribs = array( 'id' => 'mw-content-text' );
403 # Add a mw-content-ltr/rtl class to be able to style based on text direction
404 # when the content is different from the UI language, i.e.:
405 # not for special pages or file pages AND only when viewing AND if the page exists
406 # (or is in MW namespace, because that has default content)
407 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
408 in_array( $request->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) &&
409 ( $title->exists() || $title->getNamespace() == NS_MEDIAWIKI ) ) {
410 $pageLang = $title->getPageLanguage();
411 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
412 $realBodyAttribs['dir'] = $pageLang->getDir();
413 $realBodyAttribs['class'] = 'mw-content-'.$pageLang->getDir();
416 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
417 $tpl->setRef( 'bodytext', $out->mBodytext );
419 # Language links
420 $language_urls = array();
422 if ( !$wgHideInterlanguageLinks ) {
423 foreach( $out->getLanguageLinks() as $l ) {
424 $tmp = explode( ':', $l, 2 );
425 $class = 'interwiki-' . $tmp[0];
426 unset( $tmp );
427 $nt = Title::newFromText( $l );
428 if ( $nt ) {
429 $ilLangName = Language::fetchLanguageName( $nt->getInterwiki() );
430 if ( strval( $ilLangName ) === '' ) {
431 $ilLangName = $l;
432 } else {
433 $ilLangName = $this->getLanguage()->ucfirst( $ilLangName );
435 $language_urls[] = array(
436 'href' => $nt->getFullURL(),
437 'text' => $ilLangName,
438 'title' => $nt->getText(),
439 'class' => $class,
440 'lang' => $nt->getInterwiki(),
441 'hreflang' => $nt->getInterwiki(),
446 if ( count( $language_urls ) ) {
447 $tpl->setRef( 'language_urls', $language_urls );
448 } else {
449 $tpl->set( 'language_urls', false );
451 wfProfileOut( __METHOD__ . '-stuff4' );
453 wfProfileIn( __METHOD__ . '-stuff5' );
454 # Personal toolbar
455 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
456 $content_navigation = $this->buildContentNavigationUrls();
457 $content_actions = $this->buildContentActionUrls( $content_navigation );
458 $tpl->setRef( 'content_navigation', $content_navigation );
459 $tpl->setRef( 'content_actions', $content_actions );
461 $tpl->set( 'sidebar', $this->buildSidebar() );
462 $tpl->set( 'nav_urls', $this->buildNavUrls() );
464 // Set the head scripts near the end, in case the above actions resulted in added scripts
465 if ( $this->useHeadElement ) {
466 $tpl->set( 'headelement', $out->headElement( $this ) );
467 } else {
468 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
471 $tpl->set( 'debughtml', $this->generateDebugHTML() );
472 $tpl->set( 'reporttime', wfReportTime() );
474 // original version by hansm
475 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
476 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
479 // Set the bodytext to another key so that skins can just output it on it's own
480 // and output printfooter and debughtml separately
481 $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
483 // Append printfooter and debughtml onto bodytext so that skins that were already
484 // using bodytext before they were split out don't suddenly start not outputting information
485 $tpl->data['bodytext'] .= Html::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
486 $tpl->data['bodytext'] .= $tpl->data['debughtml'];
488 // allow extensions adding stuff after the page content.
489 // See Skin::afterContentHook() for further documentation.
490 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
491 wfProfileOut( __METHOD__ . '-stuff5' );
493 // execute template
494 wfProfileIn( __METHOD__ . '-execute' );
495 $res = $tpl->execute();
496 wfProfileOut( __METHOD__ . '-execute' );
498 // result may be an error
499 $this->printOrError( $res );
501 if ( $oldContext ) {
502 $this->setContext( $oldContext );
504 wfProfileOut( __METHOD__ );
508 * Output the string, or print error message if it's
509 * an error object of the appropriate type.
510 * For the base class, assume strings all around.
512 * @param $str Mixed
513 * @private
515 function printOrError( $str ) {
516 echo $str;
520 * Output a boolean indiciating if buildPersonalUrls should output separate
521 * login and create account links or output a combined link
522 * By default we simply return a global config setting that affects most skins
523 * This is setup as a method so that like with $wgLogo and getLogo() a skin
524 * can override this setting and always output one or the other if it has
525 * a reason it can't output one of the two modes.
526 * @return bool
528 function useCombinedLoginLink() {
529 global $wgUseCombinedLoginLink;
530 return $wgUseCombinedLoginLink;
534 * build array of urls for personal toolbar
535 * @return array
537 protected function buildPersonalUrls() {
538 $title = $this->getTitle();
539 $request = $this->getRequest();
540 $pageurl = $title->getLocalURL();
541 wfProfileIn( __METHOD__ );
543 /* set up the default links for the personal toolbar */
544 $personal_urls = array();
546 # Due to bug 32276, if a user does not have read permissions,
547 # $this->getTitle() will just give Special:Badtitle, which is
548 # not especially useful as a returnto parameter. Use the title
549 # from the request instead, if there was one.
550 $page = Title::newFromURL( $request->getVal( 'title', '' ) );
551 $page = $request->getVal( 'returnto', $page );
552 $a = array();
553 if ( strval( $page ) !== '' ) {
554 $a['returnto'] = $page;
555 $query = $request->getVal( 'returntoquery', $this->thisquery );
556 if( $query != '' ) {
557 $a['returntoquery'] = $query;
560 $returnto = wfArrayToCGI( $a );
561 if( $this->loggedin ) {
562 $personal_urls['userpage'] = array(
563 'text' => $this->username,
564 'href' => &$this->userpageUrlDetails['href'],
565 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
566 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
568 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
569 $personal_urls['mytalk'] = array(
570 'text' => $this->msg( 'mytalk' )->text(),
571 'href' => &$usertalkUrlDetails['href'],
572 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
573 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
575 $href = self::makeSpecialUrl( 'Preferences' );
576 $personal_urls['preferences'] = array(
577 'text' => $this->msg( 'mypreferences' )->text(),
578 'href' => $href,
579 'active' => ( $href == $pageurl )
581 $href = self::makeSpecialUrl( 'Watchlist' );
582 $personal_urls['watchlist'] = array(
583 'text' => $this->msg( 'mywatchlist' )->text(),
584 'href' => $href,
585 'active' => ( $href == $pageurl )
588 # We need to do an explicit check for Special:Contributions, as we
589 # have to match both the title, and the target, which could come
590 # from request values (Special:Contributions?target=Jimbo_Wales)
591 # or be specified in "sub page" form
592 # (Special:Contributions/Jimbo_Wales). The plot
593 # thickens, because the Title object is altered for special pages,
594 # so it doesn't contain the original alias-with-subpage.
595 $origTitle = Title::newFromText( $request->getText( 'title' ) );
596 if( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
597 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
598 $active = $spName == 'Contributions'
599 && ( ( $spPar && $spPar == $this->username )
600 || $request->getText( 'target' ) == $this->username );
601 } else {
602 $active = false;
605 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
606 $personal_urls['mycontris'] = array(
607 'text' => $this->msg( 'mycontris' )->text(),
608 'href' => $href,
609 'active' => $active
611 $personal_urls['logout'] = array(
612 'text' => $this->msg( 'userlogout' )->text(),
613 'href' => self::makeSpecialUrl( 'Userlogout',
614 // userlogout link must always contain an & character, otherwise we might not be able
615 // to detect a buggy precaching proxy (bug 17790)
616 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
618 'active' => false
620 } else {
621 $useCombinedLoginLink = $this->useCombinedLoginLink();
622 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
623 ? 'nav-login-createaccount'
624 : 'login';
625 $is_signup = $request->getText( 'type' ) == 'signup';
627 # anonlogin & login are the same
628 $login_url = array(
629 'text' => $this->msg( $loginlink )->text(),
630 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
631 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup )
633 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
634 $createaccount_url = array(
635 'text' => $this->msg( 'createaccount' )->text(),
636 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
637 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
640 global $wgServer, $wgSecureLogin;
641 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
642 $title = SpecialPage::getTitleFor( 'Userlogin' );
643 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
644 $login_url['href'] = $https_url;
645 # @todo FIXME: Class depends on skin
646 $login_url['class'] = 'link-https';
647 if ( isset( $createaccount_url ) ) {
648 $https_url = preg_replace( '/^http:/', 'https:',
649 $title->getFullURL( 'type=signup' ) );
650 $createaccount_url['href'] = $https_url;
651 # @todo FIXME: Class depends on skin
652 $createaccount_url['class'] = 'link-https';
656 if ( isset( $createaccount_url ) ) {
657 $personal_urls['createaccount'] = $createaccount_url;
660 if( $this->showIPinHeader() ) {
661 $href = &$this->userpageUrlDetails['href'];
662 $personal_urls['anonuserpage'] = array(
663 'text' => $this->username,
664 'href' => $href,
665 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
666 'active' => ( $pageurl == $href )
668 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
669 $href = &$usertalkUrlDetails['href'];
670 $personal_urls['anontalk'] = array(
671 'text' => $this->msg( 'anontalk' )->text(),
672 'href' => $href,
673 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
674 'active' => ( $pageurl == $href )
676 $personal_urls['anonlogin'] = $login_url;
677 } else {
678 $personal_urls['login'] = $login_url;
682 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
683 wfProfileOut( __METHOD__ );
684 return $personal_urls;
688 * TODO document
689 * @param $title Title
690 * @param $message String message key
691 * @param $selected Bool
692 * @param $query String
693 * @param $checkEdit Bool
694 * @return array
696 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
697 $classes = array();
698 if( $selected ) {
699 $classes[] = 'selected';
701 if( $checkEdit && !$title->isKnown() ) {
702 $classes[] = 'new';
703 $query = 'action=edit&redlink=1';
706 // wfMessageFallback will nicely accept $message as an array of fallbacks
707 // or just a single key
708 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
709 if ( is_array( $message ) ) {
710 // for hook compatibility just keep the last message name
711 $message = end( $message );
713 if ( $msg->exists() ) {
714 $text = $msg->text();
715 } else {
716 global $wgContLang;
717 $text = $wgContLang->getFormattedNsText(
718 MWNamespace::getSubject( $title->getNamespace() ) );
721 $result = array();
722 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
723 $title, $message, $selected, $checkEdit,
724 &$classes, &$query, &$text, &$result ) ) ) {
725 return $result;
728 return array(
729 'class' => implode( ' ', $classes ),
730 'text' => $text,
731 'href' => $title->getLocalUrl( $query ),
732 'primary' => true );
735 function makeTalkUrlDetails( $name, $urlaction = '' ) {
736 $title = Title::newFromText( $name );
737 if( !is_object( $title ) ) {
738 throw new MWException( __METHOD__ . " given invalid pagename $name" );
740 $title = $title->getTalkPage();
741 self::checkTitle( $title, $name );
742 return array(
743 'href' => $title->getLocalURL( $urlaction ),
744 'exists' => $title->getArticleID() != 0,
748 function makeArticleUrlDetails( $name, $urlaction = '' ) {
749 $title = Title::newFromText( $name );
750 $title= $title->getSubjectPage();
751 self::checkTitle( $title, $name );
752 return array(
753 'href' => $title->getLocalURL( $urlaction ),
754 'exists' => $title->getArticleID() != 0,
759 * a structured array of links usually used for the tabs in a skin
761 * There are 4 standard sections
762 * namespaces: Used for namespace tabs like special, page, and talk namespaces
763 * views: Used for primary page views like read, edit, history
764 * actions: Used for most extra page actions like deletion, protection, etc...
765 * variants: Used to list the language variants for the page
767 * Each section's value is a key/value array of links for that section.
768 * The links themseves have these common keys:
769 * - class: The css classes to apply to the tab
770 * - text: The text to display on the tab
771 * - href: The href for the tab to point to
772 * - rel: An optional rel= for the tab's link
773 * - redundant: If true the tab will be dropped in skins using content_actions
774 * this is useful for tabs like "Read" which only have meaning in skins that
775 * take special meaning from the grouped structure of content_navigation
777 * Views also have an extra key which can be used:
778 * - primary: If this is not true skins like vector may try to hide the tab
779 * when the user has limited space in their browser window
781 * content_navigation using code also expects these ids to be present on the
782 * links, however these are usually automatically generated by SkinTemplate
783 * itself and are not necessary when using a hook. The only things these may
784 * matter to are people modifying content_navigation after it's initial creation:
785 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
786 * - tooltiponly: This is set to true for some tabs in cases where the system
787 * believes that the accesskey should not be added to the tab.
789 * @return array
791 protected function buildContentNavigationUrls() {
792 global $wgDisableLangConversion;
794 wfProfileIn( __METHOD__ );
796 // Display tabs for the relevant title rather than always the title itself
797 $title = $this->getRelevantTitle();
798 $onPage = $title->equals( $this->getTitle() );
800 $out = $this->getOutput();
801 $request = $this->getRequest();
802 $user = $this->getUser();
804 $content_navigation = array(
805 'namespaces' => array(),
806 'views' => array(),
807 'actions' => array(),
808 'variants' => array()
811 // parameters
812 $action = $request->getVal( 'action', 'view' );
814 $userCanRead = $title->quickUserCan( 'read', $user );
816 $preventActiveTabs = false;
817 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
819 // Checks if page is some kind of content
820 if( $title->canExist() ) {
821 // Gets page objects for the related namespaces
822 $subjectPage = $title->getSubjectPage();
823 $talkPage = $title->getTalkPage();
825 // Determines if this is a talk page
826 $isTalk = $title->isTalkPage();
828 // Generates XML IDs from namespace names
829 $subjectId = $title->getNamespaceKey( '' );
831 if ( $subjectId == 'main' ) {
832 $talkId = 'talk';
833 } else {
834 $talkId = "{$subjectId}_talk";
837 $skname = $this->skinname;
839 // Adds namespace links
840 $subjectMsg = array( "nstab-$subjectId" );
841 if ( $subjectPage->isMainPage() ) {
842 array_unshift( $subjectMsg, 'mainpage-nstab' );
844 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
845 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
847 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
848 $content_navigation['namespaces'][$talkId] = $this->tabAction(
849 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
851 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
853 if ( $userCanRead ) {
854 // Adds view view link
855 if ( $title->exists() ) {
856 $content_navigation['views']['view'] = $this->tabAction(
857 $isTalk ? $talkPage : $subjectPage,
858 array( "$skname-view-view", 'view' ),
859 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
861 // signal to hide this from simple content_actions
862 $content_navigation['views']['view']['redundant'] = true;
865 wfProfileIn( __METHOD__ . '-edit' );
867 // Checks if user can edit the current page if it exists or create it otherwise
868 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() || $title->quickUserCan( 'create', $user ) ) ) {
869 // Builds CSS class for talk page links
870 $isTalkClass = $isTalk ? ' istalk' : '';
871 // Whether the user is editing the page
872 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
873 // Whether to show the "Add a new section" tab
874 // Checks if this is a current rev of talk page and is not forced to be hidden
875 $showNewSection = !$out->forceHideNewSectionLink()
876 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
877 $section = $request->getVal( 'section' );
879 $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
880 'edit' : 'create';
881 $content_navigation['views']['edit'] = array(
882 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass,
883 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
884 'href' => $title->getLocalURL( $this->editUrlOptions() ),
885 'primary' => true, // don't collapse this in vector
888 // section link
889 if ( $showNewSection ) {
890 // Adds new section link
891 //$content_navigation['actions']['addsection']
892 $content_navigation['views']['addsection'] = array(
893 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
894 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
895 'href' => $title->getLocalURL( 'action=edit&section=new' )
898 // Checks if the page has some kind of viewable content
899 } elseif ( $title->hasSourceText() ) {
900 // Adds view source view link
901 $content_navigation['views']['viewsource'] = array(
902 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
903 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
904 'href' => $title->getLocalURL( $this->editUrlOptions() ),
905 'primary' => true, // don't collapse this in vector
908 wfProfileOut( __METHOD__ . '-edit' );
910 wfProfileIn( __METHOD__ . '-live' );
911 // Checks if the page exists
912 if ( $title->exists() ) {
913 // Adds history view link
914 $content_navigation['views']['history'] = array(
915 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
916 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
917 'href' => $title->getLocalURL( 'action=history' ),
918 'rel' => 'archives',
921 if ( $title->quickUserCan( 'delete', $user ) ) {
922 $content_navigation['actions']['delete'] = array(
923 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
924 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
925 'href' => $title->getLocalURL( 'action=delete' )
929 if ( $title->quickUserCan( 'move', $user ) ) {
930 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
931 $content_navigation['actions']['move'] = array(
932 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
933 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
934 'href' => $moveTitle->getLocalURL()
937 } else {
938 // article doesn't exist or is deleted
939 if ( $user->isAllowed( 'deletedhistory' ) ) {
940 $n = $title->isDeleted();
941 if ( $n ) {
942 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
943 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
944 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
945 $content_navigation['actions']['undelete'] = array(
946 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
947 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
948 ->setContext( $this->getContext() )->numParams( $n )->text(),
949 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
955 if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) ) {
956 $mode = $title->isProtected() ? 'unprotect' : 'protect';
957 $content_navigation['actions'][$mode] = array(
958 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
959 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
960 'href' => $title->getLocalURL( "action=$mode" )
964 wfProfileOut( __METHOD__ . '-live' );
966 // Checks if the user is logged in
967 if ( $this->loggedin ) {
969 * The following actions use messages which, if made particular to
970 * the any specific skins, would break the Ajax code which makes this
971 * action happen entirely inline. Skin::makeGlobalVariablesScript
972 * defines a set of messages in a javascript object - and these
973 * messages are assumed to be global for all skins. Without making
974 * a change to that procedure these messages will have to remain as
975 * the global versions.
977 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
978 $token = WatchAction::getWatchToken( $title, $user, $mode );
979 $content_navigation['actions'][$mode] = array(
980 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
981 // uses 'watch' or 'unwatch' message
982 'text' => $this->msg( $mode )->text(),
983 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
988 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
990 if ( $userCanRead && !$wgDisableLangConversion ) {
991 $pageLang = $title->getPageLanguage();
992 // Gets list of language variants
993 $variants = $pageLang->getVariants();
994 // Checks that language conversion is enabled and variants exist
995 // And if it is not in the special namespace
996 if ( count( $variants ) > 1 ) {
997 // Gets preferred variant (note that user preference is
998 // only possible for wiki content language variant)
999 $preferred = $pageLang->getPreferredVariant();
1000 // Loops over each variant
1001 foreach( $variants as $code ) {
1002 // Gets variant name from language code
1003 $varname = $pageLang->getVariantname( $code );
1004 // Checks if the variant is marked as disabled
1005 if( $varname == 'disable' ) {
1006 // Skips this variant
1007 continue;
1009 // Appends variant link
1010 $content_navigation['variants'][] = array(
1011 'class' => ( $code == $preferred ) ? 'selected' : false,
1012 'text' => $varname,
1013 'href' => $title->getLocalURL( array( 'variant' => $code ) ),
1014 'lang' => $code,
1015 'hreflang' => $code
1020 } else {
1021 // If it's not content, it's got to be a special page
1022 $content_navigation['namespaces']['special'] = array(
1023 'class' => 'selected',
1024 'text' => $this->msg( 'nstab-special' )->text(),
1025 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1026 'context' => 'subject'
1029 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1030 array( &$this, &$content_navigation ) );
1033 // Equiv to SkinTemplateContentActions
1034 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1036 // Setup xml ids and tooltip info
1037 foreach ( $content_navigation as $section => &$links ) {
1038 foreach ( $links as $key => &$link ) {
1039 $xmlID = $key;
1040 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1041 $xmlID = 'ca-nstab-' . $xmlID;
1042 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1043 $xmlID = 'ca-talk';
1044 } elseif ( $section == 'variants' ) {
1045 $xmlID = 'ca-varlang-' . $xmlID;
1046 } else {
1047 $xmlID = 'ca-' . $xmlID;
1049 $link['id'] = $xmlID;
1053 # We don't want to give the watch tab an accesskey if the
1054 # page is being edited, because that conflicts with the
1055 # accesskey on the watch checkbox. We also don't want to
1056 # give the edit tab an accesskey, because that's fairly su-
1057 # perfluous and conflicts with an accesskey (Ctrl-E) often
1058 # used for editing in Safari.
1059 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1060 if ( isset( $content_navigation['views']['edit'] ) ) {
1061 $content_navigation['views']['edit']['tooltiponly'] = true;
1063 if ( isset( $content_navigation['actions']['watch'] ) ) {
1064 $content_navigation['actions']['watch']['tooltiponly'] = true;
1066 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1067 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1071 wfProfileOut( __METHOD__ );
1073 return $content_navigation;
1077 * an array of edit links by default used for the tabs
1078 * @return array
1079 * @private
1081 function buildContentActionUrls( $content_navigation ) {
1083 wfProfileIn( __METHOD__ );
1085 // content_actions has been replaced with content_navigation for backwards
1086 // compatibility and also for skins that just want simple tabs content_actions
1087 // is now built by flattening the content_navigation arrays into one
1089 $content_actions = array();
1091 foreach ( $content_navigation as $links ) {
1093 foreach ( $links as $key => $value ) {
1095 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1096 // Redundant tabs are dropped from content_actions
1097 continue;
1100 // content_actions used to have ids built using the "ca-$key" pattern
1101 // so the xmlID based id is much closer to the actual $key that we want
1102 // for that reason we'll just strip out the ca- if present and use
1103 // the latter potion of the "id" as the $key
1104 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1105 $key = substr( $value['id'], 3 );
1108 if ( isset( $content_actions[$key] ) ) {
1109 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1110 continue;
1113 $content_actions[$key] = $value;
1119 wfProfileOut( __METHOD__ );
1121 return $content_actions;
1125 * build array of common navigation links
1126 * @return array
1127 * @private
1129 protected function buildNavUrls() {
1130 global $wgUploadNavigationUrl;
1132 wfProfileIn( __METHOD__ );
1134 $out = $this->getOutput();
1135 $request = $this->getRequest();
1137 $nav_urls = array();
1138 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1139 if( $wgUploadNavigationUrl ) {
1140 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1141 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1142 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1143 } else {
1144 $nav_urls['upload'] = false;
1146 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1148 $nav_urls['print'] = false;
1149 $nav_urls['permalink'] = false;
1150 $nav_urls['whatlinkshere'] = false;
1151 $nav_urls['recentchangeslinked'] = false;
1152 $nav_urls['contributions'] = false;
1153 $nav_urls['log'] = false;
1154 $nav_urls['blockip'] = false;
1155 $nav_urls['emailuser'] = false;
1157 // A print stylesheet is attached to all pages, but nobody ever
1158 // figures that out. :) Add a link...
1159 if ( $out->isArticle() ) {
1160 if ( !$out->isPrintable() ) {
1161 $nav_urls['print'] = array(
1162 'text' => $this->msg( 'printableversion' )->text(),
1163 'href' => $this->getTitle()->getLocalURL(
1164 $request->appendQueryValue( 'printable', 'yes', true ) )
1168 // Also add a "permalink" while we're at it
1169 $revid = $this->getRevisionId();
1170 if ( $revid ) {
1171 $nav_urls['permalink'] = array(
1172 'text' => $this->msg( 'permalink' )->text(),
1173 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1177 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1178 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1179 array( &$this, &$nav_urls, &$revid, &$revid ) );
1182 if ( $out->isArticleRelated() ) {
1183 $nav_urls['whatlinkshere'] = array(
1184 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalUrl()
1186 if ( $this->getTitle()->getArticleID() ) {
1187 $nav_urls['recentchangeslinked'] = array(
1188 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalUrl()
1193 $user = $this->getRelevantUser();
1194 if ( $user ) {
1195 $rootUser = $user->getName();
1197 $nav_urls['contributions'] = array(
1198 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1201 $logPage = SpecialPage::getTitleFor( 'Log' );
1202 $nav_urls['log'] = array(
1203 'href' => $logPage->getLocalUrl( array( 'user' => $rootUser ) )
1206 if ( $this->getUser()->isAllowed( 'block' ) ) {
1207 $nav_urls['blockip'] = array(
1208 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1212 if ( $this->showEmailUser( $user ) ) {
1213 $nav_urls['emailuser'] = array(
1214 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1219 wfProfileOut( __METHOD__ );
1220 return $nav_urls;
1224 * Generate strings used for xml 'id' names
1225 * @return string
1226 * @private
1228 function getNameSpaceKey() {
1229 return $this->getTitle()->getNamespaceKey();
1232 public function commonPrintStylesheet() {
1233 return false;
1238 * Generic wrapper for template functions, with interface
1239 * compatible with what we use of PHPTAL 0.7.
1240 * @ingroup Skins
1242 abstract class QuickTemplate {
1244 * Constructor
1246 public function QuickTemplate() {
1247 $this->data = array();
1248 $this->translator = new MediaWiki_I18N();
1252 * Sets the value $value to $name
1253 * @param $name
1254 * @param $value
1256 public function set( $name, $value ) {
1257 $this->data[$name] = $value;
1261 * @param $name
1262 * @param $value
1264 public function setRef( $name, &$value ) {
1265 $this->data[$name] =& $value;
1269 * @param $t
1271 public function setTranslator( &$t ) {
1272 $this->translator = &$t;
1276 * Main function, used by classes that subclass QuickTemplate
1277 * to show the actual HTML output
1279 abstract public function execute();
1282 * @private
1284 function text( $str ) {
1285 echo htmlspecialchars( $this->data[$str] );
1289 * @private
1291 function jstext( $str ) {
1292 echo Xml::escapeJsString( $this->data[$str] );
1296 * @private
1298 function html( $str ) {
1299 echo $this->data[$str];
1303 * @private
1305 function msg( $str ) {
1306 echo htmlspecialchars( $this->translator->translate( $str ) );
1310 * @private
1312 function msgHtml( $str ) {
1313 echo $this->translator->translate( $str );
1317 * An ugly, ugly hack.
1318 * @private
1320 function msgWiki( $str ) {
1321 global $wgOut;
1323 $text = $this->translator->translate( $str );
1324 echo $wgOut->parse( $text );
1328 * @private
1329 * @return bool
1331 function haveData( $str ) {
1332 return isset( $this->data[$str] );
1336 * @private
1338 * @return bool
1340 function haveMsg( $str ) {
1341 $msg = $this->translator->translate( $str );
1342 return ( $msg != '-' ) && ( $msg != '' ); # ????
1346 * Get the Skin object related to this object
1348 * @return Skin object
1350 public function getSkin() {
1351 return $this->data['skin'];
1356 * New base template for a skin's template extended from QuickTemplate
1357 * this class features helper methods that provide common ways of interacting
1358 * with the data stored in the QuickTemplate
1360 abstract class BaseTemplate extends QuickTemplate {
1363 * Get a Message object with its context set
1365 * @param $name string message name
1366 * @return Message
1368 public function getMsg( $name ) {
1369 return $this->getSkin()->msg( $name );
1372 function msg( $str ) {
1373 echo $this->getMsg( $str )->escaped();
1376 function msgHtml( $str ) {
1377 echo $this->getMsg( $str )->text();
1380 function msgWiki( $str ) {
1381 echo $this->getMsg( $str )->parseAsBlock();
1385 * Create an array of common toolbox items from the data in the quicktemplate
1386 * stored by SkinTemplate.
1387 * The resulting array is built acording to a format intended to be passed
1388 * through makeListItem to generate the html.
1389 * @return array
1391 function getToolbox() {
1392 wfProfileIn( __METHOD__ );
1394 $toolbox = array();
1395 if ( isset( $this->data['nav_urls']['whatlinkshere'] ) && $this->data['nav_urls']['whatlinkshere'] ) {
1396 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1397 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1399 if ( isset( $this->data['nav_urls']['recentchangeslinked'] ) && $this->data['nav_urls']['recentchangeslinked'] ) {
1400 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1401 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1402 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1404 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
1405 $toolbox['feeds']['id'] = 'feedlinks';
1406 $toolbox['feeds']['links'] = array();
1407 foreach ( $this->data['feeds'] as $key => $feed ) {
1408 $toolbox['feeds']['links'][$key] = $feed;
1409 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1410 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1411 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1412 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1415 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1416 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
1417 $toolbox[$special] = $this->data['nav_urls'][$special];
1418 $toolbox[$special]['id'] = "t-$special";
1421 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
1422 $toolbox['print'] = $this->data['nav_urls']['print'];
1423 $toolbox['print']['rel'] = 'alternate';
1424 $toolbox['print']['msg'] = 'printableversion';
1426 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
1427 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1428 if ( $toolbox['permalink']['href'] === '' ) {
1429 unset( $toolbox['permalink']['href'] );
1430 $toolbox['ispermalink']['tooltiponly'] = true;
1431 $toolbox['ispermalink']['id'] = 't-ispermalink';
1432 $toolbox['ispermalink']['msg'] = 'permalink';
1433 } else {
1434 $toolbox['permalink']['id'] = 't-permalink';
1437 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1438 wfProfileOut( __METHOD__ );
1439 return $toolbox;
1443 * Create an array of personal tools items from the data in the quicktemplate
1444 * stored by SkinTemplate.
1445 * The resulting array is built acording to a format intended to be passed
1446 * through makeListItem to generate the html.
1447 * This is in reality the same list as already stored in personal_urls
1448 * however it is reformatted so that you can just pass the individual items
1449 * to makeListItem instead of hardcoding the element creation boilerplate.
1450 * @return array
1452 function getPersonalTools() {
1453 $personal_tools = array();
1454 foreach ( $this->data['personal_urls'] as $key => $plink ) {
1455 # The class on a personal_urls item is meant to go on the <a> instead
1456 # of the <li> so we have to use a single item "links" array instead
1457 # of using most of the personal_url's keys directly.
1458 $ptool = array(
1459 'links' => array(
1460 array( 'single-id' => "pt-$key" ),
1462 'id' => "pt-$key",
1464 if ( isset( $plink['active'] ) ) {
1465 $ptool['active'] = $plink['active'];
1467 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1468 if ( isset( $plink[$k] ) )
1469 $ptool['links'][0][$k] = $plink[$k];
1471 $personal_tools[$key] = $ptool;
1473 return $personal_tools;
1476 function getSidebar( $options = array() ) {
1477 // Force the rendering of the following portals
1478 $sidebar = $this->data['sidebar'];
1479 if ( !isset( $sidebar['SEARCH'] ) ) {
1480 $sidebar['SEARCH'] = true;
1482 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1483 $sidebar['TOOLBOX'] = true;
1485 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1486 $sidebar['LANGUAGES'] = true;
1489 if ( !isset( $options['search'] ) || $options['search'] !== true ) {
1490 unset( $sidebar['SEARCH'] );
1492 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1493 unset( $sidebar['TOOLBOX'] );
1495 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1496 unset( $sidebar['LANGUAGES'] );
1499 $boxes = array();
1500 foreach ( $sidebar as $boxName => $content ) {
1501 if ( $content === false ) {
1502 continue;
1504 switch ( $boxName ) {
1505 case 'SEARCH':
1506 // Search is a special case, skins should custom implement this
1507 $boxes[$boxName] = array(
1508 'id' => 'p-search',
1509 'header' => $this->getMsg( 'search' )->text(),
1510 'generated' => false,
1511 'content' => true,
1513 break;
1514 case 'TOOLBOX':
1515 $msgObj = $this->getMsg( 'toolbox' );
1516 $boxes[$boxName] = array(
1517 'id' => 'p-tb',
1518 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
1519 'generated' => false,
1520 'content' => $this->getToolbox(),
1522 break;
1523 case 'LANGUAGES':
1524 if ( $this->data['language_urls'] ) {
1525 $msgObj = $this->getMsg( 'otherlanguages' );
1526 $boxes[$boxName] = array(
1527 'id' => 'p-lang',
1528 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
1529 'generated' => false,
1530 'content' => $this->data['language_urls'],
1533 break;
1534 default:
1535 $msgObj = $this->getMsg( $boxName );
1536 $boxes[$boxName] = array(
1537 'id' => "p-$boxName",
1538 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
1539 'generated' => true,
1540 'content' => $content,
1542 break;
1546 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1547 $hookContents = null;
1548 if ( isset( $boxes['TOOLBOX'] ) ) {
1549 ob_start();
1550 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1551 // can abort and avoid outputting double toolbox links
1552 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1553 $hookContents = ob_get_contents();
1554 ob_end_clean();
1555 if ( !trim( $hookContents ) ) {
1556 $hookContents = null;
1559 // END hack
1561 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1562 foreach ( $boxes as $boxName => $box ) {
1563 if ( is_array( $box['content'] ) ) {
1564 $content = '<ul>';
1565 foreach ( $box['content'] as $key => $val ) {
1566 $content .= "\n " . $this->makeListItem( $key, $val );
1568 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1569 if ( $hookContents ) {
1570 $content .= "\n $hookContents";
1572 // END hack
1573 $content .= "\n</ul>\n";
1574 $boxes[$boxName]['content'] = $content;
1577 } else {
1578 if ( $hookContents ) {
1579 $boxes['TOOLBOXEND'] = array(
1580 'id' => 'p-toolboxend',
1581 'header' => $boxes['TOOLBOX']['header'],
1582 'generated' => false,
1583 'content' => "<ul>{$hookContents}</ul>",
1585 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1586 $boxes2 = array();
1587 foreach ( $boxes as $key => $box ) {
1588 if ( $key === 'TOOLBOXEND' ) {
1589 continue;
1591 $boxes2[$key] = $box;
1592 if ( $key === 'TOOLBOX' ) {
1593 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1596 $boxes = $boxes2;
1597 // END hack
1601 return $boxes;
1605 * Makes a link, usually used by makeListItem to generate a link for an item
1606 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1608 * $key is a string, usually a key from the list you are generating this link from
1609 * $item is an array containing some of a specific set of keys.
1610 * The text of the link will be generated either from the contents of the "text"
1611 * key in the $item array, if a "msg" key is present a message by that name will
1612 * be used, and if neither of those are set the $key will be used as a message name.
1613 * If a "href" key is not present makeLink will just output htmlescaped text.
1614 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1615 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1616 * is present it will be used to generate a tooltip and accesskey for the link.
1617 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1618 * $options can be used to affect the output of a link:
1619 * You can use a text-wrapper key to specify a list of elements to wrap the
1620 * text of a link in. This should be an array of arrays containing a 'tag' and
1621 * optionally an 'attributes' key. If you only have one element you don't need
1622 * to wrap it in another array. eg: To use <a><span>...</span></a> in all links
1623 * use array( 'text-wrapper' => array( 'tag' => 'span' ) ) for your options.
1624 * A link-class key can be used to specify additional classes to apply to all links.
1625 * A link-fallback can be used to specify a tag to use instead of <a> if there is
1626 * no link. eg: If you specify 'link-fallback' => 'span' than any non-link will
1627 * output a <span> instead of just text.
1628 * @return string
1630 function makeLink( $key, $item, $options = array() ) {
1631 if ( isset( $item['text'] ) ) {
1632 $text = $item['text'];
1633 } else {
1634 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1637 $html = htmlspecialchars( $text );
1639 if ( isset( $options['text-wrapper'] ) ) {
1640 $wrapper = $options['text-wrapper'];
1641 if ( isset( $wrapper['tag'] ) ) {
1642 $wrapper = array( $wrapper );
1644 while ( count( $wrapper ) > 0 ) {
1645 $element = array_pop( $wrapper );
1646 $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html );
1650 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
1651 $attrs = $item;
1652 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1653 unset( $attrs[$k] );
1656 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1657 $item['single-id'] = $item['id'];
1659 if ( isset( $item['single-id'] ) ) {
1660 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1661 $title = Linker::titleAttrib( $item['single-id'] );
1662 if ( $title !== false ) {
1663 $attrs['title'] = $title;
1665 } else {
1666 $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] );
1667 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1668 $attrs['title'] = $tip['title'];
1670 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1671 $attrs['accesskey'] = $tip['accesskey'];
1675 if ( isset( $options['link-class'] ) ) {
1676 if ( isset( $attrs['class'] ) ) {
1677 $attrs['class'] .= " {$options['link-class']}";
1678 } else {
1679 $attrs['class'] = $options['link-class'];
1682 $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html );
1685 return $html;
1689 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1690 * $key is a string, usually a key from the list you are generating this link from
1691 * $item is an array of list item data containing some of a specific set of keys.
1692 * The "id" and "class" keys will be used as attributes for the list item,
1693 * if "active" contains a value of true a "active" class will also be appended to class.
1694 * If you want something other than a <li> you can pass a tag name such as
1695 * "tag" => "span" in the $options array to change the tag used.
1696 * link/content data for the list item may come in one of two forms
1697 * A "links" key may be used, in which case it should contain an array with
1698 * a list of links to include inside the list item, see makeLink for the format
1699 * of individual links array items.
1700 * Otherwise the relevant keys from the list item $item array will be passed
1701 * to makeLink instead. Note however that "id" and "class" are used by the
1702 * list item directly so they will not be passed to makeLink
1703 * (however the link will still support a tooltip and accesskey from it)
1704 * If you need an id or class on a single link you should include a "links"
1705 * array with just one link item inside of it.
1706 * $options is also passed on to makeLink calls
1707 * @return string
1709 function makeListItem( $key, $item, $options = array() ) {
1710 if ( isset( $item['links'] ) ) {
1711 $html = '';
1712 foreach ( $item['links'] as $linkKey => $link ) {
1713 $html .= $this->makeLink( $linkKey, $link, $options );
1715 } else {
1716 $link = $item;
1717 // These keys are used by makeListItem and shouldn't be passed on to the link
1718 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1719 unset( $link[$k] );
1721 if ( isset( $item['id'] ) ) {
1722 // The id goes on the <li> not on the <a> for single links
1723 // but makeSidebarLink still needs to know what id to use when
1724 // generating tooltips and accesskeys.
1725 $link['single-id'] = $item['id'];
1727 $html = $this->makeLink( $key, $link, $options );
1730 $attrs = array();
1731 foreach ( array( 'id', 'class' ) as $attr ) {
1732 if ( isset( $item[$attr] ) ) {
1733 $attrs[$attr] = $item[$attr];
1736 if ( isset( $item['active'] ) && $item['active'] ) {
1737 if ( !isset( $attrs['class'] ) ) {
1738 $attrs['class'] = '';
1740 $attrs['class'] .= ' active';
1741 $attrs['class'] = trim( $attrs['class'] );
1743 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1746 function makeSearchInput( $attrs = array() ) {
1747 $realAttrs = array(
1748 'type' => 'search',
1749 'name' => 'search',
1750 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1752 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1753 return Html::element( 'input', $realAttrs );
1756 function makeSearchButton( $mode, $attrs = array() ) {
1757 switch( $mode ) {
1758 case 'go':
1759 case 'fulltext':
1760 $realAttrs = array(
1761 'type' => 'submit',
1762 'name' => $mode,
1763 'value' => $this->translator->translate(
1764 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1766 $realAttrs = array_merge(
1767 $realAttrs,
1768 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1769 $attrs
1771 return Html::element( 'input', $realAttrs );
1772 case 'image':
1773 $buttonAttrs = array(
1774 'type' => 'submit',
1775 'name' => 'button',
1777 $buttonAttrs = array_merge(
1778 $buttonAttrs,
1779 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1780 $attrs
1782 unset( $buttonAttrs['src'] );
1783 unset( $buttonAttrs['alt'] );
1784 $imgAttrs = array(
1785 'src' => $attrs['src'],
1786 'alt' => isset( $attrs['alt'] )
1787 ? $attrs['alt']
1788 : $this->translator->translate( 'searchbutton' ),
1790 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1791 default:
1792 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1797 * Returns an array of footerlinks trimmed down to only those footer links that
1798 * are valid.
1799 * If you pass "flat" as an option then the returned array will be a flat array
1800 * of footer icons instead of a key/value array of footerlinks arrays broken
1801 * up into categories.
1802 * @return array|mixed
1804 function getFooterLinks( $option = null ) {
1805 $footerlinks = $this->data['footerlinks'];
1807 // Reduce footer links down to only those which are being used
1808 $validFooterLinks = array();
1809 foreach( $footerlinks as $category => $links ) {
1810 $validFooterLinks[$category] = array();
1811 foreach( $links as $link ) {
1812 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1813 $validFooterLinks[$category][] = $link;
1816 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1817 unset( $validFooterLinks[$category] );
1821 if ( $option == 'flat' ) {
1822 // fold footerlinks into a single array using a bit of trickery
1823 $validFooterLinks = call_user_func_array(
1824 'array_merge',
1825 array_values( $validFooterLinks )
1829 return $validFooterLinks;
1833 * Returns an array of footer icons filtered down by options relevant to how
1834 * the skin wishes to display them.
1835 * If you pass "icononly" as the option all footer icons which do not have an
1836 * image icon set will be filtered out.
1837 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1838 * in the list of footer icons. This is mostly useful for skins which only
1839 * display the text from footericons instead of the images and don't want a
1840 * duplicate copyright statement because footerlinks already rendered one.
1841 * @return
1843 function getFooterIcons( $option = null ) {
1844 // Generate additional footer icons
1845 $footericons = $this->data['footericons'];
1847 if ( $option == 'icononly' ) {
1848 // Unset any icons which don't have an image
1849 foreach ( $footericons as &$footerIconsBlock ) {
1850 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1851 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1852 unset( $footerIconsBlock[$footerIconKey] );
1856 // Redo removal of any empty blocks
1857 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1858 if ( count( $footerIconsBlock ) <= 0 ) {
1859 unset( $footericons[$footerIconsKey] );
1862 } elseif ( $option == 'nocopyright' ) {
1863 unset( $footericons['copyright']['copyright'] );
1864 if ( count( $footericons['copyright'] ) <= 0 ) {
1865 unset( $footericons['copyright'] );
1869 return $footericons;
1873 * Output the basic end-page trail including bottomscripts, reporttime, and
1874 * debug stuff. This should be called right before outputting the closing
1875 * body and html tags.
1877 function printTrail() { ?>
1878 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
1879 <?php $this->html( 'reporttime' ) ?>
1880 <?php if ( $this->data['debug'] ): ?>
1881 <!-- Debug output:
1882 <?php $this->text( 'debug' ); ?>
1885 <?php endif;