* Fix regression in authentication hook auto-creation on login
[mediawiki.git] / includes / SkinTemplate.php
blobca3546d1f51ae142917b78dfb589c6145c41efdf
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 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
30 * @package MediaWiki
31 * @subpackage Skins
34 /**
35 * Wrapper object for MediaWiki's localization functions,
36 * to be passed to the template engine.
38 * @private
39 * @package MediaWiki
41 class MediaWiki_I18N {
42 var $_context = array();
44 function set($varName, $value) {
45 $this->_context[$varName] = $value;
48 function translate($value) {
49 $fname = 'SkinTemplate-translate';
50 wfProfileIn( $fname );
52 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
53 $value = preg_replace( '/^string:/', '', $value );
55 $value = wfMsg( $value );
56 // interpolate variables
57 $m = array();
58 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
59 list($src, $var) = $m;
60 wfSuppressWarnings();
61 $varValue = $this->_context[$var];
62 wfRestoreWarnings();
63 $value = str_replace($src, $varValue, $value);
65 wfProfileOut( $fname );
66 return $value;
70 /**
72 * @package MediaWiki
74 class SkinTemplate extends Skin {
75 /**#@+
76 * @private
79 /**
80 * Name of our skin, set in initPage()
81 * It probably need to be all lower case.
83 var $skinname;
85 /**
86 * Stylesheets set to use
87 * Sub directory in ./skins/ where various stylesheets are located
89 var $stylename;
91 /**
92 * For QuickTemplate, the name of the subclass which
93 * will actually fill the template.
95 var $template;
97 /**#@-*/
99 /**
100 * Setup the base parameters...
101 * Child classes should override this to set the name,
102 * style subdirectory, and template filler callback.
104 * @param OutputPage $out
106 function initPage( &$out ) {
107 parent::initPage( $out );
108 $this->skinname = 'monobook';
109 $this->stylename = 'monobook';
110 $this->template = 'QuickTemplate';
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 string $callback (or file)
119 * @param string $repository subdirectory where we keep template files
120 * @param string $cache_dir
121 * @return object
122 * @private
124 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
125 return new $classname();
129 * initialize various variables and generate the template
131 * @param OutputPage $out
132 * @public
134 function outputPage( &$out ) {
135 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
139 global $wgMaxCredits, $wgShowCreditsIfMax;
140 global $wgPageShowWatchingUsers;
141 global $wgUseTrackbacks;
142 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
144 $fname = 'SkinTemplate::outputPage';
145 wfProfileIn( $fname );
147 // Hook that allows last minute changes to the output page, e.g.
148 // adding of CSS or Javascript by extensions.
149 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
151 $oldid = $wgRequest->getVal( 'oldid' );
152 $diff = $wgRequest->getVal( 'diff' );
154 wfProfileIn( "$fname-init" );
155 $this->initPage( $out );
157 $this->mTitle =& $wgTitle;
158 $this->mUser =& $wgUser;
160 $tpl = $this->setupTemplate( $this->template, 'skins' );
162 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
163 $tpl->setTranslator(new MediaWiki_I18N());
165 wfProfileOut( "$fname-init" );
167 wfProfileIn( "$fname-stuff" );
168 $this->thispage = $this->mTitle->getPrefixedDbKey();
169 $this->thisurl = $this->mTitle->getPrefixedURL();
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();
174 $userPage = $wgUser->getUserPage();
175 $this->userpage = $userPage->getPrefixedText();
177 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
178 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
179 } else {
180 # This won't be used in the standard skins, but we define it to preserve the interface
181 # To save time, we check for existence
182 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
185 $this->usercss = $this->userjs = $this->userjsprev = false;
186 $this->setupUserCss();
187 $this->setupUserJs();
188 $this->titletxt = $this->mTitle->getPrefixedText();
189 wfProfileOut( "$fname-stuff" );
191 wfProfileIn( "$fname-stuff2" );
192 $tpl->set( 'title', $wgOut->getPageTitle() );
193 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
194 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
195 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
197 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
198 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
199 $this->mTitle->getNsText();
201 $tpl->set( 'nscanonical', $nsname );
202 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
203 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
204 $tpl->set( 'titletext', $this->mTitle->getText() );
205 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
206 $tpl->set( 'isarticle', $wgOut->isArticle() );
208 $tpl->setRef( "thispage", $this->thispage );
209 $subpagestr = $this->subPageSubtitle();
210 $tpl->set(
211 'subtitle', !empty($subpagestr)?
212 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
213 $out->getSubtitle()
215 $undelete = $this->getUndeleteLink();
216 $tpl->set(
217 "undelete", !empty($undelete)?
218 '<span class="subpages">'.$undelete.'</span>':
222 $tpl->set( 'catlinks', $this->getCategories());
223 if( $wgOut->isSyndicated() ) {
224 $feeds = array();
225 foreach( $wgFeedClasses as $format => $class ) {
226 $linktext = $format;
227 if ( $format == "atom" ) {
228 $linktext = wfMsg( 'feed-atom' );
229 } else if ( $format == "rss" ) {
230 $linktext = wfMsg( 'feed-rss' );
232 $feeds[$format] = array(
233 'text' => $linktext,
234 'href' => $wgRequest->appendQuery( "feed=$format" )
237 $tpl->setRef( 'feeds', $feeds );
238 } else {
239 $tpl->set( 'feeds', false );
241 if ($wgUseTrackbacks && $out->isArticleRelated()) {
242 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
243 } else {
244 $tpl->set( 'trackbackhtml', null );
247 $tpl->setRef( 'mimetype', $wgMimeType );
248 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
249 $tpl->setRef( 'charset', $wgOutputEncoding );
250 $tpl->set( 'headlinks', $out->getHeadLinks() );
251 $tpl->set('headscripts', $out->getScript() );
252 $tpl->setRef( 'wgScript', $wgScript );
253 $tpl->setRef( 'skinname', $this->skinname );
254 $tpl->set( 'skinclass', get_class( $this ) );
255 $tpl->setRef( 'stylename', $this->stylename );
256 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
257 $tpl->setRef( 'loggedin', $this->loggedin );
258 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
259 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
260 /* XXX currently unused, might get useful later
261 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
262 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
263 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
264 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
265 $tpl->set( "helppage", wfMsg('helppage'));
267 $tpl->set( 'searchaction', $this->escapeSearchLink() );
268 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
269 $tpl->setRef( 'stylepath', $wgStylePath );
270 $tpl->setRef( 'articlepath', $wgArticlePath );
271 $tpl->setRef( 'scriptpath', $wgScriptPath );
272 $tpl->setRef( 'serverurl', $wgServer );
273 $tpl->setRef( 'logopath', $wgLogo );
274 $tpl->setRef( "lang", $wgContLanguageCode );
275 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
276 $tpl->set( 'rtl', $wgContLang->isRTL() );
277 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
278 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
279 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
280 $tpl->setRef( 'userpage', $this->userpage);
281 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
282 $tpl->set( 'userlang', $wgLang->getCode() );
283 $tpl->set( 'pagecss', $this->setupPageCss() );
284 $tpl->setRef( 'usercss', $this->usercss);
285 $tpl->setRef( 'userjs', $this->userjs);
286 $tpl->setRef( 'userjsprev', $this->userjsprev);
287 global $wgUseSiteJs;
288 if ($wgUseSiteJs) {
289 if($this->loggedin) {
290 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&smaxage=0&gen=js') );
291 } else {
292 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&gen=js') );
294 } else {
295 $tpl->set('jsvarurl', false);
297 $newtalks = $wgUser->getNewMessageLinks();
299 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
300 $usertitle = $this->mUser->getUserPage();
301 $usertalktitle = $usertitle->getTalkPage();
302 if( !$usertalktitle->equals( $this->mTitle ) ) {
303 $ntl = wfMsg( 'youhavenewmessages',
304 $this->makeKnownLinkObj(
305 $usertalktitle,
306 wfMsgHtml( 'newmessageslink' ),
307 'redirect=no'
309 $this->makeKnownLinkObj(
310 $usertalktitle,
311 wfMsgHtml( 'newmessagesdifflink' ),
312 'diff=cur'
315 # Disable Cache
316 $wgOut->setSquidMaxage(0);
318 } else if (count($newtalks)) {
319 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
320 $msgs = array();
321 foreach ($newtalks as $newtalk) {
322 $msgs[] = wfElement("a",
323 array('href' => $newtalk["link"]), $newtalk["wiki"]);
325 $parts = implode($sep, $msgs);
326 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
327 $wgOut->setSquidMaxage(0);
328 } else {
329 $ntl = '';
331 wfProfileOut( "$fname-stuff2" );
333 wfProfileIn( "$fname-stuff3" );
334 $tpl->setRef( 'newtalk', $ntl );
335 $tpl->setRef( 'skin', $this);
336 $tpl->set( 'logo', $this->logoText() );
337 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
338 $wgArticle and 0 != $wgArticle->getID() )
340 if ( !$wgDisableCounters ) {
341 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
342 if ( $viewcount ) {
343 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
344 } else {
345 $tpl->set('viewcount', false);
347 } else {
348 $tpl->set('viewcount', false);
351 if ($wgPageShowWatchingUsers) {
352 $dbr =& wfGetDB( DB_SLAVE );
353 $watchlist = $dbr->tableName( 'watchlist' );
354 $sql = "SELECT COUNT(*) AS n FROM $watchlist
355 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
356 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
357 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
358 $x = $dbr->fetchObject( $res );
359 $numberofwatchingusers = $x->n;
360 if ($numberofwatchingusers > 0) {
361 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
362 } else {
363 $tpl->set('numberofwatchingusers', false);
365 } else {
366 $tpl->set('numberofwatchingusers', false);
369 $tpl->set('copyright',$this->getCopyright());
371 $this->credits = false;
373 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
374 require_once("Credits.php");
375 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
376 } else {
377 $tpl->set('lastmod', $this->lastModified());
380 $tpl->setRef( 'credits', $this->credits );
382 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
383 $tpl->set('copyright', $this->getCopyright());
384 $tpl->set('viewcount', false);
385 $tpl->set('lastmod', false);
386 $tpl->set('credits', false);
387 $tpl->set('numberofwatchingusers', false);
388 } else {
389 $tpl->set('copyright', false);
390 $tpl->set('viewcount', false);
391 $tpl->set('lastmod', false);
392 $tpl->set('credits', false);
393 $tpl->set('numberofwatchingusers', false);
395 wfProfileOut( "$fname-stuff3" );
397 wfProfileIn( "$fname-stuff4" );
398 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
399 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
400 $tpl->set( 'disclaimer', $this->disclaimerLink() );
401 $tpl->set( 'privacy', $this->privacyLink() );
402 $tpl->set( 'about', $this->aboutLink() );
404 $tpl->setRef( 'debug', $out->mDebugtext );
405 $tpl->set( 'reporttime', $out->reportTime() );
406 $tpl->set( 'sitenotice', wfGetSiteNotice() );
407 $tpl->set( 'bottomscripts', $this->bottomScripts() );
409 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
410 $out->mBodytext .= $printfooter ;
411 $tpl->setRef( 'bodytext', $out->mBodytext );
413 # Language links
414 $language_urls = array();
416 if ( !$wgHideInterlanguageLinks ) {
417 foreach( $wgOut->getLanguageLinks() as $l ) {
418 $tmp = explode( ':', $l, 2 );
419 $class = 'interwiki-' . $tmp[0];
420 unset($tmp);
421 $nt = Title::newFromText( $l );
422 $language_urls[] = array(
423 'href' => $nt->getFullURL(),
424 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
425 'class' => $class
429 if(count($language_urls)) {
430 $tpl->setRef( 'language_urls', $language_urls);
431 } else {
432 $tpl->set('language_urls', false);
434 wfProfileOut( "$fname-stuff4" );
436 # Personal toolbar
437 $tpl->set('personal_urls', $this->buildPersonalUrls());
438 $content_actions = $this->buildContentActionUrls();
439 $tpl->setRef('content_actions', $content_actions);
441 // XXX: attach this from javascript, same with section editing
442 if($this->iseditable && $wgUser->getOption("editondblclick") )
444 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
445 } else {
446 $tpl->set('body_ondblclick', false);
448 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
449 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
450 } else {
451 $tpl->set( 'body_onload', false );
453 $tpl->set( 'sidebar', $this->buildSidebar() );
454 $tpl->set( 'nav_urls', $this->buildNavUrls() );
456 // execute template
457 wfProfileIn( "$fname-execute" );
458 $res = $tpl->execute();
459 wfProfileOut( "$fname-execute" );
461 // result may be an error
462 $this->printOrError( $res );
463 wfProfileOut( $fname );
467 * Output the string, or print error message if it's
468 * an error object of the appropriate type.
469 * For the base class, assume strings all around.
471 * @param mixed $str
472 * @private
474 function printOrError( &$str ) {
475 echo $str;
479 * build array of urls for personal toolbar
480 * @return array
481 * @private
483 function buildPersonalUrls() {
484 global $wgTitle, $wgShowIPinHeader;
486 $fname = 'SkinTemplate::buildPersonalUrls';
487 $pageurl = $wgTitle->getLocalURL();
488 wfProfileIn( $fname );
490 /* set up the default links for the personal toolbar */
491 $personal_urls = array();
492 if ($this->loggedin) {
493 $personal_urls['userpage'] = array(
494 'text' => $this->username,
495 'href' => &$this->userpageUrlDetails['href'],
496 'class' => $this->userpageUrlDetails['exists']?false:'new',
497 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
499 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
500 $personal_urls['mytalk'] = array(
501 'text' => wfMsg('mytalk'),
502 'href' => &$usertalkUrlDetails['href'],
503 'class' => $usertalkUrlDetails['exists']?false:'new',
504 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
506 $href = self::makeSpecialUrl( 'Preferences' );
507 $personal_urls['preferences'] = array(
508 'text' => wfMsg( 'mypreferences' ),
509 'href' => self::makeSpecialUrl( 'Preferences' ),
510 'active' => ( $href == $pageurl )
512 $href = self::makeSpecialUrl( 'Watchlist' );
513 $personal_urls['watchlist'] = array(
514 'text' => wfMsg( 'watchlist' ),
515 'href' => $href,
516 'active' => ( $href == $pageurl )
518 $href = self::makeSpecialUrl( "Contributions/$this->username" );
519 $personal_urls['mycontris'] = array(
520 'text' => wfMsg( 'mycontris' ),
521 'href' => $href,
522 // FIXME # 'active' was disabed in r11346 with message: "disable bold link to my contributions; link was bold on all
523 // Special:Contributions, not just current user's (fix me please!)". Until resolved, explicitly setting active to false.
524 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
526 $personal_urls['logout'] = array(
527 'text' => wfMsg( 'userlogout' ),
528 'href' => self::makeSpecialUrl( 'Userlogout',
529 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
531 'active' => false
533 } else {
534 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
535 $href = &$this->userpageUrlDetails['href'];
536 $personal_urls['anonuserpage'] = array(
537 'text' => $this->username,
538 'href' => $href,
539 'class' => $this->userpageUrlDetails['exists']?false:'new',
540 'active' => ( $pageurl == $href )
542 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
543 $href = &$usertalkUrlDetails['href'];
544 $personal_urls['anontalk'] = array(
545 'text' => wfMsg('anontalk'),
546 'href' => $href,
547 'class' => $usertalkUrlDetails['exists']?false:'new',
548 'active' => ( $pageurl == $href )
550 $personal_urls['anonlogin'] = array(
551 'text' => wfMsg('userlogin'),
552 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
553 'active' => $wgTitle->isSpecial( 'Userlogin' )
555 } else {
557 $personal_urls['login'] = array(
558 'text' => wfMsg('userlogin'),
559 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
560 'active' => $wgTitle->isSpecial( 'Userlogin' )
565 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
566 wfProfileOut( $fname );
567 return $personal_urls;
571 * Returns true if the IP should be shown in the header
573 function showIPinHeader() {
574 global $wgShowIPinHeader;
575 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
578 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
579 $classes = array();
580 if( $selected ) {
581 $classes[] = 'selected';
583 if( $checkEdit && $title->getArticleId() == 0 ) {
584 $classes[] = 'new';
585 $query = 'action=edit';
588 $text = wfMsg( $message );
589 if ( wfEmptyMsg( $message, $text ) ) {
590 global $wgContLang;
591 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
594 return array(
595 'class' => implode( ' ', $classes ),
596 'text' => $text,
597 'href' => $title->getLocalUrl( $query ) );
600 function makeTalkUrlDetails( $name, $urlaction = '' ) {
601 $title = Title::newFromText( $name );
602 $title = $title->getTalkPage();
603 self::checkTitle( $title, $name );
604 return array(
605 'href' => $title->getLocalURL( $urlaction ),
606 'exists' => $title->getArticleID() != 0 ? true : false
610 function makeArticleUrlDetails( $name, $urlaction = '' ) {
611 $title = Title::newFromText( $name );
612 $title= $title->getSubjectPage();
613 self::checkTitle( $title, $name );
614 return array(
615 'href' => $title->getLocalURL( $urlaction ),
616 'exists' => $title->getArticleID() != 0 ? true : false
621 * an array of edit links by default used for the tabs
622 * @return array
623 * @private
625 function buildContentActionUrls () {
626 global $wgContLang, $wgOut;
627 $fname = 'SkinTemplate::buildContentActionUrls';
628 wfProfileIn( $fname );
630 global $wgUser, $wgRequest;
631 $action = $wgRequest->getText( 'action' );
632 $section = $wgRequest->getText( 'section' );
633 $content_actions = array();
635 $prevent_active_tabs = false ;
636 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
638 if( $this->iscontent ) {
639 $subjpage = $this->mTitle->getSubjectPage();
640 $talkpage = $this->mTitle->getTalkPage();
642 $nskey = $this->mTitle->getNamespaceKey();
643 $content_actions[$nskey] = $this->tabAction(
644 $subjpage,
645 $nskey,
646 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
647 '', true);
649 $content_actions['talk'] = $this->tabAction(
650 $talkpage,
651 'talk',
652 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
654 true);
656 wfProfileIn( "$fname-edit" );
657 if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {
658 $istalk = $this->mTitle->isTalkPage();
659 $istalkclass = $istalk?' istalk':'';
660 $content_actions['edit'] = array(
661 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
662 'text' => wfMsg('edit'),
663 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
666 if ( $istalk || $wgOut->showNewSectionLink() ) {
667 $content_actions['addsection'] = array(
668 'class' => $section == 'new'?'selected':false,
669 'text' => wfMsg('addsection'),
670 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
673 } else {
674 $content_actions['viewsource'] = array(
675 'class' => ($action == 'edit') ? 'selected' : false,
676 'text' => wfMsg('viewsource'),
677 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
680 wfProfileOut( "$fname-edit" );
682 wfProfileIn( "$fname-live" );
683 if ( $this->mTitle->getArticleId() ) {
685 $content_actions['history'] = array(
686 'class' => ($action == 'history') ? 'selected' : false,
687 'text' => wfMsg('history_short'),
688 'href' => $this->mTitle->getLocalUrl( 'action=history')
691 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
692 if(!$this->mTitle->isProtected()){
693 $content_actions['protect'] = array(
694 'class' => ($action == 'protect') ? 'selected' : false,
695 'text' => wfMsg('protect'),
696 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
699 } else {
700 $content_actions['unprotect'] = array(
701 'class' => ($action == 'unprotect') ? 'selected' : false,
702 'text' => wfMsg('unprotect'),
703 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
707 if($wgUser->isAllowed('delete')){
708 $content_actions['delete'] = array(
709 'class' => ($action == 'delete') ? 'selected' : false,
710 'text' => wfMsg('delete'),
711 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
714 if ( $this->mTitle->userCanMove()) {
715 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
716 $content_actions['move'] = array(
717 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
718 'text' => wfMsg('move'),
719 'href' => $moveTitle->getLocalUrl()
722 } else {
723 //article doesn't exist or is deleted
724 if( $wgUser->isAllowed( 'delete' ) ) {
725 if( $n = $this->mTitle->isDeleted() ) {
726 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
727 $content_actions['undelete'] = array(
728 'class' => false,
729 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
730 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
731 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
736 wfProfileOut( "$fname-live" );
738 if( $this->loggedin ) {
739 if( !$this->mTitle->userIsWatching()) {
740 $content_actions['watch'] = array(
741 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
742 'text' => wfMsg('watch'),
743 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
745 } else {
746 $content_actions['unwatch'] = array(
747 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
748 'text' => wfMsg('unwatch'),
749 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
754 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
755 } else {
756 /* show special page tab */
758 $content_actions[$this->mTitle->getNamespaceKey()] = array(
759 'class' => 'selected',
760 'text' => wfMsg('specialpage'),
761 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
764 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
767 /* show links to different language variants */
768 global $wgDisableLangConversion;
769 $variants = $wgContLang->getVariants();
770 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
771 $preferred = $wgContLang->getPreferredVariant();
772 $vcount=0;
773 foreach( $variants as $code ) {
774 $varname = $wgContLang->getVariantname( $code );
775 if( $varname == 'disable' )
776 continue;
777 $selected = ( $code == $preferred )? 'selected' : false;
778 $content_actions['varlang-' . $vcount] = array(
779 'class' => $selected,
780 'text' => $varname,
781 'href' => $this->mTitle->getLocalURL('',$code)
783 $vcount ++;
787 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
789 wfProfileOut( $fname );
790 return $content_actions;
796 * build array of common navigation links
797 * @return array
798 * @private
800 function buildNavUrls () {
801 global $wgUseTrackbacks, $wgTitle, $wgArticle;
803 $fname = 'SkinTemplate::buildNavUrls';
804 wfProfileIn( $fname );
806 global $wgUser, $wgRequest;
807 global $wgEnableUploads, $wgUploadNavigationUrl;
809 $action = $wgRequest->getText( 'action' );
810 $oldid = $wgRequest->getVal( 'oldid' );
812 $nav_urls = array();
813 $nav_urls['mainpage'] = array( 'href' => self::makeI18nUrl( 'mainpage') );
814 if( $wgEnableUploads ) {
815 if ($wgUploadNavigationUrl) {
816 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
817 } else {
818 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
820 } else {
821 if ($wgUploadNavigationUrl)
822 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
823 else
824 $nav_urls['upload'] = false;
826 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
828 // default permalink to being off, will override it as required below.
829 $nav_urls['permalink'] = false;
831 // A print stylesheet is attached to all pages, but nobody ever
832 // figures that out. :) Add a link...
833 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
834 $revid = $wgArticle ? $wgArticle->getLatest() : 0;
835 if ( !( $revid == 0 ) )
836 $nav_urls['print'] = array(
837 'text' => wfMsg( 'printableversion' ),
838 'href' => $wgRequest->appendQuery( 'printable=yes' )
841 // Also add a "permalink" while we're at it
842 if ( (int)$oldid ) {
843 $nav_urls['permalink'] = array(
844 'text' => wfMsg( 'permalink' ),
845 'href' => ''
847 } else {
848 if ( !( $revid == 0 ) )
849 $nav_urls['permalink'] = array(
850 'text' => wfMsg( 'permalink' ),
851 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
855 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
858 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
859 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
860 $nav_urls['whatlinkshere'] = array(
861 'href' => $wlhTitle->getLocalUrl()
863 if( $this->mTitle->getArticleId() ) {
864 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
865 $nav_urls['recentchangeslinked'] = array(
866 'href' => $rclTitle->getLocalUrl()
868 } else {
869 $nav_urls['recentchangeslinked'] = false;
871 if ($wgUseTrackbacks)
872 $nav_urls['trackbacklink'] = array(
873 'href' => $wgTitle->trackbackURL()
877 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
878 $id = User::idFromName($this->mTitle->getText());
879 $ip = User::isIP($this->mTitle->getText());
880 } else {
881 $id = 0;
882 $ip = false;
885 if($id || $ip) { # both anons and non-anons have contri list
886 $nav_urls['contributions'] = array(
887 'href' => self::makeSpecialUrl( 'Contributions/' . $this->mTitle->getText() )
889 if ( $wgUser->isAllowed( 'block' ) ) {
890 $nav_urls['blockip'] = array(
891 'href' => self::makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
893 } else {
894 $nav_urls['blockip'] = false;
896 } else {
897 $nav_urls['contributions'] = false;
898 $nav_urls['blockip'] = false;
900 $nav_urls['emailuser'] = false;
901 if( $this->showEmailUser( $id ) ) {
902 $nav_urls['emailuser'] = array(
903 'href' => self::makeSpecialUrl( 'Emailuser/' . $this->mTitle->getText() )
906 wfProfileOut( $fname );
907 return $nav_urls;
911 * Generate strings used for xml 'id' names
912 * @return string
913 * @private
915 function getNameSpaceKey () {
916 return $this->mTitle->getNamespaceKey();
920 * @private
922 function setupUserCss() {
923 $fname = 'SkinTemplate::setupUserCss';
924 wfProfileIn( $fname );
926 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
928 $sitecss = '';
929 $usercss = '';
930 $siteargs = '&maxage=' . $wgSquidMaxage;
931 if( $this->loggedin ) {
932 // Ensure that logged-in users' generated CSS isn't clobbered
933 // by anons' publicly cacheable generated CSS.
934 $siteargs .= '&smaxage=0';
937 # Add user-specific code if this is a user and we allow that kind of thing
939 if ( $wgAllowUserCss && $this->loggedin ) {
940 $action = $wgRequest->getText('action');
942 # if we're previewing the CSS page, use it
943 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
944 $siteargs = "&smaxage=0&maxage=0";
945 $usercss = $wgRequest->getText('wpTextbox1');
946 } else {
947 $usercss = '@import "' .
948 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
949 'action=raw&ctype=text/css') . '";' ."\n";
952 $siteargs .= '&ts=' . $wgUser->mTouched;
955 if( $wgContLang->isRTL() ) {
956 global $wgStyleVersion;
957 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
960 # If we use the site's dynamic CSS, throw that in, too
961 if ( $wgUseSiteCss ) {
962 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
963 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
964 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
965 $sitecss .= '@import "' . self::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
968 # If we use any dynamic CSS, make a little CDATA block out of it.
970 if ( !empty($sitecss) || !empty($usercss) ) {
971 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
973 wfProfileOut( $fname );
977 * @private
979 function setupUserJs() {
980 $fname = 'SkinTemplate::setupUserJs';
981 wfProfileIn( $fname );
983 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
984 $action = $wgRequest->getText('action');
986 if( $wgAllowUserJs && $this->loggedin ) {
987 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
988 # XXX: additional security check/prompt?
989 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
990 } else {
991 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
994 wfProfileOut( $fname );
998 * Code for extensions to hook into to provide per-page CSS, see
999 * extensions/PageCSS/PageCSS.php for an implementation of this.
1001 * @private
1003 function setupPageCss() {
1004 $fname = 'SkinTemplate::setupPageCss';
1005 wfProfileIn( $fname );
1006 $out = false;
1007 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1009 wfProfileOut( $fname );
1010 return $out;
1014 * returns css with user-specific options
1015 * @public
1018 function getUserStylesheet() {
1019 $fname = 'SkinTemplate::getUserStylesheet';
1020 wfProfileIn( $fname );
1022 $s = "/* generated user stylesheet */\n";
1023 $s .= $this->reallyDoGetUserStyles();
1024 wfProfileOut( $fname );
1025 return $s;
1029 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1030 * nated together. For some bizarre reason, it does *not* return any
1031 * custom user JS from subpages. Huh?
1033 * There's absolutely no reason to have separate Monobook/Common JSes.
1034 * Any JS that cares can just check the skin variable generated at the
1035 * top. For now Monobook.js will be maintained, but it should be consi-
1036 * dered deprecated.
1038 * @return string
1040 public function getUserJs() {
1041 $fname = 'SkinTemplate::getUserJs';
1042 wfProfileIn( $fname );
1044 $s = parent::getUserJs();
1045 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1047 // avoid inclusion of non defined user JavaScript (with custom skins only)
1048 // by checking for default message content
1049 $msgKey = ucfirst($this->skinname).'.js';
1050 $userJS = wfMsgForContent($msgKey);
1051 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1052 $s .= $userJS;
1055 wfProfileOut( $fname );
1056 return $s;
1061 * Generic wrapper for template functions, with interface
1062 * compatible with what we use of PHPTAL 0.7.
1063 * @package MediaWiki
1064 * @subpackage Skins
1066 class QuickTemplate {
1068 * @public
1070 function QuickTemplate() {
1071 $this->data = array();
1072 $this->translator = new MediaWiki_I18N();
1076 * @public
1078 function set( $name, $value ) {
1079 $this->data[$name] = $value;
1083 * @public
1085 function setRef($name, &$value) {
1086 $this->data[$name] =& $value;
1090 * @public
1092 function setTranslator( &$t ) {
1093 $this->translator = &$t;
1097 * @public
1099 function execute() {
1100 echo "Override this function.";
1105 * @private
1107 function text( $str ) {
1108 echo htmlspecialchars( $this->data[$str] );
1112 * @private
1114 function jstext( $str ) {
1115 echo Xml::escapeJsString( $this->data[$str] );
1119 * @private
1121 function html( $str ) {
1122 echo $this->data[$str];
1126 * @private
1128 function msg( $str ) {
1129 echo htmlspecialchars( $this->translator->translate( $str ) );
1133 * @private
1135 function msgHtml( $str ) {
1136 echo $this->translator->translate( $str );
1140 * An ugly, ugly hack.
1141 * @private
1143 function msgWiki( $str ) {
1144 global $wgParser, $wgTitle, $wgOut;
1146 $text = $this->translator->translate( $str );
1147 $parserOutput = $wgParser->parse( $text, $wgTitle,
1148 $wgOut->parserOptions(), true );
1149 echo $parserOutput->getText();
1153 * @private
1155 function haveData( $str ) {
1156 return isset( $this->data[$str] );
1160 * @private
1162 function haveMsg( $str ) {
1163 $msg = $this->translator->translate( $str );
1164 return ($msg != '-') && ($msg != ''); # ????