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