*Re-add some things lost in merge
[mediawiki.git] / includes / SkinTemplate.php
blob7c4cf12d449f4e0add077abcc775665376805d68
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 * @addtogroup Skins
33 /**
34 * Wrapper object for MediaWiki's localization functions,
35 * to be passed to the template engine.
37 * @private
39 class MediaWiki_I18N {
40 var $_context = array();
42 function set($varName, $value) {
43 $this->_context[$varName] = $value;
46 function translate($value) {
47 $fname = 'SkinTemplate-translate';
48 wfProfileIn( $fname );
50 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
51 $value = preg_replace( '/^string:/', '', $value );
53 $value = wfMsg( $value );
54 // interpolate variables
55 $m = array();
56 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
57 list($src, $var) = $m;
58 wfSuppressWarnings();
59 $varValue = $this->_context[$var];
60 wfRestoreWarnings();
61 $value = str_replace($src, $varValue, $value);
63 wfProfileOut( $fname );
64 return $value;
68 /**
71 class SkinTemplate extends Skin {
72 /**#@+
73 * @private
76 /**
77 * Name of our skin, set in initPage()
78 * It probably need to be all lower case.
80 var $skinname;
82 /**
83 * Stylesheets set to use
84 * Sub directory in ./skins/ where various stylesheets are located
86 var $stylename;
88 /**
89 * For QuickTemplate, the name of the subclass which
90 * will actually fill the template.
92 var $template;
94 /**#@-*/
96 /**
97 * Setup the base parameters...
98 * Child classes should override this to set the name,
99 * style subdirectory, and template filler callback.
101 * @param OutputPage $out
103 function initPage( &$out ) {
104 parent::initPage( $out );
105 $this->skinname = 'monobook';
106 $this->stylename = 'monobook';
107 $this->template = 'QuickTemplate';
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
115 * @param string $callback (or file)
116 * @param string $repository subdirectory where we keep template files
117 * @param string $cache_dir
118 * @return object
119 * @private
121 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
122 return new $classname();
126 * initialize various variables and generate the template
128 * @param OutputPage $out
129 * @public
131 function outputPage( &$out ) {
132 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
133 global $wgScript, $wgStylePath, $wgContLanguageCode;
134 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
135 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
136 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
137 global $wgMaxCredits, $wgShowCreditsIfMax;
138 global $wgPageShowWatchingUsers;
139 global $wgUseTrackbacks;
140 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
142 $fname = 'SkinTemplate::outputPage';
143 wfProfileIn( $fname );
145 // Hook that allows last minute changes to the output page, e.g.
146 // adding of CSS or Javascript by extensions.
147 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
152 wfProfileIn( "$fname-init" );
153 $this->initPage( $out );
155 $this->mTitle =& $wgTitle;
156 $this->mUser =& $wgUser;
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( "$fname-init" );
165 wfProfileIn( "$fname-stuff" );
166 $this->thispage = $this->mTitle->getPrefixedDbKey();
167 $this->thisurl = $this->mTitle->getPrefixedURL();
168 $this->loggedin = $wgUser->isLoggedIn();
169 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
170 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
171 $this->username = $wgUser->getName();
172 $userPage = $wgUser->getUserPage();
173 $this->userpage = $userPage->getPrefixedText();
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->usercss = $this->userjs = $this->userjsprev = false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt = $this->mTitle->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
193 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
195 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
196 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
197 $this->mTitle->getNsText();
199 $tpl->set( 'nscanonical', $nsname );
200 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
201 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
202 $tpl->set( 'titletext', $this->mTitle->getText() );
203 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
204 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
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( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
248 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
249 $tpl->setRef( 'mimetype', $wgMimeType );
250 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
251 $tpl->setRef( 'charset', $wgOutputEncoding );
252 $tpl->set( 'headlinks', $out->getHeadLinks() );
253 $tpl->set('headscripts', $out->getScript() );
254 $tpl->setRef( 'wgScript', $wgScript );
255 $tpl->setRef( 'skinname', $this->skinname );
256 $tpl->set( 'skinclass', get_class( $this ) );
257 $tpl->setRef( 'stylename', $this->stylename );
258 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
259 $tpl->setRef( 'loggedin', $this->loggedin );
260 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
261 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
262 /* XXX currently unused, might get useful later
263 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
264 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
265 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
266 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
267 $tpl->set( "helppage", wfMsg('helppage'));
269 $tpl->set( 'searchaction', $this->escapeSearchLink() );
270 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
271 $tpl->setRef( 'stylepath', $wgStylePath );
272 $tpl->setRef( 'articlepath', $wgArticlePath );
273 $tpl->setRef( 'scriptpath', $wgScriptPath );
274 $tpl->setRef( 'serverurl', $wgServer );
275 $tpl->setRef( 'logopath', $wgLogo );
276 $tpl->setRef( "lang", $wgContLanguageCode );
277 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
278 $tpl->set( 'rtl', $wgContLang->isRTL() );
279 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
280 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
281 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
282 $tpl->setRef( 'userpage', $this->userpage);
283 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
284 $tpl->set( 'userlang', $wgLang->getCode() );
285 $tpl->set( 'pagecss', $this->setupPageCss() );
286 $tpl->setRef( 'usercss', $this->usercss);
287 $tpl->setRef( 'userjs', $this->userjs);
288 $tpl->setRef( 'userjsprev', $this->userjsprev);
289 global $wgUseSiteJs;
290 if ($wgUseSiteJs) {
291 if($this->loggedin) {
292 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&smaxage=0&gen=js') );
293 } else {
294 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&gen=js') );
296 } else {
297 $tpl->set('jsvarurl', false);
299 $newtalks = $wgUser->getNewMessageLinks();
301 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
302 $usertitle = $this->mUser->getUserPage();
303 $usertalktitle = $usertitle->getTalkPage();
304 if( !$usertalktitle->equals( $this->mTitle ) ) {
305 $ntl = wfMsg( 'youhavenewmessages',
306 $this->makeKnownLinkObj(
307 $usertalktitle,
308 wfMsgHtml( 'newmessageslink' ),
309 'redirect=no'
311 $this->makeKnownLinkObj(
312 $usertalktitle,
313 wfMsgHtml( 'newmessagesdifflink' ),
314 'diff=cur'
317 # Disable Cache
318 $wgOut->setSquidMaxage(0);
320 } else if (count($newtalks)) {
321 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
322 $msgs = array();
323 foreach ($newtalks as $newtalk) {
324 $msgs[] = wfElement("a",
325 array('href' => $newtalk["link"]), $newtalk["wiki"]);
327 $parts = implode($sep, $msgs);
328 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
329 $wgOut->setSquidMaxage(0);
330 } else {
331 $ntl = '';
333 wfProfileOut( "$fname-stuff2" );
335 wfProfileIn( "$fname-stuff3" );
336 $tpl->setRef( 'newtalk', $ntl );
337 $tpl->setRef( 'skin', $this);
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
340 $wgArticle and 0 != $wgArticle->getID() )
342 if ( !$wgDisableCounters ) {
343 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
344 if ( $viewcount ) {
345 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
346 } else {
347 $tpl->set('viewcount', false);
349 } else {
350 $tpl->set('viewcount', false);
353 if ($wgPageShowWatchingUsers) {
354 $dbr = wfGetDB( DB_SLAVE );
355 $watchlist = $dbr->tableName( 'watchlist' );
356 $sql = "SELECT COUNT(*) AS n FROM $watchlist
357 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
358 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
359 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n;
362 if ($numberofwatchingusers > 0) {
363 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
364 } else {
365 $tpl->set('numberofwatchingusers', false);
367 } else {
368 $tpl->set('numberofwatchingusers', false);
371 $tpl->set('copyright',$this->getCopyright());
373 $this->credits = false;
375 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
376 require_once("Credits.php");
377 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
378 } else {
379 $tpl->set('lastmod', $this->lastModified());
382 $tpl->setRef( 'credits', $this->credits );
384 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
385 $tpl->set('copyright', $this->getCopyright());
386 $tpl->set('viewcount', false);
387 $tpl->set('lastmod', false);
388 $tpl->set('credits', false);
389 $tpl->set('numberofwatchingusers', false);
390 } else {
391 $tpl->set('copyright', false);
392 $tpl->set('viewcount', false);
393 $tpl->set('lastmod', false);
394 $tpl->set('credits', false);
395 $tpl->set('numberofwatchingusers', false);
397 wfProfileOut( "$fname-stuff3" );
399 wfProfileIn( "$fname-stuff4" );
400 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
401 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
402 $tpl->set( 'disclaimer', $this->disclaimerLink() );
403 $tpl->set( 'privacy', $this->privacyLink() );
404 $tpl->set( 'about', $this->aboutLink() );
406 $tpl->setRef( 'debug', $out->mDebugtext );
407 $tpl->set( 'reporttime', $out->reportTime() );
408 $tpl->set( 'sitenotice', wfGetSiteNotice() );
409 $tpl->set( 'bottomscripts', $this->bottomScripts() );
411 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
412 $out->mBodytext .= $printfooter ;
413 $tpl->setRef( 'bodytext', $out->mBodytext );
415 # Language links
416 $language_urls = array();
418 if ( !$wgHideInterlanguageLinks ) {
419 foreach( $wgOut->getLanguageLinks() as $l ) {
420 $tmp = explode( ':', $l, 2 );
421 $class = 'interwiki-' . $tmp[0];
422 unset($tmp);
423 $nt = Title::newFromText( $l );
424 $language_urls[] = array(
425 'href' => $nt->getFullURL(),
426 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
427 'class' => $class
431 if(count($language_urls)) {
432 $tpl->setRef( 'language_urls', $language_urls);
433 } else {
434 $tpl->set('language_urls', false);
436 wfProfileOut( "$fname-stuff4" );
438 # Personal toolbar
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable && $wgUser->getOption("editondblclick") )
446 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
447 } else {
448 $tpl->set('body_ondblclick', false);
450 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
451 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
452 } else {
453 $tpl->set( 'body_onload', false );
455 $tpl->set( 'sidebar', $this->buildSidebar() );
456 $tpl->set( 'nav_urls', $this->buildNavUrls() );
458 // original version by hansm
459 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
460 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
463 // execute template
464 wfProfileIn( "$fname-execute" );
465 $res = $tpl->execute();
466 wfProfileOut( "$fname-execute" );
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( $fname );
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
478 * @param mixed $str
479 * @private
481 function printOrError( $str ) {
482 echo $str;
486 * build array of urls for personal toolbar
487 * @return array
488 * @private
490 function buildPersonalUrls() {
491 global $wgTitle;
493 $fname = 'SkinTemplate::buildPersonalUrls';
494 $pageurl = $wgTitle->getLocalURL();
495 wfProfileIn( $fname );
497 /* set up the default links for the personal toolbar */
498 $personal_urls = array();
499 if ($this->loggedin) {
500 $personal_urls['userpage'] = array(
501 'text' => $this->username,
502 'href' => &$this->userpageUrlDetails['href'],
503 'class' => $this->userpageUrlDetails['exists']?false:'new',
504 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
506 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
507 $personal_urls['mytalk'] = array(
508 'text' => wfMsg('mytalk'),
509 'href' => &$usertalkUrlDetails['href'],
510 'class' => $usertalkUrlDetails['exists']?false:'new',
511 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
513 $href = self::makeSpecialUrl( 'Preferences' );
514 $personal_urls['preferences'] = array(
515 'text' => wfMsg( 'mypreferences' ),
516 'href' => self::makeSpecialUrl( 'Preferences' ),
517 'active' => ( $href == $pageurl )
519 $href = self::makeSpecialUrl( 'Watchlist' );
520 $personal_urls['watchlist'] = array(
521 'text' => wfMsg( 'watchlist' ),
522 'href' => $href,
523 'active' => ( $href == $pageurl )
525 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
526 $personal_urls['mycontris'] = array(
527 'text' => wfMsg( 'mycontris' ),
528 'href' => $href,
529 // FIXME # 'active' was disabled in r11346 with message: "disable bold link to my contributions; link was bold on all
530 // Special:Contributions, not just current user's (fix me please!)". Until resolved (bug 4764), explicitly setting active to false.
531 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
533 $personal_urls['logout'] = array(
534 'text' => wfMsg( 'userlogout' ),
535 'href' => self::makeSpecialUrl( 'Userlogout',
536 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
538 'active' => false
540 } else {
541 if( $this->showIPinHeader() ) {
542 $href = &$this->userpageUrlDetails['href'];
543 $personal_urls['anonuserpage'] = array(
544 'text' => $this->username,
545 'href' => $href,
546 'class' => $this->userpageUrlDetails['exists']?false:'new',
547 'active' => ( $pageurl == $href )
549 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
550 $href = &$usertalkUrlDetails['href'];
551 $personal_urls['anontalk'] = array(
552 'text' => wfMsg('anontalk'),
553 'href' => $href,
554 'class' => $usertalkUrlDetails['exists']?false:'new',
555 'active' => ( $pageurl == $href )
557 $personal_urls['anonlogin'] = array(
558 'text' => wfMsg('userlogin'),
559 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
560 'active' => $wgTitle->isSpecial( 'Userlogin' )
562 } else {
564 $personal_urls['login'] = array(
565 'text' => wfMsg('userlogin'),
566 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
567 'active' => $wgTitle->isSpecial( 'Userlogin' )
572 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
573 wfProfileOut( $fname );
574 return $personal_urls;
577 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
578 $classes = array();
579 if( $selected ) {
580 $classes[] = 'selected';
582 if( $checkEdit && $title->getArticleId() == 0 ) {
583 $classes[] = 'new';
584 $query = 'action=edit';
587 $text = wfMsg( $message );
588 if ( wfEmptyMsg( $message, $text ) ) {
589 global $wgContLang;
590 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
593 return array(
594 'class' => implode( ' ', $classes ),
595 'text' => $text,
596 'href' => $title->getLocalUrl( $query ) );
599 function makeTalkUrlDetails( $name, $urlaction = '' ) {
600 $title = Title::newFromText( $name );
601 if( !is_object($title) ) {
602 throw new MWException( __METHOD__." given invalid pagename $name" );
604 $title = $title->getTalkPage();
605 self::checkTitle( $title, $name );
606 return array(
607 'href' => $title->getLocalURL( $urlaction ),
608 'exists' => $title->getArticleID() != 0 ? true : false
612 function makeArticleUrlDetails( $name, $urlaction = '' ) {
613 $title = Title::newFromText( $name );
614 $title= $title->getSubjectPage();
615 self::checkTitle( $title, $name );
616 return array(
617 'href' => $title->getLocalURL( $urlaction ),
618 'exists' => $title->getArticleID() != 0 ? true : false
623 * an array of edit links by default used for the tabs
624 * @return array
625 * @private
627 function buildContentActionUrls () {
628 global $wgContLang, $wgOut;
629 $fname = 'SkinTemplate::buildContentActionUrls';
630 wfProfileIn( $fname );
632 global $wgUser, $wgRequest;
633 $action = $wgRequest->getText( 'action' );
634 $section = $wgRequest->getText( 'section' );
635 $content_actions = array();
637 $prevent_active_tabs = false ;
638 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
640 if( $this->iscontent ) {
641 $subjpage = $this->mTitle->getSubjectPage();
642 $talkpage = $this->mTitle->getTalkPage();
644 $nskey = $this->mTitle->getNamespaceKey();
645 $content_actions[$nskey] = $this->tabAction(
646 $subjpage,
647 $nskey,
648 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
649 '', true);
651 $content_actions['talk'] = $this->tabAction(
652 $talkpage,
653 'talk',
654 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
656 true);
658 wfProfileIn( "$fname-edit" );
659 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
660 $istalk = $this->mTitle->isTalkPage();
661 $istalkclass = $istalk?' istalk':'';
662 $content_actions['edit'] = array(
663 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
664 'text' => wfMsg('edit'),
665 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
668 if ( $istalk || $wgOut->showNewSectionLink() ) {
669 $content_actions['addsection'] = array(
670 'class' => $section == 'new'?'selected':false,
671 'text' => wfMsg('addsection'),
672 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
675 } else {
676 $content_actions['viewsource'] = array(
677 'class' => ($action == 'edit') ? 'selected' : false,
678 'text' => wfMsg('viewsource'),
679 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
682 wfProfileOut( "$fname-edit" );
684 wfProfileIn( "$fname-live" );
685 if ( $this->mTitle->getArticleId() ) {
687 $content_actions['history'] = array(
688 'class' => ($action == 'history') ? 'selected' : false,
689 'text' => wfMsg('history_short'),
690 'href' => $this->mTitle->getLocalUrl( 'action=history')
693 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
694 if(!$this->mTitle->isProtected()){
695 $content_actions['protect'] = array(
696 'class' => ($action == 'protect') ? 'selected' : false,
697 'text' => wfMsg('protect'),
698 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
701 } else {
702 $content_actions['unprotect'] = array(
703 'class' => ($action == 'unprotect') ? 'selected' : false,
704 'text' => wfMsg('unprotect'),
705 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
709 if($wgUser->isAllowed('delete')){
710 $content_actions['delete'] = array(
711 'class' => ($action == 'delete') ? 'selected' : false,
712 'text' => wfMsg('delete'),
713 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
716 if ( $this->mTitle->quickUserCan( 'move' ) ) {
717 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
718 $content_actions['move'] = array(
719 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
720 'text' => wfMsg('move'),
721 'href' => $moveTitle->getLocalUrl()
724 } else {
725 //article doesn't exist or is deleted
726 if( $wgUser->isAllowed( 'delete' ) ) {
727 if( $n = $this->mTitle->isDeleted() ) {
728 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
729 $content_actions['undelete'] = array(
730 'class' => false,
731 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
732 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
733 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
738 wfProfileOut( "$fname-live" );
740 if( $this->loggedin ) {
741 if( !$this->mTitle->userIsWatching()) {
742 $content_actions['watch'] = array(
743 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
744 'text' => wfMsg('watch'),
745 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
747 } else {
748 $content_actions['unwatch'] = array(
749 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
750 'text' => wfMsg('unwatch'),
751 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
756 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
757 } else {
758 /* show special page tab */
760 $content_actions[$this->mTitle->getNamespaceKey()] = array(
761 'class' => 'selected',
762 'text' => wfMsg('nstab-special'),
763 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
766 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
769 /* show links to different language variants */
770 global $wgDisableLangConversion;
771 $variants = $wgContLang->getVariants();
772 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
773 $preferred = $wgContLang->getPreferredVariant();
774 $vcount=0;
775 foreach( $variants as $code ) {
776 $varname = $wgContLang->getVariantname( $code );
777 if( $varname == 'disable' )
778 continue;
779 $selected = ( $code == $preferred )? 'selected' : false;
780 $content_actions['varlang-' . $vcount] = array(
781 'class' => $selected,
782 'text' => $varname,
783 'href' => $this->mTitle->getLocalURL('',$code)
785 $vcount ++;
789 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
791 wfProfileOut( $fname );
792 return $content_actions;
798 * build array of common navigation links
799 * @return array
800 * @private
802 function buildNavUrls () {
803 global $wgUseTrackbacks, $wgTitle, $wgArticle;
805 $fname = 'SkinTemplate::buildNavUrls';
806 wfProfileIn( $fname );
808 global $wgUser, $wgRequest;
809 global $wgEnableUploads, $wgUploadNavigationUrl;
811 $action = $wgRequest->getText( 'action' );
812 $oldid = $wgRequest->getVal( 'oldid' );
814 $nav_urls = array();
815 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
816 if( $wgEnableUploads ) {
817 if ($wgUploadNavigationUrl) {
818 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
819 } else {
820 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
822 } else {
823 if ($wgUploadNavigationUrl)
824 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
825 else
826 $nav_urls['upload'] = false;
828 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
830 // default permalink to being off, will override it as required below.
831 $nav_urls['permalink'] = false;
833 // A print stylesheet is attached to all pages, but nobody ever
834 // figures that out. :) Add a link...
835 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
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 $revid = $wgArticle ? $wgArticle->getLatest() : 0;
849 if ( !( $revid == 0 ) )
850 $nav_urls['permalink'] = array(
851 'text' => wfMsg( 'permalink' ),
852 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
856 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
859 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
860 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
861 $nav_urls['whatlinkshere'] = array(
862 'href' => $wlhTitle->getLocalUrl()
864 if( $this->mTitle->getArticleId() ) {
865 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
866 $nav_urls['recentchangeslinked'] = array(
867 'href' => $rclTitle->getLocalUrl()
869 } else {
870 $nav_urls['recentchangeslinked'] = false;
872 if ($wgUseTrackbacks)
873 $nav_urls['trackbacklink'] = array(
874 'href' => $wgTitle->trackbackURL()
878 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
879 $id = User::idFromName($this->mTitle->getText());
880 $ip = User::isIP($this->mTitle->getText());
881 } else {
882 $id = 0;
883 $ip = false;
886 if($id || $ip) { # both anons and non-anons have contri list
887 $nav_urls['contributions'] = array(
888 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
890 if ( $wgUser->isAllowed( 'block' ) ) {
891 $nav_urls['blockip'] = array(
892 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
894 } else {
895 $nav_urls['blockip'] = false;
897 } else {
898 $nav_urls['contributions'] = false;
899 $nav_urls['blockip'] = false;
901 $nav_urls['emailuser'] = false;
902 if( $this->showEmailUser( $id ) ) {
903 $nav_urls['emailuser'] = array(
904 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
907 wfProfileOut( $fname );
908 return $nav_urls;
912 * Generate strings used for xml 'id' names
913 * @return string
914 * @private
916 function getNameSpaceKey () {
917 return $this->mTitle->getNamespaceKey();
921 * @private
923 function setupUserCss() {
924 $fname = 'SkinTemplate::setupUserCss';
925 wfProfileIn( $fname );
927 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
929 $sitecss = '';
930 $usercss = '';
931 $siteargs = '&maxage=' . $wgSquidMaxage;
932 if( $this->loggedin ) {
933 // Ensure that logged-in users' generated CSS isn't clobbered
934 // by anons' publicly cacheable generated CSS.
935 $siteargs .= '&smaxage=0';
938 # Add user-specific code if this is a user and we allow that kind of thing
940 if ( $wgAllowUserCss && $this->loggedin ) {
941 $action = $wgRequest->getText('action');
943 # if we're previewing the CSS page, use it
944 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
945 $siteargs = "&smaxage=0&maxage=0";
946 $usercss = $wgRequest->getText('wpTextbox1');
947 } else {
948 $usercss = '@import "' .
949 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
950 'action=raw&ctype=text/css') . '";' ."\n";
953 $siteargs .= '&ts=' . $wgUser->mTouched;
956 if( $wgContLang->isRTL() ) {
957 global $wgStyleVersion;
958 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
961 # If we use the site's dynamic CSS, throw that in, too
962 if ( $wgUseSiteCss ) {
963 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
964 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
965 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
966 $sitecss .= '@import "' . self::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
969 # If we use any dynamic CSS, make a little CDATA block out of it.
971 if ( !empty($sitecss) || !empty($usercss) ) {
972 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
974 wfProfileOut( $fname );
978 * @private
980 function setupUserJs() {
981 $fname = 'SkinTemplate::setupUserJs';
982 wfProfileIn( $fname );
984 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
985 $action = $wgRequest->getText('action');
987 if( $wgAllowUserJs && $this->loggedin ) {
988 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
989 # XXX: additional security check/prompt?
990 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
991 } else {
992 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
995 wfProfileOut( $fname );
999 * Code for extensions to hook into to provide per-page CSS, see
1000 * extensions/PageCSS/PageCSS.php for an implementation of this.
1002 * @private
1004 function setupPageCss() {
1005 $fname = 'SkinTemplate::setupPageCss';
1006 wfProfileIn( $fname );
1007 $out = false;
1008 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1010 wfProfileOut( $fname );
1011 return $out;
1015 * returns css with user-specific options
1016 * @public
1019 function getUserStylesheet() {
1020 $fname = 'SkinTemplate::getUserStylesheet';
1021 wfProfileIn( $fname );
1023 $s = "/* generated user stylesheet */\n";
1024 $s .= $this->reallyDoGetUserStyles();
1025 wfProfileOut( $fname );
1026 return $s;
1030 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1031 * nated together. For some bizarre reason, it does *not* return any
1032 * custom user JS from subpages. Huh?
1034 * There's absolutely no reason to have separate Monobook/Common JSes.
1035 * Any JS that cares can just check the skin variable generated at the
1036 * top. For now Monobook.js will be maintained, but it should be consi-
1037 * dered deprecated.
1039 * @return string
1041 public function getUserJs() {
1042 $fname = 'SkinTemplate::getUserJs';
1043 wfProfileIn( $fname );
1045 $s = parent::getUserJs();
1046 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1048 // avoid inclusion of non defined user JavaScript (with custom skins only)
1049 // by checking for default message content
1050 $msgKey = ucfirst($this->skinname).'.js';
1051 $userJS = wfMsgForContent($msgKey);
1052 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1053 $s .= $userJS;
1056 wfProfileOut( $fname );
1057 return $s;
1062 * Generic wrapper for template functions, with interface
1063 * compatible with what we use of PHPTAL 0.7.
1064 * @addtogroup 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 != ''); # ????