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