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->getID() != 0;
175 $this->iscontent
= ($this->mTitle
->getNamespace() != Namespace::getSpecial() );
176 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
177 $this->username
= $wgUser->getName();
178 $this->userpage
= $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
179 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
181 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
182 $this->setupUserCss();
183 $this->setupUserJs();
184 $this->titletxt
= $this->mTitle
->getPrefixedText();
185 wfProfileOut( "$fname-stuff" );
187 wfProfileIn( "$fname-stuff2" );
188 $tpl->set( 'title', $wgOut->getPageTitle() );
189 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
191 $tpl->setRef( "thispage", $this->thispage
);
192 $subpagestr = $this->subPageSubtitle();
194 'subtitle', !empty($subpagestr)?
195 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
198 $undelete = $this->getUndeleteLink();
200 "undelete", !empty($undelete)?
201 '<span class="subpages">'.$undelete.'</span>':
205 $tpl->set( 'catlinks', $this->getCategories());
206 if( $wgOut->isSyndicated() ) {
208 foreach( $wgFeedClasses as $format => $class ) {
209 $feeds[$format] = array(
211 'href' => $wgRequest->appendQuery( "feed=$format" ),
212 'ttip' => wfMsg('tooltip-'.$format)
215 $tpl->setRef( 'feeds', $feeds );
217 $tpl->set( 'feeds', false );
219 $tpl->setRef( 'mimetype', $wgMimeType );
220 $tpl->setRef( 'charset', $wgOutputEncoding );
221 $tpl->set( 'headlinks', $out->getHeadLinks() );
222 $tpl->setRef( 'wgScript', $wgScript );
223 $tpl->setRef( 'skinname', $this->skinname
);
224 $tpl->setRef( 'stylename', $this->stylename
);
225 $tpl->setRef( 'loggedin', $this->loggedin
);
226 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
227 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
228 /* XXX currently unused, might get useful later
229 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
230 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
231 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
232 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
233 $tpl->set( "helppage", wfMsg('helppage'));
235 $tpl->set( 'searchaction', $this->escapeSearchLink() );
236 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
237 $tpl->setRef( 'stylepath', $wgStylePath );
238 $tpl->setRef( 'logopath', $wgLogo );
239 $tpl->setRef( "lang", $wgContLanguageCode );
240 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
241 $tpl->set( 'rtl', $wgContLang->isRTL() );
242 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
243 $tpl->setRef( 'username', $this->username
);
244 $tpl->setRef( 'userpage', $this->userpage
);
245 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
246 $tpl->setRef( 'usercss', $this->usercss
);
247 $tpl->setRef( 'userjs', $this->userjs
);
248 $tpl->setRef( 'userjsprev', $this->userjsprev
);
251 if($this->loggedin
) {
252 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
254 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
257 $tpl->set('jsvarurl', false);
259 if( $wgUser->getNewtalk() ) {
260 $usertitle = $this->mUser
->getUserPage();
261 $usertalktitle = $usertitle->getTalkPage();
262 if( !$usertalktitle->equals( $this->mTitle
) ) {
263 $ntl = wfMsg( 'newmessages',
264 $this->makeKnownLinkObj(
266 wfMsg('newmessageslink')
270 $wgOut->setSquidMaxage(0);
275 wfProfileOut( "$fname-stuff2" );
277 wfProfileIn( "$fname-stuff3" );
278 $tpl->setRef( 'newtalk', $ntl );
279 $tpl->setRef( 'skin', $this);
280 $tpl->set( 'logo', $this->logoText() );
281 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
282 if ( !$wgDisableCounters ) {
283 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
285 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
287 $tpl->set('viewcount', false);
291 if ($wgPageShowWatchingUsers) {
292 $dbr =& wfGetDB( DB_SLAVE
);
293 extract( $dbr->tableNames( 'watchlist' ) );
294 $sql = "SELECT COUNT(*) AS n FROM $watchlist
295 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
296 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
297 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
298 $x = $dbr->fetchObject( $res );
299 $numberofwatchingusers = $x->n
;
300 if ($numberofwatchingusers > 0) {
301 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
303 $tpl->set('numberofwatchingusers', false);
306 $tpl->set('numberofwatchingusers', false);
309 $tpl->set('lastmod', $this->lastModified());
310 $tpl->set('copyright',$this->getCopyright());
312 $this->credits
= false;
314 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
315 require_once("Credits.php");
316 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
319 $tpl->setRef( 'credits', $this->credits
);
321 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
322 $tpl->set('copyright', $this->getCopyright());
323 $tpl->set('viewcount', false);
324 $tpl->set('lastmod', false);
325 $tpl->set('credits', false);
326 $tpl->set('numberofwatchingusers', false);
328 $tpl->set('copyright', false);
329 $tpl->set('viewcount', false);
330 $tpl->set('lastmod', false);
331 $tpl->set('credits', false);
332 $tpl->set('numberofwatchingusers', false);
334 wfProfileOut( "$fname-stuff3" );
336 wfProfileIn( "$fname-stuff4" );
337 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
338 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
339 $tpl->set( 'disclaimer', $this->disclaimerLink() );
340 $tpl->set( 'about', $this->aboutLink() );
342 $tpl->setRef( 'debug', $out->mDebugtext
);
343 $tpl->set( 'reporttime', $out->reportTime() );
344 $tpl->set( 'sitenotice', $wgSiteNotice );
345 $tpl->set( 'tagline', wfMsg('tagline') );
347 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
348 $out->mBodytext
.= $printfooter ;
349 $tpl->setRef( 'bodytext', $out->mBodytext
);
352 $language_urls = array();
353 foreach( $wgOut->getLanguageLinks() as $l ) {
354 $nt = Title
::newFromText( $l );
355 $language_urls[] = array('href' => $nt->getFullURL(),
356 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
357 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
359 if(count($language_urls)) {
360 $tpl->setRef( 'language_urls', $language_urls);
362 $tpl->set('language_urls', false);
364 wfProfileOut( "$fname-stuff4" );
367 $tpl->set('personal_urls', $this->buildPersonalUrls());
368 $content_actions = $this->buildContentActionUrls();
369 $tpl->setRef('content_actions', $content_actions);
371 // XXX: attach this from javascript, same with section editing
372 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
374 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
376 $tpl->set('body_ondblclick', false);
378 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
379 $tpl->set( 'nav_urls', $this->buildNavUrls() );
382 wfProfileIn( "$fname-execute" );
383 $res = $tpl->execute();
384 wfProfileOut( "$fname-execute" );
386 // result may be an error
387 $this->printOrError( $res );
388 wfProfileOut( $fname );
392 * Output the string, or print error message if it's
393 * an error object of the appropriate type.
394 * For the base class, assume strings all around.
399 function printOrError( &$str ) {
404 * build array of urls for personal toolbar
408 function buildPersonalUrls() {
409 $fname = 'SkinTemplate::buildPersonalUrls';
410 wfProfileIn( $fname );
412 /* set up the default links for the personal toolbar */
413 global $wgShowIPinHeader;
414 $personal_urls = array();
415 if ($this->loggedin
) {
416 /* Logged in users personal toolbar */
417 $personal_urls['userpage'] = array(
418 'text' => wfMsg('mypage'),
419 'href' => $this->makeSpecialUrl('Mypage')
421 $personal_urls['mytalk'] = array(
422 'text' => wfMsg('mytalk'),
423 'href' => $this->makeSpecialUrl('Mytalk')
425 $personal_urls['preferences'] = array(
426 'text' => wfMsg('preferences'),
427 'href' => $this->makeSpecialUrl('Preferences')
429 $personal_urls['watchlist'] = array(
430 'text' => wfMsg('watchlist'),
431 'href' => $this->makeSpecialUrl('Watchlist')
433 $personal_urls['mycontris'] = array(
434 'text' => wfMsg('mycontris'),
435 'href' => $this->makeSpecialUrl('Mycontributions')
437 $personal_urls['logout'] = array(
438 'text' => wfMsg('userlogout'),
439 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
442 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
443 /* Anonymous with session users personal toolbar */
444 $personal_urls['anonuserpage'] = array(
445 'text' => wfMsg('mypage'),
446 'href' => $this->makeSpecialUrl('Mypage')
448 $personal_urls['mytalk'] = array(
449 'text' => wfMsg('mytalk'),
450 'href' => $this->makeSpecialUrl('Mytalk')
453 $personal_urls['anonlogin'] = array(
454 'text' => wfMsg('userlogin'),
455 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
458 /* Anonymous users personal toolbar */
459 $personal_urls['login'] = array(
460 'text' => wfMsg('userlogin'),
461 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
465 wfProfileOut( $fname );
466 return $personal_urls;
470 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
473 $classes[] = 'selected';
475 if( $checkEdit && $title->getArticleId() == 0 ) {
479 'class' => implode( ' ', $classes ),
480 'text' => wfMsg( $message ),
481 'href' => $title->getLocalUrl( $query ) );
485 * an array of edit links by default used for the tabs
489 function buildContentActionUrls () {
491 $fname = 'SkinTemplate::buildContentActionUrls';
492 wfProfileIn( $fname );
494 global $wgUser, $wgRequest;
495 $action = $wgRequest->getText( 'action' );
496 $section = $wgRequest->getText( 'section' );
497 $oldid = $wgRequest->getVal( 'oldid' );
498 $diff = $wgRequest->getVal( 'diff' );
499 $content_actions = array();
501 if( $this->iscontent
) {
503 $nskey = $this->getNameSpaceKey();
504 $content_actions[$nskey] = $this->tabAction(
505 $this->mTitle
->getSubjectPage(),
507 !$this->mTitle
->isTalkPage() );
509 $content_actions['talk'] = $this->tabAction(
510 $this->mTitle
->getTalkPage(),
512 $this->mTitle
->isTalkPage(),
516 wfProfileIn( "$fname-edit" );
517 if ( $this->mTitle
->userCanEdit() ) {
518 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
519 $istalk = $this->mTitle
->isTalkPage();
520 $istalkclass = $istalk?
' istalk':'';
521 $content_actions['edit'] = array(
522 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
523 'text' => wfMsg('edit'),
524 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
528 $content_actions['addsection'] = array(
529 'class' => $section == 'new'?
'selected':false,
530 'text' => wfMsg('addsection'),
531 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
535 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
536 $content_actions['viewsource'] = array(
537 'class' => ($action == 'edit') ?
'selected' : false,
538 'text' => wfMsg('viewsource'),
539 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
542 wfProfileOut( "$fname-edit" );
544 wfProfileIn( "$fname-live" );
545 if ( $this->mTitle
->getArticleId() ) {
547 $content_actions['history'] = array(
548 'class' => ($action == 'history') ?
'selected' : false,
549 'text' => wfMsg('history_short'),
550 'href' => $this->mTitle
->getLocalUrl( 'action=history')
553 if($wgUser->isAllowed('protect')){
554 if(!$this->mTitle
->isProtected()){
555 $content_actions['protect'] = array(
556 'class' => ($action == 'protect') ?
'selected' : false,
557 'text' => wfMsg('protect'),
558 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
562 $content_actions['unprotect'] = array(
563 'class' => ($action == 'unprotect') ?
'selected' : false,
564 'text' => wfMsg('unprotect'),
565 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
569 if($wgUser->isAllowed('delete')){
570 $content_actions['delete'] = array(
571 'class' => ($action == 'delete') ?
'selected' : false,
572 'text' => wfMsg('delete'),
573 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
576 if ( $wgUser->getID() != 0 ) {
577 if ( $this->mTitle
->userCanMove()) {
578 $content_actions['move'] = array(
579 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== Namespace::getSpecial()) ?
'selected' : false,
580 'text' => wfMsg('move'),
581 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
) )
586 //article doesn't exist or is deleted
587 if($wgUser->isAllowed('delete')){
588 if( $n = $this->mTitle
->isDeleted() ) {
589 $content_actions['undelete'] = array(
591 'text' => wfMsg( "undelete_short", $n ),
592 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
597 wfProfileOut( "$fname-live" );
599 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
600 if( !$this->mTitle
->userIsWatching()) {
601 $content_actions['watch'] = array(
602 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
603 'text' => wfMsg('watch'),
604 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
607 $content_actions['unwatch'] = array(
608 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
609 'text' => wfMsg('unwatch'),
610 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
616 /* show special page tab */
618 $content_actions['article'] = array(
619 'class' => 'selected',
620 'text' => wfMsg('specialpage'),
625 /* show links to different language variants */
626 global $wgDisableLangConversion;
627 $variants = $wgContLang->getVariants();
628 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
629 $preferred = $wgContLang->getPreferredVariant();
632 $actstr = 'action=' . $action . '&';
634 foreach( $variants as $code ) {
635 $varname = $wgContLang->getVariantname( $code );
636 if( $varname == 'disable' )
638 $selected = ( $code == $preferred )?
'selected' : false;
639 $content_actions['varlang-' . $vcount] = array(
640 'class' => $selected,
642 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
648 wfProfileOut( $fname );
649 return $content_actions;
653 * build array of global navigation links
657 function buildNavigationUrls () {
658 $fname = 'SkinTemplate::buildNavigationUrls';
659 wfProfileIn( $fname );
661 global $wgNavigationLinks;
663 foreach ( $wgNavigationLinks as $link ) {
664 $text = wfMsg( $link['text'] );
665 wfProfileIn( "$fname-{$link['text']}" );
667 $dest = wfMsgForContent( $link['href'] );
668 wfProfileIn( "$fname-{$link['text']}2" );
671 'href' => $this->makeInternalOrExternalUrl( $dest ),
672 'id' => 'n-'.$link['text']
674 wfProfileOut( "$fname-{$link['text']}2" );
676 wfProfileOut( "$fname-{$link['text']}" );
678 wfProfileOut( $fname );
683 * build array of common navigation links
687 function buildNavUrls () {
688 $fname = 'SkinTemplate::buildNavUrls';
689 wfProfileIn( $fname );
691 global $wgUser, $wgRequest;
692 global $wgSiteSupportPage, $wgDisableUploads;
694 $action = $wgRequest->getText( 'action' );
695 $oldid = $wgRequest->getVal( 'oldid' );
696 $diff = $wgRequest->getVal( 'diff' );
699 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
700 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
701 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
702 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
703 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
704 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
705 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
706 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
707 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
708 if( $this->loggedin
&& !$wgDisableUploads ) {
709 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
711 $nav_urls['upload'] = false;
713 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
715 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
716 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
717 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
720 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
721 $id = User
::idFromName($this->mTitle
->getText());
722 $ip = User
::isIP($this->mTitle
->getText());
728 if($id ||
$ip) { # both anons and non-anons have contri list
729 $nav_urls['contributions'] = array(
730 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle
->getPartialURL() )
733 $nav_urls['contributions'] = false;
735 $nav_urls['emailuser'] = false;
736 if( $this->showEmailUser( $id ) ) {
737 $nav_urls['emailuser'] = array(
738 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle
->getPartialURL() )
741 wfProfileOut( $fname );
746 * Generate strings used for xml 'id' names
750 function getNameSpaceKey () {
751 switch ($this->mTitle
->getNamespace()) {
759 return 'nstab-media';
761 return 'nstab-special';
763 case NS_PROJECT_TALK
:
767 return 'nstab-image';
769 case NS_MEDIAWIKI_TALK
:
770 return 'nstab-mediawiki';
772 case NS_TEMPLATE_TALK
:
773 return 'nstab-template';
778 case NS_CATEGORY_TALK
:
779 return 'nstab-category';
788 function setupUserCss() {
789 $fname = 'SkinTemplate::setupUserCss';
790 wfProfileIn( $fname );
792 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
796 $siteargs = '&maxage=' . $wgSquidMaxage;
798 # Add user-specific code if this is a user and we allow that kind of thing
800 if ( $wgAllowUserCss && $this->loggedin
) {
801 $action = $wgRequest->getText('action');
803 # if we're previewing the CSS page, use it
804 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
805 $siteargs = "&smaxage=0&maxage=0";
806 $usercss = $wgRequest->getText('wpTextbox1');
808 $usercss = '@import "' .
809 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
810 'action=raw&ctype=text/css') . '";' ."\n";
813 $siteargs .= '&ts=' . $wgUser->mTouched
;
816 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
818 # If we use the site's dynamic CSS, throw that in, too
819 if ( $wgUseSiteCss ) {
820 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
821 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
824 # If we use any dynamic CSS, make a little CDATA block out of it.
826 if ( !empty($sitecss) ||
!empty($usercss) ) {
827 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
829 wfProfileOut( $fname );
835 function setupUserJs() {
836 $fname = 'SkinTemplate::setupUserJs';
837 wfProfileIn( $fname );
839 global $wgRequest, $wgAllowUserJs;
840 $action = $wgRequest->getText('action');
842 if( $wgAllowUserJs && $this->loggedin
) {
843 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
844 # XXX: additional security check/prompt?
845 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
847 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
850 wfProfileOut( $fname );
854 * returns css with user-specific options
857 function getUserStylesheet() {
858 $fname = 'SkinTemplate::getUserStylesheet';
859 wfProfileIn( $fname );
862 $s = "/* generated user stylesheet */\n";
864 if($wgUser->getID() != 0) {
865 if ( 1 == $wgUser->getOption( "underline" ) ) {
866 $s .= "a { text-decoration: underline; }\n";
868 $s .= "a { text-decoration: none; }\n";
871 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
872 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
874 if ( 1 == $wgUser->getOption( "justify" ) ) {
875 $s .= "#bodyContent { text-align: justify; }\n";
877 wfProfileOut( $fname );
884 function getUserJs() {
885 $fname = 'SkinTemplate::getUserJs';
886 wfProfileIn( $fname );
888 global $wgUser, $wgStylePath;
889 $s = '/* generated javascript */';
890 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
891 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
892 $s .= wfMsg(ucfirst($this->skinname
).'.js');
894 wfProfileOut( $fname );
900 * Generic wrapper for template functions, with interface
901 * compatible with what we use of PHPTAL 0.7.
905 class QuickTemplate
{
909 function QuickTemplate() {
910 $this->data
= array();
911 $this->translator
= new MediaWiki_I18N();
917 function set( $name, $value ) {
918 $this->data
[$name] = $value;
924 function setRef($name, &$value) {
925 $this->data
[$name] =& $value;
931 function setTranslator( &$t ) {
932 $this->translator
= &$t;
939 echo "Override this function.";
946 function text( $str ) {
947 echo htmlspecialchars( $this->data
[$str] );
953 function html( $str ) {
954 echo $this->data
[$str];
960 function msg( $str ) {
961 echo htmlspecialchars( $this->translator
->translate( $str ) );
967 function msgHtml( $str ) {
968 echo $this->translator
->translate( $str );
972 * An ugly, ugly hack.
975 function msgWiki( $str ) {
976 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
978 $text = $this->translator
->translate( $str );
979 $parserOutput = $wgParser->parse( $text, $wgTitle,
980 $wgOut->mParserOptions
, true );
981 echo $parserOutput->getText();
987 function haveData( $str ) {
988 return $this->data
[$str];
994 function haveMsg( $str ) {
995 $msg = $this->translator
->translate( $str );
996 return ($msg != '-') && ($msg != ''); # ????
1000 } // end of if( defined( 'MEDIAWIKI' ) )