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 $wgUseSiteJs, $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();
159 wfProfileIn( __METHOD__
. '-init' );
160 $this->initPage( $out );
162 $tpl = $this->setupTemplate( $this->template
, 'skins' );
163 wfProfileOut( __METHOD__
. '-init' );
165 wfProfileIn( __METHOD__
. '-stuff' );
166 $this->thispage
= $this->getTitle()->getPrefixedDBkey();
167 $this->userpage
= $user->getUserPage()->getPrefixedText();
169 if ( !$request->wasPosted() ) {
170 $query = $request->getValues();
171 unset( $query['title'] );
172 unset( $query['returnto'] );
173 unset( $query['returntoquery'] );
175 $this->thisquery
= wfArrayToCGI( $query );
176 $this->loggedin
= $user->isLoggedIn();
177 $this->username
= $user->getName();
178 $this->userdisplayname
= $user->getDisplayName();
180 if ( $user->isLoggedIn() ||
$this->showIPinHeader() ) {
181 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
183 # This won't be used in the standard skins, but we define it to preserve the interface
184 # To save time, we check for existence
185 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
188 $this->titletxt
= $this->getTitle()->getPrefixedText();
189 wfProfileOut( __METHOD__
. '-stuff' );
191 wfProfileIn( __METHOD__
. '-stuff-head' );
192 if ( !$this->useHeadElement
) {
193 $tpl->set( 'pagecss', false );
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() );
217 $tpl->set( 'csslinks', $out->buildCssLinks() );
218 $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
219 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
221 wfProfileOut( __METHOD__
. '-stuff-head' );
223 wfProfileIn( __METHOD__
. '-stuff2' );
224 $tpl->set( 'title', $out->getPageTitle() );
225 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
226 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
228 $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
229 $tpl->set( 'titletext', $this->getTitle()->getText() );
230 $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
232 $tpl->set( 'isarticle', $out->isArticle() );
234 $tpl->setRef( 'thispage', $this->thispage
);
235 $subpagestr = $this->subPageSubtitle();
237 'subtitle', !empty( $subpagestr ) ?
238 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
241 $undelete = $this->getUndeleteLink();
243 'undelete', !empty( $undelete ) ?
244 '<span class="subpages">' . $undelete . '</span>' :
248 $tpl->set( 'catlinks', $this->getCategories() );
249 if( $out->isSyndicated() ) {
251 foreach( $out->getSyndicationLinks() as $format => $link ) {
252 $feeds[$format] = array(
253 'text' => $this->msg( "feed-$format" )->text(),
257 $tpl->setRef( 'feeds', $feeds );
259 $tpl->set( 'feeds', false );
262 $tpl->setRef( 'mimetype', $wgMimeType );
263 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
264 $tpl->set( 'charset', 'UTF-8' );
265 $tpl->setRef( 'wgScript', $wgScript );
266 $tpl->setRef( 'skinname', $this->skinname
);
267 $tpl->set( 'skinclass', get_class( $this ) );
268 $tpl->setRef( 'stylename', $this->stylename
);
269 $tpl->set( 'printable', $out->isPrintable() );
270 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
271 $tpl->setRef( 'loggedin', $this->loggedin
);
272 $tpl->set( 'notspecialpage', !$this->getTitle()->isSpecialPage() );
273 /* XXX currently unused, might get useful later
274 $tpl->set( 'editable', ( !$this->getTitle()->isSpecialPage() ) );
275 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
276 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
277 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
278 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
280 $tpl->set( 'searchaction', $this->escapeSearchLink() );
281 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
282 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
283 $tpl->setRef( 'stylepath', $wgStylePath );
284 $tpl->setRef( 'articlepath', $wgArticlePath );
285 $tpl->setRef( 'scriptpath', $wgScriptPath );
286 $tpl->setRef( 'serverurl', $wgServer );
287 $tpl->setRef( 'logopath', $wgLogo );
288 $tpl->setRef( 'sitename', $wgSitename );
290 $contentlang = $wgContLang->getCode();
291 $contentdir = $wgContLang->getDir();
292 $userlang = $this->getLanguage()->getCode();
293 $userdir = $this->getLanguage()->getDir();
295 $tpl->set( 'lang', $userlang );
296 $tpl->set( 'dir', $userdir );
297 $tpl->set( 'rtl', $this->getLanguage()->isRTL() );
299 $tpl->set( 'capitalizeallnouns', $this->getLanguage()->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
300 $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) );
301 $tpl->set( 'username', $user->isAnon() ?
null : $this->username
);
302 $tpl->set( 'userdisplayname', $user->isAnon() ?
null : $this->userdisplayname
);
303 $tpl->setRef( 'userpage', $this->userpage
);
304 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
305 $tpl->set( 'userlang', $userlang );
307 // Users can have their language set differently than the
308 // content of the wiki. For these users, tell the web browser
309 // that interface elements are in a different language.
310 $tpl->set( 'userlangattributes', '' );
311 $tpl->set( 'specialpageattributes', '' ); # obsolete
313 if ( $userlang !== $contentlang ||
$userdir !== $contentdir ) {
314 $attrs = " lang='$userlang' dir='$userdir'";
315 $tpl->set( 'userlangattributes', $attrs );
318 wfProfileOut( __METHOD__
. '-stuff2' );
320 wfProfileIn( __METHOD__
. '-stuff3' );
321 $tpl->set( 'newtalk', $this->getNewtalks() );
322 $tpl->setRef( 'skin', $this );
323 $tpl->set( 'logo', $this->logoText() );
325 $tpl->set( 'copyright', false );
326 $tpl->set( 'viewcount', false );
327 $tpl->set( 'lastmod', false );
328 $tpl->set( 'credits', false );
329 $tpl->set( 'numberofwatchingusers', false );
330 if ( $out->isArticle() && $this->getTitle()->exists() ) {
331 if ( $this->isRevisionCurrent() ) {
332 $page = WikiPage
::factory( $this->getTitle() );
333 if ( !$wgDisableCounters ) {
334 $viewcount = $page->getCount();
336 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
340 if( $wgPageShowWatchingUsers ) {
341 $dbr = wfGetDB( DB_SLAVE
);
342 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
343 array( 'wl_title' => $this->getTitle()->getDBkey(), 'wl_namespace' => $this->getTitle()->getNamespace() ),
347 $tpl->set( 'numberofwatchingusers',
348 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
353 if ( $wgMaxCredits != 0 ) {
354 $tpl->set( 'credits', Action
::factory( 'credits', $page, $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
356 $tpl->set( 'lastmod', $this->lastModified( $page ) );
359 $tpl->set( 'copyright', $this->getCopyright() );
361 wfProfileOut( __METHOD__
. '-stuff3' );
363 wfProfileIn( __METHOD__
. '-stuff4' );
364 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
365 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
366 $tpl->set( 'disclaimer', $this->disclaimerLink() );
367 $tpl->set( 'privacy', $this->privacyLink() );
368 $tpl->set( 'about', $this->aboutLink() );
370 $tpl->set( 'footerlinks', array(
374 'numberofwatchingusers',
385 global $wgFooterIcons;
386 $tpl->set( 'footericons', $wgFooterIcons );
387 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
388 if ( count( $footerIconsBlock ) > 0 ) {
389 foreach ( $footerIconsBlock as &$footerIcon ) {
390 if ( isset( $footerIcon['src'] ) ) {
391 if ( !isset( $footerIcon['width'] ) ) {
392 $footerIcon['width'] = 88;
394 if ( !isset( $footerIcon['height'] ) ) {
395 $footerIcon['height'] = 31;
400 unset( $tpl->data
['footericons'][$footerIconsKey] );
404 if ( $wgDebugComments ) {
405 $tpl->setRef( 'debug', $out->mDebugtext
);
407 $tpl->set( 'debug', '' );
410 $tpl->set( 'reporttime', wfReportTime() );
411 $tpl->set( 'sitenotice', $this->getSiteNotice() );
412 $tpl->set( 'bottomscripts', $this->bottomScripts() );
413 $tpl->set( 'printfooter', $this->printSource() );
415 # Add a <div class="mw-content-ltr/rtl"> around the body text
416 # not for special pages or file pages AND only when viewing AND if the page exists
417 # (or is in MW namespace, because that has default content)
418 if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
419 in_array( $request->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) &&
420 ( $this->getTitle()->exists() ||
$this->getTitle()->getNamespace() == NS_MEDIAWIKI
) ) {
421 $pageLang = $this->getTitle()->getPageLanguage();
422 $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
423 'class' => 'mw-content-'.$pageLang->getDir() );
424 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
427 $tpl->setRef( 'bodytext', $out->mBodytext
);
430 $language_urls = array();
432 if ( !$wgHideInterlanguageLinks ) {
433 foreach( $out->getLanguageLinks() as $l ) {
434 $tmp = explode( ':', $l, 2 );
435 $class = 'interwiki-' . $tmp[0];
437 $nt = Title
::newFromText( $l );
439 $language_urls[] = array(
440 'href' => $nt->getFullURL(),
441 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
442 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
443 'title' => $nt->getText(),
449 if( count( $language_urls ) ) {
450 $tpl->setRef( 'language_urls', $language_urls );
452 $tpl->set( 'language_urls', false );
454 wfProfileOut( __METHOD__
. '-stuff4' );
456 wfProfileIn( __METHOD__
. '-stuff5' );
458 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
459 $content_navigation = $this->buildContentNavigationUrls();
460 $content_actions = $this->buildContentActionUrls( $content_navigation );
461 $tpl->setRef( 'content_navigation', $content_navigation );
462 $tpl->setRef( 'content_actions', $content_actions );
464 $tpl->set( 'sidebar', $this->buildSidebar() );
465 $tpl->set( 'nav_urls', $this->buildNavUrls() );
467 // Set the head scripts near the end, in case the above actions resulted in added scripts
468 if ( $this->useHeadElement
) {
469 $tpl->set( 'headelement', $out->headElement( $this ) );
471 $tpl->set( 'headscripts', $out->getScript() );
474 $tpl->set( 'debughtml', $this->generateDebugHTML() );
476 // original version by hansm
477 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
478 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
481 // Set the bodytext to another key so that skins can just output it on it's own
482 // and output printfooter and debughtml separately
483 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
485 // Append printfooter and debughtml onto bodytext so that skins that were already
486 // using bodytext before they were split out don't suddenly start not outputting information
487 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
488 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
490 // allow extensions adding stuff after the page content.
491 // See Skin::afterContentHook() for further documentation.
492 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
493 wfProfileOut( __METHOD__
. '-stuff5' );
496 wfProfileIn( __METHOD__
. '-execute' );
497 $res = $tpl->execute();
498 wfProfileOut( __METHOD__
. '-execute' );
500 // result may be an error
501 $this->printOrError( $res );
504 $this->setContext( $oldContext );
506 wfProfileOut( __METHOD__
);
510 * Output the string, or print error message if it's
511 * an error object of the appropriate type.
512 * For the base class, assume strings all around.
517 function printOrError( $str ) {
522 * Output a boolean indiciating if buildPersonalUrls should output separate
523 * login and create account links or output a combined link
524 * By default we simply return a global config setting that affects most skins
525 * This is setup as a method so that like with $wgLogo and getLogo() a skin
526 * can override this setting and always output one or the other if it has
527 * a reason it can't output one of the two modes.
529 function useCombinedLoginLink() {
530 global $wgUseCombinedLoginLink;
531 return $wgUseCombinedLoginLink;
535 * build array of urls for personal toolbar
538 protected function buildPersonalUrls() {
539 $title = $this->getTitle();
540 $request = $this->getRequest();
541 $pageurl = $title->getLocalURL();
542 wfProfileIn( __METHOD__
);
544 /* set up the default links for the personal toolbar */
545 $personal_urls = array();
547 # Due to bug 32276, if a user does not have read permissions,
548 # $this->getTitle() will just give Special:Badtitle, which is
549 # not especially useful as a returnto parameter. Use the title
550 # from the request instead, if there was one.
551 $page = Title
::newFromURL( $request->getVal( 'title', '' ) );
552 $page = $request->getVal( 'returnto', $page );
554 if ( strval( $page ) !== '' ) {
555 $a['returnto'] = $page;
556 $query = $request->getVal( 'returntoquery', $this->thisquery
);
558 $a['returntoquery'] = $query;
561 $returnto = wfArrayToCGI( $a );
562 if( $this->loggedin
) {
563 $personal_urls['userpage'] = array(
564 'text' => $this->userdisplayname
,
565 'href' => &$this->userpageUrlDetails
['href'],
566 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
567 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
569 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
570 $personal_urls['mytalk'] = array(
571 'text' => $this->msg( 'mytalk' )->text(),
572 'href' => &$usertalkUrlDetails['href'],
573 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
574 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
576 $href = self
::makeSpecialUrl( 'Preferences' );
577 $personal_urls['preferences'] = array(
578 'text' => $this->msg( 'mypreferences' )->text(),
580 'active' => ( $href == $pageurl )
582 $href = self
::makeSpecialUrl( 'Watchlist' );
583 $personal_urls['watchlist'] = array(
584 'text' => $this->msg( 'mywatchlist' )->text(),
586 'active' => ( $href == $pageurl )
589 # We need to do an explicit check for Special:Contributions, as we
590 # have to match both the title, and the target (which could come
591 # from request values or be specified in "sub page" form. The plot
592 # thickens, because $wgTitle is altered for special pages, so doesn't
593 # contain the original alias-with-subpage.
594 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
595 if( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
596 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
597 $active = $spName == 'Contributions'
598 && ( ( $spPar && $spPar == $this->username
)
599 ||
$request->getText( 'target' ) == $this->username
);
604 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
605 $personal_urls['mycontris'] = array(
606 'text' => $this->msg( 'mycontris' )->text(),
610 $personal_urls['logout'] = array(
611 'text' => $this->msg( 'userlogout' )->text(),
612 'href' => self
::makeSpecialUrl( 'Userlogout',
613 // userlogout link must always contain an & character, otherwise we might not be able
614 // to detect a buggy precaching proxy (bug 17790)
615 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
620 $useCombinedLoginLink = $this->useCombinedLoginLink();
621 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
622 ?
'nav-login-createaccount'
624 $is_signup = $request->getText('type') == "signup";
626 # anonlogin & login are the same
628 'text' => $this->msg( $loginlink )->text(),
629 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
630 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" ||
!$is_signup )
632 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
633 $createaccount_url = array(
634 'text' => $this->msg( 'createaccount' )->text(),
635 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
636 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
639 global $wgServer, $wgSecureLogin;
640 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
641 $title = SpecialPage
::getTitleFor( 'Userlogin' );
642 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
643 $login_url['href'] = $https_url;
644 # @todo FIXME: Class depends on skin
645 $login_url['class'] = 'link-https';
646 if ( isset($createaccount_url) ) {
647 $https_url = preg_replace( '/^http:/', 'https:',
648 $title->getFullURL("type=signup") );
649 $createaccount_url['href'] = $https_url;
650 # @todo FIXME: Class depends on skin
651 $createaccount_url['class'] = 'link-https';
656 if( $this->showIPinHeader() ) {
657 $href = &$this->userpageUrlDetails
['href'];
658 $personal_urls['anonuserpage'] = array(
659 'text' => $this->userdisplayname
,
661 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
662 'active' => ( $pageurl == $href )
664 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
665 $href = &$usertalkUrlDetails['href'];
666 $personal_urls['anontalk'] = array(
667 'text' => $this->msg( 'anontalk' )->text(),
669 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
670 'active' => ( $pageurl == $href )
672 $personal_urls['anonlogin'] = $login_url;
674 $personal_urls['login'] = $login_url;
676 if ( isset($createaccount_url) ) {
677 $personal_urls['createaccount'] = $createaccount_url;
681 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
682 wfProfileOut( __METHOD__
);
683 return $personal_urls;
688 * @param $title Title
689 * @param $message String message key
690 * @param $selected Bool
691 * @param $query String
692 * @param $checkEdit Bool
695 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
698 $classes[] = 'selected';
700 if( $checkEdit && !$title->isKnown() ) {
702 $query = 'action=edit&redlink=1';
705 // wfMessageFallback will nicely accept $message as an array of fallbacks
706 // or just a single key
707 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
708 if ( is_array($message) ) {
709 // for hook compatibility just keep the last message name
710 $message = end($message);
712 if ( $msg->exists() ) {
713 $text = $msg->text();
716 $text = $wgContLang->getFormattedNsText(
717 MWNamespace
::getSubject( $title->getNamespace() ) );
721 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
722 $title, $message, $selected, $checkEdit,
723 &$classes, &$query, &$text, &$result ) ) ) {
728 'class' => implode( ' ', $classes ),
730 'href' => $title->getLocalUrl( $query ),
734 function makeTalkUrlDetails( $name, $urlaction = '' ) {
735 $title = Title
::newFromText( $name );
736 if( !is_object( $title ) ) {
737 throw new MWException( __METHOD__
. " given invalid pagename $name" );
739 $title = $title->getTalkPage();
740 self
::checkTitle( $title, $name );
742 'href' => $title->getLocalURL( $urlaction ),
743 'exists' => $title->getArticleID() != 0,
747 function makeArticleUrlDetails( $name, $urlaction = '' ) {
748 $title = Title
::newFromText( $name );
749 $title= $title->getSubjectPage();
750 self
::checkTitle( $title, $name );
752 'href' => $title->getLocalURL( $urlaction ),
753 'exists' => $title->getArticleID() != 0,
758 * a structured array of links usually used for the tabs in a skin
760 * There are 4 standard sections
761 * namespaces: Used for namespace tabs like special, page, and talk namespaces
762 * views: Used for primary page views like read, edit, history
763 * actions: Used for most extra page actions like deletion, protection, etc...
764 * variants: Used to list the language variants for the page
766 * Each section's value is a key/value array of links for that section.
767 * The links themseves have these common keys:
768 * - class: The css classes to apply to the tab
769 * - text: The text to display on the tab
770 * - href: The href for the tab to point to
771 * - rel: An optional rel= for the tab's link
772 * - redundant: If true the tab will be dropped in skins using content_actions
773 * this is useful for tabs like "Read" which only have meaning in skins that
774 * take special meaning from the grouped structure of content_navigation
776 * Views also have an extra key which can be used:
777 * - primary: If this is not true skins like vector may try to hide the tab
778 * when the user has limited space in their browser window
780 * content_navigation using code also expects these ids to be present on the
781 * links, however these are usually automatically generated by SkinTemplate
782 * itself and are not necessary when using a hook. The only things these may
783 * matter to are people modifying content_navigation after it's initial creation:
784 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
785 * - tooltiponly: This is set to true for some tabs in cases where the system
786 * believes that the accesskey should not be added to the tab.
790 protected function buildContentNavigationUrls() {
791 global $wgDisableLangConversion;
793 wfProfileIn( __METHOD__
);
795 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
796 $onPage = $title->equals($this->getTitle());
798 $out = $this->getOutput();
799 $request = $this->getRequest();
800 $user = $this->getUser();
802 $content_navigation = array(
803 'namespaces' => array(),
805 'actions' => array(),
806 'variants' => array()
810 $action = $request->getVal( 'action', 'view' );
812 $userCanRead = $title->quickUserCan( 'read', $user );
814 $preventActiveTabs = false;
815 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
817 // Checks if page is some kind of content
818 if( $title->canExist() ) {
819 // Gets page objects for the related namespaces
820 $subjectPage = $title->getSubjectPage();
821 $talkPage = $title->getTalkPage();
823 // Determines if this is a talk page
824 $isTalk = $title->isTalkPage();
826 // Generates XML IDs from namespace names
827 $subjectId = $title->getNamespaceKey( '' );
829 if ( $subjectId == 'main' ) {
832 $talkId = "{$subjectId}_talk";
835 $skname = $this->skinname
;
837 // Adds namespace links
838 $subjectMsg = array( "nstab-$subjectId" );
839 if ( $subjectPage->isMainPage() ) {
840 array_unshift($subjectMsg, 'mainpage-nstab');
842 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
843 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
845 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
846 $content_navigation['namespaces'][$talkId] = $this->tabAction(
847 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
849 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
851 if ( $userCanRead ) {
852 // Adds view view link
853 if ( $title->exists() ) {
854 $content_navigation['views']['view'] = $this->tabAction(
855 $isTalk ?
$talkPage : $subjectPage,
856 array( "$skname-view-view", 'view' ),
857 ( $onPage && ($action == 'view' ||
$action == 'purge' ) ), '', true
859 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
862 wfProfileIn( __METHOD__
. '-edit' );
864 // Checks if user can edit the current page if it exists or create it otherwise
865 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
866 // Builds CSS class for talk page links
867 $isTalkClass = $isTalk ?
' istalk' : '';
868 // Whether the user is editing the page
869 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
870 // Whether to show the "Add a new section" tab
871 // Checks if this is a current rev of talk page and is not forced to be hidden
872 $showNewSection = !$out->forceHideNewSectionLink()
873 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
874 $section = $request->getVal( 'section' );
876 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
878 $content_navigation['views']['edit'] = array(
879 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
880 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
881 'href' => $title->getLocalURL( $this->editUrlOptions() ),
882 'primary' => true, // don't collapse this in vector
886 if ( $showNewSection ) {
887 // Adds new section link
888 //$content_navigation['actions']['addsection']
889 $content_navigation['views']['addsection'] = array(
890 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
891 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
892 'href' => $title->getLocalURL( 'action=edit§ion=new' )
895 // Checks if the page has some kind of viewable content
896 } elseif ( $title->hasSourceText() ) {
897 // Adds view source view link
898 $content_navigation['views']['viewsource'] = array(
899 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
900 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
901 'href' => $title->getLocalURL( $this->editUrlOptions() ),
902 'primary' => true, // don't collapse this in vector
905 wfProfileOut( __METHOD__
. '-edit' );
907 wfProfileIn( __METHOD__
. '-live' );
908 // Checks if the page exists
909 if ( $title->exists() ) {
910 // Adds history view link
911 $content_navigation['views']['history'] = array(
912 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
913 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
914 'href' => $title->getLocalURL( 'action=history' ),
918 if ( $title->quickUserCan( 'delete', $user ) ) {
919 $content_navigation['actions']['delete'] = array(
920 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
921 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
922 'href' => $title->getLocalURL( 'action=delete' )
926 if ( $title->quickUserCan( 'move', $user ) ) {
927 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
928 $content_navigation['actions']['move'] = array(
929 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
930 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
931 'href' => $moveTitle->getLocalURL()
935 // article doesn't exist or is deleted
936 if ( $user->isAllowed( 'deletedhistory' ) ) {
937 $n = $title->isDeleted();
939 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
940 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
941 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
942 $content_navigation['actions']['undelete'] = array(
943 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
944 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
945 ->setContext( $this->getContext() )->numParams( $n )->text(),
946 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
952 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) ) {
953 $mode = $title->isProtected() ?
'unprotect' : 'protect';
954 $content_navigation['actions'][$mode] = array(
955 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
956 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
957 'href' => $title->getLocalURL( "action=$mode" )
961 wfProfileOut( __METHOD__
. '-live' );
963 // Checks if the user is logged in
964 if ( $this->loggedin
) {
966 * The following actions use messages which, if made particular to
967 * the any specific skins, would break the Ajax code which makes this
968 * action happen entirely inline. Skin::makeGlobalVariablesScript
969 * defines a set of messages in a javascript object - and these
970 * messages are assumed to be global for all skins. Without making
971 * a change to that procedure these messages will have to remain as
972 * the global versions.
974 $mode = $title->userIsWatching() ?
'unwatch' : 'watch';
975 $token = WatchAction
::getWatchToken( $title, $user, $mode );
976 $content_navigation['actions'][$mode] = array(
977 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
978 'text' => $this->msg( $mode )->text(), // uses 'watch' or 'unwatch' message
979 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
984 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
986 if ( $userCanRead && !$wgDisableLangConversion ) {
987 $pageLang = $title->getPageLanguage();
988 // Gets list of language variants
989 $variants = $pageLang->getVariants();
990 // Checks that language conversion is enabled and variants exist
991 // And if it is not in the special namespace
992 if( count( $variants ) > 1 ) {
993 // Gets preferred variant (note that user preference is
994 // only possible for wiki content language variant)
995 $preferred = $pageLang->getPreferredVariant();
996 // Loops over each variant
997 foreach( $variants as $code ) {
998 // Gets variant name from language code
999 $varname = $pageLang->getVariantname( $code );
1000 // Checks if the variant is marked as disabled
1001 if( $varname == 'disable' ) {
1002 // Skips this variant
1005 // Appends variant link
1006 $content_navigation['variants'][] = array(
1007 'class' => ( $code == $preferred ) ?
'selected' : false,
1009 'href' => $title->getLocalURL( '', $code )
1015 // If it's not content, it's got to be a special page
1016 $content_navigation['namespaces']['special'] = array(
1017 'class' => 'selected',
1018 'text' => $this->msg( 'nstab-special' )->text(),
1019 'href' => $request->getRequestURL(), // @bug 2457, 2510
1020 'context' => 'subject'
1023 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1024 array( &$this, &$content_navigation ) );
1027 // Equiv to SkinTemplateContentActions
1028 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1030 // Setup xml ids and tooltip info
1031 foreach ( $content_navigation as $section => &$links ) {
1032 foreach ( $links as $key => &$link ) {
1034 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1035 $xmlID = 'ca-nstab-' . $xmlID;
1036 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1038 } elseif ( $section == "variants" ) {
1039 $xmlID = 'ca-varlang-' . $xmlID;
1041 $xmlID = 'ca-' . $xmlID;
1043 $link['id'] = $xmlID;
1047 # We don't want to give the watch tab an accesskey if the
1048 # page is being edited, because that conflicts with the
1049 # accesskey on the watch checkbox. We also don't want to
1050 # give the edit tab an accesskey, because that's fairly su-
1051 # perfluous and conflicts with an accesskey (Ctrl-E) often
1052 # used for editing in Safari.
1053 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1054 if ( isset($content_navigation['views']['edit']) ) {
1055 $content_navigation['views']['edit']['tooltiponly'] = true;
1057 if ( isset($content_navigation['actions']['watch']) ) {
1058 $content_navigation['actions']['watch']['tooltiponly'] = true;
1060 if ( isset($content_navigation['actions']['unwatch']) ) {
1061 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1065 wfProfileOut( __METHOD__
);
1067 return $content_navigation;
1071 * an array of edit links by default used for the tabs
1075 function buildContentActionUrls( $content_navigation ) {
1077 wfProfileIn( __METHOD__
);
1079 // content_actions has been replaced with content_navigation for backwards
1080 // compatibility and also for skins that just want simple tabs content_actions
1081 // is now built by flattening the content_navigation arrays into one
1083 $content_actions = array();
1085 foreach ( $content_navigation as $links ) {
1087 foreach ( $links as $key => $value ) {
1089 if ( isset($value["redundant"]) && $value["redundant"] ) {
1090 // Redundant tabs are dropped from content_actions
1094 // content_actions used to have ids built using the "ca-$key" pattern
1095 // so the xmlID based id is much closer to the actual $key that we want
1096 // for that reason we'll just strip out the ca- if present and use
1097 // the latter potion of the "id" as the $key
1098 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1099 $key = substr($value["id"], 3);
1102 if ( isset($content_actions[$key]) ) {
1103 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1107 $content_actions[$key] = $value;
1113 wfProfileOut( __METHOD__
);
1115 return $content_actions;
1119 * build array of common navigation links
1123 protected function buildNavUrls() {
1124 global $wgUploadNavigationUrl;
1126 wfProfileIn( __METHOD__
);
1128 $out = $this->getOutput();
1129 $request = $this->getRequest();
1131 $nav_urls = array();
1132 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1133 if( $wgUploadNavigationUrl ) {
1134 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1135 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1136 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1138 $nav_urls['upload'] = false;
1140 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1142 $nav_urls['print'] = false;
1143 $nav_urls['permalink'] = false;
1144 $nav_urls['whatlinkshere'] = false;
1145 $nav_urls['recentchangeslinked'] = false;
1146 $nav_urls['contributions'] = false;
1147 $nav_urls['log'] = false;
1148 $nav_urls['blockip'] = false;
1149 $nav_urls['emailuser'] = false;
1151 // A print stylesheet is attached to all pages, but nobody ever
1152 // figures that out. :) Add a link...
1153 if( $out->isArticle() ) {
1154 if ( !$out->isPrintable() ) {
1155 $nav_urls['print'] = array(
1156 'text' => $this->msg( 'printableversion' )->text(),
1157 'href' => $this->getTitle()->getLocalURL(
1158 $request->appendQueryValue( 'printable', 'yes', true ) )
1162 // Also add a "permalink" while we're at it
1163 $revid = $this->getRevisionId();
1165 $nav_urls['permalink'] = array(
1166 'text' => $this->msg( 'permalink' )->text(),
1167 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1171 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1172 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1173 array( &$this, &$nav_urls, &$revid, &$revid ) );
1176 if ( $out->isArticleRelated() ) {
1177 $nav_urls['whatlinkshere'] = array(
1178 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalUrl()
1180 if ( $this->getTitle()->getArticleId() ) {
1181 $nav_urls['recentchangeslinked'] = array(
1182 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalUrl()
1187 $user = $this->getRelevantUser();
1189 $rootUser = $user->getName();
1191 $nav_urls['contributions'] = array(
1192 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1195 if ( $user->isLoggedIn() ) {
1196 $logPage = SpecialPage
::getTitleFor( 'Log' );
1197 $nav_urls['log'] = array(
1198 'href' => $logPage->getLocalUrl( array( 'user' => $rootUser ) )
1202 if ( $this->getUser()->isAllowed( 'block' ) ) {
1203 $nav_urls['blockip'] = array(
1204 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1208 if ( $this->showEmailUser( $user ) ) {
1209 $nav_urls['emailuser'] = array(
1210 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1215 wfProfileOut( __METHOD__
);
1220 * Generate strings used for xml 'id' names
1224 function getNameSpaceKey() {
1225 return $this->getTitle()->getNamespaceKey();
1230 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1232 function setupUserJs( $allowUserJs ) {
1233 global $wgJsMimeType;
1234 wfProfileIn( __METHOD__
);
1236 if( $allowUserJs && $this->loggedin
) {
1237 if( $this->getTitle()->isJsSubpage() and $this->getOutput()->userCanPreview() ) {
1238 # XXX: additional security check/prompt?
1239 $this->userjsprev
= '/*<![CDATA[*/ ' . $this->getRequest()->getText( 'wpTextbox1' ) . ' /*]]>*/';
1241 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1244 wfProfileOut( __METHOD__
);
1247 public function commonPrintStylesheet() {
1253 * Generic wrapper for template functions, with interface
1254 * compatible with what we use of PHPTAL 0.7.
1257 abstract class QuickTemplate
{
1261 public function QuickTemplate() {
1262 $this->data
= array();
1263 $this->translator
= new MediaWiki_I18N();
1267 * Sets the value $value to $name
1271 public function set( $name, $value ) {
1272 $this->data
[$name] = $value;
1279 public function setRef( $name, &$value ) {
1280 $this->data
[$name] =& $value;
1286 public function setTranslator( &$t ) {
1287 $this->translator
= &$t;
1291 * Main function, used by classes that subclass QuickTemplate
1292 * to show the actual HTML output
1294 abstract public function execute();
1299 function text( $str ) {
1300 echo htmlspecialchars( $this->data
[$str] );
1306 function jstext( $str ) {
1307 echo Xml
::escapeJsString( $this->data
[$str] );
1313 function html( $str ) {
1314 echo $this->data
[$str];
1320 function msg( $str ) {
1321 echo htmlspecialchars( $this->translator
->translate( $str ) );
1327 function msgHtml( $str ) {
1328 echo $this->translator
->translate( $str );
1332 * An ugly, ugly hack.
1335 function msgWiki( $str ) {
1338 $text = $this->translator
->translate( $str );
1339 echo $wgOut->parse( $text );
1345 function haveData( $str ) {
1346 return isset( $this->data
[$str] );
1354 function haveMsg( $str ) {
1355 $msg = $this->translator
->translate( $str );
1356 return ( $msg != '-' ) && ( $msg != '' ); # ????
1360 * Get the Skin object related to this object
1362 * @return Skin object
1364 public function getSkin() {
1365 return $this->data
['skin'];
1370 * New base template for a skin's template extended from QuickTemplate
1371 * this class features helper methods that provide common ways of interacting
1372 * with the data stored in the QuickTemplate
1374 abstract class BaseTemplate
extends QuickTemplate
{
1377 * Get a Message object with its context set
1379 * @param $name Str message name
1382 public function getMsg( $name ) {
1383 return $this->getSkin()->msg( $name );
1386 function msg( $str ) {
1387 echo $this->getMsg( $str )->escaped();
1390 function msgHtml( $str ) {
1391 echo $this->getMsg( $str )->text();
1394 function msgWiki( $str ) {
1395 echo $this->getMsg( $str )->parseAsBlock();
1399 * Create an array of common toolbox items from the data in the quicktemplate
1400 * stored by SkinTemplate.
1401 * The resulting array is built acording to a format intended to be passed
1402 * through makeListItem to generate the html.
1404 function getToolbox() {
1405 wfProfileIn( __METHOD__
);
1408 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1409 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1410 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1412 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1413 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1414 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1415 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1417 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1418 $toolbox['feeds']['id'] = 'feedlinks';
1419 $toolbox['feeds']['links'] = array();
1420 foreach ( $this->data
['feeds'] as $key => $feed ) {
1421 $toolbox['feeds']['links'][$key] = $feed;
1422 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1423 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1424 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1425 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1428 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1429 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1430 $toolbox[$special] = $this->data
['nav_urls'][$special];
1431 $toolbox[$special]['id'] = "t-$special";
1434 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1435 $toolbox['print'] = $this->data
['nav_urls']['print'];
1436 $toolbox['print']['rel'] = 'alternate';
1437 $toolbox['print']['msg'] = 'printableversion';
1439 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1440 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1441 if( $toolbox['permalink']['href'] === '' ) {
1442 unset( $toolbox['permalink']['href'] );
1443 $toolbox['ispermalink']['tooltiponly'] = true;
1444 $toolbox['ispermalink']['id'] = 't-ispermalink';
1445 $toolbox['ispermalink']['msg'] = 'permalink';
1447 $toolbox['permalink']['id'] = 't-permalink';
1450 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1451 wfProfileOut( __METHOD__
);
1456 * Create an array of personal tools items from the data in the quicktemplate
1457 * stored by SkinTemplate.
1458 * The resulting array is built acording to a format intended to be passed
1459 * through makeListItem to generate the html.
1460 * This is in reality the same list as already stored in personal_urls
1461 * however it is reformatted so that you can just pass the individual items
1462 * to makeListItem instead of hardcoding the element creation boilerplate.
1465 function getPersonalTools() {
1466 $personal_tools = array();
1467 foreach( $this->data
['personal_urls'] as $key => $ptool ) {
1468 # The class on a personal_urls item is meant to go on the <a> instead
1469 # of the <li> so we have to use a single item "links" array instead
1470 # of using most of the personal_url's keys directly
1471 $personal_tools[$key] = array();
1472 $personal_tools[$key]["links"][] = array();
1473 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1474 if ( isset($ptool["active"]) ) {
1475 $personal_tools[$key]["active"] = $ptool["active"];
1477 foreach ( array("href", "class", "text") as $k ) {
1478 if ( isset($ptool[$k]) )
1479 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1482 return $personal_tools;
1485 function getSidebar( $options = array() ) {
1486 // Force the rendering of the following portals
1487 $sidebar = $this->data
['sidebar'];
1488 if ( !isset( $sidebar['SEARCH'] ) ) {
1489 $sidebar['SEARCH'] = true;
1491 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1492 $sidebar['TOOLBOX'] = true;
1494 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1495 $sidebar['LANGUAGES'] = true;
1498 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1499 unset( $sidebar['SEARCH'] );
1501 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1502 unset( $sidebar['TOOLBOX'] );
1504 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1505 unset( $sidebar['LANGUAGES'] );
1509 foreach ( $sidebar as $boxName => $content ) {
1510 if ( $content === false ) {
1513 switch ( $boxName ) {
1515 // Search is a special case, skins should custom implement this
1516 $boxes[$boxName] = array(
1518 'header' => $this->getMsg( 'search' )->text(),
1519 'generated' => false,
1524 $msgObj = $this->getMsg( 'toolbox' );
1525 $boxes[$boxName] = array(
1527 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1528 'generated' => false,
1529 'content' => $this->getToolbox(),
1533 if ( $this->data
['language_urls'] ) {
1534 $msgObj = $this->getMsg( 'otherlanguages' );
1535 $boxes[$boxName] = array(
1537 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1538 'generated' => false,
1539 'content' => $this->data
['language_urls'],
1544 $msgObj = $this->getMsg( $boxName );
1545 $boxes[$boxName] = array(
1546 'id' => "p-$boxName",
1547 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1548 'generated' => true,
1549 'content' => $content,
1555 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1556 $hookContents = null;
1557 if ( isset( $boxes['TOOLBOX'] ) ) {
1559 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1560 // can abort and avoid outputting double toolbox links
1561 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1562 $hookContents = ob_get_contents();
1564 if ( !trim( $hookContents ) ) {
1565 $hookContents = null;
1570 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1571 foreach ( $boxes as $boxName => $box ) {
1572 if ( is_array( $box['content'] ) ) {
1574 foreach ( $box['content'] as $key => $val ) {
1575 $content .= "\n " . $this->makeListItem( $key, $val );
1577 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1578 if ( $hookContents ) {
1579 $content .= "\n $hookContents";
1582 $content .= "\n</ul>\n";
1583 $boxes[$boxName]['content'] = $content;
1587 if ( $hookContents ) {
1588 $boxes['TOOLBOXEND'] = array(
1589 'id' => "p-toolboxend",
1590 'header' => $boxes['TOOLBOX']['header'],
1591 'generated' => false,
1592 'content' => "<ul>{$hookContents}</ul>",
1594 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1596 foreach ( $boxes as $key => $box ) {
1597 if ( $key === 'TOOLBOXEND' ) {
1600 $boxes2[$key] = $box;
1601 if ( $key === 'TOOLBOX' ) {
1602 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1614 * Makes a link, usually used by makeListItem to generate a link for an item
1615 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1617 * $key is a string, usually a key from the list you are generating this link from
1618 * $item is an array containing some of a specific set of keys.
1619 * The text of the link will be generated either from the contents of the "text"
1620 * key in the $item array, if a "msg" key is present a message by that name will
1621 * be used, and if neither of those are set the $key will be used as a message name.
1622 * If a "href" key is not present makeLink will just output htmlescaped text.
1623 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1624 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1625 * is present it will be used to generate a tooltip and accesskey for the link.
1626 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1627 * $options can be used to affect the output of a link:
1628 * You can use a text-wrapper key to specify a list of elements to wrap the
1629 * text of a link in. This should be an array of arrays containing a 'tag' and
1630 * optionally an 'attributes' key. If you only have one element you don't need
1631 * to wrap it in another array. eg: To use <a><span>...</span></a> in all links
1632 * use array( 'text-wrapper' => array( 'tag' => 'span' ) ) for your options.
1633 * A link-class key can be used to specify additional classes to apply to all links.
1634 * A link-fallback can be used to specify a tag to use instead of <a> if there is
1635 * no link. eg: If you specify 'link-fallback' => 'span' than any non-link will
1636 * output a <span> instead of just text.
1638 function makeLink( $key, $item, $options = array() ) {
1639 if ( isset( $item['text'] ) ) {
1640 $text = $item['text'];
1642 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1645 $html = htmlspecialchars( $text );
1647 if ( isset( $options['text-wrapper'] ) ) {
1648 $wrapper = $options['text-wrapper'];
1649 if ( isset( $wrapper['tag'] ) ) {
1650 $wrapper = array( $wrapper );
1652 while ( count( $wrapper ) > 0 ) {
1653 $element = array_pop( $wrapper );
1654 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1658 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1660 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1661 unset( $attrs[$k] );
1664 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1665 $item['single-id'] = $item['id'];
1667 if ( isset( $item['single-id'] ) ) {
1668 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1669 $title = Linker
::titleAttrib( $item['single-id'] );
1670 if ( $title !== false ) {
1671 $attrs['title'] = $title;
1674 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1675 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1676 $attrs['title'] = $tip['title'];
1678 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1679 $attrs['accesskey'] = $tip['accesskey'];
1683 if ( isset( $options['link-class'] ) ) {
1684 if ( isset( $attrs['class'] ) ) {
1685 $attrs['class'] .= " {$options['link-class']}";
1687 $attrs['class'] = $options['link-class'];
1690 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1697 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1698 * $key is a string, usually a key from the list you are generating this link from
1699 * $item is an array of list item data containing some of a specific set of keys.
1700 * The "id" and "class" keys will be used as attributes for the list item,
1701 * if "active" contains a value of true a "active" class will also be appended to class.
1702 * If you want something other than a <li> you can pass a tag name such as
1703 * "tag" => "span" in the $options array to change the tag used.
1704 * link/content data for the list item may come in one of two forms
1705 * A "links" key may be used, in which case it should contain an array with
1706 * a list of links to include inside the list item, see makeLink for the format
1707 * of individual links array items.
1708 * Otherwise the relevant keys from the list item $item array will be passed
1709 * to makeLink instead. Note however that "id" and "class" are used by the
1710 * list item directly so they will not be passed to makeLink
1711 * (however the link will still support a tooltip and accesskey from it)
1712 * If you need an id or class on a single link you should include a "links"
1713 * array with just one link item inside of it.
1714 * $options is also passed on to makeLink calls
1716 function makeListItem( $key, $item, $options = array() ) {
1717 if ( isset( $item['links'] ) ) {
1719 foreach ( $item['links'] as $linkKey => $link ) {
1720 $html .= $this->makeLink( $linkKey, $link, $options );
1724 // These keys are used by makeListItem and shouldn't be passed on to the link
1725 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1728 if ( isset( $item['id'] ) ) {
1729 // The id goes on the <li> not on the <a> for single links
1730 // but makeSidebarLink still needs to know what id to use when
1731 // generating tooltips and accesskeys.
1732 $link['single-id'] = $item['id'];
1734 $html = $this->makeLink( $key, $link, $options );
1738 foreach ( array( 'id', 'class' ) as $attr ) {
1739 if ( isset( $item[$attr] ) ) {
1740 $attrs[$attr] = $item[$attr];
1743 if ( isset( $item['active'] ) && $item['active'] ) {
1744 if ( !isset( $attrs['class'] ) ) {
1745 $attrs['class'] = '';
1747 $attrs['class'] .= ' active';
1748 $attrs['class'] = trim( $attrs['class'] );
1750 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1753 function makeSearchInput( $attrs = array() ) {
1757 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1759 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1760 return Html
::element( 'input', $realAttrs );
1763 function makeSearchButton( $mode, $attrs = array() ) {
1770 'value' => $this->translator
->translate(
1771 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1773 $realAttrs = array_merge(
1775 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1778 return Html
::element( 'input', $realAttrs );
1780 $buttonAttrs = array(
1784 $buttonAttrs = array_merge(
1786 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1789 unset( $buttonAttrs['src'] );
1790 unset( $buttonAttrs['alt'] );
1792 'src' => $attrs['src'],
1793 'alt' => isset( $attrs['alt'] )
1795 : $this->translator
->translate( 'searchbutton' ),
1797 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1799 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1804 * Returns an array of footerlinks trimmed down to only those footer links that
1806 * If you pass "flat" as an option then the returned array will be a flat array
1807 * of footer icons instead of a key/value array of footerlinks arrays broken
1808 * up into categories.
1810 function getFooterLinks( $option = null ) {
1811 $footerlinks = $this->data
['footerlinks'];
1813 // Reduce footer links down to only those which are being used
1814 $validFooterLinks = array();
1815 foreach( $footerlinks as $category => $links ) {
1816 $validFooterLinks[$category] = array();
1817 foreach( $links as $link ) {
1818 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1819 $validFooterLinks[$category][] = $link;
1822 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1823 unset( $validFooterLinks[$category] );
1827 if ( $option == 'flat' ) {
1828 // fold footerlinks into a single array using a bit of trickery
1829 $validFooterLinks = call_user_func_array(
1831 array_values( $validFooterLinks )
1835 return $validFooterLinks;
1839 * Returns an array of footer icons filtered down by options relevant to how
1840 * the skin wishes to display them.
1841 * If you pass "icononly" as the option all footer icons which do not have an
1842 * image icon set will be filtered out.
1843 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1844 * in the list of footer icons. This is mostly useful for skins which only
1845 * display the text from footericons instead of the images and don't want a
1846 * duplicate copyright statement because footerlinks already rendered one.
1848 function getFooterIcons( $option = null ) {
1849 // Generate additional footer icons
1850 $footericons = $this->data
['footericons'];
1852 if ( $option == 'icononly' ) {
1853 // Unset any icons which don't have an image
1854 foreach ( $footericons as &$footerIconsBlock ) {
1855 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1856 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1857 unset( $footerIconsBlock[$footerIconKey] );
1861 // Redo removal of any empty blocks
1862 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1863 if ( count( $footerIconsBlock ) <= 0 ) {
1864 unset( $footericons[$footerIconsKey] );
1867 } elseif ( $option == 'nocopyright' ) {
1868 unset( $footericons['copyright']['copyright'] );
1869 if ( count( $footericons['copyright'] ) <= 0 ) {
1870 unset( $footericons['copyright'] );
1874 return $footericons;
1878 * Output the basic end-page trail including bottomscripts, reporttime, and
1879 * debug stuff. This should be called right before outputting the closing
1880 * body and html tags.
1882 function printTrail() { ?
>
1883 <?php
$this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?
>
1884 <?php
$this->html('reporttime') ?
>
1885 <?php
if ( $this->data
['debug'] ): ?
>
1887 <?php
$this->text( 'debug' ); ?
>