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