4282a95ba3e240cd3abeaf3812b5c98254f13ace
[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 = 'monobook';
64 $this->template = 'MonoBook';
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', 'skins');
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 # Disable Cache
171 $wgOut->setSquidMaxage(0);
172 }
173 } else {
174 $ntl = '';
175 }
176
177 $tpl->setRef( 'newtalk', $ntl );
178 $tpl->setRef( 'skin', $this);
179 $tpl->set( 'logo', $this->logoText() );
180 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
181 if ( !$wgDisableCounters ) {
182 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
183 if ( $viewcount ) {
184 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
185 }
186 }
187 $tpl->set('lastmod', $this->lastModified());
188 $tpl->set('copyright',$this->getCopyright());
189
190 $this->credits = false;
191
192 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
193 require_once("Credits.php");
194 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
195 }
196
197 $tpl->setRef( 'credits', $this->credits );
198
199 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
200 $tpl->set('copyright', $this->getCopyright());
201 }
202
203 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
204 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
205 $tpl->set( 'disclaimer', $this->disclaimerLink() );
206 $tpl->set( 'about', $this->aboutLink() );
207
208 $tpl->setRef( 'debug', $out->mDebugtext );
209 $tpl->set( 'reporttime', $out->reportTime() );
210 $tpl->set( 'sitenotice', $wgSiteNotice );
211
212 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
213 $out->mBodytext .= $printfooter ;
214 $tpl->setRef( 'bodytext', $out->mBodytext );
215
216 $language_urls = array();
217 foreach( $wgOut->getLanguageLinks() as $l ) {
218 $nt = Title::newFromText( $l );
219 $language_urls[] = array('href' => $nt->getFullURL(),
220 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
221 'class' => $wgLang->isRTL() ? 'rtl' : 'ltr');
222 }
223 if(count($language_urls)) {
224 $tpl->setRef( 'language_urls', $language_urls);
225 } else {
226 $tpl->set('language_urls', false);
227 }
228 $tpl->set('personal_urls', $this->buildPersonalUrls());
229 $content_actions = $this->buildContentActionUrls();
230 $tpl->setRef('content_actions', $content_actions);
231 // XXX: attach this from javascript, same with section editing
232 if($this->iseditable && $wgUser->getOption("editondblclick") )
233 {
234 $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
235 } else {
236 $tpl->set('body-ondblclick', false);
237 }
238 $tpl->set( 'nav_urls', $this->buildNavUrls() );
239
240 // execute template
241 $res = $tpl->execute();
242 // result may be an error
243 if (PEAR::isError($res)) {
244 echo $res->toString(), "\n";
245 } else {
246 echo $res;
247 }
248
249 }
250
251 # build array of urls for personal toolbar
252 function buildPersonalUrls() {
253 /* set up the default links for the personal toolbar */
254 global $wgShowIPinHeader;
255 $personal_urls = array();
256 if ($this->loggedin) {
257 $personal_urls['userpage'] = array(
258 'text' => $this->username,
259 'href' => &$this->userpageUrlDetails['href'],
260 'class' => $this->userpageUrlDetails['exists']?false:'new'
261 );
262 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
263 $personal_urls['mytalk'] = array(
264 'text' => wfMsg('mytalk'),
265 'href' => &$usertalkUrlDetails['href'],
266 'class' => $usertalkUrlDetails['exists']?false:'new'
267 );
268 $personal_urls['preferences'] = array(
269 'text' => wfMsg('preferences'),
270 'href' => $this->makeSpecialUrl('Preferences')
271 );
272 $personal_urls['watchlist'] = array(
273 'text' => wfMsg('watchlist'),
274 'href' => $this->makeSpecialUrl('Watchlist')
275 );
276 $personal_urls['mycontris'] = array(
277 'text' => wfMsg('mycontris'),
278 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) )
279 );
280 $personal_urls['logout'] = array(
281 'text' => wfMsg('userlogout'),
282 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
283 );
284 } else {
285 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
286 $personal_urls['anonuserpage'] = array(
287 'text' => $this->username,
288 'href' => &$this->userpageUrlDetails['href'],
289 'class' => $this->userpageUrlDetails['exists']?false:'new'
290 );
291 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
292 $personal_urls['anontalk'] = array(
293 'text' => wfMsg('anontalk'),
294 'href' => &$usertalkUrlDetails['href'],
295 'class' => $usertalkUrlDetails['exists']?false:'new'
296 );
297 $personal_urls['anonlogin'] = array(
298 'text' => wfMsg('userlogin'),
299 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
300 );
301 } else {
302
303 $personal_urls['login'] = array(
304 'text' => wfMsg('userlogin'),
305 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
306 );
307 }
308 }
309
310 return $personal_urls;
311 }
312
313 # an array of edit links by default used for the tabs
314 function buildContentActionUrls () {
315 global $wgTitle, $wgUser, $wgRequest, $wgUseValidation;
316 $action = $wgRequest->getText( 'action' );
317 $section = $wgRequest->getText( 'section' );
318 $oldid = $wgRequest->getVal( 'oldid' );
319 $diff = $wgRequest->getVal( 'diff' );
320 $content_actions = array();
321
322 if( $this->iscontent ) {
323
324 $nskey = $this->getNameSpaceKey();
325 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
326 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
327 $content_actions[$nskey] = array('class' => ($is_active) ? 'selected' : false,
328 'text' => wfMsg($nskey),
329 'href' => $this->makeArticleUrl($this->thispage));
330
331 /* set up the classes for the talk link */
332 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : false);
333 $talktitle = Title::newFromText( $this->titletxt );
334 $talktitle = $talktitle->getTalkPage();
335 $this->checkTitle($talktitle, $this->titletxt);
336 if($talktitle->getArticleId() != 0) {
337 $content_actions['talk'] = array(
338 'class' => $talk_class,
339 'text' => wfMsg('talk'),
340 'href' => $this->makeTalkUrl($this->titletxt)
341 );
342 } else {
343 $content_actions['talk'] = array(
344 'class' => $talk_class?$talk_class.' new':'new',
345 'text' => wfMsg('talk'),
346 'href' => $this->makeTalkUrl($this->titletxt,'action=edit')
347 );
348 }
349
350 if ( $wgTitle->userCanEdit() ) {
351 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : false;
352 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
353 $istalkclass = $istalk?' istalk':'';
354 $content_actions['edit'] = array(
355 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
356 'text' => wfMsg('edit'),
357 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid)
358 );
359 if ( $istalk ) {
360 $content_actions['addsection'] = array(
361 'class' => $section == 'new'?'selected':false,
362 'text' => wfMsg('addsection'),
363 'href' => $this->makeUrl($this->thispage, 'action=edit&section=new')
364 );
365 }
366 } else {
367 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : '';
368 $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
369 'text' => wfMsg('viewsource'),
370 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
371 }
372
373 if ( $wgTitle->getArticleId() ) {
374
375 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : false,
376 'text' => wfMsg('history_short'),
377 'href' => $this->makeUrl($this->thispage, 'action=history'));
378
379 # XXX: is there a rollback action anywhere or is it planned?
380 # Don't recall where i got this from...
381 /*if( $wgUser->getNewtalk() ) {
382 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
383 'text' => wfMsg('rollback_short'),
384 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
385 'ttip' => wfMsg('tooltip-rollback'),
386 'akey' => wfMsg('accesskey-rollback'));
387 }*/
388
389 if($wgUser->isSysop()){
390 if(!$wgTitle->isProtected()){
391 $content_actions['protect'] = array(
392 'class' => ($action == 'protect') ? 'selected' : false,
393 'text' => wfMsg('protect'),
394 'href' => $this->makeUrl($this->thispage, 'action=protect')
395 );
396
397 } else {
398 $content_actions['unprotect'] = array(
399 'class' => ($action == 'unprotect') ? 'selected' : false,
400 'text' => wfMsg('unprotect'),
401 'href' => $this->makeUrl($this->thispage, 'action=unprotect')
402 );
403 }
404 $content_actions['delete'] = array(
405 'class' => ($action == 'delete') ? 'selected' : false,
406 'text' => wfMsg('delete'),
407 'href' => $this->makeUrl($this->thispage, 'action=delete')
408 );
409 }
410 if ( $wgUser->getID() != 0 ) {
411 if ( $wgTitle->userCanEdit()) {
412 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
413 'text' => wfMsg('move'),
414 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
415 );
416 } else {
417 $content_actions['move'] = array('class' => 'inactive',
418 'text' => wfMsg('move'),
419 'href' => false);
420
421 }
422 }
423 } else {
424 //article doesn't exist or is deleted
425 if($wgUser->isSysop()){
426 if( $n = $wgTitle->isDeleted() ) {
427 $content_actions['delete'] = array(
428 'class' => false,
429 'text' => wfMsg( "undelete_short", $n ),
430 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
431 );
432 }
433 }
434 }
435
436 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
437 if( !$wgTitle->userIsWatching()) {
438 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
439 'text' => wfMsg('watch'),
440 'href' => $this->makeUrl($this->thispage, 'action=watch'));
441 } else {
442 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
443 'text' => wfMsg('unwatch'),
444 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
445 }
446 }
447
448 # Show validate tab
449 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
450 global $wgArticle ;
451 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
452 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
453 'text' => wfMsg('val_tab'),
454 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
455 }
456
457 } else {
458 /* show special page tab */
459
460 $content_actions['article'] = array('class' => 'selected',
461 'text' => wfMsg('specialpage'),
462 'href' => false);
463 }
464
465 return $content_actions;
466 }
467
468 # build array of common navigation links
469 function buildNavUrls () {
470 global $wgTitle, $wgUser, $wgRequest;
471 global $wgSiteSupportPage, $wgDisableUploads;
472
473 $action = $wgRequest->getText( 'action' );
474 $oldid = $wgRequest->getVal( 'oldid' );
475 $diff = $wgRequest->getVal( 'diff' );
476 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
477 $nav_urls = array();
478 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
479 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
480 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
481 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage ))));
482 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : false;
483 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : false;
484 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage ))));
485 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
486 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
487 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
488 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
489 if( $this->loggedin && !$wgDisableUploads ) {
490 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
491 }
492 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
493
494 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
495 $id = User::idFromName($wgTitle->getText());
496 $ip = User::isIP($wgTitle->getText());
497 } else {
498 $id = 0;
499 $ip = false;
500 }
501
502 if($id || $ip) { # both anons and non-anons have contri list
503 $nav_urls['contributions'] = array(
504 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
505 );
506 }
507 if ( 0 != $wgUser->getID() ) { # show only to signed in users
508 if($id) { # can only email non-anons
509 $nav_urls['emailuser'] = array(
510 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
511 );
512 }
513 }
514
515
516 return $nav_urls;
517 }
518
519 # Generate strings used for xml 'id' names
520 function getNameSpaceKey () {
521 global $wgTitle;
522 switch ($wgTitle->getNamespace()) {
523 case NS_MAIN:
524 case NS_TALK:
525 return 'nstab-main';
526 case NS_USER:
527 case NS_USER_TALK:
528 return 'nstab-user';
529 case NS_MEDIA:
530 return 'nstab-media';
531 case NS_SPECIAL:
532 return 'nstab-special';
533 case NS_PROJECT:
534 case NS_PROJECT_TALK:
535 return 'nstab-wp';
536 case NS_IMAGE:
537 case NS_IMAGE_TALK:
538 return 'nstab-image';
539 case NS_MEDIAWIKI:
540 case NS_MEDIAWIKI_TALK:
541 return 'nstab-mediawiki';
542 case NS_TEMPLATE:
543 case NS_TEMPLATE_TALK:
544 return 'nstab-template';
545 case NS_HELP:
546 case NS_HELP_TALK:
547 return 'nstab-help';
548 case NS_CATEGORY:
549 case NS_CATEGORY_TALK:
550 return 'nstab-category';
551 default:
552 return 'nstab-main';
553 }
554 }
555
556
557 /* private */ function setupUserCssJs () {
558 global $wgRequest, $wgTitle;
559 $action = $wgRequest->getText('action');
560 # generated css
561 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n";
562
563 if( $this->loggedin ) {
564 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
565 # generated css
566 $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n";
567 // css preview
568 $this->usercss .= $wgRequest->getText('wpTextbox1');
569 } else {
570 # generated css
571 $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n";
572 # import user stylesheet
573 $this->usercss .= '@import "'.
574 $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n";
575 }
576 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
577 # XXX: additional security check/prompt?
578 $this->userjsprev = $wgRequest->getText('wpTextbox1');
579 } else {
580 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
581 }
582 }
583 }
584
585 # returns css with user-specific options
586 function getUserStylesheet() {
587 global $wgUser, $wgRequest, $wgTitle, $wgLang, $wgSquidMaxage, $wgStylePath;
588 $action = $wgRequest->getText('action');
589 $maxage = $wgRequest->getText('maxage');
590 $s = "/* generated user stylesheet */\n";
591 if($wgLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->skinname.'/rtl.css";'."\n";
592 $s .= '@import "'.
593 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
594 if($wgUser->getID() != 0) {
595 if ( 1 == $wgUser->getOption( "underline" ) ) {
596 $s .= "a { text-decoration: underline; }\n";
597 } else {
598 $s .= "a { text-decoration: none; }\n";
599 }
600 }
601 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
602 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
603 }
604 if ( 1 == $wgUser->getOption( "justify" ) ) {
605 $s .= "#bodyContent { text-align: justify; }\n";
606 }
607 return $s;
608 }
609
610 function getUserJs() {
611 global $wgUser, $wgStylePath;
612 $s = '/* generated javascript */';
613 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
614 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
615 $s .= wfMsg(ucfirst($this->skinname).'.js');
616 return $s;
617 }
618 }
619
620 } // end of if( defined( 'MEDIAWIKI' ) )
621 ?>