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