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