3 * Base class for template-based skins
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 if ( !defined( 'MEDIAWIKI' ) ) {
28 * Wrapper object for MediaWiki's localization functions,
29 * to be passed to the template engine.
34 class MediaWiki_I18N
{
35 var $_context = array();
37 function set( $varName, $value ) {
38 $this->_context
[$varName] = $value;
41 function translate( $value ) {
42 wfProfileIn( __METHOD__
);
44 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
45 $value = preg_replace( '/^string:/', '', $value );
47 $value = wfMsg( $value );
48 // interpolate variables
50 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
51 list( $src, $var ) = $m;
53 $varValue = $this->_context
[$var];
55 $value = str_replace( $src, $varValue, $value );
57 wfProfileOut( __METHOD__
);
63 * Template-filler skin base class
64 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
65 * Based on Brion's smarty skin
66 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
68 * @todo Needs some serious refactoring into functions that correspond
69 * to the computations individual esi snippets need. Most importantly no body
70 * parsing for most of those of course.
74 class SkinTemplate
extends Skin
{
80 * Name of our skin, it probably needs to be all lower case. Child classes
81 * should override the default.
83 var $skinname = 'monobook';
86 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
87 * are located. Child classes should override the default.
89 var $stylename = 'monobook';
92 * For QuickTemplate, the name of the subclass which will actually fill the
93 * template. Child classes should override the default.
95 var $template = 'QuickTemplate';
98 * Whether this skin use OutputPage::headElement() to generate the <head>
101 var $useHeadElement = false;
106 * Add specific styles for this skin
108 * @param $out OutputPage
110 function setupSkinUserCss( OutputPage
$out ) {
111 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
119 * @param $classname String
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return QuickTemplate
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
130 * initialize various variables and generate the template
132 * @param $out OutputPage
134 function outputPage( OutputPage
$out ) {
135 global $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath;
137 global $wgMimeType, $wgJsMimeType, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
143 global $wgArticlePath, $wgScriptPath, $wgServer;
145 wfProfileIn( __METHOD__
);
146 Profiler
::instance()->setTemplated( true );
148 $oldid = $wgRequest->getVal( 'oldid' );
149 $diff = $wgRequest->getVal( 'diff' );
150 $action = $wgRequest->getVal( 'action', 'view' );
152 wfProfileIn( __METHOD__
. '-init' );
153 $this->initPage( $out );
155 $tpl = $this->setupTemplate( $this->template
, 'skins' );
156 wfProfileOut( __METHOD__
. '-init' );
158 wfProfileIn( __METHOD__
. '-stuff' );
159 $this->thispage
= $this->getTitle()->getPrefixedDBkey();
160 $this->thisurl
= $this->getTitle()->getPrefixedURL();
162 if ( !$wgRequest->wasPosted() ) {
163 $query = $wgRequest->getValues();
164 unset( $query['title'] );
165 unset( $query['returnto'] );
166 unset( $query['returntoquery'] );
168 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
169 $this->loggedin
= $wgUser->isLoggedIn();
170 $this->iscontent
= ( $this->getTitle()->getNamespace() != NS_SPECIAL
);
171 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
172 $this->username
= $wgUser->getName();
174 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
175 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
177 # This won't be used in the standard skins, but we define it to preserve the interface
178 # To save time, we check for existence
179 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
182 $this->titletxt
= $this->getTitle()->getPrefixedText();
183 wfProfileOut( __METHOD__
. '-stuff' );
185 wfProfileIn( __METHOD__
. '-stuff-head' );
186 if ( !$this->useHeadElement
) {
187 $this->setupUserCss( $out );
189 $tpl->set( 'pagecss', false );
190 $tpl->set( 'usercss', false );
192 $this->userjs
= $this->userjsprev
= false;
193 # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we
194 # get rid of it? For that matter, why is any of this here at all?
195 $this->setupUserJs( $out->isUserJsAllowed() );
196 $tpl->setRef( 'userjs', $this->userjs
);
197 $tpl->setRef( 'userjsprev', $this->userjsprev
);
200 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
201 $tpl->set( 'jsvarurl',
203 "action=raw$jsCache&gen=js&useskin=" .
204 urlencode( $this->getSkinName() ) ) );
206 $tpl->set( 'jsvarurl', false );
209 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
210 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
211 $tpl->set( 'html5version', $wgHtml5Version );
212 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
213 $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
215 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
216 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
218 $tpl->set( 'trackbackhtml', null );
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
);
227 $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
228 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
230 $nsname = MWNamespace
::exists( $this->getTitle()->getNamespace() ) ?
231 MWNamespace
::getCanonicalName( $this->getTitle()->getNamespace() ) :
232 $this->getTitle()->getNsText();
234 $tpl->set( 'nscanonical', $nsname );
235 $tpl->set( 'nsnumber', $this->getTitle()->getNamespace() );
236 $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
237 $tpl->set( 'titletext', $this->getTitle()->getText() );
238 $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
239 $tpl->set( 'currevisionid', $this->getTitle()->getLatestRevID() );
241 $tpl->set( 'isarticle', $out->isArticle() );
243 $tpl->setRef( 'thispage', $this->thispage
);
244 $subpagestr = $this->subPageSubtitle();
246 'subtitle', !empty( $subpagestr ) ?
247 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
250 $undelete = $this->getUndeleteLink();
252 'undelete', !empty( $undelete ) ?
253 '<span class="subpages">' . $undelete . '</span>' :
257 $tpl->set( 'catlinks', $this->getCategories() );
258 if( $out->isSyndicated() ) {
260 foreach( $out->getSyndicationLinks() as $format => $link ) {
261 $feeds[$format] = array(
262 'text' => wfMsg( "feed-$format" ),
266 $tpl->setRef( 'feeds', $feeds );
268 $tpl->set( 'feeds', false );
271 $tpl->setRef( 'mimetype', $wgMimeType );
272 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
273 $tpl->set( 'charset', 'UTF-8' );
274 $tpl->setRef( 'wgScript', $wgScript );
275 $tpl->setRef( 'skinname', $this->skinname
);
276 $tpl->set( 'skinclass', get_class( $this ) );
277 $tpl->setRef( 'stylename', $this->stylename
);
278 $tpl->set( 'printable', $out->isPrintable() );
279 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
280 $tpl->setRef( 'loggedin', $this->loggedin
);
281 $tpl->set( 'notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL
);
282 /* XXX currently unused, might get useful later
283 $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) );
284 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
285 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
286 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
287 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
289 $tpl->set( 'searchaction', $this->escapeSearchLink() );
290 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
291 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
292 $tpl->setRef( 'stylepath', $wgStylePath );
293 $tpl->setRef( 'articlepath', $wgArticlePath );
294 $tpl->setRef( 'scriptpath', $wgScriptPath );
295 $tpl->setRef( 'serverurl', $wgServer );
296 $tpl->setRef( 'logopath', $wgLogo );
298 $contentlang = $wgContLang->getCode();
299 $contentdir = $wgContLang->getDir();
300 $userlang = $wgLang->getCode();
301 $userdir = $wgLang->getDir();
303 $tpl->set( 'lang', $userlang );
304 $tpl->set( 'dir', $userdir );
305 $tpl->set( 'rtl', $wgLang->isRTL() );
307 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
308 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
309 $tpl->set( 'username', $wgUser->isAnon() ?
null : $this->username
);
310 $tpl->setRef( 'userpage', $this->userpage
);
311 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
312 $tpl->set( 'userlang', $userlang );
314 // Users can have their language set differently than the
315 // content of the wiki. For these users, tell the web browser
316 // that interface elements are in a different language.
317 $tpl->set( 'userlangattributes', '' );
318 $tpl->set( 'specialpageattributes', '' ); # obsolete
320 if ( $userlang !== $contentlang ||
$userdir !== $contentdir ) {
321 $attrs = " lang='$userlang' dir='$userdir'";
322 $tpl->set( 'userlangattributes', $attrs );
325 $newtalks = $this->getNewtalks( $out );
327 wfProfileOut( __METHOD__
. '-stuff2' );
329 wfProfileIn( __METHOD__
. '-stuff3' );
330 $tpl->setRef( 'newtalk', $newtalks );
331 $tpl->setRef( 'skin', $this );
332 $tpl->set( 'logo', $this->logoText() );
333 if ( $out->isArticle() && ( !isset( $oldid ) ||
isset( $diff ) ) &&
334 $this->getTitle()->exists() )
336 $article = new Article( $this->getTitle(), 0 );
337 if ( !$wgDisableCounters ) {
338 $viewcount = $wgLang->formatNum( $article->getCount() );
340 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
342 $tpl->set( 'viewcount', false );
345 $tpl->set( 'viewcount', false );
348 if( $wgPageShowWatchingUsers ) {
349 $dbr = wfGetDB( DB_SLAVE
);
350 $res = $dbr->select( 'watchlist',
351 array( 'COUNT(*) AS n' ),
352 array( 'wl_title' => $dbr->strencode( $this->getTitle()->getDBkey() ), 'wl_namespace' => $this->getTitle()->getNamespace() ),
355 $x = $dbr->fetchObject( $res );
356 $numberofwatchingusers = $x->n
;
357 if( $numberofwatchingusers > 0 ) {
358 $tpl->set( 'numberofwatchingusers',
359 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
360 $wgLang->formatNum( $numberofwatchingusers ) )
363 $tpl->set( 'numberofwatchingusers', false );
366 $tpl->set( 'numberofwatchingusers', false );
369 $tpl->set( 'copyright', $this->getCopyright() );
371 $this->credits
= false;
373 if( $wgMaxCredits != 0 ){
374 $this->credits
= Action
::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax );
376 $tpl->set( 'lastmod', $this->lastModified( $article ) );
379 $tpl->setRef( 'credits', $this->credits
);
381 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
382 $tpl->set( 'copyright', $this->getCopyright() );
383 $tpl->set( 'viewcount', false );
384 $tpl->set( 'lastmod', false );
385 $tpl->set( 'credits', false );
386 $tpl->set( 'numberofwatchingusers', false );
388 $tpl->set( 'copyright', false );
389 $tpl->set( 'viewcount', false );
390 $tpl->set( 'lastmod', false );
391 $tpl->set( 'credits', false );
392 $tpl->set( 'numberofwatchingusers', false );
394 wfProfileOut( __METHOD__
. '-stuff3' );
396 wfProfileIn( __METHOD__
. '-stuff4' );
397 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
398 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
399 $tpl->set( 'disclaimer', $this->disclaimerLink() );
400 $tpl->set( 'privacy', $this->privacyLink() );
401 $tpl->set( 'about', $this->aboutLink() );
403 $tpl->set( 'footerlinks', array(
407 'numberofwatchingusers',
418 global $wgFooterIcons;
419 $tpl->set( 'footericons', $wgFooterIcons );
420 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
421 if ( count( $footerIconsBlock ) > 0 ) {
422 foreach ( $footerIconsBlock as &$footerIcon ) {
423 if ( isset( $footerIcon['src'] ) ) {
424 if ( !isset( $footerIcon['width'] ) ) {
425 $footerIcon['width'] = 88;
427 if ( !isset( $footerIcon['height'] ) ) {
428 $footerIcon['height'] = 31;
433 unset( $tpl->data
['footericons'][$footerIconsKey] );
437 if ( $wgDebugComments ) {
438 $tpl->setRef( 'debug', $out->mDebugtext
);
440 $tpl->set( 'debug', '' );
443 $tpl->set( 'reporttime', wfReportTime() );
444 $tpl->set( 'sitenotice', $this->getSiteNotice() );
445 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
446 $tpl->set( 'printfooter', $this->printSource() );
448 # Add a <div class="mw-content-ltr/rtl"> around the body text
449 # not for special pages or file pages AND only when viewing AND if the page exists
450 # (or is in MW namespace, because that has default content)
451 if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
452 in_array( $action, array( 'view', 'historysubmit' ) ) &&
453 ( $this->getTitle()->exists() ||
$this->getTitle()->getNamespace() == NS_MEDIAWIKI
) ) {
454 $pageLang = $this->getTitle()->getPageLanguage();
455 $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
456 'class' => 'mw-content-'.$pageLang->getDir() );
457 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
460 $tpl->setRef( 'bodytext', $out->mBodytext
);
463 $language_urls = array();
465 if ( !$wgHideInterlanguageLinks ) {
466 foreach( $out->getLanguageLinks() as $l ) {
467 $tmp = explode( ':', $l, 2 );
468 $class = 'interwiki-' . $tmp[0];
470 $nt = Title
::newFromText( $l );
472 $language_urls[] = array(
473 'href' => $nt->getFullURL(),
474 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
475 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
476 'title' => $nt->getText(),
482 if( count( $language_urls ) ) {
483 $tpl->setRef( 'language_urls', $language_urls );
485 $tpl->set( 'language_urls', false );
487 wfProfileOut( __METHOD__
. '-stuff4' );
489 wfProfileIn( __METHOD__
. '-stuff5' );
491 $tpl->set( 'personal_urls', $this->buildPersonalUrls( $out ) );
492 $content_navigation = $this->buildContentNavigationUrls( $out );
493 $content_actions = $this->buildContentActionUrls( $content_navigation );
494 $tpl->setRef( 'content_navigation', $content_navigation );
495 $tpl->setRef( 'content_actions', $content_actions );
497 $tpl->set( 'sidebar', $this->buildSidebar() );
498 $tpl->set( 'nav_urls', $this->buildNavUrls( $out ) );
500 // Set the head scripts near the end, in case the above actions resulted in added scripts
501 if ( $this->useHeadElement
) {
502 $tpl->set( 'headelement', $out->headElement( $this ) );
504 $tpl->set( 'headscripts', $out->getScript() );
507 $tpl->set( 'debughtml', $this->generateDebugHTML() );
509 // original version by hansm
510 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
511 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
514 // allow extensions adding stuff after the page content.
515 // See Skin::afterContentHook() for further documentation.
516 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
517 wfProfileOut( __METHOD__
. '-stuff5' );
520 wfProfileIn( __METHOD__
. '-execute' );
521 $res = $tpl->execute();
522 wfProfileOut( __METHOD__
. '-execute' );
524 // result may be an error
525 $this->printOrError( $res );
526 wfProfileOut( __METHOD__
);
530 * Output the string, or print error message if it's
531 * an error object of the appropriate type.
532 * For the base class, assume strings all around.
537 function printOrError( $str ) {
542 * Output a boolean indiciating if buildPersonalUrls should output separate
543 * login and create account links or output a combined link
544 * By default we simply return a global config setting that affects most skins
545 * This is setup as a method so that like with $wgLogo and getLogo() a skin
546 * can override this setting and always output one or the other if it has
547 * a reason it can't output one of the two modes.
549 function useCombinedLoginLink() {
550 global $wgUseCombinedLoginLink;
551 return $wgUseCombinedLoginLink;
555 * build array of urls for personal toolbar
558 protected function buildPersonalUrls( OutputPage
$out ) {
561 $title = $out->getTitle();
562 $pageurl = $title->getLocalURL();
563 wfProfileIn( __METHOD__
);
565 /* set up the default links for the personal toolbar */
566 $personal_urls = array();
568 // Get the returnto and returntoquery parameters from the query string
569 // or fall back on $this->thisurl or $this->thisquery
570 // We can't use getVal()'s default value feature here because
571 // stuff from $wgRequest needs to be escaped, but thisurl and thisquery
572 // are already escaped.
573 $page = $wgRequest->getVal( 'returnto' );
574 if ( !is_null( $page ) ) {
575 $page = wfUrlencode( $page );
577 $page = $this->thisurl
;
579 $query = $wgRequest->getVal( 'returntoquery' );
580 if ( !is_null( $query ) ) {
581 $query = wfUrlencode( $query );
583 $query = $this->thisquery
;
585 $returnto = "returnto=$page";
587 $returnto .= "&returntoquery=$query";
589 if( $this->loggedin
) {
590 $personal_urls['userpage'] = array(
591 'text' => $this->username
,
592 'href' => &$this->userpageUrlDetails
['href'],
593 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
594 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
596 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
597 $personal_urls['mytalk'] = array(
598 'text' => wfMsg( 'mytalk' ),
599 'href' => &$usertalkUrlDetails['href'],
600 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
601 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
603 $href = self
::makeSpecialUrl( 'Preferences' );
604 $personal_urls['preferences'] = array(
605 'text' => wfMsg( 'mypreferences' ),
607 'active' => ( $href == $pageurl )
609 $href = self
::makeSpecialUrl( 'Watchlist' );
610 $personal_urls['watchlist'] = array(
611 'text' => wfMsg( 'mywatchlist' ),
613 'active' => ( $href == $pageurl )
616 # We need to do an explicit check for Special:Contributions, as we
617 # have to match both the title, and the target (which could come
618 # from request values or be specified in "sub page" form. The plot
619 # thickens, because $wgTitle is altered for special pages, so doesn't
620 # contain the original alias-with-subpage.
621 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
622 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
623 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
624 $active = $spName == 'Contributions'
625 && ( ( $spPar && $spPar == $this->username
)
626 ||
$wgRequest->getText( 'target' ) == $this->username
);
631 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
632 $personal_urls['mycontris'] = array(
633 'text' => wfMsg( 'mycontris' ),
637 $personal_urls['logout'] = array(
638 'text' => wfMsg( 'userlogout' ),
639 'href' => self
::makeSpecialUrl( 'Userlogout',
640 // userlogout link must always contain an & character, otherwise we might not be able
641 // to detect a buggy precaching proxy (bug 17790)
642 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
648 $useCombinedLoginLink = $this->useCombinedLoginLink();
649 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
650 ?
'nav-login-createaccount'
652 $is_signup = $wgRequest->getText('type') == "signup";
654 # anonlogin & login are the same
656 'text' => wfMsg( $loginlink ),
657 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
658 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" ||
!$is_signup )
660 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
661 $createaccount_url = array(
662 'text' => wfMsg( 'createaccount' ),
663 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
664 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
667 global $wgServer, $wgSecureLogin;
668 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
669 $title = SpecialPage
::getTitleFor( 'Userlogin' );
670 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
671 $login_url['href'] = $https_url;
672 # @todo FIXME: Class depends on skin
673 $login_url['class'] = 'link-https';
674 if ( isset($createaccount_url) ) {
675 $https_url = preg_replace( '/^http:/', 'https:',
676 $title->getFullURL("type=signup") );
677 $createaccount_url['href'] = $https_url;
678 # @todo FIXME: Class depends on skin
679 $createaccount_url['class'] = 'link-https';
684 if( $this->showIPinHeader() ) {
685 $href = &$this->userpageUrlDetails
['href'];
686 $personal_urls['anonuserpage'] = array(
687 'text' => $this->username
,
689 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
690 'active' => ( $pageurl == $href )
692 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
693 $href = &$usertalkUrlDetails['href'];
694 $personal_urls['anontalk'] = array(
695 'text' => wfMsg( 'anontalk' ),
697 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
698 'active' => ( $pageurl == $href )
700 $personal_urls['anonlogin'] = $login_url;
702 $personal_urls['login'] = $login_url;
704 if ( isset($createaccount_url) ) {
705 $personal_urls['createaccount'] = $createaccount_url;
709 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
710 wfProfileOut( __METHOD__
);
711 return $personal_urls;
716 * @param $title Title
717 * @param $message String message key
718 * @param $selected Bool
719 * @param $query String
720 * @param $checkEdit Bool
723 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
726 $classes[] = 'selected';
728 if( $checkEdit && !$title->isKnown() ) {
730 $query = 'action=edit&redlink=1';
733 // wfMessageFallback will nicely accept $message as an array of fallbacks
734 // or just a single key
735 $msg = wfMessageFallback( $message );
736 if ( is_array($message) ) {
737 // for hook compatibility just keep the last message name
738 $message = end($message);
740 if ( $msg->exists() ) {
741 $text = $msg->text();
744 $text = $wgContLang->getFormattedNsText(
745 MWNamespace
::getSubject( $title->getNamespace() ) );
749 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
750 $title, $message, $selected, $checkEdit,
751 &$classes, &$query, &$text, &$result ) ) ) {
756 'class' => implode( ' ', $classes ),
758 'href' => $title->getLocalUrl( $query ),
762 function makeTalkUrlDetails( $name, $urlaction = '' ) {
763 $title = Title
::newFromText( $name );
764 if( !is_object( $title ) ) {
765 throw new MWException( __METHOD__
. " given invalid pagename $name" );
767 $title = $title->getTalkPage();
768 self
::checkTitle( $title, $name );
770 'href' => $title->getLocalURL( $urlaction ),
771 'exists' => $title->getArticleID() != 0,
775 function makeArticleUrlDetails( $name, $urlaction = '' ) {
776 $title = Title
::newFromText( $name );
777 $title= $title->getSubjectPage();
778 self
::checkTitle( $title, $name );
780 'href' => $title->getLocalURL( $urlaction ),
781 'exists' => $title->getArticleID() != 0,
786 * a structured array of links usually used for the tabs in a skin
788 * There are 4 standard sections
789 * namespaces: Used for namespace tabs like special, page, and talk namespaces
790 * views: Used for primary page views like read, edit, history
791 * actions: Used for most extra page actions like deletion, protection, etc...
792 * variants: Used to list the language variants for the page
794 * Each section's value is a key/value array of links for that section.
795 * The links themseves have these common keys:
796 * - class: The css classes to apply to the tab
797 * - text: The text to display on the tab
798 * - href: The href for the tab to point to
799 * - rel: An optional rel= for the tab's link
800 * - redundant: If true the tab will be dropped in skins using content_actions
801 * this is useful for tabs like "Read" which only have meaning in skins that
802 * take special meaning from the grouped structure of content_navigation
804 * Views also have an extra key which can be used:
805 * - primary: If this is not true skins like vector may try to hide the tab
806 * when the user has limited space in their browser window
808 * content_navigation using code also expects these ids to be present on the
809 * links, however these are usually automatically generated by SkinTemplate
810 * itself and are not necessary when using a hook. The only things these may
811 * matter to are people modifying content_navigation after it's initial creation:
812 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
813 * - tooltiponly: This is set to true for some tabs in cases where the system
814 * believes that the accesskey should not be added to the tab.
818 protected function buildContentNavigationUrls( OutputPage
$out ) {
819 global $wgContLang, $wgLang, $wgUser, $wgRequest;
820 global $wgDisableLangConversion;
822 wfProfileIn( __METHOD__
);
824 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
825 $onPage = $title->equals($this->getTitle());
827 $content_navigation = array(
828 'namespaces' => array(),
830 'actions' => array(),
831 'variants' => array()
835 $action = $wgRequest->getVal( 'action', 'view' );
836 $section = $wgRequest->getVal( 'section' );
838 $userCanRead = $title->userCanRead();
839 $skname = $this->skinname
;
841 $preventActiveTabs = false;
842 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
844 // Checks if page is some kind of content
845 if( $title->getNamespace() != NS_SPECIAL
) {
846 // Gets page objects for the related namespaces
847 $subjectPage = $title->getSubjectPage();
848 $talkPage = $title->getTalkPage();
850 // Determines if this is a talk page
851 $isTalk = $title->isTalkPage();
853 // Generates XML IDs from namespace names
854 $subjectId = $title->getNamespaceKey( '' );
856 if ( $subjectId == 'main' ) {
859 $talkId = "{$subjectId}_talk";
862 // Adds namespace links
863 $subjectMsg = array( "nstab-$subjectId" );
864 if ( $subjectPage->isMainPage() ) {
865 array_unshift($subjectMsg, 'mainpage-nstab');
867 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
868 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
870 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
871 $content_navigation['namespaces'][$talkId] = $this->tabAction(
872 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
874 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
876 // Adds view view link
877 if ( $title->exists() && $userCanRead ) {
878 $content_navigation['views']['view'] = $this->tabAction(
879 $isTalk ?
$talkPage : $subjectPage,
880 array( "$skname-view-view", 'view' ),
881 ( $onPage && ($action == 'view' ||
$action == 'purge' ) ), '', true
883 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
886 wfProfileIn( __METHOD__
. '-edit' );
888 // Checks if user can...
890 // read and edit the current page
891 $userCanRead && $title->quickUserCan( 'edit' ) &&
895 // or they can create one here
896 $title->quickUserCan( 'create' )
899 // Builds CSS class for talk page links
900 $isTalkClass = $isTalk ?
' istalk' : '';
902 // Determines if we're in edit mode
905 ( $action == 'edit' ||
$action == 'submit' ) &&
906 ( $section != 'new' )
908 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
910 $content_navigation['views']['edit'] = array(
911 'class' => ( $selected ?
'selected' : '' ) . $isTalkClass,
912 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
913 'href' => $title->getLocalURL( $this->editUrlOptions() ),
914 'primary' => true, // don't collapse this in vector
916 // Checks if this is a current rev of talk page and we should show a new
918 if ( ( $isTalk && $this->isRevisionCurrent() ) ||
( $out->showNewSectionLink() ) ) {
919 // Checks if we should ever show a new section link
920 if ( !$out->forceHideNewSectionLink() ) {
921 // Adds new section link
922 //$content_navigation['actions']['addsection']
923 $content_navigation['views']['addsection'] = array(
924 'class' => $section == 'new' ?
'selected' : false,
925 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
926 'href' => $title->getLocalURL( 'action=edit§ion=new' )
930 // Checks if the page has some kind of viewable content
931 } elseif ( $title->hasSourceText() && $userCanRead ) {
932 // Adds view source view link
933 $content_navigation['views']['viewsource'] = array(
934 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
935 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
936 'href' => $title->getLocalURL( $this->editUrlOptions() ),
937 'primary' => true, // don't collapse this in vector
940 wfProfileOut( __METHOD__
. '-edit' );
942 wfProfileIn( __METHOD__
. '-live' );
944 // Checks if the page exists
945 if ( $title->exists() && $userCanRead ) {
946 // Adds history view link
947 $content_navigation['views']['history'] = array(
948 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
949 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
950 'href' => $title->getLocalURL( 'action=history' ),
954 if( $wgUser->isAllowed( 'delete' ) ) {
955 $content_navigation['actions']['delete'] = array(
956 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
957 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
958 'href' => $title->getLocalURL( 'action=delete' )
961 if ( $title->quickUserCan( 'move' ) ) {
962 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
963 $content_navigation['actions']['move'] = array(
964 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
965 'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
966 'href' => $moveTitle->getLocalURL()
970 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
971 $mode = !$title->isProtected() ?
'protect' : 'unprotect';
972 $content_navigation['actions'][$mode] = array(
973 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
974 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
975 'href' => $title->getLocalURL( "action=$mode" )
979 // article doesn't exist or is deleted
980 if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
981 $includeSuppressed = $wgUser->isAllowed( 'suppressrevision' );
982 $n = $title->isDeleted( $includeSuppressed );
984 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
985 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
986 $msgKey = $wgUser->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
987 $content_navigation['actions']['undelete'] = array(
988 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
989 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
990 ->params( $wgLang->formatNum( $n ) )->text(),
991 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
996 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
997 $mode = !$title->getRestrictions( 'create' ) ?
'protect' : 'unprotect';
998 $content_navigation['actions'][$mode] = array(
999 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1000 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
1001 'href' => $title->getLocalURL( "action=$mode" )
1005 wfProfileOut( __METHOD__
. '-live' );
1007 // Checks if the user is logged in
1008 if ( $this->loggedin
) {
1010 * The following actions use messages which, if made particular to
1011 * the any specific skins, would break the Ajax code which makes this
1012 * action happen entirely inline. Skin::makeGlobalVariablesScript
1013 * defines a set of messages in a javascript object - and these
1014 * messages are assumed to be global for all skins. Without making
1015 * a change to that procedure these messages will have to remain as
1016 * the global versions.
1018 $mode = $title->userIsWatching() ?
'unwatch' : 'watch';
1019 $token = WatchAction
::getWatchToken( $title, $wgUser, $mode );
1020 $content_navigation['actions'][$mode] = array(
1021 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1022 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
1023 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1027 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1029 // If it's not content, it's got to be a special page
1030 $content_navigation['namespaces']['special'] = array(
1031 'class' => 'selected',
1032 'text' => wfMsg( 'nstab-special' ),
1033 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
1034 'context' => 'subject'
1037 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1038 array( &$this, &$content_navigation ) );
1041 // Gets list of language variants
1042 $variants = $wgContLang->getVariants();
1043 // Checks that language conversion is enabled and variants exist
1044 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
1045 // Gets preferred variant
1046 $preferred = $wgContLang->getPreferredVariant();
1047 // Loops over each variant
1048 foreach( $variants as $code ) {
1049 // Gets variant name from language code
1050 $varname = $wgContLang->getVariantname( $code );
1051 // Checks if the variant is marked as disabled
1052 if( $varname == 'disable' ) {
1053 // Skips this variant
1056 // Appends variant link
1057 $content_navigation['variants'][] = array(
1058 'class' => ( $code == $preferred ) ?
'selected' : false,
1060 'href' => $title->getLocalURL( '', $code )
1065 // Equiv to SkinTemplateContentActions
1066 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1068 // Setup xml ids and tooltip info
1069 foreach ( $content_navigation as $section => &$links ) {
1070 foreach ( $links as $key => &$link ) {
1072 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1073 $xmlID = 'ca-nstab-' . $xmlID;
1074 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1076 } elseif ( $section == "variants" ) {
1077 $xmlID = 'ca-varlang-' . $xmlID;
1079 $xmlID = 'ca-' . $xmlID;
1081 $link['id'] = $xmlID;
1085 # We don't want to give the watch tab an accesskey if the
1086 # page is being edited, because that conflicts with the
1087 # accesskey on the watch checkbox. We also don't want to
1088 # give the edit tab an accesskey, because that's fairly su-
1089 # perfluous and conflicts with an accesskey (Ctrl-E) often
1090 # used for editing in Safari.
1091 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1092 if ( isset($content_navigation['views']['edit']) ) {
1093 $content_navigation['views']['edit']['tooltiponly'] = true;
1095 if ( isset($content_navigation['actions']['watch']) ) {
1096 $content_navigation['actions']['watch']['tooltiponly'] = true;
1098 if ( isset($content_navigation['actions']['unwatch']) ) {
1099 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1103 wfProfileOut( __METHOD__
);
1105 return $content_navigation;
1109 * an array of edit links by default used for the tabs
1113 function buildContentActionUrls( $content_navigation ) {
1115 wfProfileIn( __METHOD__
);
1117 // content_actions has been replaced with content_navigation for backwards
1118 // compatibility and also for skins that just want simple tabs content_actions
1119 // is now built by flattening the content_navigation arrays into one
1121 $content_actions = array();
1123 foreach ( $content_navigation as $links ) {
1125 foreach ( $links as $key => $value ) {
1127 if ( isset($value["redundant"]) && $value["redundant"] ) {
1128 // Redundant tabs are dropped from content_actions
1132 // content_actions used to have ids built using the "ca-$key" pattern
1133 // so the xmlID based id is much closer to the actual $key that we want
1134 // for that reason we'll just strip out the ca- if present and use
1135 // the latter potion of the "id" as the $key
1136 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1137 $key = substr($value["id"], 3);
1140 if ( isset($content_actions[$key]) ) {
1141 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1145 $content_actions[$key] = $value;
1151 wfProfileOut( __METHOD__
);
1153 return $content_actions;
1157 * build array of common navigation links
1161 protected function buildNavUrls( OutputPage
$out ) {
1162 global $wgUseTrackbacks, $wgUser, $wgRequest;
1163 global $wgUploadNavigationUrl;
1165 wfProfileIn( __METHOD__
);
1167 $action = $wgRequest->getVal( 'action', 'view' );
1169 $nav_urls = array();
1170 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1171 if( $wgUploadNavigationUrl ) {
1172 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1173 } elseif( UploadBase
::isEnabled() && UploadBase
::isAllowed( $wgUser ) === true ) {
1174 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1176 $nav_urls['upload'] = false;
1178 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1180 // default permalink to being off, will override it as required below.
1181 $nav_urls['permalink'] = false;
1183 // A print stylesheet is attached to all pages, but nobody ever
1184 // figures that out. :) Add a link...
1185 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
1186 if ( !$out->isPrintable() ) {
1187 $nav_urls['print'] = array(
1188 'text' => wfMsg( 'printableversion' ),
1189 'href' => $this->getTitle()->getLocalURL(
1190 $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
1194 // Also add a "permalink" while we're at it
1195 $revid = $this->getRevisionId();
1197 $nav_urls['permalink'] = array(
1198 'text' => wfMsg( 'permalink' ),
1199 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1203 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1204 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1205 array( &$this, &$nav_urls, &$revid, &$revid ) );
1208 if( $this->getTitle()->getNamespace() != NS_SPECIAL
) {
1209 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
1210 $nav_urls['whatlinkshere'] = array(
1211 'href' => $wlhTitle->getLocalUrl()
1213 if( $this->getTitle()->getArticleId() ) {
1214 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
1215 $nav_urls['recentchangeslinked'] = array(
1216 'href' => $rclTitle->getLocalUrl()
1219 $nav_urls['recentchangeslinked'] = false;
1221 if( $wgUseTrackbacks )
1222 $nav_urls['trackbacklink'] = array(
1223 'href' => $out->getTitle()->trackbackURL()
1227 $user = $this->getRelevantUser();
1229 $id = $user->getID();
1230 $ip = $user->isAnon();
1231 $rootUser = $user->getName();
1238 if( $id ||
$ip ) { # both anons and non-anons have contribs list
1239 $nav_urls['contributions'] = array(
1240 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1244 $logPage = SpecialPage
::getTitleFor( 'Log' );
1245 $nav_urls['log'] = array(
1246 'href' => $logPage->getLocalUrl(
1253 $nav_urls['log'] = false;
1256 if ( $wgUser->isAllowed( 'block' ) ) {
1257 $nav_urls['blockip'] = array(
1258 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1261 $nav_urls['blockip'] = false;
1264 $nav_urls['contributions'] = false;
1265 $nav_urls['log'] = false;
1266 $nav_urls['blockip'] = false;
1268 $nav_urls['emailuser'] = false;
1269 if( $this->showEmailUser( $id ) ) {
1270 $nav_urls['emailuser'] = array(
1271 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1274 wfProfileOut( __METHOD__
);
1279 * Generate strings used for xml 'id' names
1283 function getNameSpaceKey() {
1284 return $this->getTitle()->getNamespaceKey();
1289 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1291 function setupUserJs( $allowUserJs ) {
1292 global $wgRequest, $wgJsMimeType;
1293 wfProfileIn( __METHOD__
);
1295 if( $allowUserJs && $this->loggedin
) {
1296 if( $this->getTitle()->isJsSubpage() and $this->userCanPreview() ) {
1297 # XXX: additional security check/prompt?
1298 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1300 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1303 wfProfileOut( __METHOD__
);
1306 public function commonPrintStylesheet() {
1312 * Generic wrapper for template functions, with interface
1313 * compatible with what we use of PHPTAL 0.7.
1316 abstract class QuickTemplate
{
1320 public function QuickTemplate() {
1321 $this->data
= array();
1322 $this->translator
= new MediaWiki_I18N();
1326 * Sets the value $value to $name
1330 public function set( $name, $value ) {
1331 $this->data
[$name] = $value;
1338 public function setRef( $name, &$value ) {
1339 $this->data
[$name] =& $value;
1345 public function setTranslator( &$t ) {
1346 $this->translator
= &$t;
1350 * Main function, used by classes that subclass QuickTemplate
1351 * to show the actual HTML output
1353 abstract public function execute();
1358 function text( $str ) {
1359 echo htmlspecialchars( $this->data
[$str] );
1365 function jstext( $str ) {
1366 echo Xml
::escapeJsString( $this->data
[$str] );
1372 function html( $str ) {
1373 echo $this->data
[$str];
1379 function msg( $str ) {
1380 echo htmlspecialchars( $this->translator
->translate( $str ) );
1386 function msgHtml( $str ) {
1387 echo $this->translator
->translate( $str );
1391 * An ugly, ugly hack.
1394 function msgWiki( $str ) {
1395 global $wgParser, $wgOut;
1397 $text = $this->translator
->translate( $str );
1398 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1399 $wgOut->parserOptions(), true );
1400 echo $parserOutput->getText();
1406 function haveData( $str ) {
1407 return isset( $this->data
[$str] );
1415 function haveMsg( $str ) {
1416 $msg = $this->translator
->translate( $str );
1417 return ( $msg != '-' ) && ( $msg != '' ); # ????
1421 * Get the Skin object related to this object
1423 * @return Skin object
1425 public function getSkin() {
1426 return $this->data
['skin'];
1431 * New base template for a skin's template extended from QuickTemplate
1432 * this class features helper methods that provide common ways of interacting
1433 * with the data stored in the QuickTemplate
1435 abstract class BaseTemplate
extends QuickTemplate
{
1438 * Create an array of common toolbox items from the data in the quicktemplate
1439 * stored by SkinTemplate.
1440 * The resulting array is built acording to a format intended to be passed
1441 * through makeListItem to generate the html.
1443 function getToolbox() {
1444 wfProfileIn( __METHOD__
);
1447 if ( $this->data
['notspecialpage'] ) {
1448 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1449 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1450 if ( $this->data
['nav_urls']['recentchangeslinked'] ) {
1451 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1452 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1453 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1456 if( isset( $this->data
['nav_urls']['trackbacklink'] ) && $this->data
['nav_urls']['trackbacklink'] ) {
1457 $toolbox['trackbacklink'] = $this->data
['nav_urls']['trackbacklink'];
1458 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1460 if ( $this->data
['feeds'] ) {
1461 $toolbox['feeds']['id'] = 'feedlinks';
1462 $toolbox['feeds']['links'] = array();
1463 foreach ( $this->data
['feeds'] as $key => $feed ) {
1464 $toolbox['feeds']['links'][$key] = $feed;
1465 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1466 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1467 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1468 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1471 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1472 if ( $this->data
['nav_urls'][$special] ) {
1473 $toolbox[$special] = $this->data
['nav_urls'][$special];
1474 $toolbox[$special]['id'] = "t-$special";
1477 if ( !empty( $this->data
['nav_urls']['print']['href'] ) ) {
1478 $toolbox['print'] = $this->data
['nav_urls']['print'];
1479 $toolbox['print']['rel'] = 'alternate';
1480 $toolbox['print']['msg'] = 'printableversion';
1482 if( $this->data
['nav_urls']['permalink'] ) {
1483 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1484 if( $toolbox['permalink']['href'] === '' ) {
1485 unset( $toolbox['permalink']['href'] );
1486 $toolbox['ispermalink']['tooltiponly'] = true;
1487 $toolbox['ispermalink']['id'] = 't-ispermalink';
1488 $toolbox['ispermalink']['msg'] = 'permalink';
1490 $toolbox['permalink']['id'] = 't-permalink';
1493 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1494 wfProfileOut( __METHOD__
);
1499 * Create an array of personal tools items from the data in the quicktemplate
1500 * stored by SkinTemplate.
1501 * The resulting array is built acording to a format intended to be passed
1502 * through makeListItem to generate the html.
1503 * This is in reality the same list as already stored in personal_urls
1504 * however it is reformatted so that you can just pass the individual items
1505 * to makeListItem instead of hardcoding the element creation boilerplate.
1507 function getPersonalTools() {
1508 $personal_tools = array();
1509 foreach( $this->data
['personal_urls'] as $key => $ptool ) {
1510 # The class on a personal_urls item is meant to go on the <a> instead
1511 # of the <li> so we have to use a single item "links" array instead
1512 # of using most of the personal_url's keys directly
1513 $personal_tools[$key] = array();
1514 $personal_tools[$key]["links"][] = array();
1515 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1516 if ( isset($ptool["active"]) ) {
1517 $personal_tools[$key]["active"] = $ptool["active"];
1519 foreach ( array("href", "class", "text") as $k ) {
1520 if ( isset($ptool[$k]) )
1521 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1524 return $personal_tools;
1528 * Makes a link, usually used by makeListItem to generate a link for an item
1529 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1531 * $key is a string, usually a key from the list you are generating this link from
1532 * $item is an array containing some of a specific set of keys.
1533 * The text of the link will be generated either from the contents of the "text"
1534 * key in the $item array, if a "msg" key is present a message by that name will
1535 * be used, and if neither of those are set the $key will be used as a message name.
1536 * If a "href" key is not present makeLink will just output htmlescaped text.
1537 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1538 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1539 * is present it will be used to generate a tooltip and accesskey for the link.
1540 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1542 function makeLink( $key, $item ) {
1543 if ( isset( $item['text'] ) ) {
1544 $text = $item['text'];
1546 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1549 if ( !isset( $item['href'] ) ) {
1550 return htmlspecialchars( $text );
1554 foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) {
1555 if ( isset( $item[$attr] ) ) {
1556 $attrs[$attr] = $item[$attr];
1560 if ( isset( $item['id'] ) ) {
1561 $item['single-id'] = $item['id'];
1563 if ( isset( $item['single-id'] ) ) {
1564 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1565 $attrs['title'] = $this->skin
->titleAttrib( $item['single-id'] );
1566 if ( $attrs['title'] === false ) {
1567 unset( $attrs['title'] );
1570 $attrs = array_merge(
1572 Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] )
1577 return Html
::element( 'a', $attrs, $text );
1581 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1582 * $key is a string, usually a key from the list you are generating this link from
1583 * $item is an array of list item data containing some of a specific set of keys.
1584 * The "id" and "class" keys will be used as attributes for the list item,
1585 * if "active" contains a value of true a "active" class will also be appended to class.
1586 * If you want something other than a <li> you can pass a tag name such as
1587 * "tag" => "span" in the $options array to change the tag used.
1588 * link/content data for the list item may come in one of two forms
1589 * A "links" key may be used, in which case it should contain an array with
1590 * a list of links to include inside the list item, see makeLink for the format
1591 * of individual links array items.
1592 * Otherwise the relevant keys from the list item $item array will be passed
1593 * to makeLink instead. Note however that "id" and "class" are used by the
1594 * list item directly so they will not be passed to makeLink
1595 * (however the link will still support a tooltip and accesskey from it)
1596 * If you need an id or class on a single link you should include a "links"
1597 * array with just one link item inside of it.
1599 function makeListItem( $key, $item, $options = array() ) {
1600 if ( isset( $item['links'] ) ) {
1602 foreach ( $item['links'] as $linkKey => $link ) {
1603 $html .= $this->makeLink( $linkKey, $link );
1607 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) {
1608 if ( isset( $item[$k] ) ) {
1609 $link[$k] = $item[$k];
1612 if ( isset( $item['id'] ) ) {
1613 // The id goes on the <li> not on the <a> for single links
1614 // but makeSidebarLink still needs to know what id to use when
1615 // generating tooltips and accesskeys.
1616 $link['single-id'] = $item['id'];
1618 $html = $this->makeLink( $key, $link );
1622 foreach ( array( 'id', 'class' ) as $attr ) {
1623 if ( isset( $item[$attr] ) ) {
1624 $attrs[$attr] = $item[$attr];
1627 if ( isset( $item['active'] ) && $item['active'] ) {
1628 if ( !isset( $attrs['class'] ) ) {
1629 $attrs['class'] = '';
1631 $attrs['class'] .= ' active';
1632 $attrs['class'] = trim( $attrs['class'] );
1634 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1637 function makeSearchInput( $attrs = array() ) {
1641 'value' => isset( $this->data
['search'] ) ?
$this->data
['search'] : '',
1643 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1644 return Html
::element( 'input', $realAttrs );
1647 function makeSearchButton( $mode, $attrs = array() ) {
1654 'value' => $this->translator
->translate(
1655 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1657 $realAttrs = array_merge(
1659 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1662 return Html
::element( 'input', $realAttrs );
1664 $buttonAttrs = array(
1668 $buttonAttrs = array_merge(
1670 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1673 unset( $buttonAttrs['src'] );
1674 unset( $buttonAttrs['alt'] );
1676 'src' => $attrs['src'],
1677 'alt' => isset( $attrs['alt'] )
1679 : $this->translator
->translate( 'searchbutton' ),
1681 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1683 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1688 * Returns an array of footerlinks trimmed down to only those footer links that
1690 * If you pass "flat" as an option then the returned array will be a flat array
1691 * of footer icons instead of a key/value array of footerlinks arrays broken
1692 * up into categories.
1694 function getFooterLinks( $option = null ) {
1695 $footerlinks = $this->data
['footerlinks'];
1697 // Reduce footer links down to only those which are being used
1698 $validFooterLinks = array();
1699 foreach( $footerlinks as $category => $links ) {
1700 $validFooterLinks[$category] = array();
1701 foreach( $links as $link ) {
1702 if( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1703 $validFooterLinks[$category][] = $link;
1706 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1707 unset( $validFooterLinks[$category] );
1711 if ( $option == 'flat' ) {
1712 // fold footerlinks into a single array using a bit of trickery
1713 $validFooterLinks = call_user_func_array(
1715 array_values( $validFooterLinks )
1719 return $validFooterLinks;
1723 * Returns an array of footer icons filtered down by options relevant to how
1724 * the skin wishes to display them.
1725 * If you pass "icononly" as the option all footer icons which do not have an
1726 * image icon set will be filtered out.
1727 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1728 * in the list of footer icons. This is mostly useful for skins which only
1729 * display the text from footericons instead of the images and don't want a
1730 * duplicate copyright statement because footerlinks already rendered one.
1732 function getFooterIcons( $option = null ) {
1733 // Generate additional footer icons
1734 $footericons = $this->data
['footericons'];
1736 if ( $option == 'icononly' ) {
1737 // Unset any icons which don't have an image
1738 foreach ( $footericons as &$footerIconsBlock ) {
1739 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1740 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1741 unset( $footerIconsBlock[$footerIconKey] );
1745 // Redo removal of any empty blocks
1746 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1747 if ( count( $footerIconsBlock ) <= 0 ) {
1748 unset( $footericons[$footerIconsKey] );
1751 } elseif ( $option == 'nocopyright' ) {
1752 unset( $footericons['copyright']['copyright'] );
1753 if ( count( $footericons['copyright'] ) <= 0 ) {
1754 unset( $footericons['copyright'] );
1758 return $footericons;
1762 * Output the basic end-page trail including bottomscripts, reporttime, and
1763 * debug stuff. This should be called right before outputting the closing
1764 * body and html tags.
1766 function printTrail() { ?
>
1767 <?php
$this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?
>
1768 <?php
$this->html('reporttime') ?
>
1769 <?php
if ( $this->data
['debug'] ): ?
>
1771 <?php
$this->text( 'debug' ); ?
>