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