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