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