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