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=null ) {
136 global $wgScript, $wgStylePath;
137 global $wgMimeType, $wgJsMimeType;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
139 global $wgDisableCounters, $wgSitename, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgDebugComments;
143 global $wgArticlePath, $wgScriptPath, $wgServer;
145 wfProfileIn( __METHOD__
);
146 Profiler
::instance()->setTemplated( true );
149 if ( $out !== null ) {
150 // @todo Add wfDeprecated in 1.20
151 $oldContext = $this->getContext();
152 $this->setContext( $out->getContext() );
155 $out = $this->getOutput();
156 $request = $this->getRequest();
157 $user = $this->getUser();
158 $title = $this->getTitle();
160 wfProfileIn( __METHOD__
. '-init' );
161 $this->initPage( $out );
163 $tpl = $this->setupTemplate( $this->template
, 'skins' );
164 wfProfileOut( __METHOD__
. '-init' );
166 wfProfileIn( __METHOD__
. '-stuff' );
167 $this->thispage
= $title->getPrefixedDBkey();
168 $this->userpage
= $user->getUserPage()->getPrefixedText();
170 if ( !$request->wasPosted() ) {
171 $query = $request->getValues();
172 unset( $query['title'] );
173 unset( $query['returnto'] );
174 unset( $query['returntoquery'] );
176 $this->thisquery
= wfArrayToCGI( $query );
177 $this->loggedin
= $user->isLoggedIn();
178 $this->username
= $user->getName();
179 $this->userdisplayname
= $user->getDisplayName();
181 if ( $user->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
= $title->getPrefixedText();
190 wfProfileOut( __METHOD__
. '-stuff' );
192 wfProfileIn( __METHOD__
. '-stuff-head' );
193 if ( !$this->useHeadElement
) {
194 $tpl->set( 'pagecss', false );
195 $tpl->set( 'usercss', false );
197 $this->userjs
= $this->userjsprev
= false;
198 # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we
199 # get rid of it? For that matter, why is any of this here at all?
200 $this->setupUserJs( $out->isUserJsAllowed() );
201 $tpl->setRef( 'userjs', $this->userjs
);
202 $tpl->setRef( 'userjsprev', $this->userjsprev
);
204 $tpl->set( 'jsvarurl', false );
206 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
207 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
208 $tpl->set( 'html5version', $wgHtml5Version );
209 $tpl->set( 'headlinks', $out->getHeadLinks() );
210 $tpl->set( 'csslinks', $out->buildCssLinks() );
211 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
212 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
214 wfProfileOut( __METHOD__
. '-stuff-head' );
216 wfProfileIn( __METHOD__
. '-stuff2' );
217 $tpl->set( 'title', $out->getPageTitle() );
218 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
219 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
221 $tpl->set( 'titleprefixeddbkey', $title->getPrefixedDBKey() );
222 $tpl->set( 'titletext', $title->getText() );
223 $tpl->set( 'articleid', $title->getArticleId() );
225 $tpl->set( 'isarticle', $out->isArticle() );
227 $tpl->setRef( 'thispage', $this->thispage
);
228 $subpagestr = $this->subPageSubtitle();
230 'subtitle', !empty( $subpagestr ) ?
231 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
234 $undelete = $this->getUndeleteLink();
236 'undelete', !empty( $undelete ) ?
237 '<span class="subpages">' . $undelete . '</span>' :
241 $tpl->set( 'catlinks', $this->getCategories() );
242 if( $out->isSyndicated() ) {
244 foreach( $out->getSyndicationLinks() as $format => $link ) {
245 $feeds[$format] = array(
246 'text' => $this->msg( "feed-$format" )->text(),
250 $tpl->setRef( 'feeds', $feeds );
252 $tpl->set( 'feeds', false );
255 $tpl->setRef( 'mimetype', $wgMimeType );
256 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
257 $tpl->set( 'charset', 'UTF-8' );
258 $tpl->setRef( 'wgScript', $wgScript );
259 $tpl->setRef( 'skinname', $this->skinname
);
260 $tpl->set( 'skinclass', get_class( $this ) );
261 $tpl->setRef( 'stylename', $this->stylename
);
262 $tpl->set( 'printable', $out->isPrintable() );
263 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
264 $tpl->setRef( 'loggedin', $this->loggedin
);
265 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
266 /* XXX currently unused, might get useful later
267 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
268 $tpl->set( 'exists', $title->getArticleID() != 0 );
269 $tpl->set( 'watch', $title->userIsWatching() ? 'unwatch' : 'watch' );
270 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
271 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
273 $tpl->set( 'searchaction', $this->escapeSearchLink() );
274 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
275 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
276 $tpl->setRef( 'stylepath', $wgStylePath );
277 $tpl->setRef( 'articlepath', $wgArticlePath );
278 $tpl->setRef( 'scriptpath', $wgScriptPath );
279 $tpl->setRef( 'serverurl', $wgServer );
280 $tpl->setRef( 'logopath', $wgLogo );
281 $tpl->setRef( 'sitename', $wgSitename );
283 $contentlang = $wgContLang->getHtmlCode();
284 $contentdir = $wgContLang->getDir();
285 $userlang = $this->getLanguage()->getHtmlCode();
286 $userdir = $this->getLanguage()->getDir();
288 $tpl->set( 'lang', $userlang );
289 $tpl->set( 'dir', $userdir );
290 $tpl->set( 'rtl', $this->getLanguage()->isRTL() );
292 $tpl->set( 'capitalizeallnouns', $this->getLanguage()->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
293 $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) );
294 $tpl->set( 'username', $user->isAnon() ?
null : $this->username
);
295 $tpl->set( 'userdisplayname', $user->isAnon() ?
null : $this->userdisplayname
);
296 $tpl->setRef( 'userpage', $this->userpage
);
297 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
298 $tpl->set( 'userlang', $userlang );
300 // Users can have their language set differently than the
301 // content of the wiki. For these users, tell the web browser
302 // that interface elements are in a different language.
303 $tpl->set( 'userlangattributes', '' );
304 $tpl->set( 'specialpageattributes', '' ); # obsolete
306 if ( $userlang !== $contentlang ||
$userdir !== $contentdir ) {
307 $attrs = " lang='$userlang' dir='$userdir'";
308 $tpl->set( 'userlangattributes', $attrs );
311 wfProfileOut( __METHOD__
. '-stuff2' );
313 wfProfileIn( __METHOD__
. '-stuff3' );
314 $tpl->set( 'newtalk', $this->getNewtalks() );
315 $tpl->setRef( 'skin', $this );
316 $tpl->set( 'logo', $this->logoText() );
318 $tpl->set( 'copyright', false );
319 $tpl->set( 'viewcount', false );
320 $tpl->set( 'lastmod', false );
321 $tpl->set( 'credits', false );
322 $tpl->set( 'numberofwatchingusers', false );
323 if ( $out->isArticle() && $title->exists() ) {
324 if ( $this->isRevisionCurrent() ) {
325 if ( !$wgDisableCounters ) {
326 $viewcount = $title->getCount();
328 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
332 if( $wgPageShowWatchingUsers ) {
333 $dbr = wfGetDB( DB_SLAVE
);
334 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
335 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
339 $tpl->set( 'numberofwatchingusers',
340 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
345 if ( $wgMaxCredits != 0 ) {
346 $tpl->set( 'credits', Action
::factory( 'credits', WikiPage
::factory( $title ),
347 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
349 $tpl->set( 'lastmod', $this->lastModified() );
352 $tpl->set( 'copyright', $this->getCopyright() );
354 wfProfileOut( __METHOD__
. '-stuff3' );
356 wfProfileIn( __METHOD__
. '-stuff4' );
357 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
358 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
359 $tpl->set( 'disclaimer', $this->disclaimerLink() );
360 $tpl->set( 'privacy', $this->privacyLink() );
361 $tpl->set( 'about', $this->aboutLink() );
363 $tpl->set( 'footerlinks', array(
367 'numberofwatchingusers',
378 global $wgFooterIcons;
379 $tpl->set( 'footericons', $wgFooterIcons );
380 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
381 if ( count( $footerIconsBlock ) > 0 ) {
382 foreach ( $footerIconsBlock as &$footerIcon ) {
383 if ( isset( $footerIcon['src'] ) ) {
384 if ( !isset( $footerIcon['width'] ) ) {
385 $footerIcon['width'] = 88;
387 if ( !isset( $footerIcon['height'] ) ) {
388 $footerIcon['height'] = 31;
393 unset( $tpl->data
['footericons'][$footerIconsKey] );
397 if ( $wgDebugComments ) {
398 $tpl->setRef( 'debug', $out->mDebugtext
);
400 $tpl->set( 'debug', '' );
403 $tpl->set( 'reporttime', wfReportTime() );
404 $tpl->set( 'sitenotice', $this->getSiteNotice() );
405 $tpl->set( 'bottomscripts', $this->bottomScripts() );
406 $tpl->set( 'printfooter', $this->printSource() );
408 # Add a <div class="mw-content-ltr/rtl"> around the body text
409 # not for special pages or file pages AND only when viewing AND if the page exists
410 # (or is in MW namespace, because that has default content)
411 if( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
412 in_array( $request->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) &&
413 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
414 $pageLang = $title->getPageLanguage();
415 $realBodyAttribs = array( 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
416 'class' => 'mw-content-'.$pageLang->getDir() );
417 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
420 $tpl->setRef( 'bodytext', $out->mBodytext
);
423 $language_urls = array();
425 if ( !$wgHideInterlanguageLinks ) {
426 foreach( $out->getLanguageLinks() as $l ) {
427 $tmp = explode( ':', $l, 2 );
428 $class = 'interwiki-' . $tmp[0];
430 $nt = Title
::newFromText( $l );
432 $language_urls[] = array(
433 'href' => $nt->getFullURL(),
434 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
435 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
436 'title' => $nt->getText(),
438 'lang' => $nt->getInterwiki(),
439 'hreflang' => $nt->getInterwiki(),
444 if( count( $language_urls ) ) {
445 $tpl->setRef( 'language_urls', $language_urls );
447 $tpl->set( 'language_urls', false );
449 wfProfileOut( __METHOD__
. '-stuff4' );
451 wfProfileIn( __METHOD__
. '-stuff5' );
453 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
454 $content_navigation = $this->buildContentNavigationUrls();
455 $content_actions = $this->buildContentActionUrls( $content_navigation );
456 $tpl->setRef( 'content_navigation', $content_navigation );
457 $tpl->setRef( 'content_actions', $content_actions );
459 $tpl->set( 'sidebar', $this->buildSidebar() );
460 $tpl->set( 'nav_urls', $this->buildNavUrls() );
462 // Set the head scripts near the end, in case the above actions resulted in added scripts
463 if ( $this->useHeadElement
) {
464 $tpl->set( 'headelement', $out->headElement( $this ) );
466 $tpl->set( 'headscripts', $out->getScript() );
469 $tpl->set( 'debughtml', $this->generateDebugHTML() );
471 // original version by hansm
472 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
473 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
476 // Set the bodytext to another key so that skins can just output it on it's own
477 // and output printfooter and debughtml separately
478 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
480 // Append printfooter and debughtml onto bodytext so that skins that were already
481 // using bodytext before they were split out don't suddenly start not outputting information
482 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
483 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
485 // allow extensions adding stuff after the page content.
486 // See Skin::afterContentHook() for further documentation.
487 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
488 wfProfileOut( __METHOD__
. '-stuff5' );
491 wfProfileIn( __METHOD__
. '-execute' );
492 $res = $tpl->execute();
493 wfProfileOut( __METHOD__
. '-execute' );
495 // result may be an error
496 $this->printOrError( $res );
499 $this->setContext( $oldContext );
501 wfProfileOut( __METHOD__
);
505 * Output the string, or print error message if it's
506 * an error object of the appropriate type.
507 * For the base class, assume strings all around.
512 function printOrError( $str ) {
517 * Output a boolean indiciating if buildPersonalUrls should output separate
518 * login and create account links or output a combined link
519 * By default we simply return a global config setting that affects most skins
520 * This is setup as a method so that like with $wgLogo and getLogo() a skin
521 * can override this setting and always output one or the other if it has
522 * a reason it can't output one of the two modes.
524 function useCombinedLoginLink() {
525 global $wgUseCombinedLoginLink;
526 return $wgUseCombinedLoginLink;
530 * build array of urls for personal toolbar
533 protected function buildPersonalUrls() {
534 $title = $this->getTitle();
535 $request = $this->getRequest();
536 $pageurl = $title->getLocalURL();
537 wfProfileIn( __METHOD__
);
539 /* set up the default links for the personal toolbar */
540 $personal_urls = array();
542 # Due to bug 32276, if a user does not have read permissions,
543 # $this->getTitle() will just give Special:Badtitle, which is
544 # not especially useful as a returnto parameter. Use the title
545 # from the request instead, if there was one.
546 $page = Title
::newFromURL( $request->getVal( 'title', '' ) );
547 $page = $request->getVal( 'returnto', $page );
549 if ( strval( $page ) !== '' ) {
550 $a['returnto'] = $page;
551 $query = $request->getVal( 'returntoquery', $this->thisquery
);
553 $a['returntoquery'] = $query;
556 $returnto = wfArrayToCGI( $a );
557 if( $this->loggedin
) {
558 $personal_urls['userpage'] = array(
559 'text' => $this->userdisplayname
,
560 'href' => &$this->userpageUrlDetails
['href'],
561 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
562 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
564 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
565 $personal_urls['mytalk'] = array(
566 'text' => $this->msg( 'mytalk' )->text(),
567 'href' => &$usertalkUrlDetails['href'],
568 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
569 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
571 $href = self
::makeSpecialUrl( 'Preferences' );
572 $personal_urls['preferences'] = array(
573 'text' => $this->msg( 'mypreferences' )->text(),
575 'active' => ( $href == $pageurl )
577 $href = self
::makeSpecialUrl( 'Watchlist' );
578 $personal_urls['watchlist'] = array(
579 'text' => $this->msg( 'mywatchlist' )->text(),
581 'active' => ( $href == $pageurl )
584 # We need to do an explicit check for Special:Contributions, as we
585 # have to match both the title, and the target (which could come
586 # from request values or be specified in "sub page" form. The plot
587 # thickens, because $wgTitle is altered for special pages, so doesn't
588 # contain the original alias-with-subpage.
589 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
590 if( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
591 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
592 $active = $spName == 'Contributions'
593 && ( ( $spPar && $spPar == $this->username
)
594 ||
$request->getText( 'target' ) == $this->username
);
599 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
600 $personal_urls['mycontris'] = array(
601 'text' => $this->msg( 'mycontris' )->text(),
605 $personal_urls['logout'] = array(
606 'text' => $this->msg( 'userlogout' )->text(),
607 'href' => self
::makeSpecialUrl( 'Userlogout',
608 // userlogout link must always contain an & character, otherwise we might not be able
609 // to detect a buggy precaching proxy (bug 17790)
610 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
615 $useCombinedLoginLink = $this->useCombinedLoginLink();
616 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
617 ?
'nav-login-createaccount'
619 $is_signup = $request->getText('type') == "signup";
621 # anonlogin & login are the same
623 'text' => $this->msg( $loginlink )->text(),
624 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
625 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" ||
!$is_signup )
627 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
628 $createaccount_url = array(
629 'text' => $this->msg( 'createaccount' )->text(),
630 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
631 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
634 global $wgServer, $wgSecureLogin;
635 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
636 $title = SpecialPage
::getTitleFor( 'Userlogin' );
637 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
638 $login_url['href'] = $https_url;
639 # @todo FIXME: Class depends on skin
640 $login_url['class'] = 'link-https';
641 if ( isset($createaccount_url) ) {
642 $https_url = preg_replace( '/^http:/', 'https:',
643 $title->getFullURL("type=signup") );
644 $createaccount_url['href'] = $https_url;
645 # @todo FIXME: Class depends on skin
646 $createaccount_url['class'] = 'link-https';
651 if( $this->showIPinHeader() ) {
652 $href = &$this->userpageUrlDetails
['href'];
653 $personal_urls['anonuserpage'] = array(
654 'text' => $this->userdisplayname
,
656 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
657 'active' => ( $pageurl == $href )
659 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
660 $href = &$usertalkUrlDetails['href'];
661 $personal_urls['anontalk'] = array(
662 'text' => $this->msg( 'anontalk' )->text(),
664 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
665 'active' => ( $pageurl == $href )
667 $personal_urls['anonlogin'] = $login_url;
669 $personal_urls['login'] = $login_url;
671 if ( isset($createaccount_url) ) {
672 $personal_urls['createaccount'] = $createaccount_url;
676 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
677 wfProfileOut( __METHOD__
);
678 return $personal_urls;
683 * @param $title Title
684 * @param $message String message key
685 * @param $selected Bool
686 * @param $query String
687 * @param $checkEdit Bool
690 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
693 $classes[] = 'selected';
695 if( $checkEdit && !$title->isKnown() ) {
697 $query = 'action=edit&redlink=1';
700 // wfMessageFallback will nicely accept $message as an array of fallbacks
701 // or just a single key
702 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
703 if ( is_array($message) ) {
704 // for hook compatibility just keep the last message name
705 $message = end($message);
707 if ( $msg->exists() ) {
708 $text = $msg->text();
711 $text = $wgContLang->getFormattedNsText(
712 MWNamespace
::getSubject( $title->getNamespace() ) );
716 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
717 $title, $message, $selected, $checkEdit,
718 &$classes, &$query, &$text, &$result ) ) ) {
723 'class' => implode( ' ', $classes ),
725 'href' => $title->getLocalUrl( $query ),
729 function makeTalkUrlDetails( $name, $urlaction = '' ) {
730 $title = Title
::newFromText( $name );
731 if( !is_object( $title ) ) {
732 throw new MWException( __METHOD__
. " given invalid pagename $name" );
734 $title = $title->getTalkPage();
735 self
::checkTitle( $title, $name );
737 'href' => $title->getLocalURL( $urlaction ),
738 'exists' => $title->getArticleID() != 0,
742 function makeArticleUrlDetails( $name, $urlaction = '' ) {
743 $title = Title
::newFromText( $name );
744 $title= $title->getSubjectPage();
745 self
::checkTitle( $title, $name );
747 'href' => $title->getLocalURL( $urlaction ),
748 'exists' => $title->getArticleID() != 0,
753 * a structured array of links usually used for the tabs in a skin
755 * There are 4 standard sections
756 * namespaces: Used for namespace tabs like special, page, and talk namespaces
757 * views: Used for primary page views like read, edit, history
758 * actions: Used for most extra page actions like deletion, protection, etc...
759 * variants: Used to list the language variants for the page
761 * Each section's value is a key/value array of links for that section.
762 * The links themseves have these common keys:
763 * - class: The css classes to apply to the tab
764 * - text: The text to display on the tab
765 * - href: The href for the tab to point to
766 * - rel: An optional rel= for the tab's link
767 * - redundant: If true the tab will be dropped in skins using content_actions
768 * this is useful for tabs like "Read" which only have meaning in skins that
769 * take special meaning from the grouped structure of content_navigation
771 * Views also have an extra key which can be used:
772 * - primary: If this is not true skins like vector may try to hide the tab
773 * when the user has limited space in their browser window
775 * content_navigation using code also expects these ids to be present on the
776 * links, however these are usually automatically generated by SkinTemplate
777 * itself and are not necessary when using a hook. The only things these may
778 * matter to are people modifying content_navigation after it's initial creation:
779 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
780 * - tooltiponly: This is set to true for some tabs in cases where the system
781 * believes that the accesskey should not be added to the tab.
785 protected function buildContentNavigationUrls() {
786 global $wgDisableLangConversion;
788 wfProfileIn( __METHOD__
);
790 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
791 $onPage = $title->equals($this->getTitle());
793 $out = $this->getOutput();
794 $request = $this->getRequest();
795 $user = $this->getUser();
797 $content_navigation = array(
798 'namespaces' => array(),
800 'actions' => array(),
801 'variants' => array()
805 $action = $request->getVal( 'action', 'view' );
807 $userCanRead = $title->quickUserCan( 'read', $user );
809 $preventActiveTabs = false;
810 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
812 // Checks if page is some kind of content
813 if( $title->canExist() ) {
814 // Gets page objects for the related namespaces
815 $subjectPage = $title->getSubjectPage();
816 $talkPage = $title->getTalkPage();
818 // Determines if this is a talk page
819 $isTalk = $title->isTalkPage();
821 // Generates XML IDs from namespace names
822 $subjectId = $title->getNamespaceKey( '' );
824 if ( $subjectId == 'main' ) {
827 $talkId = "{$subjectId}_talk";
830 $skname = $this->skinname
;
832 // Adds namespace links
833 $subjectMsg = array( "nstab-$subjectId" );
834 if ( $subjectPage->isMainPage() ) {
835 array_unshift($subjectMsg, 'mainpage-nstab');
837 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
838 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
840 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
841 $content_navigation['namespaces'][$talkId] = $this->tabAction(
842 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
844 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
846 if ( $userCanRead ) {
847 // Adds view view link
848 if ( $title->exists() ) {
849 $content_navigation['views']['view'] = $this->tabAction(
850 $isTalk ?
$talkPage : $subjectPage,
851 array( "$skname-view-view", 'view' ),
852 ( $onPage && ($action == 'view' ||
$action == 'purge' ) ), '', true
854 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
857 wfProfileIn( __METHOD__
. '-edit' );
859 // Checks if user can edit the current page if it exists or create it otherwise
860 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
861 // Builds CSS class for talk page links
862 $isTalkClass = $isTalk ?
' istalk' : '';
863 // Whether the user is editing the page
864 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
865 // Whether to show the "Add a new section" tab
866 // Checks if this is a current rev of talk page and is not forced to be hidden
867 $showNewSection = !$out->forceHideNewSectionLink()
868 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
869 $section = $request->getVal( 'section' );
871 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
873 $content_navigation['views']['edit'] = array(
874 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
875 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
876 'href' => $title->getLocalURL( $this->editUrlOptions() ),
877 'primary' => true, // don't collapse this in vector
881 if ( $showNewSection ) {
882 // Adds new section link
883 //$content_navigation['actions']['addsection']
884 $content_navigation['views']['addsection'] = array(
885 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
886 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
887 'href' => $title->getLocalURL( 'action=edit§ion=new' )
890 // Checks if the page has some kind of viewable content
891 } elseif ( $title->hasSourceText() ) {
892 // Adds view source view link
893 $content_navigation['views']['viewsource'] = array(
894 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
895 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
896 'href' => $title->getLocalURL( $this->editUrlOptions() ),
897 'primary' => true, // don't collapse this in vector
900 wfProfileOut( __METHOD__
. '-edit' );
902 wfProfileIn( __METHOD__
. '-live' );
903 // Checks if the page exists
904 if ( $title->exists() ) {
905 // Adds history view link
906 $content_navigation['views']['history'] = array(
907 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
908 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
909 'href' => $title->getLocalURL( 'action=history' ),
913 if ( $title->quickUserCan( 'delete', $user ) ) {
914 $content_navigation['actions']['delete'] = array(
915 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
916 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
917 'href' => $title->getLocalURL( 'action=delete' )
921 if ( $title->quickUserCan( 'move', $user ) ) {
922 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
923 $content_navigation['actions']['move'] = array(
924 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
925 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
926 'href' => $moveTitle->getLocalURL()
930 // article doesn't exist or is deleted
931 if ( $user->isAllowed( 'deletedhistory' ) ) {
932 $n = $title->isDeleted();
934 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
935 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
936 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
937 $content_navigation['actions']['undelete'] = array(
938 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
939 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
940 ->setContext( $this->getContext() )->numParams( $n )->text(),
941 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
947 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) ) {
948 $mode = $title->isProtected() ?
'unprotect' : 'protect';
949 $content_navigation['actions'][$mode] = array(
950 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
951 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
952 'href' => $title->getLocalURL( "action=$mode" )
956 wfProfileOut( __METHOD__
. '-live' );
958 // Checks if the user is logged in
959 if ( $this->loggedin
) {
961 * The following actions use messages which, if made particular to
962 * the any specific skins, would break the Ajax code which makes this
963 * action happen entirely inline. Skin::makeGlobalVariablesScript
964 * defines a set of messages in a javascript object - and these
965 * messages are assumed to be global for all skins. Without making
966 * a change to that procedure these messages will have to remain as
967 * the global versions.
969 $mode = $title->userIsWatching() ?
'unwatch' : 'watch';
970 $token = WatchAction
::getWatchToken( $title, $user, $mode );
971 $content_navigation['actions'][$mode] = array(
972 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
973 'text' => $this->msg( $mode )->text(), // uses 'watch' or 'unwatch' message
974 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
979 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
981 if ( $userCanRead && !$wgDisableLangConversion ) {
982 $pageLang = $title->getPageLanguage();
983 // Gets list of language variants
984 $variants = $pageLang->getVariants();
985 // Checks that language conversion is enabled and variants exist
986 // And if it is not in the special namespace
987 if( count( $variants ) > 1 ) {
988 // Gets preferred variant (note that user preference is
989 // only possible for wiki content language variant)
990 $preferred = $pageLang->getPreferredVariant();
991 // Loops over each variant
992 foreach( $variants as $code ) {
993 // Gets variant name from language code
994 $varname = $pageLang->getVariantname( $code );
995 // Checks if the variant is marked as disabled
996 if( $varname == 'disable' ) {
997 // Skips this variant
1000 // Appends variant link
1001 $content_navigation['variants'][] = array(
1002 'class' => ( $code == $preferred ) ?
'selected' : false,
1004 'href' => $title->getLocalURL( array( 'variant' => $code ) )
1010 // If it's not content, it's got to be a special page
1011 $content_navigation['namespaces']['special'] = array(
1012 'class' => 'selected',
1013 'text' => $this->msg( 'nstab-special' )->text(),
1014 'href' => $request->getRequestURL(), // @bug 2457, 2510
1015 'context' => 'subject'
1018 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1019 array( &$this, &$content_navigation ) );
1022 // Equiv to SkinTemplateContentActions
1023 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1025 // Setup xml ids and tooltip info
1026 foreach ( $content_navigation as $section => &$links ) {
1027 foreach ( $links as $key => &$link ) {
1029 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1030 $xmlID = 'ca-nstab-' . $xmlID;
1031 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1033 } elseif ( $section == "variants" ) {
1034 $xmlID = 'ca-varlang-' . $xmlID;
1036 $xmlID = 'ca-' . $xmlID;
1038 $link['id'] = $xmlID;
1042 # We don't want to give the watch tab an accesskey if the
1043 # page is being edited, because that conflicts with the
1044 # accesskey on the watch checkbox. We also don't want to
1045 # give the edit tab an accesskey, because that's fairly su-
1046 # perfluous and conflicts with an accesskey (Ctrl-E) often
1047 # used for editing in Safari.
1048 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1049 if ( isset($content_navigation['views']['edit']) ) {
1050 $content_navigation['views']['edit']['tooltiponly'] = true;
1052 if ( isset($content_navigation['actions']['watch']) ) {
1053 $content_navigation['actions']['watch']['tooltiponly'] = true;
1055 if ( isset($content_navigation['actions']['unwatch']) ) {
1056 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1060 wfProfileOut( __METHOD__
);
1062 return $content_navigation;
1066 * an array of edit links by default used for the tabs
1070 function buildContentActionUrls( $content_navigation ) {
1072 wfProfileIn( __METHOD__
);
1074 // content_actions has been replaced with content_navigation for backwards
1075 // compatibility and also for skins that just want simple tabs content_actions
1076 // is now built by flattening the content_navigation arrays into one
1078 $content_actions = array();
1080 foreach ( $content_navigation as $links ) {
1082 foreach ( $links as $key => $value ) {
1084 if ( isset($value["redundant"]) && $value["redundant"] ) {
1085 // Redundant tabs are dropped from content_actions
1089 // content_actions used to have ids built using the "ca-$key" pattern
1090 // so the xmlID based id is much closer to the actual $key that we want
1091 // for that reason we'll just strip out the ca- if present and use
1092 // the latter potion of the "id" as the $key
1093 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1094 $key = substr($value["id"], 3);
1097 if ( isset($content_actions[$key]) ) {
1098 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1102 $content_actions[$key] = $value;
1108 wfProfileOut( __METHOD__
);
1110 return $content_actions;
1114 * build array of common navigation links
1118 protected function buildNavUrls() {
1119 global $wgUploadNavigationUrl;
1121 wfProfileIn( __METHOD__
);
1123 $out = $this->getOutput();
1124 $request = $this->getRequest();
1126 $nav_urls = array();
1127 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1128 if( $wgUploadNavigationUrl ) {
1129 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1130 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1131 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1133 $nav_urls['upload'] = false;
1135 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1137 $nav_urls['print'] = false;
1138 $nav_urls['permalink'] = false;
1139 $nav_urls['whatlinkshere'] = false;
1140 $nav_urls['recentchangeslinked'] = false;
1141 $nav_urls['contributions'] = false;
1142 $nav_urls['log'] = false;
1143 $nav_urls['blockip'] = false;
1144 $nav_urls['emailuser'] = false;
1146 // A print stylesheet is attached to all pages, but nobody ever
1147 // figures that out. :) Add a link...
1148 if( $out->isArticle() ) {
1149 if ( !$out->isPrintable() ) {
1150 $nav_urls['print'] = array(
1151 'text' => $this->msg( 'printableversion' )->text(),
1152 'href' => $this->getTitle()->getLocalURL(
1153 $request->appendQueryValue( 'printable', 'yes', true ) )
1157 // Also add a "permalink" while we're at it
1158 $revid = $this->getRevisionId();
1160 $nav_urls['permalink'] = array(
1161 'text' => $this->msg( 'permalink' )->text(),
1162 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1166 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1167 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1168 array( &$this, &$nav_urls, &$revid, &$revid ) );
1171 if ( $out->isArticleRelated() ) {
1172 $nav_urls['whatlinkshere'] = array(
1173 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalUrl()
1175 if ( $this->getTitle()->getArticleId() ) {
1176 $nav_urls['recentchangeslinked'] = array(
1177 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalUrl()
1182 $user = $this->getRelevantUser();
1184 $rootUser = $user->getName();
1186 $nav_urls['contributions'] = array(
1187 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1190 if ( $user->isLoggedIn() ) {
1191 $logPage = SpecialPage
::getTitleFor( 'Log' );
1192 $nav_urls['log'] = array(
1193 'href' => $logPage->getLocalUrl( array( 'user' => $rootUser ) )
1197 if ( $this->getUser()->isAllowed( 'block' ) ) {
1198 $nav_urls['blockip'] = array(
1199 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1203 if ( $this->showEmailUser( $user ) ) {
1204 $nav_urls['emailuser'] = array(
1205 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1210 wfProfileOut( __METHOD__
);
1215 * Generate strings used for xml 'id' names
1219 function getNameSpaceKey() {
1220 return $this->getTitle()->getNamespaceKey();
1225 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1227 function setupUserJs( $allowUserJs ) {
1228 global $wgJsMimeType;
1229 wfProfileIn( __METHOD__
);
1231 if( $allowUserJs && $this->loggedin
) {
1232 if( $this->getTitle()->isJsSubpage() and $this->getOutput()->userCanPreview() ) {
1233 # XXX: additional security check/prompt?
1234 $this->userjsprev
= '/*<![CDATA[*/ ' . $this->getRequest()->getText( 'wpTextbox1' ) . ' /*]]>*/';
1236 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1239 wfProfileOut( __METHOD__
);
1242 public function commonPrintStylesheet() {
1248 * Generic wrapper for template functions, with interface
1249 * compatible with what we use of PHPTAL 0.7.
1252 abstract class QuickTemplate
{
1256 public function QuickTemplate() {
1257 $this->data
= array();
1258 $this->translator
= new MediaWiki_I18N();
1262 * Sets the value $value to $name
1266 public function set( $name, $value ) {
1267 $this->data
[$name] = $value;
1274 public function setRef( $name, &$value ) {
1275 $this->data
[$name] =& $value;
1281 public function setTranslator( &$t ) {
1282 $this->translator
= &$t;
1286 * Main function, used by classes that subclass QuickTemplate
1287 * to show the actual HTML output
1289 abstract public function execute();
1294 function text( $str ) {
1295 echo htmlspecialchars( $this->data
[$str] );
1301 function jstext( $str ) {
1302 echo Xml
::escapeJsString( $this->data
[$str] );
1308 function html( $str ) {
1309 echo $this->data
[$str];
1315 function msg( $str ) {
1316 echo htmlspecialchars( $this->translator
->translate( $str ) );
1322 function msgHtml( $str ) {
1323 echo $this->translator
->translate( $str );
1327 * An ugly, ugly hack.
1330 function msgWiki( $str ) {
1333 $text = $this->translator
->translate( $str );
1334 echo $wgOut->parse( $text );
1340 function haveData( $str ) {
1341 return isset( $this->data
[$str] );
1349 function haveMsg( $str ) {
1350 $msg = $this->translator
->translate( $str );
1351 return ( $msg != '-' ) && ( $msg != '' ); # ????
1355 * Get the Skin object related to this object
1357 * @return Skin object
1359 public function getSkin() {
1360 return $this->data
['skin'];
1365 * New base template for a skin's template extended from QuickTemplate
1366 * this class features helper methods that provide common ways of interacting
1367 * with the data stored in the QuickTemplate
1369 abstract class BaseTemplate
extends QuickTemplate
{
1372 * Get a Message object with its context set
1374 * @param $name Str message name
1377 public function getMsg( $name ) {
1378 return $this->getSkin()->msg( $name );
1381 function msg( $str ) {
1382 echo $this->getMsg( $str )->escaped();
1385 function msgHtml( $str ) {
1386 echo $this->getMsg( $str )->text();
1389 function msgWiki( $str ) {
1390 echo $this->getMsg( $str )->parseAsBlock();
1394 * Create an array of common toolbox items from the data in the quicktemplate
1395 * stored by SkinTemplate.
1396 * The resulting array is built acording to a format intended to be passed
1397 * through makeListItem to generate the html.
1399 function getToolbox() {
1400 wfProfileIn( __METHOD__
);
1403 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1404 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1405 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1407 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1408 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1409 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1410 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1412 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1413 $toolbox['feeds']['id'] = 'feedlinks';
1414 $toolbox['feeds']['links'] = array();
1415 foreach ( $this->data
['feeds'] as $key => $feed ) {
1416 $toolbox['feeds']['links'][$key] = $feed;
1417 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1418 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1419 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1420 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1423 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1424 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1425 $toolbox[$special] = $this->data
['nav_urls'][$special];
1426 $toolbox[$special]['id'] = "t-$special";
1429 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1430 $toolbox['print'] = $this->data
['nav_urls']['print'];
1431 $toolbox['print']['rel'] = 'alternate';
1432 $toolbox['print']['msg'] = 'printableversion';
1434 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1435 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1436 if( $toolbox['permalink']['href'] === '' ) {
1437 unset( $toolbox['permalink']['href'] );
1438 $toolbox['ispermalink']['tooltiponly'] = true;
1439 $toolbox['ispermalink']['id'] = 't-ispermalink';
1440 $toolbox['ispermalink']['msg'] = 'permalink';
1442 $toolbox['permalink']['id'] = 't-permalink';
1445 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1446 wfProfileOut( __METHOD__
);
1451 * Create an array of personal tools items from the data in the quicktemplate
1452 * stored by SkinTemplate.
1453 * The resulting array is built acording to a format intended to be passed
1454 * through makeListItem to generate the html.
1455 * This is in reality the same list as already stored in personal_urls
1456 * however it is reformatted so that you can just pass the individual items
1457 * to makeListItem instead of hardcoding the element creation boilerplate.
1460 function getPersonalTools() {
1461 $personal_tools = array();
1462 foreach( $this->data
['personal_urls'] as $key => $ptool ) {
1463 # The class on a personal_urls item is meant to go on the <a> instead
1464 # of the <li> so we have to use a single item "links" array instead
1465 # of using most of the personal_url's keys directly
1466 $personal_tools[$key] = array();
1467 $personal_tools[$key]["links"][] = array();
1468 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1469 if ( isset($ptool["active"]) ) {
1470 $personal_tools[$key]["active"] = $ptool["active"];
1472 foreach ( array("href", "class", "text") as $k ) {
1473 if ( isset($ptool[$k]) )
1474 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1477 return $personal_tools;
1480 function getSidebar( $options = array() ) {
1481 // Force the rendering of the following portals
1482 $sidebar = $this->data
['sidebar'];
1483 if ( !isset( $sidebar['SEARCH'] ) ) {
1484 $sidebar['SEARCH'] = true;
1486 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1487 $sidebar['TOOLBOX'] = true;
1489 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1490 $sidebar['LANGUAGES'] = true;
1493 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1494 unset( $sidebar['SEARCH'] );
1496 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1497 unset( $sidebar['TOOLBOX'] );
1499 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1500 unset( $sidebar['LANGUAGES'] );
1504 foreach ( $sidebar as $boxName => $content ) {
1505 if ( $content === false ) {
1508 switch ( $boxName ) {
1510 // Search is a special case, skins should custom implement this
1511 $boxes[$boxName] = array(
1513 'header' => $this->getMsg( 'search' )->text(),
1514 'generated' => false,
1519 $msgObj = $this->getMsg( 'toolbox' );
1520 $boxes[$boxName] = array(
1522 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1523 'generated' => false,
1524 'content' => $this->getToolbox(),
1528 if ( $this->data
['language_urls'] ) {
1529 $msgObj = $this->getMsg( 'otherlanguages' );
1530 $boxes[$boxName] = array(
1532 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1533 'generated' => false,
1534 'content' => $this->data
['language_urls'],
1539 $msgObj = $this->getMsg( $boxName );
1540 $boxes[$boxName] = array(
1541 'id' => "p-$boxName",
1542 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1543 'generated' => true,
1544 'content' => $content,
1550 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1551 $hookContents = null;
1552 if ( isset( $boxes['TOOLBOX'] ) ) {
1554 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1555 // can abort and avoid outputting double toolbox links
1556 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1557 $hookContents = ob_get_contents();
1559 if ( !trim( $hookContents ) ) {
1560 $hookContents = null;
1565 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1566 foreach ( $boxes as $boxName => $box ) {
1567 if ( is_array( $box['content'] ) ) {
1569 foreach ( $box['content'] as $key => $val ) {
1570 $content .= "\n " . $this->makeListItem( $key, $val );
1572 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1573 if ( $hookContents ) {
1574 $content .= "\n $hookContents";
1577 $content .= "\n</ul>\n";
1578 $boxes[$boxName]['content'] = $content;
1582 if ( $hookContents ) {
1583 $boxes['TOOLBOXEND'] = array(
1584 'id' => "p-toolboxend",
1585 'header' => $boxes['TOOLBOX']['header'],
1586 'generated' => false,
1587 'content' => "<ul>{$hookContents}</ul>",
1589 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1591 foreach ( $boxes as $key => $box ) {
1592 if ( $key === 'TOOLBOXEND' ) {
1595 $boxes2[$key] = $box;
1596 if ( $key === 'TOOLBOX' ) {
1597 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1609 * Makes a link, usually used by makeListItem to generate a link for an item
1610 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1612 * $key is a string, usually a key from the list you are generating this link from
1613 * $item is an array containing some of a specific set of keys.
1614 * The text of the link will be generated either from the contents of the "text"
1615 * key in the $item array, if a "msg" key is present a message by that name will
1616 * be used, and if neither of those are set the $key will be used as a message name.
1617 * If a "href" key is not present makeLink will just output htmlescaped text.
1618 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1619 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1620 * is present it will be used to generate a tooltip and accesskey for the link.
1621 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1622 * $options can be used to affect the output of a link:
1623 * You can use a text-wrapper key to specify a list of elements to wrap the
1624 * text of a link in. This should be an array of arrays containing a 'tag' and
1625 * optionally an 'attributes' key. If you only have one element you don't need
1626 * to wrap it in another array. eg: To use <a><span>...</span></a> in all links
1627 * use array( 'text-wrapper' => array( 'tag' => 'span' ) ) for your options.
1628 * A link-class key can be used to specify additional classes to apply to all links.
1629 * A link-fallback can be used to specify a tag to use instead of <a> if there is
1630 * no link. eg: If you specify 'link-fallback' => 'span' than any non-link will
1631 * output a <span> instead of just text.
1633 function makeLink( $key, $item, $options = array() ) {
1634 if ( isset( $item['text'] ) ) {
1635 $text = $item['text'];
1637 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1640 $html = htmlspecialchars( $text );
1642 if ( isset( $options['text-wrapper'] ) ) {
1643 $wrapper = $options['text-wrapper'];
1644 if ( isset( $wrapper['tag'] ) ) {
1645 $wrapper = array( $wrapper );
1647 while ( count( $wrapper ) > 0 ) {
1648 $element = array_pop( $wrapper );
1649 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1653 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1655 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1656 unset( $attrs[$k] );
1659 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1660 $item['single-id'] = $item['id'];
1662 if ( isset( $item['single-id'] ) ) {
1663 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1664 $title = Linker
::titleAttrib( $item['single-id'] );
1665 if ( $title !== false ) {
1666 $attrs['title'] = $title;
1669 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1670 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1671 $attrs['title'] = $tip['title'];
1673 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1674 $attrs['accesskey'] = $tip['accesskey'];
1678 if ( isset( $options['link-class'] ) ) {
1679 if ( isset( $attrs['class'] ) ) {
1680 $attrs['class'] .= " {$options['link-class']}";
1682 $attrs['class'] = $options['link-class'];
1685 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1692 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1693 * $key is a string, usually a key from the list you are generating this link from
1694 * $item is an array of list item data containing some of a specific set of keys.
1695 * The "id" and "class" keys will be used as attributes for the list item,
1696 * if "active" contains a value of true a "active" class will also be appended to class.
1697 * If you want something other than a <li> you can pass a tag name such as
1698 * "tag" => "span" in the $options array to change the tag used.
1699 * link/content data for the list item may come in one of two forms
1700 * A "links" key may be used, in which case it should contain an array with
1701 * a list of links to include inside the list item, see makeLink for the format
1702 * of individual links array items.
1703 * Otherwise the relevant keys from the list item $item array will be passed
1704 * to makeLink instead. Note however that "id" and "class" are used by the
1705 * list item directly so they will not be passed to makeLink
1706 * (however the link will still support a tooltip and accesskey from it)
1707 * If you need an id or class on a single link you should include a "links"
1708 * array with just one link item inside of it.
1709 * $options is also passed on to makeLink calls
1711 function makeListItem( $key, $item, $options = array() ) {
1712 if ( isset( $item['links'] ) ) {
1714 foreach ( $item['links'] as $linkKey => $link ) {
1715 $html .= $this->makeLink( $linkKey, $link, $options );
1719 // These keys are used by makeListItem and shouldn't be passed on to the link
1720 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1723 if ( isset( $item['id'] ) ) {
1724 // The id goes on the <li> not on the <a> for single links
1725 // but makeSidebarLink still needs to know what id to use when
1726 // generating tooltips and accesskeys.
1727 $link['single-id'] = $item['id'];
1729 $html = $this->makeLink( $key, $link, $options );
1733 foreach ( array( 'id', 'class' ) as $attr ) {
1734 if ( isset( $item[$attr] ) ) {
1735 $attrs[$attr] = $item[$attr];
1738 if ( isset( $item['active'] ) && $item['active'] ) {
1739 if ( !isset( $attrs['class'] ) ) {
1740 $attrs['class'] = '';
1742 $attrs['class'] .= ' active';
1743 $attrs['class'] = trim( $attrs['class'] );
1745 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1748 function makeSearchInput( $attrs = array() ) {
1752 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1754 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1755 return Html
::element( 'input', $realAttrs );
1758 function makeSearchButton( $mode, $attrs = array() ) {
1765 'value' => $this->translator
->translate(
1766 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1768 $realAttrs = array_merge(
1770 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1773 return Html
::element( 'input', $realAttrs );
1775 $buttonAttrs = array(
1779 $buttonAttrs = array_merge(
1781 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1784 unset( $buttonAttrs['src'] );
1785 unset( $buttonAttrs['alt'] );
1787 'src' => $attrs['src'],
1788 'alt' => isset( $attrs['alt'] )
1790 : $this->translator
->translate( 'searchbutton' ),
1792 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1794 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1799 * Returns an array of footerlinks trimmed down to only those footer links that
1801 * If you pass "flat" as an option then the returned array will be a flat array
1802 * of footer icons instead of a key/value array of footerlinks arrays broken
1803 * up into categories.
1805 function getFooterLinks( $option = null ) {
1806 $footerlinks = $this->data
['footerlinks'];
1808 // Reduce footer links down to only those which are being used
1809 $validFooterLinks = array();
1810 foreach( $footerlinks as $category => $links ) {
1811 $validFooterLinks[$category] = array();
1812 foreach( $links as $link ) {
1813 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1814 $validFooterLinks[$category][] = $link;
1817 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1818 unset( $validFooterLinks[$category] );
1822 if ( $option == 'flat' ) {
1823 // fold footerlinks into a single array using a bit of trickery
1824 $validFooterLinks = call_user_func_array(
1826 array_values( $validFooterLinks )
1830 return $validFooterLinks;
1834 * Returns an array of footer icons filtered down by options relevant to how
1835 * the skin wishes to display them.
1836 * If you pass "icononly" as the option all footer icons which do not have an
1837 * image icon set will be filtered out.
1838 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1839 * in the list of footer icons. This is mostly useful for skins which only
1840 * display the text from footericons instead of the images and don't want a
1841 * duplicate copyright statement because footerlinks already rendered one.
1843 function getFooterIcons( $option = null ) {
1844 // Generate additional footer icons
1845 $footericons = $this->data
['footericons'];
1847 if ( $option == 'icononly' ) {
1848 // Unset any icons which don't have an image
1849 foreach ( $footericons as &$footerIconsBlock ) {
1850 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1851 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1852 unset( $footerIconsBlock[$footerIconKey] );
1856 // Redo removal of any empty blocks
1857 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1858 if ( count( $footerIconsBlock ) <= 0 ) {
1859 unset( $footericons[$footerIconsKey] );
1862 } elseif ( $option == 'nocopyright' ) {
1863 unset( $footericons['copyright']['copyright'] );
1864 if ( count( $footericons['copyright'] ) <= 0 ) {
1865 unset( $footericons['copyright'] );
1869 return $footericons;
1873 * Output the basic end-page trail including bottomscripts, reporttime, and
1874 * debug stuff. This should be called right before outputting the closing
1875 * body and html tags.
1877 function printTrail() { ?
>
1878 <?php
$this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?
>
1879 <?php
$this->html('reporttime') ?
>
1880 <?php
if ( $this->data
['debug'] ): ?
>
1882 <?php
$this->text( 'debug' ); ?
>