15d65a95eab96f2b2a8531c5b50c69da8d1d3de3
[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 }
267 }
268 $tpl->set('lastmod', $this->lastModified());
269 $tpl->set('copyright',$this->getCopyright());
270
271 $this->credits = false;
272
273 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
274 require_once("Credits.php");
275 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
276 }
277
278 $tpl->setRef( 'credits', $this->credits );
279
280 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
281 $tpl->set('copyright', $this->getCopyright());
282 $tpl->set('viewcount', false);
283 $tpl->set('lastmod', false);
284 $tpl->set('credits', false);
285 } else {
286 $tpl->set('copyright', false);
287 $tpl->set('viewcount', false);
288 $tpl->set('lastmod', false);
289 $tpl->set('credits', false);
290 }
291
292 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
293 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
294 $tpl->set( 'disclaimer', $this->disclaimerLink() );
295 $tpl->set( 'about', $this->aboutLink() );
296
297 $tpl->setRef( 'debug', $out->mDebugtext );
298 $tpl->set( 'reporttime', $out->reportTime() );
299 $tpl->set( 'sitenotice', $wgSiteNotice );
300
301 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
302 $out->mBodytext .= $printfooter ;
303 $tpl->setRef( 'bodytext', $out->mBodytext );
304
305 # Language links
306 $language_urls = array();
307 foreach( $wgOut->getLanguageLinks() as $l ) {
308 $nt = Title::newFromText( $l );
309 $language_urls[] = array('href' => $nt->getFullURL(),
310 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
311 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
312 }
313 if(count($language_urls)) {
314 $tpl->setRef( 'language_urls', $language_urls);
315 } else {
316 $tpl->set('language_urls', false);
317 }
318
319 # Personal toolbar
320 $tpl->set('personal_urls', $this->buildPersonalUrls());
321 $content_actions = $this->buildContentActionUrls();
322 $tpl->setRef('content_actions', $content_actions);
323 // XXX: attach this from javascript, same with section editing
324 if($this->iseditable && $wgUser->getOption("editondblclick") )
325 {
326 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
327 } else {
328 $tpl->set('body_ondblclick', false);
329 }
330 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
331 $tpl->set( 'nav_urls', $this->buildNavUrls() );
332
333 // execute template
334 $res = $tpl->execute();
335 // result may be an error
336 if (PEAR::isError($res)) {
337 echo $res->toString(), "\n";
338 } else {
339 echo $res;
340 }
341
342 }
343
344 /**
345 * build array of urls for personal toolbar
346 */
347 function buildPersonalUrls() {
348 /* set up the default links for the personal toolbar */
349 global $wgShowIPinHeader;
350 $personal_urls = array();
351 if ($this->loggedin) {
352 $personal_urls['userpage'] = array(
353 'text' => $this->username,
354 'href' => &$this->userpageUrlDetails['href'],
355 'class' => $this->userpageUrlDetails['exists']?false:'new'
356 );
357 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
358 $personal_urls['mytalk'] = array(
359 'text' => wfMsg('mytalk'),
360 'href' => &$usertalkUrlDetails['href'],
361 'class' => $usertalkUrlDetails['exists']?false:'new'
362 );
363 $personal_urls['preferences'] = array(
364 'text' => wfMsg('preferences'),
365 'href' => $this->makeSpecialUrl('Preferences')
366 );
367 $personal_urls['watchlist'] = array(
368 'text' => wfMsg('watchlist'),
369 'href' => $this->makeSpecialUrl('Watchlist')
370 );
371 $personal_urls['mycontris'] = array(
372 'text' => wfMsg('mycontris'),
373 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) )
374 );
375 $personal_urls['logout'] = array(
376 'text' => wfMsg('userlogout'),
377 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
378 );
379 } else {
380 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
381 $personal_urls['anonuserpage'] = array(
382 'text' => $this->username,
383 'href' => &$this->userpageUrlDetails['href'],
384 'class' => $this->userpageUrlDetails['exists']?false:'new'
385 );
386 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
387 $personal_urls['anontalk'] = array(
388 'text' => wfMsg('anontalk'),
389 'href' => &$usertalkUrlDetails['href'],
390 'class' => $usertalkUrlDetails['exists']?false:'new'
391 );
392 $personal_urls['anonlogin'] = array(
393 'text' => wfMsg('userlogin'),
394 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
395 );
396 } else {
397
398 $personal_urls['login'] = array(
399 'text' => wfMsg('userlogin'),
400 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
401 );
402 }
403 }
404
405 return $personal_urls;
406 }
407
408 /**
409 * an array of edit links by default used for the tabs
410 */
411 function buildContentActionUrls () {
412 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
413 $action = $wgRequest->getText( 'action' );
414 $section = $wgRequest->getText( 'section' );
415 $oldid = $wgRequest->getVal( 'oldid' );
416 $diff = $wgRequest->getVal( 'diff' );
417 $content_actions = array();
418
419 if( $this->iscontent and !$wgOut->isQuickbarSuppressed() ) {
420
421 $nskey = $this->getNameSpaceKey();
422 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
423 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
424 $content_actions[$nskey] = array('class' => ($is_active) ? 'selected' : false,
425 'text' => wfMsg($nskey),
426 'href' => $this->makeArticleUrl($this->thispage));
427
428 /* set up the classes for the talk link */
429 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : false);
430 $talktitle = Title::newFromText( $this->titletxt );
431 $talktitle = $talktitle->getTalkPage();
432 $this->checkTitle($talktitle, $this->titletxt);
433 if($talktitle->getArticleId() != 0) {
434 $content_actions['talk'] = array(
435 'class' => $talk_class,
436 'text' => wfMsg('talk'),
437 'href' => $this->makeTalkUrl($this->titletxt)
438 );
439 } else {
440 $content_actions['talk'] = array(
441 'class' => $talk_class?$talk_class.' new':'new',
442 'text' => wfMsg('talk'),
443 'href' => $this->makeTalkUrl($this->titletxt,'action=edit')
444 );
445 }
446
447 if ( $wgTitle->userCanEdit() ) {
448 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : false;
449 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
450 $istalkclass = $istalk?' istalk':'';
451 $content_actions['edit'] = array(
452 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
453 'text' => wfMsg('edit'),
454 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid)
455 );
456 if ( $istalk ) {
457 $content_actions['addsection'] = array(
458 'class' => $section == 'new'?'selected':false,
459 'text' => wfMsg('addsection'),
460 'href' => $this->makeUrl($this->thispage, 'action=edit&section=new')
461 );
462 }
463 } else {
464 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : '';
465 $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
466 'text' => wfMsg('viewsource'),
467 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
468 }
469
470 if ( $wgTitle->getArticleId() ) {
471
472 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : false,
473 'text' => wfMsg('history_short'),
474 'href' => $this->makeUrl($this->thispage, 'action=history'));
475
476 # XXX: is there a rollback action anywhere or is it planned?
477 # Don't recall where i got this from...
478 /*if( $wgUser->getNewtalk() ) {
479 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
480 'text' => wfMsg('rollback_short'),
481 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
482 'ttip' => wfMsg('tooltip-rollback'),
483 'akey' => wfMsg('accesskey-rollback'));
484 }*/
485
486 if($wgUser->isSysop()){
487 if(!$wgTitle->isProtected()){
488 $content_actions['protect'] = array(
489 'class' => ($action == 'protect') ? 'selected' : false,
490 'text' => wfMsg('protect'),
491 'href' => $this->makeUrl($this->thispage, 'action=protect')
492 );
493
494 } else {
495 $content_actions['unprotect'] = array(
496 'class' => ($action == 'unprotect') ? 'selected' : false,
497 'text' => wfMsg('unprotect'),
498 'href' => $this->makeUrl($this->thispage, 'action=unprotect')
499 );
500 }
501 $content_actions['delete'] = array(
502 'class' => ($action == 'delete') ? 'selected' : false,
503 'text' => wfMsg('delete'),
504 'href' => $this->makeUrl($this->thispage, 'action=delete')
505 );
506 }
507 if ( $wgUser->getID() != 0 ) {
508 if ( $wgTitle->userCanEdit()) {
509 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
510 'text' => wfMsg('move'),
511 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
512 );
513 } else {
514 $content_actions['move'] = array('class' => 'inactive',
515 'text' => wfMsg('move'),
516 'href' => false);
517
518 }
519 }
520 } else {
521 //article doesn't exist or is deleted
522 if($wgUser->isSysop()){
523 if( $n = $wgTitle->isDeleted() ) {
524 $content_actions['delete'] = array(
525 'class' => false,
526 'text' => wfMsg( "undelete_short", $n ),
527 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
528 );
529 }
530 }
531 }
532
533 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
534 if( !$wgTitle->userIsWatching()) {
535 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
536 'text' => wfMsg('watch'),
537 'href' => $this->makeUrl($this->thispage, 'action=watch'));
538 } else {
539 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
540 'text' => wfMsg('unwatch'),
541 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
542 }
543 }
544
545 # Show validate tab
546 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
547 global $wgArticle ;
548 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
549 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
550 'text' => wfMsg('val_tab'),
551 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
552 }
553
554 } else {
555 /* show special page tab */
556
557 $content_actions['article'] = array('class' => 'selected',
558 'text' => wfMsg('specialpage'),
559 'href' => false);
560 }
561
562 return $content_actions;
563 }
564
565 /**
566 * build array of global navigation links
567 */
568 function buildNavigationUrls () {
569 global $wgNavigationLinks;
570 $result = array();
571 foreach ( $wgNavigationLinks as $link ) {
572 $result[] = array(
573 'text' => wfMsg( $link['text'] ),
574 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
575 'id' => 'n-'.$link['text']
576 );
577 }
578 return $result;
579 }
580
581 /**
582 * build array of common navigation links
583 */
584 function buildNavUrls () {
585 global $wgTitle, $wgUser, $wgRequest;
586 global $wgSiteSupportPage, $wgDisableUploads;
587
588 $action = $wgRequest->getText( 'action' );
589 $oldid = $wgRequest->getVal( 'oldid' );
590 $diff = $wgRequest->getVal( 'diff' );
591 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
592 $nav_urls = array();
593 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
594 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
595 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
596 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
597 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
598 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
599 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
600 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
601 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
602 if( $this->loggedin && !$wgDisableUploads ) {
603 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
604 } else {
605 $nav_urls['upload'] = false;
606 }
607 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
608
609 if( $wgTitle->getNamespace() != NS_SPECIAL) {
610 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
611 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
612 }
613
614 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
615 $id = User::idFromName($wgTitle->getText());
616 $ip = User::isIP($wgTitle->getText());
617 } else {
618 $id = 0;
619 $ip = false;
620 }
621
622 if($id || $ip) { # both anons and non-anons have contri list
623 $nav_urls['contributions'] = array(
624 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
625 );
626 } else {
627 $nav_urls['contributions'] = false;
628 }
629 $nav_urls['emailuser'] = false;
630 if ( 0 != $wgUser->getID() ) { # show only to signed in users
631 if($id) { # can only email non-anons
632 $nav_urls['emailuser'] = array(
633 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
634 );
635 }
636 }
637
638 return $nav_urls;
639 }
640
641 /**
642 * Generate strings used for xml 'id' names
643 */
644 function getNameSpaceKey () {
645 global $wgTitle;
646 switch ($wgTitle->getNamespace()) {
647 case NS_MAIN:
648 case NS_TALK:
649 return 'nstab-main';
650 case NS_USER:
651 case NS_USER_TALK:
652 return 'nstab-user';
653 case NS_MEDIA:
654 return 'nstab-media';
655 case NS_SPECIAL:
656 return 'nstab-special';
657 case NS_PROJECT:
658 case NS_PROJECT_TALK:
659 return 'nstab-wp';
660 case NS_IMAGE:
661 case NS_IMAGE_TALK:
662 return 'nstab-image';
663 case NS_MEDIAWIKI:
664 case NS_MEDIAWIKI_TALK:
665 return 'nstab-mediawiki';
666 case NS_TEMPLATE:
667 case NS_TEMPLATE_TALK:
668 return 'nstab-template';
669 case NS_HELP:
670 case NS_HELP_TALK:
671 return 'nstab-help';
672 case NS_CATEGORY:
673 case NS_CATEGORY_TALK:
674 return 'nstab-category';
675 default:
676 return 'nstab-main';
677 }
678 }
679
680
681 /**
682 * @access private
683 */
684 function setupUserCssJs () {
685 global $wgRequest, $wgTitle;
686 $action = $wgRequest->getText('action');
687 # generated css
688 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n";
689
690 if( $this->loggedin ) {
691 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
692 # generated css
693 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n";
694 // css preview
695 $this->usercss .= $wgRequest->getText('wpTextbox1');
696 } else {
697 # generated css
698 $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n";
699 # import user stylesheet
700 $this->usercss .= '@import "'.
701 $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n";
702 }
703 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
704 # XXX: additional security check/prompt?
705 $this->userjsprev = $wgRequest->getText('wpTextbox1');
706 } else {
707 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
708 }
709 }
710 $this->usercss = '/*<![CDATA[*/ ' . $this->usercss . ' /*]]>*/';
711 if( $this->userjsprev ) {
712 $this->userjsprev = '/*<![CDATA[*/ ' . $this->userjsprev . ' /*]]>*/';
713 }
714 }
715
716 /**
717 * returns css with user-specific options
718 */
719 function getUserStylesheet() {
720 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
721 $action = $wgRequest->getText('action');
722 $maxage = $wgRequest->getText('maxage');
723 $s = "/* generated user stylesheet */\n";
724 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename.'/rtl.css";'."\n";
725 $s .= '@import "'.
726 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
727 if($wgUser->getID() != 0) {
728 if ( 1 == $wgUser->getOption( "underline" ) ) {
729 $s .= "a { text-decoration: underline; }\n";
730 } else {
731 $s .= "a { text-decoration: none; }\n";
732 }
733 }
734 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
735 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
736 }
737 if ( 1 == $wgUser->getOption( "justify" ) ) {
738 $s .= "#bodyContent { text-align: justify; }\n";
739 }
740 return $s;
741 }
742
743 /**
744 *
745 */
746 function getUserJs() {
747 global $wgUser, $wgStylePath;
748 $s = '/* generated javascript */';
749 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
750 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
751 $s .= wfMsg(ucfirst($this->skinname).'.js');
752 return $s;
753 }
754 }
755
756 class PHPTAL_version_bridge {
757 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
758 $this->tpl =& new PHPTAL( $file );
759 if( $repository ) {
760 $this->tpl->setTemplateRepository( $repository );
761 }
762 }
763
764 function set( $name, $value ) {
765 $this->tpl->$name = $value;
766 }
767
768 function setRef($name, &$value) {
769 $this->set( $name, $value );
770 }
771
772 function setTranslator( &$t ) {
773 $this->tpl->setTranslator( $t );
774 }
775
776 function execute() {
777 /*
778 try {
779 */
780 return $this->tpl->execute();
781 /*
782 }
783 catch (Exception $e) {
784 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 ";
785 echo $e;
786 echo "</div>";
787 }
788 */
789 }
790 }
791
792 } // end of if( defined( 'MEDIAWIKI' ) )
793 ?>