Remove some cruft from skins... sooooo much cruft yet to go
[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 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
60
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
63
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
68 wfSuppressWarnings();
69 $varValue = $this->_context[$var];
70 wfRestoreWarnings();
71 $value = str_replace($src, $varValue, $value);
72 }
73 wfProfileOut( $fname );
74 return $value;
75 }
76 }
77
78 /**
79 *
80 * @package MediaWiki
81 */
82 class SkinTemplate extends Skin {
83 /**#@+
84 * @access private
85 */
86
87 /**
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
90 */
91 var $skinname;
92
93 /**
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
96 */
97 var $stylename;
98
99 /**
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
102 *
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /**
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
114 *
115 * @param OutputPage $out
116 */
117 function initPage( &$out ) {
118 parent::initPage( $out );
119 $this->skinname = 'monobook';
120 $this->stylename = 'monobook';
121 $this->template = 'QuickTemplate';
122 }
123
124 /**
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
128 *
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
132 * @return object
133 * @access private
134 */
135 function &setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
137 }
138
139 /**
140 * initialize various variables and generate the template
141 *
142 * @param OutputPage $out
143 * @access public
144 */
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
155
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
160
161 $this->mTitle = $wgTitle;
162 $this->mUser =& $wgUser;
163
164 $tpl =& $this->setupTemplate( $this->template, 'skins' );
165
166 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
167 $tpl->setTranslator(new MediaWiki_I18N());
168 #}
169 wfProfileOut( "$fname-init" );
170
171 wfProfileIn( "$fname-stuff" );
172 $this->thispage = $this->mTitle->getPrefixedDbKey();
173 $this->thisurl = $this->mTitle->getPrefixedURL();
174 $this->loggedin = $wgUser->getID() != 0;
175 $this->iscontent = ($this->mTitle->getNamespace() != Namespace::getSpecial() );
176 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
177 $this->username = $wgUser->getName();
178 $this->userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
179 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
180
181 $this->usercss = $this->userjs = $this->userjsprev = false;
182 $this->setupUserCss();
183 $this->setupUserJs();
184 $this->titletxt = $this->mTitle->getPrefixedText();
185 wfProfileOut( "$fname-stuff" );
186
187 wfProfileIn( "$fname-stuff2" );
188 $tpl->set( 'title', $wgOut->getPageTitle() );
189 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
190
191 $tpl->setRef( "thispage", $this->thispage );
192 $subpagestr = $this->subPageSubtitle();
193 $tpl->set(
194 'subtitle', !empty($subpagestr)?
195 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
196 $out->getSubtitle()
197 );
198 $undelete = $this->getUndeleteLink();
199 $tpl->set(
200 "undelete", !empty($undelete)?
201 '<span class="subpages">'.$undelete.'</span>':
202 ''
203 );
204
205 $tpl->set( 'catlinks', $this->getCategories());
206 if( $wgOut->isSyndicated() ) {
207 $feeds = array();
208 foreach( $wgFeedClasses as $format => $class ) {
209 $feeds[$format] = array(
210 'text' => $format,
211 'href' => $wgRequest->appendQuery( "feed=$format" ),
212 'ttip' => wfMsg('tooltip-'.$format)
213 );
214 }
215 $tpl->setRef( 'feeds', $feeds );
216 } else {
217 $tpl->set( 'feeds', false );
218 }
219 $tpl->setRef( 'mimetype', $wgMimeType );
220 $tpl->setRef( 'charset', $wgOutputEncoding );
221 $tpl->set( 'headlinks', $out->getHeadLinks() );
222 $tpl->setRef( 'wgScript', $wgScript );
223 $tpl->setRef( 'skinname', $this->skinname );
224 $tpl->setRef( 'stylename', $this->stylename );
225 $tpl->setRef( 'loggedin', $this->loggedin );
226 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
227 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
228 /* XXX currently unused, might get useful later
229 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
230 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
231 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
232 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
233 $tpl->set( "helppage", wfMsg('helppage'));
234 */
235 $tpl->set( 'searchaction', $this->escapeSearchLink() );
236 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
237 $tpl->setRef( 'stylepath', $wgStylePath );
238 $tpl->setRef( 'logopath', $wgLogo );
239 $tpl->setRef( "lang", $wgContLanguageCode );
240 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
241 $tpl->set( 'rtl', $wgContLang->isRTL() );
242 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
243 $tpl->setRef( 'username', $this->username );
244 $tpl->setRef( 'userpage', $this->userpage);
245 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
246 $tpl->setRef( 'usercss', $this->usercss);
247 $tpl->setRef( 'userjs', $this->userjs);
248 $tpl->setRef( 'userjsprev', $this->userjsprev);
249 global $wgUseSiteJs;
250 if ($wgUseSiteJs) {
251 if($this->loggedin) {
252 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
253 } else {
254 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
255 }
256 } else {
257 $tpl->set('jsvarurl', false);
258 }
259 if( $wgUser->getNewtalk() ) {
260 $usertitle = $this->mUser->getUserPage();
261 $usertalktitle = $usertitle->getTalkPage();
262 if( !$usertalktitle->equals( $this->mTitle ) ) {
263 $ntl = wfMsg( 'newmessages',
264 $this->makeKnownLinkObj(
265 $usertalktitle,
266 wfMsg('newmessageslink')
267 )
268 );
269 # Disable Cache
270 $wgOut->setSquidMaxage(0);
271 }
272 } else {
273 $ntl = '';
274 }
275 wfProfileOut( "$fname-stuff2" );
276
277 wfProfileIn( "$fname-stuff3" );
278 $tpl->setRef( 'newtalk', $ntl );
279 $tpl->setRef( 'skin', $this);
280 $tpl->set( 'logo', $this->logoText() );
281 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
282 if ( !$wgDisableCounters ) {
283 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
284 if ( $viewcount ) {
285 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
286 } else {
287 $tpl->set('viewcount', false);
288 }
289 }
290
291 if ($wgPageShowWatchingUsers) {
292 $dbr =& wfGetDB( DB_SLAVE );
293 extract( $dbr->tableNames( 'watchlist' ) );
294 $sql = "SELECT COUNT(*) AS n FROM $watchlist
295 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
296 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
297 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
298 $x = $dbr->fetchObject( $res );
299 $numberofwatchingusers = $x->n;
300 if ($numberofwatchingusers > 0) {
301 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
302 } else {
303 $tpl->set('numberofwatchingusers', false);
304 }
305 } else {
306 $tpl->set('numberofwatchingusers', false);
307 }
308
309 $tpl->set('lastmod', $this->lastModified());
310 $tpl->set('copyright',$this->getCopyright());
311
312 $this->credits = false;
313
314 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
315 require_once("Credits.php");
316 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
317 }
318
319 $tpl->setRef( 'credits', $this->credits );
320
321 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
322 $tpl->set('copyright', $this->getCopyright());
323 $tpl->set('viewcount', false);
324 $tpl->set('lastmod', false);
325 $tpl->set('credits', false);
326 $tpl->set('numberofwatchingusers', false);
327 } else {
328 $tpl->set('copyright', false);
329 $tpl->set('viewcount', false);
330 $tpl->set('lastmod', false);
331 $tpl->set('credits', false);
332 $tpl->set('numberofwatchingusers', false);
333 }
334 wfProfileOut( "$fname-stuff3" );
335
336 wfProfileIn( "$fname-stuff4" );
337 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
338 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
339 $tpl->set( 'disclaimer', $this->disclaimerLink() );
340 $tpl->set( 'about', $this->aboutLink() );
341
342 $tpl->setRef( 'debug', $out->mDebugtext );
343 $tpl->set( 'reporttime', $out->reportTime() );
344 $tpl->set( 'sitenotice', $wgSiteNotice );
345 $tpl->set( 'tagline', wfMsg('tagline') );
346
347 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
348 $out->mBodytext .= $printfooter ;
349 $tpl->setRef( 'bodytext', $out->mBodytext );
350
351 # Language links
352 $language_urls = array();
353 foreach( $wgOut->getLanguageLinks() as $l ) {
354 $nt = Title::newFromText( $l );
355 $language_urls[] = array('href' => $nt->getFullURL(),
356 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
357 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
358 }
359 if(count($language_urls)) {
360 $tpl->setRef( 'language_urls', $language_urls);
361 } else {
362 $tpl->set('language_urls', false);
363 }
364 wfProfileOut( "$fname-stuff4" );
365
366 # Personal toolbar
367 $tpl->set('personal_urls', $this->buildPersonalUrls());
368 $content_actions = $this->buildContentActionUrls();
369 $tpl->setRef('content_actions', $content_actions);
370
371 // XXX: attach this from javascript, same with section editing
372 if($this->iseditable && $wgUser->getOption("editondblclick") )
373 {
374 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
375 } else {
376 $tpl->set('body_ondblclick', false);
377 }
378 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
379 $tpl->set( 'nav_urls', $this->buildNavUrls() );
380
381 // execute template
382 wfProfileIn( "$fname-execute" );
383 $res = $tpl->execute();
384 wfProfileOut( "$fname-execute" );
385
386 // result may be an error
387 $this->printOrError( $res );
388 wfProfileOut( $fname );
389 }
390
391 /**
392 * Output the string, or print error message if it's
393 * an error object of the appropriate type.
394 * For the base class, assume strings all around.
395 *
396 * @param mixed $str
397 * @access private
398 */
399 function printOrError( &$str ) {
400 echo $str;
401 }
402
403 /**
404 * build array of urls for personal toolbar
405 * @return array
406 * @access private
407 */
408 function buildPersonalUrls() {
409 $fname = 'SkinTemplate::buildPersonalUrls';
410 wfProfileIn( $fname );
411
412 /* set up the default links for the personal toolbar */
413 global $wgShowIPinHeader;
414 $personal_urls = array();
415 if ($this->loggedin) {
416 /* Logged in users personal toolbar */
417 $personal_urls['userpage'] = array(
418 'text' => wfMsg('mypage'),
419 'href' => $this->makeSpecialUrl('Mypage')
420 );
421 $personal_urls['mytalk'] = array(
422 'text' => wfMsg('mytalk'),
423 'href' => $this->makeSpecialUrl('Mytalk')
424 );
425 $personal_urls['preferences'] = array(
426 'text' => wfMsg('preferences'),
427 'href' => $this->makeSpecialUrl('Preferences')
428 );
429 $personal_urls['watchlist'] = array(
430 'text' => wfMsg('watchlist'),
431 'href' => $this->makeSpecialUrl('Watchlist')
432 );
433 $personal_urls['mycontris'] = array(
434 'text' => wfMsg('mycontris'),
435 'href' => $this->makeSpecialUrl('Mycontributions')
436 );
437 $personal_urls['logout'] = array(
438 'text' => wfMsg('userlogout'),
439 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
440 );
441 } else {
442 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
443 /* Anonymous with session users personal toolbar */
444 $personal_urls['anonuserpage'] = array(
445 'text' => wfMsg('mypage'),
446 'href' => $this->makeSpecialUrl('Mypage')
447 );
448 $personal_urls['mytalk'] = array(
449 'text' => wfMsg('mytalk'),
450 'href' => $this->makeSpecialUrl('Mytalk')
451 );
452
453 $personal_urls['anonlogin'] = array(
454 'text' => wfMsg('userlogin'),
455 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
456 );
457 } else {
458 /* Anonymous users personal toolbar */
459 $personal_urls['login'] = array(
460 'text' => wfMsg('userlogin'),
461 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
462 );
463 }
464 }
465 wfProfileOut( $fname );
466 return $personal_urls;
467 }
468
469
470 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
471 $classes = array();
472 if( $selected ) {
473 $classes[] = 'selected';
474 }
475 if( $checkEdit && $title->getArticleId() == 0 ) {
476 $classes[] = 'new';
477 }
478 return array(
479 'class' => implode( ' ', $classes ),
480 'text' => wfMsg( $message ),
481 'href' => $title->getLocalUrl( $query ) );
482 }
483
484 /**
485 * an array of edit links by default used for the tabs
486 * @return array
487 * @access private
488 */
489 function buildContentActionUrls () {
490 global $wgContLang;
491 $fname = 'SkinTemplate::buildContentActionUrls';
492 wfProfileIn( $fname );
493
494 global $wgUser, $wgRequest;
495 $action = $wgRequest->getText( 'action' );
496 $section = $wgRequest->getText( 'section' );
497 $oldid = $wgRequest->getVal( 'oldid' );
498 $diff = $wgRequest->getVal( 'diff' );
499 $content_actions = array();
500
501 if( $this->iscontent ) {
502
503 $nskey = $this->getNameSpaceKey();
504 $content_actions[$nskey] = $this->tabAction(
505 $this->mTitle->getSubjectPage(),
506 $nskey,
507 !$this->mTitle->isTalkPage() );
508
509 $content_actions['talk'] = $this->tabAction(
510 $this->mTitle->getTalkPage(),
511 'talk',
512 $this->mTitle->isTalkPage(),
513 '',
514 true);
515
516 wfProfileIn( "$fname-edit" );
517 if ( $this->mTitle->userCanEdit() ) {
518 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
519 $istalk = $this->mTitle->isTalkPage();
520 $istalkclass = $istalk?' istalk':'';
521 $content_actions['edit'] = array(
522 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
523 'text' => wfMsg('edit'),
524 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
525 );
526
527 if ( $istalk ) {
528 $content_actions['addsection'] = array(
529 'class' => $section == 'new'?'selected':false,
530 'text' => wfMsg('addsection'),
531 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
532 );
533 }
534 } else {
535 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
536 $content_actions['viewsource'] = array(
537 'class' => ($action == 'edit') ? 'selected' : false,
538 'text' => wfMsg('viewsource'),
539 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
540 );
541 }
542 wfProfileOut( "$fname-edit" );
543
544 wfProfileIn( "$fname-live" );
545 if ( $this->mTitle->getArticleId() ) {
546
547 $content_actions['history'] = array(
548 'class' => ($action == 'history') ? 'selected' : false,
549 'text' => wfMsg('history_short'),
550 'href' => $this->mTitle->getLocalUrl( 'action=history')
551 );
552
553 if($wgUser->isAllowed('protect')){
554 if(!$this->mTitle->isProtected()){
555 $content_actions['protect'] = array(
556 'class' => ($action == 'protect') ? 'selected' : false,
557 'text' => wfMsg('protect'),
558 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
559 );
560
561 } else {
562 $content_actions['unprotect'] = array(
563 'class' => ($action == 'unprotect') ? 'selected' : false,
564 'text' => wfMsg('unprotect'),
565 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
566 );
567 }
568 }
569 if($wgUser->isAllowed('delete')){
570 $content_actions['delete'] = array(
571 'class' => ($action == 'delete') ? 'selected' : false,
572 'text' => wfMsg('delete'),
573 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
574 );
575 }
576 if ( $wgUser->getID() != 0 ) {
577 if ( $this->mTitle->userCanMove()) {
578 $content_actions['move'] = array(
579 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
580 'text' => wfMsg('move'),
581 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ) )
582 );
583 }
584 }
585 } else {
586 //article doesn't exist or is deleted
587 if($wgUser->isAllowed('delete')){
588 if( $n = $this->mTitle->isDeleted() ) {
589 $content_actions['undelete'] = array(
590 'class' => false,
591 'text' => wfMsg( "undelete_short", $n ),
592 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
593 );
594 }
595 }
596 }
597 wfProfileOut( "$fname-live" );
598
599 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
600 if( !$this->mTitle->userIsWatching()) {
601 $content_actions['watch'] = array(
602 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
603 'text' => wfMsg('watch'),
604 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
605 );
606 } else {
607 $content_actions['unwatch'] = array(
608 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
609 'text' => wfMsg('unwatch'),
610 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
611 );
612 }
613 }
614
615 } else {
616 /* show special page tab */
617
618 $content_actions['article'] = array(
619 'class' => 'selected',
620 'text' => wfMsg('specialpage'),
621 'href' => false
622 );
623 }
624
625 /* show links to different language variants */
626 global $wgDisableLangConversion;
627 $variants = $wgContLang->getVariants();
628 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
629 $preferred = $wgContLang->getPreferredVariant();
630 $actstr = '';
631 if( $action )
632 $actstr = 'action=' . $action . '&';
633 $vcount=0;
634 foreach( $variants as $code ) {
635 $varname = $wgContLang->getVariantname( $code );
636 if( $varname == 'disable' )
637 continue;
638 $selected = ( $code == $preferred )? 'selected' : false;
639 $content_actions['varlang-' . $vcount] = array(
640 'class' => $selected,
641 'text' => $varname,
642 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
643 );
644 $vcount ++;
645 }
646 }
647
648 wfProfileOut( $fname );
649 return $content_actions;
650 }
651
652 /**
653 * build array of global navigation links
654 * @return array
655 * @access private
656 */
657 function buildNavigationUrls () {
658 $fname = 'SkinTemplate::buildNavigationUrls';
659 wfProfileIn( $fname );
660
661 global $wgNavigationLinks;
662 $result = array();
663 foreach ( $wgNavigationLinks as $link ) {
664 $text = wfMsg( $link['text'] );
665 wfProfileIn( "$fname-{$link['text']}" );
666 if ($text != '-') {
667 $dest = wfMsgForContent( $link['href'] );
668 wfProfileIn( "$fname-{$link['text']}2" );
669 $result[] = array(
670 'text' => $text,
671 'href' => $this->makeInternalOrExternalUrl( $dest ),
672 'id' => 'n-'.$link['text']
673 );
674 wfProfileOut( "$fname-{$link['text']}2" );
675 }
676 wfProfileOut( "$fname-{$link['text']}" );
677 }
678 wfProfileOut( $fname );
679 return $result;
680 }
681
682 /**
683 * build array of common navigation links
684 * @return array
685 * @access private
686 */
687 function buildNavUrls () {
688 $fname = 'SkinTemplate::buildNavUrls';
689 wfProfileIn( $fname );
690
691 global $wgUser, $wgRequest;
692 global $wgSiteSupportPage, $wgDisableUploads;
693
694 $action = $wgRequest->getText( 'action' );
695 $oldid = $wgRequest->getVal( 'oldid' );
696 $diff = $wgRequest->getVal( 'diff' );
697
698 $nav_urls = array();
699 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
700 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
701 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
702 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
703 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
704 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
705 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
706 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
707 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
708 if( $this->loggedin && !$wgDisableUploads ) {
709 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
710 } else {
711 $nav_urls['upload'] = false;
712 }
713 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
714
715 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
716 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
717 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
718 }
719
720 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
721 $id = User::idFromName($this->mTitle->getText());
722 $ip = User::isIP($this->mTitle->getText());
723 } else {
724 $id = 0;
725 $ip = false;
726 }
727
728 if($id || $ip) { # both anons and non-anons have contri list
729 $nav_urls['contributions'] = array(
730 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle->getPartialURL() )
731 );
732 } else {
733 $nav_urls['contributions'] = false;
734 }
735 $nav_urls['emailuser'] = false;
736 if( $this->showEmailUser( $id ) ) {
737 $nav_urls['emailuser'] = array(
738 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle->getPartialURL() )
739 );
740 }
741 wfProfileOut( $fname );
742 return $nav_urls;
743 }
744
745 /**
746 * Generate strings used for xml 'id' names
747 * @return string
748 * @private
749 */
750 function getNameSpaceKey () {
751 switch ($this->mTitle->getNamespace()) {
752 case NS_MAIN:
753 case NS_TALK:
754 return 'nstab-main';
755 case NS_USER:
756 case NS_USER_TALK:
757 return 'nstab-user';
758 case NS_MEDIA:
759 return 'nstab-media';
760 case NS_SPECIAL:
761 return 'nstab-special';
762 case NS_PROJECT:
763 case NS_PROJECT_TALK:
764 return 'nstab-wp';
765 case NS_IMAGE:
766 case NS_IMAGE_TALK:
767 return 'nstab-image';
768 case NS_MEDIAWIKI:
769 case NS_MEDIAWIKI_TALK:
770 return 'nstab-mediawiki';
771 case NS_TEMPLATE:
772 case NS_TEMPLATE_TALK:
773 return 'nstab-template';
774 case NS_HELP:
775 case NS_HELP_TALK:
776 return 'nstab-help';
777 case NS_CATEGORY:
778 case NS_CATEGORY_TALK:
779 return 'nstab-category';
780 default:
781 return 'nstab-main';
782 }
783 }
784
785 /**
786 * @access private
787 */
788 function setupUserCss() {
789 $fname = 'SkinTemplate::setupUserCss';
790 wfProfileIn( $fname );
791
792 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
793
794 $sitecss = '';
795 $usercss = '';
796 $siteargs = '&maxage=' . $wgSquidMaxage;
797
798 # Add user-specific code if this is a user and we allow that kind of thing
799
800 if ( $wgAllowUserCss && $this->loggedin ) {
801 $action = $wgRequest->getText('action');
802
803 # if we're previewing the CSS page, use it
804 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
805 $siteargs = "&smaxage=0&maxage=0";
806 $usercss = $wgRequest->getText('wpTextbox1');
807 } else {
808 $usercss = '@import "' .
809 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
810 'action=raw&ctype=text/css') . '";' ."\n";
811 }
812
813 $siteargs .= '&ts=' . $wgUser->mTouched;
814 }
815
816 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
817
818 # If we use the site's dynamic CSS, throw that in, too
819 if ( $wgUseSiteCss ) {
820 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
821 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
822 }
823
824 # If we use any dynamic CSS, make a little CDATA block out of it.
825
826 if ( !empty($sitecss) || !empty($usercss) ) {
827 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
828 }
829 wfProfileOut( $fname );
830 }
831
832 /**
833 * @access private
834 */
835 function setupUserJs() {
836 $fname = 'SkinTemplate::setupUserJs';
837 wfProfileIn( $fname );
838
839 global $wgRequest, $wgAllowUserJs;
840 $action = $wgRequest->getText('action');
841
842 if( $wgAllowUserJs && $this->loggedin ) {
843 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
844 # XXX: additional security check/prompt?
845 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
846 } else {
847 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
848 }
849 }
850 wfProfileOut( $fname );
851 }
852
853 /**
854 * returns css with user-specific options
855 * @access public
856 */
857 function getUserStylesheet() {
858 $fname = 'SkinTemplate::getUserStylesheet';
859 wfProfileIn( $fname );
860
861 global $wgUser;
862 $s = "/* generated user stylesheet */\n";
863
864 if($wgUser->getID() != 0) {
865 if ( 1 == $wgUser->getOption( "underline" ) ) {
866 $s .= "a { text-decoration: underline; }\n";
867 } else {
868 $s .= "a { text-decoration: none; }\n";
869 }
870 }
871 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
872 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
873 }
874 if ( 1 == $wgUser->getOption( "justify" ) ) {
875 $s .= "#bodyContent { text-align: justify; }\n";
876 }
877 wfProfileOut( $fname );
878 return $s;
879 }
880
881 /**
882 * @access public
883 */
884 function getUserJs() {
885 $fname = 'SkinTemplate::getUserJs';
886 wfProfileIn( $fname );
887
888 global $wgUser, $wgStylePath;
889 $s = '/* generated javascript */';
890 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
891 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
892 $s .= wfMsg(ucfirst($this->skinname).'.js');
893
894 wfProfileOut( $fname );
895 return $s;
896 }
897 }
898
899 /**
900 * Generic wrapper for template functions, with interface
901 * compatible with what we use of PHPTAL 0.7.
902 * @package MediaWiki
903 * @subpackage Skins
904 */
905 class QuickTemplate {
906 /**
907 * @access public
908 */
909 function QuickTemplate() {
910 $this->data = array();
911 $this->translator = new MediaWiki_I18N();
912 }
913
914 /**
915 * @access public
916 */
917 function set( $name, $value ) {
918 $this->data[$name] = $value;
919 }
920
921 /**
922 * @access public
923 */
924 function setRef($name, &$value) {
925 $this->data[$name] =& $value;
926 }
927
928 /**
929 * @access public
930 */
931 function setTranslator( &$t ) {
932 $this->translator = &$t;
933 }
934
935 /**
936 * @access public
937 */
938 function execute() {
939 echo "Override this function.";
940 }
941
942
943 /**
944 * @access private
945 */
946 function text( $str ) {
947 echo htmlspecialchars( $this->data[$str] );
948 }
949
950 /**
951 * @access private
952 */
953 function html( $str ) {
954 echo $this->data[$str];
955 }
956
957 /**
958 * @access private
959 */
960 function msg( $str ) {
961 echo htmlspecialchars( $this->translator->translate( $str ) );
962 }
963
964 /**
965 * @access private
966 */
967 function msgHtml( $str ) {
968 echo $this->translator->translate( $str );
969 }
970
971 /**
972 * An ugly, ugly hack.
973 * @access private
974 */
975 function msgWiki( $str ) {
976 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
977
978 $text = $this->translator->translate( $str );
979 $parserOutput = $wgParser->parse( $text, $wgTitle,
980 $wgOut->mParserOptions, true );
981 echo $parserOutput->getText();
982 }
983
984 /**
985 * @access private
986 */
987 function haveData( $str ) {
988 return $this->data[$str];
989 }
990
991 /**
992 * @access private
993 */
994 function haveMsg( $str ) {
995 $msg = $this->translator->translate( $str );
996 return ($msg != '-') && ($msg != ''); # ????
997 }
998 }
999
1000 } // end of if( defined( 'MEDIAWIKI' ) )
1001 ?>