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