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
23 if ( !defined( 'MEDIAWIKI' ) ) {
28 * Wrapper object for MediaWiki's localization functions,
29 * to be passed to the template engine.
34 class MediaWiki_I18N
{
35 var $_context = array();
37 function set( $varName, $value ) {
38 $this->_context
[$varName] = $value;
41 function translate( $value ) {
42 wfProfileIn( __METHOD__
);
44 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
45 $value = preg_replace( '/^string:/', '', $value );
47 $value = wfMsg( $value );
48 // interpolate variables
50 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
51 list( $src, $var ) = $m;
53 $varValue = $this->_context
[$var];
55 $value = str_replace( $src, $varValue, $value );
57 wfProfileOut( __METHOD__
);
63 * Template-filler skin base class
64 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
65 * Based on Brion's smarty skin
66 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
68 * @todo Needs some serious refactoring into functions that correspond
69 * to the computations individual esi snippets need. Most importantly no body
70 * parsing for most of those of course.
74 class SkinTemplate
extends Skin
{
80 * Name of our skin, it probably needs to be all lower case. Child classes
81 * should override the default.
83 var $skinname = 'monobook';
86 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
87 * are located. Child classes should override the default.
89 var $stylename = 'monobook';
92 * For QuickTemplate, the name of the subclass which will actually fill the
93 * template. Child classes should override the default.
95 var $template = 'QuickTemplate';
98 * Whether this skin use OutputPage::headElement() to generate the <head>
101 var $useHeadElement = false;
106 * Add specific styles for this skin
108 * @param $out OutputPage
110 function setupSkinUserCss( OutputPage
$out ){
111 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
119 * @param $classname string (or file)
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
130 * initialize various variables and generate the template
132 * @param $out OutputPage
134 function outputPage( OutputPage
$out ) {
135 global $wgArticle, $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath, $wgLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgProfiler;
145 wfProfileIn( __METHOD__
);
146 if ( is_object( $wgProfiler ) ) {
147 $wgProfiler->setTemplated( true );
150 $oldid = $wgRequest->getVal( 'oldid' );
151 $diff = $wgRequest->getVal( 'diff' );
152 $action = $wgRequest->getVal( 'action', 'view' );
154 wfProfileIn( __METHOD__
. '-init' );
155 $this->initPage( $out );
158 $tpl = $this->setupTemplate( $this->template
, 'skins' );
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator( new MediaWiki_I18N() );
163 wfProfileOut( __METHOD__
. '-init' );
165 wfProfileIn( __METHOD__
. '-stuff' );
166 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
167 $this->thisurl
= $this->mTitle
->getPrefixedURL();
169 if ( !$wgRequest->wasPosted() ) {
170 $query = $wgRequest->getValues();
171 unset( $query['title'] );
172 unset( $query['returnto'] );
173 unset( $query['returntoquery'] );
175 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
176 $this->loggedin
= $wgUser->isLoggedIn();
177 $this->iscontent
= ( $this->mTitle
->getNamespace() != NS_SPECIAL
);
178 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
179 $this->username
= $wgUser->getName();
181 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
182 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
184 # This won't be used in the standard skins, but we define it to preserve the interface
185 # To save time, we check for existence
186 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
189 $this->titletxt
= $this->mTitle
->getPrefixedText();
190 wfProfileOut( __METHOD__
. '-stuff' );
192 wfProfileIn( __METHOD__
. '-stuff-head' );
193 if ( $this->useHeadElement
) {
194 $pagecss = $this->setupPageCss();
196 $out->addInlineStyle( $pagecss );
198 $this->setupUserCss( $out );
200 $tpl->set( 'pagecss', $this->setupPageCss() );
201 $tpl->setRef( 'usercss', $this->usercss
);
203 $this->userjs
= $this->userjsprev
= false;
204 $this->setupUserJs( $out->isUserJsAllowed() );
205 $tpl->setRef( 'userjs', $this->userjs
);
206 $tpl->setRef( 'userjsprev', $this->userjsprev
);
209 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
210 $tpl->set( 'jsvarurl',
212 "action=raw$jsCache&gen=js&useskin=" .
213 urlencode( $this->getSkinName() ) ) );
215 $tpl->set( 'jsvarurl', false );
218 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
219 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
220 $tpl->set( 'html5version', $wgHtml5Version );
221 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
222 $tpl->set( 'csslinks', $out->buildCssLinks() );
224 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
225 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
227 $tpl->set( 'trackbackhtml', null );
230 wfProfileOut( __METHOD__
. '-stuff-head' );
232 wfProfileIn( __METHOD__
. '-stuff2' );
233 $tpl->set( 'title', $out->getPageTitle() );
234 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
235 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
236 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
237 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
239 $nsname = MWNamespace
::exists( $this->mTitle
->getNamespace() ) ?
240 MWNamespace
::getCanonicalName( $this->mTitle
->getNamespace() ) :
241 $this->mTitle
->getNsText();
243 $tpl->set( 'nscanonical', $nsname );
244 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
245 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
246 $tpl->set( 'titletext', $this->mTitle
->getText() );
247 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
248 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
250 $tpl->set( 'isarticle', $out->isArticle() );
252 $tpl->setRef( 'thispage', $this->thispage
);
253 $subpagestr = $this->subPageSubtitle();
255 'subtitle', !empty( $subpagestr ) ?
256 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
259 $undelete = $this->getUndeleteLink();
261 'undelete', !empty( $undelete ) ?
262 '<span class="subpages">' . $undelete . '</span>' :
266 $tpl->set( 'catlinks', $this->getCategories() );
267 if( $out->isSyndicated() ) {
269 foreach( $out->getSyndicationLinks() as $format => $link ) {
270 $feeds[$format] = array(
271 'text' => wfMsg( "feed-$format" ),
275 $tpl->setRef( 'feeds', $feeds );
277 $tpl->set( 'feeds', false );
280 $tpl->setRef( 'mimetype', $wgMimeType );
281 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
282 $tpl->setRef( 'charset', $wgOutputEncoding );
283 $tpl->setRef( 'wgScript', $wgScript );
284 $tpl->setRef( 'skinname', $this->skinname
);
285 $tpl->set( 'skinclass', get_class( $this ) );
286 $tpl->setRef( 'stylename', $this->stylename
);
287 $tpl->set( 'printable', $out->isPrintable() );
288 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
289 $tpl->setRef( 'loggedin', $this->loggedin
);
290 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
291 /* XXX currently unused, might get useful later
292 $tpl->set( 'editable', ( $this->mTitle->getNamespace() != NS_SPECIAL ) );
293 $tpl->set( 'exists', $this->mTitle->getArticleID() != 0 );
294 $tpl->set( 'watch', $this->mTitle->userIsWatching() ? 'unwatch' : 'watch' );
295 $tpl->set( 'protect', count( $this->mTitle->isProtected() ) ? 'unprotect' : 'protect' );
296 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
298 $tpl->set( 'searchaction', $this->escapeSearchLink() );
299 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
300 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
301 $tpl->setRef( 'stylepath', $wgStylePath );
302 $tpl->setRef( 'articlepath', $wgArticlePath );
303 $tpl->setRef( 'scriptpath', $wgScriptPath );
304 $tpl->setRef( 'serverurl', $wgServer );
305 $tpl->setRef( 'logopath', $wgLogo );
308 $tpl->set( 'lang', $lang->getCode() );
309 $tpl->set( 'dir', $lang->getDir() );
310 $tpl->set( 'rtl', $lang->isRTL() );
312 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
313 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
314 $tpl->set( 'username', $wgUser->isAnon() ?
null : $this->username
);
315 $tpl->setRef( 'userpage', $this->userpage
);
316 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
317 $tpl->set( 'userlang', $wgLang->getCode() );
319 // Users can have their language set differently than the
320 // content of the wiki. For these users, tell the web browser
321 // that interface elements are in a different language.
322 $tpl->set( 'userlangattributes', '' );
323 $tpl->set( 'specialpageattributes', '' );
325 $lang = $wgLang->getCode();
326 $dir = $wgLang->getDir();
327 if ( $lang !== $wgContLang->getCode() ||
$dir !== $wgContLang->getDir() ) {
328 $attrs = " lang='$lang' dir='$dir'";
330 $tpl->set( 'userlangattributes', $attrs );
332 // The content of SpecialPages should be presented in the
333 // user's language. Content of regular pages should not be touched.
334 if( $this->mTitle
->isSpecialPage() ) {
335 $tpl->set( 'specialpageattributes', $attrs );
339 $newtalks = $this->getNewtalks();
341 wfProfileOut( __METHOD__
. '-stuff2' );
343 wfProfileIn( __METHOD__
. '-stuff3' );
344 $tpl->setRef( 'newtalk', $newtalks );
345 $tpl->setRef( 'skin', $this );
346 $tpl->set( 'logo', $this->logoText() );
347 if ( $out->isArticle() && ( !isset( $oldid ) ||
isset( $diff ) ) &&
348 $wgArticle && 0 != $wgArticle->getID() ){
349 if ( !$wgDisableCounters ) {
350 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
352 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
354 $tpl->set( 'viewcount', false );
357 $tpl->set( 'viewcount', false );
360 if( $wgPageShowWatchingUsers ) {
361 $dbr = wfGetDB( DB_SLAVE
);
362 $res = $dbr->select( 'watchlist',
363 array( 'COUNT(*) AS n' ),
364 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
367 $x = $dbr->fetchObject( $res );
368 $numberofwatchingusers = $x->n
;
369 if( $numberofwatchingusers > 0 ) {
370 $tpl->set( 'numberofwatchingusers',
371 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
372 $wgLang->formatNum( $numberofwatchingusers ) )
375 $tpl->set( 'numberofwatchingusers', false );
378 $tpl->set( 'numberofwatchingusers', false );
381 $tpl->set( 'copyright', $this->getCopyright() );
383 $this->credits
= false;
385 if( $wgMaxCredits != 0 ){
386 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
388 $tpl->set( 'lastmod', $this->lastModified() );
391 $tpl->setRef( 'credits', $this->credits
);
393 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
394 $tpl->set( 'copyright', $this->getCopyright() );
395 $tpl->set( 'viewcount', false );
396 $tpl->set( 'lastmod', false );
397 $tpl->set( 'credits', false );
398 $tpl->set( 'numberofwatchingusers', false );
400 $tpl->set( 'copyright', false );
401 $tpl->set( 'viewcount', false );
402 $tpl->set( 'lastmod', false );
403 $tpl->set( 'credits', false );
404 $tpl->set( 'numberofwatchingusers', false );
406 wfProfileOut( __METHOD__
. '-stuff3' );
408 wfProfileIn( __METHOD__
. '-stuff4' );
409 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
410 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
411 $tpl->set( 'disclaimer', $this->disclaimerLink() );
412 $tpl->set( 'privacy', $this->privacyLink() );
413 $tpl->set( 'about', $this->aboutLink() );
415 $tpl->set( 'footerlinks', array(
419 'numberofwatchingusers',
430 global $wgFooterIcons;
431 $tpl->set( 'footericons', $wgFooterIcons );
432 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
433 if ( count( $footerIconsBlock ) > 0 ) {
434 foreach ( $footerIconsBlock as &$footerIcon ) {
435 if ( isset( $footerIcon['src'] ) ) {
436 if ( !isset( $footerIcon['width'] ) ) {
437 $footerIcon['width'] = 88;
439 if ( !isset( $footerIcon['height'] ) ) {
440 $footerIcon['height'] = 31;
445 unset( $tpl->data
['footericons'][$footerIconsKey] );
449 if ( $wgDebugComments ) {
450 $tpl->setRef( 'debug', $out->mDebugtext
);
452 $tpl->set( 'debug', '' );
455 $tpl->set( 'reporttime', wfReportTime() );
456 $tpl->set( 'sitenotice', wfGetSiteNotice() );
457 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
459 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
460 global $wgBetterDirectionality;
461 if ( $wgBetterDirectionality ) {
462 $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
463 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
465 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
466 $tpl->setRef( 'bodytext', $out->mBodytext
);
469 $language_urls = array();
471 if ( !$wgHideInterlanguageLinks ) {
472 foreach( $out->getLanguageLinks() as $l ) {
473 $tmp = explode( ':', $l, 2 );
474 $class = 'interwiki-' . $tmp[0];
476 $nt = Title
::newFromText( $l );
478 $language_urls[] = array(
479 'href' => $nt->getFullURL(),
480 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
481 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
482 'title' => $nt->getText(),
488 if( count( $language_urls ) ) {
489 $tpl->setRef( 'language_urls', $language_urls );
491 $tpl->set( 'language_urls', false );
493 wfProfileOut( __METHOD__
. '-stuff4' );
495 wfProfileIn( __METHOD__
. '-stuff5' );
497 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
498 $content_actions = $this->buildContentActionUrls();
499 $tpl->setRef( 'content_actions', $content_actions );
501 $tpl->set( 'sidebar', $this->buildSidebar() );
502 $tpl->set( 'nav_urls', $this->buildNavUrls() );
504 // Set the head scripts near the end, in case the above actions resulted in added scripts
505 if ( $this->useHeadElement
) {
506 $tpl->set( 'headelement', $out->headElement( $this ) );
508 $tpl->set( 'headscripts', $out->getScript() );
511 // original version by hansm
512 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
513 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
516 // allow extensions adding stuff after the page content.
517 // See Skin::afterContentHook() for further documentation.
518 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
519 wfProfileOut( __METHOD__
. '-stuff5' );
522 wfProfileIn( __METHOD__
. '-execute' );
523 $res = $tpl->execute();
524 wfProfileOut( __METHOD__
. '-execute' );
526 // result may be an error
527 $this->printOrError( $res );
528 wfProfileOut( __METHOD__
);
532 * Output the string, or print error message if it's
533 * an error object of the appropriate type.
534 * For the base class, assume strings all around.
539 function printOrError( $str ) {
544 * Output a boolean indiciating if buildPersonalUrls should output separate
545 * login and create account links or output a combined link
546 * By default we simply return a global config setting that affects most skins
547 * This is setup as a method so that like with $wgLogo and getLogo() a skin
548 * can override this setting and always output one or the other if it has
549 * a reason it can't output one of the two modes.
551 function useCombinedLoginLink() {
552 global $wgUseCombinedLoginLink;
553 return $wgUseCombinedLoginLink;
557 * build array of urls for personal toolbar
561 function buildPersonalUrls() {
562 global $wgOut, $wgRequest;
564 $title = $wgOut->getTitle();
565 $pageurl = $title->getLocalURL();
566 wfProfileIn( __METHOD__
);
568 /* set up the default links for the personal toolbar */
569 $personal_urls = array();
570 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
571 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
572 $returnto = "returnto=$page";
573 if( $this->thisquery
!= '' ) {
574 $returnto .= "&returntoquery=$query";
576 if( $this->loggedin
) {
577 $personal_urls['userpage'] = array(
578 'text' => $this->username
,
579 'href' => &$this->userpageUrlDetails
['href'],
580 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
581 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
583 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
584 $personal_urls['mytalk'] = array(
585 'text' => wfMsg( 'mytalk' ),
586 'href' => &$usertalkUrlDetails['href'],
587 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
588 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
590 $href = self
::makeSpecialUrl( 'Preferences' );
591 $personal_urls['preferences'] = array(
592 'text' => wfMsg( 'mypreferences' ),
594 'active' => ( $href == $pageurl )
596 $href = self
::makeSpecialUrl( 'Watchlist' );
597 $personal_urls['watchlist'] = array(
598 'text' => wfMsg( 'mywatchlist' ),
600 'active' => ( $href == $pageurl )
603 # We need to do an explicit check for Special:Contributions, as we
604 # have to match both the title, and the target (which could come
605 # from request values or be specified in "sub page" form. The plot
606 # thickens, because $wgTitle is altered for special pages, so doesn't
607 # contain the original alias-with-subpage.
608 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
609 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
610 list( $spName, $spPar ) =
611 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
612 $active = $spName == 'Contributions'
613 && ( ( $spPar && $spPar == $this->username
)
614 ||
$wgRequest->getText( 'target' ) == $this->username
);
619 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
620 $personal_urls['mycontris'] = array(
621 'text' => wfMsg( 'mycontris' ),
625 $personal_urls['logout'] = array(
626 'text' => wfMsg( 'userlogout' ),
627 'href' => self
::makeSpecialUrl( 'Userlogout',
628 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
634 $useCombinedLoginLink = $this->useCombinedLoginLink();
635 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
636 ?
'nav-login-createaccount'
638 $is_signup = $wgRequest->getText('type') == "signup";
640 # anonlogin & login are the same
642 'text' => wfMsg( $loginlink ),
643 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
644 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" ||
!$is_signup )
646 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
647 $createaccount_url = array(
648 'text' => wfMsg( 'createaccount' ),
649 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
650 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
653 global $wgProto, $wgSecureLogin;
654 if( $wgProto === 'http' && $wgSecureLogin ) {
655 $title = SpecialPage
::getTitleFor( 'Userlogin' );
656 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
657 $login_url['href'] = $https_url;
658 $login_url['class'] = 'link-https'; # FIXME class depends on skin
659 if ( isset($createaccount_url) ) {
660 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL("type=signup") );
661 $createaccount_url['href'] = $https_url;
662 $createaccount_url['class'] = 'link-https'; # FIXME class depends on skin
667 if( $this->showIPinHeader() ) {
668 $href = &$this->userpageUrlDetails
['href'];
669 $personal_urls['anonuserpage'] = array(
670 'text' => $this->username
,
672 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
673 'active' => ( $pageurl == $href )
675 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
676 $href = &$usertalkUrlDetails['href'];
677 $personal_urls['anontalk'] = array(
678 'text' => wfMsg( 'anontalk' ),
680 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
681 'active' => ( $pageurl == $href )
683 $personal_urls['anonlogin'] = $login_url;
684 if ( isset($createaccount_url) ) {
685 $personal_urls['createaccount'] = $createaccount_url;
688 $personal_urls['login'] = $login_url;
692 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
693 wfProfileOut( __METHOD__
);
694 return $personal_urls;
697 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
700 $classes[] = 'selected';
702 if( $checkEdit && !$title->isKnown() ) {
704 $query = 'action=edit&redlink=1';
707 $text = wfMsg( $message );
708 if ( wfEmptyMsg( $message, $text ) ) {
710 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
714 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
715 $title, $message, $selected, $checkEdit,
716 &$classes, &$query, &$text, &$result ) ) ) {
721 'class' => implode( ' ', $classes ),
723 'href' => $title->getLocalUrl( $query ) );
726 function makeTalkUrlDetails( $name, $urlaction = '' ) {
727 $title = Title
::newFromText( $name );
728 if( !is_object( $title ) ) {
729 throw new MWException( __METHOD__
. " given invalid pagename $name" );
731 $title = $title->getTalkPage();
732 self
::checkTitle( $title, $name );
734 'href' => $title->getLocalURL( $urlaction ),
735 'exists' => $title->getArticleID() != 0,
739 function makeArticleUrlDetails( $name, $urlaction = '' ) {
740 $title = Title
::newFromText( $name );
741 $title= $title->getSubjectPage();
742 self
::checkTitle( $title, $name );
744 'href' => $title->getLocalURL( $urlaction ),
745 'exists' => $title->getArticleID() != 0,
750 * an array of edit links by default used for the tabs
754 function buildContentActionUrls() {
755 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
757 wfProfileIn( __METHOD__
);
759 $action = $wgRequest->getVal( 'action', 'view' );
760 $section = $wgRequest->getVal( 'section' );
761 $content_actions = array();
762 $userCanRead = $this->mTitle
->userCanRead();
764 $prevent_active_tabs = false;
765 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
767 if( $this->iscontent
) {
768 $subjpage = $this->mTitle
->getSubjectPage();
769 $talkpage = $this->mTitle
->getTalkPage();
771 $nskey = $this->mTitle
->getNamespaceKey();
772 $content_actions[$nskey] = $this->tabAction(
775 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
779 $content_actions['talk'] = $this->tabAction(
782 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
787 wfProfileIn( __METHOD__
. '-edit' );
788 if ( $userCanRead && $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
789 $istalk = $this->mTitle
->isTalkPage();
790 $istalkclass = $istalk?
' istalk':'';
791 $content_actions['edit'] = array(
792 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
793 'text' => ( $this->mTitle
->exists() ||
( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
&& !wfEmptyMsg( $this->mTitle
->getText() ) ) )
796 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
799 // adds new section link if page is a current revision of a talk page or
800 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
801 if ( !$wgOut->forceHideNewSectionLink() ) {
802 $content_actions['addsection'] = array(
803 'class' => $section == 'new' ?
'selected' : false,
804 'text' => wfMsg( 'addsection' ),
805 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
809 } elseif ( $this->mTitle
->hasSourceText() && $userCanRead ) {
810 $content_actions['viewsource'] = array(
811 'class' => ($action == 'edit') ?
'selected' : false,
812 'text' => wfMsg( 'viewsource' ),
813 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
816 wfProfileOut( __METHOD__
. '-edit' );
818 wfProfileIn( __METHOD__
. '-live' );
819 if ( $this->mTitle
->exists() && $userCanRead ) {
821 $content_actions['history'] = array(
822 'class' => ($action == 'history') ?
'selected' : false,
823 'text' => wfMsg( 'history_short' ),
824 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
828 if( $wgUser->isAllowed( 'delete' ) ) {
829 $content_actions['delete'] = array(
830 'class' => ($action == 'delete') ?
'selected' : false,
831 'text' => wfMsg( 'delete' ),
832 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
835 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
836 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
837 $content_actions['move'] = array(
838 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
839 'text' => wfMsg( 'move' ),
840 'href' => $moveTitle->getLocalUrl()
844 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
845 if( !$this->mTitle
->isProtected() ){
846 $content_actions['protect'] = array(
847 'class' => ($action == 'protect') ?
'selected' : false,
848 'text' => wfMsg( 'protect' ),
849 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
853 $content_actions['unprotect'] = array(
854 'class' => ($action == 'unprotect') ?
'selected' : false,
855 'text' => wfMsg( 'unprotect' ),
856 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
861 //article doesn't exist or is deleted
862 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
863 $n = $this->mTitle
->isDeleted();
865 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
866 $content_actions['undelete'] = array(
868 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
869 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
870 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
875 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
876 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
877 $content_actions['protect'] = array(
878 'class' => ($action == 'protect') ?
'selected' : false,
879 'text' => wfMsg( 'protect' ),
880 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
884 $content_actions['unprotect'] = array(
885 'class' => ($action == 'unprotect') ?
'selected' : false,
886 'text' => wfMsg( 'unprotect' ),
887 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
893 wfProfileOut( __METHOD__
. '-live' );
895 if( $this->loggedin
) {
896 if( !$this->mTitle
->userIsWatching()) {
897 $content_actions['watch'] = array(
898 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
899 'text' => wfMsg( 'watch' ),
900 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
903 $content_actions['unwatch'] = array(
904 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
905 'text' => wfMsg( 'unwatch' ),
906 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
912 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
914 /* show special page tab */
916 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
917 'class' => 'selected',
918 'text' => wfMsg('nstab-special'),
919 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
922 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
925 /* show links to different language variants */
926 global $wgDisableLangConversion;
927 $variants = $wgContLang->getVariants();
928 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
929 $preferred = $wgContLang->getPreferredVariant();
931 foreach( $variants as $code ) {
932 $varname = $wgContLang->getVariantname( $code );
933 if( $varname == 'disable' )
935 $selected = ( $code == $preferred )?
'selected' : false;
936 $content_actions['varlang-' . $vcount] = array(
937 'class' => $selected,
939 'href' => $this->mTitle
->getLocalURL( '', $code )
945 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
947 wfProfileOut( __METHOD__
);
948 return $content_actions;
952 * build array of common navigation links
956 function buildNavUrls() {
957 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
958 global $wgUploadNavigationUrl;
960 wfProfileIn( __METHOD__
);
962 $action = $wgRequest->getVal( 'action', 'view' );
965 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
966 if( $wgUploadNavigationUrl ) {
967 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
968 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $wgUser ) === true ) {
969 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
971 $nav_urls['upload'] = false;
973 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
975 // default permalink to being off, will override it as required below.
976 $nav_urls['permalink'] = false;
978 // A print stylesheet is attached to all pages, but nobody ever
979 // figures that out. :) Add a link...
980 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
981 if ( !$wgOut->isPrintable() ) {
982 $nav_urls['print'] = array(
983 'text' => wfMsg( 'printableversion' ),
984 'href' => $wgRequest->appendQuery( 'printable=yes' )
988 // Also add a "permalink" while we're at it
989 if ( $this->mRevisionId
) {
990 $nav_urls['permalink'] = array(
991 'text' => wfMsg( 'permalink' ),
992 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
996 // Copy in case this undocumented, shady hook tries to mess with internals
997 $revid = $this->mRevisionId
;
998 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
1001 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
1002 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
1003 $nav_urls['whatlinkshere'] = array(
1004 'href' => $wlhTitle->getLocalUrl()
1006 if( $this->mTitle
->getArticleId() ) {
1007 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
1008 $nav_urls['recentchangeslinked'] = array(
1009 'href' => $rclTitle->getLocalUrl()
1012 $nav_urls['recentchangeslinked'] = false;
1014 if( $wgUseTrackbacks )
1015 $nav_urls['trackbacklink'] = array(
1016 'href' => $wgOut->getTitle()->trackbackURL()
1020 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1021 $rootUser = strtok( $this->mTitle
->getText(), '/' );
1022 $id = User
::idFromName( $rootUser );
1023 $ip = User
::isIP( $rootUser );
1029 if( $id ||
$ip ) { # both anons and non-anons have contribs list
1030 $nav_urls['contributions'] = array(
1031 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1035 $logPage = SpecialPage
::getTitleFor( 'Log' );
1036 $nav_urls['log'] = array(
1037 'href' => $logPage->getLocalUrl(
1044 $nav_urls['log'] = false;
1047 if ( $wgUser->isAllowed( 'block' ) ) {
1048 $nav_urls['blockip'] = array(
1049 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $rootUser )
1052 $nav_urls['blockip'] = false;
1055 $nav_urls['contributions'] = false;
1056 $nav_urls['log'] = false;
1057 $nav_urls['blockip'] = false;
1059 $nav_urls['emailuser'] = false;
1060 if( $this->showEmailUser( $id ) ) {
1061 $nav_urls['emailuser'] = array(
1062 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1065 wfProfileOut( __METHOD__
);
1070 * Generate strings used for xml 'id' names
1074 function getNameSpaceKey() {
1075 return $this->mTitle
->getNamespaceKey();
1081 function setupUserJs( $allowUserJs ) {
1082 global $wgRequest, $wgJsMimeType;
1083 wfProfileIn( __METHOD__
);
1085 $action = $wgRequest->getVal( 'action', 'view' );
1087 if( $allowUserJs && $this->loggedin
) {
1088 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1089 # XXX: additional security check/prompt?
1090 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1092 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1095 wfProfileOut( __METHOD__
);
1099 * Code for extensions to hook into to provide per-page CSS, see
1100 * extensions/PageCSS/PageCSS.php for an implementation of this.
1104 function setupPageCss() {
1105 wfProfileIn( __METHOD__
);
1107 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1108 wfProfileOut( __METHOD__
);
1112 public function commonPrintStylesheet() {
1118 * Generic wrapper for template functions, with interface
1119 * compatible with what we use of PHPTAL 0.7.
1122 abstract class QuickTemplate
{
1126 public function QuickTemplate() {
1127 $this->data
= array();
1128 $this->translator
= new MediaWiki_I18N();
1132 * Sets the value $value to $name
1136 public function set( $name, $value ) {
1137 $this->data
[$name] = $value;
1144 public function setRef( $name, &$value ) {
1145 $this->data
[$name] =& $value;
1151 public function setTranslator( &$t ) {
1152 $this->translator
= &$t;
1156 * Main function, used by classes that subclass QuickTemplate
1157 * to show the actual HTML output
1159 abstract public function execute();
1164 function text( $str ) {
1165 echo htmlspecialchars( $this->data
[$str] );
1171 function jstext( $str ) {
1172 echo Xml
::escapeJsString( $this->data
[$str] );
1178 function html( $str ) {
1179 echo $this->data
[$str];
1185 function msg( $str ) {
1186 echo htmlspecialchars( $this->translator
->translate( $str ) );
1192 function msgHtml( $str ) {
1193 echo $this->translator
->translate( $str );
1197 * An ugly, ugly hack.
1200 function msgWiki( $str ) {
1201 global $wgParser, $wgOut;
1203 $text = $this->translator
->translate( $str );
1204 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1205 $wgOut->parserOptions(), true );
1206 echo $parserOutput->getText();
1212 function haveData( $str ) {
1213 return isset( $this->data
[$str] );
1219 function haveMsg( $str ) {
1220 $msg = $this->translator
->translate( $str );
1221 return ( $msg != '-' ) && ( $msg != '' ); # ????
1226 * New base template for a skin's template extended from QuickTemplate
1227 * this class features helper methods that provide common ways of interacting
1228 * with the data stored in the QuickTemplate
1230 abstract class BaseTemplate
extends QuickTemplate
{
1233 * Create an array of common toolbox items from the data in the quicktemplate
1234 * stored by SkinTemplate.
1235 * The resulting array is built acording to a format intended to be passed
1236 * through makeListItem to generate the html.
1238 function getToolbox() {
1239 wfProfileIn( __METHOD__
);
1242 if ( $this->data
['notspecialpage'] ) {
1243 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1244 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1245 if ( $this->data
['nav_urls']['recentchangeslinked'] ) {
1246 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1247 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1248 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1251 if( isset( $this->data
['nav_urls']['trackbacklink'] ) && $this->data
['nav_urls']['trackbacklink'] ) {
1252 $toolbox['trackbacklink'] = $this->data
['nav_urls']['trackbacklink'];
1253 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1255 if ( $this->data
['feeds'] ) {
1256 $toolbox['feeds']['id'] = 'feedlinks';
1257 $toolbox['feeds']['links'] = array();
1258 foreach ( $this->data
['feeds'] as $key => $feed ) {
1259 $toolbox['feeds']['links'][$key] = $feed;
1260 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1261 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1262 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1263 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1266 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1267 if ( $this->data
['nav_urls'][$special] ) {
1268 $toolbox[$special] = $this->data
['nav_urls'][$special];
1269 $toolbox[$special]['id'] = "t-$special";
1272 if ( !empty( $this->data
['nav_urls']['print']['href'] ) ) {
1273 $toolbox['print'] = $this->data
['nav_urls']['print'];
1274 $toolbox['print']['rel'] = 'alternate';
1275 $toolbox['print']['msg'] = 'printableversion';
1277 if ( !empty( $this->data
['nav_urls']['permalink']['href'] ) ) {
1278 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1279 $toolbox['permalink']['id'] = 't-permalink';
1280 } elseif ( $this->data
['nav_urls']['permalink']['href'] === '' ) {
1281 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1282 unset( $toolbox['permalink']['href'] );
1283 $toolbox['ispermalink']['tooltiponly'] = true;
1284 $toolbox['ispermalink']['id'] = 't-ispermalink';
1285 $toolbox['ispermalink']['msg'] = 'permalink';
1287 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1288 wfProfileOut( __METHOD__
);
1293 * Create an array of personal tools items from the data in the quicktemplate
1294 * stored by SkinTemplate.
1295 * The resulting array is built acording to a format intended to be passed
1296 * through makeListItem to generate the html.
1297 * This is in reality the same list as already stored in personal_urls
1298 * however it is reformatted so that you can just pass the individual items
1299 * to makeListItem instead of hardcoding the element creation boilerplate.
1301 function getPersonalTools() {
1302 $personal_tools = array();
1303 foreach( $this->data
['personal_urls'] as $key => $ptool ) {
1304 # The class on a personal_urls item is meant to go on the <a> instead
1305 # of the <li> so we have to use a single item "links" array instead
1306 # of using most of the personal_url's keys directly
1307 $personal_tools[$key] = array();
1308 $personal_tools[$key]["links"][] = array();
1309 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1310 if ( isset($ptool["active"]) ) {
1311 $personal_tools[$key]["active"] = $ptool["active"];
1313 foreach ( array("href", "class", "text") as $k ) {
1314 if ( isset($ptool[$k]) )
1315 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1318 return $personal_tools;
1322 * Makes a link, usually used by makeListItem to generate a link for an item
1323 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1325 * $key is a string, usually a key from the list you are generating this link from
1326 * $item is an array containing some of a specific set of keys.
1327 * The text of the link will be generated either from the contents of the "text"
1328 * key in the $item array, if a "msg" key is present a message by that name will
1329 * be used, and if neither of those are set the $key will be used as a message name.
1330 * If a "href" key is not present makeLink will just output htmlescaped text.
1331 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1332 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1333 * is present it will be used to generate a tooltip and accesskey for the link.
1334 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1336 function makeLink( $key, $item ) {
1337 if ( isset( $item['text'] ) ) {
1338 $text = $item['text'];
1340 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1343 if ( !isset( $item['href'] ) ) {
1344 return htmlspecialchars( $text );
1348 foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
1349 if ( isset( $item[$attr] ) ) {
1350 $attrs[$attr] = $item[$attr];
1354 if ( isset( $item['id'] ) ) {
1355 $item['single-id'] = $item['id'];
1357 if ( isset( $item['single-id'] ) ) {
1358 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1359 $attrs['title'] = $this->skin
->titleAttrib( $item['single-id'] );
1360 if ( $attrs['title'] === false ) {
1361 unset( $attrs['title'] );
1364 $attrs = array_merge(
1366 $this->skin
->tooltipAndAccesskeyAttribs( $item['single-id'] )
1371 return Html
::element( 'a', $attrs, $text );
1375 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1376 * $key is a string, usually a key from the list you are generating this link from
1377 * $item is an array of list item data containing some of a specific set of keys.
1378 * The "id" and "class" keys will be used as attributes for the list item,
1379 * if "active" contains a value of true a "active" class will also be appended to class.
1380 * If you want something other than a <li> you can pass a tag name such as
1381 * "tag" => "span" in the $options array to change the tag used.
1382 * link/content data for the list item may come in one of two forms
1383 * A "links" key may be used, in which case it should contain an array with
1384 * a list of links to include inside the list item, see makeLink for the format
1385 * of individual links array items.
1386 * Otherwise the relevant keys from the list item $item array will be passed
1387 * to makeLink instead. Note however that "id" and "class" are used by the
1388 * list item directly so they will not be passed to makeLink
1389 * (however the link will still support a tooltip and accesskey from it)
1390 * If you need an id or class on a single link you should include a "links"
1391 * array with just one link item inside of it.
1393 function makeListItem( $key, $item, $options = array() ) {
1394 if ( isset( $item['links'] ) ) {
1396 foreach ( $item['links'] as $linkKey => $link ) {
1397 $html .= $this->makeLink( $linkKey, $link );
1401 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
1402 if ( isset( $item[$k] ) ) {
1403 $link[$k] = $item[$k];
1406 if ( isset( $item['id'] ) ) {
1407 // The id goes on the <li> not on the <a> for single links
1408 // but makeSidebarLink still needs to know what id to use when
1409 // generating tooltips and accesskeys.
1410 $link['single-id'] = $item['id'];
1412 $html = $this->makeLink( $key, $link );
1416 foreach ( array( 'id', 'class' ) as $attr ) {
1417 if ( isset( $item[$attr] ) ) {
1418 $attrs[$attr] = $item[$attr];
1421 if ( isset( $item['active'] ) && $item['active'] ) {
1422 if ( !isset( $attrs['class'] ) ) {
1423 $attrs['class'] = '';
1425 $attrs['class'] .= ' active';
1426 $attrs['class'] = trim( $attrs['class'] );
1428 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1431 function makeSearchInput( $attrs = array() ) {
1435 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1437 $realAttrs = array_merge( $realAttrs, $this->skin
->tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1438 return Html
::element( 'input', $realAttrs );
1441 function makeSearchButton( $mode, $attrs = array() ) {
1448 'value' => $this->translator
->translate( $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1450 $realAttrs = array_merge(
1452 $this->skin
->tooltipAndAccesskeyAttribs( "search-$mode" ),
1455 return Html
::element( 'input', $realAttrs );
1457 $buttonAttrs = array(
1461 $buttonAttrs = array_merge(
1463 $this->skin
->tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1466 unset( $buttonAttrs['src'] );
1467 unset( $buttonAttrs['alt'] );
1469 'src' => $attrs['src'],
1470 'alt' => isset( $attrs['alt'] ) ?
$attrs['alt'] : $this->translator
->translate( 'searchbutton' ),
1472 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1474 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1479 * Returns an array of footerlinks trimmed down to only those footer links that
1481 * If you pass "flat" as an option then the returned array will be a flat array
1482 * of footer icons instead of a key/value array of footerlinks arrays broken
1483 * up into categories.
1485 function getFooterLinks( $option = null ) {
1486 $footerlinks = $this->data
['footerlinks'];
1488 // Reduce footer links down to only those which are being used
1489 $validFooterLinks = array();
1490 foreach( $footerlinks as $category => $links ) {
1491 $validFooterLinks[$category] = array();
1492 foreach( $links as $link ) {
1493 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1494 $validFooterLinks[$category][] = $link;
1497 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1498 unset( $validFooterLinks[$category] );
1502 if ( $option == 'flat' ) {
1503 // fold footerlinks into a single array using a bit of trickery
1504 $validFooterLinks = call_user_func_array(
1506 array_values( $validFooterLinks )
1510 return $validFooterLinks;
1514 * Returns an array of footer icons filtered down by options relevant to how
1515 * the skin wishes to display them.
1516 * If you pass "icononly" as the option all footer icons which do not have an
1517 * image icon set will be filtered out.
1518 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1519 * in the list of footer icons. This is mostly useful for skins which only
1520 * display the text from footericons instead of the images and don't want a
1521 * duplicate copyright statement because footerlinks already rendered one.
1523 function getFooterIcons( $option = null ) {
1524 // Generate additional footer icons
1525 $footericons = $this->data
['footericons'];
1527 if ( $option == 'icononly' ) {
1528 // Unset any icons which don't have an image
1529 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1530 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1531 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1532 unset( $footerIconsBlock[$footerIconKey] );
1536 // Redo removal of any empty blocks
1537 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1538 if ( count( $footerIconsBlock ) <= 0 ) {
1539 unset( $footericons[$footerIconsKey] );
1542 } elseif ( $option == 'nocopyright' ) {
1543 $footericons = $this->data
['footericons'];
1544 unset( $footericons['copyright']['copyright'] );
1545 if ( count( $footericons['copyright'] ) <= 0 ) {
1546 unset( $footericons['copyright'] );
1550 return $footericons;