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.
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.
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
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/
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.
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.
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
39 if( defined( 'MEDIAWIKI' ) ) {
41 require_once 'GlobalFunctions.php';
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
50 class MediaWiki_I18N
{
51 var $_context = array();
53 function set($varName, $value) {
54 $this->_context
[$varName] = $value;
57 function translate($value) {
58 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
59 $value = preg_replace( '/^string:/', '', $value );
61 $value = wfMsg( $value );
62 // interpolate variables
63 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
64 list($src, $var) = $m;
66 $varValue = $this->_context
[$var];
68 $value = str_replace($src, $varValue, $value);
78 class SkinTemplate
extends Skin
{
84 * Name of our skin, set in initPage()
85 * It probably need to be all lower case.
90 * Stylesheets set to use
91 * Sub directory in ./skins/ where various stylesheets are located
96 * For QuickTemplate, name or reference to callback function which
97 * will actually fill the template.
99 * In PHPTal mode, name of PHPTal template to be used.
100 * '.pt' will be automaticly added to it on PHPTAL object creation
107 * Setup the base parameters...
108 * Child classes should override this to set the name,
109 * style subdirectory, and template filler callback.
111 * @param OutputPage $out
113 function initPage( &$out ) {
114 parent
::initPage( $out );
115 $this->skinname
= 'monobook';
116 $this->stylename
= 'monobook';
117 $this->template
= 'MonoBookTemplate';
121 * Create the template engine object; we feed it a bunch of data
122 * and eventually it spits out some HTML. Should have interface
123 * roughly equivalent to PHPTAL 0.7.
125 * @param string $callback (or file)
126 * @param string $repository subdirectory where we keep template files
127 * @param string $cache_dir
131 function &setupTemplate( $callback, $repository=false, $cache_dir=false ) {
132 return new QuickTemplate( $callback );
136 * initialize various variables and generate the template
138 * @param OutputPage $out
141 function outputPage( &$out ) {
142 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
143 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
144 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
145 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
146 global $wgMaxCredits, $wgShowCreditsIfMax;
148 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
150 $this->initPage( $out );
151 $tpl =& $this->setupTemplate( $this->template
, 'skins' );
153 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
154 $tpl->setTranslator(new MediaWiki_I18N());
157 $this->thispage
= $wgTitle->getPrefixedDbKey();
158 $this->thisurl
= $wgTitle->getPrefixedURL();
159 $this->loggedin
= $wgUser->getID() != 0;
160 $this->iscontent
= ($wgTitle->getNamespace() != Namespace::getSpecial() );
161 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
162 $this->username
= $wgUser->getName();
163 $this->userpage
= $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
164 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
166 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
167 $this->setupUserCss();
168 $this->setupUserJs();
169 $this->titletxt
= $wgTitle->getPrefixedText();
171 $tpl->set( 'title', $wgOut->getPageTitle() );
172 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
174 $tpl->setRef( "thispage", $this->thispage
);
175 $subpagestr = $this->subPageSubtitle();
177 'subtitle', !empty($subpagestr)?
178 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
181 $undelete = $this->getUndeleteLink();
183 "undelete", !empty($undelete)?
184 '<span class="subpages">'.$undelete.'</span>':
188 $tpl->set( 'catlinks', $this->getCategories());
189 if( $wgOut->isSyndicated() ) {
191 foreach( $wgFeedClasses as $format => $class ) {
192 $feeds[$format] = array(
194 'href' => $wgRequest->appendQuery( "feed=$format" ),
195 'ttip' => wfMsg('tooltip-'.$format)
198 $tpl->setRef( 'feeds', $feeds );
200 $tpl->set( 'feeds', false );
202 $tpl->setRef( 'mimetype', $wgMimeType );
203 $tpl->setRef( 'charset', $wgOutputEncoding );
204 $tpl->set( 'headlinks', $out->getHeadLinks() );
205 $tpl->setRef( 'wgScript', $wgScript );
206 $tpl->setRef( 'skinname', $this->skinname
);
207 $tpl->setRef( 'stylename', $this->stylename
);
208 $tpl->setRef( 'loggedin', $this->loggedin
);
209 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
210 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL
);
211 /* XXX currently unused, might get useful later
212 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
213 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
214 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
215 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
216 $tpl->set( "helppage", wfMsg('helppage'));
218 $tpl->set( 'searchaction', $this->escapeSearchLink() );
219 $tpl->setRef( 'stylepath', $wgStylePath );
220 $tpl->setRef( 'logopath', $wgLogo );
221 $tpl->setRef( "lang", $wgContLanguageCode );
222 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
223 $tpl->set( 'rtl', $wgContLang->isRTL() );
224 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
225 $tpl->setRef( 'username', $this->username
);
226 $tpl->setRef( 'userpage', $this->userpage
);
227 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
228 $tpl->setRef( 'usercss', $this->usercss
);
229 $tpl->setRef( 'userjs', $this->userjs
);
230 $tpl->setRef( 'userjsprev', $this->userjsprev
);
233 if($this->loggedin
) {
234 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
236 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
239 $tpl->set('jsvarurl', false);
241 if( $wgUser->getNewtalk() ) {
242 $usertitle = Title
::newFromText( $this->userpage
);
243 $usertalktitle = $usertitle->getTalkPage();
244 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
246 $ntl = wfMsg( 'newmessages',
247 $this->makeKnownLink(
248 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
249 . ':' . $this->username
,
250 wfMsg('newmessageslink') )
253 $wgOut->setSquidMaxage(0);
259 $tpl->setRef( 'newtalk', $ntl );
260 $tpl->setRef( 'skin', $this);
261 $tpl->set( 'logo', $this->logoText() );
262 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
263 if ( !$wgDisableCounters ) {
264 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
266 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
268 $tpl->set('viewcount', false);
271 $tpl->set('lastmod', $this->lastModified());
272 $tpl->set('copyright',$this->getCopyright());
274 $this->credits
= false;
276 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
277 require_once("Credits.php");
278 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
281 $tpl->setRef( 'credits', $this->credits
);
283 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
284 $tpl->set('copyright', $this->getCopyright());
285 $tpl->set('viewcount', false);
286 $tpl->set('lastmod', false);
287 $tpl->set('credits', false);
289 $tpl->set('copyright', false);
290 $tpl->set('viewcount', false);
291 $tpl->set('lastmod', false);
292 $tpl->set('credits', false);
295 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
296 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
297 $tpl->set( 'disclaimer', $this->disclaimerLink() );
298 $tpl->set( 'about', $this->aboutLink() );
300 $tpl->setRef( 'debug', $out->mDebugtext
);
301 $tpl->set( 'reporttime', $out->reportTime() );
302 $tpl->set( 'sitenotice', $wgSiteNotice );
304 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
305 $out->mBodytext
.= $printfooter ;
306 $tpl->setRef( 'bodytext', $out->mBodytext
);
309 $language_urls = array();
310 foreach( $wgOut->getLanguageLinks() as $l ) {
311 $nt = Title
::newFromText( $l );
312 $language_urls[] = array('href' => $nt->getFullURL(),
313 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
314 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
316 if(count($language_urls)) {
317 $tpl->setRef( 'language_urls', $language_urls);
319 $tpl->set('language_urls', false);
323 $tpl->set('personal_urls', $this->buildPersonalUrls());
324 $content_actions = $this->buildContentActionUrls();
325 $tpl->setRef('content_actions', $content_actions);
326 // XXX: attach this from javascript, same with section editing
327 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
329 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
331 $tpl->set('body_ondblclick', false);
333 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
334 $tpl->set( 'nav_urls', $this->buildNavUrls() );
337 $res = $tpl->execute();
339 // result may be an error
340 $this->printOrError( $res );
345 * Output the string, or print error message if it's
346 * an error object of the appropriate type.
347 * For the base class, assume strings all around.
352 function printOrError( &$str ) {
357 * build array of urls for personal toolbar
361 function buildPersonalUrls() {
362 /* set up the default links for the personal toolbar */
363 global $wgShowIPinHeader;
364 $personal_urls = array();
365 if ($this->loggedin
) {
366 $personal_urls['userpage'] = array(
367 'text' => $this->username
,
368 'href' => &$this->userpageUrlDetails
['href'],
369 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
371 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
372 $personal_urls['mytalk'] = array(
373 'text' => wfMsg('mytalk'),
374 'href' => &$usertalkUrlDetails['href'],
375 'class' => $usertalkUrlDetails['exists']?
false:'new'
377 $personal_urls['preferences'] = array(
378 'text' => wfMsg('preferences'),
379 'href' => $this->makeSpecialUrl('Preferences')
381 $personal_urls['watchlist'] = array(
382 'text' => wfMsg('watchlist'),
383 'href' => $this->makeSpecialUrl('Watchlist')
385 $personal_urls['mycontris'] = array(
386 'text' => wfMsg('mycontris'),
387 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username
) )
389 $personal_urls['logout'] = array(
390 'text' => wfMsg('userlogout'),
391 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
394 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
395 $personal_urls['anonuserpage'] = array(
396 'text' => $this->username
,
397 'href' => &$this->userpageUrlDetails
['href'],
398 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
400 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
401 $personal_urls['anontalk'] = array(
402 'text' => wfMsg('anontalk'),
403 'href' => &$usertalkUrlDetails['href'],
404 'class' => $usertalkUrlDetails['exists']?
false:'new'
406 $personal_urls['anonlogin'] = array(
407 'text' => wfMsg('userlogin'),
408 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
412 $personal_urls['login'] = array(
413 'text' => wfMsg('userlogin'),
414 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
419 return $personal_urls;
423 * an array of edit links by default used for the tabs
427 function buildContentActionUrls () {
428 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
429 $action = $wgRequest->getText( 'action' );
430 $section = $wgRequest->getText( 'section' );
431 $oldid = $wgRequest->getVal( 'oldid' );
432 $diff = $wgRequest->getVal( 'diff' );
433 $content_actions = array();
435 if( $this->iscontent
and !$wgOut->isQuickbarSuppressed() ) {
437 $nskey = $this->getNameSpaceKey();
438 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
439 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
440 $content_actions[$nskey] = array('class' => ($is_active) ?
'selected' : false,
441 'text' => wfMsg($nskey),
442 'href' => $this->makeArticleUrl($this->thispage
));
444 /* set up the classes for the talk link */
445 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : false);
446 $talktitle = Title
::newFromText( $this->titletxt
);
447 $talktitle = $talktitle->getTalkPage();
448 $this->checkTitle($talktitle, $this->titletxt
);
449 if($talktitle->getArticleId() != 0) {
450 $content_actions['talk'] = array(
451 'class' => $talk_class,
452 'text' => wfMsg('talk'),
453 'href' => $this->makeTalkUrl($this->titletxt
)
456 $content_actions['talk'] = array(
457 'class' => $talk_class?
$talk_class.' new':'new',
458 'text' => wfMsg('talk'),
459 'href' => $this->makeTalkUrl($this->titletxt
,'action=edit')
463 if ( $wgTitle->userCanEdit() ) {
464 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
465 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
466 $istalkclass = $istalk?
' istalk':'';
467 $content_actions['edit'] = array(
468 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
469 'text' => wfMsg('edit'),
470 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid)
473 $content_actions['addsection'] = array(
474 'class' => $section == 'new'?
'selected':false,
475 'text' => wfMsg('addsection'),
476 'href' => $this->makeUrl($this->thispage
, 'action=edit§ion=new')
480 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
481 $content_actions['viewsource'] = array('class' => ($action == 'edit') ?
'selected' : false,
482 'text' => wfMsg('viewsource'),
483 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid));
486 if ( $wgTitle->getArticleId() ) {
488 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : false,
489 'text' => wfMsg('history_short'),
490 'href' => $this->makeUrl($this->thispage
, 'action=history'));
492 # XXX: is there a rollback action anywhere or is it planned?
493 # Don't recall where i got this from...
494 /*if( $wgUser->getNewtalk() ) {
495 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
496 'text' => wfMsg('rollback_short'),
497 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
498 'ttip' => wfMsg('tooltip-rollback'),
499 'akey' => wfMsg('accesskey-rollback'));
503 if($wgUser->isAllowed('protect')){
504 if(!$wgTitle->isProtected()){
505 $content_actions['protect'] = array(
506 'class' => ($action == 'protect') ?
'selected' : false,
507 'text' => wfMsg('protect'),
508 'href' => $this->makeUrl($this->thispage
, 'action=protect')
512 $content_actions['unprotect'] = array(
513 'class' => ($action == 'unprotect') ?
'selected' : false,
514 'text' => wfMsg('unprotect'),
515 'href' => $this->makeUrl($this->thispage
, 'action=unprotect')
519 if($wgUser->isAllowed('delete')){
520 $content_actions['delete'] = array(
521 'class' => ($action == 'delete') ?
'selected' : false,
522 'text' => wfMsg('delete'),
523 'href' => $this->makeUrl($this->thispage
, 'action=delete')
526 if ( $wgUser->getID() != 0 ) {
527 if ( $wgTitle->userCanEdit()) {
528 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : false,
529 'text' => wfMsg('move'),
530 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
))
535 //article doesn't exist or is deleted
536 if($wgUser->isAllowed('delete')){
537 if( $n = $wgTitle->isDeleted() ) {
538 $content_actions['undelete'] = array(
540 'text' => wfMsg( "undelete_short", $n ),
541 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
547 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
548 if( !$wgTitle->userIsWatching()) {
549 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
550 'text' => wfMsg('watch'),
551 'href' => $this->makeUrl($this->thispage
, 'action=watch'));
553 $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
554 'text' => wfMsg('unwatch'),
555 'href' => $this->makeUrl($this->thispage
, 'action=unwatch'));
560 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
562 $article_time = "×tamp=" . $wgArticle->mTimestamp
;
563 $content_actions['validate'] = array('class' => ($action == 'validate') ?
'selected' : false ,
564 'text' => wfMsg('val_tab'),
565 'href' => $this->makeUrl($this->thispage
, 'action=validate'.$article_time));
569 /* show special page tab */
571 $content_actions['article'] = array('class' => 'selected',
572 'text' => wfMsg('specialpage'),
576 return $content_actions;
580 * build array of global navigation links
584 function buildNavigationUrls () {
585 global $wgNavigationLinks;
587 foreach ( $wgNavigationLinks as $link ) {
588 if (wfMsg( $link['text'] ) != '-') {
590 'text' => wfMsg( $link['text'] ),
591 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
592 'id' => 'n-'.$link['text']
600 * build array of common navigation links
604 function buildNavUrls () {
605 global $wgTitle, $wgUser, $wgRequest;
606 global $wgSiteSupportPage, $wgDisableUploads;
608 $action = $wgRequest->getText( 'action' );
609 $oldid = $wgRequest->getVal( 'oldid' );
610 $diff = $wgRequest->getVal( 'diff' );
611 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
613 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
614 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
615 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
616 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
617 $nav_urls['portal'] = (wfMsg('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
618 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
619 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
620 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
621 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
622 if( $this->loggedin
&& !$wgDisableUploads ) {
623 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
625 $nav_urls['upload'] = false;
627 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
629 if( $wgTitle->getNamespace() != NS_SPECIAL
) {
630 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
631 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
634 if( $wgTitle->getNamespace() == NS_USER ||
$wgTitle->getNamespace() == NS_USER_TALK
) {
635 $id = User
::idFromName($wgTitle->getText());
636 $ip = User
::isIP($wgTitle->getText());
642 if($id ||
$ip) { # both anons and non-anons have contri list
643 $nav_urls['contributions'] = array(
644 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
647 $nav_urls['contributions'] = false;
649 $nav_urls['emailuser'] = false;
650 if ( 0 != $wgUser->getID() ) { # show only to signed in users
651 if($id) { # can only email non-anons
652 $nav_urls['emailuser'] = array(
653 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
662 * Generate strings used for xml 'id' names
666 function getNameSpaceKey () {
668 switch ($wgTitle->getNamespace()) {
676 return 'nstab-media';
678 return 'nstab-special';
680 case NS_PROJECT_TALK
:
684 return 'nstab-image';
686 case NS_MEDIAWIKI_TALK
:
687 return 'nstab-mediawiki';
689 case NS_TEMPLATE_TALK
:
690 return 'nstab-template';
695 case NS_CATEGORY_TALK
:
696 return 'nstab-category';
705 function setupUserCss() {
706 global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss;
712 # Add user-specific code if this is a user and we allow that kind of thing
714 if ( $wgAllowUserCss && $this->loggedin
) {
715 $action = $wgRequest->getText('action');
717 # if we're previewing the CSS page, use it
718 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
719 $siteargs .= "&smaxage=0&maxage=0";
720 $usercss = $wgRequest->getText('wpTextbox1');
722 $siteargs .= "&maxage=0";
723 $usercss = '@import "' .
724 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
725 'action=raw&ctype=text/css') . '";' ."\n";
729 # If we use the site's dynamic CSS, throw that in, too
731 if ( $wgUseSiteCss ) {
732 $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n";
735 # If we use any dynamic CSS, make a little CDATA block out of it.
737 if ( !empty($sitecss) ||
!empty($usercss) ) {
738 $this->usercss
= '/*<![CDATA[*/ ' . $sitecss . ' ' . $usercss . ' /*]]>*/';
745 function setupUserJs() {
746 global $wgRequest, $wgTitle, $wgAllowUserJs;
747 $action = $wgRequest->getText('action');
749 if( $wgAllowUserJs && $this->loggedin
) {
750 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
751 # XXX: additional security check/prompt?
752 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
754 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
760 * returns css with user-specific options
763 function getUserStylesheet() {
764 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
765 $action = $wgRequest->getText('action');
766 $maxage = $wgRequest->getText('maxage');
767 $s = "/* generated user stylesheet */\n";
768 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename
.'/rtl.css";'."\n";
770 $this->makeNSUrl(ucfirst($this->skinname
).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI
)."\";\n";
771 if($wgUser->getID() != 0) {
772 if ( 1 == $wgUser->getOption( "underline" ) ) {
773 $s .= "a { text-decoration: underline; }\n";
775 $s .= "a { text-decoration: none; }\n";
778 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
779 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
781 if ( 1 == $wgUser->getOption( "justify" ) ) {
782 $s .= "#bodyContent { text-align: justify; }\n";
790 function getUserJs() {
791 global $wgUser, $wgStylePath;
792 $s = '/* generated javascript */';
793 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
794 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
795 $s .= wfMsg(ucfirst($this->skinname
).'.js');
801 * Generic wrapper for template functions, with interface
802 * compatible with what we use of PHPTAL 0.7.
804 class QuickTemplate
{
805 function QuickTemplate( $callback, $repository=false, $cache_dir=false ) {
806 $this->outputCallback
= $callback;
807 $this->data
= array();
808 $this->translator
= null;
811 function set( $name, $value ) {
812 $this->data
[$name] = $value;
815 function setRef($name, &$value) {
816 $this->data
[$name] =& $value;
819 function setTranslator( &$t ) {
820 $this->translator
= &$t;
824 return call_user_func_array( $this->outputCallback
,
825 array( &$this->data
, &$this->translator
) );
829 } // end of if( defined( 'MEDIAWIKI' ) )