Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / SkinTemplate.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 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 *
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
26 *
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42
43 /**
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
46 *
47 * @access private
48 * @package MediaWiki
49 */
50 class MediaWiki_I18N {
51 var $_context = array();
52
53 function set($varName, $value) {
54 $this->_context[$varName] = $value;
55 }
56
57 function translate($value) {
58 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
59 $value = preg_replace( '/^string:/', '', $value );
60
61 $value = wfMsg( $value );
62 // interpolate variables
63 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
64 list($src, $var) = $m;
65 wfSuppressWarnings();
66 $varValue = $this->_context[$var];
67 wfRestoreWarnings();
68 $value = str_replace($src, $varValue, $value);
69 }
70 return $value;
71 }
72 }
73
74 /**
75 *
76 * @package MediaWiki
77 */
78 class SkinTemplate extends Skin {
79 /**#@+
80 * @access private
81 */
82
83 /**
84 * Name of our skin, set in initPage()
85 * It probably need to be all lower case.
86 */
87 var $skinname;
88
89 /**
90 * Stylesheets set to use
91 * Sub directory in ./skins/ where various stylesheets are located
92 */
93 var $stylename;
94
95 /**
96 * For QuickTemplate, name or reference to callback function which
97 * will actually fill the template.
98 *
99 * In PHPTal mode, name of PHPTal template to be used.
100 * '.pt' will be automaticly added to it on PHPTAL object creation
101 */
102 var $template;
103
104 /**#@-*/
105
106 /**
107 * Setup the base parameters...
108 * Child classes should override this to set the name,
109 * style subdirectory, and template filler callback.
110 *
111 * @param OutputPage $out
112 */
113 function initPage( &$out ) {
114 parent::initPage( $out );
115 $this->skinname = 'monobook';
116 $this->stylename = 'monobook';
117 $this->template = 'MonoBookTemplate';
118 }
119
120 /**
121 * Create the template engine object; we feed it a bunch of data
122 * and eventually it spits out some HTML. Should have interface
123 * roughly equivalent to PHPTAL 0.7.
124 *
125 * @param string $callback (or file)
126 * @param string $repository subdirectory where we keep template files
127 * @param string $cache_dir
128 * @return object
129 * @access private
130 */
131 function &setupTemplate( $callback, $repository=false, $cache_dir=false ) {
132 return new QuickTemplate( $callback );
133 }
134
135 /**
136 * initialize various variables and generate the template
137 *
138 * @param OutputPage $out
139 * @access public
140 */
141 function outputPage( &$out ) {
142 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
143 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
144 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
145 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
146 global $wgMaxCredits, $wgShowCreditsIfMax;
147
148 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
149
150 $this->initPage( $out );
151 $tpl =& $this->setupTemplate( $this->template, 'skins' );
152
153 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
154 $tpl->setTranslator(new MediaWiki_I18N());
155 #}
156
157 $this->thispage = $wgTitle->getPrefixedDbKey();
158 $this->thisurl = $wgTitle->getPrefixedURL();
159 $this->loggedin = $wgUser->getID() != 0;
160 $this->iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
161 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
162 $this->username = $wgUser->getName();
163 $this->userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
164 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
165
166 $this->usercss = $this->userjs = $this->userjsprev = false;
167 $this->setupUserCss();
168 $this->setupUserJs();
169 $this->titletxt = $wgTitle->getPrefixedText();
170
171 $tpl->set( 'title', $wgOut->getPageTitle() );
172 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
173
174 $tpl->setRef( "thispage", $this->thispage );
175 $subpagestr = $this->subPageSubtitle();
176 $tpl->set(
177 'subtitle', !empty($subpagestr)?
178 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
179 $out->getSubtitle()
180 );
181 $undelete = $this->getUndeleteLink();
182 $tpl->set(
183 "undelete", !empty($undelete)?
184 '<span class="subpages">'.$undelete.'</span>':
185 ''
186 );
187
188 $tpl->set( 'catlinks', $this->getCategories());
189 if( $wgOut->isSyndicated() ) {
190 $feeds = array();
191 foreach( $wgFeedClasses as $format => $class ) {
192 $feeds[$format] = array(
193 'text' => $format,
194 'href' => $wgRequest->appendQuery( "feed=$format" ),
195 'ttip' => wfMsg('tooltip-'.$format)
196 );
197 }
198 $tpl->setRef( 'feeds', $feeds );
199 } else {
200 $tpl->set( 'feeds', false );
201 }
202 $tpl->setRef( 'mimetype', $wgMimeType );
203 $tpl->setRef( 'charset', $wgOutputEncoding );
204 $tpl->set( 'headlinks', $out->getHeadLinks() );
205 $tpl->setRef( 'wgScript', $wgScript );
206 $tpl->setRef( 'skinname', $this->skinname );
207 $tpl->setRef( 'stylename', $this->stylename );
208 $tpl->setRef( 'loggedin', $this->loggedin );
209 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
210 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL);
211 /* XXX currently unused, might get useful later
212 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
213 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
214 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
215 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
216 $tpl->set( "helppage", wfMsg('helppage'));
217 */
218 $tpl->set( 'searchaction', $this->escapeSearchLink() );
219 $tpl->setRef( 'stylepath', $wgStylePath );
220 $tpl->setRef( 'logopath', $wgLogo );
221 $tpl->setRef( "lang", $wgContLanguageCode );
222 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
223 $tpl->set( 'rtl', $wgContLang->isRTL() );
224 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
225 $tpl->setRef( 'username', $this->username );
226 $tpl->setRef( 'userpage', $this->userpage);
227 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
228 $tpl->setRef( 'usercss', $this->usercss);
229 $tpl->setRef( 'userjs', $this->userjs);
230 $tpl->setRef( 'userjsprev', $this->userjsprev);
231 global $wgUseSiteJs;
232 if ($wgUseSiteJs) {
233 if($this->loggedin) {
234 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
235 } else {
236 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
237 }
238 } else {
239 $tpl->set('jsvarurl', false);
240 }
241 if( $wgUser->getNewtalk() ) {
242 $usertitle = Title::newFromText( $this->userpage );
243 $usertalktitle = $usertitle->getTalkPage();
244 if($usertalktitle->getPrefixedDbKey() != $this->thispage){
245
246 $ntl = wfMsg( 'newmessages',
247 $this->makeKnownLink(
248 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
249 . ':' . $this->username,
250 wfMsg('newmessageslink') )
251 );
252 # Disable Cache
253 $wgOut->setSquidMaxage(0);
254 }
255 } else {
256 $ntl = '';
257 }
258
259 $tpl->setRef( 'newtalk', $ntl );
260 $tpl->setRef( 'skin', $this);
261 $tpl->set( 'logo', $this->logoText() );
262 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
263 if ( !$wgDisableCounters ) {
264 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
265 if ( $viewcount ) {
266 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
267 } else {
268 $tpl->set('viewcount', false);
269 }
270 }
271 $tpl->set('lastmod', $this->lastModified());
272 $tpl->set('copyright',$this->getCopyright());
273
274 $this->credits = false;
275
276 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
277 require_once("Credits.php");
278 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
279 }
280
281 $tpl->setRef( 'credits', $this->credits );
282
283 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
284 $tpl->set('copyright', $this->getCopyright());
285 $tpl->set('viewcount', false);
286 $tpl->set('lastmod', false);
287 $tpl->set('credits', false);
288 } else {
289 $tpl->set('copyright', false);
290 $tpl->set('viewcount', false);
291 $tpl->set('lastmod', false);
292 $tpl->set('credits', false);
293 }
294
295 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
296 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
297 $tpl->set( 'disclaimer', $this->disclaimerLink() );
298 $tpl->set( 'about', $this->aboutLink() );
299
300 $tpl->setRef( 'debug', $out->mDebugtext );
301 $tpl->set( 'reporttime', $out->reportTime() );
302 $tpl->set( 'sitenotice', $wgSiteNotice );
303
304 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
305 $out->mBodytext .= $printfooter ;
306 $tpl->setRef( 'bodytext', $out->mBodytext );
307
308 # Language links
309 $language_urls = array();
310 foreach( $wgOut->getLanguageLinks() as $l ) {
311 $nt = Title::newFromText( $l );
312 $language_urls[] = array('href' => $nt->getFullURL(),
313 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
314 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
315 }
316 if(count($language_urls)) {
317 $tpl->setRef( 'language_urls', $language_urls);
318 } else {
319 $tpl->set('language_urls', false);
320 }
321
322 # Personal toolbar
323 $tpl->set('personal_urls', $this->buildPersonalUrls());
324 $content_actions = $this->buildContentActionUrls();
325 $tpl->setRef('content_actions', $content_actions);
326 // XXX: attach this from javascript, same with section editing
327 if($this->iseditable && $wgUser->getOption("editondblclick") )
328 {
329 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
330 } else {
331 $tpl->set('body_ondblclick', false);
332 }
333 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
334 $tpl->set( 'nav_urls', $this->buildNavUrls() );
335
336 // execute template
337 $res = $tpl->execute();
338
339 // result may be an error
340 $this->printOrError( $res );
341
342 }
343
344 /**
345 * Output the string, or print error message if it's
346 * an error object of the appropriate type.
347 * For the base class, assume strings all around.
348 *
349 * @param mixed $str
350 * @access private
351 */
352 function printOrError( &$str ) {
353 echo $str;
354 }
355
356 /**
357 * build array of urls for personal toolbar
358 * @return array
359 * @access private
360 */
361 function buildPersonalUrls() {
362 /* set up the default links for the personal toolbar */
363 global $wgShowIPinHeader;
364 $personal_urls = array();
365 if ($this->loggedin) {
366 $personal_urls['userpage'] = array(
367 'text' => $this->username,
368 'href' => &$this->userpageUrlDetails['href'],
369 'class' => $this->userpageUrlDetails['exists']?false:'new'
370 );
371 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
372 $personal_urls['mytalk'] = array(
373 'text' => wfMsg('mytalk'),
374 'href' => &$usertalkUrlDetails['href'],
375 'class' => $usertalkUrlDetails['exists']?false:'new'
376 );
377 $personal_urls['preferences'] = array(
378 'text' => wfMsg('preferences'),
379 'href' => $this->makeSpecialUrl('Preferences')
380 );
381 $personal_urls['watchlist'] = array(
382 'text' => wfMsg('watchlist'),
383 'href' => $this->makeSpecialUrl('Watchlist')
384 );
385 $personal_urls['mycontris'] = array(
386 'text' => wfMsg('mycontris'),
387 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username ) )
388 );
389 $personal_urls['logout'] = array(
390 'text' => wfMsg('userlogout'),
391 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
392 );
393 } else {
394 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
395 $personal_urls['anonuserpage'] = array(
396 'text' => $this->username,
397 'href' => &$this->userpageUrlDetails['href'],
398 'class' => $this->userpageUrlDetails['exists']?false:'new'
399 );
400 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
401 $personal_urls['anontalk'] = array(
402 'text' => wfMsg('anontalk'),
403 'href' => &$usertalkUrlDetails['href'],
404 'class' => $usertalkUrlDetails['exists']?false:'new'
405 );
406 $personal_urls['anonlogin'] = array(
407 'text' => wfMsg('userlogin'),
408 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
409 );
410 } else {
411
412 $personal_urls['login'] = array(
413 'text' => wfMsg('userlogin'),
414 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
415 );
416 }
417 }
418
419 return $personal_urls;
420 }
421
422 /**
423 * an array of edit links by default used for the tabs
424 * @return array
425 * @access private
426 */
427 function buildContentActionUrls () {
428 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
429 $action = $wgRequest->getText( 'action' );
430 $section = $wgRequest->getText( 'section' );
431 $oldid = $wgRequest->getVal( 'oldid' );
432 $diff = $wgRequest->getVal( 'diff' );
433 $content_actions = array();
434
435 if( $this->iscontent and !$wgOut->isQuickbarSuppressed() ) {
436
437 $nskey = $this->getNameSpaceKey();
438 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
439 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
440 $content_actions[$nskey] = array('class' => ($is_active) ? 'selected' : false,
441 'text' => wfMsg($nskey),
442 'href' => $this->makeArticleUrl($this->thispage));
443
444 /* set up the classes for the talk link */
445 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : false);
446 $talktitle = Title::newFromText( $this->titletxt );
447 $talktitle = $talktitle->getTalkPage();
448 $this->checkTitle($talktitle, $this->titletxt);
449 if($talktitle->getArticleId() != 0) {
450 $content_actions['talk'] = array(
451 'class' => $talk_class,
452 'text' => wfMsg('talk'),
453 'href' => $this->makeTalkUrl($this->titletxt)
454 );
455 } else {
456 $content_actions['talk'] = array(
457 'class' => $talk_class?$talk_class.' new':'new',
458 'text' => wfMsg('talk'),
459 'href' => $this->makeTalkUrl($this->titletxt,'action=edit')
460 );
461 }
462
463 if ( $wgTitle->userCanEdit() ) {
464 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
465 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
466 $istalkclass = $istalk?' istalk':'';
467 $content_actions['edit'] = array(
468 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
469 'text' => wfMsg('edit'),
470 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid)
471 );
472 if ( $istalk ) {
473 $content_actions['addsection'] = array(
474 'class' => $section == 'new'?'selected':false,
475 'text' => wfMsg('addsection'),
476 'href' => $this->makeUrl($this->thispage, 'action=edit&section=new')
477 );
478 }
479 } else {
480 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
481 $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
482 'text' => wfMsg('viewsource'),
483 'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
484 }
485
486 if ( $wgTitle->getArticleId() ) {
487
488 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : false,
489 'text' => wfMsg('history_short'),
490 'href' => $this->makeUrl($this->thispage, 'action=history'));
491
492 # XXX: is there a rollback action anywhere or is it planned?
493 # Don't recall where i got this from...
494 /*if( $wgUser->getNewtalk() ) {
495 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
496 'text' => wfMsg('rollback_short'),
497 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
498 'ttip' => wfMsg('tooltip-rollback'),
499 'akey' => wfMsg('accesskey-rollback'));
500 }
501 */
502
503 if($wgUser->isAllowed('protect')){
504 if(!$wgTitle->isProtected()){
505 $content_actions['protect'] = array(
506 'class' => ($action == 'protect') ? 'selected' : false,
507 'text' => wfMsg('protect'),
508 'href' => $this->makeUrl($this->thispage, 'action=protect')
509 );
510
511 } else {
512 $content_actions['unprotect'] = array(
513 'class' => ($action == 'unprotect') ? 'selected' : false,
514 'text' => wfMsg('unprotect'),
515 'href' => $this->makeUrl($this->thispage, 'action=unprotect')
516 );
517 }
518 }
519 if($wgUser->isAllowed('delete')){
520 $content_actions['delete'] = array(
521 'class' => ($action == 'delete') ? 'selected' : false,
522 'text' => wfMsg('delete'),
523 'href' => $this->makeUrl($this->thispage, 'action=delete')
524 );
525 }
526 if ( $wgUser->getID() != 0 ) {
527 if ( $wgTitle->userCanEdit()) {
528 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
529 'text' => wfMsg('move'),
530 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
531 );
532 }
533 }
534 } else {
535 //article doesn't exist or is deleted
536 if($wgUser->isAllowed('delete')){
537 if( $n = $wgTitle->isDeleted() ) {
538 $content_actions['undelete'] = array(
539 'class' => false,
540 'text' => wfMsg( "undelete_short", $n ),
541 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
542 );
543 }
544 }
545 }
546
547 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
548 if( !$wgTitle->userIsWatching()) {
549 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
550 'text' => wfMsg('watch'),
551 'href' => $this->makeUrl($this->thispage, 'action=watch'));
552 } else {
553 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
554 'text' => wfMsg('unwatch'),
555 'href' => $this->makeUrl($this->thispage, 'action=unwatch'));
556 }
557 }
558
559 # Show validate tab
560 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
561 global $wgArticle ;
562 $article_time = "&timestamp=" . $wgArticle->mTimestamp ;
563 $content_actions['validate'] = array('class' => ($action == 'validate') ? 'selected' : false ,
564 'text' => wfMsg('val_tab'),
565 'href' => $this->makeUrl($this->thispage, 'action=validate'.$article_time));
566 }
567
568 } else {
569 /* show special page tab */
570
571 $content_actions['article'] = array('class' => 'selected',
572 'text' => wfMsg('specialpage'),
573 'href' => false);
574 }
575
576 return $content_actions;
577 }
578
579 /**
580 * build array of global navigation links
581 * @return array
582 * @access private
583 */
584 function buildNavigationUrls () {
585 global $wgNavigationLinks;
586 $result = array();
587 foreach ( $wgNavigationLinks as $link ) {
588 if (wfMsg( $link['text'] ) != '-') {
589 $result[] = array(
590 'text' => wfMsg( $link['text'] ),
591 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
592 'id' => 'n-'.$link['text']
593 );
594 }
595 }
596 return $result;
597 }
598
599 /**
600 * build array of common navigation links
601 * @return array
602 * @access private
603 */
604 function buildNavUrls () {
605 global $wgTitle, $wgUser, $wgRequest;
606 global $wgSiteSupportPage, $wgDisableUploads;
607
608 $action = $wgRequest->getText( 'action' );
609 $oldid = $wgRequest->getVal( 'oldid' );
610 $diff = $wgRequest->getVal( 'diff' );
611 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
612 $nav_urls = array();
613 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
614 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
615 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
616 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
617 $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
618 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
619 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
620 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
621 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
622 if( $this->loggedin && !$wgDisableUploads ) {
623 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
624 } else {
625 $nav_urls['upload'] = false;
626 }
627 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
628
629 if( $wgTitle->getNamespace() != NS_SPECIAL) {
630 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
631 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
632 }
633
634 if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
635 $id = User::idFromName($wgTitle->getText());
636 $ip = User::isIP($wgTitle->getText());
637 } else {
638 $id = 0;
639 $ip = false;
640 }
641
642 if($id || $ip) { # both anons and non-anons have contri list
643 $nav_urls['contributions'] = array(
644 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
645 );
646 } else {
647 $nav_urls['contributions'] = false;
648 }
649 $nav_urls['emailuser'] = false;
650 if ( 0 != $wgUser->getID() ) { # show only to signed in users
651 if($id) { # can only email non-anons
652 $nav_urls['emailuser'] = array(
653 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
654 );
655 }
656 }
657
658 return $nav_urls;
659 }
660
661 /**
662 * Generate strings used for xml 'id' names
663 * @return string
664 * @private
665 */
666 function getNameSpaceKey () {
667 global $wgTitle;
668 switch ($wgTitle->getNamespace()) {
669 case NS_MAIN:
670 case NS_TALK:
671 return 'nstab-main';
672 case NS_USER:
673 case NS_USER_TALK:
674 return 'nstab-user';
675 case NS_MEDIA:
676 return 'nstab-media';
677 case NS_SPECIAL:
678 return 'nstab-special';
679 case NS_PROJECT:
680 case NS_PROJECT_TALK:
681 return 'nstab-wp';
682 case NS_IMAGE:
683 case NS_IMAGE_TALK:
684 return 'nstab-image';
685 case NS_MEDIAWIKI:
686 case NS_MEDIAWIKI_TALK:
687 return 'nstab-mediawiki';
688 case NS_TEMPLATE:
689 case NS_TEMPLATE_TALK:
690 return 'nstab-template';
691 case NS_HELP:
692 case NS_HELP_TALK:
693 return 'nstab-help';
694 case NS_CATEGORY:
695 case NS_CATEGORY_TALK:
696 return 'nstab-category';
697 default:
698 return 'nstab-main';
699 }
700 }
701
702 /**
703 * @access private
704 */
705 function setupUserCss() {
706 global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss;
707
708 $sitecss = "";
709 $usercss = "";
710 $siteargs = "";
711
712 # Add user-specific code if this is a user and we allow that kind of thing
713
714 if ( $wgAllowUserCss && $this->loggedin ) {
715 $action = $wgRequest->getText('action');
716
717 # if we're previewing the CSS page, use it
718 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
719 $siteargs .= "&smaxage=0&maxage=0";
720 $usercss = $wgRequest->getText('wpTextbox1');
721 } else {
722 $siteargs .= "&maxage=0";
723 $usercss = '@import "' .
724 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
725 'action=raw&ctype=text/css') . '";' ."\n";
726 }
727 }
728
729 # If we use the site's dynamic CSS, throw that in, too
730
731 if ( $wgUseSiteCss ) {
732 $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n";
733 }
734
735 # If we use any dynamic CSS, make a little CDATA block out of it.
736
737 if ( !empty($sitecss) || !empty($usercss) ) {
738 $this->usercss = '/*<![CDATA[*/ ' . $sitecss . ' ' . $usercss . ' /*]]>*/';
739 }
740 }
741
742 /**
743 * @access private
744 */
745 function setupUserJs() {
746 global $wgRequest, $wgTitle, $wgAllowUserJs;
747 $action = $wgRequest->getText('action');
748
749 if( $wgAllowUserJs && $this->loggedin ) {
750 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
751 # XXX: additional security check/prompt?
752 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
753 } else {
754 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
755 }
756 }
757 }
758
759 /**
760 * returns css with user-specific options
761 * @access public
762 */
763 function getUserStylesheet() {
764 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
765 $action = $wgRequest->getText('action');
766 $maxage = $wgRequest->getText('maxage');
767 $s = "/* generated user stylesheet */\n";
768 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename.'/rtl.css";'."\n";
769 $s .= '@import "'.
770 $this->makeNSUrl(ucfirst($this->skinname).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI)."\";\n";
771 if($wgUser->getID() != 0) {
772 if ( 1 == $wgUser->getOption( "underline" ) ) {
773 $s .= "a { text-decoration: underline; }\n";
774 } else {
775 $s .= "a { text-decoration: none; }\n";
776 }
777 }
778 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
779 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
780 }
781 if ( 1 == $wgUser->getOption( "justify" ) ) {
782 $s .= "#bodyContent { text-align: justify; }\n";
783 }
784 return $s;
785 }
786
787 /**
788 * @access public
789 */
790 function getUserJs() {
791 global $wgUser, $wgStylePath;
792 $s = '/* generated javascript */';
793 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
794 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
795 $s .= wfMsg(ucfirst($this->skinname).'.js');
796 return $s;
797 }
798 }
799
800 /**
801 * Generic wrapper for template functions, with interface
802 * compatible with what we use of PHPTAL 0.7.
803 */
804 class QuickTemplate {
805 function QuickTemplate( $callback, $repository=false, $cache_dir=false ) {
806 $this->outputCallback = $callback;
807 $this->data = array();
808 $this->translator = null;
809 }
810
811 function set( $name, $value ) {
812 $this->data[$name] = $value;
813 }
814
815 function setRef($name, &$value) {
816 $this->data[$name] =& $value;
817 }
818
819 function setTranslator( &$t ) {
820 $this->translator = &$t;
821 }
822
823 function execute() {
824 return call_user_func_array( $this->outputCallback,
825 array( &$this->data, &$this->translator ) );
826 }
827 }
828
829 } // end of if( defined( 'MEDIAWIKI' ) )
830 ?>