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' ) )
27 * Wrapper object for MediaWiki's localization functions,
28 * to be passed to the template engine.
33 class MediaWiki_I18N {
34 var $_context = array();
36 function set( $varName, $value ) {
37 $this->_context[$varName] = $value;
40 function translate( $value ) {
41 wfProfileIn( __METHOD__ );
43 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
44 $value = preg_replace( '/^string:/', '', $value );
46 $value = wfMsg( $value );
47 // interpolate variables
49 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
50 list( $src, $var ) = $m;
52 $varValue = $this->_context[$var];
54 $value = str_replace( $src, $varValue, $value );
56 wfProfileOut( __METHOD__ );
62 * Template-filler skin base class
63 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
64 * Based on Brion's smarty skin
65 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
67 * @todo Needs some serious refactoring into functions that correspond
68 * to the computations individual esi snippets need. Most importantly no body
69 * parsing for most of those of course.
73 class SkinTemplate extends Skin {
79 * Name of our skin, it probably needs to be all lower case. Child classes
80 * should override the default.
82 var $skinname = 'monobook';
85 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
86 * are located. Child classes should override the default.
88 var $stylename = 'monobook';
91 * For QuickTemplate, the name of the subclass which will actually fill the
92 * template. Child classes should override the default.
94 var $template = 'QuickTemplate';
97 * Whether this skin use OutputPage::headElement() to generate the <head>
100 var $useHeadElement = false;
105 * Add specific styles for this skin
107 * @param $out OutputPage
109 function setupSkinUserCss( OutputPage $out ){
110 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
114 * Create the template engine object; we feed it a bunch of data
115 * and eventually it spits out some HTML. Should have interface
116 * roughly equivalent to PHPTAL 0.7.
118 * @param $classname string (or file)
119 * @param $repository string: subdirectory where we keep template files
120 * @param $cache_dir string
124 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
125 return new $classname();
129 * initialize various variables and generate the template
131 * @param $out OutputPage
133 function outputPage( OutputPage $out ) {
134 global $wgArticle, $wgUser, $wgLang, $wgContLang;
135 global $wgScript, $wgStylePath, $wgLanguageCode;
136 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
137 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
138 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
139 global $wgMaxCredits, $wgShowCreditsIfMax;
140 global $wgPageShowWatchingUsers;
141 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
142 global $wgArticlePath, $wgScriptPath, $wgServer, $wgProfiler;
144 wfProfileIn( __METHOD__ );
145 if ( is_object( $wgProfiler ) ) {
146 $wgProfiler->setTemplated( true );
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151 $action = $wgRequest->getVal( 'action', 'view' );
153 wfProfileIn( __METHOD__ . '-init' );
154 $this->initPage( $out );
157 $tpl = $this->setupTemplate( $this->template, 'skins' );
159 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
160 $tpl->setTranslator( new MediaWiki_I18N() );
162 wfProfileOut( __METHOD__ . '-init' );
164 wfProfileIn( __METHOD__ . '-stuff' );
165 $this->thispage = $this->mTitle->getPrefixedDBkey();
166 $this->thisurl = $this->mTitle->getPrefixedURL();
168 if ( !$wgRequest->wasPosted() ) {
169 $query = $wgRequest->getValues();
170 unset( $query['title'] );
171 unset( $query['returnto'] );
172 unset( $query['returntoquery'] );
174 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
175 $this->loggedin = $wgUser->isLoggedIn();
176 $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
177 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
178 $this->username = $wgUser->getName();
180 if ( $wgUser->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->mTitle->getPrefixedText();
189 wfProfileOut( __METHOD__ . '-stuff' );
191 wfProfileIn( __METHOD__ . '-stuff-head' );
192 if ( $this->useHeadElement ) {
193 $pagecss = $this->setupPageCss();
195 $out->addInlineStyle( $pagecss );
197 $this->setupUserCss( $out );
199 $tpl->set( 'pagecss', $this->setupPageCss() );
200 $tpl->setRef( 'usercss', $this->usercss );
202 $this->userjs = $this->userjsprev = false;
203 $this->setupUserJs( $out->isUserJsAllowed() );
204 $tpl->setRef( 'userjs', $this->userjs );
205 $tpl->setRef( 'userjsprev', $this->userjsprev );
208 $jsCache = $this->loggedin ? '&smaxage=0' : '';
209 $tpl->set( 'jsvarurl',
211 "action=raw$jsCache&gen=js&useskin=" .
212 urlencode( $this->getSkinName() ) ) );
214 $tpl->set( 'jsvarurl', false );
217 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
218 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
219 $tpl->set( 'html5version', $wgHtml5Version );
220 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
221 $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
223 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
224 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
226 $tpl->set( 'trackbackhtml', null );
229 wfProfileOut( __METHOD__ . '-stuff-head' );
231 wfProfileIn( __METHOD__ . '-stuff2' );
232 $tpl->set( 'title', $out->getPageTitle() );
233 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
234 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
235 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
236 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
238 $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
239 MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
240 $this->mTitle->getNsText();
242 $tpl->set( 'nscanonical', $nsname );
243 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
244 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
245 $tpl->set( 'titletext', $this->mTitle->getText() );
246 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
247 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
249 $tpl->set( 'isarticle', $out->isArticle() );
251 $tpl->setRef( 'thispage', $this->thispage );
252 $subpagestr = $this->subPageSubtitle();
254 'subtitle', !empty( $subpagestr ) ?
255 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
258 $undelete = $this->getUndeleteLink();
260 'undelete', !empty( $undelete ) ?
261 '<span class="subpages">'.$undelete.'</span>' :
265 $tpl->set( 'catlinks', $this->getCategories() );
266 if( $out->isSyndicated() ) {
268 foreach( $out->getSyndicationLinks() as $format => $link ) {
269 $feeds[$format] = array(
270 'text' => wfMsg( "feed-$format" ),
274 $tpl->setRef( 'feeds', $feeds );
276 $tpl->set( 'feeds', false );
279 $tpl->setRef( 'mimetype', $wgMimeType );
280 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
281 $tpl->setRef( 'charset', $wgOutputEncoding );
282 $tpl->setRef( 'wgScript', $wgScript );
283 $tpl->setRef( 'skinname', $this->skinname );
284 $tpl->set( 'skinclass', get_class( $this ) );
285 $tpl->setRef( 'stylename', $this->stylename );
286 $tpl->set( 'printable', $out->isPrintable() );
287 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
288 $tpl->setRef( 'loggedin', $this->loggedin );
289 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
290 /* XXX currently unused, might get useful later
291 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
292 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
293 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
294 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
295 $tpl->set( "helppage", wfMsg('helppage'));
297 $tpl->set( 'searchaction', $this->escapeSearchLink() );
298 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
299 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
300 $tpl->setRef( 'stylepath', $wgStylePath );
301 $tpl->setRef( 'articlepath', $wgArticlePath );
302 $tpl->setRef( 'scriptpath', $wgScriptPath );
303 $tpl->setRef( 'serverurl', $wgServer );
304 $tpl->setRef( 'logopath', $wgLogo );
307 $tpl->set( 'lang', $lang->getCode() );
308 $tpl->set( 'dir', $lang->getDir() );
309 $tpl->set( 'rtl', $lang->isRTL() );
311 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
312 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
313 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
314 $tpl->setRef( 'userpage', $this->userpage );
315 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
316 $tpl->set( 'userlang', $wgLang->getCode() );
318 // Users can have their language set differently than the
319 // content of the wiki. For these users, tell the web browser
320 // that interface elements are in a different language.
321 $tpl->set( 'userlangattributes', '' );
322 $tpl->set( 'specialpageattributes', '' );
324 $lang = $wgLang->getCode();
325 $dir = $wgLang->getDir();
326 if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
327 $attrs = " lang='$lang' dir='$dir'";
329 $tpl->set( 'userlangattributes', $attrs );
331 // The content of SpecialPages should be presented in the
332 // user's language. Content of regular pages should not be touched.
333 if( $this->mTitle->isSpecialPage() ) {
334 $tpl->set( 'specialpageattributes', $attrs );
338 $newtalks = $this->getNewtalks();
340 wfProfileOut( __METHOD__ . '-stuff2' );
342 wfProfileIn( __METHOD__ . '-stuff3' );
343 $tpl->setRef( 'newtalk', $newtalks );
344 $tpl->setRef( 'skin', $this );
345 $tpl->set( 'logo', $this->logoText() );
346 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
347 $wgArticle and 0 != $wgArticle->getID() ){
348 if ( !$wgDisableCounters ) {
349 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
351 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
353 $tpl->set( 'viewcount', false );
356 $tpl->set( 'viewcount', false );
359 if( $wgPageShowWatchingUsers ) {
360 $dbr = wfGetDB( DB_SLAVE );
361 $res = $dbr->select( 'watchlist',
362 array( 'COUNT(*) AS n' ),
363 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
366 $x = $dbr->fetchObject( $res );
367 $numberofwatchingusers = $x->n;
368 if( $numberofwatchingusers > 0 ) {
369 $tpl->set( 'numberofwatchingusers',
370 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
371 $wgLang->formatNum( $numberofwatchingusers ) )
374 $tpl->set( 'numberofwatchingusers', false );
377 $tpl->set( 'numberofwatchingusers', false );
380 $tpl->set( 'copyright', $this->getCopyright() );
382 $this->credits = false;
384 if( $wgMaxCredits != 0 ){
385 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
387 $tpl->set( 'lastmod', $this->lastModified() );
390 $tpl->setRef( 'credits', $this->credits );
392 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
393 $tpl->set( 'copyright', $this->getCopyright() );
394 $tpl->set( 'viewcount', false );
395 $tpl->set( 'lastmod', false );
396 $tpl->set( 'credits', false );
397 $tpl->set( 'numberofwatchingusers', false );
399 $tpl->set( 'copyright', false );
400 $tpl->set( 'viewcount', false );
401 $tpl->set( 'lastmod', false );
402 $tpl->set( 'credits', false );
403 $tpl->set( 'numberofwatchingusers', false );
405 wfProfileOut( __METHOD__ . '-stuff3' );
407 wfProfileIn( __METHOD__ . '-stuff4' );
408 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
409 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
410 $tpl->set( 'disclaimer', $this->disclaimerLink() );
411 $tpl->set( 'privacy', $this->privacyLink() );
412 $tpl->set( 'about', $this->aboutLink() );
414 $tpl->set( 'footerlinks', array(
418 'numberofwatchingusers',
429 global $wgFooterIcons;
430 $tpl->set( 'footericons', $wgFooterIcons );
431 foreach ( $tpl->data["footericons"] as $footerIconsKey => &$footerIconsBlock ) {
432 if ( count($footerIconsBlock) > 0 ) {
433 foreach ( $footerIconsBlock as &$footerIcon ) {
434 if ( isset($footerIcon["src"]) ) {
435 if ( !isset($footerIcon["width"]) ) $footerIcon["width"] = 88;
436 if ( !isset($footerIcon["height"]) ) $footerIcon["height"] = 31;
440 unset($tpl->data["footericons"][$footerIconsKey]);
444 if ( $wgDebugComments ) {
445 $tpl->setRef( 'debug', $out->mDebugtext );
447 $tpl->set( 'debug', '' );
450 $tpl->set( 'reporttime', wfReportTime() );
451 $tpl->set( 'sitenotice', wfGetSiteNotice() );
452 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
454 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
455 global $wgBetterDirectionality;
456 if ( $wgBetterDirectionality ) {
457 $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
458 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
460 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
461 $tpl->setRef( 'bodytext', $out->mBodytext );
464 $language_urls = array();
466 if ( !$wgHideInterlanguageLinks ) {
467 foreach( $out->getLanguageLinks() as $l ) {
468 $tmp = explode( ':', $l, 2 );
469 $class = 'interwiki-' . $tmp[0];
471 $nt = Title::newFromText( $l );
473 $language_urls[] = array(
474 'href' => $nt->getFullURL(),
475 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
476 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
477 'title' => $nt->getText(),
483 if( count( $language_urls ) ) {
484 $tpl->setRef( 'language_urls', $language_urls );
486 $tpl->set( 'language_urls', false );
488 wfProfileOut( __METHOD__ . '-stuff4' );
490 wfProfileIn( __METHOD__ . '-stuff5' );
492 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
493 $content_actions = $this->buildContentActionUrls();
494 $tpl->setRef( 'content_actions', $content_actions );
496 $tpl->set( 'sidebar', $this->buildSidebar() );
497 $tpl->set( 'nav_urls', $this->buildNavUrls() );
499 // Set the head scripts near the end, in case the above actions resulted in added scripts
500 if ( $this->useHeadElement ) {
501 $tpl->set( 'headelement', $out->headElement( $this ) );
503 $tpl->set( 'headscripts', $out->getScript() );
506 // original version by hansm
507 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
508 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
511 // allow extensions adding stuff after the page content.
512 // See Skin::afterContentHook() for further documentation.
513 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
514 wfProfileOut( __METHOD__ . '-stuff5' );
517 wfProfileIn( __METHOD__ . '-execute' );
518 $res = $tpl->execute();
519 wfProfileOut( __METHOD__ . '-execute' );
521 // result may be an error
522 $this->printOrError( $res );
523 wfProfileOut( __METHOD__ );
527 * Output the string, or print error message if it's
528 * an error object of the appropriate type.
529 * For the base class, assume strings all around.
534 function printOrError( $str ) {
539 * build array of urls for personal toolbar
543 function buildPersonalUrls() {
544 global $wgOut, $wgRequest;
546 $title = $wgOut->getTitle();
547 $pageurl = $title->getLocalURL();
548 wfProfileIn( __METHOD__ );
550 /* set up the default links for the personal toolbar */
551 $personal_urls = array();
552 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
553 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
554 $returnto = "returnto=$page";
555 if( $this->thisquery != '' )
556 $returnto .= "&returntoquery=$query";
557 if( $this->loggedin ) {
558 $personal_urls['userpage'] = array(
559 'text' => $this->username,
560 'href' => &$this->userpageUrlDetails['href'],
561 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
562 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
564 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
565 $personal_urls['mytalk'] = array(
566 'text' => wfMsg( 'mytalk' ),
567 'href' => &$usertalkUrlDetails['href'],
568 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
569 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
571 $href = self::makeSpecialUrl( 'Preferences' );
572 $personal_urls['preferences'] = array(
573 'text' => wfMsg( 'mypreferences' ),
575 'active' => ( $href == $pageurl )
577 $href = self::makeSpecialUrl( 'Watchlist' );
578 $personal_urls['watchlist'] = array(
579 'text' => wfMsg( 'mywatchlist' ),
581 'active' => ( $href == $pageurl )
584 # We need to do an explicit check for Special:Contributions, as we
585 # have to match both the title, and the target (which could come
586 # from request values or be specified in "sub page" form. The plot
587 # thickens, because $wgTitle is altered for special pages, so doesn't
588 # contain the original alias-with-subpage.
589 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
590 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
591 list( $spName, $spPar ) =
592 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
593 $active = $spName == 'Contributions'
594 && ( ( $spPar && $spPar == $this->username )
595 || $wgRequest->getText( 'target' ) == $this->username );
600 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
601 $personal_urls['mycontris'] = array(
602 'text' => wfMsg( 'mycontris' ),
606 $personal_urls['logout'] = array(
607 'text' => wfMsg( 'userlogout' ),
608 'href' => self::makeSpecialUrl( 'Userlogout',
609 // userlogout link must always contain an & character, otherwise we might not be able
610 // to detect a buggy precaching proxy (bug 17790)
611 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
617 $loginlink = $wgUser->isAllowed( 'createaccount' )
618 ? 'nav-login-createaccount'
621 # anonlogin & login are the same
623 'text' => wfMsg( $loginlink ),
624 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
625 'active' => $title->isSpecial( 'Userlogin' )
627 global $wgProto, $wgSecureLogin;
628 if( $wgProto === 'http' && $wgSecureLogin ) {
629 $title = SpecialPage::getTitleFor( 'Userlogin' );
630 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
631 $login_url['href'] = $https_url;
632 $login_url['class'] = 'link-https'; # FIXME class depends on skin
635 if( $this->showIPinHeader() ) {
636 $href = &$this->userpageUrlDetails['href'];
637 $personal_urls['anonuserpage'] = array(
638 'text' => $this->username,
640 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
641 'active' => ( $pageurl == $href )
643 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
644 $href = &$usertalkUrlDetails['href'];
645 $personal_urls['anontalk'] = array(
646 'text' => wfMsg( 'anontalk' ),
648 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
649 'active' => ( $pageurl == $href )
651 $personal_urls['anonlogin'] = $login_url;
653 $personal_urls['login'] = $login_url;
657 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
658 wfProfileOut( __METHOD__ );
659 return $personal_urls;
662 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
665 $classes[] = 'selected';
667 if( $checkEdit && !$title->isKnown() ) {
669 $query = 'action=edit&redlink=1';
672 $text = wfMsg( $message );
673 if ( wfEmptyMsg( $message, $text ) ) {
675 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
679 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
680 $title, $message, $selected, $checkEdit,
681 &$classes, &$query, &$text, &$result ) ) ) {
686 'class' => implode( ' ', $classes ),
688 'href' => $title->getLocalUrl( $query ) );
691 function makeTalkUrlDetails( $name, $urlaction = '' ) {
692 $title = Title::newFromText( $name );
693 if( !is_object( $title ) ) {
694 throw new MWException( __METHOD__ . " given invalid pagename $name" );
696 $title = $title->getTalkPage();
697 self::checkTitle( $title, $name );
699 'href' => $title->getLocalURL( $urlaction ),
700 'exists' => $title->getArticleID() != 0,
704 function makeArticleUrlDetails( $name, $urlaction = '' ) {
705 $title = Title::newFromText( $name );
706 $title= $title->getSubjectPage();
707 self::checkTitle( $title, $name );
709 'href' => $title->getLocalURL( $urlaction ),
710 'exists' => $title->getArticleID() != 0,
715 * an array of edit links by default used for the tabs
719 function buildContentActionUrls() {
720 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
722 wfProfileIn( __METHOD__ );
724 $action = $wgRequest->getVal( 'action', 'view' );
725 $section = $wgRequest->getVal( 'section' );
726 $content_actions = array();
727 $userCanRead = $this->mTitle->userCanRead();
729 $prevent_active_tabs = false;
730 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
732 if( $this->iscontent ) {
733 $subjpage = $this->mTitle->getSubjectPage();
734 $talkpage = $this->mTitle->getTalkPage();
736 $nskey = $this->mTitle->getNamespaceKey();
737 $content_actions[$nskey] = $this->tabAction(
740 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
744 $content_actions['talk'] = $this->tabAction(
747 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
752 wfProfileIn( __METHOD__ . '-edit' );
753 if ( $userCanRead && $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
754 $istalk = $this->mTitle->isTalkPage();
755 $istalkclass = $istalk?' istalk':'';
756 $content_actions['edit'] = array(
757 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
758 'text' => ( $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) )
761 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
764 // adds new section link if page is a current revision of a talk page or
765 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
766 if ( !$wgOut->forceHideNewSectionLink() ) {
767 $content_actions['addsection'] = array(
768 'class' => $section == 'new' ? 'selected' : false,
769 'text' => wfMsg( 'addsection' ),
770 'href' => $this->mTitle->getLocalUrl( 'action=edit§ion=new' )
774 } elseif ( $this->mTitle->hasSourceText() && $userCanRead ) {
775 $content_actions['viewsource'] = array(
776 'class' => ($action == 'edit') ? 'selected' : false,
777 'text' => wfMsg( 'viewsource' ),
778 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
781 wfProfileOut( __METHOD__ . '-edit' );
783 wfProfileIn( __METHOD__ . '-live' );
784 if ( $this->mTitle->exists() && $userCanRead ) {
786 $content_actions['history'] = array(
787 'class' => ($action == 'history') ? 'selected' : false,
788 'text' => wfMsg( 'history_short' ),
789 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
793 if( $wgUser->isAllowed( 'delete' ) ) {
794 $content_actions['delete'] = array(
795 'class' => ($action == 'delete') ? 'selected' : false,
796 'text' => wfMsg( 'delete' ),
797 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
800 if ( $this->mTitle->quickUserCan( 'move' ) ) {
801 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
802 $content_actions['move'] = array(
803 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
804 'text' => wfMsg( 'move' ),
805 'href' => $moveTitle->getLocalUrl()
809 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
810 if( !$this->mTitle->isProtected() ){
811 $content_actions['protect'] = array(
812 'class' => ($action == 'protect') ? 'selected' : false,
813 'text' => wfMsg( 'protect' ),
814 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
818 $content_actions['unprotect'] = array(
819 'class' => ($action == 'unprotect') ? 'selected' : false,
820 'text' => wfMsg( 'unprotect' ),
821 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
826 //article doesn't exist or is deleted
827 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
828 $n = $this->mTitle->isDeleted();
830 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
831 $content_actions['undelete'] = array(
833 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
834 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
835 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
840 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
841 if( !$this->mTitle->getRestrictions( 'create' ) ) {
842 $content_actions['protect'] = array(
843 'class' => ($action == 'protect') ? 'selected' : false,
844 'text' => wfMsg( 'protect' ),
845 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
849 $content_actions['unprotect'] = array(
850 'class' => ($action == 'unprotect') ? 'selected' : false,
851 'text' => wfMsg( 'unprotect' ),
852 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
858 wfProfileOut( __METHOD__ . '-live' );
860 if( $this->loggedin ) {
861 if( !$this->mTitle->userIsWatching()) {
862 $content_actions['watch'] = array(
863 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
864 'text' => wfMsg( 'watch' ),
865 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
868 $content_actions['unwatch'] = array(
869 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
870 'text' => wfMsg( 'unwatch' ),
871 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
877 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
879 /* show special page tab */
881 $content_actions[$this->mTitle->getNamespaceKey()] = array(
882 'class' => 'selected',
883 'text' => wfMsg('nstab-special'),
884 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
887 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
890 /* show links to different language variants */
891 global $wgDisableLangConversion;
892 $variants = $wgContLang->getVariants();
893 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
894 $preferred = $wgContLang->getPreferredVariant();
896 foreach( $variants as $code ) {
897 $varname = $wgContLang->getVariantname( $code );
898 if( $varname == 'disable' )
900 $selected = ( $code == $preferred )? 'selected' : false;
901 $content_actions['varlang-' . $vcount] = array(
902 'class' => $selected,
904 'href' => $this->mTitle->getLocalURL( '', $code )
910 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
912 wfProfileOut( __METHOD__ );
913 return $content_actions;
917 * build array of common navigation links
921 function buildNavUrls() {
922 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
923 global $wgUploadNavigationUrl;
925 wfProfileIn( __METHOD__ );
927 $action = $wgRequest->getVal( 'action', 'view' );
930 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
931 if( $wgUploadNavigationUrl ) {
932 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
933 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
934 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
936 $nav_urls['upload'] = false;
938 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
940 // default permalink to being off, will override it as required below.
941 $nav_urls['permalink'] = false;
943 // A print stylesheet is attached to all pages, but nobody ever
944 // figures that out. :) Add a link...
945 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
946 if ( !$wgOut->isPrintable() ) {
947 $nav_urls['print'] = array(
948 'text' => wfMsg( 'printableversion' ),
949 'href' => $wgRequest->appendQuery( 'printable=yes' )
953 // Also add a "permalink" while we're at it
954 if ( $this->mRevisionId ) {
955 $nav_urls['permalink'] = array(
956 'text' => wfMsg( 'permalink' ),
957 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
961 // Copy in case this undocumented, shady hook tries to mess with internals
962 $revid = $this->mRevisionId;
963 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
966 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
967 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
968 $nav_urls['whatlinkshere'] = array(
969 'href' => $wlhTitle->getLocalUrl()
971 if( $this->mTitle->getArticleId() ) {
972 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
973 $nav_urls['recentchangeslinked'] = array(
974 'href' => $rclTitle->getLocalUrl()
977 $nav_urls['recentchangeslinked'] = false;
979 if( $wgUseTrackbacks )
980 $nav_urls['trackbacklink'] = array(
981 'href' => $wgOut->getTitle()->trackbackURL()
985 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
986 $rootUser = strtok( $this->mTitle->getText(), '/' );
987 $id = User::idFromName( $rootUser );
988 $ip = User::isIP( $rootUser );
994 if( $id || $ip ) { # both anons and non-anons have contribs list
995 $nav_urls['contributions'] = array(
996 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1000 $logPage = SpecialPage::getTitleFor( 'Log' );
1001 $nav_urls['log'] = array(
1002 'href' => $logPage->getLocalUrl(
1009 $nav_urls['log'] = false;
1012 if ( $wgUser->isAllowed( 'block' ) ) {
1013 $nav_urls['blockip'] = array(
1014 'href' => self::makeSpecialUrlSubpage( 'Blockip', $rootUser )
1017 $nav_urls['blockip'] = false;
1020 $nav_urls['contributions'] = false;
1021 $nav_urls['log'] = false;
1022 $nav_urls['blockip'] = false;
1024 $nav_urls['emailuser'] = false;
1025 if( $this->showEmailUser( $id ) ) {
1026 $nav_urls['emailuser'] = array(
1027 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1030 wfProfileOut( __METHOD__ );
1035 * Generate strings used for xml 'id' names
1039 function getNameSpaceKey() {
1040 return $this->mTitle->getNamespaceKey();
1046 function setupUserJs( $allowUserJs ) {
1047 global $wgRequest, $wgJsMimeType;
1048 wfProfileIn( __METHOD__ );
1050 $action = $wgRequest->getVal( 'action', 'view' );
1052 if( $allowUserJs && $this->loggedin ) {
1053 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1054 # XXX: additional security check/prompt?
1055 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1057 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1060 wfProfileOut( __METHOD__ );
1064 * Code for extensions to hook into to provide per-page CSS, see
1065 * extensions/PageCSS/PageCSS.php for an implementation of this.
1069 function setupPageCss() {
1070 wfProfileIn( __METHOD__ );
1072 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1073 wfProfileOut( __METHOD__ );
1077 public function commonPrintStylesheet() {
1083 * Generic wrapper for template functions, with interface
1084 * compatible with what we use of PHPTAL 0.7.
1087 abstract class QuickTemplate {
1091 public function QuickTemplate() {
1092 $this->data = array();
1093 $this->translator = new MediaWiki_I18N();
1097 * Sets the value $value to $name
1101 public function set( $name, $value ) {
1102 $this->data[$name] = $value;
1109 public function setRef( $name, &$value ) {
1110 $this->data[$name] =& $value;
1116 public function setTranslator( &$t ) {
1117 $this->translator = &$t;
1121 * Main function, used by classes that subclass QuickTemplate
1122 * to show the actual HTML output
1124 abstract public function execute();
1129 function text( $str ) {
1130 echo htmlspecialchars( $this->data[$str] );
1136 function jstext( $str ) {
1137 echo Xml::escapeJsString( $this->data[$str] );
1143 function html( $str ) {
1144 echo $this->data[$str];
1150 function msg( $str ) {
1151 echo htmlspecialchars( $this->translator->translate( $str ) );
1157 function msgHtml( $str ) {
1158 echo $this->translator->translate( $str );
1162 * An ugly, ugly hack.
1165 function msgWiki( $str ) {
1166 global $wgParser, $wgOut;
1168 $text = $this->translator->translate( $str );
1169 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1170 $wgOut->parserOptions(), true );
1171 echo $parserOutput->getText();
1177 function haveData( $str ) {
1178 return isset( $this->data[$str] );
1184 function haveMsg( $str ) {
1185 $msg = $this->translator->translate( $str );
1186 return ( $msg != '-' ) && ( $msg != '' ); # ????