f986ae4b6e597cb3c0a434df0084d11c5401eda6
[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 $tpl->set( "sysop", $wgUser->isSysop() );
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 if($wgUser->isSysop()){
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 $content_actions['delete'] = array(
495 'class' => ($action == 'delete') ? 'selected' : false,
496 'text' => wfMsg('delete'),
497 'href' => $this->makeUrl($this->thispage, 'action=delete')
498 );
499 }
500 if ( $wgUser->getID() != 0 ) {
501 if ( $wgTitle->userCanEdit()) {
502 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
503 'text' => wfMsg('move'),
504 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
505 );
506 }
507 }
508 } else {
509 //article doesn't exist or is deleted
510 if($wgUser->isSysop()){
511 if( $n = $wgTitle->isDeleted() ) {
512 $content_actions['undelete'] = array(
513 'class' => false,
514 'text' => wfMsg( "undelete_short", $n ),
515 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
516 );
517 }
518 }
519 }
520
521 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
522 if( !$wgTitle->userIsWatching()) {
523 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
524 'text' => wfMsg('watch'),
525 'href' => $this->makeUrl($this->thispage, 'action=watch'));
526 } else {
527 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
528 'text' => wfMsg('unwatch'),
529 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
530 }
531 }
532
533 # Show validate tab
534 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
535 global $wgArticle ;
536 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
537 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
538 'text' => wfMsg('val_tab'),
539 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
540 }
541
542 } else {
543 /* show special page tab */
544
545 $content_actions['article'] = array('class' => 'selected',
546 'text' => wfMsg('specialpage'),
547 'href' => false);
548 }
549
550 return $content_actions;
551 }
552
553 /**
554 * build array of global navigation links
555 */
556 function buildNavigationUrls () {
557 global $wgNavigationLinks;
558 $result = array();
559 foreach ( $wgNavigationLinks as $link ) {
560 if (wfMsg( $link['text'] ) != '-') {
561 $result[] = array(
562 'text' => wfMsg( $link['text'] ),
563 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
564 'id' => 'n-'.$link['text']
565 );
566 }
567 }
568 return $result;
569 }
570
571 /**
572 * build array of common navigation links
573 */
574 function buildNavUrls () {
575 global $wgTitle, $wgUser, $wgRequest;
576 global $wgSiteSupportPage, $wgDisableUploads;
577
578 $action = $wgRequest->getText( 'action' );
579 $oldid = $wgRequest->getVal( 'oldid' );
580 $diff = $wgRequest->getVal( 'diff' );
581 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
582 $nav_urls = array();
583 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
584 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
585 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
586 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
587 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
588 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
589 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
590 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
591 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
592 if( $this->loggedin && !$wgDisableUploads ) {
593 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
594 } else {
595 $nav_urls['upload'] = false;
596 }
597 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
598
599 if( $wgTitle->getNamespace() != NS_SPECIAL) {
600 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
601 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
602 }
603
604 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
605 $id = User::idFromName($wgTitle->getText());
606 $ip = User::isIP($wgTitle->getText());
607 } else {
608 $id = 0;
609 $ip = false;
610 }
611
612 if($id || $ip) { # both anons and non-anons have contri list
613 $nav_urls['contributions'] = array(
614 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
615 );
616 } else {
617 $nav_urls['contributions'] = false;
618 }
619 $nav_urls['emailuser'] = false;
620 if ( 0 != $wgUser->getID() ) { # show only to signed in users
621 if($id) { # can only email non-anons
622 $nav_urls['emailuser'] = array(
623 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
624 );
625 }
626 }
627
628 return $nav_urls;
629 }
630
631 /**
632 * Generate strings used for xml 'id' names
633 */
634 function getNameSpaceKey () {
635 global $wgTitle;
636 switch ($wgTitle->getNamespace()) {
637 case NS_MAIN:
638 case NS_TALK:
639 return 'nstab-main';
640 case NS_USER:
641 case NS_USER_TALK:
642 return 'nstab-user';
643 case NS_MEDIA:
644 return 'nstab-media';
645 case NS_SPECIAL:
646 return 'nstab-special';
647 case NS_PROJECT:
648 case NS_PROJECT_TALK:
649 return 'nstab-wp';
650 case NS_IMAGE:
651 case NS_IMAGE_TALK:
652 return 'nstab-image';
653 case NS_MEDIAWIKI:
654 case NS_MEDIAWIKI_TALK:
655 return 'nstab-mediawiki';
656 case NS_TEMPLATE:
657 case NS_TEMPLATE_TALK:
658 return 'nstab-template';
659 case NS_HELP:
660 case NS_HELP_TALK:
661 return 'nstab-help';
662 case NS_CATEGORY:
663 case NS_CATEGORY_TALK:
664 return 'nstab-category';
665 default:
666 return 'nstab-main';
667 }
668 }
669
670
671 /**
672 * @access private
673 */
674 function setupUserCssJs () {
675 global $wgRequest, $wgTitle;
676 $action = $wgRequest->getText('action');
677 # generated css
678 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n";
679
680 if( $this->loggedin ) {
681 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
682 # generated css
683 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n";
684 // css preview
685 $this->usercss .= $wgRequest->getText('wpTextbox1');
686 } else {
687 # generated css
688 $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n";
689 # import user stylesheet
690 $this->usercss .= '@import "'.
691 $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n";
692 }
693 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
694 # XXX: additional security check/prompt?
695 $this->userjsprev = $wgRequest->getText('wpTextbox1');
696 } else {
697 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
698 }
699 }
700 $this->usercss = '/*<![CDATA[*/ ' . $this->usercss . ' /*]]>*/';
701 if( $this->userjsprev ) {
702 $this->userjsprev = '/*<![CDATA[*/ ' . $this->userjsprev . ' /*]]>*/';
703 }
704 }
705
706 /**
707 * returns css with user-specific options
708 */
709 function getUserStylesheet() {
710 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
711 $action = $wgRequest->getText('action');
712 $maxage = $wgRequest->getText('maxage');
713 $s = "/* generated user stylesheet */\n";
714 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename.'/rtl.css";'."\n";
715 $s .= '@import "'.
716 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
717 if($wgUser->getID() != 0) {
718 if ( 1 == $wgUser->getOption( "underline" ) ) {
719 $s .= "a { text-decoration: underline; }\n";
720 } else {
721 $s .= "a { text-decoration: none; }\n";
722 }
723 }
724 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
725 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
726 }
727 if ( 1 == $wgUser->getOption( "justify" ) ) {
728 $s .= "#bodyContent { text-align: justify; }\n";
729 }
730 return $s;
731 }
732
733 /**
734 *
735 */
736 function getUserJs() {
737 global $wgUser, $wgStylePath;
738 $s = '/* generated javascript */';
739 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
740 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
741 $s .= wfMsg(ucfirst($this->skinname).'.js');
742 return $s;
743 }
744 }
745
746 class PHPTAL_version_bridge {
747 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
748 $this->tpl =& new PHPTAL( $file );
749 if( $repository ) {
750 $this->tpl->setTemplateRepository( $repository );
751 }
752 }
753
754 function set( $name, $value ) {
755 $this->tpl->$name = $value;
756 }
757
758 function setRef($name, &$value) {
759 $this->set( $name, $value );
760 }
761
762 function setTranslator( &$t ) {
763 $this->tpl->setTranslator( $t );
764 }
765
766 function execute() {
767 /*
768 try {
769 */
770 return $this->tpl->execute();
771 /*
772 }
773 catch (Exception $e) {
774 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 ";
775 echo $e;
776 echo "</div>";
777 }
778 */
779 }
780 }
781
782 } // end of if( defined( 'MEDIAWIKI' ) )
783 ?>