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 $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 # FIXME: this is the only use of OutputPage::isUserJsAllowed() anywhere; can we
205 # get rid of it? For that matter, why is any of this here at all?
206 $this->setupUserJs( $out->isUserJsAllowed() );
207 $tpl->setRef( 'userjs', $this->userjs
);
208 $tpl->setRef( 'userjsprev', $this->userjsprev
);
211 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
212 $tpl->set( 'jsvarurl',
214 "action=raw$jsCache&gen=js&useskin=" .
215 urlencode( $this->getSkinName() ) ) );
217 $tpl->set( 'jsvarurl', false );
220 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
221 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
222 $tpl->set( 'html5version', $wgHtml5Version );
223 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
224 $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
226 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
227 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
229 $tpl->set( 'trackbackhtml', null );
232 wfProfileOut( __METHOD__
. '-stuff-head' );
234 wfProfileIn( __METHOD__
. '-stuff2' );
235 $tpl->set( 'title', $out->getPageTitle() );
236 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
237 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
238 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
239 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
241 $nsname = MWNamespace
::exists( $this->mTitle
->getNamespace() ) ?
242 MWNamespace
::getCanonicalName( $this->mTitle
->getNamespace() ) :
243 $this->mTitle
->getNsText();
245 $tpl->set( 'nscanonical', $nsname );
246 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
247 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
248 $tpl->set( 'titletext', $this->mTitle
->getText() );
249 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
250 $tpl->set( 'currevisionid', $this->mTitle
->getLatestRevID() );
252 $tpl->set( 'isarticle', $out->isArticle() );
254 $tpl->setRef( 'thispage', $this->thispage
);
255 $subpagestr = $this->subPageSubtitle();
257 'subtitle', !empty( $subpagestr ) ?
258 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
261 $undelete = $this->getUndeleteLink();
263 'undelete', !empty( $undelete ) ?
264 '<span class="subpages">' . $undelete . '</span>' :
268 $tpl->set( 'catlinks', $this->getCategories() );
269 if( $out->isSyndicated() ) {
271 foreach( $out->getSyndicationLinks() as $format => $link ) {
272 $feeds[$format] = array(
273 'text' => wfMsg( "feed-$format" ),
277 $tpl->setRef( 'feeds', $feeds );
279 $tpl->set( 'feeds', false );
282 $tpl->setRef( 'mimetype', $wgMimeType );
283 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
284 $tpl->setRef( 'charset', $wgOutputEncoding );
285 $tpl->setRef( 'wgScript', $wgScript );
286 $tpl->setRef( 'skinname', $this->skinname
);
287 $tpl->set( 'skinclass', get_class( $this ) );
288 $tpl->setRef( 'stylename', $this->stylename
);
289 $tpl->set( 'printable', $out->isPrintable() );
290 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
291 $tpl->setRef( 'loggedin', $this->loggedin
);
292 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
293 /* XXX currently unused, might get useful later
294 $tpl->set( 'editable', ( $this->mTitle->getNamespace() != NS_SPECIAL ) );
295 $tpl->set( 'exists', $this->mTitle->getArticleID() != 0 );
296 $tpl->set( 'watch', $this->mTitle->userIsWatching() ? 'unwatch' : 'watch' );
297 $tpl->set( 'protect', count( $this->mTitle->isProtected() ) ? 'unprotect' : 'protect' );
298 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
300 $tpl->set( 'searchaction', $this->escapeSearchLink() );
301 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
302 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
303 $tpl->setRef( 'stylepath', $wgStylePath );
304 $tpl->setRef( 'articlepath', $wgArticlePath );
305 $tpl->setRef( 'scriptpath', $wgScriptPath );
306 $tpl->setRef( 'serverurl', $wgServer );
307 $tpl->setRef( 'logopath', $wgLogo );
310 $tpl->set( 'lang', $lang->getCode() );
311 $tpl->set( 'dir', $lang->getDir() );
312 $tpl->set( 'rtl', $lang->isRTL() );
314 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
315 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
316 $tpl->set( 'username', $wgUser->isAnon() ?
null : $this->username
);
317 $tpl->setRef( 'userpage', $this->userpage
);
318 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
319 $tpl->set( 'userlang', $wgLang->getCode() );
321 // Users can have their language set differently than the
322 // content of the wiki. For these users, tell the web browser
323 // that interface elements are in a different language.
324 $tpl->set( 'userlangattributes', '' );
325 $tpl->set( 'specialpageattributes', '' );
327 $lang = $wgLang->getCode();
328 $dir = $wgLang->getDir();
329 if ( $lang !== $wgContLang->getCode() ||
$dir !== $wgContLang->getDir() ) {
330 $attrs = " lang='$lang' dir='$dir'";
332 $tpl->set( 'userlangattributes', $attrs );
334 // The content of SpecialPages should be presented in the
335 // user's language. Content of regular pages should not be touched.
336 if( $this->mTitle
->isSpecialPage() ) {
337 $tpl->set( 'specialpageattributes', $attrs );
341 $newtalks = $this->getNewtalks();
343 wfProfileOut( __METHOD__
. '-stuff2' );
345 wfProfileIn( __METHOD__
. '-stuff3' );
346 $tpl->setRef( 'newtalk', $newtalks );
347 $tpl->setRef( 'skin', $this );
348 $tpl->set( 'logo', $this->logoText() );
349 if ( $out->isArticle() && ( !isset( $oldid ) ||
isset( $diff ) ) &&
350 $this->mTitle
->exists() )
352 $article = new Article( $this->mTitle
, 0 );
353 if ( !$wgDisableCounters ) {
354 $viewcount = $wgLang->formatNum( $article->getCount() );
356 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
358 $tpl->set( 'viewcount', false );
361 $tpl->set( 'viewcount', false );
364 if( $wgPageShowWatchingUsers ) {
365 $dbr = wfGetDB( DB_SLAVE
);
366 $res = $dbr->select( 'watchlist',
367 array( 'COUNT(*) AS n' ),
368 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
371 $x = $dbr->fetchObject( $res );
372 $numberofwatchingusers = $x->n
;
373 if( $numberofwatchingusers > 0 ) {
374 $tpl->set( 'numberofwatchingusers',
375 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
376 $wgLang->formatNum( $numberofwatchingusers ) )
379 $tpl->set( 'numberofwatchingusers', false );
382 $tpl->set( 'numberofwatchingusers', false );
385 $tpl->set( 'copyright', $this->getCopyright() );
387 $this->credits
= false;
389 if( $wgMaxCredits != 0 ){
390 $this->credits
= Credits
::getCredits( $article, $wgMaxCredits, $wgShowCreditsIfMax );
392 $tpl->set( 'lastmod', $this->lastModified( $article ) );
395 $tpl->setRef( 'credits', $this->credits
);
397 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
398 $tpl->set( 'copyright', $this->getCopyright() );
399 $tpl->set( 'viewcount', false );
400 $tpl->set( 'lastmod', false );
401 $tpl->set( 'credits', false );
402 $tpl->set( 'numberofwatchingusers', false );
404 $tpl->set( 'copyright', false );
405 $tpl->set( 'viewcount', false );
406 $tpl->set( 'lastmod', false );
407 $tpl->set( 'credits', false );
408 $tpl->set( 'numberofwatchingusers', false );
410 wfProfileOut( __METHOD__
. '-stuff3' );
412 wfProfileIn( __METHOD__
. '-stuff4' );
413 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
414 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
415 $tpl->set( 'disclaimer', $this->disclaimerLink() );
416 $tpl->set( 'privacy', $this->privacyLink() );
417 $tpl->set( 'about', $this->aboutLink() );
419 $tpl->set( 'footerlinks', array(
423 'numberofwatchingusers',
434 global $wgFooterIcons;
435 $tpl->set( 'footericons', $wgFooterIcons );
436 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
437 if ( count( $footerIconsBlock ) > 0 ) {
438 foreach ( $footerIconsBlock as &$footerIcon ) {
439 if ( isset( $footerIcon['src'] ) ) {
440 if ( !isset( $footerIcon['width'] ) ) {
441 $footerIcon['width'] = 88;
443 if ( !isset( $footerIcon['height'] ) ) {
444 $footerIcon['height'] = 31;
449 unset( $tpl->data
['footericons'][$footerIconsKey] );
453 if ( $wgDebugComments ) {
454 $tpl->setRef( 'debug', $out->mDebugtext
);
456 $tpl->set( 'debug', '' );
459 $tpl->set( 'reporttime', wfReportTime() );
460 $tpl->set( 'sitenotice', wfGetSiteNotice() );
461 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
463 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
464 global $wgBetterDirectionality;
465 if ( $wgBetterDirectionality ) {
466 $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
467 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
469 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
470 $tpl->setRef( 'bodytext', $out->mBodytext
);
473 $language_urls = array();
475 if ( !$wgHideInterlanguageLinks ) {
476 foreach( $out->getLanguageLinks() as $l ) {
477 $tmp = explode( ':', $l, 2 );
478 $class = 'interwiki-' . $tmp[0];
480 $nt = Title
::newFromText( $l );
482 $language_urls[] = array(
483 'href' => $nt->getFullURL(),
484 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
485 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
486 'title' => $nt->getText(),
492 if( count( $language_urls ) ) {
493 $tpl->setRef( 'language_urls', $language_urls );
495 $tpl->set( 'language_urls', false );
497 wfProfileOut( __METHOD__
. '-stuff4' );
499 wfProfileIn( __METHOD__
. '-stuff5' );
501 $tpl->set( 'personal_urls', $this->buildPersonalUrls( $out ) );
502 $content_navigation = $this->buildContentNavigationUrls( $out );
503 $content_actions = $this->buildContentActionUrls( $content_navigation );
504 $tpl->setRef( 'content_navigation', $content_navigation );
505 $tpl->setRef( 'content_actions', $content_actions );
507 $tpl->set( 'sidebar', $this->buildSidebar() );
508 $tpl->set( 'nav_urls', $this->buildNavUrls( $out ) );
510 // Set the head scripts near the end, in case the above actions resulted in added scripts
511 if ( $this->useHeadElement
) {
512 $tpl->set( 'headelement', $out->headElement( $this ) );
514 $tpl->set( 'headscripts', $out->getScript() );
517 // original version by hansm
518 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
519 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
522 // allow extensions adding stuff after the page content.
523 // See Skin::afterContentHook() for further documentation.
524 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
525 wfProfileOut( __METHOD__
. '-stuff5' );
528 wfProfileIn( __METHOD__
. '-execute' );
529 $res = $tpl->execute();
530 wfProfileOut( __METHOD__
. '-execute' );
532 // result may be an error
533 $this->printOrError( $res );
534 wfProfileOut( __METHOD__
);
538 * Output the string, or print error message if it's
539 * an error object of the appropriate type.
540 * For the base class, assume strings all around.
545 function printOrError( $str ) {
550 * Output a boolean indiciating if buildPersonalUrls should output separate
551 * login and create account links or output a combined link
552 * By default we simply return a global config setting that affects most skins
553 * This is setup as a method so that like with $wgLogo and getLogo() a skin
554 * can override this setting and always output one or the other if it has
555 * a reason it can't output one of the two modes.
557 function useCombinedLoginLink() {
558 global $wgUseCombinedLoginLink;
559 return $wgUseCombinedLoginLink;
563 * build array of urls for personal toolbar
566 protected function buildPersonalUrls( OutputPage
$out ) {
569 $title = $out->getTitle();
570 $pageurl = $title->getLocalURL();
571 wfProfileIn( __METHOD__
);
573 /* set up the default links for the personal toolbar */
574 $personal_urls = array();
575 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
576 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
577 $returnto = "returnto=$page";
578 if( $this->thisquery
!= '' ) {
579 $returnto .= "&returntoquery=$query";
581 if( $this->loggedin
) {
582 $personal_urls['userpage'] = array(
583 'text' => $this->username
,
584 'href' => &$this->userpageUrlDetails
['href'],
585 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
586 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
588 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
589 $personal_urls['mytalk'] = array(
590 'text' => wfMsg( 'mytalk' ),
591 'href' => &$usertalkUrlDetails['href'],
592 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
593 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
595 $href = self
::makeSpecialUrl( 'Preferences' );
596 $personal_urls['preferences'] = array(
597 'text' => wfMsg( 'mypreferences' ),
599 'active' => ( $href == $pageurl )
601 $href = self
::makeSpecialUrl( 'Watchlist' );
602 $personal_urls['watchlist'] = array(
603 'text' => wfMsg( 'mywatchlist' ),
605 'active' => ( $href == $pageurl )
608 # We need to do an explicit check for Special:Contributions, as we
609 # have to match both the title, and the target (which could come
610 # from request values or be specified in "sub page" form. The plot
611 # thickens, because $wgTitle is altered for special pages, so doesn't
612 # contain the original alias-with-subpage.
613 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
614 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
615 list( $spName, $spPar ) =
616 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
617 $active = $spName == 'Contributions'
618 && ( ( $spPar && $spPar == $this->username
)
619 ||
$wgRequest->getText( 'target' ) == $this->username
);
624 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
625 $personal_urls['mycontris'] = array(
626 'text' => wfMsg( 'mycontris' ),
630 $personal_urls['logout'] = array(
631 'text' => wfMsg( 'userlogout' ),
632 'href' => self
::makeSpecialUrl( 'Userlogout',
633 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
639 $useCombinedLoginLink = $this->useCombinedLoginLink();
640 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
641 ?
'nav-login-createaccount'
643 $is_signup = $wgRequest->getText('type') == "signup";
645 # anonlogin & login are the same
647 'text' => wfMsg( $loginlink ),
648 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
649 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" ||
!$is_signup )
651 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
652 $createaccount_url = array(
653 'text' => wfMsg( 'createaccount' ),
654 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
655 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
658 global $wgProto, $wgSecureLogin;
659 if( $wgProto === 'http' && $wgSecureLogin ) {
660 $title = SpecialPage
::getTitleFor( 'Userlogin' );
661 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
662 $login_url['href'] = $https_url;
663 $login_url['class'] = 'link-https'; # FIXME class depends on skin
664 if ( isset($createaccount_url) ) {
665 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL("type=signup") );
666 $createaccount_url['href'] = $https_url;
667 $createaccount_url['class'] = 'link-https'; # FIXME class depends on skin
672 if( $this->showIPinHeader() ) {
673 $href = &$this->userpageUrlDetails
['href'];
674 $personal_urls['anonuserpage'] = array(
675 'text' => $this->username
,
677 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
678 'active' => ( $pageurl == $href )
680 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
681 $href = &$usertalkUrlDetails['href'];
682 $personal_urls['anontalk'] = array(
683 'text' => wfMsg( 'anontalk' ),
685 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
686 'active' => ( $pageurl == $href )
688 $personal_urls['anonlogin'] = $login_url;
689 if ( isset($createaccount_url) ) {
690 $personal_urls['createaccount'] = $createaccount_url;
693 $personal_urls['login'] = $login_url;
697 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
698 wfProfileOut( __METHOD__
);
699 return $personal_urls;
702 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
705 $classes[] = 'selected';
707 if( $checkEdit && !$title->isKnown() ) {
709 $query = 'action=edit&redlink=1';
712 // wfMessageFallback will nicely accept $message as an array of fallbacks
713 // or just a single key
714 $msg = wfMessageFallback( $message );
715 if ( is_array($message) ) {
716 // for hook compatibility just keep the last message name
717 $message = end($message);
719 if ( $msg->exists() ) {
720 $text = $msg->text();
723 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
727 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
728 $title, $message, $selected, $checkEdit,
729 &$classes, &$query, &$text, &$result ) ) ) {
734 'class' => implode( ' ', $classes ),
736 'href' => $title->getLocalUrl( $query ),
740 function makeTalkUrlDetails( $name, $urlaction = '' ) {
741 $title = Title
::newFromText( $name );
742 if( !is_object( $title ) ) {
743 throw new MWException( __METHOD__
. " given invalid pagename $name" );
745 $title = $title->getTalkPage();
746 self
::checkTitle( $title, $name );
748 'href' => $title->getLocalURL( $urlaction ),
749 'exists' => $title->getArticleID() != 0,
753 function makeArticleUrlDetails( $name, $urlaction = '' ) {
754 $title = Title
::newFromText( $name );
755 $title= $title->getSubjectPage();
756 self
::checkTitle( $title, $name );
758 'href' => $title->getLocalURL( $urlaction ),
759 'exists' => $title->getArticleID() != 0,
764 * a structured array of links usually used for the tabs in a skin
766 * There are 4 standard sections
767 * namespaces: Used for namespace tabs like special, page, and talk namespaces
768 * views: Used for primary page views like read, edit, history
769 * actions: Used for most extra page actions like deletion, protection, etc...
770 * variants: Used to list the language variants for the page
772 * Each section's value is a key/value array of links for that section.
773 * The links themseves have these common keys:
774 * - class: The css classes to apply to the tab
775 * - text: The text to display on the tab
776 * - href: The href for the tab to point to
777 * - rel: An optional rel= for the tab's link
778 * - redundant: If true the tab will be dropped in skins using content_actions
779 * this is useful for tabs like "Read" which only have meaning in skins that
780 * take special meaning from the grouped structure of content_navigation
782 * Views also have an extra key which can be used:
783 * - primary: If this is not true skins like vector may try to hide the tab
784 * when the user has limited space in their browser window
786 * content_navigation using code also expects these ids to be present on the
787 * links, however these are usually automatically generated by SkinTemplate
788 * itself and are not necessary when using a hook. The only things these may
789 * matter to are people modifying content_navigation after it's initial creation:
790 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
791 * - tooltiponly: This is set to true for some tabs in cases where the system
792 * believes that the accesskey should not be added to the tab.
796 protected function buildContentNavigationUrls( OutputPage
$out ) {
797 global $wgContLang, $wgLang, $wgUser, $wgRequest;
798 global $wgDisableLangConversion;
800 wfProfileIn( __METHOD__
);
802 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
803 $onPage = $title->equals($this->mTitle
);
805 $content_navigation = array(
806 'namespaces' => array(),
808 'actions' => array(),
809 'variants' => array()
813 $action = $wgRequest->getVal( 'action', 'view' );
814 $section = $wgRequest->getVal( 'section' );
816 $userCanRead = $title->userCanRead();
817 $skname = $this->skinname
;
819 $preventActiveTabs = false;
820 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
822 // Checks if page is some kind of content
823 if( $title->getNamespace() != NS_SPECIAL
) {
824 // Gets page objects for the related namespaces
825 $subjectPage = $title->getSubjectPage();
826 $talkPage = $title->getTalkPage();
828 // Determines if this is a talk page
829 $isTalk = $title->isTalkPage();
831 // Generates XML IDs from namespace names
832 $subjectId = $title->getNamespaceKey( '' );
834 if ( $subjectId == 'main' ) {
837 $talkId = "{$subjectId}_talk";
840 // Adds namespace links
841 $subjectMsg = array( "nstab-$subjectId" );
842 if ( $subjectPage->isMainPage() ) {
843 array_unshift($subjectMsg, 'mainpage-nstab');
845 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
846 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
848 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
849 $content_navigation['namespaces'][$talkId] = $this->tabAction(
850 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
852 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
854 // Adds view view link
855 if ( $title->exists() && $userCanRead ) {
856 $content_navigation['views']['view'] = $this->tabAction(
857 $isTalk ?
$talkPage : $subjectPage,
858 array( "$skname-view-view", 'view' ),
859 ( $onPage && ($action == 'view' ||
$action == 'purge' ) ), '', true
861 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
864 wfProfileIn( __METHOD__
. '-edit' );
866 // Checks if user can...
868 // read and edit the current page
869 $userCanRead && $title->quickUserCan( 'edit' ) &&
873 // or they can create one here
874 $title->quickUserCan( 'create' )
877 // Builds CSS class for talk page links
878 $isTalkClass = $isTalk ?
' istalk' : '';
880 // Determines if we're in edit mode
883 ( $action == 'edit' ||
$action == 'submit' ) &&
884 ( $section != 'new' )
886 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& !wfEmptyMsg( $title->getText() ) ) ?
888 $content_navigation['views']['edit'] = array(
889 'class' => ( $selected ?
'selected' : '' ) . $isTalkClass,
890 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
891 'href' => $title->getLocalURL( $this->editUrlOptions() ),
892 'primary' => true, // don't collapse this in vector
894 // Checks if this is a current rev of talk page and we should show a new
896 if ( ( $isTalk && $this->isRevisionCurrent() ) ||
( $out->showNewSectionLink() ) ) {
897 // Checks if we should ever show a new section link
898 if ( !$out->forceHideNewSectionLink() ) {
899 // Adds new section link
900 //$content_navigation['actions']['addsection']
901 $content_navigation['views']['addsection'] = array(
902 'class' => $section == 'new' ?
'selected' : false,
903 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
904 'href' => $title->getLocalURL( 'action=edit§ion=new' )
908 // Checks if the page has some kind of viewable content
909 } elseif ( $title->hasSourceText() && $userCanRead ) {
910 // Adds view source view link
911 $content_navigation['views']['viewsource'] = array(
912 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
913 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
914 'href' => $title->getLocalURL( $this->editUrlOptions() ),
915 'primary' => true, // don't collapse this in vector
918 wfProfileOut( __METHOD__
. '-edit' );
920 wfProfileIn( __METHOD__
. '-live' );
922 // Checks if the page exists
923 if ( $title->exists() && $userCanRead ) {
924 // Adds history view link
925 $content_navigation['views']['history'] = array(
926 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
927 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
928 'href' => $title->getLocalURL( 'action=history' ),
932 if( $wgUser->isAllowed( 'delete' ) ) {
933 $content_navigation['actions']['delete'] = array(
934 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
935 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
936 'href' => $title->getLocalURL( 'action=delete' )
939 if ( $title->quickUserCan( 'move' ) ) {
940 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
941 $content_navigation['actions']['move'] = array(
942 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
943 'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
944 'href' => $moveTitle->getLocalURL()
948 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
949 $mode = !$title->isProtected() ?
'protect' : 'unprotect';
950 $content_navigation['actions'][$mode] = array(
951 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
952 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
953 'href' => $title->getLocalURL( "action=$mode" )
957 // article doesn't exist or is deleted
958 if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
959 $n = $title->isDeleted();
961 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
962 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
963 $msgKey = $wgUser->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
964 $content_navigation['actions']['undelete'] = array(
965 'class' => $this->mTitle
->isSpecial( 'Undelete' ) ?
'selected' : false,
966 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
967 ->params( $wgLang->formatNum( $n ) )->text(),
968 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
973 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
974 $mode = !$title->getRestrictions( 'create' ) ?
'protect' : 'unprotect';
975 $content_navigation['actions'][$mode] = array(
976 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
977 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
978 'href' => $title->getLocalURL( "action=$mode" )
982 wfProfileOut( __METHOD__
. '-live' );
984 // Checks if the user is logged in
985 if ( $this->loggedin
) {
987 * The following actions use messages which, if made particular to
988 * the any specific skins, would break the Ajax code which makes this
989 * action happen entirely inline. Skin::makeGlobalVariablesScript
990 * defines a set of messages in a javascript object - and these
991 * messages are assumed to be global for all skins. Without making
992 * a change to that procedure these messages will have to remain as
993 * the global versions.
995 $mode = $title->userIsWatching() ?
'unwatch' : 'watch';
996 $content_navigation['actions'][$mode] = array(
997 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
998 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
999 'href' => $title->getLocalURL( 'action=' . $mode )
1003 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1005 // If it's not content, it's got to be a special page
1006 $content_navigation['namespaces']['special'] = array(
1007 'class' => 'selected',
1008 'text' => wfMsg( 'nstab-special' ),
1009 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
1010 'context' => 'subject'
1013 wfRunHooks( 'SkinTemplateNavigation::SpecialPage', array( &$this, &$content_navigation ) );
1016 // Gets list of language variants
1017 $variants = $wgContLang->getVariants();
1018 // Checks that language conversion is enabled and variants exist
1019 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1020 // Gets preferred variant
1021 $preferred = $wgContLang->getPreferredVariant();
1022 // Loops over each variant
1023 foreach( $variants as $code ) {
1024 // Gets variant name from language code
1025 $varname = $wgContLang->getVariantname( $code );
1026 // Checks if the variant is marked as disabled
1027 if( $varname == 'disable' ) {
1028 // Skips this variant
1031 // Appends variant link
1032 $content_navigation['variants'][] = array(
1033 'class' => ( $code == $preferred ) ?
'selected' : false,
1035 'href' => $title->getLocalURL( '', $code )
1040 // Equiv to SkinTemplateContentActions
1041 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1043 // Setup xml ids and tooltip info
1044 foreach ( $content_navigation as $section => &$links ) {
1045 foreach ( $links as $key => &$link ) {
1047 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1048 $xmlID = 'ca-nstab-' . $xmlID;
1049 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1051 } elseif ( $section == "variants" ) {
1052 $xmlID = 'ca-varlang-' . $xmlID;
1054 $xmlID = 'ca-' . $xmlID;
1056 $link['id'] = $xmlID;
1060 # We don't want to give the watch tab an accesskey if the
1061 # page is being edited, because that conflicts with the
1062 # accesskey on the watch checkbox. We also don't want to
1063 # give the edit tab an accesskey, because that's fairly su-
1064 # perfluous and conflicts with an accesskey (Ctrl-E) often
1065 # used for editing in Safari.
1066 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1067 if ( isset($content_navigation['views']['edit']) ) {
1068 $content_navigation['views']['edit']['tooltiponly'] = true;
1070 if ( isset($content_navigation['actions']['watch']) ) {
1071 $content_navigation['actions']['watch']['tooltiponly'] = true;
1073 if ( isset($content_navigation['actions']['unwatch']) ) {
1074 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1078 wfProfileOut( __METHOD__
);
1080 return $content_navigation;
1084 * an array of edit links by default used for the tabs
1088 function buildContentActionUrls( $content_navigation ) {
1090 wfProfileIn( __METHOD__
);
1092 // content_actions has been replaced with content_navigation for backwards
1093 // compatibility and also for skins that just want simple tabs content_actions
1094 // is now built by flattening the content_navigation arrays into one
1096 $content_actions = array();
1098 foreach ( $content_navigation as $section => $links ) {
1100 foreach ( $links as $key => $value ) {
1102 if ( isset($value["redundant"]) && $value["redundant"] ) {
1103 // Redundant tabs are dropped from content_actions
1107 // content_actions used to have ids built using the "ca-$key" pattern
1108 // so the xmlID based id is much closer to the actual $key that we want
1109 // for that reason we'll just strip out the ca- if present and use
1110 // the latter potion of the "id" as the $key
1111 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1112 $key = substr($value["id"], 3);
1115 if ( isset($content_actions[$key]) ) {
1116 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1120 $content_actions[$key] = $value;
1126 wfProfileOut( __METHOD__
);
1128 return $content_actions;
1132 * build array of common navigation links
1136 protected function buildNavUrls( OutputPage
$out ) {
1137 global $wgUseTrackbacks, $wgUser, $wgRequest;
1138 global $wgUploadNavigationUrl;
1140 wfProfileIn( __METHOD__
);
1142 $action = $wgRequest->getVal( 'action', 'view' );
1144 $nav_urls = array();
1145 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1146 if( $wgUploadNavigationUrl ) {
1147 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1148 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $wgUser ) === true ) {
1149 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1151 $nav_urls['upload'] = false;
1153 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1155 // default permalink to being off, will override it as required below.
1156 $nav_urls['permalink'] = false;
1158 // A print stylesheet is attached to all pages, but nobody ever
1159 // figures that out. :) Add a link...
1160 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
1161 if ( !$out->isPrintable() ) {
1162 $nav_urls['print'] = array(
1163 'text' => wfMsg( 'printableversion' ),
1164 'href' => $wgRequest->appendQuery( 'printable=yes' )
1168 // Also add a "permalink" while we're at it
1169 if ( $this->mRevisionId
) {
1170 $nav_urls['permalink'] = array(
1171 'text' => wfMsg( 'permalink' ),
1172 'href' => $out->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
1176 // Copy in case this undocumented, shady hook tries to mess with internals
1177 $revid = $this->mRevisionId
;
1178 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
1181 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
1182 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
1183 $nav_urls['whatlinkshere'] = array(
1184 'href' => $wlhTitle->getLocalUrl()
1186 if( $this->mTitle
->getArticleId() ) {
1187 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
1188 $nav_urls['recentchangeslinked'] = array(
1189 'href' => $rclTitle->getLocalUrl()
1192 $nav_urls['recentchangeslinked'] = false;
1194 if( $wgUseTrackbacks )
1195 $nav_urls['trackbacklink'] = array(
1196 'href' => $out->getTitle()->trackbackURL()
1200 if ( $user = $this->getRelevantUser() ) {
1201 $id = $user->getID();
1202 $ip = $user->isAnon();
1203 $rootUser = $user->getName();
1209 if( $id ||
$ip ) { # both anons and non-anons have contribs list
1210 $nav_urls['contributions'] = array(
1211 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1215 $logPage = SpecialPage
::getTitleFor( 'Log' );
1216 $nav_urls['log'] = array(
1217 'href' => $logPage->getLocalUrl(
1224 $nav_urls['log'] = false;
1227 if ( $wgUser->isAllowed( 'block' ) ) {
1228 $nav_urls['blockip'] = array(
1229 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $rootUser )
1232 $nav_urls['blockip'] = false;
1235 $nav_urls['contributions'] = false;
1236 $nav_urls['log'] = false;
1237 $nav_urls['blockip'] = false;
1239 $nav_urls['emailuser'] = false;
1240 if( $this->showEmailUser( $id ) ) {
1241 $nav_urls['emailuser'] = array(
1242 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1245 wfProfileOut( __METHOD__
);
1250 * Generate strings used for xml 'id' names
1254 function getNameSpaceKey() {
1255 return $this->mTitle
->getNamespaceKey();
1260 * FIXME: why is this duplicated in/from OutputPage::getHeadScripts()??
1262 function setupUserJs( $allowUserJs ) {
1263 global $wgRequest, $wgJsMimeType;
1264 wfProfileIn( __METHOD__
);
1266 $action = $wgRequest->getVal( 'action', 'view' );
1268 if( $allowUserJs && $this->loggedin
) {
1269 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1270 # XXX: additional security check/prompt?
1271 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1273 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1276 wfProfileOut( __METHOD__
);
1280 * Code for extensions to hook into to provide per-page CSS, see
1281 * extensions/PageCSS/PageCSS.php for an implementation of this.
1285 function setupPageCss() {
1286 wfProfileIn( __METHOD__
);
1288 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1289 wfProfileOut( __METHOD__
);
1293 public function commonPrintStylesheet() {
1299 * Generic wrapper for template functions, with interface
1300 * compatible with what we use of PHPTAL 0.7.
1303 abstract class QuickTemplate
{
1307 public function QuickTemplate() {
1308 $this->data
= array();
1309 $this->translator
= new MediaWiki_I18N();
1313 * Sets the value $value to $name
1317 public function set( $name, $value ) {
1318 $this->data
[$name] = $value;
1325 public function setRef( $name, &$value ) {
1326 $this->data
[$name] =& $value;
1332 public function setTranslator( &$t ) {
1333 $this->translator
= &$t;
1337 * Main function, used by classes that subclass QuickTemplate
1338 * to show the actual HTML output
1340 abstract public function execute();
1345 function text( $str ) {
1346 echo htmlspecialchars( $this->data
[$str] );
1352 function jstext( $str ) {
1353 echo Xml
::escapeJsString( $this->data
[$str] );
1359 function html( $str ) {
1360 echo $this->data
[$str];
1366 function msg( $str ) {
1367 echo htmlspecialchars( $this->translator
->translate( $str ) );
1373 function msgHtml( $str ) {
1374 echo $this->translator
->translate( $str );
1378 * An ugly, ugly hack.
1381 function msgWiki( $str ) {
1382 global $wgParser, $wgOut;
1384 $text = $this->translator
->translate( $str );
1385 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1386 $wgOut->parserOptions(), true );
1387 echo $parserOutput->getText();
1393 function haveData( $str ) {
1394 return isset( $this->data
[$str] );
1400 function haveMsg( $str ) {
1401 $msg = $this->translator
->translate( $str );
1402 return ( $msg != '-' ) && ( $msg != '' ); # ????
1406 * Get the Skin object related to this object
1408 * @return Skin object
1410 public function getSkin() {
1411 return $this->data
['skin'];
1416 * New base template for a skin's template extended from QuickTemplate
1417 * this class features helper methods that provide common ways of interacting
1418 * with the data stored in the QuickTemplate
1420 abstract class BaseTemplate
extends QuickTemplate
{
1423 * Create an array of common toolbox items from the data in the quicktemplate
1424 * stored by SkinTemplate.
1425 * The resulting array is built acording to a format intended to be passed
1426 * through makeListItem to generate the html.
1428 function getToolbox() {
1429 wfProfileIn( __METHOD__
);
1432 if ( $this->data
['notspecialpage'] ) {
1433 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1434 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1435 if ( $this->data
['nav_urls']['recentchangeslinked'] ) {
1436 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1437 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1438 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1441 if( isset( $this->data
['nav_urls']['trackbacklink'] ) && $this->data
['nav_urls']['trackbacklink'] ) {
1442 $toolbox['trackbacklink'] = $this->data
['nav_urls']['trackbacklink'];
1443 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1445 if ( $this->data
['feeds'] ) {
1446 $toolbox['feeds']['id'] = 'feedlinks';
1447 $toolbox['feeds']['links'] = array();
1448 foreach ( $this->data
['feeds'] as $key => $feed ) {
1449 $toolbox['feeds']['links'][$key] = $feed;
1450 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1451 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1452 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1453 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1456 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1457 if ( $this->data
['nav_urls'][$special] ) {
1458 $toolbox[$special] = $this->data
['nav_urls'][$special];
1459 $toolbox[$special]['id'] = "t-$special";
1462 if ( !empty( $this->data
['nav_urls']['print']['href'] ) ) {
1463 $toolbox['print'] = $this->data
['nav_urls']['print'];
1464 $toolbox['print']['rel'] = 'alternate';
1465 $toolbox['print']['msg'] = 'printableversion';
1467 if ( !empty( $this->data
['nav_urls']['permalink']['href'] ) ) {
1468 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1469 $toolbox['permalink']['id'] = 't-permalink';
1470 } elseif ( $this->data
['nav_urls']['permalink']['href'] === '' ) {
1471 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1472 unset( $toolbox['permalink']['href'] );
1473 $toolbox['ispermalink']['tooltiponly'] = true;
1474 $toolbox['ispermalink']['id'] = 't-ispermalink';
1475 $toolbox['ispermalink']['msg'] = 'permalink';
1477 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1478 wfProfileOut( __METHOD__
);
1483 * Create an array of personal tools items from the data in the quicktemplate
1484 * stored by SkinTemplate.
1485 * The resulting array is built acording to a format intended to be passed
1486 * through makeListItem to generate the html.
1487 * This is in reality the same list as already stored in personal_urls
1488 * however it is reformatted so that you can just pass the individual items
1489 * to makeListItem instead of hardcoding the element creation boilerplate.
1491 function getPersonalTools() {
1492 $personal_tools = array();
1493 foreach( $this->data
['personal_urls'] as $key => $ptool ) {
1494 # The class on a personal_urls item is meant to go on the <a> instead
1495 # of the <li> so we have to use a single item "links" array instead
1496 # of using most of the personal_url's keys directly
1497 $personal_tools[$key] = array();
1498 $personal_tools[$key]["links"][] = array();
1499 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1500 if ( isset($ptool["active"]) ) {
1501 $personal_tools[$key]["active"] = $ptool["active"];
1503 foreach ( array("href", "class", "text") as $k ) {
1504 if ( isset($ptool[$k]) )
1505 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1508 return $personal_tools;
1512 * Makes a link, usually used by makeListItem to generate a link for an item
1513 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1515 * $key is a string, usually a key from the list you are generating this link from
1516 * $item is an array containing some of a specific set of keys.
1517 * The text of the link will be generated either from the contents of the "text"
1518 * key in the $item array, if a "msg" key is present a message by that name will
1519 * be used, and if neither of those are set the $key will be used as a message name.
1520 * If a "href" key is not present makeLink will just output htmlescaped text.
1521 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1522 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1523 * is present it will be used to generate a tooltip and accesskey for the link.
1524 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1526 function makeLink( $key, $item ) {
1527 if ( isset( $item['text'] ) ) {
1528 $text = $item['text'];
1530 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1533 if ( !isset( $item['href'] ) ) {
1534 return htmlspecialchars( $text );
1538 foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
1539 if ( isset( $item[$attr] ) ) {
1540 $attrs[$attr] = $item[$attr];
1544 if ( isset( $item['id'] ) ) {
1545 $item['single-id'] = $item['id'];
1547 if ( isset( $item['single-id'] ) ) {
1548 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1549 $attrs['title'] = $this->skin
->titleAttrib( $item['single-id'] );
1550 if ( $attrs['title'] === false ) {
1551 unset( $attrs['title'] );
1554 $attrs = array_merge(
1556 $this->skin
->tooltipAndAccesskeyAttribs( $item['single-id'] )
1561 return Html
::element( 'a', $attrs, $text );
1565 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1566 * $key is a string, usually a key from the list you are generating this link from
1567 * $item is an array of list item data containing some of a specific set of keys.
1568 * The "id" and "class" keys will be used as attributes for the list item,
1569 * if "active" contains a value of true a "active" class will also be appended to class.
1570 * If you want something other than a <li> you can pass a tag name such as
1571 * "tag" => "span" in the $options array to change the tag used.
1572 * link/content data for the list item may come in one of two forms
1573 * A "links" key may be used, in which case it should contain an array with
1574 * a list of links to include inside the list item, see makeLink for the format
1575 * of individual links array items.
1576 * Otherwise the relevant keys from the list item $item array will be passed
1577 * to makeLink instead. Note however that "id" and "class" are used by the
1578 * list item directly so they will not be passed to makeLink
1579 * (however the link will still support a tooltip and accesskey from it)
1580 * If you need an id or class on a single link you should include a "links"
1581 * array with just one link item inside of it.
1583 function makeListItem( $key, $item, $options = array() ) {
1584 if ( isset( $item['links'] ) ) {
1586 foreach ( $item['links'] as $linkKey => $link ) {
1587 $html .= $this->makeLink( $linkKey, $link );
1591 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
1592 if ( isset( $item[$k] ) ) {
1593 $link[$k] = $item[$k];
1596 if ( isset( $item['id'] ) ) {
1597 // The id goes on the <li> not on the <a> for single links
1598 // but makeSidebarLink still needs to know what id to use when
1599 // generating tooltips and accesskeys.
1600 $link['single-id'] = $item['id'];
1602 $html = $this->makeLink( $key, $link );
1606 foreach ( array( 'id', 'class' ) as $attr ) {
1607 if ( isset( $item[$attr] ) ) {
1608 $attrs[$attr] = $item[$attr];
1611 if ( isset( $item['active'] ) && $item['active'] ) {
1612 if ( !isset( $attrs['class'] ) ) {
1613 $attrs['class'] = '';
1615 $attrs['class'] .= ' active';
1616 $attrs['class'] = trim( $attrs['class'] );
1618 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1621 function makeSearchInput( $attrs = array() ) {
1625 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1627 $realAttrs = array_merge( $realAttrs, $this->skin
->tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1628 return Html
::element( 'input', $realAttrs );
1631 function makeSearchButton( $mode, $attrs = array() ) {
1638 'value' => $this->translator
->translate( $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1640 $realAttrs = array_merge(
1642 $this->skin
->tooltipAndAccesskeyAttribs( "search-$mode" ),
1645 return Html
::element( 'input', $realAttrs );
1647 $buttonAttrs = array(
1651 $buttonAttrs = array_merge(
1653 $this->skin
->tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1656 unset( $buttonAttrs['src'] );
1657 unset( $buttonAttrs['alt'] );
1659 'src' => $attrs['src'],
1660 'alt' => isset( $attrs['alt'] ) ?
$attrs['alt'] : $this->translator
->translate( 'searchbutton' ),
1662 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1664 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1669 * Returns an array of footerlinks trimmed down to only those footer links that
1671 * If you pass "flat" as an option then the returned array will be a flat array
1672 * of footer icons instead of a key/value array of footerlinks arrays broken
1673 * up into categories.
1675 function getFooterLinks( $option = null ) {
1676 $footerlinks = $this->data
['footerlinks'];
1678 // Reduce footer links down to only those which are being used
1679 $validFooterLinks = array();
1680 foreach( $footerlinks as $category => $links ) {
1681 $validFooterLinks[$category] = array();
1682 foreach( $links as $link ) {
1683 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1684 $validFooterLinks[$category][] = $link;
1687 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1688 unset( $validFooterLinks[$category] );
1692 if ( $option == 'flat' ) {
1693 // fold footerlinks into a single array using a bit of trickery
1694 $validFooterLinks = call_user_func_array(
1696 array_values( $validFooterLinks )
1700 return $validFooterLinks;
1704 * Returns an array of footer icons filtered down by options relevant to how
1705 * the skin wishes to display them.
1706 * If you pass "icononly" as the option all footer icons which do not have an
1707 * image icon set will be filtered out.
1708 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1709 * in the list of footer icons. This is mostly useful for skins which only
1710 * display the text from footericons instead of the images and don't want a
1711 * duplicate copyright statement because footerlinks already rendered one.
1713 function getFooterIcons( $option = null ) {
1714 // Generate additional footer icons
1715 $footericons = $this->data
['footericons'];
1717 if ( $option == 'icononly' ) {
1718 // Unset any icons which don't have an image
1719 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1720 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1721 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1722 unset( $footerIconsBlock[$footerIconKey] );
1726 // Redo removal of any empty blocks
1727 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1728 if ( count( $footerIconsBlock ) <= 0 ) {
1729 unset( $footericons[$footerIconsKey] );
1732 } elseif ( $option == 'nocopyright' ) {
1733 unset( $footericons['copyright']['copyright'] );
1734 if ( count( $footericons['copyright'] ) <= 0 ) {
1735 unset( $footericons['copyright'] );
1739 return $footericons;
1743 * Output the basic end-page trail including bottomscripts, reporttime, and
1744 * debug stuff. This should be called right before outputting the closing
1745 * body and html tags.
1747 function printTrail() { ?
>
1748 <?php
$this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?
>
1749 <?php
$this->html('reporttime') ?
>
1750 <?php
if ( $this->data
['debug'] ): ?
>
1752 <?php
$this->text( 'debug' ); ?
>