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