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