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