12029c6f6df79bf41fc340eb911bfa92a9cc6137
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 *
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
26 *
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42
43 /**
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
46 *
47 * @access private
48 * @package MediaWiki
49 */
50 class MediaWiki_I18N {
51 var $_context = array();
52
53 function set($varName, $value) {
54 $this->_context[$varName] = $value;
55 }
56
57 function translate($value) {
58 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
60
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
63
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
68 wfSuppressWarnings();
69 $varValue = $this->_context[$var];
70 wfRestoreWarnings();
71 $value = str_replace($src, $varValue, $value);
72 }
73 wfProfileOut( $fname );
74 return $value;
75 }
76 }
77
78 /**
79 *
80 * @package MediaWiki
81 */
82 class SkinTemplate extends Skin {
83 /**#@+
84 * @access private
85 */
86
87 /**
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
90 */
91 var $skinname;
92
93 /**
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
96 */
97 var $stylename;
98
99 /**
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
102 *
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /**
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
114 *
115 * @param OutputPage $out
116 */
117 function initPage( &$out ) {
118 parent::initPage( $out );
119 $this->skinname = 'monobook';
120 $this->stylename = 'monobook';
121 $this->template = 'QuickTemplate';
122 }
123
124 /**
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
128 *
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
132 * @return object
133 * @access private
134 */
135 function &setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
137 }
138
139 /**
140 * initialize various variables and generate the template
141 *
142 * @param OutputPage $out
143 * @access public
144 */
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
155
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
160
161 $this->mTitle = $wgTitle;
162 $this->mUser =& $wgUser;
163
164 $tpl =& $this->setupTemplate( $this->template, 'skins' );
165
166 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
167 $tpl->setTranslator(new MediaWiki_I18N());
168 #}
169 wfProfileOut( "$fname-init" );
170
171 wfProfileIn( "$fname-stuff" );
172 $this->thispage = $this->mTitle->getPrefixedDbKey();
173 $this->thisurl = $this->mTitle->getPrefixedURL();
174 $this->loggedin = $wgUser->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', $wgSiteNotice );
348 $tpl->set( 'tagline', wfMsg('tagline') );
349
350 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
351 $out->mBodytext .= $printfooter ;
352 $tpl->setRef( 'bodytext', $out->mBodytext );
353
354 # Language links
355 $language_urls = array();
356 foreach( $wgOut->getLanguageLinks() as $l ) {
357 $nt = Title::newFromText( $l );
358 $language_urls[] = array('href' => $nt->getFullURL(),
359 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
360 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
361 }
362 if(count($language_urls)) {
363 $tpl->setRef( 'language_urls', $language_urls);
364 } else {
365 $tpl->set('language_urls', false);
366 }
367 wfProfileOut( "$fname-stuff4" );
368
369 # Personal toolbar
370 $tpl->set('personal_urls', $this->buildPersonalUrls());
371 $content_actions = $this->buildContentActionUrls();
372 $tpl->setRef('content_actions', $content_actions);
373
374 // XXX: attach this from javascript, same with section editing
375 if($this->iseditable && $wgUser->getOption("editondblclick") )
376 {
377 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
378 } else {
379 $tpl->set('body_ondblclick', false);
380 }
381 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
382 $tpl->set( 'nav_urls', $this->buildNavUrls() );
383
384 // execute template
385 wfProfileIn( "$fname-execute" );
386 $res = $tpl->execute();
387 wfProfileOut( "$fname-execute" );
388
389 // result may be an error
390 $this->printOrError( $res );
391 wfProfileOut( $fname );
392 }
393
394 /**
395 * Output the string, or print error message if it's
396 * an error object of the appropriate type.
397 * For the base class, assume strings all around.
398 *
399 * @param mixed $str
400 * @access private
401 */
402 function printOrError( &$str ) {
403 echo $str;
404 }
405
406 /**
407 * build array of urls for personal toolbar
408 * @return array
409 * @access private
410 */
411 function buildPersonalUrls() {
412 $fname = 'SkinTemplate::buildPersonalUrls';
413 wfProfileIn( $fname );
414
415 /* set up the default links for the personal toolbar */
416 global $wgShowIPinHeader;
417 $personal_urls = array();
418 if ($this->loggedin) {
419 /* Logged in users personal toolbar */
420 $personal_urls['userpage'] = array(
421 'text' => wfMsg('mypage'),
422 'href' => $this->makeSpecialUrl('Mypage')
423 );
424 $personal_urls['mytalk'] = array(
425 'text' => wfMsg('mytalk'),
426 'href' => $this->makeSpecialUrl('Mytalk')
427 );
428 $personal_urls['preferences'] = array(
429 'text' => wfMsg('preferences'),
430 'href' => $this->makeSpecialUrl('Preferences')
431 );
432 $personal_urls['watchlist'] = array(
433 'text' => wfMsg('watchlist'),
434 'href' => $this->makeSpecialUrl('Watchlist')
435 );
436 $personal_urls['mycontris'] = array(
437 'text' => wfMsg('mycontris'),
438 'href' => $this->makeSpecialUrl('Mycontributions')
439 );
440 $personal_urls['logout'] = array(
441 'text' => wfMsg('userlogout'),
442 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
443 );
444 } else {
445 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
446 /* Anonymous with session users personal toolbar */
447 $personal_urls['anonuserpage'] = array(
448 'text' => wfMsg('mypage'),
449 'href' => $this->makeSpecialUrl('Mypage')
450 );
451 $personal_urls['mytalk'] = array(
452 'text' => wfMsg('mytalk'),
453 'href' => $this->makeSpecialUrl('Mytalk')
454 );
455
456 $personal_urls['anonlogin'] = array(
457 'text' => wfMsg('userlogin'),
458 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
459 );
460 } else {
461 /* Anonymous users personal toolbar */
462 $personal_urls['login'] = array(
463 'text' => wfMsg('userlogin'),
464 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
465 );
466 }
467 }
468 wfProfileOut( $fname );
469 return $personal_urls;
470 }
471
472
473 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
474 $classes = array();
475 if( $selected ) {
476 $classes[] = 'selected';
477 }
478 if( $checkEdit && $title->getArticleId() == 0 ) {
479 $classes[] = 'new';
480 }
481 return array(
482 'class' => implode( ' ', $classes ),
483 'text' => wfMsg( $message ),
484 'href' => $title->getLocalUrl( $query ) );
485 }
486
487 /**
488 * an array of edit links by default used for the tabs
489 * @return array
490 * @access private
491 */
492 function buildContentActionUrls () {
493 global $wgContLang, $wgUseValidation;
494 $fname = 'SkinTemplate::buildContentActionUrls';
495 wfProfileIn( $fname );
496
497 global $wgUser, $wgRequest;
498 $action = $wgRequest->getText( 'action' );
499 $section = $wgRequest->getText( 'section' );
500 $oldid = $wgRequest->getVal( 'oldid' );
501 $diff = $wgRequest->getVal( 'diff' );
502 $content_actions = array();
503
504 if( $this->iscontent ) {
505
506 $nskey = $this->getNameSpaceKey();
507 $content_actions[$nskey] = $this->tabAction(
508 $this->mTitle->getSubjectPage(),
509 $nskey,
510 !$this->mTitle->isTalkPage() );
511
512 $content_actions['talk'] = $this->tabAction(
513 $this->mTitle->getTalkPage(),
514 'talk',
515 $this->mTitle->isTalkPage(),
516 '',
517 true);
518
519 wfProfileIn( "$fname-edit" );
520 if ( $this->mTitle->userCanEdit() ) {
521 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
522 $istalk = $this->mTitle->isTalkPage();
523 $istalkclass = $istalk?' istalk':'';
524 $content_actions['edit'] = array(
525 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
526 'text' => wfMsg('edit'),
527 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
528 );
529
530 if ( $istalk ) {
531 $content_actions['addsection'] = array(
532 'class' => $section == 'new'?'selected':false,
533 'text' => wfMsg('addsection'),
534 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
535 );
536 }
537 } else {
538 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
539 $content_actions['viewsource'] = array(
540 'class' => ($action == 'edit') ? 'selected' : false,
541 'text' => wfMsg('viewsource'),
542 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
543 );
544 }
545 wfProfileOut( "$fname-edit" );
546
547 wfProfileIn( "$fname-live" );
548 if ( $this->mTitle->getArticleId() ) {
549
550 $content_actions['history'] = array(
551 'class' => ($action == 'history') ? 'selected' : false,
552 'text' => wfMsg('history_short'),
553 'href' => $this->mTitle->getLocalUrl( 'action=history')
554 );
555
556 if($wgUser->isAllowed('protect')){
557 if(!$this->mTitle->isProtected()){
558 $content_actions['protect'] = array(
559 'class' => ($action == 'protect') ? 'selected' : false,
560 'text' => wfMsg('protect'),
561 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
562 );
563
564 } else {
565 $content_actions['unprotect'] = array(
566 'class' => ($action == 'unprotect') ? 'selected' : false,
567 'text' => wfMsg('unprotect'),
568 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
569 );
570 }
571 }
572 if($wgUser->isAllowed('delete')){
573 $content_actions['delete'] = array(
574 'class' => ($action == 'delete') ? 'selected' : false,
575 'text' => wfMsg('delete'),
576 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
577 );
578 }
579 if ( $wgUser->isLoggedIn() ) {
580 if ( $this->mTitle->userCanMove()) {
581 $content_actions['move'] = array(
582 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
583 'text' => wfMsg('move'),
584 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ) )
585 );
586 }
587 }
588 } else {
589 //article doesn't exist or is deleted
590 if($wgUser->isAllowed('delete')){
591 if( $n = $this->mTitle->isDeleted() ) {
592 $content_actions['undelete'] = array(
593 'class' => false,
594 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
595 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
596 );
597 }
598 }
599 }
600 wfProfileOut( "$fname-live" );
601
602 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
603 if( !$this->mTitle->userIsWatching()) {
604 $content_actions['watch'] = array(
605 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
606 'text' => wfMsg('watch'),
607 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
608 );
609 } else {
610 $content_actions['unwatch'] = array(
611 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
612 'text' => wfMsg('unwatch'),
613 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
614 );
615 }
616
617 # Validate tab. TODO: add validation to logged-in user rights
618 if($wgUseValidation && $action=='view'){ # && $wgUser->isAllowed('validate')){
619 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
620 else
621 {# Trying to get the current article revision through this weird stunt
622 $tid = $this->mTitle->getArticleID();
623 $tns = $this->mTitle->getNamespace();
624 $sql = "SELECT page_latest FROM page WHERE page_id={$tid} AND page_namespace={$tns}" ;
625 $res = wfQuery( $sql, DB_READ );
626 if( $s = wfFetchObject( $res ) )
627 $oid = $s->page_latest ;
628 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
629 }
630 if ( $oid != "" ) {
631 $oid = "&revision={$oid}" ;
632 $content_actions['validate'] = array(
633 'class' => ($action == 'validate') ? 'selected' : false,
634 'text' => wfMsg('val_tab'),
635 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
636 );
637 }
638 }
639 }
640 } else {
641 /* show special page tab */
642
643 $content_actions['article'] = array(
644 'class' => 'selected',
645 'text' => wfMsg('specialpage'),
646 'href' => false
647 );
648 }
649
650 /* show links to different language variants */
651 global $wgDisableLangConversion;
652 $variants = $wgContLang->getVariants();
653 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
654 $preferred = $wgContLang->getPreferredVariant();
655 $actstr = '';
656 if( $action )
657 $actstr = 'action=' . $action . '&';
658 $vcount=0;
659 foreach( $variants as $code ) {
660 $varname = $wgContLang->getVariantname( $code );
661 if( $varname == 'disable' )
662 continue;
663 $selected = ( $code == $preferred )? 'selected' : false;
664 $content_actions['varlang-' . $vcount] = array(
665 'class' => $selected,
666 'text' => $varname,
667 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
668 );
669 $vcount ++;
670 }
671 }
672
673 wfProfileOut( $fname );
674 return $content_actions;
675 }
676
677 /**
678 * build array of global navigation links
679 * @return array
680 * @access private
681 */
682 function buildNavigationUrls () {
683 $fname = 'SkinTemplate::buildNavigationUrls';
684 wfProfileIn( $fname );
685
686 global $wgNavigationLinks;
687 $result = array();
688 foreach ( $wgNavigationLinks as $link ) {
689 $text = wfMsg( $link['text'] );
690 wfProfileIn( "$fname-{$link['text']}" );
691 if ($text != '-') {
692 $dest = wfMsgForContent( $link['href'] );
693 wfProfileIn( "$fname-{$link['text']}2" );
694 $result[] = array(
695 'text' => $text,
696 'href' => $this->makeInternalOrExternalUrl( $dest ),
697 'id' => 'n-'.$link['text']
698 );
699 wfProfileOut( "$fname-{$link['text']}2" );
700 }
701 wfProfileOut( "$fname-{$link['text']}" );
702 }
703 wfProfileOut( $fname );
704 return $result;
705 }
706
707 /**
708 * build array of common navigation links
709 * @return array
710 * @access private
711 */
712 function buildNavUrls () {
713 $fname = 'SkinTemplate::buildNavUrls';
714 wfProfileIn( $fname );
715
716 global $wgUser, $wgRequest;
717 global $wgSiteSupportPage, $wgDisableUploads;
718
719 $action = $wgRequest->getText( 'action' );
720 $oldid = $wgRequest->getVal( 'oldid' );
721 $diff = $wgRequest->getVal( 'diff' );
722
723 $nav_urls = array();
724 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
725 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
726 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
727 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
728 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
729 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
730 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
731 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
732 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
733 if( $this->loggedin && !$wgDisableUploads ) {
734 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
735 } else {
736 $nav_urls['upload'] = false;
737 }
738 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
739
740 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
741 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
742 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
743 }
744
745 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
746 $id = User::idFromName($this->mTitle->getText());
747 $ip = User::isIP($this->mTitle->getText());
748 } else {
749 $id = 0;
750 $ip = false;
751 }
752
753 if($id || $ip) { # both anons and non-anons have contri list
754 $nav_urls['contributions'] = array(
755 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle->getPartialURL() )
756 );
757 } else {
758 $nav_urls['contributions'] = false;
759 }
760 $nav_urls['emailuser'] = false;
761 if( $this->showEmailUser( $id ) ) {
762 $nav_urls['emailuser'] = array(
763 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle->getPartialURL() )
764 );
765 }
766 wfProfileOut( $fname );
767 return $nav_urls;
768 }
769
770 /**
771 * Generate strings used for xml 'id' names
772 * @return string
773 * @private
774 */
775 function getNameSpaceKey () {
776 switch ($this->mTitle->getNamespace()) {
777 case NS_MAIN:
778 case NS_TALK:
779 return 'nstab-main';
780 case NS_USER:
781 case NS_USER_TALK:
782 return 'nstab-user';
783 case NS_MEDIA:
784 return 'nstab-media';
785 case NS_SPECIAL:
786 return 'nstab-special';
787 case NS_PROJECT:
788 case NS_PROJECT_TALK:
789 return 'nstab-wp';
790 case NS_IMAGE:
791 case NS_IMAGE_TALK:
792 return 'nstab-image';
793 case NS_MEDIAWIKI:
794 case NS_MEDIAWIKI_TALK:
795 return 'nstab-mediawiki';
796 case NS_TEMPLATE:
797 case NS_TEMPLATE_TALK:
798 return 'nstab-template';
799 case NS_HELP:
800 case NS_HELP_TALK:
801 return 'nstab-help';
802 case NS_CATEGORY:
803 case NS_CATEGORY_TALK:
804 return 'nstab-category';
805 default:
806 return 'nstab-main';
807 }
808 }
809
810 /**
811 * @access private
812 */
813 function setupUserCss() {
814 $fname = 'SkinTemplate::setupUserCss';
815 wfProfileIn( $fname );
816
817 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
818
819 $sitecss = '';
820 $usercss = '';
821 $siteargs = '&maxage=' . $wgSquidMaxage;
822
823 # Add user-specific code if this is a user and we allow that kind of thing
824
825 if ( $wgAllowUserCss && $this->loggedin ) {
826 $action = $wgRequest->getText('action');
827
828 # if we're previewing the CSS page, use it
829 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
830 $siteargs = "&smaxage=0&maxage=0";
831 $usercss = $wgRequest->getText('wpTextbox1');
832 } else {
833 $usercss = '@import "' .
834 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
835 'action=raw&ctype=text/css') . '";' ."\n";
836 }
837
838 $siteargs .= '&ts=' . $wgUser->mTouched;
839 }
840
841 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
842
843 # If we use the site's dynamic CSS, throw that in, too
844 if ( $wgUseSiteCss ) {
845 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
846 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
847 }
848
849 # If we use any dynamic CSS, make a little CDATA block out of it.
850
851 if ( !empty($sitecss) || !empty($usercss) ) {
852 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
853 }
854 wfProfileOut( $fname );
855 }
856
857 /**
858 * @access private
859 */
860 function setupUserJs() {
861 $fname = 'SkinTemplate::setupUserJs';
862 wfProfileIn( $fname );
863
864 global $wgRequest, $wgAllowUserJs;
865 $action = $wgRequest->getText('action');
866
867 if( $wgAllowUserJs && $this->loggedin ) {
868 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
869 # XXX: additional security check/prompt?
870 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
871 } else {
872 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
873 }
874 }
875 wfProfileOut( $fname );
876 }
877
878 /**
879 * returns css with user-specific options
880 * @access public
881 */
882
883 function getUserStylesheet() {
884 $fname = 'SkinTemplate::getUserStylesheet';
885 wfProfileIn( $fname );
886
887 global $wgUser;
888 $s = "/* generated user stylesheet */\n";
889 $s .= $this->reallyDoGetUserStyles();
890 wfProfileOut( $fname );
891 return $s;
892 }
893
894 /**
895 * @access public
896 */
897 function getUserJs() {
898 $fname = 'SkinTemplate::getUserJs';
899 wfProfileIn( $fname );
900
901 global $wgStylePath;
902 $s = '/* generated javascript */';
903 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
904 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
905 $s .= wfMsg(ucfirst($this->skinname).'.js');
906
907 wfProfileOut( $fname );
908 return $s;
909 }
910 }
911
912 /**
913 * Generic wrapper for template functions, with interface
914 * compatible with what we use of PHPTAL 0.7.
915 * @package MediaWiki
916 * @subpackage Skins
917 */
918 class QuickTemplate {
919 /**
920 * @access public
921 */
922 function QuickTemplate() {
923 $this->data = array();
924 $this->translator = new MediaWiki_I18N();
925 }
926
927 /**
928 * @access public
929 */
930 function set( $name, $value ) {
931 $this->data[$name] = $value;
932 }
933
934 /**
935 * @access public
936 */
937 function setRef($name, &$value) {
938 $this->data[$name] =& $value;
939 }
940
941 /**
942 * @access public
943 */
944 function setTranslator( &$t ) {
945 $this->translator = &$t;
946 }
947
948 /**
949 * @access public
950 */
951 function execute() {
952 echo "Override this function.";
953 }
954
955
956 /**
957 * @access private
958 */
959 function text( $str ) {
960 echo htmlspecialchars( $this->data[$str] );
961 }
962
963 /**
964 * @access private
965 */
966 function html( $str ) {
967 echo $this->data[$str];
968 }
969
970 /**
971 * @access private
972 */
973 function msg( $str ) {
974 echo htmlspecialchars( $this->translator->translate( $str ) );
975 }
976
977 /**
978 * @access private
979 */
980 function msgHtml( $str ) {
981 echo $this->translator->translate( $str );
982 }
983
984 /**
985 * An ugly, ugly hack.
986 * @access private
987 */
988 function msgWiki( $str ) {
989 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
990
991 $text = $this->translator->translate( $str );
992 $parserOutput = $wgParser->parse( $text, $wgTitle,
993 $wgOut->mParserOptions, true );
994 echo $parserOutput->getText();
995 }
996
997 /**
998 * @access private
999 */
1000 function haveData( $str ) {
1001 return $this->data[$str];
1002 }
1003
1004 /**
1005 * @access private
1006 */
1007 function haveMsg( $str ) {
1008 $msg = $this->translator->translate( $str );
1009 return ($msg != '-') && ($msg != ''); # ????
1010 }
1011 }
1012
1013 } // end of if( defined( 'MEDIAWIKI' ) )
1014 ?>