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