Restored line accidentally removed in r70520
[mediawiki.git] / includes / SkinTemplate.php
blobe14674bda9e30a119e6f5c445408e42c7be5fb85
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
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 /**
21 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
24 * @private
25 * @ingroup Skins
27 class MediaWiki_I18N {
28 var $_context = array();
30 function set( $varName, $value ) {
31 $this->_context[$varName] = $value;
34 function translate( $value ) {
35 wfProfileIn( __METHOD__ );
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
40 $value = wfMsg( $value );
41 // interpolate variables
42 $m = array();
43 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
44 list( $src, $var ) = $m;
45 wfSuppressWarnings();
46 $varValue = $this->_context[$var];
47 wfRestoreWarnings();
48 $value = str_replace( $src, $varValue, $value );
50 wfProfileOut( __METHOD__ );
51 return $value;
55 /**
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
65 * @ingroup Skins
67 class SkinTemplate extends Skin {
68 /**#@+
69 * @private
72 /**
73 * Name of our skin, it probably needs to be all lower case. Child classes
74 * should override the default.
76 var $skinname = 'monobook';
78 /**
79 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
80 * are located. Child classes should override the default.
82 var $stylename = 'monobook';
84 /**
85 * For QuickTemplate, the name of the subclass which will actually fill the
86 * template. Child classes should override the default.
88 var $template = 'QuickTemplate';
90 /**
91 * Whether this skin use OutputPage::headElement() to generate the <head>
92 * tag
94 var $useHeadElement = false;
96 /**#@-*/
98 /**
99 * Add specific styles for this skin
101 * @param $out OutputPage
103 function setupSkinUserCss( OutputPage $out ){
104 $out->addStyle( 'common/shared.css', 'screen' );
105 $out->addStyle( 'common/commonPrint.css', 'print' );
109 * Create the template engine object; we feed it a bunch of data
110 * and eventually it spits out some HTML. Should have interface
111 * roughly equivalent to PHPTAL 0.7.
113 * @param $classname string (or file)
114 * @param $repository string: subdirectory where we keep template files
115 * @param $cache_dir string
116 * @return object
117 * @private
119 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
120 return new $classname();
124 * initialize various variables and generate the template
126 * @param $out OutputPage
128 function outputPage( OutputPage $out ) {
129 global $wgArticle, $wgUser, $wgLang, $wgContLang;
130 global $wgScript, $wgStylePath, $wgContLanguageCode;
131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
133 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
134 global $wgMaxCredits, $wgShowCreditsIfMax;
135 global $wgPageShowWatchingUsers;
136 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
137 global $wgArticlePath, $wgScriptPath, $wgServer, $wgProfiler;
139 wfProfileIn( __METHOD__ );
140 if ( is_object( $wgProfiler ) ) {
141 $wgProfiler->setTemplated( true );
144 $oldid = $wgRequest->getVal( 'oldid' );
145 $diff = $wgRequest->getVal( 'diff' );
146 $action = $wgRequest->getVal( 'action', 'view' );
148 wfProfileIn( __METHOD__ . '-init' );
149 $this->initPage( $out );
151 $this->setMembers();
152 $tpl = $this->setupTemplate( $this->template, 'skins' );
154 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
155 $tpl->setTranslator( new MediaWiki_I18N() );
157 wfProfileOut( __METHOD__ . '-init' );
159 wfProfileIn( __METHOD__ . '-stuff' );
160 $this->thispage = $this->mTitle->getPrefixedDBkey();
161 $this->thisurl = $this->mTitle->getPrefixedURL();
162 $query = array();
163 if ( !$wgRequest->wasPosted() ) {
164 $query = $wgRequest->getValues();
165 unset( $query['title'] );
166 unset( $query['returnto'] );
167 unset( $query['returntoquery'] );
169 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
170 $this->loggedin = $wgUser->isLoggedIn();
171 $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
172 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
173 $this->username = $wgUser->getName();
175 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
176 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
177 } else {
178 # This won't be used in the standard skins, but we define it to preserve the interface
179 # To save time, we check for existence
180 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
183 $this->titletxt = $this->mTitle->getPrefixedText();
184 wfProfileOut( __METHOD__ . '-stuff' );
186 wfProfileIn( __METHOD__ . '-stuff-head' );
187 if ( $this->useHeadElement ) {
188 $pagecss = $this->setupPageCss();
189 if( $pagecss )
190 $out->addInlineStyle( $pagecss );
191 } else {
192 $this->setupUserCss( $out );
194 $tpl->set( 'pagecss', $this->setupPageCss() );
195 $tpl->setRef( 'usercss', $this->usercss );
197 $this->userjs = $this->userjsprev = false;
198 $this->setupUserJs( $out->isUserJsAllowed() );
199 $tpl->setRef( 'userjs', $this->userjs );
200 $tpl->setRef( 'userjsprev', $this->userjsprev );
202 if( $wgUseSiteJs ) {
203 $jsCache = $this->loggedin ? '&smaxage=0' : '';
204 $tpl->set( 'jsvarurl',
205 self::makeUrl( '-',
206 "action=raw$jsCache&gen=js&useskin=" .
207 urlencode( $this->getSkinName() ) ) );
208 } else {
209 $tpl->set( 'jsvarurl', false );
212 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
213 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
214 $tpl->set( 'html5version', $wgHtml5Version );
215 $tpl->set( 'headlinks', $out->getHeadLinks() );
216 $tpl->set( 'csslinks', $out->buildCssLinks() );
218 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
219 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
220 } else {
221 $tpl->set( 'trackbackhtml', null );
224 wfProfileOut( __METHOD__ . '-stuff-head' );
226 wfProfileIn( __METHOD__ . '-stuff2' );
227 $tpl->set( 'title', $out->getPageTitle() );
228 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
229 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
230 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
231 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
233 $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
234 MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
235 $this->mTitle->getNsText();
237 $tpl->set( 'nscanonical', $nsname );
238 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
239 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
240 $tpl->set( 'titletext', $this->mTitle->getText() );
241 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
242 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
244 $tpl->set( 'isarticle', $out->isArticle() );
246 $tpl->setRef( 'thispage', $this->thispage );
247 $subpagestr = $this->subPageSubtitle();
248 $tpl->set(
249 'subtitle', !empty( $subpagestr ) ?
250 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
251 $out->getSubtitle()
253 $undelete = $this->getUndeleteLink();
254 $tpl->set(
255 'undelete', !empty( $undelete ) ?
256 '<span class="subpages">'.$undelete.'</span>' :
260 $tpl->set( 'catlinks', $this->getCategories() );
261 if( $out->isSyndicated() ) {
262 $feeds = array();
263 foreach( $out->getSyndicationLinks() as $format => $link ) {
264 $feeds[$format] = array(
265 'text' => wfMsg( "feed-$format" ),
266 'href' => $link
269 $tpl->setRef( 'feeds', $feeds );
270 } else {
271 $tpl->set( 'feeds', false );
274 $tpl->setRef( 'mimetype', $wgMimeType );
275 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
276 $tpl->setRef( 'charset', $wgOutputEncoding );
277 $tpl->setRef( 'wgScript', $wgScript );
278 $tpl->setRef( 'skinname', $this->skinname );
279 $tpl->set( 'skinclass', get_class( $this ) );
280 $tpl->setRef( 'stylename', $this->stylename );
281 $tpl->set( 'printable', $out->isPrintable() );
282 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
283 $tpl->setRef( 'loggedin', $this->loggedin );
284 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
285 /* XXX currently unused, might get useful later
286 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
287 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
288 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
289 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
290 $tpl->set( "helppage", wfMsg('helppage'));
292 $tpl->set( 'searchaction', $this->escapeSearchLink() );
293 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
294 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
295 $tpl->setRef( 'stylepath', $wgStylePath );
296 $tpl->setRef( 'articlepath', $wgArticlePath );
297 $tpl->setRef( 'scriptpath', $wgScriptPath );
298 $tpl->setRef( 'serverurl', $wgServer );
299 $tpl->setRef( 'logopath', $wgLogo );
301 $lang = wfUILang();
302 $tpl->set( 'lang', $lang->getCode() );
303 $tpl->set( 'dir', $lang->getDir() );
304 $tpl->set( 'rtl', $lang->isRTL() );
306 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
307 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
308 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
309 $tpl->setRef( 'userpage', $this->userpage );
310 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
311 $tpl->set( 'userlang', $wgLang->getCode() );
313 // Users can have their language set differently than the
314 // content of the wiki. For these users, tell the web browser
315 // that interface elements are in a different language.
316 $tpl->set( 'userlangattributes', '' );
317 $tpl->set( 'specialpageattributes', '' );
319 $lang = $wgLang->getCode();
320 $dir = $wgLang->getDir();
321 if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
322 $attrs = " lang='$lang' dir='$dir'";
324 $tpl->set( 'userlangattributes', $attrs );
326 // The content of SpecialPages should be presented in the
327 // user's language. Content of regular pages should not be touched.
328 if( $this->mTitle->isSpecialPage() ) {
329 $tpl->set( 'specialpageattributes', $attrs );
333 $newtalks = $this->getNewtalks();
335 wfProfileOut( __METHOD__ . '-stuff2' );
337 wfProfileIn( __METHOD__ . '-stuff3' );
338 $tpl->setRef( 'newtalk', $newtalks );
339 $tpl->setRef( 'skin', $this );
340 $tpl->set( 'logo', $this->logoText() );
341 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
342 $wgArticle and 0 != $wgArticle->getID() ){
343 if ( !$wgDisableCounters ) {
344 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
345 if ( $viewcount ) {
346 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
347 } else {
348 $tpl->set( 'viewcount', false );
350 } else {
351 $tpl->set( 'viewcount', false );
354 if( $wgPageShowWatchingUsers ) {
355 $dbr = wfGetDB( DB_SLAVE );
356 $watchlist = $dbr->tableName( 'watchlist' );
357 $res = $dbr->select( 'watchlist',
358 array( 'COUNT(*) AS n' ),
359 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
360 __METHOD__
362 $x = $dbr->fetchObject( $res );
363 $numberofwatchingusers = $x->n;
364 if( $numberofwatchingusers > 0 ) {
365 $tpl->set( 'numberofwatchingusers',
366 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
367 $wgLang->formatNum( $numberofwatchingusers ) )
369 } else {
370 $tpl->set( 'numberofwatchingusers', false );
372 } else {
373 $tpl->set( 'numberofwatchingusers', false );
376 $tpl->set( 'copyright', $this->getCopyright() );
378 $this->credits = false;
380 if( $wgMaxCredits != 0 ){
381 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
382 } else {
383 $tpl->set( 'lastmod', $this->lastModified() );
386 $tpl->setRef( 'credits', $this->credits );
388 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
389 $tpl->set( 'copyright', $this->getCopyright() );
390 $tpl->set( 'viewcount', false );
391 $tpl->set( 'lastmod', false );
392 $tpl->set( 'credits', false );
393 $tpl->set( 'numberofwatchingusers', false );
394 } else {
395 $tpl->set( 'copyright', false );
396 $tpl->set( 'viewcount', false );
397 $tpl->set( 'lastmod', false );
398 $tpl->set( 'credits', false );
399 $tpl->set( 'numberofwatchingusers', false );
401 wfProfileOut( __METHOD__ . '-stuff3' );
403 wfProfileIn( __METHOD__ . '-stuff4' );
404 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
405 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
406 $tpl->set( 'disclaimer', $this->disclaimerLink() );
407 $tpl->set( 'privacy', $this->privacyLink() );
408 $tpl->set( 'about', $this->aboutLink() );
410 if ( $wgDebugComments ) {
411 $tpl->setRef( 'debug', $out->mDebugtext );
412 } else {
413 $tpl->set( 'debug', '' );
416 $tpl->set( 'reporttime', wfReportTime() );
417 $tpl->set( 'sitenotice', wfGetSiteNotice() );
418 $tpl->set( 'bottomscripts', $this->bottomScripts() );
420 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
421 global $wgBetterDirectionality;
422 if ( $wgBetterDirectionality ) {
423 $realBodyAttribs = array( 'lang' => $wgContLanguageCode, 'dir' => $wgContLang->getDir() );
424 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
426 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
427 $tpl->setRef( 'bodytext', $out->mBodytext );
429 # Language links
430 $language_urls = array();
432 if ( !$wgHideInterlanguageLinks ) {
433 foreach( $out->getLanguageLinks() as $l ) {
434 $tmp = explode( ':', $l, 2 );
435 $class = 'interwiki-' . $tmp[0];
436 unset( $tmp );
437 $nt = Title::newFromText( $l );
438 if ( $nt ) {
439 $language_urls[] = array(
440 'href' => $nt->getFullURL(),
441 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
442 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
443 'title' => $nt->getText(),
444 'class' => $class
449 if( count( $language_urls ) ) {
450 $tpl->setRef( 'language_urls', $language_urls );
451 } else {
452 $tpl->set( 'language_urls', false );
454 wfProfileOut( __METHOD__ . '-stuff4' );
456 wfProfileIn( __METHOD__ . '-stuff5' );
457 # Personal toolbar
458 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
459 $content_actions = $this->buildContentActionUrls();
460 $tpl->setRef( 'content_actions', $content_actions );
462 $tpl->set( 'sidebar', $this->buildSidebar() );
463 $tpl->set( 'nav_urls', $this->buildNavUrls() );
465 // Set the head scripts near the end, in case the above actions resulted in added scripts
466 if ( $this->useHeadElement ) {
467 $tpl->set( 'headelement', $out->headElement( $this ) );
468 } else {
469 $tpl->set( 'headscripts', $out->getScript() );
472 // original version by hansm
473 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
474 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
477 // allow extensions adding stuff after the page content.
478 // See Skin::afterContentHook() for further documentation.
479 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
480 wfProfileOut( __METHOD__ . '-stuff5' );
482 // execute template
483 wfProfileIn( __METHOD__ . '-execute' );
484 $res = $tpl->execute();
485 wfProfileOut( __METHOD__ . '-execute' );
487 // result may be an error
488 $this->printOrError( $res );
489 wfProfileOut( __METHOD__ );
493 * Output the string, or print error message if it's
494 * an error object of the appropriate type.
495 * For the base class, assume strings all around.
497 * @param $str Mixed
498 * @private
500 function printOrError( $str ) {
501 echo $str;
505 * build array of urls for personal toolbar
506 * @return array
507 * @private
509 function buildPersonalUrls() {
510 global $wgOut, $wgRequest;
512 $title = $wgOut->getTitle();
513 $pageurl = $title->getLocalURL();
514 wfProfileIn( __METHOD__ );
516 /* set up the default links for the personal toolbar */
517 $personal_urls = array();
518 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
519 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
520 $returnto = "returnto=$page";
521 if( $this->thisquery != '' )
522 $returnto .= "&returntoquery=$query";
523 if( $this->loggedin ) {
524 $personal_urls['userpage'] = array(
525 'text' => $this->username,
526 'href' => &$this->userpageUrlDetails['href'],
527 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
528 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
530 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
531 $personal_urls['mytalk'] = array(
532 'text' => wfMsg( 'mytalk' ),
533 'href' => &$usertalkUrlDetails['href'],
534 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
535 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
537 $href = self::makeSpecialUrl( 'Preferences' );
538 $personal_urls['preferences'] = array(
539 'text' => wfMsg( 'mypreferences' ),
540 'href' => $href,
541 'active' => ( $href == $pageurl )
543 $href = self::makeSpecialUrl( 'Watchlist' );
544 $personal_urls['watchlist'] = array(
545 'text' => wfMsg( 'mywatchlist' ),
546 'href' => $href,
547 'active' => ( $href == $pageurl )
550 # We need to do an explicit check for Special:Contributions, as we
551 # have to match both the title, and the target (which could come
552 # from request values or be specified in "sub page" form. The plot
553 # thickens, because $wgTitle is altered for special pages, so doesn't
554 # contain the original alias-with-subpage.
555 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
556 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
557 list( $spName, $spPar ) =
558 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
559 $active = $spName == 'Contributions'
560 && ( ( $spPar && $spPar == $this->username )
561 || $wgRequest->getText( 'target' ) == $this->username );
562 } else {
563 $active = false;
566 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
567 $personal_urls['mycontris'] = array(
568 'text' => wfMsg( 'mycontris' ),
569 'href' => $href,
570 'active' => $active
572 $personal_urls['logout'] = array(
573 'text' => wfMsg( 'userlogout' ),
574 'href' => self::makeSpecialUrl( 'Userlogout',
575 $title->isSpecial( 'Preferences' ) ? '' : $returnto
577 'active' => false
579 } else {
580 global $wgUser;
581 $loginlink = $wgUser->isAllowed( 'createaccount' )
582 ? 'nav-login-createaccount'
583 : 'login';
584 if( $this->showIPinHeader() ) {
585 $href = &$this->userpageUrlDetails['href'];
586 $personal_urls['anonuserpage'] = array(
587 'text' => $this->username,
588 'href' => $href,
589 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
590 'active' => ( $pageurl == $href )
592 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
593 $href = &$usertalkUrlDetails['href'];
594 $personal_urls['anontalk'] = array(
595 'text' => wfMsg( 'anontalk' ),
596 'href' => $href,
597 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
598 'active' => ( $pageurl == $href )
600 $personal_urls['anonlogin'] = array(
601 'text' => wfMsg( $loginlink ),
602 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
603 'active' => $title->isSpecial( 'Userlogin' )
605 } else {
606 $personal_urls['login'] = array(
607 'text' => wfMsg( $loginlink ),
608 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
609 'active' => $title->isSpecial( 'Userlogin' )
614 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
615 wfProfileOut( __METHOD__ );
616 return $personal_urls;
619 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
620 $classes = array();
621 if( $selected ) {
622 $classes[] = 'selected';
624 if( $checkEdit && !$title->isKnown() ) {
625 $classes[] = 'new';
626 $query = 'action=edit&redlink=1';
629 $text = wfMsg( $message );
630 if ( wfEmptyMsg( $message, $text ) ) {
631 global $wgContLang;
632 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
635 $result = array();
636 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
637 $title, $message, $selected, $checkEdit,
638 &$classes, &$query, &$text, &$result ) ) ) {
639 return $result;
642 return array(
643 'class' => implode( ' ', $classes ),
644 'text' => $text,
645 'href' => $title->getLocalUrl( $query ) );
648 function makeTalkUrlDetails( $name, $urlaction = '' ) {
649 $title = Title::newFromText( $name );
650 if( !is_object( $title ) ) {
651 throw new MWException( __METHOD__ . " given invalid pagename $name" );
653 $title = $title->getTalkPage();
654 self::checkTitle( $title, $name );
655 return array(
656 'href' => $title->getLocalURL( $urlaction ),
657 'exists' => $title->getArticleID() != 0 ? true : false
661 function makeArticleUrlDetails( $name, $urlaction = '' ) {
662 $title = Title::newFromText( $name );
663 $title= $title->getSubjectPage();
664 self::checkTitle( $title, $name );
665 return array(
666 'href' => $title->getLocalURL( $urlaction ),
667 'exists' => $title->getArticleID() != 0 ? true : false
672 * an array of edit links by default used for the tabs
673 * @return array
674 * @private
676 function buildContentActionUrls() {
677 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
679 wfProfileIn( __METHOD__ );
681 $action = $wgRequest->getVal( 'action', 'view' );
682 $section = $wgRequest->getVal( 'section' );
683 $content_actions = array();
685 $prevent_active_tabs = false;
686 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
688 if( $this->iscontent ) {
689 $subjpage = $this->mTitle->getSubjectPage();
690 $talkpage = $this->mTitle->getTalkPage();
692 $nskey = $this->mTitle->getNamespaceKey();
693 $content_actions[$nskey] = $this->tabAction(
694 $subjpage,
695 $nskey,
696 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
697 '', true
700 $content_actions['talk'] = $this->tabAction(
701 $talkpage,
702 'talk',
703 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
705 true
708 wfProfileIn( __METHOD__ . '-edit' );
709 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
710 $istalk = $this->mTitle->isTalkPage();
711 $istalkclass = $istalk?' istalk':'';
712 $content_actions['edit'] = array(
713 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
714 'text' => ( $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) )
715 ? wfMsg( 'edit' )
716 : wfMsg( 'create' ),
717 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
720 // adds new section link if page is a current revision of a talk page or
721 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
722 if ( !$wgOut->forceHideNewSectionLink() ) {
723 $content_actions['addsection'] = array(
724 'class' => $section == 'new' ? 'selected' : false,
725 'text' => wfMsg( 'addsection' ),
726 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
730 } elseif ( $this->mTitle->hasSourceText() ) {
731 $content_actions['viewsource'] = array(
732 'class' => ($action == 'edit') ? 'selected' : false,
733 'text' => wfMsg( 'viewsource' ),
734 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
737 wfProfileOut( __METHOD__ . '-edit' );
739 wfProfileIn( __METHOD__ . '-live' );
740 if ( $this->mTitle->exists() ) {
742 $content_actions['history'] = array(
743 'class' => ($action == 'history') ? 'selected' : false,
744 'text' => wfMsg( 'history_short' ),
745 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
746 'rel' => 'archives',
749 if( $wgUser->isAllowed( 'delete' ) ) {
750 $content_actions['delete'] = array(
751 'class' => ($action == 'delete') ? 'selected' : false,
752 'text' => wfMsg( 'delete' ),
753 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
756 if ( $this->mTitle->quickUserCan( 'move' ) ) {
757 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
758 $content_actions['move'] = array(
759 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
760 'text' => wfMsg( 'move' ),
761 'href' => $moveTitle->getLocalUrl()
765 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
766 if( !$this->mTitle->isProtected() ){
767 $content_actions['protect'] = array(
768 'class' => ($action == 'protect') ? 'selected' : false,
769 'text' => wfMsg( 'protect' ),
770 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
773 } else {
774 $content_actions['unprotect'] = array(
775 'class' => ($action == 'unprotect') ? 'selected' : false,
776 'text' => wfMsg( 'unprotect' ),
777 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
781 } else {
782 //article doesn't exist or is deleted
783 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
784 if( $n = $this->mTitle->isDeleted() ) {
785 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
786 $content_actions['undelete'] = array(
787 'class' => false,
788 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
789 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
790 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
795 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
796 if( !$this->mTitle->getRestrictions( 'create' ) ) {
797 $content_actions['protect'] = array(
798 'class' => ($action == 'protect') ? 'selected' : false,
799 'text' => wfMsg( 'protect' ),
800 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
803 } else {
804 $content_actions['unprotect'] = array(
805 'class' => ($action == 'unprotect') ? 'selected' : false,
806 'text' => wfMsg( 'unprotect' ),
807 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
813 wfProfileOut( __METHOD__ . '-live' );
815 if( $this->loggedin ) {
816 if( !$this->mTitle->userIsWatching()) {
817 $content_actions['watch'] = array(
818 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
819 'text' => wfMsg( 'watch' ),
820 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
822 } else {
823 $content_actions['unwatch'] = array(
824 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
825 'text' => wfMsg( 'unwatch' ),
826 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
832 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
833 } else {
834 /* show special page tab */
836 $content_actions[$this->mTitle->getNamespaceKey()] = array(
837 'class' => 'selected',
838 'text' => wfMsg('nstab-special'),
839 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
842 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
845 /* show links to different language variants */
846 global $wgDisableLangConversion;
847 $variants = $wgContLang->getVariants();
848 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
849 $preferred = $wgContLang->getPreferredVariant();
850 $vcount=0;
851 foreach( $variants as $code ) {
852 $varname = $wgContLang->getVariantname( $code );
853 if( $varname == 'disable' )
854 continue;
855 $selected = ( $code == $preferred )? 'selected' : false;
856 $content_actions['varlang-' . $vcount] = array(
857 'class' => $selected,
858 'text' => $varname,
859 'href' => $this->mTitle->getLocalURL( '', $code )
861 $vcount ++;
865 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
867 wfProfileOut( __METHOD__ );
868 return $content_actions;
872 * build array of common navigation links
873 * @return array
874 * @private
876 function buildNavUrls() {
877 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
878 global $wgUploadNavigationUrl;
880 wfProfileIn( __METHOD__ );
882 $action = $wgRequest->getVal( 'action', 'view' );
884 $nav_urls = array();
885 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
886 if( $wgUploadNavigationUrl ) {
887 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
888 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
889 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
890 } else {
891 $nav_urls['upload'] = false;
893 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
895 // default permalink to being off, will override it as required below.
896 $nav_urls['permalink'] = false;
898 // A print stylesheet is attached to all pages, but nobody ever
899 // figures that out. :) Add a link...
900 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
901 if ( !$wgOut->isPrintable() ) {
902 $nav_urls['print'] = array(
903 'text' => wfMsg( 'printableversion' ),
904 'href' => $wgRequest->appendQuery( 'printable=yes' )
908 // Also add a "permalink" while we're at it
909 if ( $this->mRevisionId ) {
910 $nav_urls['permalink'] = array(
911 'text' => wfMsg( 'permalink' ),
912 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
916 // Copy in case this undocumented, shady hook tries to mess with internals
917 $revid = $this->mRevisionId;
918 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
921 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
922 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
923 $nav_urls['whatlinkshere'] = array(
924 'href' => $wlhTitle->getLocalUrl()
926 if( $this->mTitle->getArticleId() ) {
927 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
928 $nav_urls['recentchangeslinked'] = array(
929 'href' => $rclTitle->getLocalUrl()
931 } else {
932 $nav_urls['recentchangeslinked'] = false;
934 if( $wgUseTrackbacks )
935 $nav_urls['trackbacklink'] = array(
936 'href' => $wgOut->getTitle()->trackbackURL()
940 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
941 $parts = explode( '/', $this->mTitle->getText() );
942 $rootUser = $parts[0];
943 $id = User::idFromName( $rootUser );
944 $ip = User::isIP( $rootUser );
945 } else {
946 $id = 0;
947 $ip = false;
950 if( $id || $ip ) { # both anons and non-anons have contribs list
951 $nav_urls['contributions'] = array(
952 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
955 if( $id ) {
956 $logPage = SpecialPage::getTitleFor( 'Log' );
957 $nav_urls['log'] = array(
958 'href' => $logPage->getLocalUrl(
959 array(
960 'user' => $rootUser
964 } else {
965 $nav_urls['log'] = false;
968 if ( $wgUser->isAllowed( 'block' ) ) {
969 $nav_urls['blockip'] = array(
970 'href' => self::makeSpecialUrlSubpage( 'Blockip', $rootUser )
972 } else {
973 $nav_urls['blockip'] = false;
975 } else {
976 $nav_urls['contributions'] = false;
977 $nav_urls['log'] = false;
978 $nav_urls['blockip'] = false;
980 $nav_urls['emailuser'] = false;
981 if( $this->showEmailUser( $id ) ) {
982 $nav_urls['emailuser'] = array(
983 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
986 wfProfileOut( __METHOD__ );
987 return $nav_urls;
991 * Generate strings used for xml 'id' names
992 * @return string
993 * @private
995 function getNameSpaceKey() {
996 return $this->mTitle->getNamespaceKey();
1000 * @private
1002 function setupUserJs( $allowUserJs ) {
1003 global $wgRequest, $wgJsMimeType;
1004 wfProfileIn( __METHOD__ );
1006 $action = $wgRequest->getVal( 'action', 'view' );
1008 if( $allowUserJs && $this->loggedin ) {
1009 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1010 # XXX: additional security check/prompt?
1011 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1012 } else {
1013 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1016 wfProfileOut( __METHOD__ );
1020 * Code for extensions to hook into to provide per-page CSS, see
1021 * extensions/PageCSS/PageCSS.php for an implementation of this.
1023 * @private
1025 function setupPageCss() {
1026 wfProfileIn( __METHOD__ );
1027 $out = false;
1028 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1029 wfProfileOut( __METHOD__ );
1030 return $out;
1033 public function commonPrintStylesheet() {
1034 return false;
1039 * Generic wrapper for template functions, with interface
1040 * compatible with what we use of PHPTAL 0.7.
1041 * @ingroup Skins
1043 abstract class QuickTemplate {
1045 * Constructor
1047 public function QuickTemplate() {
1048 $this->data = array();
1049 $this->translator = new MediaWiki_I18N();
1053 * Sets the value $value to $name
1054 * @param $name
1055 * @param $value
1057 public function set( $name, $value ) {
1058 $this->data[$name] = $value;
1062 * @param $name
1063 * @param $value
1065 public function setRef( $name, &$value ) {
1066 $this->data[$name] =& $value;
1070 * @param $t
1072 public function setTranslator( &$t ) {
1073 $this->translator = &$t;
1077 * Main function, used by classes that subclass QuickTemplate
1078 * to show the actual HTML output
1080 abstract public function execute();
1083 * @private
1085 function text( $str ) {
1086 echo htmlspecialchars( $this->data[$str] );
1090 * @private
1092 function jstext( $str ) {
1093 echo Xml::escapeJsString( $this->data[$str] );
1097 * @private
1099 function html( $str ) {
1100 echo $this->data[$str];
1104 * @private
1106 function msg( $str ) {
1107 echo htmlspecialchars( $this->translator->translate( $str ) );
1111 * @private
1113 function msgHtml( $str ) {
1114 echo $this->translator->translate( $str );
1118 * An ugly, ugly hack.
1119 * @private
1121 function msgWiki( $str ) {
1122 global $wgParser, $wgOut;
1124 $text = $this->translator->translate( $str );
1125 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1126 $wgOut->parserOptions(), true );
1127 echo $parserOutput->getText();
1131 * @private
1133 function haveData( $str ) {
1134 return isset( $this->data[$str] );
1138 * @private
1140 function haveMsg( $str ) {
1141 $msg = $this->translator->translate( $str );
1142 return ( $msg != '-' ) && ( $msg != '' ); # ????