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);
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));
304 $tpl->set('numberofwatchingusers', false);
307 $tpl->set('numberofwatchingusers', false);
310 $tpl->set('lastmod', $this->lastModified());
311 $tpl->set('copyright',$this->getCopyright());
313 $this->credits
= false;
315 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
316 require_once("Credits.php");
317 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
320 $tpl->setRef( 'credits', $this->credits
);
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);
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);
335 wfProfileOut( "$fname-stuff3" );
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() );
343 $tpl->setRef( 'debug', $out->mDebugtext
);
344 $tpl->set( 'reporttime', $out->reportTime() );
345 $tpl->set( 'sitenotice', $wgSiteNotice );
346 $tpl->set( 'tagline', wfMsg('tagline') );
348 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
349 $out->mBodytext
.= $printfooter ;
350 $tpl->setRef( 'bodytext', $out->mBodytext
);
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');
360 if(count($language_urls)) {
361 $tpl->setRef( 'language_urls', $language_urls);
363 $tpl->set('language_urls', false);
365 wfProfileOut( "$fname-stuff4" );
368 $tpl->set('personal_urls', $this->buildPersonalUrls());
369 $content_actions = $this->buildContentActionUrls();
370 $tpl->setRef('content_actions', $content_actions);
372 // XXX: attach this from javascript, same with section editing
373 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
375 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
377 $tpl->set('body_ondblclick', false);
379 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
380 $tpl->set( 'nav_urls', $this->buildNavUrls() );
383 wfProfileIn( "$fname-execute" );
384 $res = $tpl->execute();
385 wfProfileOut( "$fname-execute" );
387 // result may be an error
388 $this->printOrError( $res );
389 wfProfileOut( $fname );
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.
400 function printOrError( &$str ) {
405 * build array of urls for personal toolbar
409 function buildPersonalUrls() {
410 $fname = 'SkinTemplate::buildPersonalUrls';
411 wfProfileIn( $fname );
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')
422 $personal_urls['mytalk'] = array(
423 'text' => wfMsg('mytalk'),
424 'href' => $this->makeSpecialUrl('Mytalk')
426 $personal_urls['preferences'] = array(
427 'text' => wfMsg('preferences'),
428 'href' => $this->makeSpecialUrl('Preferences')
430 $personal_urls['watchlist'] = array(
431 'text' => wfMsg('watchlist'),
432 'href' => $this->makeSpecialUrl('Watchlist')
434 $personal_urls['mycontris'] = array(
435 'text' => wfMsg('mycontris'),
436 'href' => $this->makeSpecialUrl('Mycontributions')
438 $personal_urls['logout'] = array(
439 'text' => wfMsg('userlogout'),
440 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
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')
449 $personal_urls['mytalk'] = array(
450 'text' => wfMsg('mytalk'),
451 'href' => $this->makeSpecialUrl('Mytalk')
454 $personal_urls['anonlogin'] = array(
455 'text' => wfMsg('userlogin'),
456 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
459 /* Anonymous users personal toolbar */
460 $personal_urls['login'] = array(
461 'text' => wfMsg('userlogin'),
462 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
466 wfProfileOut( $fname );
467 return $personal_urls;
471 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
474 $classes[] = 'selected';
476 if( $checkEdit && $title->getArticleId() == 0 ) {
480 'class' => implode( ' ', $classes ),
481 'text' => wfMsg( $message ),
482 'href' => $title->getLocalUrl( $query ) );
486 * an array of edit links by default used for the tabs
490 function buildContentActionUrls () {
492 $fname = 'SkinTemplate::buildContentActionUrls';
493 wfProfileIn( $fname );
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();
502 if( $this->iscontent
) {
504 $nskey = $this->getNameSpaceKey();
505 $content_actions[$nskey] = $this->tabAction(
506 $this->mTitle
->getSubjectPage(),
508 !$this->mTitle
->isTalkPage() );
510 $content_actions['talk'] = $this->tabAction(
511 $this->mTitle
->getTalkPage(),
513 $this->mTitle
->isTalkPage(),
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 )
529 $content_actions['addsection'] = array(
530 'class' => $section == 'new'?
'selected':false,
531 'text' => wfMsg('addsection'),
532 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
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 )
543 wfProfileOut( "$fname-edit" );
545 wfProfileIn( "$fname-live" );
546 if ( $this->mTitle
->getArticleId() ) {
548 $content_actions['history'] = array(
549 'class' => ($action == 'history') ?
'selected' : false,
550 'text' => wfMsg('history_short'),
551 'href' => $this->mTitle
->getLocalUrl( 'action=history')
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' )
563 $content_actions['unprotect'] = array(
564 'class' => ($action == 'unprotect') ?
'selected' : false,
565 'text' => wfMsg('unprotect'),
566 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
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' )
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
) )
587 //article doesn't exist or is deleted
588 if($wgUser->isAllowed('delete')){
589 if( $n = $this->mTitle
->isDeleted() ) {
590 $content_actions['undelete'] = array(
592 'text' => wfMsg( "undelete_short", $n ),
593 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
598 wfProfileOut( "$fname-live" );
600 if ( $wgUser->isLoggedIn() and $action != 'submit' ) {
601 if( !$this->mTitle
->userIsWatching()) {
602 $content_actions['watch'] = array(
603 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
604 'text' => wfMsg('watch'),
605 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
608 $content_actions['unwatch'] = array(
609 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
610 'text' => wfMsg('unwatch'),
611 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
617 /* show special page tab */
619 $content_actions['article'] = array(
620 'class' => 'selected',
621 'text' => wfMsg('specialpage'),
626 /* show links to different language variants */
627 global $wgDisableLangConversion;
628 $variants = $wgContLang->getVariants();
629 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
630 $preferred = $wgContLang->getPreferredVariant();
633 $actstr = 'action=' . $action . '&';
635 foreach( $variants as $code ) {
636 $varname = $wgContLang->getVariantname( $code );
637 if( $varname == 'disable' )
639 $selected = ( $code == $preferred )?
'selected' : false;
640 $content_actions['varlang-' . $vcount] = array(
641 'class' => $selected,
643 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
649 wfProfileOut( $fname );
650 return $content_actions;
654 * build array of global navigation links
658 function buildNavigationUrls () {
659 $fname = 'SkinTemplate::buildNavigationUrls';
660 wfProfileIn( $fname );
662 global $wgNavigationLinks;
664 foreach ( $wgNavigationLinks as $link ) {
665 $text = wfMsg( $link['text'] );
666 wfProfileIn( "$fname-{$link['text']}" );
668 $dest = wfMsgForContent( $link['href'] );
669 wfProfileIn( "$fname-{$link['text']}2" );
672 'href' => $this->makeInternalOrExternalUrl( $dest ),
673 'id' => 'n-'.$link['text']
675 wfProfileOut( "$fname-{$link['text']}2" );
677 wfProfileOut( "$fname-{$link['text']}" );
679 wfProfileOut( $fname );
684 * build array of common navigation links
688 function buildNavUrls () {
689 $fname = 'SkinTemplate::buildNavUrls';
690 wfProfileIn( $fname );
692 global $wgUser, $wgRequest;
693 global $wgSiteSupportPage, $wgDisableUploads;
695 $action = $wgRequest->getText( 'action' );
696 $oldid = $wgRequest->getVal( 'oldid' );
697 $diff = $wgRequest->getVal( 'diff' );
700 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
701 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
702 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
703 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
704 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
705 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
706 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
707 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
708 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
709 if( $this->loggedin
&& !$wgDisableUploads ) {
710 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
712 $nav_urls['upload'] = false;
714 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
716 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
717 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
718 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
721 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
722 $id = User
::idFromName($this->mTitle
->getText());
723 $ip = User
::isIP($this->mTitle
->getText());
729 if($id ||
$ip) { # both anons and non-anons have contri list
730 $nav_urls['contributions'] = array(
731 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle
->getPartialURL() )
734 $nav_urls['contributions'] = false;
736 $nav_urls['emailuser'] = false;
737 if( $this->showEmailUser( $id ) ) {
738 $nav_urls['emailuser'] = array(
739 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle
->getPartialURL() )
742 wfProfileOut( $fname );
747 * Generate strings used for xml 'id' names
751 function getNameSpaceKey () {
752 switch ($this->mTitle
->getNamespace()) {
760 return 'nstab-media';
762 return 'nstab-special';
764 case NS_PROJECT_TALK
:
768 return 'nstab-image';
770 case NS_MEDIAWIKI_TALK
:
771 return 'nstab-mediawiki';
773 case NS_TEMPLATE_TALK
:
774 return 'nstab-template';
779 case NS_CATEGORY_TALK
:
780 return 'nstab-category';
789 function setupUserCss() {
790 $fname = 'SkinTemplate::setupUserCss';
791 wfProfileIn( $fname );
793 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
797 $siteargs = '&maxage=' . $wgSquidMaxage;
799 # Add user-specific code if this is a user and we allow that kind of thing
801 if ( $wgAllowUserCss && $this->loggedin
) {
802 $action = $wgRequest->getText('action');
804 # if we're previewing the CSS page, use it
805 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
806 $siteargs = "&smaxage=0&maxage=0";
807 $usercss = $wgRequest->getText('wpTextbox1');
809 $usercss = '@import "' .
810 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
811 'action=raw&ctype=text/css') . '";' ."\n";
814 $siteargs .= '&ts=' . $wgUser->mTouched
;
817 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
819 # If we use the site's dynamic CSS, throw that in, too
820 if ( $wgUseSiteCss ) {
821 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
822 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
825 # If we use any dynamic CSS, make a little CDATA block out of it.
827 if ( !empty($sitecss) ||
!empty($usercss) ) {
828 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
830 wfProfileOut( $fname );
836 function setupUserJs() {
837 $fname = 'SkinTemplate::setupUserJs';
838 wfProfileIn( $fname );
840 global $wgRequest, $wgAllowUserJs;
841 $action = $wgRequest->getText('action');
843 if( $wgAllowUserJs && $this->loggedin
) {
844 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
845 # XXX: additional security check/prompt?
846 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
848 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
851 wfProfileOut( $fname );
855 * returns css with user-specific options
858 function getUserStylesheet() {
859 $fname = 'SkinTemplate::getUserStylesheet';
860 wfProfileIn( $fname );
863 $s = "/* generated user stylesheet */\n";
865 if( $wgUser->isLoggedIn() ) {
866 if ( $wgUser->getOption( "underline" ) ) {
867 $s .= "a { text-decoration: underline; }\n";
869 $s .= "a { text-decoration: none; }\n";
872 if ( !$wgUser->getOption( "highlightbroken" ) ) {
873 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
875 if ( $wgUser->getOption( "justify" ) ) {
876 $s .= "#bodyContent { text-align: justify; }\n";
878 wfProfileOut( $fname );
885 function getUserJs() {
886 $fname = 'SkinTemplate::getUserJs';
887 wfProfileIn( $fname );
890 $s = '/* generated javascript */';
891 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
892 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
893 $s .= wfMsg(ucfirst($this->skinname
).'.js');
895 wfProfileOut( $fname );
901 * Generic wrapper for template functions, with interface
902 * compatible with what we use of PHPTAL 0.7.
906 class QuickTemplate
{
910 function QuickTemplate() {
911 $this->data
= array();
912 $this->translator
= new MediaWiki_I18N();
918 function set( $name, $value ) {
919 $this->data
[$name] = $value;
925 function setRef($name, &$value) {
926 $this->data
[$name] =& $value;
932 function setTranslator( &$t ) {
933 $this->translator
= &$t;
940 echo "Override this function.";
947 function text( $str ) {
948 echo htmlspecialchars( $this->data
[$str] );
954 function html( $str ) {
955 echo $this->data
[$str];
961 function msg( $str ) {
962 echo htmlspecialchars( $this->translator
->translate( $str ) );
968 function msgHtml( $str ) {
969 echo $this->translator
->translate( $str );
973 * An ugly, ugly hack.
976 function msgWiki( $str ) {
977 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
979 $text = $this->translator
->translate( $str );
980 $parserOutput = $wgParser->parse( $text, $wgTitle,
981 $wgOut->mParserOptions
, true );
982 echo $parserOutput->getText();
988 function haveData( $str ) {
989 return $this->data
[$str];
995 function haveMsg( $str ) {
996 $msg = $this->translator
->translate( $str );
997 return ($msg != '-') && ($msg != ''); # ????
1001 } // end of if( defined( 'MEDIAWIKI' ) )