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