* (bug 2064) Configurable JavaScript mimetype with $wgJsMimeType
[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( 'navigation_urls', $this->buildNavigationUrls() );
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','target=' . urlencode( $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;
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', 'target='. urlencode( $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 # Validate tab. TODO: add validation to logged-in user rights
646 if($wgUseValidation && ( $action == "" || $action=='view' ) ){ # && $wgUser->isAllowed('validate')){
647 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
648 else
649 {# Trying to get the current article revision through this weird stunt
650 $tid = $this->mTitle->getArticleID();
651 $tns = $this->mTitle->getNamespace();
652 $sql = "SELECT page_latest FROM page WHERE page_id={$tid} AND page_namespace={$tns}" ;
653 $res = wfQuery( $sql, DB_READ );
654 if( $s = wfFetchObject( $res ) )
655 $oid = $s->page_latest ;
656 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
657 }
658 if ( $oid != "" ) {
659 $oid = "&revision={$oid}" ;
660 $content_actions['validate'] = array(
661 'class' => ($action == 'validate') ? 'selected' : false,
662 'text' => wfMsg('val_tab'),
663 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
664 );
665 }
666 }
667 }
668 } else {
669 /* show special page tab */
670
671 $content_actions['article'] = array(
672 'class' => 'selected',
673 'text' => wfMsg('specialpage'),
674 'href' => false
675 );
676 }
677
678 /* show links to different language variants */
679 global $wgDisableLangConversion;
680 $variants = $wgContLang->getVariants();
681 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
682 $preferred = $wgContLang->getPreferredVariant();
683 $actstr = '';
684 if( $action )
685 $actstr = 'action=' . $action . '&';
686 $vcount=0;
687 foreach( $variants as $code ) {
688 $varname = $wgContLang->getVariantname( $code );
689 if( $varname == 'disable' )
690 continue;
691 $selected = ( $code == $preferred )? 'selected' : false;
692 $content_actions['varlang-' . $vcount] = array(
693 'class' => $selected,
694 'text' => $varname,
695 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
696 );
697 $vcount ++;
698 }
699 }
700
701 wfProfileOut( $fname );
702 return $content_actions;
703 }
704
705 function getNavigationLinks() {
706 global $wgNavigationLinks;
707 return $wgNavigationLinks;
708 }
709
710 /**
711 * build array of global navigation links
712 * @return array
713 * @access private
714 */
715 function buildNavigationUrls () {
716 $fname = 'SkinTemplate::buildNavigationUrls';
717 wfProfileIn( $fname );
718
719 $links = $this->getNavigationLinks();
720
721 $result = array();
722 foreach ( $links as $link ) {
723 $text = wfMsg( $link['text'] );
724 wfProfileIn( "$fname-{$link['text']}" );
725 if ($text != '-') {
726 $dest = wfMsgForContent( $link['href'] );
727 wfProfileIn( "$fname-{$link['text']}2" );
728 $result[] = array(
729 'text' => $text,
730 'href' => $this->makeInternalOrExternalUrl( $dest ),
731 'id' => 'n-'.$link['text']
732 );
733 wfProfileOut( "$fname-{$link['text']}2" );
734 }
735 wfProfileOut( "$fname-{$link['text']}" );
736 }
737 wfProfileOut( $fname );
738 return $result;
739 }
740
741 /**
742 * build array of common navigation links
743 * @return array
744 * @access private
745 */
746 function buildNavUrls () {
747 $fname = 'SkinTemplate::buildNavUrls';
748 wfProfileIn( $fname );
749
750 global $wgUser, $wgRequest;
751 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
752
753 $action = $wgRequest->getText( 'action' );
754 $oldid = $wgRequest->getVal( 'oldid' );
755 $diff = $wgRequest->getVal( 'diff' );
756
757 $nav_urls = array();
758 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
759 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
760 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
761 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
762 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
763 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
764 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
765 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
766 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
767 if( $wgEnableUploads ) {
768 if ($wgUploadNavigationUrl) {
769 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
770 } else {
771 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
772 }
773 } else {
774 $nav_urls['upload'] = false;
775 }
776 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
777
778 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
779 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
780 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
781 }
782
783 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
784 $id = User::idFromName($this->mTitle->getText());
785 $ip = User::isIP($this->mTitle->getText());
786 } else {
787 $id = 0;
788 $ip = false;
789 }
790
791 if($id || $ip) { # both anons and non-anons have contri list
792 $nav_urls['contributions'] = array(
793 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle->getPartialURL() )
794 );
795 } else {
796 $nav_urls['contributions'] = false;
797 }
798 $nav_urls['emailuser'] = false;
799 if( $this->showEmailUser( $id ) ) {
800 $nav_urls['emailuser'] = array(
801 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle->getPartialURL() )
802 );
803 }
804 wfProfileOut( $fname );
805 return $nav_urls;
806 }
807
808 /**
809 * Generate strings used for xml 'id' names
810 * @return string
811 * @private
812 */
813 function getNameSpaceKey () {
814 switch ($this->mTitle->getNamespace()) {
815 case NS_MAIN:
816 case NS_TALK:
817 return 'nstab-main';
818 case NS_USER:
819 case NS_USER_TALK:
820 return 'nstab-user';
821 case NS_MEDIA:
822 return 'nstab-media';
823 case NS_SPECIAL:
824 return 'nstab-special';
825 case NS_PROJECT:
826 case NS_PROJECT_TALK:
827 return 'nstab-wp';
828 case NS_IMAGE:
829 case NS_IMAGE_TALK:
830 return 'nstab-image';
831 case NS_MEDIAWIKI:
832 case NS_MEDIAWIKI_TALK:
833 return 'nstab-mediawiki';
834 case NS_TEMPLATE:
835 case NS_TEMPLATE_TALK:
836 return 'nstab-template';
837 case NS_HELP:
838 case NS_HELP_TALK:
839 return 'nstab-help';
840 case NS_CATEGORY:
841 case NS_CATEGORY_TALK:
842 return 'nstab-category';
843 default:
844 return 'nstab-main';
845 }
846 }
847
848 /**
849 * @access private
850 */
851 function setupUserCss() {
852 $fname = 'SkinTemplate::setupUserCss';
853 wfProfileIn( $fname );
854
855 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
856
857 $sitecss = '';
858 $usercss = '';
859 $siteargs = '&maxage=' . $wgSquidMaxage;
860
861 # Add user-specific code if this is a user and we allow that kind of thing
862
863 if ( $wgAllowUserCss && $this->loggedin ) {
864 $action = $wgRequest->getText('action');
865
866 # if we're previewing the CSS page, use it
867 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
868 $siteargs = "&smaxage=0&maxage=0";
869 $usercss = $wgRequest->getText('wpTextbox1');
870 } else {
871 $usercss = '@import "' .
872 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
873 'action=raw&ctype=text/css') . '";' ."\n";
874 }
875
876 $siteargs .= '&ts=' . $wgUser->mTouched;
877 }
878
879 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
880
881 # If we use the site's dynamic CSS, throw that in, too
882 if ( $wgUseSiteCss ) {
883 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
884 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
885 }
886
887 # If we use any dynamic CSS, make a little CDATA block out of it.
888
889 if ( !empty($sitecss) || !empty($usercss) ) {
890 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
891 }
892 wfProfileOut( $fname );
893 }
894
895 /**
896 * @access private
897 */
898 function setupUserJs() {
899 $fname = 'SkinTemplate::setupUserJs';
900 wfProfileIn( $fname );
901
902 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
903 $action = $wgRequest->getText('action');
904
905 if( $wgAllowUserJs && $this->loggedin ) {
906 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
907 # XXX: additional security check/prompt?
908 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
909 } else {
910 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
911 }
912 }
913 wfProfileOut( $fname );
914 }
915
916 /**
917 * returns css with user-specific options
918 * @access public
919 */
920
921 function getUserStylesheet() {
922 $fname = 'SkinTemplate::getUserStylesheet';
923 wfProfileIn( $fname );
924
925 global $wgUser;
926 $s = "/* generated user stylesheet */\n";
927 $s .= $this->reallyDoGetUserStyles();
928 wfProfileOut( $fname );
929 return $s;
930 }
931
932 /**
933 * @access public
934 */
935 function getUserJs() {
936 $fname = 'SkinTemplate::getUserJs';
937 wfProfileIn( $fname );
938
939 global $wgStylePath;
940 $s = '/* generated javascript */';
941 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
942 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
943
944 // avoid inclusion of non defined user JavaScript (with custom skins only)
945 // by checking for default message content
946 $msgKey = ucfirst($this->skinname).'.js';
947 $userJS = wfMsg($msgKey);
948 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
949 $s .= $userJS;
950 }
951
952 wfProfileOut( $fname );
953 return $s;
954 }
955 }
956
957 /**
958 * Generic wrapper for template functions, with interface
959 * compatible with what we use of PHPTAL 0.7.
960 * @package MediaWiki
961 * @subpackage Skins
962 */
963 class QuickTemplate {
964 /**
965 * @access public
966 */
967 function QuickTemplate() {
968 $this->data = array();
969 $this->translator = new MediaWiki_I18N();
970 }
971
972 /**
973 * @access public
974 */
975 function set( $name, $value ) {
976 $this->data[$name] = $value;
977 }
978
979 /**
980 * @access public
981 */
982 function setRef($name, &$value) {
983 $this->data[$name] =& $value;
984 }
985
986 /**
987 * @access public
988 */
989 function setTranslator( &$t ) {
990 $this->translator = &$t;
991 }
992
993 /**
994 * @access public
995 */
996 function execute() {
997 echo "Override this function.";
998 }
999
1000
1001 /**
1002 * @access private
1003 */
1004 function text( $str ) {
1005 echo htmlspecialchars( $this->data[$str] );
1006 }
1007
1008 /**
1009 * @access private
1010 */
1011 function html( $str ) {
1012 echo $this->data[$str];
1013 }
1014
1015 /**
1016 * @access private
1017 */
1018 function msg( $str ) {
1019 echo htmlspecialchars( $this->translator->translate( $str ) );
1020 }
1021
1022 /**
1023 * @access private
1024 */
1025 function msgHtml( $str ) {
1026 echo $this->translator->translate( $str );
1027 }
1028
1029 /**
1030 * An ugly, ugly hack.
1031 * @access private
1032 */
1033 function msgWiki( $str ) {
1034 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1035
1036 $text = $this->translator->translate( $str );
1037 $parserOutput = $wgParser->parse( $text, $wgTitle,
1038 $wgOut->mParserOptions, true );
1039 echo $parserOutput->getText();
1040 }
1041
1042 /**
1043 * @access private
1044 */
1045 function haveData( $str ) {
1046 return $this->data[$str];
1047 }
1048
1049 /**
1050 * @access private
1051 */
1052 function haveMsg( $str ) {
1053 $msg = $this->translator->translate( $str );
1054 return ($msg != '-') && ($msg != ''); # ????
1055 }
1056 }
1057
1058 } // end of if( defined( 'MEDIAWIKI' ) )
1059 ?>