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