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