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