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
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return QuickTemplate
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, $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;
145 wfProfileIn( __METHOD__
);
146 Profiler
::instance()->setTemplated( true );
148 $oldid = $wgRequest->getVal( 'oldid' );
149 $diff = $wgRequest->getVal( 'diff' );
150 $action = $wgRequest->getVal( 'action', 'view' );
152 wfProfileIn( __METHOD__
. '-init' );
153 $this->initPage( $out );
155 $tpl = $this->setupTemplate( $this->template
, 'skins' );
156 wfProfileOut( __METHOD__
. '-init' );
158 wfProfileIn( __METHOD__
. '-stuff' );
159 $this->thispage
= $this->getTitle()->getPrefixedDBkey();
160 $this->thisurl
= $this->getTitle()->getPrefixedURL();
162 if ( !$wgRequest->wasPosted() ) {
163 $query = $wgRequest->getValues();
164 unset( $query['title'] );
165 unset( $query['returnto'] );
166 unset( $query['returntoquery'] );
168 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
169 $this->loggedin
= $wgUser->isLoggedIn();
170 $this->iscontent
= ( $this->getTitle()->getNamespace() != NS_SPECIAL
);
171 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
172 $this->username
= $wgUser->getName();
174 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
175 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
177 # This won't be used in the standard skins, but we define it to preserve the interface
178 # To save time, we check for existence
179 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
182 $this->titletxt
= $this->getTitle()->getPrefixedText();
183 wfProfileOut( __METHOD__
. '-stuff' );
185 wfProfileIn( __METHOD__
. '-stuff-head' );
186 if ( $this->useHeadElement
) {
187 $pagecss = $this->setupPageCss();
189 $out->addInlineStyle( $pagecss );
191 $this->setupUserCss( $out );
193 $tpl->set( 'pagecss', $this->setupPageCss() );
194 $tpl->set( 'usercss', false );
196 $this->userjs
= $this->userjsprev
= false;
197 # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we
198 # get rid of it? For that matter, why is any of this here at all?
199 $this->setupUserJs( $out->isUserJsAllowed() );
200 $tpl->setRef( 'userjs', $this->userjs
);
201 $tpl->setRef( 'userjsprev', $this->userjsprev
);
204 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
205 $tpl->set( 'jsvarurl',
207 "action=raw$jsCache&gen=js&useskin=" .
208 urlencode( $this->getSkinName() ) ) );
210 $tpl->set( 'jsvarurl', false );
213 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
214 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
215 $tpl->set( 'html5version', $wgHtml5Version );
216 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
217 $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
219 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
220 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
222 $tpl->set( 'trackbackhtml', null );
225 wfProfileOut( __METHOD__
. '-stuff-head' );
227 wfProfileIn( __METHOD__
. '-stuff2' );
228 $tpl->set( 'title', $out->getPageTitle() );
229 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
230 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
231 $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
232 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
234 $nsname = MWNamespace
::exists( $this->getTitle()->getNamespace() ) ?
235 MWNamespace
::getCanonicalName( $this->getTitle()->getNamespace() ) :
236 $this->getTitle()->getNsText();
238 $tpl->set( 'nscanonical', $nsname );
239 $tpl->set( 'nsnumber', $this->getTitle()->getNamespace() );
240 $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
241 $tpl->set( 'titletext', $this->getTitle()->getText() );
242 $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
243 $tpl->set( 'currevisionid', $this->getTitle()->getLatestRevID() );
245 $tpl->set( 'isarticle', $out->isArticle() );
247 $tpl->setRef( 'thispage', $this->thispage
);
248 $subpagestr = $this->subPageSubtitle();
250 'subtitle', !empty( $subpagestr ) ?
251 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
254 $undelete = $this->getUndeleteLink();
256 'undelete', !empty( $undelete ) ?
257 '<span class="subpages">' . $undelete . '</span>' :
261 $tpl->set( 'catlinks', $this->getCategories() );
262 if( $out->isSyndicated() ) {
264 foreach( $out->getSyndicationLinks() as $format => $link ) {
265 $feeds[$format] = array(
266 'text' => wfMsg( "feed-$format" ),
270 $tpl->setRef( 'feeds', $feeds );
272 $tpl->set( 'feeds', false );
275 $tpl->setRef( 'mimetype', $wgMimeType );
276 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
277 $tpl->set( 'charset', 'UTF-8' );
278 $tpl->setRef( 'wgScript', $wgScript );
279 $tpl->setRef( 'skinname', $this->skinname
);
280 $tpl->set( 'skinclass', get_class( $this ) );
281 $tpl->setRef( 'stylename', $this->stylename
);
282 $tpl->set( 'printable', $out->isPrintable() );
283 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
284 $tpl->setRef( 'loggedin', $this->loggedin
);
285 $tpl->set( 'notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL
);
286 /* XXX currently unused, might get useful later
287 $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) );
288 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
289 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
290 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
291 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
293 $tpl->set( 'searchaction', $this->escapeSearchLink() );
294 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
295 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
296 $tpl->setRef( 'stylepath', $wgStylePath );
297 $tpl->setRef( 'articlepath', $wgArticlePath );
298 $tpl->setRef( 'scriptpath', $wgScriptPath );
299 $tpl->setRef( 'serverurl', $wgServer );
300 $tpl->setRef( 'logopath', $wgLogo );
303 $tpl->set( 'lang', $lang->getCode() );
304 $tpl->set( 'dir', $lang->getDir() );
305 $tpl->set( 'rtl', $lang->isRTL() );
307 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
308 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
309 $tpl->set( 'username', $wgUser->isAnon() ?
null : $this->username
);
310 $tpl->setRef( 'userpage', $this->userpage
);
311 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
312 $tpl->set( 'userlang', $wgLang->getCode() );
314 // Users can have their language set differently than the
315 // content of the wiki. For these users, tell the web browser
316 // that interface elements are in a different language.
317 $tpl->set( 'userlangattributes', '' );
318 $tpl->set( 'specialpageattributes', '' );
320 $lang = $wgLang->getCode();
321 $dir = $wgLang->getDir();
322 if ( $lang !== $wgContLang->getCode() ||
$dir !== $wgContLang->getDir() ) {
323 $attrs = " lang='$lang' dir='$dir'";
325 $tpl->set( 'userlangattributes', $attrs );
327 // The content of SpecialPages should be presented in the
328 // user's language. Content of regular pages should not be touched.
329 if( $this->getTitle()->isSpecialPage() ) {
330 $tpl->set( 'specialpageattributes', $attrs );
334 $newtalks = $this->getNewtalks( $out );
336 wfProfileOut( __METHOD__
. '-stuff2' );
338 wfProfileIn( __METHOD__
. '-stuff3' );
339 $tpl->setRef( 'newtalk', $newtalks );
340 $tpl->setRef( 'skin', $this );
341 $tpl->set( 'logo', $this->logoText() );
342 if ( $out->isArticle() && ( !isset( $oldid ) ||
isset( $diff ) ) &&
343 $this->getTitle()->exists() )
345 $article = new Article( $this->getTitle(), 0 );
346 if ( !$wgDisableCounters ) {
347 $viewcount = $wgLang->formatNum( $article->getCount() );
349 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
351 $tpl->set( 'viewcount', false );
354 $tpl->set( 'viewcount', false );
357 if( $wgPageShowWatchingUsers ) {
358 $dbr = wfGetDB( DB_SLAVE
);
359 $res = $dbr->select( 'watchlist',
360 array( 'COUNT(*) AS n' ),
361 array( 'wl_title' => $dbr->strencode( $this->getTitle()->getDBkey() ), 'wl_namespace' => $this->getTitle()->getNamespace() ),
364 $x = $dbr->fetchObject( $res );
365 $numberofwatchingusers = $x->n
;
366 if( $numberofwatchingusers > 0 ) {
367 $tpl->set( 'numberofwatchingusers',
368 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
369 $wgLang->formatNum( $numberofwatchingusers ) )
372 $tpl->set( 'numberofwatchingusers', false );
375 $tpl->set( 'numberofwatchingusers', false );
378 $tpl->set( 'copyright', $this->getCopyright() );
380 $this->credits
= false;
382 if( $wgMaxCredits != 0 ){
383 $this->credits
= Action
::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax );
385 $tpl->set( 'lastmod', $this->lastModified( $article ) );
388 $tpl->setRef( 'credits', $this->credits
);
390 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
391 $tpl->set( 'copyright', $this->getCopyright() );
392 $tpl->set( 'viewcount', false );
393 $tpl->set( 'lastmod', false );
394 $tpl->set( 'credits', false );
395 $tpl->set( 'numberofwatchingusers', false );
397 $tpl->set( 'copyright', false );
398 $tpl->set( 'viewcount', false );
399 $tpl->set( 'lastmod', false );
400 $tpl->set( 'credits', false );
401 $tpl->set( 'numberofwatchingusers', false );
403 wfProfileOut( __METHOD__
. '-stuff3' );
405 wfProfileIn( __METHOD__
. '-stuff4' );
406 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
407 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
408 $tpl->set( 'disclaimer', $this->disclaimerLink() );
409 $tpl->set( 'privacy', $this->privacyLink() );
410 $tpl->set( 'about', $this->aboutLink() );
412 $tpl->set( 'footerlinks', array(
416 'numberofwatchingusers',
427 global $wgFooterIcons;
428 $tpl->set( 'footericons', $wgFooterIcons );
429 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
430 if ( count( $footerIconsBlock ) > 0 ) {
431 foreach ( $footerIconsBlock as &$footerIcon ) {
432 if ( isset( $footerIcon['src'] ) ) {
433 if ( !isset( $footerIcon['width'] ) ) {
434 $footerIcon['width'] = 88;
436 if ( !isset( $footerIcon['height'] ) ) {
437 $footerIcon['height'] = 31;
442 unset( $tpl->data
['footericons'][$footerIconsKey] );
446 if ( $wgDebugComments ) {
447 $tpl->setRef( 'debug', $out->mDebugtext
);
449 $tpl->set( 'debug', '' );
452 $tpl->set( 'reporttime', wfReportTime() );
453 $tpl->set( 'sitenotice', $this->getSiteNotice() );
454 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
455 $tpl->set( 'printfooter', $this->printSource() );
457 global $wgBetterDirectionality;
458 if ( $wgBetterDirectionality ) {
459 // not for special pages or file pages AND only when viewing AND if the page exists
460 // (or is in MW namespace, because that has default content)
461 if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
462 in_array( $action, array( 'view', 'render', 'print' ) ) &&
463 ( $this->getTitle()->exists() ||
$this->getTitle()->getNamespace() == NS_MEDIAWIKI
) ) {
464 $pageLang = $this->getTitle()->getPageLanguage();
465 $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
466 'class' => 'mw-content-'.$pageLang->getDir() );
467 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
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 $tpl->set( 'debughtml', $this->generateDebugHTML() );
519 // original version by hansm
520 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
521 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
524 // allow extensions adding stuff after the page content.
525 // See Skin::afterContentHook() for further documentation.
526 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
527 wfProfileOut( __METHOD__
. '-stuff5' );
530 wfProfileIn( __METHOD__
. '-execute' );
531 $res = $tpl->execute();
532 wfProfileOut( __METHOD__
. '-execute' );
534 // result may be an error
535 $this->printOrError( $res );
536 wfProfileOut( __METHOD__
);
540 * Output the string, or print error message if it's
541 * an error object of the appropriate type.
542 * For the base class, assume strings all around.
547 function printOrError( $str ) {
552 * Output a boolean indiciating if buildPersonalUrls should output separate
553 * login and create account links or output a combined link
554 * By default we simply return a global config setting that affects most skins
555 * This is setup as a method so that like with $wgLogo and getLogo() a skin
556 * can override this setting and always output one or the other if it has
557 * a reason it can't output one of the two modes.
559 function useCombinedLoginLink() {
560 global $wgUseCombinedLoginLink;
561 return $wgUseCombinedLoginLink;
565 * build array of urls for personal toolbar
568 protected function buildPersonalUrls( OutputPage
$out ) {
571 $title = $out->getTitle();
572 $pageurl = $title->getLocalURL();
573 wfProfileIn( __METHOD__
);
575 /* set up the default links for the personal toolbar */
576 $personal_urls = array();
578 // Get the returnto and returntoquery parameters from the query string
579 // or fall back on $this->thisurl or $this->thisquery
580 // We can't use getVal()'s default value feature here because
581 // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
582 // are already escaped.
583 $page = $wgRequest->getVal( 'returnto' );
584 if ( !is_null( $page ) ) {
585 $page = wfUrlencode( $page );
587 $page = $this->thisurl
;
589 $query = $wgRequest->getVal( 'returntoquery' );
590 if ( !is_null( $query ) ) {
591 $query = wfUrlencode( $query );
593 $query = $this->thisquery
;
595 $returnto = "returnto=$page";
597 $returnto .= "&returntoquery=$query";
599 if( $this->loggedin
) {
600 $personal_urls['userpage'] = array(
601 'text' => $this->username
,
602 'href' => &$this->userpageUrlDetails
['href'],
603 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
604 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
606 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
607 $personal_urls['mytalk'] = array(
608 'text' => wfMsg( 'mytalk' ),
609 'href' => &$usertalkUrlDetails['href'],
610 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
611 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
613 $href = self
::makeSpecialUrl( 'Preferences' );
614 $personal_urls['preferences'] = array(
615 'text' => wfMsg( 'mypreferences' ),
617 'active' => ( $href == $pageurl )
619 $href = self
::makeSpecialUrl( 'Watchlist' );
620 $personal_urls['watchlist'] = array(
621 'text' => wfMsg( 'mywatchlist' ),
623 'active' => ( $href == $pageurl )
626 # We need to do an explicit check for Special:Contributions, as we
627 # have to match both the title, and the target (which could come
628 # from request values or be specified in "sub page" form. The plot
629 # thickens, because $wgTitle is altered for special pages, so doesn't
630 # contain the original alias-with-subpage.
631 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
632 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
633 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
634 $active = $spName == 'Contributions'
635 && ( ( $spPar && $spPar == $this->username
)
636 ||
$wgRequest->getText( 'target' ) == $this->username
);
641 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
642 $personal_urls['mycontris'] = array(
643 'text' => wfMsg( 'mycontris' ),
647 $personal_urls['logout'] = array(
648 'text' => wfMsg( 'userlogout' ),
649 'href' => self
::makeSpecialUrl( 'Userlogout',
650 // userlogout link must always contain an & character, otherwise we might not be able
651 // to detect a buggy precaching proxy (bug 17790)
652 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
658 $useCombinedLoginLink = $this->useCombinedLoginLink();
659 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
660 ?
'nav-login-createaccount'
662 $is_signup = $wgRequest->getText('type') == "signup";
664 # anonlogin & login are the same
666 'text' => wfMsg( $loginlink ),
667 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
668 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" ||
!$is_signup )
670 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
671 $createaccount_url = array(
672 'text' => wfMsg( 'createaccount' ),
673 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
674 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
677 global $wgServer, $wgSecureLogin;
678 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
679 $title = SpecialPage
::getTitleFor( 'Userlogin' );
680 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
681 $login_url['href'] = $https_url;
682 # @todo FIXME: Class depends on skin
683 $login_url['class'] = 'link-https';
684 if ( isset($createaccount_url) ) {
685 $https_url = preg_replace( '/^http:/', 'https:',
686 $title->getFullURL("type=signup") );
687 $createaccount_url['href'] = $https_url;
688 # @todo FIXME: Class depends on skin
689 $createaccount_url['class'] = 'link-https';
694 if( $this->showIPinHeader() ) {
695 $href = &$this->userpageUrlDetails
['href'];
696 $personal_urls['anonuserpage'] = array(
697 'text' => $this->username
,
699 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
700 'active' => ( $pageurl == $href )
702 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
703 $href = &$usertalkUrlDetails['href'];
704 $personal_urls['anontalk'] = array(
705 'text' => wfMsg( 'anontalk' ),
707 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
708 'active' => ( $pageurl == $href )
710 $personal_urls['anonlogin'] = $login_url;
712 $personal_urls['login'] = $login_url;
714 if ( isset($createaccount_url) ) {
715 $personal_urls['createaccount'] = $createaccount_url;
719 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
720 wfProfileOut( __METHOD__
);
721 return $personal_urls;
726 * @param $title Title
727 * @param $message String message key
728 * @param $selected Bool
729 * @param $query String
730 * @param $checkEdit Bool
733 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
736 $classes[] = 'selected';
738 if( $checkEdit && !$title->isKnown() ) {
740 $query = 'action=edit&redlink=1';
743 // wfMessageFallback will nicely accept $message as an array of fallbacks
744 // or just a single key
745 $msg = wfMessageFallback( $message );
746 if ( is_array($message) ) {
747 // for hook compatibility just keep the last message name
748 $message = end($message);
750 if ( $msg->exists() ) {
751 $text = $msg->text();
754 $text = $wgContLang->getFormattedNsText(
755 MWNamespace
::getSubject( $title->getNamespace() ) );
759 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
760 $title, $message, $selected, $checkEdit,
761 &$classes, &$query, &$text, &$result ) ) ) {
766 'class' => implode( ' ', $classes ),
768 'href' => $title->getLocalUrl( $query ),
772 function makeTalkUrlDetails( $name, $urlaction = '' ) {
773 $title = Title
::newFromText( $name );
774 if( !is_object( $title ) ) {
775 throw new MWException( __METHOD__
. " given invalid pagename $name" );
777 $title = $title->getTalkPage();
778 self
::checkTitle( $title, $name );
780 'href' => $title->getLocalURL( $urlaction ),
781 'exists' => $title->getArticleID() != 0,
785 function makeArticleUrlDetails( $name, $urlaction = '' ) {
786 $title = Title
::newFromText( $name );
787 $title= $title->getSubjectPage();
788 self
::checkTitle( $title, $name );
790 'href' => $title->getLocalURL( $urlaction ),
791 'exists' => $title->getArticleID() != 0,
796 * a structured array of links usually used for the tabs in a skin
798 * There are 4 standard sections
799 * namespaces: Used for namespace tabs like special, page, and talk namespaces
800 * views: Used for primary page views like read, edit, history
801 * actions: Used for most extra page actions like deletion, protection, etc...
802 * variants: Used to list the language variants for the page
804 * Each section's value is a key/value array of links for that section.
805 * The links themseves have these common keys:
806 * - class: The css classes to apply to the tab
807 * - text: The text to display on the tab
808 * - href: The href for the tab to point to
809 * - rel: An optional rel= for the tab's link
810 * - redundant: If true the tab will be dropped in skins using content_actions
811 * this is useful for tabs like "Read" which only have meaning in skins that
812 * take special meaning from the grouped structure of content_navigation
814 * Views also have an extra key which can be used:
815 * - primary: If this is not true skins like vector may try to hide the tab
816 * when the user has limited space in their browser window
818 * content_navigation using code also expects these ids to be present on the
819 * links, however these are usually automatically generated by SkinTemplate
820 * itself and are not necessary when using a hook. The only things these may
821 * matter to are people modifying content_navigation after it's initial creation:
822 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
823 * - tooltiponly: This is set to true for some tabs in cases where the system
824 * believes that the accesskey should not be added to the tab.
828 protected function buildContentNavigationUrls( OutputPage
$out ) {
829 global $wgContLang, $wgLang, $wgUser, $wgRequest;
830 global $wgDisableLangConversion;
832 wfProfileIn( __METHOD__
);
834 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
835 $onPage = $title->equals($this->getTitle());
837 $content_navigation = array(
838 'namespaces' => array(),
840 'actions' => array(),
841 'variants' => array()
845 $action = $wgRequest->getVal( 'action', 'view' );
846 $section = $wgRequest->getVal( 'section' );
848 $userCanRead = $title->userCanRead();
849 $skname = $this->skinname
;
851 $preventActiveTabs = false;
852 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
854 // Checks if page is some kind of content
855 if( $title->getNamespace() != NS_SPECIAL
) {
856 // Gets page objects for the related namespaces
857 $subjectPage = $title->getSubjectPage();
858 $talkPage = $title->getTalkPage();
860 // Determines if this is a talk page
861 $isTalk = $title->isTalkPage();
863 // Generates XML IDs from namespace names
864 $subjectId = $title->getNamespaceKey( '' );
866 if ( $subjectId == 'main' ) {
869 $talkId = "{$subjectId}_talk";
872 // Adds namespace links
873 $subjectMsg = array( "nstab-$subjectId" );
874 if ( $subjectPage->isMainPage() ) {
875 array_unshift($subjectMsg, 'mainpage-nstab');
877 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
878 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
880 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
881 $content_navigation['namespaces'][$talkId] = $this->tabAction(
882 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
884 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
886 // Adds view view link
887 if ( $title->exists() && $userCanRead ) {
888 $content_navigation['views']['view'] = $this->tabAction(
889 $isTalk ?
$talkPage : $subjectPage,
890 array( "$skname-view-view", 'view' ),
891 ( $onPage && ($action == 'view' ||
$action == 'purge' ) ), '', true
893 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
896 wfProfileIn( __METHOD__
. '-edit' );
898 // Checks if user can...
900 // read and edit the current page
901 $userCanRead && $title->quickUserCan( 'edit' ) &&
905 // or they can create one here
906 $title->quickUserCan( 'create' )
909 // Builds CSS class for talk page links
910 $isTalkClass = $isTalk ?
' istalk' : '';
912 // Determines if we're in edit mode
915 ( $action == 'edit' ||
$action == 'submit' ) &&
916 ( $section != 'new' )
918 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
920 $content_navigation['views']['edit'] = array(
921 'class' => ( $selected ?
'selected' : '' ) . $isTalkClass,
922 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
923 'href' => $title->getLocalURL( $this->editUrlOptions() ),
924 'primary' => true, // don't collapse this in vector
926 // Checks if this is a current rev of talk page and we should show a new
928 if ( ( $isTalk && $this->isRevisionCurrent() ) ||
( $out->showNewSectionLink() ) ) {
929 // Checks if we should ever show a new section link
930 if ( !$out->forceHideNewSectionLink() ) {
931 // Adds new section link
932 //$content_navigation['actions']['addsection']
933 $content_navigation['views']['addsection'] = array(
934 'class' => $section == 'new' ?
'selected' : false,
935 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
936 'href' => $title->getLocalURL( 'action=edit§ion=new' )
940 // Checks if the page has some kind of viewable content
941 } elseif ( $title->hasSourceText() && $userCanRead ) {
942 // Adds view source view link
943 $content_navigation['views']['viewsource'] = array(
944 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
945 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
946 'href' => $title->getLocalURL( $this->editUrlOptions() ),
947 'primary' => true, // don't collapse this in vector
950 wfProfileOut( __METHOD__
. '-edit' );
952 wfProfileIn( __METHOD__
. '-live' );
954 // Checks if the page exists
955 if ( $title->exists() && $userCanRead ) {
956 // Adds history view link
957 $content_navigation['views']['history'] = array(
958 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
959 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
960 'href' => $title->getLocalURL( 'action=history' ),
964 if( $wgUser->isAllowed( 'delete' ) ) {
965 $content_navigation['actions']['delete'] = array(
966 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
967 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
968 'href' => $title->getLocalURL( 'action=delete' )
971 if ( $title->quickUserCan( 'move' ) ) {
972 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
973 $content_navigation['actions']['move'] = array(
974 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
975 'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
976 'href' => $moveTitle->getLocalURL()
980 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
981 $mode = !$title->isProtected() ?
'protect' : 'unprotect';
982 $content_navigation['actions'][$mode] = array(
983 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
984 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
985 'href' => $title->getLocalURL( "action=$mode" )
989 // article doesn't exist or is deleted
990 if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
991 $n = $title->isDeleted();
993 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
994 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
995 $msgKey = $wgUser->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
996 $content_navigation['actions']['undelete'] = array(
997 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
998 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
999 ->params( $wgLang->formatNum( $n ) )->text(),
1000 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1005 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
1006 $mode = !$title->getRestrictions( 'create' ) ?
'protect' : 'unprotect';
1007 $content_navigation['actions'][$mode] = array(
1008 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1009 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
1010 'href' => $title->getLocalURL( "action=$mode" )
1014 wfProfileOut( __METHOD__
. '-live' );
1016 // Checks if the user is logged in
1017 if ( $this->loggedin
) {
1019 * The following actions use messages which, if made particular to
1020 * the any specific skins, would break the Ajax code which makes this
1021 * action happen entirely inline. Skin::makeGlobalVariablesScript
1022 * defines a set of messages in a javascript object - and these
1023 * messages are assumed to be global for all skins. Without making
1024 * a change to that procedure these messages will have to remain as
1025 * the global versions.
1027 $mode = $title->userIsWatching() ?
'unwatch' : 'watch';
1028 $token = WatchAction
::getWatchToken( $title, $wgUser, $mode );
1029 $content_navigation['actions'][$mode] = array(
1030 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1031 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
1032 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1036 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1038 // If it's not content, it's got to be a special page
1039 $content_navigation['namespaces']['special'] = array(
1040 'class' => 'selected',
1041 'text' => wfMsg( 'nstab-special' ),
1042 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
1043 'context' => 'subject'
1046 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1047 array( &$this, &$content_navigation ) );
1050 // Gets list of language variants
1051 $variants = $wgContLang->getVariants();
1052 // Checks that language conversion is enabled and variants exist
1053 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1054 // Gets preferred variant
1055 $preferred = $wgContLang->getPreferredVariant();
1056 // Loops over each variant
1057 foreach( $variants as $code ) {
1058 // Gets variant name from language code
1059 $varname = $wgContLang->getVariantname( $code );
1060 // Checks if the variant is marked as disabled
1061 if( $varname == 'disable' ) {
1062 // Skips this variant
1065 // Appends variant link
1066 $content_navigation['variants'][] = array(
1067 'class' => ( $code == $preferred ) ?
'selected' : false,
1069 'href' => $title->getLocalURL( '', $code )
1074 // Equiv to SkinTemplateContentActions
1075 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1077 // Setup xml ids and tooltip info
1078 foreach ( $content_navigation as $section => &$links ) {
1079 foreach ( $links as $key => &$link ) {
1081 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1082 $xmlID = 'ca-nstab-' . $xmlID;
1083 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1085 } elseif ( $section == "variants" ) {
1086 $xmlID = 'ca-varlang-' . $xmlID;
1088 $xmlID = 'ca-' . $xmlID;
1090 $link['id'] = $xmlID;
1094 # We don't want to give the watch tab an accesskey if the
1095 # page is being edited, because that conflicts with the
1096 # accesskey on the watch checkbox. We also don't want to
1097 # give the edit tab an accesskey, because that's fairly su-
1098 # perfluous and conflicts with an accesskey (Ctrl-E) often
1099 # used for editing in Safari.
1100 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1101 if ( isset($content_navigation['views']['edit']) ) {
1102 $content_navigation['views']['edit']['tooltiponly'] = true;
1104 if ( isset($content_navigation['actions']['watch']) ) {
1105 $content_navigation['actions']['watch']['tooltiponly'] = true;
1107 if ( isset($content_navigation['actions']['unwatch']) ) {
1108 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1112 wfProfileOut( __METHOD__
);
1114 return $content_navigation;
1118 * an array of edit links by default used for the tabs
1122 function buildContentActionUrls( $content_navigation ) {
1124 wfProfileIn( __METHOD__
);
1126 // content_actions has been replaced with content_navigation for backwards
1127 // compatibility and also for skins that just want simple tabs content_actions
1128 // is now built by flattening the content_navigation arrays into one
1130 $content_actions = array();
1132 foreach ( $content_navigation as $links ) {
1134 foreach ( $links as $key => $value ) {
1136 if ( isset($value["redundant"]) && $value["redundant"] ) {
1137 // Redundant tabs are dropped from content_actions
1141 // content_actions used to have ids built using the "ca-$key" pattern
1142 // so the xmlID based id is much closer to the actual $key that we want
1143 // for that reason we'll just strip out the ca- if present and use
1144 // the latter potion of the "id" as the $key
1145 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1146 $key = substr($value["id"], 3);
1149 if ( isset($content_actions[$key]) ) {
1150 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1154 $content_actions[$key] = $value;
1160 wfProfileOut( __METHOD__
);
1162 return $content_actions;
1166 * build array of common navigation links
1170 protected function buildNavUrls( OutputPage
$out ) {
1171 global $wgUseTrackbacks, $wgUser, $wgRequest;
1172 global $wgUploadNavigationUrl;
1174 wfProfileIn( __METHOD__
);
1176 $action = $wgRequest->getVal( 'action', 'view' );
1178 $nav_urls = array();
1179 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1180 if( $wgUploadNavigationUrl ) {
1181 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1182 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $wgUser ) === true ) {
1183 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1185 $nav_urls['upload'] = false;
1187 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1189 // default permalink to being off, will override it as required below.
1190 $nav_urls['permalink'] = false;
1192 // A print stylesheet is attached to all pages, but nobody ever
1193 // figures that out. :) Add a link...
1194 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
1195 if ( !$out->isPrintable() ) {
1196 $nav_urls['print'] = array(
1197 'text' => wfMsg( 'printableversion' ),
1198 'href' => $this->getTitle()->getLocalURL(
1199 $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
1203 // Also add a "permalink" while we're at it
1204 $revid = $this->getRevisionId();
1206 $nav_urls['permalink'] = array(
1207 'text' => wfMsg( 'permalink' ),
1208 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1212 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1213 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1214 array( &$this, &$nav_urls, &$revid, &$revid ) );
1217 if( $this->getTitle()->getNamespace() != NS_SPECIAL
) {
1218 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
1219 $nav_urls['whatlinkshere'] = array(
1220 'href' => $wlhTitle->getLocalUrl()
1222 if( $this->getTitle()->getArticleId() ) {
1223 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
1224 $nav_urls['recentchangeslinked'] = array(
1225 'href' => $rclTitle->getLocalUrl()
1228 $nav_urls['recentchangeslinked'] = false;
1230 if( $wgUseTrackbacks )
1231 $nav_urls['trackbacklink'] = array(
1232 'href' => $out->getTitle()->trackbackURL()
1236 $user = $this->getRelevantUser();
1238 $id = $user->getID();
1239 $ip = $user->isAnon();
1240 $rootUser = $user->getName();
1247 if( $id ||
$ip ) { # both anons and non-anons have contribs list
1248 $nav_urls['contributions'] = array(
1249 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1253 $logPage = SpecialPage
::getTitleFor( 'Log' );
1254 $nav_urls['log'] = array(
1255 'href' => $logPage->getLocalUrl(
1262 $nav_urls['log'] = false;
1265 if ( $wgUser->isAllowed( 'block' ) ) {
1266 $nav_urls['blockip'] = array(
1267 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1270 $nav_urls['blockip'] = false;
1273 $nav_urls['contributions'] = false;
1274 $nav_urls['log'] = false;
1275 $nav_urls['blockip'] = false;
1277 $nav_urls['emailuser'] = false;
1278 if( $this->showEmailUser( $id ) ) {
1279 $nav_urls['emailuser'] = array(
1280 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1283 wfProfileOut( __METHOD__
);
1288 * Generate strings used for xml 'id' names
1292 function getNameSpaceKey() {
1293 return $this->getTitle()->getNamespaceKey();
1298 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1300 function setupUserJs( $allowUserJs ) {
1301 global $wgRequest, $wgJsMimeType;
1302 wfProfileIn( __METHOD__
);
1304 $action = $wgRequest->getVal( 'action', 'view' );
1306 if( $allowUserJs && $this->loggedin
) {
1307 if( $this->getTitle()->isJsSubpage() and $this->userCanPreview( $action ) ) {
1308 # XXX: additional security check/prompt?
1309 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1311 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1314 wfProfileOut( __METHOD__
);
1318 * Code for extensions to hook into to provide per-page CSS, see
1319 * extensions/PageCSS/PageCSS.php for an implementation of this.
1323 function setupPageCss() {
1324 wfProfileIn( __METHOD__
);
1326 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1327 wfProfileOut( __METHOD__
);
1331 public function commonPrintStylesheet() {
1337 * Generic wrapper for template functions, with interface
1338 * compatible with what we use of PHPTAL 0.7.
1341 abstract class QuickTemplate
{
1345 public function QuickTemplate() {
1346 $this->data
= array();
1347 $this->translator
= new MediaWiki_I18N();
1351 * Sets the value $value to $name
1355 public function set( $name, $value ) {
1356 $this->data
[$name] = $value;
1363 public function setRef( $name, &$value ) {
1364 $this->data
[$name] =& $value;
1370 public function setTranslator( &$t ) {
1371 $this->translator
= &$t;
1375 * Main function, used by classes that subclass QuickTemplate
1376 * to show the actual HTML output
1378 abstract public function execute();
1383 function text( $str ) {
1384 echo htmlspecialchars( $this->data
[$str] );
1390 function jstext( $str ) {
1391 echo Xml
::escapeJsString( $this->data
[$str] );
1397 function html( $str ) {
1398 echo $this->data
[$str];
1404 function msg( $str ) {
1405 echo htmlspecialchars( $this->translator
->translate( $str ) );
1411 function msgHtml( $str ) {
1412 echo $this->translator
->translate( $str );
1416 * An ugly, ugly hack.
1419 function msgWiki( $str ) {
1420 global $wgParser, $wgOut;
1422 $text = $this->translator
->translate( $str );
1423 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1424 $wgOut->parserOptions(), true );
1425 echo $parserOutput->getText();
1431 function haveData( $str ) {
1432 return isset( $this->data
[$str] );
1440 function haveMsg( $str ) {
1441 $msg = $this->translator
->translate( $str );
1442 return ( $msg != '-' ) && ( $msg != '' ); # ????
1446 * Get the Skin object related to this object
1448 * @return Skin object
1450 public function getSkin() {
1451 return $this->data
['skin'];
1456 * New base template for a skin's template extended from QuickTemplate
1457 * this class features helper methods that provide common ways of interacting
1458 * with the data stored in the QuickTemplate
1460 abstract class BaseTemplate
extends QuickTemplate
{
1463 * Create an array of common toolbox items from the data in the quicktemplate
1464 * stored by SkinTemplate.
1465 * The resulting array is built acording to a format intended to be passed
1466 * through makeListItem to generate the html.
1468 function getToolbox() {
1469 wfProfileIn( __METHOD__
);
1472 if ( $this->data
['notspecialpage'] ) {
1473 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1474 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1475 if ( $this->data
['nav_urls']['recentchangeslinked'] ) {
1476 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1477 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1478 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1481 if( isset( $this->data
['nav_urls']['trackbacklink'] ) && $this->data
['nav_urls']['trackbacklink'] ) {
1482 $toolbox['trackbacklink'] = $this->data
['nav_urls']['trackbacklink'];
1483 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1485 if ( $this->data
['feeds'] ) {
1486 $toolbox['feeds']['id'] = 'feedlinks';
1487 $toolbox['feeds']['links'] = array();
1488 foreach ( $this->data
['feeds'] as $key => $feed ) {
1489 $toolbox['feeds']['links'][$key] = $feed;
1490 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1491 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1492 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1493 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1496 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1497 if ( $this->data
['nav_urls'][$special] ) {
1498 $toolbox[$special] = $this->data
['nav_urls'][$special];
1499 $toolbox[$special]['id'] = "t-$special";
1502 if ( !empty( $this->data
['nav_urls']['print']['href'] ) ) {
1503 $toolbox['print'] = $this->data
['nav_urls']['print'];
1504 $toolbox['print']['rel'] = 'alternate';
1505 $toolbox['print']['msg'] = 'printableversion';
1507 if( $this->data
['nav_urls']['permalink'] ) {
1508 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1509 if( $toolbox['permalink']['href'] === '' ) {
1510 unset( $toolbox['permalink']['href'] );
1511 $toolbox['ispermalink']['tooltiponly'] = true;
1512 $toolbox['ispermalink']['id'] = 't-ispermalink';
1513 $toolbox['ispermalink']['msg'] = 'permalink';
1515 $toolbox['permalink']['id'] = 't-permalink';
1518 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1519 wfProfileOut( __METHOD__
);
1524 * Create an array of personal tools items from the data in the quicktemplate
1525 * stored by SkinTemplate.
1526 * The resulting array is built acording to a format intended to be passed
1527 * through makeListItem to generate the html.
1528 * This is in reality the same list as already stored in personal_urls
1529 * however it is reformatted so that you can just pass the individual items
1530 * to makeListItem instead of hardcoding the element creation boilerplate.
1532 function getPersonalTools() {
1533 $personal_tools = array();
1534 foreach( $this->data
['personal_urls'] as $key => $ptool ) {
1535 # The class on a personal_urls item is meant to go on the <a> instead
1536 # of the <li> so we have to use a single item "links" array instead
1537 # of using most of the personal_url's keys directly
1538 $personal_tools[$key] = array();
1539 $personal_tools[$key]["links"][] = array();
1540 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1541 if ( isset($ptool["active"]) ) {
1542 $personal_tools[$key]["active"] = $ptool["active"];
1544 foreach ( array("href", "class", "text") as $k ) {
1545 if ( isset($ptool[$k]) )
1546 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1549 return $personal_tools;
1553 * Makes a link, usually used by makeListItem to generate a link for an item
1554 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1556 * $key is a string, usually a key from the list you are generating this link from
1557 * $item is an array containing some of a specific set of keys.
1558 * The text of the link will be generated either from the contents of the "text"
1559 * key in the $item array, if a "msg" key is present a message by that name will
1560 * be used, and if neither of those are set the $key will be used as a message name.
1561 * If a "href" key is not present makeLink will just output htmlescaped text.
1562 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1563 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1564 * is present it will be used to generate a tooltip and accesskey for the link.
1565 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1567 function makeLink( $key, $item ) {
1568 if ( isset( $item['text'] ) ) {
1569 $text = $item['text'];
1571 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1574 if ( !isset( $item['href'] ) ) {
1575 return htmlspecialchars( $text );
1579 foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
1580 if ( isset( $item[$attr] ) ) {
1581 $attrs[$attr] = $item[$attr];
1585 if ( isset( $item['id'] ) ) {
1586 $item['single-id'] = $item['id'];
1588 if ( isset( $item['single-id'] ) ) {
1589 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1590 $attrs['title'] = $this->skin
->titleAttrib( $item['single-id'] );
1591 if ( $attrs['title'] === false ) {
1592 unset( $attrs['title'] );
1595 $attrs = array_merge(
1597 $this->skin
->tooltipAndAccesskeyAttribs( $item['single-id'] )
1602 return Html
::element( 'a', $attrs, $text );
1606 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1607 * $key is a string, usually a key from the list you are generating this link from
1608 * $item is an array of list item data containing some of a specific set of keys.
1609 * The "id" and "class" keys will be used as attributes for the list item,
1610 * if "active" contains a value of true a "active" class will also be appended to class.
1611 * If you want something other than a <li> you can pass a tag name such as
1612 * "tag" => "span" in the $options array to change the tag used.
1613 * link/content data for the list item may come in one of two forms
1614 * A "links" key may be used, in which case it should contain an array with
1615 * a list of links to include inside the list item, see makeLink for the format
1616 * of individual links array items.
1617 * Otherwise the relevant keys from the list item $item array will be passed
1618 * to makeLink instead. Note however that "id" and "class" are used by the
1619 * list item directly so they will not be passed to makeLink
1620 * (however the link will still support a tooltip and accesskey from it)
1621 * If you need an id or class on a single link you should include a "links"
1622 * array with just one link item inside of it.
1624 function makeListItem( $key, $item, $options = array() ) {
1625 if ( isset( $item['links'] ) ) {
1627 foreach ( $item['links'] as $linkKey => $link ) {
1628 $html .= $this->makeLink( $linkKey, $link );
1632 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
1633 if ( isset( $item[$k] ) ) {
1634 $link[$k] = $item[$k];
1637 if ( isset( $item['id'] ) ) {
1638 // The id goes on the <li> not on the <a> for single links
1639 // but makeSidebarLink still needs to know what id to use when
1640 // generating tooltips and accesskeys.
1641 $link['single-id'] = $item['id'];
1643 $html = $this->makeLink( $key, $link );
1647 foreach ( array( 'id', 'class' ) as $attr ) {
1648 if ( isset( $item[$attr] ) ) {
1649 $attrs[$attr] = $item[$attr];
1652 if ( isset( $item['active'] ) && $item['active'] ) {
1653 if ( !isset( $attrs['class'] ) ) {
1654 $attrs['class'] = '';
1656 $attrs['class'] .= ' active';
1657 $attrs['class'] = trim( $attrs['class'] );
1659 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1662 function makeSearchInput( $attrs = array() ) {
1666 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1668 $realAttrs = array_merge( $realAttrs, $this->skin
->tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1669 return Html
::element( 'input', $realAttrs );
1672 function makeSearchButton( $mode, $attrs = array() ) {
1679 'value' => $this->translator
->translate(
1680 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1682 $realAttrs = array_merge(
1684 $this->skin
->tooltipAndAccesskeyAttribs( "search-$mode" ),
1687 return Html
::element( 'input', $realAttrs );
1689 $buttonAttrs = array(
1693 $buttonAttrs = array_merge(
1695 $this->skin
->tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1698 unset( $buttonAttrs['src'] );
1699 unset( $buttonAttrs['alt'] );
1701 'src' => $attrs['src'],
1702 'alt' => isset( $attrs['alt'] )
1704 : $this->translator
->translate( 'searchbutton' ),
1706 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1708 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1713 * Returns an array of footerlinks trimmed down to only those footer links that
1715 * If you pass "flat" as an option then the returned array will be a flat array
1716 * of footer icons instead of a key/value array of footerlinks arrays broken
1717 * up into categories.
1719 function getFooterLinks( $option = null ) {
1720 $footerlinks = $this->data
['footerlinks'];
1722 // Reduce footer links down to only those which are being used
1723 $validFooterLinks = array();
1724 foreach( $footerlinks as $category => $links ) {
1725 $validFooterLinks[$category] = array();
1726 foreach( $links as $link ) {
1727 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1728 $validFooterLinks[$category][] = $link;
1731 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1732 unset( $validFooterLinks[$category] );
1736 if ( $option == 'flat' ) {
1737 // fold footerlinks into a single array using a bit of trickery
1738 $validFooterLinks = call_user_func_array(
1740 array_values( $validFooterLinks )
1744 return $validFooterLinks;
1748 * Returns an array of footer icons filtered down by options relevant to how
1749 * the skin wishes to display them.
1750 * If you pass "icononly" as the option all footer icons which do not have an
1751 * image icon set will be filtered out.
1752 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1753 * in the list of footer icons. This is mostly useful for skins which only
1754 * display the text from footericons instead of the images and don't want a
1755 * duplicate copyright statement because footerlinks already rendered one.
1757 function getFooterIcons( $option = null ) {
1758 // Generate additional footer icons
1759 $footericons = $this->data
['footericons'];
1761 if ( $option == 'icononly' ) {
1762 // Unset any icons which don't have an image
1763 foreach ( $footericons as &$footerIconsBlock ) {
1764 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1765 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1766 unset( $footerIconsBlock[$footerIconKey] );
1770 // Redo removal of any empty blocks
1771 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1772 if ( count( $footerIconsBlock ) <= 0 ) {
1773 unset( $footericons[$footerIconsKey] );
1776 } elseif ( $option == 'nocopyright' ) {
1777 unset( $footericons['copyright']['copyright'] );
1778 if ( count( $footericons['copyright'] ) <= 0 ) {
1779 unset( $footericons['copyright'] );
1783 return $footericons;
1787 * Output the basic end-page trail including bottomscripts, reporttime, and
1788 * debug stuff. This should be called right before outputting the closing
1789 * body and html tags.
1791 function printTrail() { ?
>
1792 <?php
$this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?
>
1793 <?php
$this->html('reporttime') ?
>
1794 <?php
if ( $this->data
['debug'] ): ?
>
1796 <?php
$this->text( 'debug' ); ?
>