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