Fixed regex in doMagicLinks (broken since r15976)
[mediawiki.git] / includes / SkinTemplate.php
blob496219dbce1ddc612fb381e8ba17005560ec215d
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 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
58 list($src, $var) = $m;
59 wfSuppressWarnings();
60 $varValue = $this->_context[$var];
61 wfRestoreWarnings();
62 $value = str_replace($src, $varValue, $value);
64 wfProfileOut( $fname );
65 return $value;
69 /**
71 * @package MediaWiki
73 class SkinTemplate extends Skin {
74 /**#@+
75 * @private
78 /**
79 * Name of our skin, set in initPage()
80 * It probably need to be all lower case.
82 var $skinname;
84 /**
85 * Stylesheets set to use
86 * Sub directory in ./skins/ where various stylesheets are located
88 var $stylename;
90 /**
91 * For QuickTemplate, the name of the subclass which
92 * will actually fill the template.
94 var $template;
96 /**#@-*/
98 /**
99 * Setup the base parameters...
100 * Child classes should override this to set the name,
101 * style subdirectory, and template filler callback.
103 * @param OutputPage $out
105 function initPage( &$out ) {
106 parent::initPage( $out );
107 $this->skinname = 'monobook';
108 $this->stylename = 'monobook';
109 $this->template = 'QuickTemplate';
113 * Create the template engine object; we feed it a bunch of data
114 * and eventually it spits out some HTML. Should have interface
115 * roughly equivalent to PHPTAL 0.7.
117 * @param string $callback (or file)
118 * @param string $repository subdirectory where we keep template files
119 * @param string $cache_dir
120 * @return object
121 * @private
123 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
124 return new $classname();
128 * initialize various variables and generate the template
130 * @param OutputPage $out
131 * @public
133 function outputPage( &$out ) {
134 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
135 global $wgScript, $wgStylePath, $wgContLanguageCode;
136 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
137 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
138 global $wgMaxCredits, $wgShowCreditsIfMax;
139 global $wgPageShowWatchingUsers;
140 global $wgUseTrackbacks;
141 global $wgDBname;
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 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
153 wfProfileIn( "$fname-init" );
154 $this->initPage( $out );
156 $this->mTitle =& $wgTitle;
157 $this->mUser =& $wgUser;
159 $tpl = $this->setupTemplate( $this->template, 'skins' );
161 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
162 $tpl->setTranslator(new MediaWiki_I18N());
164 wfProfileOut( "$fname-init" );
166 wfProfileIn( "$fname-stuff" );
167 $this->thispage = $this->mTitle->getPrefixedDbKey();
168 $this->thisurl = $this->mTitle->getPrefixedURL();
169 $this->loggedin = $wgUser->isLoggedIn();
170 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
171 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
172 $this->username = $wgUser->getName();
173 $userPage = $wgUser->getUserPage();
174 $this->userpage = $userPage->getPrefixedText();
176 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
177 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
178 } else {
179 # This won't be used in the standard skins, but we define it to preserve the interface
180 # To save time, we check for existence
181 $this->userpageUrlDetails = $this->makeKnownUrlDetails($this->userpage);
184 $this->usercss = $this->userjs = $this->userjsprev = false;
185 $this->setupUserCss();
186 $this->setupUserJs();
187 $this->titletxt = $this->mTitle->getPrefixedText();
188 wfProfileOut( "$fname-stuff" );
190 wfProfileIn( "$fname-stuff2" );
191 $tpl->set( 'title', $wgOut->getPageTitle() );
192 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
193 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
195 $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ];
196 if ( $nsname === NULL ) $nsname = $this->mTitle->getNsText();
198 $tpl->set( 'nscanonical', $nsname );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle->getText() );
201 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
203 $tpl->setRef( "thispage", $this->thispage );
204 $subpagestr = $this->subPageSubtitle();
205 $tpl->set(
206 'subtitle', !empty($subpagestr)?
207 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
208 $out->getSubtitle()
210 $undelete = $this->getUndeleteLink();
211 $tpl->set(
212 "undelete", !empty($undelete)?
213 '<span class="subpages">'.$undelete.'</span>':
217 $tpl->set( 'catlinks', $this->getCategories());
218 if( $wgOut->isSyndicated() ) {
219 $feeds = array();
220 foreach( $wgFeedClasses as $format => $class ) {
221 $feeds[$format] = array(
222 'text' => $format,
223 'href' => $wgRequest->appendQuery( "feed=$format" )
226 $tpl->setRef( 'feeds', $feeds );
227 } else {
228 $tpl->set( 'feeds', false );
230 if ($wgUseTrackbacks && $out->isArticleRelated())
231 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
233 $tpl->setRef( 'mimetype', $wgMimeType );
234 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
235 $tpl->setRef( 'charset', $wgOutputEncoding );
236 $tpl->set( 'headlinks', $out->getHeadLinks() );
237 $tpl->set('headscripts', $out->getScript() );
238 $tpl->setRef( 'wgScript', $wgScript );
239 $tpl->setRef( 'skinname', $this->skinname );
240 $tpl->set( 'skinclass', get_class( $this ) );
241 $tpl->setRef( 'stylename', $this->stylename );
242 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
243 $tpl->setRef( 'loggedin', $this->loggedin );
244 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
245 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
246 /* XXX currently unused, might get useful later
247 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
248 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
249 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
250 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
251 $tpl->set( "helppage", wfMsg('helppage'));
253 $tpl->set( 'searchaction', $this->escapeSearchLink() );
254 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
255 $tpl->setRef( 'stylepath', $wgStylePath );
256 $tpl->setRef( 'articlepath', $wgArticlePath );
257 $tpl->setRef( 'scriptpath', $wgScriptPath );
258 $tpl->setRef( 'serverurl', $wgServer );
259 $tpl->setRef( 'logopath', $wgLogo );
260 $tpl->setRef( "lang", $wgContLanguageCode );
261 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
262 $tpl->set( 'rtl', $wgContLang->isRTL() );
263 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
264 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
265 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
266 $tpl->setRef( 'userpage', $this->userpage);
267 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
268 $tpl->set( 'userlang', $wgLang->getCode() );
269 $tpl->set( 'pagecss', $this->setupPageCss() );
270 $tpl->setRef( 'usercss', $this->usercss);
271 $tpl->setRef( 'userjs', $this->userjs);
272 $tpl->setRef( 'userjsprev', $this->userjsprev);
273 global $wgUseSiteJs;
274 if ($wgUseSiteJs) {
275 if($this->loggedin) {
276 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
277 } else {
278 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
280 } else {
281 $tpl->set('jsvarurl', false);
283 $newtalks = $wgUser->getNewMessageLinks();
285 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
286 $usertitle = $this->mUser->getUserPage();
287 $usertalktitle = $usertitle->getTalkPage();
288 if( !$usertalktitle->equals( $this->mTitle ) ) {
289 $ntl = wfMsg( 'youhavenewmessages',
290 $this->makeKnownLinkObj(
291 $usertalktitle,
292 wfMsgHtml( 'newmessageslink' ),
293 'redirect=no'
295 $this->makeKnownLinkObj(
296 $usertalktitle,
297 wfMsgHtml( 'newmessagesdifflink' ),
298 'diff=cur'
301 # Disable Cache
302 $wgOut->setSquidMaxage(0);
304 } else if (count($newtalks)) {
305 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
306 $msgs = array();
307 foreach ($newtalks as $newtalk) {
308 $msgs[] = wfElement("a",
309 array('href' => $newtalk["link"]), $newtalk["wiki"]);
311 $parts = implode($sep, $msgs);
312 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
313 $wgOut->setSquidMaxage(0);
314 } else {
315 $ntl = '';
317 wfProfileOut( "$fname-stuff2" );
319 wfProfileIn( "$fname-stuff3" );
320 $tpl->setRef( 'newtalk', $ntl );
321 $tpl->setRef( 'skin', $this);
322 $tpl->set( 'logo', $this->logoText() );
323 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
324 if ( !$wgDisableCounters ) {
325 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
326 if ( $viewcount ) {
327 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
328 } else {
329 $tpl->set('viewcount', false);
331 } else {
332 $tpl->set('viewcount', false);
335 if ($wgPageShowWatchingUsers) {
336 $dbr =& wfGetDB( DB_SLAVE );
337 extract( $dbr->tableNames( 'watchlist' ) );
338 $sql = "SELECT COUNT(*) AS n FROM $watchlist
339 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
340 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
341 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
342 $x = $dbr->fetchObject( $res );
343 $numberofwatchingusers = $x->n;
344 if ($numberofwatchingusers > 0) {
345 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
346 } else {
347 $tpl->set('numberofwatchingusers', false);
349 } else {
350 $tpl->set('numberofwatchingusers', false);
353 $tpl->set('copyright',$this->getCopyright());
355 $this->credits = false;
357 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
358 require_once("Credits.php");
359 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
360 } else {
361 $tpl->set('lastmod', $this->lastModified());
364 $tpl->setRef( 'credits', $this->credits );
366 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
367 $tpl->set('copyright', $this->getCopyright());
368 $tpl->set('viewcount', false);
369 $tpl->set('lastmod', false);
370 $tpl->set('credits', false);
371 $tpl->set('numberofwatchingusers', false);
372 } else {
373 $tpl->set('copyright', false);
374 $tpl->set('viewcount', false);
375 $tpl->set('lastmod', false);
376 $tpl->set('credits', false);
377 $tpl->set('numberofwatchingusers', false);
379 wfProfileOut( "$fname-stuff3" );
381 wfProfileIn( "$fname-stuff4" );
382 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
383 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
384 $tpl->set( 'disclaimer', $this->disclaimerLink() );
385 $tpl->set( 'privacy', $this->privacyLink() );
386 $tpl->set( 'about', $this->aboutLink() );
388 $tpl->setRef( 'debug', $out->mDebugtext );
389 $tpl->set( 'reporttime', $out->reportTime() );
390 $tpl->set( 'sitenotice', wfGetSiteNotice() );
391 $tpl->set( 'bottomscripts', $this->bottomScripts() );
393 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
394 $out->mBodytext .= $printfooter ;
395 $tpl->setRef( 'bodytext', $out->mBodytext );
397 # Language links
398 $language_urls = array();
400 if ( !$wgHideInterlanguageLinks ) {
401 foreach( $wgOut->getLanguageLinks() as $l ) {
402 $tmp = explode( ':', $l, 2 );
403 $class = 'interwiki-' . $tmp[0];
404 unset($tmp);
405 $nt = Title::newFromText( $l );
406 $language_urls[] = array(
407 'href' => $nt->getFullURL(),
408 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
409 'class' => $class
413 if(count($language_urls)) {
414 $tpl->setRef( 'language_urls', $language_urls);
415 } else {
416 $tpl->set('language_urls', false);
418 wfProfileOut( "$fname-stuff4" );
420 # Personal toolbar
421 $tpl->set('personal_urls', $this->buildPersonalUrls());
422 $content_actions = $this->buildContentActionUrls();
423 $tpl->setRef('content_actions', $content_actions);
425 // XXX: attach this from javascript, same with section editing
426 if($this->iseditable && $wgUser->getOption("editondblclick") )
428 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
429 } else {
430 $tpl->set('body_ondblclick', false);
432 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
433 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
434 } else {
435 $tpl->set( 'body_onload', false );
437 $tpl->set( 'sidebar', $this->buildSidebar() );
438 $tpl->set( 'nav_urls', $this->buildNavUrls() );
440 // execute template
441 wfProfileIn( "$fname-execute" );
442 $res = $tpl->execute();
443 wfProfileOut( "$fname-execute" );
445 // result may be an error
446 $this->printOrError( $res );
447 wfProfileOut( $fname );
451 * Output the string, or print error message if it's
452 * an error object of the appropriate type.
453 * For the base class, assume strings all around.
455 * @param mixed $str
456 * @private
458 function printOrError( &$str ) {
459 echo $str;
463 * build array of urls for personal toolbar
464 * @return array
465 * @private
467 function buildPersonalUrls() {
468 global $wgTitle, $wgShowIPinHeader;
470 $fname = 'SkinTemplate::buildPersonalUrls';
471 $pageurl = $wgTitle->getLocalURL();
472 wfProfileIn( $fname );
474 /* set up the default links for the personal toolbar */
475 $personal_urls = array();
476 if ($this->loggedin) {
477 $personal_urls['userpage'] = array(
478 'text' => $this->username,
479 'href' => &$this->userpageUrlDetails['href'],
480 'class' => $this->userpageUrlDetails['exists']?false:'new',
481 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
483 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
484 $personal_urls['mytalk'] = array(
485 'text' => wfMsg('mytalk'),
486 'href' => &$usertalkUrlDetails['href'],
487 'class' => $usertalkUrlDetails['exists']?false:'new',
488 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
490 $href = $this->makeSpecialUrl('Preferences');
491 $personal_urls['preferences'] = array(
492 'text' => wfMsg('preferences'),
493 'href' => $this->makeSpecialUrl('Preferences'),
494 'active' => ( $href == $pageurl )
496 $href = $this->makeSpecialUrl('Watchlist');
497 $personal_urls['watchlist'] = array(
498 'text' => wfMsg('watchlist'),
499 'href' => $href,
500 'active' => ( $href == $pageurl )
502 $href = $this->makeSpecialUrl("Contributions/$this->username");
503 $personal_urls['mycontris'] = array(
504 'text' => wfMsg('mycontris'),
505 'href' => $href
506 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
508 $personal_urls['logout'] = array(
509 'text' => wfMsg('userlogout'),
510 'href' => $this->makeSpecialUrl( 'Userlogout',
511 $wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"
514 } else {
515 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
516 $href = &$this->userpageUrlDetails['href'];
517 $personal_urls['anonuserpage'] = array(
518 'text' => $this->username,
519 'href' => $href,
520 'class' => $this->userpageUrlDetails['exists']?false:'new',
521 'active' => ( $pageurl == $href )
523 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
524 $href = &$usertalkUrlDetails['href'];
525 $personal_urls['anontalk'] = array(
526 'text' => wfMsg('anontalk'),
527 'href' => $href,
528 'class' => $usertalkUrlDetails['exists']?false:'new',
529 'active' => ( $pageurl == $href )
531 $personal_urls['anonlogin'] = array(
532 'text' => wfMsg('userlogin'),
533 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
534 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
536 } else {
538 $personal_urls['login'] = array(
539 'text' => wfMsg('userlogin'),
540 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
541 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
546 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
547 wfProfileOut( $fname );
548 return $personal_urls;
552 * Returns true if the IP should be shown in the header
554 function showIPinHeader() {
555 global $wgShowIPinHeader;
556 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
559 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
560 $classes = array();
561 if( $selected ) {
562 $classes[] = 'selected';
564 if( $checkEdit && $title->getArticleId() == 0 ) {
565 $classes[] = 'new';
566 $query = 'action=edit';
569 $text = wfMsg( $message );
570 if ( $text == "&lt;$message&gt;" ) {
571 global $wgContLang;
572 $text = $wgContLang->getNsText( Namespace::getSubject( $title->getNamespace() ) );
575 return array(
576 'class' => implode( ' ', $classes ),
577 'text' => $text,
578 'href' => $title->getLocalUrl( $query ) );
581 function makeTalkUrlDetails( $name, $urlaction='' ) {
582 $title = Title::newFromText( $name );
583 $title = $title->getTalkPage();
584 $this->checkTitle($title, $name);
585 return array(
586 'href' => $title->getLocalURL( $urlaction ),
587 'exists' => $title->getArticleID() != 0?true:false
591 function makeArticleUrlDetails( $name, $urlaction='' ) {
592 $title = Title::newFromText( $name );
593 $title= $title->getSubjectPage();
594 $this->checkTitle($title, $name);
595 return array(
596 'href' => $title->getLocalURL( $urlaction ),
597 'exists' => $title->getArticleID() != 0?true:false
602 * an array of edit links by default used for the tabs
603 * @return array
604 * @private
606 function buildContentActionUrls () {
607 global $wgContLang, $wgOut;
608 $fname = 'SkinTemplate::buildContentActionUrls';
609 wfProfileIn( $fname );
611 global $wgUser, $wgRequest;
612 $action = $wgRequest->getText( 'action' );
613 $section = $wgRequest->getText( 'section' );
614 $content_actions = array();
616 $prevent_active_tabs = false ;
617 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
619 if( $this->iscontent ) {
620 $subjpage = $this->mTitle->getSubjectPage();
621 $talkpage = $this->mTitle->getTalkPage();
623 $nskey = $this->mTitle->getNamespaceKey();
624 $content_actions[$nskey] = $this->tabAction(
625 $subjpage,
626 $nskey,
627 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
628 '', true);
630 $content_actions['talk'] = $this->tabAction(
631 $talkpage,
632 'talk',
633 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
635 true);
637 wfProfileIn( "$fname-edit" );
638 if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {
639 $istalk = $this->mTitle->isTalkPage();
640 $istalkclass = $istalk?' istalk':'';
641 $content_actions['edit'] = array(
642 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
643 'text' => wfMsg('edit'),
644 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
647 if ( $istalk || $wgOut->showNewSectionLink() ) {
648 $content_actions['addsection'] = array(
649 'class' => $section == 'new'?'selected':false,
650 'text' => wfMsg('addsection'),
651 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
654 } else {
655 $content_actions['viewsource'] = array(
656 'class' => ($action == 'edit') ? 'selected' : false,
657 'text' => wfMsg('viewsource'),
658 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
661 wfProfileOut( "$fname-edit" );
663 wfProfileIn( "$fname-live" );
664 if ( $this->mTitle->getArticleId() ) {
666 $content_actions['history'] = array(
667 'class' => ($action == 'history') ? 'selected' : false,
668 'text' => wfMsg('history_short'),
669 'href' => $this->mTitle->getLocalUrl( 'action=history')
672 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
673 if(!$this->mTitle->isProtected()){
674 $content_actions['protect'] = array(
675 'class' => ($action == 'protect') ? 'selected' : false,
676 'text' => wfMsg('protect'),
677 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
680 } else {
681 $content_actions['unprotect'] = array(
682 'class' => ($action == 'unprotect') ? 'selected' : false,
683 'text' => wfMsg('unprotect'),
684 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
688 if($wgUser->isAllowed('delete')){
689 $content_actions['delete'] = array(
690 'class' => ($action == 'delete') ? 'selected' : false,
691 'text' => wfMsg('delete'),
692 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
695 if ( $this->mTitle->userCanMove()) {
696 $moveTitle = Title::makeTitle( NS_SPECIAL, 'Movepage' );
697 $content_actions['move'] = array(
698 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
699 'text' => wfMsg('move'),
700 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
703 } else {
704 //article doesn't exist or is deleted
705 if( $wgUser->isAllowed( 'delete' ) ) {
706 if( $n = $this->mTitle->isDeleted() ) {
707 $undelTitle = Title::makeTitle( NS_SPECIAL, 'Undelete' );
708 $content_actions['undelete'] = array(
709 'class' => false,
710 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
711 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
712 #'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
717 wfProfileOut( "$fname-live" );
719 if( $this->loggedin ) {
720 if( !$this->mTitle->userIsWatching()) {
721 $content_actions['watch'] = array(
722 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
723 'text' => wfMsg('watch'),
724 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
726 } else {
727 $content_actions['unwatch'] = array(
728 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
729 'text' => wfMsg('unwatch'),
730 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
735 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
736 } else {
737 /* show special page tab */
739 $content_actions['article'] = array(
740 'class' => 'selected',
741 'text' => wfMsg('specialpage'),
742 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
745 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
748 /* show links to different language variants */
749 global $wgDisableLangConversion;
750 $variants = $wgContLang->getVariants();
751 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
752 $preferred = $wgContLang->getPreferredVariant();
753 $actstr = '';
754 if( $action )
755 $actstr = 'action=' . $action . '&';
756 $vcount=0;
757 foreach( $variants as $code ) {
758 $varname = $wgContLang->getVariantname( $code );
759 if( $varname == 'disable' )
760 continue;
761 $selected = ( $code == $preferred )? 'selected' : false;
762 $content_actions['varlang-' . $vcount] = array(
763 'class' => $selected,
764 'text' => $varname,
765 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
767 $vcount ++;
771 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
773 wfProfileOut( $fname );
774 return $content_actions;
780 * build array of common navigation links
781 * @return array
782 * @private
784 function buildNavUrls () {
785 global $wgUseTrackbacks, $wgTitle, $wgArticle;
787 $fname = 'SkinTemplate::buildNavUrls';
788 wfProfileIn( $fname );
790 global $wgUser, $wgRequest;
791 global $wgEnableUploads, $wgUploadNavigationUrl;
793 $action = $wgRequest->getText( 'action' );
794 $oldid = $wgRequest->getVal( 'oldid' );
795 $diff = $wgRequest->getVal( 'diff' );
797 $nav_urls = array();
798 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
799 if( $wgEnableUploads ) {
800 if ($wgUploadNavigationUrl) {
801 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
802 } else {
803 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
805 } else {
806 if ($wgUploadNavigationUrl)
807 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
808 else
809 $nav_urls['upload'] = false;
811 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
814 // A print stylesheet is attached to all pages, but nobody ever
815 // figures that out. :) Add a link...
816 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
817 $revid = $wgArticle->getLatest();
818 if ( !( $revid == 0 ) )
819 $nav_urls['print'] = array(
820 'text' => wfMsg( 'printableversion' ),
821 'href' => $wgRequest->appendQuery( 'printable=yes' )
824 // Also add a "permalink" while we're at it
825 if ( (int)$oldid ) {
826 $nav_urls['permalink'] = array(
827 'text' => wfMsg( 'permalink' ),
828 'href' => ''
830 } else {
831 if ( !( $revid == 0 ) )
832 $nav_urls['permalink'] = array(
833 'text' => wfMsg( 'permalink' ),
834 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
838 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
841 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
842 $wlhTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
843 $nav_urls['whatlinkshere'] = array(
844 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
846 if( $this->mTitle->getArticleId() ) {
847 $rclTitle = Title::makeTitle( NS_SPECIAL, 'Recentchangeslinked' );
848 $nav_urls['recentchangeslinked'] = array(
849 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
852 if ($wgUseTrackbacks)
853 $nav_urls['trackbacklink'] = array(
854 'href' => $wgTitle->trackbackURL()
858 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
859 $id = User::idFromName($this->mTitle->getText());
860 $ip = User::isIP($this->mTitle->getText());
861 } else {
862 $id = 0;
863 $ip = false;
866 if($id || $ip) { # both anons and non-anons have contri list
867 $nav_urls['contributions'] = array(
868 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
870 if ( $wgUser->isAllowed( 'block' ) )
871 $nav_urls['blockip'] = array(
872 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
874 } else {
875 $nav_urls['contributions'] = false;
877 $nav_urls['emailuser'] = false;
878 if( $this->showEmailUser( $id ) ) {
879 $nav_urls['emailuser'] = array(
880 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
883 wfProfileOut( $fname );
884 return $nav_urls;
888 * Generate strings used for xml 'id' names
889 * @return string
890 * @private
892 function getNameSpaceKey () {
893 return $this->mTitle->getNamespaceKey();
897 * @private
899 function setupUserCss() {
900 $fname = 'SkinTemplate::setupUserCss';
901 wfProfileIn( $fname );
903 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
905 $sitecss = '';
906 $usercss = '';
907 $siteargs = '&maxage=' . $wgSquidMaxage;
909 # Add user-specific code if this is a user and we allow that kind of thing
911 if ( $wgAllowUserCss && $this->loggedin ) {
912 $action = $wgRequest->getText('action');
914 # if we're previewing the CSS page, use it
915 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
916 $siteargs = "&smaxage=0&maxage=0";
917 $usercss = $wgRequest->getText('wpTextbox1');
918 } else {
919 $usercss = '@import "' .
920 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
921 'action=raw&ctype=text/css') . '";' ."\n";
924 $siteargs .= '&ts=' . $wgUser->mTouched;
927 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
929 # If we use the site's dynamic CSS, throw that in, too
930 if ( $wgUseSiteCss ) {
931 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
932 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
933 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', $query, NS_MEDIAWIKI) . '";' . "\n";
934 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
937 # If we use any dynamic CSS, make a little CDATA block out of it.
939 if ( !empty($sitecss) || !empty($usercss) ) {
940 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
942 wfProfileOut( $fname );
946 * @private
948 function setupUserJs() {
949 $fname = 'SkinTemplate::setupUserJs';
950 wfProfileIn( $fname );
952 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
953 $action = $wgRequest->getText('action');
955 if( $wgAllowUserJs && $this->loggedin ) {
956 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
957 # XXX: additional security check/prompt?
958 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
959 } else {
960 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
963 wfProfileOut( $fname );
967 * Code for extensions to hook into to provide per-page CSS, see
968 * extensions/PageCSS/PageCSS.php for an implementation of this.
970 * @private
972 function setupPageCss() {
973 $fname = 'SkinTemplate::setupPageCss';
974 wfProfileIn( $fname );
975 $out = false;
976 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
978 wfProfileOut( $fname );
979 return $out;
983 * returns css with user-specific options
984 * @public
987 function getUserStylesheet() {
988 $fname = 'SkinTemplate::getUserStylesheet';
989 wfProfileIn( $fname );
991 $s = "/* generated user stylesheet */\n";
992 $s .= $this->reallyDoGetUserStyles();
993 wfProfileOut( $fname );
994 return $s;
998 * @public
1000 function getUserJs() {
1001 $fname = 'SkinTemplate::getUserJs';
1002 wfProfileIn( $fname );
1004 global $wgStylePath;
1005 $s = '/* generated javascript */';
1006 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1007 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
1009 // avoid inclusion of non defined user JavaScript (with custom skins only)
1010 // by checking for default message content
1011 $msgKey = ucfirst($this->skinname).'.js';
1012 $userJS = wfMsg($msgKey);
1013 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
1014 $s .= $userJS;
1017 wfProfileOut( $fname );
1018 return $s;
1023 * Generic wrapper for template functions, with interface
1024 * compatible with what we use of PHPTAL 0.7.
1025 * @package MediaWiki
1026 * @subpackage Skins
1028 class QuickTemplate {
1030 * @public
1032 function QuickTemplate() {
1033 $this->data = array();
1034 $this->translator = new MediaWiki_I18N();
1038 * @public
1040 function set( $name, $value ) {
1041 $this->data[$name] = $value;
1045 * @public
1047 function setRef($name, &$value) {
1048 $this->data[$name] =& $value;
1052 * @public
1054 function setTranslator( &$t ) {
1055 $this->translator = &$t;
1059 * @public
1061 function execute() {
1062 echo "Override this function.";
1067 * @private
1069 function text( $str ) {
1070 echo htmlspecialchars( $this->data[$str] );
1074 * @private
1076 function jstext( $str ) {
1077 echo Xml::escapeJsString( $this->data[$str] );
1081 * @private
1083 function html( $str ) {
1084 echo $this->data[$str];
1088 * @private
1090 function msg( $str ) {
1091 echo htmlspecialchars( $this->translator->translate( $str ) );
1095 * @private
1097 function msgHtml( $str ) {
1098 echo $this->translator->translate( $str );
1102 * An ugly, ugly hack.
1103 * @private
1105 function msgWiki( $str ) {
1106 global $wgParser, $wgTitle, $wgOut;
1108 $text = $this->translator->translate( $str );
1109 $parserOutput = $wgParser->parse( $text, $wgTitle,
1110 $wgOut->parserOptions(), true );
1111 echo $parserOutput->getText();
1115 * @private
1117 function haveData( $str ) {
1118 return $this->data[$str];
1122 * @private
1124 function haveMsg( $str ) {
1125 $msg = $this->translator->translate( $str );
1126 return ($msg != '-') && ($msg != ''); # ????