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