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 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
69 $varValue = $this->_context
[$var];
71 $value = str_replace($src, $varValue, $value);
73 wfProfileOut( $fname );
82 class SkinTemplate
extends Skin
{
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
115 * @param OutputPage $out
117 function initPage( &$out ) {
118 parent
::initPage( $out );
119 $this->skinname
= 'monobook';
120 $this->stylename
= 'monobook';
121 $this->template
= 'QuickTemplate';
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.
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
135 function &setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
140 * initialize various variables and generate the template
142 * @param OutputPage $out
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;
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
161 $this->mTitle
= $wgTitle;
162 $this->mUser
=& $wgUser;
164 $tpl =& $this->setupTemplate( $this->template
, 'skins' );
166 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
167 $tpl->setTranslator(new MediaWiki_I18N());
169 wfProfileOut( "$fname-init" );
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
);
182 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
183 $this->setupUserCss();
184 $this->setupUserJs();
185 $this->titletxt
= $this->mTitle
->getPrefixedText();
186 wfProfileOut( "$fname-stuff" );
188 wfProfileIn( "$fname-stuff2" );
189 $tpl->set( 'title', $wgOut->getPageTitle() );
190 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192 $tpl->setRef( "thispage", $this->thispage
);
193 $subpagestr = $this->subPageSubtitle();
195 'subtitle', !empty($subpagestr)?
196 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
199 $undelete = $this->getUndeleteLink();
201 "undelete", !empty($undelete)?
202 '<span class="subpages">'.$undelete.'</span>':
206 $tpl->set( 'catlinks', $this->getCategories());
207 if( $wgOut->isSyndicated() ) {
209 foreach( $wgFeedClasses as $format => $class ) {
210 $feeds[$format] = array(
212 'href' => $wgRequest->appendQuery( "feed=$format" ),
213 'ttip' => wfMsg('tooltip-'.$format)
216 $tpl->setRef( 'feeds', $feeds );
218 $tpl->set( 'feeds', false );
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'));
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
);
252 if($this->loggedin
) {
253 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
255 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
258 $tpl->set('jsvarurl', false);
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(
267 wfMsg('newmessageslink')
271 $wgOut->setSquidMaxage(0);
276 wfProfileOut( "$fname-stuff2" );
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() );
286 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
288 $tpl->set('viewcount', false);
291 $tpl->set('viewcount', false);
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));
306 $tpl->set('numberofwatchingusers', false);
309 $tpl->set('numberofwatchingusers', false);
312 $tpl->set('lastmod', $this->lastModified());
313 $tpl->set('copyright',$this->getCopyright());
315 $this->credits
= false;
317 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
318 require_once("Credits.php");
319 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
322 $tpl->setRef( 'credits', $this->credits
);
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);
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);
337 wfProfileOut( "$fname-stuff3" );
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() );
345 $tpl->setRef( 'debug', $out->mDebugtext
);
346 $tpl->set( 'reporttime', $out->reportTime() );
347 $tpl->set( 'sitenotice', $wgSiteNotice );
348 $tpl->set( 'tagline', wfMsg('tagline') );
350 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
351 $out->mBodytext
.= $printfooter ;
352 $tpl->setRef( 'bodytext', $out->mBodytext
);
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');
362 if(count($language_urls)) {
363 $tpl->setRef( 'language_urls', $language_urls);
365 $tpl->set('language_urls', false);
367 wfProfileOut( "$fname-stuff4" );
370 $tpl->set('personal_urls', $this->buildPersonalUrls());
371 $content_actions = $this->buildContentActionUrls();
372 $tpl->setRef('content_actions', $content_actions);
374 // XXX: attach this from javascript, same with section editing
375 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
377 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
379 $tpl->set('body_ondblclick', false);
381 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
382 $tpl->set( 'nav_urls', $this->buildNavUrls() );
385 wfProfileIn( "$fname-execute" );
386 $res = $tpl->execute();
387 wfProfileOut( "$fname-execute" );
389 // result may be an error
390 $this->printOrError( $res );
391 wfProfileOut( $fname );
395 * Output the string, or print error message if it's
396 * an error object of the appropriate type.
397 * For the base class, assume strings all around.
402 function printOrError( &$str ) {
407 * build array of urls for personal toolbar
411 function buildPersonalUrls() {
412 $fname = 'SkinTemplate::buildPersonalUrls';
413 wfProfileIn( $fname );
415 /* set up the default links for the personal toolbar */
416 global $wgShowIPinHeader;
417 $personal_urls = array();
418 if ($this->loggedin
) {
419 /* Logged in users personal toolbar */
420 $personal_urls['userpage'] = array(
421 'text' => wfMsg('mypage'),
422 'href' => $this->makeSpecialUrl('Mypage')
424 $personal_urls['mytalk'] = array(
425 'text' => wfMsg('mytalk'),
426 'href' => $this->makeSpecialUrl('Mytalk')
428 $personal_urls['preferences'] = array(
429 'text' => wfMsg('preferences'),
430 'href' => $this->makeSpecialUrl('Preferences')
432 $personal_urls['watchlist'] = array(
433 'text' => wfMsg('watchlist'),
434 'href' => $this->makeSpecialUrl('Watchlist')
436 $personal_urls['mycontris'] = array(
437 'text' => wfMsg('mycontris'),
438 'href' => $this->makeSpecialUrl('Mycontributions')
440 $personal_urls['logout'] = array(
441 'text' => wfMsg('userlogout'),
442 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
445 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
446 /* Anonymous with session users personal toolbar */
447 $personal_urls['anonuserpage'] = array(
448 'text' => wfMsg('mypage'),
449 'href' => $this->makeSpecialUrl('Mypage')
451 $personal_urls['mytalk'] = array(
452 'text' => wfMsg('mytalk'),
453 'href' => $this->makeSpecialUrl('Mytalk')
456 $personal_urls['anonlogin'] = array(
457 'text' => wfMsg('userlogin'),
458 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
461 /* Anonymous users personal toolbar */
462 $personal_urls['login'] = array(
463 'text' => wfMsg('userlogin'),
464 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
468 wfProfileOut( $fname );
469 return $personal_urls;
473 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
476 $classes[] = 'selected';
478 if( $checkEdit && $title->getArticleId() == 0 ) {
482 'class' => implode( ' ', $classes ),
483 'text' => wfMsg( $message ),
484 'href' => $title->getLocalUrl( $query ) );
488 * an array of edit links by default used for the tabs
492 function buildContentActionUrls () {
493 global $wgContLang, $wgUseValidation;
494 $fname = 'SkinTemplate::buildContentActionUrls';
495 wfProfileIn( $fname );
497 global $wgUser, $wgRequest;
498 $action = $wgRequest->getText( 'action' );
499 $section = $wgRequest->getText( 'section' );
500 $oldid = $wgRequest->getVal( 'oldid' );
501 $diff = $wgRequest->getVal( 'diff' );
502 $content_actions = array();
504 if( $this->iscontent
) {
506 $nskey = $this->getNameSpaceKey();
507 $content_actions[$nskey] = $this->tabAction(
508 $this->mTitle
->getSubjectPage(),
510 !$this->mTitle
->isTalkPage() );
512 $content_actions['talk'] = $this->tabAction(
513 $this->mTitle
->getTalkPage(),
515 $this->mTitle
->isTalkPage(),
519 wfProfileIn( "$fname-edit" );
520 if ( $this->mTitle
->userCanEdit() ) {
521 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
522 $istalk = $this->mTitle
->isTalkPage();
523 $istalkclass = $istalk?
' istalk':'';
524 $content_actions['edit'] = array(
525 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
526 'text' => wfMsg('edit'),
527 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
531 $content_actions['addsection'] = array(
532 'class' => $section == 'new'?
'selected':false,
533 'text' => wfMsg('addsection'),
534 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
538 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
539 $content_actions['viewsource'] = array(
540 'class' => ($action == 'edit') ?
'selected' : false,
541 'text' => wfMsg('viewsource'),
542 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
545 wfProfileOut( "$fname-edit" );
547 wfProfileIn( "$fname-live" );
548 if ( $this->mTitle
->getArticleId() ) {
550 $content_actions['history'] = array(
551 'class' => ($action == 'history') ?
'selected' : false,
552 'text' => wfMsg('history_short'),
553 'href' => $this->mTitle
->getLocalUrl( 'action=history')
556 if($wgUser->isAllowed('protect')){
557 if(!$this->mTitle
->isProtected()){
558 $content_actions['protect'] = array(
559 'class' => ($action == 'protect') ?
'selected' : false,
560 'text' => wfMsg('protect'),
561 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
565 $content_actions['unprotect'] = array(
566 'class' => ($action == 'unprotect') ?
'selected' : false,
567 'text' => wfMsg('unprotect'),
568 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
572 if($wgUser->isAllowed('delete')){
573 $content_actions['delete'] = array(
574 'class' => ($action == 'delete') ?
'selected' : false,
575 'text' => wfMsg('delete'),
576 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
579 if ( $wgUser->isLoggedIn() ) {
580 if ( $this->mTitle
->userCanMove()) {
581 $content_actions['move'] = array(
582 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
583 'text' => wfMsg('move'),
584 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
) )
589 //article doesn't exist or is deleted
590 if($wgUser->isAllowed('delete')){
591 if( $n = $this->mTitle
->isDeleted() ) {
592 $content_actions['undelete'] = array(
594 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
595 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
600 wfProfileOut( "$fname-live" );
602 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
603 if( !$this->mTitle
->userIsWatching()) {
604 $content_actions['watch'] = array(
605 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
606 'text' => wfMsg('watch'),
607 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
610 $content_actions['unwatch'] = array(
611 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
612 'text' => wfMsg('unwatch'),
613 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
617 # Validate tab. TODO: add validation to logged-in user rights
618 if($wgUseValidation){ # && $wgUser->isAllowed('validate')){
619 $content_actions['validate'] = array(
620 'class' => ($action == 'validate') ?
'selected' : false,
621 'text' => wfMsg('val_tab'),
622 'href' => $this->mTitle
->getLocalUrl( 'action=validate' )
627 /* show special page tab */
629 $content_actions['article'] = array(
630 'class' => 'selected',
631 'text' => wfMsg('specialpage'),
636 /* show links to different language variants */
637 global $wgDisableLangConversion;
638 $variants = $wgContLang->getVariants();
639 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
640 $preferred = $wgContLang->getPreferredVariant();
643 $actstr = 'action=' . $action . '&';
645 foreach( $variants as $code ) {
646 $varname = $wgContLang->getVariantname( $code );
647 if( $varname == 'disable' )
649 $selected = ( $code == $preferred )?
'selected' : false;
650 $content_actions['varlang-' . $vcount] = array(
651 'class' => $selected,
653 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
659 wfProfileOut( $fname );
660 return $content_actions;
664 * build array of global navigation links
668 function buildNavigationUrls () {
669 $fname = 'SkinTemplate::buildNavigationUrls';
670 wfProfileIn( $fname );
672 global $wgNavigationLinks;
674 foreach ( $wgNavigationLinks as $link ) {
675 $text = wfMsg( $link['text'] );
676 wfProfileIn( "$fname-{$link['text']}" );
678 $dest = wfMsgForContent( $link['href'] );
679 wfProfileIn( "$fname-{$link['text']}2" );
682 'href' => $this->makeInternalOrExternalUrl( $dest ),
683 'id' => 'n-'.$link['text']
685 wfProfileOut( "$fname-{$link['text']}2" );
687 wfProfileOut( "$fname-{$link['text']}" );
689 wfProfileOut( $fname );
694 * build array of common navigation links
698 function buildNavUrls () {
699 $fname = 'SkinTemplate::buildNavUrls';
700 wfProfileIn( $fname );
702 global $wgUser, $wgRequest;
703 global $wgSiteSupportPage, $wgDisableUploads;
705 $action = $wgRequest->getText( 'action' );
706 $oldid = $wgRequest->getVal( 'oldid' );
707 $diff = $wgRequest->getVal( 'diff' );
710 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
711 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
712 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
713 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
714 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
715 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
716 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
717 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
718 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
719 if( $this->loggedin
&& !$wgDisableUploads ) {
720 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
722 $nav_urls['upload'] = false;
724 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
726 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
727 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
728 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
731 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
732 $id = User
::idFromName($this->mTitle
->getText());
733 $ip = User
::isIP($this->mTitle
->getText());
739 if($id ||
$ip) { # both anons and non-anons have contri list
740 $nav_urls['contributions'] = array(
741 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle
->getPartialURL() )
744 $nav_urls['contributions'] = false;
746 $nav_urls['emailuser'] = false;
747 if( $this->showEmailUser( $id ) ) {
748 $nav_urls['emailuser'] = array(
749 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle
->getPartialURL() )
752 wfProfileOut( $fname );
757 * Generate strings used for xml 'id' names
761 function getNameSpaceKey () {
762 switch ($this->mTitle
->getNamespace()) {
770 return 'nstab-media';
772 return 'nstab-special';
774 case NS_PROJECT_TALK
:
778 return 'nstab-image';
780 case NS_MEDIAWIKI_TALK
:
781 return 'nstab-mediawiki';
783 case NS_TEMPLATE_TALK
:
784 return 'nstab-template';
789 case NS_CATEGORY_TALK
:
790 return 'nstab-category';
799 function setupUserCss() {
800 $fname = 'SkinTemplate::setupUserCss';
801 wfProfileIn( $fname );
803 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
807 $siteargs = '&maxage=' . $wgSquidMaxage;
809 # Add user-specific code if this is a user and we allow that kind of thing
811 if ( $wgAllowUserCss && $this->loggedin
) {
812 $action = $wgRequest->getText('action');
814 # if we're previewing the CSS page, use it
815 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
816 $siteargs = "&smaxage=0&maxage=0";
817 $usercss = $wgRequest->getText('wpTextbox1');
819 $usercss = '@import "' .
820 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
821 'action=raw&ctype=text/css') . '";' ."\n";
824 $siteargs .= '&ts=' . $wgUser->mTouched
;
827 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
829 # If we use the site's dynamic CSS, throw that in, too
830 if ( $wgUseSiteCss ) {
831 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
832 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
835 # If we use any dynamic CSS, make a little CDATA block out of it.
837 if ( !empty($sitecss) ||
!empty($usercss) ) {
838 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
840 wfProfileOut( $fname );
846 function setupUserJs() {
847 $fname = 'SkinTemplate::setupUserJs';
848 wfProfileIn( $fname );
850 global $wgRequest, $wgAllowUserJs;
851 $action = $wgRequest->getText('action');
853 if( $wgAllowUserJs && $this->loggedin
) {
854 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
855 # XXX: additional security check/prompt?
856 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
858 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
861 wfProfileOut( $fname );
865 * returns css with user-specific options
868 function getUserStylesheet() {
869 $fname = 'SkinTemplate::getUserStylesheet';
870 wfProfileIn( $fname );
873 $s = "/* generated user stylesheet */\n";
875 if( $wgUser->isLoggedIn() ) {
876 if ( $wgUser->getOption( "underline" ) ) {
877 $s .= "a { text-decoration: underline; }\n";
879 $s .= "a { text-decoration: none; }\n";
882 if ( !$wgUser->getOption( "highlightbroken" ) ) {
883 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
885 if ( $wgUser->getOption( "justify" ) ) {
886 $s .= "#bodyContent { text-align: justify; }\n";
888 wfProfileOut( $fname );
895 function getUserJs() {
896 $fname = 'SkinTemplate::getUserJs';
897 wfProfileIn( $fname );
900 $s = '/* generated javascript */';
901 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
902 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
903 $s .= wfMsg(ucfirst($this->skinname
).'.js');
905 wfProfileOut( $fname );
911 * Generic wrapper for template functions, with interface
912 * compatible with what we use of PHPTAL 0.7.
916 class QuickTemplate
{
920 function QuickTemplate() {
921 $this->data
= array();
922 $this->translator
= new MediaWiki_I18N();
928 function set( $name, $value ) {
929 $this->data
[$name] = $value;
935 function setRef($name, &$value) {
936 $this->data
[$name] =& $value;
942 function setTranslator( &$t ) {
943 $this->translator
= &$t;
950 echo "Override this function.";
957 function text( $str ) {
958 echo htmlspecialchars( $this->data
[$str] );
964 function html( $str ) {
965 echo $this->data
[$str];
971 function msg( $str ) {
972 echo htmlspecialchars( $this->translator
->translate( $str ) );
978 function msgHtml( $str ) {
979 echo $this->translator
->translate( $str );
983 * An ugly, ugly hack.
986 function msgWiki( $str ) {
987 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
989 $text = $this->translator
->translate( $str );
990 $parserOutput = $wgParser->parse( $text, $wgTitle,
991 $wgOut->mParserOptions
, true );
992 echo $parserOutput->getText();
998 function haveData( $str ) {
999 return $this->data
[$str];
1005 function haveMsg( $str ) {
1006 $msg = $this->translator
->translate( $str );
1007 return ($msg != '-') && ($msg != ''); # ????
1011 } // end of if( defined( 'MEDIAWIKI' ) )