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() and ( !isset( $oldid ) or isset( $diff ) ) and
348 $wgArticle and 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 * build array of urls for personal toolbar
548 function buildPersonalUrls() {
549 global $wgOut, $wgRequest;
551 $title = $wgOut->getTitle();
552 $pageurl = $title->getLocalURL();
553 wfProfileIn( __METHOD__
);
555 /* set up the default links for the personal toolbar */
556 $personal_urls = array();
557 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
558 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
559 $returnto = "returnto=$page";
560 if( $this->thisquery
!= '' ) {
561 $returnto .= "&returntoquery=$query";
563 if( $this->loggedin
) {
564 $personal_urls['userpage'] = array(
565 'text' => $this->username
,
566 'href' => &$this->userpageUrlDetails
['href'],
567 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
568 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
570 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
571 $personal_urls['mytalk'] = array(
572 'text' => wfMsg( 'mytalk' ),
573 'href' => &$usertalkUrlDetails['href'],
574 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
575 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
577 $href = self
::makeSpecialUrl( 'Preferences' );
578 $personal_urls['preferences'] = array(
579 'text' => wfMsg( 'mypreferences' ),
581 'active' => ( $href == $pageurl )
583 $href = self
::makeSpecialUrl( 'Watchlist' );
584 $personal_urls['watchlist'] = array(
585 'text' => wfMsg( 'mywatchlist' ),
587 'active' => ( $href == $pageurl )
590 # We need to do an explicit check for Special:Contributions, as we
591 # have to match both the title, and the target (which could come
592 # from request values or be specified in "sub page" form. The plot
593 # thickens, because $wgTitle is altered for special pages, so doesn't
594 # contain the original alias-with-subpage.
595 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
596 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
597 list( $spName, $spPar ) =
598 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
599 $active = $spName == 'Contributions'
600 && ( ( $spPar && $spPar == $this->username
)
601 ||
$wgRequest->getText( 'target' ) == $this->username
);
606 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
607 $personal_urls['mycontris'] = array(
608 'text' => wfMsg( 'mycontris' ),
612 $personal_urls['logout'] = array(
613 'text' => wfMsg( 'userlogout' ),
614 'href' => self
::makeSpecialUrl( 'Userlogout',
615 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
621 $loginlink = $wgUser->isAllowed( 'createaccount' )
622 ?
'nav-login-createaccount'
625 # anonlogin & login are the same
627 'text' => wfMsg( $loginlink ),
628 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
629 'active' => $title->isSpecial( 'Userlogin' )
631 global $wgProto, $wgSecureLogin;
632 if( $wgProto === 'http' && $wgSecureLogin ) {
633 $title = SpecialPage
::getTitleFor( 'Userlogin' );
634 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
635 $login_url['href'] = $https_url;
636 $login_url['class'] = 'link-https'; # FIXME class depends on skin
639 if( $this->showIPinHeader() ) {
640 $href = &$this->userpageUrlDetails
['href'];
641 $personal_urls['anonuserpage'] = array(
642 'text' => $this->username
,
644 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
645 'active' => ( $pageurl == $href )
647 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
648 $href = &$usertalkUrlDetails['href'];
649 $personal_urls['anontalk'] = array(
650 'text' => wfMsg( 'anontalk' ),
652 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
653 'active' => ( $pageurl == $href )
655 $personal_urls['anonlogin'] = $login_url;
657 $personal_urls['login'] = $login_url;
661 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
662 wfProfileOut( __METHOD__
);
663 return $personal_urls;
666 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
669 $classes[] = 'selected';
671 if( $checkEdit && !$title->isKnown() ) {
673 $query = 'action=edit&redlink=1';
676 $text = wfMsg( $message );
677 if ( wfEmptyMsg( $message, $text ) ) {
679 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
683 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
684 $title, $message, $selected, $checkEdit,
685 &$classes, &$query, &$text, &$result ) ) ) {
690 'class' => implode( ' ', $classes ),
692 'href' => $title->getLocalUrl( $query ) );
695 function makeTalkUrlDetails( $name, $urlaction = '' ) {
696 $title = Title
::newFromText( $name );
697 if( !is_object( $title ) ) {
698 throw new MWException( __METHOD__
. " given invalid pagename $name" );
700 $title = $title->getTalkPage();
701 self
::checkTitle( $title, $name );
703 'href' => $title->getLocalURL( $urlaction ),
704 'exists' => $title->getArticleID() != 0,
708 function makeArticleUrlDetails( $name, $urlaction = '' ) {
709 $title = Title
::newFromText( $name );
710 $title= $title->getSubjectPage();
711 self
::checkTitle( $title, $name );
713 'href' => $title->getLocalURL( $urlaction ),
714 'exists' => $title->getArticleID() != 0,
719 * an array of edit links by default used for the tabs
723 function buildContentActionUrls() {
724 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
726 wfProfileIn( __METHOD__
);
728 $action = $wgRequest->getVal( 'action', 'view' );
729 $section = $wgRequest->getVal( 'section' );
730 $content_actions = array();
732 $prevent_active_tabs = false;
733 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
735 if( $this->iscontent
) {
736 $subjpage = $this->mTitle
->getSubjectPage();
737 $talkpage = $this->mTitle
->getTalkPage();
739 $nskey = $this->mTitle
->getNamespaceKey();
740 $content_actions[$nskey] = $this->tabAction(
743 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
747 $content_actions['talk'] = $this->tabAction(
750 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
755 wfProfileIn( __METHOD__
. '-edit' );
756 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
757 $istalk = $this->mTitle
->isTalkPage();
758 $istalkclass = $istalk?
' istalk':'';
759 $content_actions['edit'] = array(
760 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
761 'text' => ( $this->mTitle
->exists() ||
( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
&& !wfEmptyMsg( $this->mTitle
->getText() ) ) )
764 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
767 // adds new section link if page is a current revision of a talk page or
768 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
769 if ( !$wgOut->forceHideNewSectionLink() ) {
770 $content_actions['addsection'] = array(
771 'class' => $section == 'new' ?
'selected' : false,
772 'text' => wfMsg( 'addsection' ),
773 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
777 } elseif ( $this->mTitle
->hasSourceText() ) {
778 $content_actions['viewsource'] = array(
779 'class' => ($action == 'edit') ?
'selected' : false,
780 'text' => wfMsg( 'viewsource' ),
781 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
784 wfProfileOut( __METHOD__
. '-edit' );
786 wfProfileIn( __METHOD__
. '-live' );
787 if ( $this->mTitle
->exists() ) {
789 $content_actions['history'] = array(
790 'class' => ($action == 'history') ?
'selected' : false,
791 'text' => wfMsg( 'history_short' ),
792 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
796 if( $wgUser->isAllowed( 'delete' ) ) {
797 $content_actions['delete'] = array(
798 'class' => ($action == 'delete') ?
'selected' : false,
799 'text' => wfMsg( 'delete' ),
800 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
803 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
804 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
805 $content_actions['move'] = array(
806 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
807 'text' => wfMsg( 'move' ),
808 'href' => $moveTitle->getLocalUrl()
812 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
813 if( !$this->mTitle
->isProtected() ){
814 $content_actions['protect'] = array(
815 'class' => ($action == 'protect') ?
'selected' : false,
816 'text' => wfMsg( 'protect' ),
817 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
821 $content_actions['unprotect'] = array(
822 'class' => ($action == 'unprotect') ?
'selected' : false,
823 'text' => wfMsg( 'unprotect' ),
824 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
829 //article doesn't exist or is deleted
830 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
831 $n = $this->mTitle
->isDeleted();
833 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
834 $content_actions['undelete'] = array(
836 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
837 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
838 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
843 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
844 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
845 $content_actions['protect'] = array(
846 'class' => ($action == 'protect') ?
'selected' : false,
847 'text' => wfMsg( 'protect' ),
848 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
852 $content_actions['unprotect'] = array(
853 'class' => ($action == 'unprotect') ?
'selected' : false,
854 'text' => wfMsg( 'unprotect' ),
855 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
861 wfProfileOut( __METHOD__
. '-live' );
863 if( $this->loggedin
) {
864 if( !$this->mTitle
->userIsWatching()) {
865 $content_actions['watch'] = array(
866 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
867 'text' => wfMsg( 'watch' ),
868 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
871 $content_actions['unwatch'] = array(
872 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
873 'text' => wfMsg( 'unwatch' ),
874 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
880 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
882 /* show special page tab */
884 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
885 'class' => 'selected',
886 'text' => wfMsg('nstab-special'),
887 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
890 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
893 /* show links to different language variants */
894 global $wgDisableLangConversion;
895 $variants = $wgContLang->getVariants();
896 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
897 $preferred = $wgContLang->getPreferredVariant();
899 foreach( $variants as $code ) {
900 $varname = $wgContLang->getVariantname( $code );
901 if( $varname == 'disable' )
903 $selected = ( $code == $preferred )?
'selected' : false;
904 $content_actions['varlang-' . $vcount] = array(
905 'class' => $selected,
907 'href' => $this->mTitle
->getLocalURL( '', $code )
913 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
915 wfProfileOut( __METHOD__
);
916 return $content_actions;
920 * build array of common navigation links
924 function buildNavUrls() {
925 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
926 global $wgUploadNavigationUrl;
928 wfProfileIn( __METHOD__
);
930 $action = $wgRequest->getVal( 'action', 'view' );
933 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
934 if( $wgUploadNavigationUrl ) {
935 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
936 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $wgUser ) === true ) {
937 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
939 $nav_urls['upload'] = false;
941 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
943 // default permalink to being off, will override it as required below.
944 $nav_urls['permalink'] = false;
946 // A print stylesheet is attached to all pages, but nobody ever
947 // figures that out. :) Add a link...
948 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
949 if ( !$wgOut->isPrintable() ) {
950 $nav_urls['print'] = array(
951 'text' => wfMsg( 'printableversion' ),
952 'href' => $wgRequest->appendQuery( 'printable=yes' )
956 // Also add a "permalink" while we're at it
957 if ( $this->mRevisionId
) {
958 $nav_urls['permalink'] = array(
959 'text' => wfMsg( 'permalink' ),
960 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
964 // Copy in case this undocumented, shady hook tries to mess with internals
965 $revid = $this->mRevisionId
;
966 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
969 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
970 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
971 $nav_urls['whatlinkshere'] = array(
972 'href' => $wlhTitle->getLocalUrl()
974 if( $this->mTitle
->getArticleId() ) {
975 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
976 $nav_urls['recentchangeslinked'] = array(
977 'href' => $rclTitle->getLocalUrl()
980 $nav_urls['recentchangeslinked'] = false;
982 if( $wgUseTrackbacks )
983 $nav_urls['trackbacklink'] = array(
984 'href' => $wgOut->getTitle()->trackbackURL()
988 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
989 $rootUser = strtok( $this->mTitle
->getText(), '/' );
990 $id = User
::idFromName( $rootUser );
991 $ip = User
::isIP( $rootUser );
997 if( $id ||
$ip ) { # both anons and non-anons have contribs list
998 $nav_urls['contributions'] = array(
999 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1003 $logPage = SpecialPage
::getTitleFor( 'Log' );
1004 $nav_urls['log'] = array(
1005 'href' => $logPage->getLocalUrl(
1012 $nav_urls['log'] = false;
1015 if ( $wgUser->isAllowed( 'block' ) ) {
1016 $nav_urls['blockip'] = array(
1017 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $rootUser )
1020 $nav_urls['blockip'] = false;
1023 $nav_urls['contributions'] = false;
1024 $nav_urls['log'] = false;
1025 $nav_urls['blockip'] = false;
1027 $nav_urls['emailuser'] = false;
1028 if( $this->showEmailUser( $id ) ) {
1029 $nav_urls['emailuser'] = array(
1030 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1033 wfProfileOut( __METHOD__
);
1038 * Generate strings used for xml 'id' names
1042 function getNameSpaceKey() {
1043 return $this->mTitle
->getNamespaceKey();
1049 function setupUserJs( $allowUserJs ) {
1050 global $wgRequest, $wgJsMimeType;
1051 wfProfileIn( __METHOD__
);
1053 $action = $wgRequest->getVal( 'action', 'view' );
1055 if( $allowUserJs && $this->loggedin
) {
1056 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1057 # XXX: additional security check/prompt?
1058 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1060 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1063 wfProfileOut( __METHOD__
);
1067 * Code for extensions to hook into to provide per-page CSS, see
1068 * extensions/PageCSS/PageCSS.php for an implementation of this.
1072 function setupPageCss() {
1073 wfProfileIn( __METHOD__
);
1075 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1076 wfProfileOut( __METHOD__
);
1080 public function commonPrintStylesheet() {
1086 * Generic wrapper for template functions, with interface
1087 * compatible with what we use of PHPTAL 0.7.
1090 abstract class QuickTemplate
{
1094 public function QuickTemplate() {
1095 $this->data
= array();
1096 $this->translator
= new MediaWiki_I18N();
1100 * Sets the value $value to $name
1104 public function set( $name, $value ) {
1105 $this->data
[$name] = $value;
1112 public function setRef( $name, &$value ) {
1113 $this->data
[$name] =& $value;
1119 public function setTranslator( &$t ) {
1120 $this->translator
= &$t;
1124 * Main function, used by classes that subclass QuickTemplate
1125 * to show the actual HTML output
1127 abstract public function execute();
1132 function text( $str ) {
1133 echo htmlspecialchars( $this->data
[$str] );
1139 function jstext( $str ) {
1140 echo Xml
::escapeJsString( $this->data
[$str] );
1146 function html( $str ) {
1147 echo $this->data
[$str];
1153 function msg( $str ) {
1154 echo htmlspecialchars( $this->translator
->translate( $str ) );
1160 function msgHtml( $str ) {
1161 echo $this->translator
->translate( $str );
1165 * An ugly, ugly hack.
1168 function msgWiki( $str ) {
1169 global $wgParser, $wgOut;
1171 $text = $this->translator
->translate( $str );
1172 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1173 $wgOut->parserOptions(), true );
1174 echo $parserOutput->getText();
1180 function haveData( $str ) {
1181 return isset( $this->data
[$str] );
1187 function haveMsg( $str ) {
1188 $msg = $this->translator
->translate( $str );
1189 return ( $msg != '-' ) && ( $msg != '' ); # ????
1194 * New base template for a skin's template extended from QuickTemplate
1195 * this class features helper methods that provide common ways of interacting
1196 * with the data stored in the QuickTemplate
1198 abstract class BaseTemplate
extends QuickTemplate
{
1201 * Create an array of common toolbox items from the data in the quicktemplate
1202 * stored by SkinTemplate.
1203 * The resulting array is built acording to a format intended to be passed
1204 * through makeListItem to generate the html.
1206 function getToolbox() {
1207 wfProfileIn( __METHOD__
);
1210 if ( $this->data
['notspecialpage'] ) {
1211 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1212 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1213 if ( $this->data
['nav_urls']['recentchangeslinked'] ) {
1214 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1215 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1216 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1219 if( isset( $this->data
['nav_urls']['trackbacklink'] ) && $this->data
['nav_urls']['trackbacklink'] ) {
1220 $toolbox['trackbacklink'] = $this->data
['nav_urls']['trackbacklink'];
1221 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1223 if ( $this->data
['feeds'] ) {
1224 $toolbox['feeds']['id'] = 'feedlinks';
1225 $toolbox['feeds']['links'] = array();
1226 foreach ( $this->data
['feeds'] as $key => $feed ) {
1227 $toolbox['feeds']['links'][$key] = $feed;
1228 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1229 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1230 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1231 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1234 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1235 if ( $this->data
['nav_urls'][$special] ) {
1236 $toolbox[$special] = $this->data
['nav_urls'][$special];
1237 $toolbox[$special]['id'] = "t-$special";
1240 if ( !empty( $this->data
['nav_urls']['print']['href'] ) ) {
1241 $toolbox['print'] = $this->data
['nav_urls']['print'];
1242 $toolbox['print']['rel'] = 'alternate';
1243 $toolbox['print']['msg'] = 'printableversion';
1245 if ( !empty( $this->data
['nav_urls']['permalink']['href'] ) ) {
1246 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1247 $toolbox['permalink']['id'] = 't-permalink';
1248 } elseif ( $this->data
['nav_urls']['permalink']['href'] === '' ) {
1249 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1250 unset( $toolbox['permalink']['href'] );
1251 $toolbox['ispermalink']['tooltiponly'] = true;
1252 $toolbox['ispermalink']['id'] = 't-ispermalink';
1253 $toolbox['ispermalink']['msg'] = 'permalink';
1255 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1256 wfProfileOut( __METHOD__
);
1261 * Makes a link, usually used by makeListItem to generate a link for an item
1262 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1264 * $key is a string, usually a key from the list you are generating this link from
1265 * $item is an array containing some of a specific set of keys.
1266 * The text of the link will be generated either from the contents of the "text"
1267 * key in the $item array, if a "msg" key is present a message by that name will
1268 * be used, and if neither of those are set the $key will be used as a message name.
1269 * If a "href" key is not present makeLink will just output htmlescaped text.
1270 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1271 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1272 * is present it will be used to generate a tooltip and accesskey for the link.
1273 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1275 function makeLink( $key, $item ) {
1276 if ( isset( $item['text'] ) ) {
1277 $text = $item['text'];
1279 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1282 if ( !isset( $item['href'] ) ) {
1283 return htmlspecialchars( $text );
1287 foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
1288 if ( isset( $item[$attr] ) ) {
1289 $attrs[$attr] = $item[$attr];
1293 if ( isset( $item['id'] ) ) {
1294 $item['single-id'] = $item['id'];
1296 if ( isset( $item['single-id'] ) ) {
1297 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1298 $attrs['title'] = $this->skin
->titleAttrib( $item['single-id'] );
1299 if ( $attrs['title'] === false ) {
1300 unset( $attrs['title'] );
1303 $attrs = array_merge(
1305 $this->skin
->tooltipAndAccesskeyAttribs( $item['single-id'] )
1310 return Html
::element( 'a', $attrs, $text );
1314 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1315 * $key is a string, usually a key from the list you are generating this link from
1316 * $item is an array of list item data containing some of a specific set of keys.
1317 * The "id" and "class" keys will be used as attributes for the list item,
1318 * if "active" contains a value of true a "active" class will also be appended to class.
1319 * If you want something other than a <li> you can pass a tag name such as
1320 * "tag" => "span" in the $options array to change the tag used.
1321 * link/content data for the list item may come in one of two forms
1322 * A "links" key may be used, in which case it should contain an array with
1323 * a list of links to include inside the list item, see makeLink for the format
1324 * of individual links array items.
1325 * Otherwise the relevant keys from the list item $item array will be passed
1326 * to makeLink instead. Note however that "id" and "class" are used by the
1327 * list item directly so they will not be passed to makeLink
1328 * (however the link will still support a tooltip and accesskey from it)
1329 * If you need an id or class on a single link you should include a "links"
1330 * array with just one link item inside of it.
1332 function makeListItem( $key, $item, $options = array() ) {
1333 if ( isset( $item['links'] ) ) {
1335 foreach ( $item['links'] as $linkKey => $link ) {
1336 $html .= $this->makeLink( $linkKey, $link );
1340 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
1341 if ( isset( $item[$k] ) ) {
1342 $link[$k] = $item[$k];
1345 if ( isset( $item['id'] ) ) {
1346 // The id goes on the <li> not on the <a> for single links
1347 // but makeSidebarLink still needs to know what id to use when
1348 // generating tooltips and accesskeys.
1349 $link['single-id'] = $item['id'];
1351 $html = $this->makeLink( $key, $link );
1355 foreach ( array( 'id', 'class' ) as $attr ) {
1356 if ( isset( $item[$attr] ) ) {
1357 $attrs[$attr] = $item[$attr];
1360 if ( isset( $item['active'] ) && $item['active'] ) {
1361 $attrs['class'] .= ' active';
1362 $attrs['class'] = trim( $attrs['class'] );
1364 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1367 function makeSearchInput( $attrs = array() ) {
1371 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1373 $realAttrs = array_merge( $realAttrs, $this->skin
->tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1374 return Html
::element( 'input', $realAttrs );
1377 function makeSearchButton( $mode, $attrs = array() ) {
1384 'value' => $this->translator
->translate( $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1386 $realAttrs = array_merge(
1388 $this->skin
->tooltipAndAccesskeyAttribs( "search-$mode" ),
1391 return Html
::element( 'input', $realAttrs );
1393 $buttonAttrs = array(
1397 $buttonAttrs = array_merge(
1399 $this->skin
->tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1402 unset( $buttonAttrs['src'] );
1403 unset( $buttonAttrs['alt'] );
1405 'src' => $attrs['src'],
1406 'alt' => isset( $attrs['alt'] ) ?
$attrs['alt'] : $this->translator
->translate( 'searchbutton' ),
1408 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1410 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1415 * Returns an array of footerlinks trimmed down to only those footer links that
1417 * If you pass "flat" as an option then the returned array will be a flat array
1418 * of footer icons instead of a key/value array of footerlinks arrays broken
1419 * up into categories.
1421 function getFooterLinks( $option = null ) {
1422 $footerlinks = $this->data
['footerlinks'];
1424 // Reduce footer links down to only those which are being used
1425 $validFooterLinks = array();
1426 foreach( $footerlinks as $category => $links ) {
1427 $validFooterLinks[$category] = array();
1428 foreach( $links as $link ) {
1429 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1430 $validFooterLinks[$category][] = $link;
1433 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1434 unset( $validFooterLinks[$category] );
1438 if ( $option == 'flat' ) {
1439 // fold footerlinks into a single array using a bit of trickery
1440 $validFooterLinks = call_user_func_array(
1442 array_values( $validFooterLinks )
1446 return $validFooterLinks;
1450 * Returns an array of footer icons filtered down by options relevant to how
1451 * the skin wishes to display them.
1452 * If you pass "icononly" as the option all footer icons which do not have an
1453 * image icon set will be filtered out.
1454 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1455 * in the list of footer icons. This is mostly useful for skins which only
1456 * display the text from footericons instead of the images and don't want a
1457 * duplicate copyright statement because footerlinks already rendered one.
1459 function getFooterIcons( $option = null ) {
1460 // Generate additional footer icons
1461 $footericons = $this->data
['footericons'];
1463 if ( $option == 'icononly' ) {
1464 // Unset any icons which don't have an image
1465 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1466 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1467 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1468 unset( $footerIconsBlock[$footerIconKey] );
1472 // Redo removal of any empty blocks
1473 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1474 if ( count( $footerIconsBlock ) <= 0 ) {
1475 unset( $footericons[$footerIconsKey] );
1478 } elseif ( $option == 'nocopyright' ) {
1479 $footericons = $this->data
['footericons'];
1480 unset( $footericons['copyright']['copyright'] );
1481 if ( count( $footericons['copyright'] ) <= 0 ) {
1482 unset( $footericons['copyright'] );
1486 return $footericons;