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