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