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 $repository string: 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 * initialize various variables and generate the template
128 * @param $out OutputPage
130 function outputPage( OutputPage
$out=null ) {
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 $wgArticlePath, $wgScriptPath, $wgServer;
140 wfProfileIn( __METHOD__
);
141 Profiler
::instance()->setTemplated( true );
144 if ( $out !== null ) {
145 // @todo Add wfDeprecated in 1.20
146 $oldContext = $this->getContext();
147 $this->setContext( $out->getContext() );
150 $out = $this->getOutput();
151 $request = $this->getRequest();
152 $user = $this->getUser();
153 $title = $this->getTitle();
155 wfProfileIn( __METHOD__
. '-init' );
156 $this->initPage( $out );
158 $tpl = $this->setupTemplate( $this->template
, 'skins' );
159 wfProfileOut( __METHOD__
. '-init' );
161 wfProfileIn( __METHOD__
. '-stuff' );
162 $this->thispage
= $title->getPrefixedDBkey();
163 $this->titletxt
= $title->getPrefixedText();
164 $this->userpage
= $user->getUserPage()->getPrefixedText();
166 if ( !$request->wasPosted() ) {
167 $query = $request->getValues();
168 unset( $query['title'] );
169 unset( $query['returnto'] );
170 unset( $query['returntoquery'] );
172 $this->thisquery
= wfArrayToCGI( $query );
173 $this->loggedin
= $user->isLoggedIn();
174 $this->username
= $user->getName();
176 if ( $this->loggedin ||
$this->showIPinHeader() ) {
177 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
179 # This won't be used in the standard skins, but we define it to preserve the interface
180 # To save time, we check for existence
181 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
184 wfProfileOut( __METHOD__
. '-stuff' );
186 wfProfileIn( __METHOD__
. '-stuff-head' );
187 if ( !$this->useHeadElement
) {
188 $tpl->set( 'pagecss', false );
189 $tpl->set( 'usercss', false );
191 $tpl->set( 'userjs', false );
192 $tpl->set( 'userjsprev', false );
194 $tpl->set( 'jsvarurl', false );
196 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
197 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
198 $tpl->set( 'html5version', $wgHtml5Version );
199 $tpl->set( 'headlinks', $out->getHeadLinks() );
200 $tpl->set( 'csslinks', $out->buildCssLinks() );
201 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
202 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
204 wfProfileOut( __METHOD__
. '-stuff-head' );
206 wfProfileIn( __METHOD__
. '-stuff2' );
207 $tpl->set( 'title', $out->getPageTitle() );
208 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
209 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
211 $tpl->setRef( 'thispage', $this->thispage
);
212 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
213 $tpl->set( 'titletext', $title->getText() );
214 $tpl->set( 'articleid', $title->getArticleID() );
216 $tpl->set( 'isarticle', $out->isArticle() );
218 $subpagestr = $this->subPageSubtitle();
219 if ( $subpagestr !== '' ) {
220 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
222 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
224 $undelete = $this->getUndeleteLink();
225 if ( $undelete === '' ) {
226 $tpl->set( 'undelete', '' );
228 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
231 $tpl->set( 'catlinks', $this->getCategories() );
232 if( $out->isSyndicated() ) {
234 foreach( $out->getSyndicationLinks() as $format => $link ) {
235 $feeds[$format] = array(
236 'text' => $this->msg( "feed-$format" )->text(),
240 $tpl->setRef( 'feeds', $feeds );
242 $tpl->set( 'feeds', false );
245 $tpl->setRef( 'mimetype', $wgMimeType );
246 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
247 $tpl->set( 'charset', 'UTF-8' );
248 $tpl->setRef( 'wgScript', $wgScript );
249 $tpl->setRef( 'skinname', $this->skinname
);
250 $tpl->set( 'skinclass', get_class( $this ) );
251 $tpl->setRef( 'skin', $this );
252 $tpl->setRef( 'stylename', $this->stylename
);
253 $tpl->set( 'printable', $out->isPrintable() );
254 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
255 $tpl->setRef( 'loggedin', $this->loggedin
);
256 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
257 /* XXX currently unused, might get useful later
258 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
259 $tpl->set( 'exists', $title->getArticleID() != 0 );
260 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
261 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
262 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
264 $tpl->set( 'searchaction', $this->escapeSearchLink() );
265 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
266 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
267 $tpl->setRef( 'stylepath', $wgStylePath );
268 $tpl->setRef( 'articlepath', $wgArticlePath );
269 $tpl->setRef( 'scriptpath', $wgScriptPath );
270 $tpl->setRef( 'serverurl', $wgServer );
271 $tpl->setRef( 'logopath', $wgLogo );
272 $tpl->setRef( 'sitename', $wgSitename );
274 $userLang = $this->getLanguage();
275 $userLangCode = $userLang->getHtmlCode();
276 $userLangDir = $userLang->getDir();
278 $tpl->set( 'lang', $userLangCode );
279 $tpl->set( 'dir', $userLangDir );
280 $tpl->set( 'rtl', $userLang->isRTL() );
282 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
283 $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) );
284 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
285 $tpl->setRef( 'userpage', $this->userpage
);
286 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
287 $tpl->set( 'userlang', $userLangCode );
289 // Users can have their language set differently than the
290 // content of the wiki. For these users, tell the web browser
291 // that interface elements are in a different language.
292 $tpl->set( 'userlangattributes', '' );
293 $tpl->set( 'specialpageattributes', '' ); # obsolete
295 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
296 $escUserlang = htmlspecialchars( $userLangCode );
297 $escUserdir = htmlspecialchars( $userLangDir );
298 // Attributes must be in double quotes because htmlspecialchars() doesn't
299 // escape single quotes
300 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
301 $tpl->set( 'userlangattributes', $attrs );
304 wfProfileOut( __METHOD__
. '-stuff2' );
306 wfProfileIn( __METHOD__
. '-stuff3' );
307 $tpl->set( 'newtalk', $this->getNewtalks() );
308 $tpl->set( 'logo', $this->logoText() );
310 $tpl->set( 'copyright', false );
311 $tpl->set( 'viewcount', false );
312 $tpl->set( 'lastmod', false );
313 $tpl->set( 'credits', false );
314 $tpl->set( 'numberofwatchingusers', false );
315 if ( $out->isArticle() && $title->exists() ) {
316 if ( $this->isRevisionCurrent() ) {
317 if ( !$wgDisableCounters ) {
318 $viewcount = $this->getWikiPage()->getCount();
320 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
324 if ( $wgPageShowWatchingUsers ) {
325 $dbr = wfGetDB( DB_SLAVE
);
326 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
327 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
331 $tpl->set( 'numberofwatchingusers',
332 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
337 if ( $wgMaxCredits != 0 ) {
338 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
339 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
341 $tpl->set( 'lastmod', $this->lastModified() );
344 $tpl->set( 'copyright', $this->getCopyright() );
346 wfProfileOut( __METHOD__
. '-stuff3' );
348 wfProfileIn( __METHOD__
. '-stuff4' );
349 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
350 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
351 $tpl->set( 'disclaimer', $this->disclaimerLink() );
352 $tpl->set( 'privacy', $this->privacyLink() );
353 $tpl->set( 'about', $this->aboutLink() );
355 $tpl->set( 'footerlinks', array(
359 'numberofwatchingusers',
370 global $wgFooterIcons;
371 $tpl->set( 'footericons', $wgFooterIcons );
372 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
373 if ( count( $footerIconsBlock ) > 0 ) {
374 foreach ( $footerIconsBlock as &$footerIcon ) {
375 if ( isset( $footerIcon['src'] ) ) {
376 if ( !isset( $footerIcon['width'] ) ) {
377 $footerIcon['width'] = 88;
379 if ( !isset( $footerIcon['height'] ) ) {
380 $footerIcon['height'] = 31;
385 unset( $tpl->data
['footericons'][$footerIconsKey] );
389 $tpl->set( 'sitenotice', $this->getSiteNotice() );
390 $tpl->set( 'bottomscripts', $this->bottomScripts() );
391 $tpl->set( 'printfooter', $this->printSource() );
393 # An ID that includes the actual body text; without categories, contentSub, ...
394 $realBodyAttribs = array( 'id' => 'mw-content-text' );
396 # Add a mw-content-ltr/rtl class to be able to style based on text direction
397 # when the content is different from the UI language, i.e.:
398 # not for special pages or file pages AND only when viewing AND if the page exists
399 # (or is in MW namespace, because that has default content)
400 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
401 in_array( $request->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) &&
402 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
403 $pageLang = $title->getPageViewLanguage();
404 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
405 $realBodyAttribs['dir'] = $pageLang->getDir();
406 $realBodyAttribs['class'] = 'mw-content-'.$pageLang->getDir();
409 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
410 $tpl->setRef( 'bodytext', $out->mBodytext
);
413 $language_urls = array();
415 if ( !$wgHideInterlanguageLinks ) {
416 foreach( $out->getLanguageLinks() as $l ) {
417 $tmp = explode( ':', $l, 2 );
418 $class = 'interwiki-' . $tmp[0];
420 $nt = Title
::newFromText( $l );
422 $ilLangName = Language
::fetchLanguageName( $nt->getInterwiki() );
423 if ( strval( $ilLangName ) === '' ) {
426 $ilLangName = $this->formatLanguageName( $ilLangName );
428 $language_urls[] = array(
429 'href' => $nt->getFullURL(),
430 'text' => $ilLangName,
431 'title' => $nt->getText(),
433 'lang' => $nt->getInterwiki(),
434 'hreflang' => $nt->getInterwiki(),
439 if ( count( $language_urls ) ) {
440 $tpl->setRef( 'language_urls', $language_urls );
442 $tpl->set( 'language_urls', false );
444 wfProfileOut( __METHOD__
. '-stuff4' );
446 wfProfileIn( __METHOD__
. '-stuff5' );
448 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
449 $content_navigation = $this->buildContentNavigationUrls();
450 $content_actions = $this->buildContentActionUrls( $content_navigation );
451 $tpl->setRef( 'content_navigation', $content_navigation );
452 $tpl->setRef( 'content_actions', $content_actions );
454 $tpl->set( 'sidebar', $this->buildSidebar() );
455 $tpl->set( 'nav_urls', $this->buildNavUrls() );
457 // Set the head scripts near the end, in case the above actions resulted in added scripts
458 if ( $this->useHeadElement
) {
459 $tpl->set( 'headelement', $out->headElement( $this ) );
461 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
464 $tpl->set( 'debug', '' );
465 $tpl->set( 'debughtml', $this->generateDebugHTML() );
466 $tpl->set( 'reporttime', wfReportTime() );
468 // original version by hansm
469 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
470 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
473 // Set the bodytext to another key so that skins can just output it on it's own
474 // and output printfooter and debughtml separately
475 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
477 // Append printfooter and debughtml onto bodytext so that skins that were already
478 // using bodytext before they were split out don't suddenly start not outputting information
479 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
480 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
482 // allow extensions adding stuff after the page content.
483 // See Skin::afterContentHook() for further documentation.
484 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
485 wfProfileOut( __METHOD__
. '-stuff5' );
488 wfProfileIn( __METHOD__
. '-execute' );
489 $res = $tpl->execute();
490 wfProfileOut( __METHOD__
. '-execute' );
492 // result may be an error
493 $this->printOrError( $res );
496 $this->setContext( $oldContext );
498 wfProfileOut( __METHOD__
);
502 * Format language name for use in sidebar interlanguage links list.
503 * By default it is capitalized.
505 * @param $name string Language name, e.g. "English" or "español"
508 function formatLanguageName( $name ) {
509 return $this->getLanguage()->ucfirst( $name );
513 * Output the string, or print error message if it's
514 * an error object of the appropriate type.
515 * For the base class, assume strings all around.
520 function printOrError( $str ) {
525 * Output a boolean indiciating if buildPersonalUrls should output separate
526 * login and create account links or output a combined link
527 * By default we simply return a global config setting that affects most skins
528 * This is setup as a method so that like with $wgLogo and getLogo() a skin
529 * can override this setting and always output one or the other if it has
530 * a reason it can't output one of the two modes.
533 function useCombinedLoginLink() {
534 global $wgUseCombinedLoginLink;
535 return $wgUseCombinedLoginLink;
539 * build array of urls for personal toolbar
542 protected function buildPersonalUrls() {
543 global $wgSecureLogin;
545 $title = $this->getTitle();
546 $request = $this->getRequest();
547 $pageurl = $title->getLocalURL();
548 wfProfileIn( __METHOD__
);
550 /* set up the default links for the personal toolbar */
551 $personal_urls = array();
553 # Due to bug 32276, if a user does not have read permissions,
554 # $this->getTitle() will just give Special:Badtitle, which is
555 # not especially useful as a returnto parameter. Use the title
556 # from the request instead, if there was one.
557 $page = Title
::newFromURL( $request->getVal( 'title', '' ) );
558 $page = $request->getVal( 'returnto', $page );
560 if ( strval( $page ) !== '' ) {
561 $a['returnto'] = $page;
562 $query = $request->getVal( 'returntoquery', $this->thisquery
);
564 $a['returntoquery'] = $query;
568 if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) {
569 $a['wpStickHTTPS'] = true;
572 $returnto = wfArrayToCGI( $a );
573 if( $this->loggedin
) {
574 $personal_urls['userpage'] = array(
575 'text' => $this->username
,
576 'href' => &$this->userpageUrlDetails
['href'],
577 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
578 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
581 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
582 $personal_urls['mytalk'] = array(
583 'text' => $this->msg( 'mytalk' )->text(),
584 'href' => &$usertalkUrlDetails['href'],
585 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
586 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
588 $href = self
::makeSpecialUrl( 'Preferences' );
589 $personal_urls['preferences'] = array(
590 'text' => $this->msg( 'mypreferences' )->text(),
592 'active' => ( $href == $pageurl )
594 $href = self
::makeSpecialUrl( 'Watchlist' );
595 $personal_urls['watchlist'] = array(
596 'text' => $this->msg( 'mywatchlist' )->text(),
598 'active' => ( $href == $pageurl )
601 # We need to do an explicit check for Special:Contributions, as we
602 # have to match both the title, and the target, which could come
603 # from request values (Special:Contributions?target=Jimbo_Wales)
604 # or be specified in "sub page" form
605 # (Special:Contributions/Jimbo_Wales). The plot
606 # thickens, because the Title object is altered for special pages,
607 # so it doesn't contain the original alias-with-subpage.
608 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
609 if( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
610 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
611 $active = $spName == 'Contributions'
612 && ( ( $spPar && $spPar == $this->username
)
613 ||
$request->getText( 'target' ) == $this->username
);
618 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
619 $personal_urls['mycontris'] = array(
620 'text' => $this->msg( 'mycontris' )->text(),
624 $personal_urls['logout'] = array(
625 'text' => $this->msg( 'userlogout' )->text(),
626 'href' => self
::makeSpecialUrl( 'Userlogout',
627 // userlogout link must always contain an & character, otherwise we might not be able
628 // to detect a buggy precaching proxy (bug 17790)
629 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
634 $useCombinedLoginLink = $this->useCombinedLoginLink();
635 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
636 ?
'nav-login-createaccount'
638 $is_signup = $request->getText( 'type' ) == 'signup';
640 # anonlogin & login are the same
641 global $wgSecureLogin;
642 $proto = $wgSecureLogin ? PROTO_HTTPS
: null;
644 $login_id = $this->showIPinHeader() ?
'anonlogin' : 'login';
646 'text' => $this->msg( $loginlink )->text(),
647 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
648 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
649 'class' => $wgSecureLogin ?
'link-https' : ''
651 $createaccount_url = array(
652 'text' => $this->msg( 'createaccount' )->text(),
653 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
654 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
655 'class' => $wgSecureLogin ?
'link-https' : ''
658 if( $this->showIPinHeader() ) {
659 $href = &$this->userpageUrlDetails
['href'];
660 $personal_urls['anonuserpage'] = array(
661 'text' => $this->username
,
663 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
664 'active' => ( $pageurl == $href )
666 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
667 $href = &$usertalkUrlDetails['href'];
668 $personal_urls['anontalk'] = array(
669 'text' => $this->msg( 'anontalk' )->text(),
671 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
672 'active' => ( $pageurl == $href )
676 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
677 $personal_urls['createaccount'] = $createaccount_url;
680 $personal_urls[$login_id] = $login_url;
683 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
684 wfProfileOut( __METHOD__
);
685 return $personal_urls;
690 * @param $title Title
691 * @param $message String message key
692 * @param $selected Bool
693 * @param $query String
694 * @param $checkEdit Bool
697 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
700 $classes[] = 'selected';
702 if( $checkEdit && !$title->isKnown() ) {
704 $query = 'action=edit&redlink=1';
707 // wfMessageFallback will nicely accept $message as an array of fallbacks
708 // or just a single key
709 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
710 if ( is_array( $message ) ) {
711 // for hook compatibility just keep the last message name
712 $message = end( $message );
714 if ( $msg->exists() ) {
715 $text = $msg->text();
718 $text = $wgContLang->getFormattedNsText(
719 MWNamespace
::getSubject( $title->getNamespace() ) );
723 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
724 $title, $message, $selected, $checkEdit,
725 &$classes, &$query, &$text, &$result ) ) ) {
730 'class' => implode( ' ', $classes ),
732 'href' => $title->getLocalUrl( $query ),
736 function makeTalkUrlDetails( $name, $urlaction = '' ) {
737 $title = Title
::newFromText( $name );
738 if( !is_object( $title ) ) {
739 throw new MWException( __METHOD__
. " given invalid pagename $name" );
741 $title = $title->getTalkPage();
742 self
::checkTitle( $title, $name );
744 'href' => $title->getLocalURL( $urlaction ),
745 'exists' => $title->getArticleID() != 0,
749 function makeArticleUrlDetails( $name, $urlaction = '' ) {
750 $title = Title
::newFromText( $name );
751 $title= $title->getSubjectPage();
752 self
::checkTitle( $title, $name );
754 'href' => $title->getLocalURL( $urlaction ),
755 'exists' => $title->getArticleID() != 0,
760 * a structured array of links usually used for the tabs in a skin
762 * There are 4 standard sections
763 * namespaces: Used for namespace tabs like special, page, and talk namespaces
764 * views: Used for primary page views like read, edit, history
765 * actions: Used for most extra page actions like deletion, protection, etc...
766 * variants: Used to list the language variants for the page
768 * Each section's value is a key/value array of links for that section.
769 * The links themseves have these common keys:
770 * - class: The css classes to apply to the tab
771 * - text: The text to display on the tab
772 * - href: The href for the tab to point to
773 * - rel: An optional rel= for the tab's link
774 * - redundant: If true the tab will be dropped in skins using content_actions
775 * this is useful for tabs like "Read" which only have meaning in skins that
776 * take special meaning from the grouped structure of content_navigation
778 * Views also have an extra key which can be used:
779 * - primary: If this is not true skins like vector may try to hide the tab
780 * when the user has limited space in their browser window
782 * content_navigation using code also expects these ids to be present on the
783 * links, however these are usually automatically generated by SkinTemplate
784 * itself and are not necessary when using a hook. The only things these may
785 * matter to are people modifying content_navigation after it's initial creation:
786 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
787 * - tooltiponly: This is set to true for some tabs in cases where the system
788 * believes that the accesskey should not be added to the tab.
792 protected function buildContentNavigationUrls() {
793 global $wgDisableLangConversion;
795 wfProfileIn( __METHOD__
);
797 // Display tabs for the relevant title rather than always the title itself
798 $title = $this->getRelevantTitle();
799 $onPage = $title->equals( $this->getTitle() );
801 $out = $this->getOutput();
802 $request = $this->getRequest();
803 $user = $this->getUser();
805 $content_navigation = array(
806 'namespaces' => array(),
808 'actions' => array(),
809 'variants' => array()
813 $action = $request->getVal( 'action', 'view' );
815 $userCanRead = $title->quickUserCan( 'read', $user );
817 $preventActiveTabs = false;
818 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
820 // Checks if page is some kind of content
821 if( $title->canExist() ) {
822 // Gets page objects for the related namespaces
823 $subjectPage = $title->getSubjectPage();
824 $talkPage = $title->getTalkPage();
826 // Determines if this is a talk page
827 $isTalk = $title->isTalkPage();
829 // Generates XML IDs from namespace names
830 $subjectId = $title->getNamespaceKey( '' );
832 if ( $subjectId == 'main' ) {
835 $talkId = "{$subjectId}_talk";
838 $skname = $this->skinname
;
840 // Adds namespace links
841 $subjectMsg = array( "nstab-$subjectId" );
842 if ( $subjectPage->isMainPage() ) {
843 array_unshift( $subjectMsg, 'mainpage-nstab' );
845 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
846 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
848 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
849 $content_navigation['namespaces'][$talkId] = $this->tabAction(
850 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
852 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
854 if ( $userCanRead ) {
855 // Adds view view link
856 if ( $title->exists() ) {
857 $content_navigation['views']['view'] = $this->tabAction(
858 $isTalk ?
$talkPage : $subjectPage,
859 array( "$skname-view-view", 'view' ),
860 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
862 // signal to hide this from simple content_actions
863 $content_navigation['views']['view']['redundant'] = true;
866 wfProfileIn( __METHOD__
. '-edit' );
868 // Checks if user can edit the current page if it exists or create it otherwise
869 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
870 // Builds CSS class for talk page links
871 $isTalkClass = $isTalk ?
' istalk' : '';
872 // Whether the user is editing the page
873 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
874 // Whether to show the "Add a new section" tab
875 // Checks if this is a current rev of talk page and is not forced to be hidden
876 $showNewSection = !$out->forceHideNewSectionLink()
877 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
878 $section = $request->getVal( 'section' );
880 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
882 $content_navigation['views']['edit'] = array(
883 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
884 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
885 'href' => $title->getLocalURL( $this->editUrlOptions() ),
886 'primary' => true, // don't collapse this in vector
890 if ( $showNewSection ) {
891 // Adds new section link
892 //$content_navigation['actions']['addsection']
893 $content_navigation['views']['addsection'] = array(
894 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
895 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
896 'href' => $title->getLocalURL( 'action=edit§ion=new' )
899 // Checks if the page has some kind of viewable content
900 } elseif ( $title->hasSourceText() ) {
901 // Adds view source view link
902 $content_navigation['views']['viewsource'] = array(
903 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
904 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
905 'href' => $title->getLocalURL( $this->editUrlOptions() ),
906 'primary' => true, // don't collapse this in vector
909 wfProfileOut( __METHOD__
. '-edit' );
911 wfProfileIn( __METHOD__
. '-live' );
912 // Checks if the page exists
913 if ( $title->exists() ) {
914 // Adds history view link
915 $content_navigation['views']['history'] = array(
916 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
917 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
918 'href' => $title->getLocalURL( 'action=history' ),
922 if ( $title->quickUserCan( 'delete', $user ) ) {
923 $content_navigation['actions']['delete'] = array(
924 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
925 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
926 'href' => $title->getLocalURL( 'action=delete' )
930 if ( $title->quickUserCan( 'move', $user ) ) {
931 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
932 $content_navigation['actions']['move'] = array(
933 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
934 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
935 'href' => $moveTitle->getLocalURL()
939 // article doesn't exist or is deleted
940 if ( $user->isAllowed( 'deletedhistory' ) ) {
941 $n = $title->isDeleted();
943 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
944 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
945 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
946 $content_navigation['actions']['undelete'] = array(
947 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
948 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
949 ->setContext( $this->getContext() )->numParams( $n )->text(),
950 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
956 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) ) {
957 $mode = $title->isProtected() ?
'unprotect' : 'protect';
958 $content_navigation['actions'][$mode] = array(
959 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
960 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
961 'href' => $title->getLocalURL( "action=$mode" )
965 wfProfileOut( __METHOD__
. '-live' );
967 // Checks if the user is logged in
968 if ( $this->loggedin
) {
970 * The following actions use messages which, if made particular to
971 * the any specific skins, would break the Ajax code which makes this
972 * action happen entirely inline. Skin::makeGlobalVariablesScript
973 * defines a set of messages in a javascript object - and these
974 * messages are assumed to be global for all skins. Without making
975 * a change to that procedure these messages will have to remain as
976 * the global versions.
978 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
979 $token = WatchAction
::getWatchToken( $title, $user, $mode );
980 $content_navigation['actions'][$mode] = array(
981 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
982 // uses 'watch' or 'unwatch' message
983 'text' => $this->msg( $mode )->text(),
984 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
989 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
991 if ( $userCanRead && !$wgDisableLangConversion ) {
992 $pageLang = $title->getPageLanguage();
993 // Gets list of language variants
994 $variants = $pageLang->getVariants();
995 // Checks that language conversion is enabled and variants exist
996 // And if it is not in the special namespace
997 if ( count( $variants ) > 1 ) {
998 // Gets preferred variant (note that user preference is
999 // only possible for wiki content language variant)
1000 $preferred = $pageLang->getPreferredVariant();
1001 // Loops over each variant
1002 foreach( $variants as $code ) {
1003 // Gets variant name from language code
1004 $varname = $pageLang->getVariantname( $code );
1005 // Checks if the variant is marked as disabled
1006 if( $varname == 'disable' ) {
1007 // Skips this variant
1010 // Appends variant link
1011 $content_navigation['variants'][] = array(
1012 'class' => ( $code == $preferred ) ?
'selected' : false,
1014 'href' => $title->getLocalURL( array( 'variant' => $code ) ),
1022 // If it's not content, it's got to be a special page
1023 $content_navigation['namespaces']['special'] = array(
1024 'class' => 'selected',
1025 'text' => $this->msg( 'nstab-special' )->text(),
1026 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1027 'context' => 'subject'
1030 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1031 array( &$this, &$content_navigation ) );
1034 // Equiv to SkinTemplateContentActions
1035 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1037 // Setup xml ids and tooltip info
1038 foreach ( $content_navigation as $section => &$links ) {
1039 foreach ( $links as $key => &$link ) {
1041 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1042 $xmlID = 'ca-nstab-' . $xmlID;
1043 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1045 } elseif ( $section == 'variants' ) {
1046 $xmlID = 'ca-varlang-' . $xmlID;
1048 $xmlID = 'ca-' . $xmlID;
1050 $link['id'] = $xmlID;
1054 # We don't want to give the watch tab an accesskey if the
1055 # page is being edited, because that conflicts with the
1056 # accesskey on the watch checkbox. We also don't want to
1057 # give the edit tab an accesskey, because that's fairly su-
1058 # perfluous and conflicts with an accesskey (Ctrl-E) often
1059 # used for editing in Safari.
1060 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1061 if ( isset( $content_navigation['views']['edit'] ) ) {
1062 $content_navigation['views']['edit']['tooltiponly'] = true;
1064 if ( isset( $content_navigation['actions']['watch'] ) ) {
1065 $content_navigation['actions']['watch']['tooltiponly'] = true;
1067 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1068 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1072 wfProfileOut( __METHOD__
);
1074 return $content_navigation;
1078 * an array of edit links by default used for the tabs
1082 function buildContentActionUrls( $content_navigation ) {
1084 wfProfileIn( __METHOD__
);
1086 // content_actions has been replaced with content_navigation for backwards
1087 // compatibility and also for skins that just want simple tabs content_actions
1088 // is now built by flattening the content_navigation arrays into one
1090 $content_actions = array();
1092 foreach ( $content_navigation as $links ) {
1094 foreach ( $links as $key => $value ) {
1096 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1097 // Redundant tabs are dropped from content_actions
1101 // content_actions used to have ids built using the "ca-$key" pattern
1102 // so the xmlID based id is much closer to the actual $key that we want
1103 // for that reason we'll just strip out the ca- if present and use
1104 // the latter potion of the "id" as the $key
1105 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1106 $key = substr( $value['id'], 3 );
1109 if ( isset( $content_actions[$key] ) ) {
1110 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1114 $content_actions[$key] = $value;
1120 wfProfileOut( __METHOD__
);
1122 return $content_actions;
1126 * build array of common navigation links
1130 protected function buildNavUrls() {
1131 global $wgUploadNavigationUrl;
1133 wfProfileIn( __METHOD__
);
1135 $out = $this->getOutput();
1136 $request = $this->getRequest();
1138 $nav_urls = array();
1139 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1140 if( $wgUploadNavigationUrl ) {
1141 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1142 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1143 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1145 $nav_urls['upload'] = false;
1147 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1149 $nav_urls['print'] = false;
1150 $nav_urls['permalink'] = false;
1151 $nav_urls['info'] = false;
1152 $nav_urls['whatlinkshere'] = false;
1153 $nav_urls['recentchangeslinked'] = false;
1154 $nav_urls['contributions'] = false;
1155 $nav_urls['log'] = false;
1156 $nav_urls['blockip'] = false;
1157 $nav_urls['emailuser'] = false;
1159 // A print stylesheet is attached to all pages, but nobody ever
1160 // figures that out. :) Add a link...
1161 if ( $out->isArticle() ) {
1162 if ( !$out->isPrintable() ) {
1163 $nav_urls['print'] = array(
1164 'text' => $this->msg( 'printableversion' )->text(),
1165 'href' => $this->getTitle()->getLocalURL(
1166 $request->appendQueryValue( 'printable', 'yes', true ) )
1170 // Also add a "permalink" while we're at it
1171 $revid = $this->getRevisionId();
1173 $nav_urls['permalink'] = array(
1174 'text' => $this->msg( 'permalink' )->text(),
1175 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1179 $nav_urls['info'] = array(
1180 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1181 'href' => $out->getTitle()->getLocalURL( "action=info" )
1184 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1185 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1186 array( &$this, &$nav_urls, &$revid, &$revid ) );
1189 if ( $out->isArticleRelated() ) {
1190 $nav_urls['whatlinkshere'] = array(
1191 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalUrl()
1193 if ( $this->getTitle()->getArticleID() ) {
1194 $nav_urls['recentchangeslinked'] = array(
1195 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalUrl()
1200 $user = $this->getRelevantUser();
1202 $rootUser = $user->getName();
1204 $nav_urls['contributions'] = array(
1205 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1208 $nav_urls['log'] = array(
1209 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1212 if ( $this->getUser()->isAllowed( 'block' ) ) {
1213 $nav_urls['blockip'] = array(
1214 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1218 if ( $this->showEmailUser( $user ) ) {
1219 $nav_urls['emailuser'] = array(
1220 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1225 wfProfileOut( __METHOD__
);
1230 * Generate strings used for xml 'id' names
1234 function getNameSpaceKey() {
1235 return $this->getTitle()->getNamespaceKey();
1238 public function commonPrintStylesheet() {
1244 * Generic wrapper for template functions, with interface
1245 * compatible with what we use of PHPTAL 0.7.
1248 abstract class QuickTemplate
{
1252 function __construct() {
1253 $this->data
= array();
1254 $this->translator
= new MediaWiki_I18N();
1258 * Sets the value $value to $name
1262 public function set( $name, $value ) {
1263 $this->data
[$name] = $value;
1270 public function setRef( $name, &$value ) {
1271 $this->data
[$name] =& $value;
1277 public function setTranslator( &$t ) {
1278 $this->translator
= &$t;
1282 * Main function, used by classes that subclass QuickTemplate
1283 * to show the actual HTML output
1285 abstract public function execute();
1290 function text( $str ) {
1291 echo htmlspecialchars( $this->data
[$str] );
1297 function jstext( $str ) {
1298 echo Xml
::escapeJsString( $this->data
[$str] );
1304 function html( $str ) {
1305 echo $this->data
[$str];
1311 function msg( $str ) {
1312 echo htmlspecialchars( $this->translator
->translate( $str ) );
1318 function msgHtml( $str ) {
1319 echo $this->translator
->translate( $str );
1323 * An ugly, ugly hack.
1326 function msgWiki( $str ) {
1329 $text = $this->translator
->translate( $str );
1330 echo $wgOut->parse( $text );
1337 function haveData( $str ) {
1338 return isset( $this->data
[$str] );
1346 function haveMsg( $str ) {
1347 $msg = $this->translator
->translate( $str );
1348 return ( $msg != '-' ) && ( $msg != '' ); # ????
1352 * Get the Skin object related to this object
1354 * @return Skin object
1356 public function getSkin() {
1357 return $this->data
['skin'];
1362 * New base template for a skin's template extended from QuickTemplate
1363 * this class features helper methods that provide common ways of interacting
1364 * with the data stored in the QuickTemplate
1366 abstract class BaseTemplate
extends QuickTemplate
{
1369 * Get a Message object with its context set
1371 * @param $name string message name
1374 public function getMsg( $name ) {
1375 return $this->getSkin()->msg( $name );
1378 function msg( $str ) {
1379 echo $this->getMsg( $str )->escaped();
1382 function msgHtml( $str ) {
1383 echo $this->getMsg( $str )->text();
1386 function msgWiki( $str ) {
1387 echo $this->getMsg( $str )->parseAsBlock();
1391 * Create an array of common toolbox items from the data in the quicktemplate
1392 * stored by SkinTemplate.
1393 * The resulting array is built acording to a format intended to be passed
1394 * through makeListItem to generate the html.
1397 function getToolbox() {
1398 wfProfileIn( __METHOD__
);
1401 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1402 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1403 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1405 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1406 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1407 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1408 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1410 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1411 $toolbox['feeds']['id'] = 'feedlinks';
1412 $toolbox['feeds']['links'] = array();
1413 foreach ( $this->data
['feeds'] as $key => $feed ) {
1414 $toolbox['feeds']['links'][$key] = $feed;
1415 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1416 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1417 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1418 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1421 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1422 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1423 $toolbox[$special] = $this->data
['nav_urls'][$special];
1424 $toolbox[$special]['id'] = "t-$special";
1427 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1428 $toolbox['print'] = $this->data
['nav_urls']['print'];
1429 $toolbox['print']['id'] = 't-print';
1430 $toolbox['print']['rel'] = 'alternate';
1431 $toolbox['print']['msg'] = 'printableversion';
1433 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1434 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1435 if ( $toolbox['permalink']['href'] === '' ) {
1436 unset( $toolbox['permalink']['href'] );
1437 $toolbox['ispermalink']['tooltiponly'] = true;
1438 $toolbox['ispermalink']['id'] = 't-ispermalink';
1439 $toolbox['ispermalink']['msg'] = 'permalink';
1441 $toolbox['permalink']['id'] = 't-permalink';
1444 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1445 $toolbox['info'] = $this->data
['nav_urls']['info'];
1448 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1449 wfProfileOut( __METHOD__
);
1454 * Create an array of personal tools items from the data in the quicktemplate
1455 * stored by SkinTemplate.
1456 * The resulting array is built acording to a format intended to be passed
1457 * through makeListItem to generate the html.
1458 * This is in reality the same list as already stored in personal_urls
1459 * however it is reformatted so that you can just pass the individual items
1460 * to makeListItem instead of hardcoding the element creation boilerplate.
1463 function getPersonalTools() {
1464 $personal_tools = array();
1465 foreach ( $this->data
['personal_urls'] as $key => $plink ) {
1466 # The class on a personal_urls item is meant to go on the <a> instead
1467 # of the <li> so we have to use a single item "links" array instead
1468 # of using most of the personal_url's keys directly.
1471 array( 'single-id' => "pt-$key" ),
1475 if ( isset( $plink['active'] ) ) {
1476 $ptool['active'] = $plink['active'];
1478 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1479 if ( isset( $plink[$k] ) )
1480 $ptool['links'][0][$k] = $plink[$k];
1482 $personal_tools[$key] = $ptool;
1484 return $personal_tools;
1487 function getSidebar( $options = array() ) {
1488 // Force the rendering of the following portals
1489 $sidebar = $this->data
['sidebar'];
1490 if ( !isset( $sidebar['SEARCH'] ) ) {
1491 $sidebar['SEARCH'] = true;
1493 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1494 $sidebar['TOOLBOX'] = true;
1496 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1497 $sidebar['LANGUAGES'] = true;
1500 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1501 unset( $sidebar['SEARCH'] );
1503 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1504 unset( $sidebar['TOOLBOX'] );
1506 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1507 unset( $sidebar['LANGUAGES'] );
1511 foreach ( $sidebar as $boxName => $content ) {
1512 if ( $content === false ) {
1515 switch ( $boxName ) {
1517 // Search is a special case, skins should custom implement this
1518 $boxes[$boxName] = array(
1520 'header' => $this->getMsg( 'search' )->text(),
1521 'generated' => false,
1526 $msgObj = $this->getMsg( 'toolbox' );
1527 $boxes[$boxName] = array(
1529 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1530 'generated' => false,
1531 'content' => $this->getToolbox(),
1535 if ( $this->data
['language_urls'] ) {
1536 $msgObj = $this->getMsg( 'otherlanguages' );
1537 $boxes[$boxName] = array(
1539 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1540 'generated' => false,
1541 'content' => $this->data
['language_urls'],
1546 $msgObj = $this->getMsg( $boxName );
1547 $boxes[$boxName] = array(
1548 'id' => "p-$boxName",
1549 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1550 'generated' => true,
1551 'content' => $content,
1557 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1558 $hookContents = null;
1559 if ( isset( $boxes['TOOLBOX'] ) ) {
1561 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1562 // can abort and avoid outputting double toolbox links
1563 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1564 $hookContents = ob_get_contents();
1566 if ( !trim( $hookContents ) ) {
1567 $hookContents = null;
1572 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1573 foreach ( $boxes as $boxName => $box ) {
1574 if ( is_array( $box['content'] ) ) {
1576 foreach ( $box['content'] as $key => $val ) {
1577 $content .= "\n " . $this->makeListItem( $key, $val );
1579 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1580 if ( $hookContents ) {
1581 $content .= "\n $hookContents";
1584 $content .= "\n</ul>\n";
1585 $boxes[$boxName]['content'] = $content;
1589 if ( $hookContents ) {
1590 $boxes['TOOLBOXEND'] = array(
1591 'id' => 'p-toolboxend',
1592 'header' => $boxes['TOOLBOX']['header'],
1593 'generated' => false,
1594 'content' => "<ul>{$hookContents}</ul>",
1596 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1598 foreach ( $boxes as $key => $box ) {
1599 if ( $key === 'TOOLBOXEND' ) {
1602 $boxes2[$key] = $box;
1603 if ( $key === 'TOOLBOX' ) {
1604 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1616 * Makes a link, usually used by makeListItem to generate a link for an item
1617 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1619 * @param $key string usually a key from the list you are generating this
1621 * @param $item array contains some of a specific set of keys.
1623 * The text of the link will be generated either from the contents of the
1624 * "text" key in the $item array, if a "msg" key is present a message by
1625 * that name will be used, and if neither of those are set the $key will be
1626 * used as a message name.
1628 * If a "href" key is not present makeLink will just output htmlescaped text.
1629 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1630 * for the link if present.
1632 * If an "id" or "single-id" (if you don't want the actual id to be output
1633 * on the link) is present it will be used to generate a tooltip and
1634 * accesskey for the link.
1636 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1638 * @param $options array can be used to affect the output of a link.
1639 * Possible options are:
1640 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1641 * a link in. This should be an array of arrays containing a 'tag' and
1642 * optionally an 'attributes' key. If you only have one element you don't
1643 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1644 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1646 * - 'link-class' key can be used to specify additional classes to apply
1648 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1649 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1650 * any non-link will output a "<span>" instead of just text.
1654 function makeLink( $key, $item, $options = array() ) {
1655 if ( isset( $item['text'] ) ) {
1656 $text = $item['text'];
1658 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1661 $html = htmlspecialchars( $text );
1663 if ( isset( $options['text-wrapper'] ) ) {
1664 $wrapper = $options['text-wrapper'];
1665 if ( isset( $wrapper['tag'] ) ) {
1666 $wrapper = array( $wrapper );
1668 while ( count( $wrapper ) > 0 ) {
1669 $element = array_pop( $wrapper );
1670 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1674 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1676 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1677 unset( $attrs[$k] );
1680 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1681 $item['single-id'] = $item['id'];
1683 if ( isset( $item['single-id'] ) ) {
1684 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1685 $title = Linker
::titleAttrib( $item['single-id'] );
1686 if ( $title !== false ) {
1687 $attrs['title'] = $title;
1690 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1691 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1692 $attrs['title'] = $tip['title'];
1694 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1695 $attrs['accesskey'] = $tip['accesskey'];
1699 if ( isset( $options['link-class'] ) ) {
1700 if ( isset( $attrs['class'] ) ) {
1701 $attrs['class'] .= " {$options['link-class']}";
1703 $attrs['class'] = $options['link-class'];
1706 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1713 * Generates a list item for a navigation, portlet, portal, sidebar... list
1715 * @param $key string, usually a key from the list you are generating this link from.
1716 * @param $item array, of list item data containing some of a specific set of keys.
1717 * The "id" and "class" keys will be used as attributes for the list item,
1718 * if "active" contains a value of true a "active" class will also be appended to class.
1720 * @param $options array
1722 * If you want something other than a "<li>" you can pass a tag name such as
1723 * "tag" => "span" in the $options array to change the tag used.
1724 * link/content data for the list item may come in one of two forms
1725 * A "links" key may be used, in which case it should contain an array with
1726 * a list of links to include inside the list item, see makeLink for the
1727 * format of individual links array items.
1729 * Otherwise the relevant keys from the list item $item array will be passed
1730 * to makeLink instead. Note however that "id" and "class" are used by the
1731 * list item directly so they will not be passed to makeLink
1732 * (however the link will still support a tooltip and accesskey from it)
1733 * If you need an id or class on a single link you should include a "links"
1734 * array with just one link item inside of it.
1735 * $options is also passed on to makeLink calls
1739 function makeListItem( $key, $item, $options = array() ) {
1740 if ( isset( $item['links'] ) ) {
1742 foreach ( $item['links'] as $linkKey => $link ) {
1743 $html .= $this->makeLink( $linkKey, $link, $options );
1747 // These keys are used by makeListItem and shouldn't be passed on to the link
1748 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1751 if ( isset( $item['id'] ) ) {
1752 // The id goes on the <li> not on the <a> for single links
1753 // but makeSidebarLink still needs to know what id to use when
1754 // generating tooltips and accesskeys.
1755 $link['single-id'] = $item['id'];
1757 $html = $this->makeLink( $key, $link, $options );
1761 foreach ( array( 'id', 'class' ) as $attr ) {
1762 if ( isset( $item[$attr] ) ) {
1763 $attrs[$attr] = $item[$attr];
1766 if ( isset( $item['active'] ) && $item['active'] ) {
1767 if ( !isset( $attrs['class'] ) ) {
1768 $attrs['class'] = '';
1770 $attrs['class'] .= ' active';
1771 $attrs['class'] = trim( $attrs['class'] );
1773 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1776 function makeSearchInput( $attrs = array() ) {
1780 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1782 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1783 return Html
::element( 'input', $realAttrs );
1786 function makeSearchButton( $mode, $attrs = array() ) {
1793 'value' => $this->translator
->translate(
1794 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1796 $realAttrs = array_merge(
1798 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1801 return Html
::element( 'input', $realAttrs );
1803 $buttonAttrs = array(
1807 $buttonAttrs = array_merge(
1809 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1812 unset( $buttonAttrs['src'] );
1813 unset( $buttonAttrs['alt'] );
1814 unset( $buttonAttrs['width'] );
1815 unset( $buttonAttrs['height'] );
1817 'src' => $attrs['src'],
1818 'alt' => isset( $attrs['alt'] )
1820 : $this->translator
->translate( 'searchbutton' ),
1821 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1822 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1824 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1826 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1831 * Returns an array of footerlinks trimmed down to only those footer links that
1833 * If you pass "flat" as an option then the returned array will be a flat array
1834 * of footer icons instead of a key/value array of footerlinks arrays broken
1835 * up into categories.
1836 * @return array|mixed
1838 function getFooterLinks( $option = null ) {
1839 $footerlinks = $this->data
['footerlinks'];
1841 // Reduce footer links down to only those which are being used
1842 $validFooterLinks = array();
1843 foreach( $footerlinks as $category => $links ) {
1844 $validFooterLinks[$category] = array();
1845 foreach( $links as $link ) {
1846 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1847 $validFooterLinks[$category][] = $link;
1850 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1851 unset( $validFooterLinks[$category] );
1855 if ( $option == 'flat' ) {
1856 // fold footerlinks into a single array using a bit of trickery
1857 $validFooterLinks = call_user_func_array(
1859 array_values( $validFooterLinks )
1863 return $validFooterLinks;
1867 * Returns an array of footer icons filtered down by options relevant to how
1868 * the skin wishes to display them.
1869 * If you pass "icononly" as the option all footer icons which do not have an
1870 * image icon set will be filtered out.
1871 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1872 * in the list of footer icons. This is mostly useful for skins which only
1873 * display the text from footericons instead of the images and don't want a
1874 * duplicate copyright statement because footerlinks already rendered one.
1877 function getFooterIcons( $option = null ) {
1878 // Generate additional footer icons
1879 $footericons = $this->data
['footericons'];
1881 if ( $option == 'icononly' ) {
1882 // Unset any icons which don't have an image
1883 foreach ( $footericons as &$footerIconsBlock ) {
1884 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1885 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1886 unset( $footerIconsBlock[$footerIconKey] );
1890 // Redo removal of any empty blocks
1891 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1892 if ( count( $footerIconsBlock ) <= 0 ) {
1893 unset( $footericons[$footerIconsKey] );
1896 } elseif ( $option == 'nocopyright' ) {
1897 unset( $footericons['copyright']['copyright'] );
1898 if ( count( $footericons['copyright'] ) <= 0 ) {
1899 unset( $footericons['copyright'] );
1903 return $footericons;
1907 * Output the basic end-page trail including bottomscripts, reporttime, and
1908 * debug stuff. This should be called right before outputting the closing
1909 * body and html tags.
1911 function printTrail() { ?
>
1912 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
1913 <?php
$this->html( 'reporttime' ) ?
>
1914 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() );