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