Single quotes
[mediawiki.git] / includes / SkinPHPTal.php
blob110707c3929109a35ec402775b4186497e420385
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
17 /**
18 * Generic PHPTal (http://phptal.sourceforge.net/) skin
19 * Based on Brion's smarty skin
20 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 * Todo: Needs some serious refactoring into functions that correspond
23 * to the computations individual esi snippets need. Most importantly no body
24 * parsing for most of those of course.
26 * Set this in LocalSettings to enable phptal:
27 * set_include_path(get_include_path() . ":" . $IP.'/PHPTAL-NP-0.7.0/libs');
28 * $wgUsePHPTal = true;
30 * @package MediaWiki
31 * @subpackage Skins
34 /**
35 * This is not a valid entry point, perform no further processing unless
36 * MEDIAWIKI is defined
38 if( defined( 'MEDIAWIKI' ) ) {
40 require_once 'GlobalFunctions.php';
42 if( version_compare( phpversion(), "5.0", "lt" ) ) {
43 define( 'OLD_PHPTAL', true );
44 global $IP;
45 require_once $IP.'/PHPTAL-NP-0.7.0/libs/PHPTAL.php';
46 } else {
47 define( 'NEW_PHPTAL', true );
48 # For now, PHPTAL 1.0.x must be installed via PEAR in system dir.
49 require_once 'PEAR.php';
50 require_once 'PHPTAL.php';
53 /**
54 * @todo document
55 * @package MediaWiki
57 // PHPTAL 1.0 no longer has the PHPTAL_I18N stub class.
58 //class MediaWiki_I18N extends PHPTAL_I18N {
59 class MediaWiki_I18N {
60 var $_context = array();
62 function set($varName, $value) {
63 $this->_context[$varName] = $value;
66 function translate($value) {
67 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
68 $value = preg_replace( '/^string:/', '', $value );
70 $value = wfMsg( $value );
71 // interpolate variables
72 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
73 list($src, $var) = $m;
74 wfSuppressWarnings();
75 $varValue = $this->_context[$var];
76 wfRestoreWarnings();
77 $value = str_replace($src, $varValue, $value);
79 return $value;
82 /**
84 * @package MediaWiki
86 class SkinPHPTal extends Skin {
87 /**#@+
88 * @access private
91 /**
92 * Name of our skin, set in initPage()
93 * It probably need to be all lower case.
95 var $skinname;
97 /**
98 * Stylesheets set to use
99 * Sub directory in ./skins/ where various stylesheets are located
101 var $stylename;
104 * PHPTal template to be used.
105 * '.pt' will be automaticly added to it on PHPTAL object creation
107 var $template;
109 /**#@-*/
111 /** */
112 function initPage( &$out ) {
113 parent::initPage( $out );
114 $this->skinname = 'monobook';
115 $this->stylename = 'monobook';
116 $this->template = 'MonoBook';
120 * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
121 * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
122 * @return object
123 * @access private
125 function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
126 if( defined( 'NEW_PHPTAL' ) ) {
127 return new PHPTAL_version_bridge( $file, $repository, $cache_dir );
128 } else {
129 return new PHPTAL( $file, $repository, $cache_dir );
134 * initialize various variables and generate the template
136 function outputPage( &$out ) {
137 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
138 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
139 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
140 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
141 global $wgMaxCredits, $wgShowCreditsIfMax;
143 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
145 $this->initPage( $out );
146 $tpl =& $this->setupTemplate( $this->template . '.pt', 'skins' );
148 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
149 $tpl->setTranslator(new MediaWiki_I18N());
152 $this->thispage = $wgTitle->getPrefixedDbKey();
153 $this->thisurl = $wgTitle->getPrefixedURL();
154 $this->loggedin = $wgUser->getID() != 0;
155 $this->iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
156 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
157 $this->username = $wgUser->getName();
158 $this->userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
159 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
161 $this->usercss = $this->userjs = $this->userjsprev = false;
162 $this->setupUserCss();
163 $this->setupUserJs();
164 $this->titletxt = $wgTitle->getPrefixedText();
166 $tpl->set( 'title', $wgOut->getPageTitle() );
167 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
169 $tpl->setRef( "thispage", $this->thispage );
170 $subpagestr = $this->subPageSubtitle();
171 $tpl->set(
172 'subtitle', !empty($subpagestr)?
173 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
174 $out->getSubtitle()
176 $undelete = $this->getUndeleteLink();
177 $tpl->set(
178 "undelete", !empty($undelete)?
179 '<span class="subpages">'.$undelete.'</span>':
183 $tpl->set( 'catlinks', $this->getCategories());
184 if( $wgOut->isSyndicated() ) {
185 $feeds = array();
186 foreach( $wgFeedClasses as $format => $class ) {
187 $feeds[$format] = array(
188 'text' => $format,
189 'href' => $wgRequest->appendQuery( "feed=$format" ),
190 'ttip' => wfMsg('tooltip-'.$format)
193 $tpl->setRef( 'feeds', $feeds );
194 } else {
195 $tpl->set( 'feeds', false );
197 $tpl->setRef( 'mimetype', $wgMimeType );
198 $tpl->setRef( 'charset', $wgOutputEncoding );
199 $tpl->set( 'headlinks', $out->getHeadLinks() );
200 $tpl->setRef( 'wgScript', $wgScript );
201 $tpl->setRef( 'skinname', $this->skinname );
202 $tpl->setRef( 'stylename', $this->stylename );
203 $tpl->setRef( 'loggedin', $this->loggedin );
204 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
205 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL);
206 /* XXX currently unused, might get useful later
207 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
208 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
209 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
210 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
211 $tpl->set( "helppage", wfMsg('helppage'));
213 $tpl->set( 'searchaction', $this->escapeSearchLink() );
214 $tpl->setRef( 'stylepath', $wgStylePath );
215 $tpl->setRef( 'logopath', $wgLogo );
216 $tpl->setRef( "lang", $wgContLanguageCode );
217 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
218 $tpl->set( 'rtl', $wgContLang->isRTL() );
219 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
220 $tpl->setRef( 'username', $this->username );
221 $tpl->setRef( 'userpage', $this->userpage);
222 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
223 $tpl->setRef( 'usercss', $this->usercss);
224 $tpl->setRef( 'userjs', $this->userjs);
225 $tpl->setRef( 'userjsprev', $this->userjsprev);
226 global $wgUseSiteJs;
227 if ($wgUseSiteJs) {
228 if($this->loggedin) {
229 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
230 } else {
231 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
233 } else {
234 $tpl->set('jsvarurl', false);
236 if( $wgUser->getNewtalk() ) {
237 $usertitle = Title::newFromText( $this->userpage );
238 $usertalktitle = $usertitle->getTalkPage();
239 if($usertalktitle->getPrefixedDbKey() != $this->thispage){
241 $ntl = wfMsg( 'newmessages',
242 $this->makeKnownLink(
243 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
244 . ':' . $this->username,
245 wfMsg('newmessageslink') )
247 # Disable Cache
248 $wgOut->setSquidMaxage(0);
250 } else {
251 $ntl = '';
254 $tpl->setRef( 'newtalk', $ntl );
255 $tpl->setRef( 'skin', $this);
256 $tpl->set( 'logo', $this->logoText() );
257 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
258 if ( !$wgDisableCounters ) {
259 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
260 if ( $viewcount ) {
261 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
262 } else {
263 $tpl->set('viewcount', false);
266 $tpl->set('lastmod', $this->lastModified());
267 $tpl->set('copyright',$this->getCopyright());
269 $this->credits = false;
271 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
272 require_once("Credits.php");
273 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
276 $tpl->setRef( 'credits', $this->credits );
278 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
279 $tpl->set('copyright', $this->getCopyright());
280 $tpl->set('viewcount', false);
281 $tpl->set('lastmod', false);
282 $tpl->set('credits', false);
283 } else {
284 $tpl->set('copyright', false);
285 $tpl->set('viewcount', false);
286 $tpl->set('lastmod', false);
287 $tpl->set('credits', false);
290 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
291 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
292 $tpl->set( 'disclaimer', $this->disclaimerLink() );
293 $tpl->set( 'about', $this->aboutLink() );
295 $tpl->setRef( 'debug', $out->mDebugtext );
296 $tpl->set( 'reporttime', $out->reportTime() );
297 $tpl->set( 'sitenotice', $wgSiteNotice );
299 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
300 $out->mBodytext .= $printfooter ;
301 $tpl->setRef( 'bodytext', $out->mBodytext );
303 # Language links
304 $language_urls = array();
305 foreach( $wgOut->getLanguageLinks() as $l ) {
306 $nt = Title::newFromText( $l );
307 $language_urls[] = array('href' => $nt->getFullURL(),
308 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
309 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
311 if(count($language_urls)) {
312 $tpl->setRef( 'language_urls', $language_urls);
313 } else {
314 $tpl->set('language_urls', false);
317 # Personal toolbar
318 $tpl->set('personal_urls', $this->buildPersonalUrls());
319 $content_actions = $this->buildContentActionUrls();
320 $tpl->setRef('content_actions', $content_actions);
321 // XXX: attach this from javascript, same with section editing
322 if($this->iseditable && $wgUser->getOption("editondblclick") )
324 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
325 } else {
326 $tpl->set('body_ondblclick', false);
328 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
329 $tpl->set( 'nav_urls', $this->buildNavUrls() );
331 // execute template
332 $res = $tpl->execute();
333 // result may be an error
334 if (PEAR::isError($res)) {
335 echo $res->toString(), "\n";
336 } else {
337 echo $res;
343 * build array of urls for personal toolbar
345 function buildPersonalUrls() {
346 /* set up the default links for the personal toolbar */
347 global $wgShowIPinHeader;
348 $personal_urls = array();
349 if ($this->loggedin) {
350 $personal_urls['userpage'] = array(
351 'text' => $this->username,
352 'href' => &$this->userpageUrlDetails['href'],
353 'class' => $this->userpageUrlDetails['exists']?false:'new'
355 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
356 $personal_urls['mytalk'] = array(
357 'text' => wfMsg('mytalk'),
358 'href' => &$usertalkUrlDetails['href'],
359 'class' => $usertalkUrlDetails['exists']?false:'new'
361 $personal_urls['preferences'] = array(
362 'text' => wfMsg('preferences'),
363 'href' => $this->makeSpecialUrl('Preferences')
365 $personal_urls['watchlist'] = array(
366 'text' => wfMsg('watchlist'),
367 'href' => $this->makeSpecialUrl('Watchlist')
369 $personal_urls['mycontris'] = array(
370 'text' => wfMsg('mycontris'),
371 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) )
373 $personal_urls['logout'] = array(
374 'text' => wfMsg('userlogout'),
375 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
377 } else {
378 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
379 $personal_urls['anonuserpage'] = array(
380 'text' => $this->username,
381 'href' => &$this->userpageUrlDetails['href'],
382 'class' => $this->userpageUrlDetails['exists']?false:'new'
384 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
385 $personal_urls['anontalk'] = array(
386 'text' => wfMsg('anontalk'),
387 'href' => &$usertalkUrlDetails['href'],
388 'class' => $usertalkUrlDetails['exists']?false:'new'
390 $personal_urls['anonlogin'] = array(
391 'text' => wfMsg('userlogin'),
392 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
394 } else {
396 $personal_urls['login'] = array(
397 'text' => wfMsg('userlogin'),
398 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
403 return $personal_urls;
407 * an array of edit links by default used for the tabs
409 function buildContentActionUrls () {
410 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
411 $action = $wgRequest->getText( 'action' );
412 $section = $wgRequest->getText( 'section' );
413 $oldid = $wgRequest->getVal( 'oldid' );
414 $diff = $wgRequest->getVal( 'diff' );
415 $content_actions = array();
417 if( $this->iscontent and !$wgOut->isQuickbarSuppressed() ) {
419 $nskey = $this->getNameSpaceKey();
420 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
421 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
422 $content_actions[$nskey] = array('class' => ($is_active) ? 'selected' : false,
423 'text' => wfMsg($nskey),
424 'href' => $this->makeArticleUrl($this->thispage));
426 /* set up the classes for the talk link */
427 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : false);
428 $talktitle = Title::newFromText( $this->titletxt );
429 $talktitle = $talktitle->getTalkPage();
430 $this->checkTitle($talktitle, $this->titletxt);
431 if($talktitle->getArticleId() != 0) {
432 $content_actions['talk'] = array(
433 'class' => $talk_class,
434 'text' => wfMsg('talk'),
435 'href' => $this->makeTalkUrl($this->titletxt)
437 } else {
438 $content_actions['talk'] = array(
439 'class' => $talk_class?$talk_class.' new':'new',
440 'text' => wfMsg('talk'),
441 'href' => $this->makeTalkUrl($this->titletxt,'action=edit')
445 if ( $wgTitle->userCanEdit() ) {
446 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
447 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
448 $istalkclass = $istalk?' istalk':'';
449 $content_actions['edit'] = array(
450 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
451 'text' => wfMsg('edit'),
452 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid)
454 if ( $istalk ) {
455 $content_actions['addsection'] = array(
456 'class' => $section == 'new'?'selected':false,
457 'text' => wfMsg('addsection'),
458 'href' => $this->makeUrl($this->thispage, 'action=edit&section=new')
461 } else {
462 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
463 $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
464 'text' => wfMsg('viewsource'),
465 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
468 if ( $wgTitle->getArticleId() ) {
470 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : false,
471 'text' => wfMsg('history_short'),
472 'href' => $this->makeUrl($this->thispage, 'action=history'));
474 # XXX: is there a rollback action anywhere or is it planned?
475 # Don't recall where i got this from...
476 /*if( $wgUser->getNewtalk() ) {
477 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
478 'text' => wfMsg('rollback_short'),
479 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
480 'ttip' => wfMsg('tooltip-rollback'),
481 'akey' => wfMsg('accesskey-rollback'));
485 if($wgUser->isAllowed('protect')){
486 if(!$wgTitle->isProtected()){
487 $content_actions['protect'] = array(
488 'class' => ($action == 'protect') ? 'selected' : false,
489 'text' => wfMsg('protect'),
490 'href' => $this->makeUrl($this->thispage, 'action=protect')
493 } else {
494 $content_actions['unprotect'] = array(
495 'class' => ($action == 'unprotect') ? 'selected' : false,
496 'text' => wfMsg('unprotect'),
497 'href' => $this->makeUrl($this->thispage, 'action=unprotect')
501 if($wgUser->isAllowed('delete')){
502 $content_actions['delete'] = array(
503 'class' => ($action == 'delete') ? 'selected' : false,
504 'text' => wfMsg('delete'),
505 'href' => $this->makeUrl($this->thispage, 'action=delete')
508 if ( $wgUser->getID() != 0 ) {
509 if ( $wgTitle->userCanEdit()) {
510 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
511 'text' => wfMsg('move'),
512 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
516 } else {
517 //article doesn't exist or is deleted
518 if($wgUser->isAllowed('delete')){
519 if( $n = $wgTitle->isDeleted() ) {
520 $content_actions['undelete'] = array(
521 'class' => false,
522 'text' => wfMsg( "undelete_short", $n ),
523 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
529 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
530 if( !$wgTitle->userIsWatching()) {
531 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
532 'text' => wfMsg('watch'),
533 'href' => $this->makeUrl($this->thispage, 'action=watch'));
534 } else {
535 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
536 'text' => wfMsg('unwatch'),
537 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
541 # Show validate tab
542 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
543 global $wgArticle ;
544 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
545 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
546 'text' => wfMsg('val_tab'),
547 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
550 } else {
551 /* show special page tab */
553 $content_actions['article'] = array('class' => 'selected',
554 'text' => wfMsg('specialpage'),
555 'href' => false);
558 return $content_actions;
562 * build array of global navigation links
564 function buildNavigationUrls () {
565 global $wgNavigationLinks;
566 $result = array();
567 foreach ( $wgNavigationLinks as $link ) {
568 if (wfMsg( $link['text'] ) != '-') {
569 $result[] = array(
570 'text' => wfMsg( $link['text'] ),
571 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
572 'id' => 'n-'.$link['text']
576 return $result;
580 * build array of common navigation links
582 function buildNavUrls () {
583 global $wgTitle, $wgUser, $wgRequest;
584 global $wgSiteSupportPage, $wgDisableUploads;
586 $action = $wgRequest->getText( 'action' );
587 $oldid = $wgRequest->getVal( 'oldid' );
588 $diff = $wgRequest->getVal( 'diff' );
589 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
590 $nav_urls = array();
591 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
592 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
593 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
594 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
595 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
596 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
597 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
598 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
599 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
600 if( $this->loggedin && !$wgDisableUploads ) {
601 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
602 } else {
603 $nav_urls['upload'] = false;
605 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
607 if( $wgTitle->getNamespace() != NS_SPECIAL) {
608 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
609 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
612 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
613 $id = User::idFromName($wgTitle->getText());
614 $ip = User::isIP($wgTitle->getText());
615 } else {
616 $id = 0;
617 $ip = false;
620 if($id || $ip) { # both anons and non-anons have contri list
621 $nav_urls['contributions'] = array(
622 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
624 } else {
625 $nav_urls['contributions'] = false;
627 $nav_urls['emailuser'] = false;
628 if ( 0 != $wgUser->getID() ) { # show only to signed in users
629 if($id) { # can only email non-anons
630 $nav_urls['emailuser'] = array(
631 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
636 return $nav_urls;
640 * Generate strings used for xml 'id' names
642 function getNameSpaceKey () {
643 global $wgTitle;
644 switch ($wgTitle->getNamespace()) {
645 case NS_MAIN:
646 case NS_TALK:
647 return 'nstab-main';
648 case NS_USER:
649 case NS_USER_TALK:
650 return 'nstab-user';
651 case NS_MEDIA:
652 return 'nstab-media';
653 case NS_SPECIAL:
654 return 'nstab-special';
655 case NS_PROJECT:
656 case NS_PROJECT_TALK:
657 return 'nstab-wp';
658 case NS_IMAGE:
659 case NS_IMAGE_TALK:
660 return 'nstab-image';
661 case NS_MEDIAWIKI:
662 case NS_MEDIAWIKI_TALK:
663 return 'nstab-mediawiki';
664 case NS_TEMPLATE:
665 case NS_TEMPLATE_TALK:
666 return 'nstab-template';
667 case NS_HELP:
668 case NS_HELP_TALK:
669 return 'nstab-help';
670 case NS_CATEGORY:
671 case NS_CATEGORY_TALK:
672 return 'nstab-category';
673 default:
674 return 'nstab-main';
679 * @access private
682 function setupUserCss () {
684 global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss;
686 $sitecss = "";
687 $usercss = "";
688 $siteargs = "";
690 # Add user-specific code if this is a user and we allow that kind of thing
692 if ( $wgAllowUserCss && $this->loggedin ) {
693 $action = $wgRequest->getText('action');
695 # if we're previewing the CSS page, use it
696 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
697 $siteargs .= "&smaxage=0&maxage=0";
698 $usercss = $wgRequest->getText('wpTextbox1');
699 } else {
700 $siteargs .= "&maxage=0";
701 $usercss = '@import "' .
702 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
703 'action=raw&ctype=text/css') . '";' ."\n";
707 # If we use the site's dynamic CSS, throw that in, too
709 if ( $wgUseSiteCss ) {
710 $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n";
713 # If we use any dynamic CSS, make a little CDATA block out of it.
715 if ( !empty($sitecss) || !empty($usercss) ) {
716 $this->usercss = '/*<![CDATA[*/ ' . $sitecss . ' ' . $usercss . ' /*]]>*/';
721 * @access private
723 function setupUserJs () {
724 global $wgRequest, $wgTitle, $wgAllowUserJs;
725 $action = $wgRequest->getText('action');
727 if( $wgAllowUserJs && $this->loggedin ) {
728 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
729 # XXX: additional security check/prompt?
730 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
731 } else {
732 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
738 * returns css with user-specific options
740 function getUserStylesheet() {
741 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
742 $action = $wgRequest->getText('action');
743 $maxage = $wgRequest->getText('maxage');
744 $s = "/* generated user stylesheet */\n";
745 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename.'/rtl.css";'."\n";
746 $s .= '@import "'.
747 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
748 if($wgUser->getID() != 0) {
749 if ( 1 == $wgUser->getOption( "underline" ) ) {
750 $s .= "a { text-decoration: underline; }\n";
751 } else {
752 $s .= "a { text-decoration: none; }\n";
755 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
756 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
758 if ( 1 == $wgUser->getOption( "justify" ) ) {
759 $s .= "#bodyContent { text-align: justify; }\n";
761 return $s;
767 function getUserJs() {
768 global $wgUser, $wgStylePath;
769 $s = '/* generated javascript */';
770 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
771 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
772 $s .= wfMsg(ucfirst($this->skinname).'.js');
773 return $s;
777 class PHPTAL_version_bridge {
778 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
779 $this->tpl =& new PHPTAL( $file );
780 if( $repository ) {
781 $this->tpl->setTemplateRepository( $repository );
785 function set( $name, $value ) {
786 $this->tpl->$name = $value;
789 function setRef($name, &$value) {
790 $this->set( $name, $value );
793 function setTranslator( &$t ) {
794 $this->tpl->setTranslator( $t );
797 function execute() {
799 try {
801 return $this->tpl->execute();
804 catch (Exception $e) {
805 echo "<div class='error' style='background: white; white-space: pre; position: absolute; z-index: 9999; border: solid 2px black; padding: 4px;'>We caught an exception...\n ";
806 echo $e;
807 echo "</div>";
813 } // end of if( defined( 'MEDIAWIKI' ) )