Fix translated core namespaces broken in r71342.
[mediawiki.git] / includes / SkinTemplate.php
blob50dfefe24e123ffb150bc7a2b19e4e9580924aee
1 <?php
2 /**
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
20 * @file
23 if ( ! defined( 'MEDIAWIKI' ) )
24 die( 1 );
26 /**
27 * Wrapper object for MediaWiki's localization functions,
28 * to be passed to the template engine.
30 * @private
31 * @ingroup Skins
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
48 $m = array();
49 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
50 list( $src, $var ) = $m;
51 wfSuppressWarnings();
52 $varValue = $this->_context[$var];
53 wfRestoreWarnings();
54 $value = str_replace( $src, $varValue, $value );
56 wfProfileOut( __METHOD__ );
57 return $value;
61 /**
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.
71 * @ingroup Skins
73 class SkinTemplate extends Skin {
74 /**#@+
75 * @private
78 /**
79 * Name of our skin, it probably needs to be all lower case. Child classes
80 * should override the default.
82 var $skinname = 'monobook';
84 /**
85 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
86 * are located. Child classes should override the default.
88 var $stylename = 'monobook';
90 /**
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';
96 /**
97 * Whether this skin use OutputPage::headElement() to generate the <head>
98 * tag
100 var $useHeadElement = false;
102 /**#@-*/
105 * Add specific styles for this skin
107 * @param $out OutputPage
109 function setupSkinUserCss( OutputPage $out ){
110 $out->addStyle( 'common/shared.css', 'screen' );
111 $out->addStyle( 'common/commonPrint.css', 'print' );
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 (or file)
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return object
123 * @private
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 $wgArticle, $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $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, $wgProfiler;
145 wfProfileIn( __METHOD__ );
146 if ( is_object( $wgProfiler ) ) {
147 $wgProfiler->setTemplated( true );
150 $oldid = $wgRequest->getVal( 'oldid' );
151 $diff = $wgRequest->getVal( 'diff' );
152 $action = $wgRequest->getVal( 'action', 'view' );
154 wfProfileIn( __METHOD__ . '-init' );
155 $this->initPage( $out );
157 $this->setMembers();
158 $tpl = $this->setupTemplate( $this->template, 'skins' );
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator( new MediaWiki_I18N() );
163 wfProfileOut( __METHOD__ . '-init' );
165 wfProfileIn( __METHOD__ . '-stuff' );
166 $this->thispage = $this->mTitle->getPrefixedDBkey();
167 $this->thisurl = $this->mTitle->getPrefixedURL();
168 $query = array();
169 if ( !$wgRequest->wasPosted() ) {
170 $query = $wgRequest->getValues();
171 unset( $query['title'] );
172 unset( $query['returnto'] );
173 unset( $query['returntoquery'] );
175 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
176 $this->loggedin = $wgUser->isLoggedIn();
177 $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
178 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
179 $this->username = $wgUser->getName();
181 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
182 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
183 } else {
184 # This won't be used in the standard skins, but we define it to preserve the interface
185 # To save time, we check for existence
186 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
189 $this->titletxt = $this->mTitle->getPrefixedText();
190 wfProfileOut( __METHOD__ . '-stuff' );
192 wfProfileIn( __METHOD__ . '-stuff-head' );
193 if ( $this->useHeadElement ) {
194 $pagecss = $this->setupPageCss();
195 if( $pagecss )
196 $out->addInlineStyle( $pagecss );
197 } else {
198 $this->setupUserCss( $out );
200 $tpl->set( 'pagecss', $this->setupPageCss() );
201 $tpl->setRef( 'usercss', $this->usercss );
203 $this->userjs = $this->userjsprev = false;
204 $this->setupUserJs( $out->isUserJsAllowed() );
205 $tpl->setRef( 'userjs', $this->userjs );
206 $tpl->setRef( 'userjsprev', $this->userjsprev );
208 if( $wgUseSiteJs ) {
209 $jsCache = $this->loggedin ? '&smaxage=0' : '';
210 $tpl->set( 'jsvarurl',
211 self::makeUrl( '-',
212 "action=raw$jsCache&gen=js&useskin=" .
213 urlencode( $this->getSkinName() ) ) );
214 } else {
215 $tpl->set( 'jsvarurl', false );
218 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
219 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
220 $tpl->set( 'html5version', $wgHtml5Version );
221 $tpl->set( 'headlinks', $out->getHeadLinks() );
222 $tpl->set( 'csslinks', $out->buildCssLinks() );
224 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
225 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
226 } else {
227 $tpl->set( 'trackbackhtml', null );
230 wfProfileOut( __METHOD__ . '-stuff-head' );
232 wfProfileIn( __METHOD__ . '-stuff2' );
233 $tpl->set( 'title', $out->getPageTitle() );
234 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
235 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
236 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
237 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
239 $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
240 MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
241 $this->mTitle->getNsText();
243 $tpl->set( 'nscanonical', $nsname );
244 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
245 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
246 $tpl->set( 'titletext', $this->mTitle->getText() );
247 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
248 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
250 $tpl->set( 'isarticle', $out->isArticle() );
252 $tpl->setRef( 'thispage', $this->thispage );
253 $subpagestr = $this->subPageSubtitle();
254 $tpl->set(
255 'subtitle', !empty( $subpagestr ) ?
256 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
257 $out->getSubtitle()
259 $undelete = $this->getUndeleteLink();
260 $tpl->set(
261 'undelete', !empty( $undelete ) ?
262 '<span class="subpages">'.$undelete.'</span>' :
266 $tpl->set( 'catlinks', $this->getCategories() );
267 if( $out->isSyndicated() ) {
268 $feeds = array();
269 foreach( $out->getSyndicationLinks() as $format => $link ) {
270 $feeds[$format] = array(
271 'text' => wfMsg( "feed-$format" ),
272 'href' => $link
275 $tpl->setRef( 'feeds', $feeds );
276 } else {
277 $tpl->set( 'feeds', false );
280 $tpl->setRef( 'mimetype', $wgMimeType );
281 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
282 $tpl->setRef( 'charset', $wgOutputEncoding );
283 $tpl->setRef( 'wgScript', $wgScript );
284 $tpl->setRef( 'skinname', $this->skinname );
285 $tpl->set( 'skinclass', get_class( $this ) );
286 $tpl->setRef( 'stylename', $this->stylename );
287 $tpl->set( 'printable', $out->isPrintable() );
288 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
289 $tpl->setRef( 'loggedin', $this->loggedin );
290 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
291 /* XXX currently unused, might get useful later
292 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
293 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
294 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
295 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
296 $tpl->set( "helppage", wfMsg('helppage'));
298 $tpl->set( 'searchaction', $this->escapeSearchLink() );
299 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
300 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
301 $tpl->setRef( 'stylepath', $wgStylePath );
302 $tpl->setRef( 'articlepath', $wgArticlePath );
303 $tpl->setRef( 'scriptpath', $wgScriptPath );
304 $tpl->setRef( 'serverurl', $wgServer );
305 $tpl->setRef( 'logopath', $wgLogo );
307 $lang = wfUILang();
308 $tpl->set( 'lang', $lang->getCode() );
309 $tpl->set( 'dir', $lang->getDir() );
310 $tpl->set( 'rtl', $lang->isRTL() );
312 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
313 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
314 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
315 $tpl->setRef( 'userpage', $this->userpage );
316 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
317 $tpl->set( 'userlang', $wgLang->getCode() );
319 // Users can have their language set differently than the
320 // content of the wiki. For these users, tell the web browser
321 // that interface elements are in a different language.
322 $tpl->set( 'userlangattributes', '' );
323 $tpl->set( 'specialpageattributes', '' );
325 $lang = $wgLang->getCode();
326 $dir = $wgLang->getDir();
327 if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
328 $attrs = " lang='$lang' dir='$dir'";
330 $tpl->set( 'userlangattributes', $attrs );
332 // The content of SpecialPages should be presented in the
333 // user's language. Content of regular pages should not be touched.
334 if( $this->mTitle->isSpecialPage() ) {
335 $tpl->set( 'specialpageattributes', $attrs );
339 $newtalks = $this->getNewtalks();
341 wfProfileOut( __METHOD__ . '-stuff2' );
343 wfProfileIn( __METHOD__ . '-stuff3' );
344 $tpl->setRef( 'newtalk', $newtalks );
345 $tpl->setRef( 'skin', $this );
346 $tpl->set( 'logo', $this->logoText() );
347 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
348 $wgArticle and 0 != $wgArticle->getID() ){
349 if ( !$wgDisableCounters ) {
350 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
351 if ( $viewcount ) {
352 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
353 } else {
354 $tpl->set( 'viewcount', false );
356 } else {
357 $tpl->set( 'viewcount', false );
360 if( $wgPageShowWatchingUsers ) {
361 $dbr = wfGetDB( DB_SLAVE );
362 $watchlist = $dbr->tableName( 'watchlist' );
363 $res = $dbr->select( 'watchlist',
364 array( 'COUNT(*) AS n' ),
365 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
366 __METHOD__
368 $x = $dbr->fetchObject( $res );
369 $numberofwatchingusers = $x->n;
370 if( $numberofwatchingusers > 0 ) {
371 $tpl->set( 'numberofwatchingusers',
372 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
373 $wgLang->formatNum( $numberofwatchingusers ) )
375 } else {
376 $tpl->set( 'numberofwatchingusers', false );
378 } else {
379 $tpl->set( 'numberofwatchingusers', false );
382 $tpl->set( 'copyright', $this->getCopyright() );
384 $this->credits = false;
386 if( $wgMaxCredits != 0 ){
387 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
388 } else {
389 $tpl->set( 'lastmod', $this->lastModified() );
392 $tpl->setRef( 'credits', $this->credits );
394 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
395 $tpl->set( 'copyright', $this->getCopyright() );
396 $tpl->set( 'viewcount', false );
397 $tpl->set( 'lastmod', false );
398 $tpl->set( 'credits', false );
399 $tpl->set( 'numberofwatchingusers', false );
400 } else {
401 $tpl->set( 'copyright', false );
402 $tpl->set( 'viewcount', false );
403 $tpl->set( 'lastmod', false );
404 $tpl->set( 'credits', false );
405 $tpl->set( 'numberofwatchingusers', false );
407 wfProfileOut( __METHOD__ . '-stuff3' );
409 wfProfileIn( __METHOD__ . '-stuff4' );
410 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
411 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
412 $tpl->set( 'disclaimer', $this->disclaimerLink() );
413 $tpl->set( 'privacy', $this->privacyLink() );
414 $tpl->set( 'about', $this->aboutLink() );
416 if ( $wgDebugComments ) {
417 $tpl->setRef( 'debug', $out->mDebugtext );
418 } else {
419 $tpl->set( 'debug', '' );
422 $tpl->set( 'reporttime', wfReportTime() );
423 $tpl->set( 'sitenotice', wfGetSiteNotice() );
424 $tpl->set( 'bottomscripts', $this->bottomScripts() );
426 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
427 global $wgBetterDirectionality;
428 if ( $wgBetterDirectionality ) {
429 $realBodyAttribs = array( 'lang' => $wgContLanguageCode, 'dir' => $wgContLang->getDir() );
430 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
432 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
433 $tpl->setRef( 'bodytext', $out->mBodytext );
435 # Language links
436 $language_urls = array();
438 if ( !$wgHideInterlanguageLinks ) {
439 foreach( $out->getLanguageLinks() as $l ) {
440 $tmp = explode( ':', $l, 2 );
441 $class = 'interwiki-' . $tmp[0];
442 unset( $tmp );
443 $nt = Title::newFromText( $l );
444 if ( $nt ) {
445 $language_urls[] = array(
446 'href' => $nt->getFullURL(),
447 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
448 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
449 'title' => $nt->getText(),
450 'class' => $class
455 if( count( $language_urls ) ) {
456 $tpl->setRef( 'language_urls', $language_urls );
457 } else {
458 $tpl->set( 'language_urls', false );
460 wfProfileOut( __METHOD__ . '-stuff4' );
462 wfProfileIn( __METHOD__ . '-stuff5' );
463 # Personal toolbar
464 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
465 $content_actions = $this->buildContentActionUrls();
466 $tpl->setRef( 'content_actions', $content_actions );
468 $tpl->set( 'sidebar', $this->buildSidebar() );
469 $tpl->set( 'nav_urls', $this->buildNavUrls() );
471 // Set the head scripts near the end, in case the above actions resulted in added scripts
472 if ( $this->useHeadElement ) {
473 $tpl->set( 'headelement', $out->headElement( $this ) );
474 } else {
475 $tpl->set( 'headscripts', $out->getScript() );
478 // original version by hansm
479 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
480 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
483 // allow extensions adding stuff after the page content.
484 // See Skin::afterContentHook() for further documentation.
485 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
486 wfProfileOut( __METHOD__ . '-stuff5' );
488 // execute template
489 wfProfileIn( __METHOD__ . '-execute' );
490 $res = $tpl->execute();
491 wfProfileOut( __METHOD__ . '-execute' );
493 // result may be an error
494 $this->printOrError( $res );
495 wfProfileOut( __METHOD__ );
499 * Output the string, or print error message if it's
500 * an error object of the appropriate type.
501 * For the base class, assume strings all around.
503 * @param $str Mixed
504 * @private
506 function printOrError( $str ) {
507 echo $str;
511 * build array of urls for personal toolbar
512 * @return array
513 * @private
515 function buildPersonalUrls() {
516 global $wgOut, $wgRequest;
518 $title = $wgOut->getTitle();
519 $pageurl = $title->getLocalURL();
520 wfProfileIn( __METHOD__ );
522 /* set up the default links for the personal toolbar */
523 $personal_urls = array();
524 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
525 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
526 $returnto = "returnto=$page";
527 if( $this->thisquery != '' )
528 $returnto .= "&returntoquery=$query";
529 if( $this->loggedin ) {
530 $personal_urls['userpage'] = array(
531 'text' => $this->username,
532 'href' => &$this->userpageUrlDetails['href'],
533 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
534 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
536 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
537 $personal_urls['mytalk'] = array(
538 'text' => wfMsg( 'mytalk' ),
539 'href' => &$usertalkUrlDetails['href'],
540 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
541 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
543 $href = self::makeSpecialUrl( 'Preferences' );
544 $personal_urls['preferences'] = array(
545 'text' => wfMsg( 'mypreferences' ),
546 'href' => $href,
547 'active' => ( $href == $pageurl )
549 $href = self::makeSpecialUrl( 'Watchlist' );
550 $personal_urls['watchlist'] = array(
551 'text' => wfMsg( 'mywatchlist' ),
552 'href' => $href,
553 'active' => ( $href == $pageurl )
556 # We need to do an explicit check for Special:Contributions, as we
557 # have to match both the title, and the target (which could come
558 # from request values or be specified in "sub page" form. The plot
559 # thickens, because $wgTitle is altered for special pages, so doesn't
560 # contain the original alias-with-subpage.
561 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
562 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
563 list( $spName, $spPar ) =
564 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
565 $active = $spName == 'Contributions'
566 && ( ( $spPar && $spPar == $this->username )
567 || $wgRequest->getText( 'target' ) == $this->username );
568 } else {
569 $active = false;
572 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
573 $personal_urls['mycontris'] = array(
574 'text' => wfMsg( 'mycontris' ),
575 'href' => $href,
576 'active' => $active
578 $personal_urls['logout'] = array(
579 'text' => wfMsg( 'userlogout' ),
580 'href' => self::makeSpecialUrl( 'Userlogout',
581 $title->isSpecial( 'Preferences' ) ? '' : $returnto
583 'active' => false
585 } else {
586 global $wgUser;
587 $loginlink = $wgUser->isAllowed( 'createaccount' )
588 ? 'nav-login-createaccount'
589 : 'login';
590 if( $this->showIPinHeader() ) {
591 $href = &$this->userpageUrlDetails['href'];
592 $personal_urls['anonuserpage'] = array(
593 'text' => $this->username,
594 'href' => $href,
595 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
596 'active' => ( $pageurl == $href )
598 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
599 $href = &$usertalkUrlDetails['href'];
600 $personal_urls['anontalk'] = array(
601 'text' => wfMsg( 'anontalk' ),
602 'href' => $href,
603 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
604 'active' => ( $pageurl == $href )
606 $personal_urls['anonlogin'] = array(
607 'text' => wfMsg( $loginlink ),
608 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
609 'active' => $title->isSpecial( 'Userlogin' )
611 } else {
612 $personal_urls['login'] = array(
613 'text' => wfMsg( $loginlink ),
614 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
615 'active' => $title->isSpecial( 'Userlogin' )
620 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
621 wfProfileOut( __METHOD__ );
622 return $personal_urls;
625 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
626 $classes = array();
627 if( $selected ) {
628 $classes[] = 'selected';
630 if( $checkEdit && !$title->isKnown() ) {
631 $classes[] = 'new';
632 $query = 'action=edit&redlink=1';
635 $text = wfMsg( $message );
636 if ( wfEmptyMsg( $message, $text ) ) {
637 global $wgContLang;
638 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
641 $result = array();
642 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
643 $title, $message, $selected, $checkEdit,
644 &$classes, &$query, &$text, &$result ) ) ) {
645 return $result;
648 return array(
649 'class' => implode( ' ', $classes ),
650 'text' => $text,
651 'href' => $title->getLocalUrl( $query ) );
654 function makeTalkUrlDetails( $name, $urlaction = '' ) {
655 $title = Title::newFromText( $name );
656 if( !is_object( $title ) ) {
657 throw new MWException( __METHOD__ . " given invalid pagename $name" );
659 $title = $title->getTalkPage();
660 self::checkTitle( $title, $name );
661 return array(
662 'href' => $title->getLocalURL( $urlaction ),
663 'exists' => $title->getArticleID() != 0 ? true : false
667 function makeArticleUrlDetails( $name, $urlaction = '' ) {
668 $title = Title::newFromText( $name );
669 $title= $title->getSubjectPage();
670 self::checkTitle( $title, $name );
671 return array(
672 'href' => $title->getLocalURL( $urlaction ),
673 'exists' => $title->getArticleID() != 0 ? true : false
678 * an array of edit links by default used for the tabs
679 * @return array
680 * @private
682 function buildContentActionUrls() {
683 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
685 wfProfileIn( __METHOD__ );
687 $action = $wgRequest->getVal( 'action', 'view' );
688 $section = $wgRequest->getVal( 'section' );
689 $content_actions = array();
691 $prevent_active_tabs = false;
692 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
694 if( $this->iscontent ) {
695 $subjpage = $this->mTitle->getSubjectPage();
696 $talkpage = $this->mTitle->getTalkPage();
698 $nskey = $this->mTitle->getNamespaceKey();
699 $content_actions[$nskey] = $this->tabAction(
700 $subjpage,
701 $nskey,
702 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
703 '', true
706 $content_actions['talk'] = $this->tabAction(
707 $talkpage,
708 'talk',
709 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
711 true
714 wfProfileIn( __METHOD__ . '-edit' );
715 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
716 $istalk = $this->mTitle->isTalkPage();
717 $istalkclass = $istalk?' istalk':'';
718 $content_actions['edit'] = array(
719 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
720 'text' => ( $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) )
721 ? wfMsg( 'edit' )
722 : wfMsg( 'create' ),
723 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
726 // adds new section link if page is a current revision of a talk page or
727 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
728 if ( !$wgOut->forceHideNewSectionLink() ) {
729 $content_actions['addsection'] = array(
730 'class' => $section == 'new' ? 'selected' : false,
731 'text' => wfMsg( 'addsection' ),
732 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
736 } elseif ( $this->mTitle->hasSourceText() ) {
737 $content_actions['viewsource'] = array(
738 'class' => ($action == 'edit') ? 'selected' : false,
739 'text' => wfMsg( 'viewsource' ),
740 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
743 wfProfileOut( __METHOD__ . '-edit' );
745 wfProfileIn( __METHOD__ . '-live' );
746 if ( $this->mTitle->exists() ) {
748 $content_actions['history'] = array(
749 'class' => ($action == 'history') ? 'selected' : false,
750 'text' => wfMsg( 'history_short' ),
751 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
752 'rel' => 'archives',
755 if( $wgUser->isAllowed( 'delete' ) ) {
756 $content_actions['delete'] = array(
757 'class' => ($action == 'delete') ? 'selected' : false,
758 'text' => wfMsg( 'delete' ),
759 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
762 if ( $this->mTitle->quickUserCan( 'move' ) ) {
763 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
764 $content_actions['move'] = array(
765 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
766 'text' => wfMsg( 'move' ),
767 'href' => $moveTitle->getLocalUrl()
771 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
772 if( !$this->mTitle->isProtected() ){
773 $content_actions['protect'] = array(
774 'class' => ($action == 'protect') ? 'selected' : false,
775 'text' => wfMsg( 'protect' ),
776 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
779 } else {
780 $content_actions['unprotect'] = array(
781 'class' => ($action == 'unprotect') ? 'selected' : false,
782 'text' => wfMsg( 'unprotect' ),
783 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
787 } else {
788 //article doesn't exist or is deleted
789 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
790 if( $n = $this->mTitle->isDeleted() ) {
791 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
792 $content_actions['undelete'] = array(
793 'class' => false,
794 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
795 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
796 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
801 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
802 if( !$this->mTitle->getRestrictions( 'create' ) ) {
803 $content_actions['protect'] = array(
804 'class' => ($action == 'protect') ? 'selected' : false,
805 'text' => wfMsg( 'protect' ),
806 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
809 } else {
810 $content_actions['unprotect'] = array(
811 'class' => ($action == 'unprotect') ? 'selected' : false,
812 'text' => wfMsg( 'unprotect' ),
813 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
819 wfProfileOut( __METHOD__ . '-live' );
821 if( $this->loggedin ) {
822 if( !$this->mTitle->userIsWatching()) {
823 $content_actions['watch'] = array(
824 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
825 'text' => wfMsg( 'watch' ),
826 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
828 } else {
829 $content_actions['unwatch'] = array(
830 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
831 'text' => wfMsg( 'unwatch' ),
832 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
838 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
839 } else {
840 /* show special page tab */
842 $content_actions[$this->mTitle->getNamespaceKey()] = array(
843 'class' => 'selected',
844 'text' => wfMsg('nstab-special'),
845 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
848 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
851 /* show links to different language variants */
852 global $wgDisableLangConversion;
853 $variants = $wgContLang->getVariants();
854 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
855 $preferred = $wgContLang->getPreferredVariant();
856 $vcount=0;
857 foreach( $variants as $code ) {
858 $varname = $wgContLang->getVariantname( $code );
859 if( $varname == 'disable' )
860 continue;
861 $selected = ( $code == $preferred )? 'selected' : false;
862 $content_actions['varlang-' . $vcount] = array(
863 'class' => $selected,
864 'text' => $varname,
865 'href' => $this->mTitle->getLocalURL( '', $code )
867 $vcount ++;
871 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
873 wfProfileOut( __METHOD__ );
874 return $content_actions;
878 * build array of common navigation links
879 * @return array
880 * @private
882 function buildNavUrls() {
883 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
884 global $wgUploadNavigationUrl;
886 wfProfileIn( __METHOD__ );
888 $action = $wgRequest->getVal( 'action', 'view' );
890 $nav_urls = array();
891 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
892 if( $wgUploadNavigationUrl ) {
893 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
894 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
895 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
896 } else {
897 $nav_urls['upload'] = false;
899 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
901 // default permalink to being off, will override it as required below.
902 $nav_urls['permalink'] = false;
904 // A print stylesheet is attached to all pages, but nobody ever
905 // figures that out. :) Add a link...
906 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
907 if ( !$wgOut->isPrintable() ) {
908 $nav_urls['print'] = array(
909 'text' => wfMsg( 'printableversion' ),
910 'href' => $wgRequest->appendQuery( 'printable=yes' )
914 // Also add a "permalink" while we're at it
915 if ( $this->mRevisionId ) {
916 $nav_urls['permalink'] = array(
917 'text' => wfMsg( 'permalink' ),
918 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
922 // Copy in case this undocumented, shady hook tries to mess with internals
923 $revid = $this->mRevisionId;
924 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
927 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
928 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
929 $nav_urls['whatlinkshere'] = array(
930 'href' => $wlhTitle->getLocalUrl()
932 if( $this->mTitle->getArticleId() ) {
933 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
934 $nav_urls['recentchangeslinked'] = array(
935 'href' => $rclTitle->getLocalUrl()
937 } else {
938 $nav_urls['recentchangeslinked'] = false;
940 if( $wgUseTrackbacks )
941 $nav_urls['trackbacklink'] = array(
942 'href' => $wgOut->getTitle()->trackbackURL()
946 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
947 $parts = explode( '/', $this->mTitle->getText() );
948 $rootUser = $parts[0];
949 $id = User::idFromName( $rootUser );
950 $ip = User::isIP( $rootUser );
951 } else {
952 $id = 0;
953 $ip = false;
956 if( $id || $ip ) { # both anons and non-anons have contribs list
957 $nav_urls['contributions'] = array(
958 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
961 if( $id ) {
962 $logPage = SpecialPage::getTitleFor( 'Log' );
963 $nav_urls['log'] = array(
964 'href' => $logPage->getLocalUrl(
965 array(
966 'user' => $rootUser
970 } else {
971 $nav_urls['log'] = false;
974 if ( $wgUser->isAllowed( 'block' ) ) {
975 $nav_urls['blockip'] = array(
976 'href' => self::makeSpecialUrlSubpage( 'Blockip', $rootUser )
978 } else {
979 $nav_urls['blockip'] = false;
981 } else {
982 $nav_urls['contributions'] = false;
983 $nav_urls['log'] = false;
984 $nav_urls['blockip'] = false;
986 $nav_urls['emailuser'] = false;
987 if( $this->showEmailUser( $id ) ) {
988 $nav_urls['emailuser'] = array(
989 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
992 wfProfileOut( __METHOD__ );
993 return $nav_urls;
997 * Generate strings used for xml 'id' names
998 * @return string
999 * @private
1001 function getNameSpaceKey() {
1002 return $this->mTitle->getNamespaceKey();
1006 * @private
1008 function setupUserJs( $allowUserJs ) {
1009 global $wgRequest, $wgJsMimeType;
1010 wfProfileIn( __METHOD__ );
1012 $action = $wgRequest->getVal( 'action', 'view' );
1014 if( $allowUserJs && $this->loggedin ) {
1015 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1016 # XXX: additional security check/prompt?
1017 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1018 } else {
1019 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1022 wfProfileOut( __METHOD__ );
1026 * Code for extensions to hook into to provide per-page CSS, see
1027 * extensions/PageCSS/PageCSS.php for an implementation of this.
1029 * @private
1031 function setupPageCss() {
1032 wfProfileIn( __METHOD__ );
1033 $out = false;
1034 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1035 wfProfileOut( __METHOD__ );
1036 return $out;
1039 public function commonPrintStylesheet() {
1040 return false;
1045 * Generic wrapper for template functions, with interface
1046 * compatible with what we use of PHPTAL 0.7.
1047 * @ingroup Skins
1049 abstract class QuickTemplate {
1051 * Constructor
1053 public function QuickTemplate() {
1054 $this->data = array();
1055 $this->translator = new MediaWiki_I18N();
1059 * Sets the value $value to $name
1060 * @param $name
1061 * @param $value
1063 public function set( $name, $value ) {
1064 $this->data[$name] = $value;
1068 * @param $name
1069 * @param $value
1071 public function setRef( $name, &$value ) {
1072 $this->data[$name] =& $value;
1076 * @param $t
1078 public function setTranslator( &$t ) {
1079 $this->translator = &$t;
1083 * Main function, used by classes that subclass QuickTemplate
1084 * to show the actual HTML output
1086 abstract public function execute();
1089 * @private
1091 function text( $str ) {
1092 echo htmlspecialchars( $this->data[$str] );
1096 * @private
1098 function jstext( $str ) {
1099 echo Xml::escapeJsString( $this->data[$str] );
1103 * @private
1105 function html( $str ) {
1106 echo $this->data[$str];
1110 * @private
1112 function msg( $str ) {
1113 echo htmlspecialchars( $this->translator->translate( $str ) );
1117 * @private
1119 function msgHtml( $str ) {
1120 echo $this->translator->translate( $str );
1124 * An ugly, ugly hack.
1125 * @private
1127 function msgWiki( $str ) {
1128 global $wgParser, $wgOut;
1130 $text = $this->translator->translate( $str );
1131 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1132 $wgOut->parserOptions(), true );
1133 echo $parserOutput->getText();
1137 * @private
1139 function haveData( $str ) {
1140 return isset( $this->data[$str] );
1144 * @private
1146 function haveMsg( $str ) {
1147 $msg = $this->translator->translate( $str );
1148 return ( $msg != '-' ) && ( $msg != '' ); # ????