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