Implementing user levels management. This is only a very basic interface and several...
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
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.
6 #
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.
11 #
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
16
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/
21 *
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.
25 *
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;
29 *
30 * @package MediaWiki
31 */
32
33 /**
34 * This is not a valid entry point, perform no further processing unless
35 * MEDIAWIKI is defined
36 */
37 if( defined( 'MEDIAWIKI' ) ) {
38
39 require_once 'GlobalFunctions.php';
40
41 if( version_compare( phpversion(), "5.0", "lt" ) ) {
42 define( 'OLD_PHPTAL', true );
43 global $IP;
44 require_once $IP.'/PHPTAL-NP-0.7.0/libs/PHPTAL.php';
45 } else {
46 define( 'NEW_PHPTAL', true );
47 # For now, PHPTAL 1.0.x must be installed via PEAR in system dir.
48 require_once 'PEAR.php';
49 require_once 'PHPTAL.php';
50 }
51
52 /**
53 * @todo document
54 * @package MediaWiki
55 */
56 // PHPTAL 1.0 no longer has the PHPTAL_I18N stub class.
57 //class MediaWiki_I18N extends PHPTAL_I18N {
58 class MediaWiki_I18N {
59 var $_context = array();
60
61 function set($varName, $value) {
62 $this->_context[$varName] = $value;
63 }
64
65 function translate($value) {
66 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
67 $value = preg_replace( '/^string:/', '', $value );
68
69 $value = wfMsg( $value );
70 // interpolate variables
71 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
72 list($src, $var) = $m;
73 wfSuppressWarnings();
74 $varValue = $this->_context[$var];
75 wfRestoreWarnings();
76 $value = str_replace($src, $varValue, $value);
77 }
78 return $value;
79 }
80 }
81 /**
82 *
83 * @package MediaWiki
84 */
85 class SkinPHPTal extends Skin {
86 /**#@+
87 * @access private
88 */
89
90 /**
91 * Name of our skin, set in initPage()
92 * It probably need to be all lower case.
93 */
94 var $skinname;
95
96 /**
97 * Stylesheets set to use
98 * Sub directory in ./skins/ where various stylesheets are located
99 */
100 var $stylename;
101
102 /**
103 * PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /** */
111 function initPage( &$out ) {
112 parent::initPage( $out );
113 $this->skinname = 'monobook';
114 $this->stylename = 'monobook';
115 $this->template = 'MonoBook';
116 }
117
118 /**
119 * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
120 * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
121 * @return object
122 * @access private
123 */
124 function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
125 if( defined( 'NEW_PHPTAL' ) ) {
126 return new PHPTAL_version_bridge( $file, $repository, $cache_dir );
127 } else {
128 return new PHPTAL( $file, $repository, $cache_dir );
129 }
130 }
131
132 /**
133 * initialize various variables and generate the template
134 */
135 function outputPage( &$out ) {
136 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
137 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
138 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
139 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141
142 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
143
144 $this->initPage( $out );
145 $tpl =& $this->setupTemplate( $this->template . '.pt', 'skins' );
146
147 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
148 $tpl->setTranslator(new MediaWiki_I18N());
149 #}
150
151 $this->thispage = $wgTitle->getPrefixedDbKey();
152 $this->thisurl = $wgTitle->getPrefixedURL();
153 $this->loggedin = $wgUser->getID() != 0;
154 $this->iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
155 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
156 $this->username = $wgUser->getName();
157 $this->userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
158 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
159
160 $this->usercss = $this->userjs = $this->userjsprev = false;
161 $this->setupUserCssJs();
162
163 $this->titletxt = $wgTitle->getPrefixedText();
164
165 $tpl->set( 'title', $wgOut->getPageTitle() );
166 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
167
168 $tpl->setRef( "thispage", $this->thispage );
169 $subpagestr = $this->subPageSubtitle();
170 $tpl->set(
171 'subtitle', !empty($subpagestr)?
172 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
173 $out->getSubtitle()
174 );
175 $undelete = $this->getUndeleteLink();
176 $tpl->set(
177 "undelete", !empty($undelete)?
178 '<span class="subpages">'.$undelete.'</span>':
179 ''
180 );
181
182 $tpl->set( 'catlinks', $this->getCategories());
183 if( $wgOut->isSyndicated() ) {
184 $feeds = array();
185 foreach( $wgFeedClasses as $format => $class ) {
186 $feeds[$format] = array(
187 'text' => $format,
188 'href' => $wgRequest->appendQuery( "feed=$format" ),
189 'ttip' => wfMsg('tooltip-'.$format)
190 );
191 }
192 $tpl->setRef( 'feeds', $feeds );
193 } else {
194 $tpl->set( 'feeds', false );
195 }
196 $tpl->setRef( 'mimetype', $wgMimeType );
197 $tpl->setRef( 'charset', $wgOutputEncoding );
198 $tpl->set( 'headlinks', $out->getHeadLinks() );
199 $tpl->setRef( 'wgScript', $wgScript );
200 $tpl->setRef( 'skinname', $this->skinname );
201 $tpl->setRef( 'stylename', $this->stylename );
202 $tpl->setRef( 'loggedin', $this->loggedin );
203 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
204 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL);
205 /* XXX currently unused, might get useful later
206 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
207 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
208 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
209 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
210 $tpl->set( "helppage", wfMsg('helppage'));
211 */
212 $tpl->set( 'searchaction', $this->escapeSearchLink() );
213 $tpl->setRef( 'stylepath', $wgStylePath );
214 $tpl->setRef( 'logopath', $wgLogo );
215 $tpl->setRef( "lang", $wgContLanguageCode );
216 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
217 $tpl->set( 'rtl', $wgContLang->isRTL() );
218 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
219 $tpl->setRef( 'username', $this->username );
220 $tpl->setRef( 'userpage', $this->userpage);
221 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
222 $tpl->setRef( 'usercss', $this->usercss);
223 $tpl->setRef( 'userjs', $this->userjs);
224 $tpl->setRef( 'userjsprev', $this->userjsprev);
225 if($this->loggedin) {
226 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
227 } else {
228 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
229 }
230 if( $wgUser->getNewtalk() ) {
231 $usertitle = Title::newFromText( $this->userpage );
232 $usertalktitle = $usertitle->getTalkPage();
233 if($usertalktitle->getPrefixedDbKey() != $this->thispage){
234
235 $ntl = wfMsg( 'newmessages',
236 $this->makeKnownLink(
237 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
238 . ':' . $this->username,
239 wfMsg('newmessageslink') )
240 );
241 # Disable Cache
242 $wgOut->setSquidMaxage(0);
243 }
244 } else {
245 $ntl = '';
246 }
247
248 $tpl->setRef( 'newtalk', $ntl );
249 $tpl->setRef( 'skin', $this);
250 $tpl->set( 'logo', $this->logoText() );
251 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
252 if ( !$wgDisableCounters ) {
253 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
254 if ( $viewcount ) {
255 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
256 } else {
257 $tpl->set('viewcount', false);
258 }
259 }
260 $tpl->set('lastmod', $this->lastModified());
261 $tpl->set('copyright',$this->getCopyright());
262
263 $this->credits = false;
264
265 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
266 require_once("Credits.php");
267 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
268 }
269
270 $tpl->setRef( 'credits', $this->credits );
271
272 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
273 $tpl->set('copyright', $this->getCopyright());
274 $tpl->set('viewcount', false);
275 $tpl->set('lastmod', false);
276 $tpl->set('credits', false);
277 } else {
278 $tpl->set('copyright', false);
279 $tpl->set('viewcount', false);
280 $tpl->set('lastmod', false);
281 $tpl->set('credits', false);
282 }
283
284 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
285 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
286 $tpl->set( 'disclaimer', $this->disclaimerLink() );
287 $tpl->set( 'about', $this->aboutLink() );
288
289 $tpl->setRef( 'debug', $out->mDebugtext );
290 $tpl->set( 'reporttime', $out->reportTime() );
291 $tpl->set( 'sitenotice', $wgSiteNotice );
292
293 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
294 $out->mBodytext .= $printfooter ;
295 $tpl->setRef( 'bodytext', $out->mBodytext );
296
297 # Language links
298 $language_urls = array();
299 foreach( $wgOut->getLanguageLinks() as $l ) {
300 $nt = Title::newFromText( $l );
301 $language_urls[] = array('href' => $nt->getFullURL(),
302 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
303 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
304 }
305 if(count($language_urls)) {
306 $tpl->setRef( 'language_urls', $language_urls);
307 } else {
308 $tpl->set('language_urls', false);
309 }
310
311 # Personal toolbar
312 $tpl->set('personal_urls', $this->buildPersonalUrls());
313 $content_actions = $this->buildContentActionUrls();
314 $tpl->setRef('content_actions', $content_actions);
315 // XXX: attach this from javascript, same with section editing
316 if($this->iseditable && $wgUser->getOption("editondblclick") )
317 {
318 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
319 } else {
320 $tpl->set('body_ondblclick', false);
321 }
322 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
323 $tpl->set( 'nav_urls', $this->buildNavUrls() );
324
325 // execute template
326 $res = $tpl->execute();
327 // result may be an error
328 if (PEAR::isError($res)) {
329 echo $res->toString(), "\n";
330 } else {
331 echo $res;
332 }
333
334 }
335
336 /**
337 * build array of urls for personal toolbar
338 */
339 function buildPersonalUrls() {
340 /* set up the default links for the personal toolbar */
341 global $wgShowIPinHeader;
342 $personal_urls = array();
343 if ($this->loggedin) {
344 $personal_urls['userpage'] = array(
345 'text' => $this->username,
346 'href' => &$this->userpageUrlDetails['href'],
347 'class' => $this->userpageUrlDetails['exists']?false:'new'
348 );
349 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
350 $personal_urls['mytalk'] = array(
351 'text' => wfMsg('mytalk'),
352 'href' => &$usertalkUrlDetails['href'],
353 'class' => $usertalkUrlDetails['exists']?false:'new'
354 );
355 $personal_urls['preferences'] = array(
356 'text' => wfMsg('preferences'),
357 'href' => $this->makeSpecialUrl('Preferences')
358 );
359 $personal_urls['watchlist'] = array(
360 'text' => wfMsg('watchlist'),
361 'href' => $this->makeSpecialUrl('Watchlist')
362 );
363 $personal_urls['mycontris'] = array(
364 'text' => wfMsg('mycontris'),
365 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) )
366 );
367 $personal_urls['logout'] = array(
368 'text' => wfMsg('userlogout'),
369 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
370 );
371 } else {
372 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
373 $personal_urls['anonuserpage'] = array(
374 'text' => $this->username,
375 'href' => &$this->userpageUrlDetails['href'],
376 'class' => $this->userpageUrlDetails['exists']?false:'new'
377 );
378 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
379 $personal_urls['anontalk'] = array(
380 'text' => wfMsg('anontalk'),
381 'href' => &$usertalkUrlDetails['href'],
382 'class' => $usertalkUrlDetails['exists']?false:'new'
383 );
384 $personal_urls['anonlogin'] = array(
385 'text' => wfMsg('userlogin'),
386 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
387 );
388 } else {
389
390 $personal_urls['login'] = array(
391 'text' => wfMsg('userlogin'),
392 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
393 );
394 }
395 }
396
397 return $personal_urls;
398 }
399
400 /**
401 * an array of edit links by default used for the tabs
402 */
403 function buildContentActionUrls () {
404 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
405 $action = $wgRequest->getText( 'action' );
406 $section = $wgRequest->getText( 'section' );
407 $oldid = $wgRequest->getVal( 'oldid' );
408 $diff = $wgRequest->getVal( 'diff' );
409 $content_actions = array();
410
411 if( $this->iscontent and !$wgOut->isQuickbarSuppressed() ) {
412
413 $nskey = $this->getNameSpaceKey();
414 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
415 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
416 $content_actions[$nskey] = array('class' => ($is_active) ? 'selected' : false,
417 'text' => wfMsg($nskey),
418 'href' => $this->makeArticleUrl($this->thispage));
419
420 /* set up the classes for the talk link */
421 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : false);
422 $talktitle = Title::newFromText( $this->titletxt );
423 $talktitle = $talktitle->getTalkPage();
424 $this->checkTitle($talktitle, $this->titletxt);
425 if($talktitle->getArticleId() != 0) {
426 $content_actions['talk'] = array(
427 'class' => $talk_class,
428 'text' => wfMsg('talk'),
429 'href' => $this->makeTalkUrl($this->titletxt)
430 );
431 } else {
432 $content_actions['talk'] = array(
433 'class' => $talk_class?$talk_class.' new':'new',
434 'text' => wfMsg('talk'),
435 'href' => $this->makeTalkUrl($this->titletxt,'action=edit')
436 );
437 }
438
439 if ( $wgTitle->userCanEdit() ) {
440 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
441 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
442 $istalkclass = $istalk?' istalk':'';
443 $content_actions['edit'] = array(
444 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
445 'text' => wfMsg('edit'),
446 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid)
447 );
448 if ( $istalk ) {
449 $content_actions['addsection'] = array(
450 'class' => $section == 'new'?'selected':false,
451 'text' => wfMsg('addsection'),
452 'href' => $this->makeUrl($this->thispage, 'action=edit&section=new')
453 );
454 }
455 } else {
456 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
457 $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
458 'text' => wfMsg('viewsource'),
459 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
460 }
461
462 if ( $wgTitle->getArticleId() ) {
463
464 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : false,
465 'text' => wfMsg('history_short'),
466 'href' => $this->makeUrl($this->thispage, 'action=history'));
467
468 # XXX: is there a rollback action anywhere or is it planned?
469 # Don't recall where i got this from...
470 /*if( $wgUser->getNewtalk() ) {
471 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
472 'text' => wfMsg('rollback_short'),
473 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
474 'ttip' => wfMsg('tooltip-rollback'),
475 'akey' => wfMsg('accesskey-rollback'));
476 }
477 */
478
479 if($wgUser->isAllowed('protect')){
480 if(!$wgTitle->isProtected()){
481 $content_actions['protect'] = array(
482 'class' => ($action == 'protect') ? 'selected' : false,
483 'text' => wfMsg('protect'),
484 'href' => $this->makeUrl($this->thispage, 'action=protect')
485 );
486
487 } else {
488 $content_actions['unprotect'] = array(
489 'class' => ($action == 'unprotect') ? 'selected' : false,
490 'text' => wfMsg('unprotect'),
491 'href' => $this->makeUrl($this->thispage, 'action=unprotect')
492 );
493 }
494 }
495 if($wgUser->isAllowed('delete')){
496 $content_actions['delete'] = array(
497 'class' => ($action == 'delete') ? 'selected' : false,
498 'text' => wfMsg('delete'),
499 'href' => $this->makeUrl($this->thispage, 'action=delete')
500 );
501 }
502 if ( $wgUser->getID() != 0 ) {
503 if ( $wgTitle->userCanEdit()) {
504 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
505 'text' => wfMsg('move'),
506 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
507 );
508 }
509 }
510 } else {
511 //article doesn't exist or is deleted
512 if($wgUser->isAllowed('delete')){
513 if( $n = $wgTitle->isDeleted() ) {
514 $content_actions['undelete'] = array(
515 'class' => false,
516 'text' => wfMsg( "undelete_short", $n ),
517 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
518 );
519 }
520 }
521 }
522
523 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
524 if( !$wgTitle->userIsWatching()) {
525 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
526 'text' => wfMsg('watch'),
527 'href' => $this->makeUrl($this->thispage, 'action=watch'));
528 } else {
529 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
530 'text' => wfMsg('unwatch'),
531 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
532 }
533 }
534
535 # Show validate tab
536 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
537 global $wgArticle ;
538 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
539 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
540 'text' => wfMsg('val_tab'),
541 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
542 }
543
544 } else {
545 /* show special page tab */
546
547 $content_actions['article'] = array('class' => 'selected',
548 'text' => wfMsg('specialpage'),
549 'href' => false);
550 }
551
552 return $content_actions;
553 }
554
555 /**
556 * build array of global navigation links
557 */
558 function buildNavigationUrls () {
559 global $wgNavigationLinks;
560 $result = array();
561 foreach ( $wgNavigationLinks as $link ) {
562 if (wfMsg( $link['text'] ) != '-') {
563 $result[] = array(
564 'text' => wfMsg( $link['text'] ),
565 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
566 'id' => 'n-'.$link['text']
567 );
568 }
569 }
570 return $result;
571 }
572
573 /**
574 * build array of common navigation links
575 */
576 function buildNavUrls () {
577 global $wgTitle, $wgUser, $wgRequest;
578 global $wgSiteSupportPage, $wgDisableUploads;
579
580 $action = $wgRequest->getText( 'action' );
581 $oldid = $wgRequest->getVal( 'oldid' );
582 $diff = $wgRequest->getVal( 'diff' );
583 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
584 $nav_urls = array();
585 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
586 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
587 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
588 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
589 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
590 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
591 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
592 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
593 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
594 if( $this->loggedin && !$wgDisableUploads ) {
595 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
596 } else {
597 $nav_urls['upload'] = false;
598 }
599 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
600
601 if( $wgTitle->getNamespace() != NS_SPECIAL) {
602 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
603 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
604 }
605
606 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
607 $id = User::idFromName($wgTitle->getText());
608 $ip = User::isIP($wgTitle->getText());
609 } else {
610 $id = 0;
611 $ip = false;
612 }
613
614 if($id || $ip) { # both anons and non-anons have contri list
615 $nav_urls['contributions'] = array(
616 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
617 );
618 } else {
619 $nav_urls['contributions'] = false;
620 }
621 $nav_urls['emailuser'] = false;
622 if ( 0 != $wgUser->getID() ) { # show only to signed in users
623 if($id) { # can only email non-anons
624 $nav_urls['emailuser'] = array(
625 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
626 );
627 }
628 }
629
630 return $nav_urls;
631 }
632
633 /**
634 * Generate strings used for xml 'id' names
635 */
636 function getNameSpaceKey () {
637 global $wgTitle;
638 switch ($wgTitle->getNamespace()) {
639 case NS_MAIN:
640 case NS_TALK:
641 return 'nstab-main';
642 case NS_USER:
643 case NS_USER_TALK:
644 return 'nstab-user';
645 case NS_MEDIA:
646 return 'nstab-media';
647 case NS_SPECIAL:
648 return 'nstab-special';
649 case NS_PROJECT:
650 case NS_PROJECT_TALK:
651 return 'nstab-wp';
652 case NS_IMAGE:
653 case NS_IMAGE_TALK:
654 return 'nstab-image';
655 case NS_MEDIAWIKI:
656 case NS_MEDIAWIKI_TALK:
657 return 'nstab-mediawiki';
658 case NS_TEMPLATE:
659 case NS_TEMPLATE_TALK:
660 return 'nstab-template';
661 case NS_HELP:
662 case NS_HELP_TALK:
663 return 'nstab-help';
664 case NS_CATEGORY:
665 case NS_CATEGORY_TALK:
666 return 'nstab-category';
667 default:
668 return 'nstab-main';
669 }
670 }
671
672
673 /**
674 * @access private
675 */
676 function setupUserCssJs () {
677 global $wgRequest, $wgTitle;
678 $action = $wgRequest->getText('action');
679 # generated css
680 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n";
681
682 if( $this->loggedin ) {
683 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
684 # generated css
685 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n";
686 // css preview
687 $this->usercss .= $wgRequest->getText('wpTextbox1');
688 } else {
689 # generated css
690 $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n";
691 # import user stylesheet
692 $this->usercss .= '@import "'.
693 $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n";
694 }
695 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
696 # XXX: additional security check/prompt?
697 $this->userjsprev = $wgRequest->getText('wpTextbox1');
698 } else {
699 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
700 }
701 }
702 $this->usercss = '/*<![CDATA[*/ ' . $this->usercss . ' /*]]>*/';
703 if( $this->userjsprev ) {
704 $this->userjsprev = '/*<![CDATA[*/ ' . $this->userjsprev . ' /*]]>*/';
705 }
706 }
707
708 /**
709 * returns css with user-specific options
710 */
711 function getUserStylesheet() {
712 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
713 $action = $wgRequest->getText('action');
714 $maxage = $wgRequest->getText('maxage');
715 $s = "/* generated user stylesheet */\n";
716 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename.'/rtl.css";'."\n";
717 $s .= '@import "'.
718 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
719 if($wgUser->getID() != 0) {
720 if ( 1 == $wgUser->getOption( "underline" ) ) {
721 $s .= "a { text-decoration: underline; }\n";
722 } else {
723 $s .= "a { text-decoration: none; }\n";
724 }
725 }
726 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
727 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
728 }
729 if ( 1 == $wgUser->getOption( "justify" ) ) {
730 $s .= "#bodyContent { text-align: justify; }\n";
731 }
732 return $s;
733 }
734
735 /**
736 *
737 */
738 function getUserJs() {
739 global $wgUser, $wgStylePath;
740 $s = '/* generated javascript */';
741 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
742 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
743 $s .= wfMsg(ucfirst($this->skinname).'.js');
744 return $s;
745 }
746 }
747
748 class PHPTAL_version_bridge {
749 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
750 $this->tpl =& new PHPTAL( $file );
751 if( $repository ) {
752 $this->tpl->setTemplateRepository( $repository );
753 }
754 }
755
756 function set( $name, $value ) {
757 $this->tpl->$name = $value;
758 }
759
760 function setRef($name, &$value) {
761 $this->set( $name, $value );
762 }
763
764 function setTranslator( &$t ) {
765 $this->tpl->setTranslator( $t );
766 }
767
768 function execute() {
769 /*
770 try {
771 */
772 return $this->tpl->execute();
773 /*
774 }
775 catch (Exception $e) {
776 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 ";
777 echo $e;
778 echo "</div>";
779 }
780 */
781 }
782 }
783
784 } // end of if( defined( 'MEDIAWIKI' ) )
785 ?>