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;
152 $fname = 'SkinTemplate::outputPage';
153 wfProfileIn( $fname );
155 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157 wfProfileIn( "$fname-init" );
158 $this->initPage( $out );
159 $tpl =& $this->setupTemplate( $this->template
, 'skins' );
161 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
162 $tpl->setTranslator(new MediaWiki_I18N());
164 wfProfileOut( "$fname-init" );
166 wfProfileIn( "$fname-stuff" );
167 $this->thispage
= $wgTitle->getPrefixedDbKey();
168 $this->thisurl
= $wgTitle->getPrefixedURL();
169 $this->loggedin
= $wgUser->getID() != 0;
170 $this->iscontent
= ($wgTitle->getNamespace() != Namespace::getSpecial() );
171 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
172 $this->username
= $wgUser->getName();
173 $this->userpage
= $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
174 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
176 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
177 $this->setupUserCss();
178 $this->setupUserJs();
179 $this->titletxt
= $wgTitle->getPrefixedText();
180 wfProfileOut( "$fname-stuff" );
182 wfProfileIn( "$fname-stuff2" );
183 $tpl->set( 'title', $wgOut->getPageTitle() );
184 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
186 $tpl->setRef( "thispage", $this->thispage
);
187 $subpagestr = $this->subPageSubtitle();
189 'subtitle', !empty($subpagestr)?
190 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
193 $undelete = $this->getUndeleteLink();
195 "undelete", !empty($undelete)?
196 '<span class="subpages">'.$undelete.'</span>':
200 $tpl->set( 'catlinks', $this->getCategories());
201 if( $wgOut->isSyndicated() ) {
203 foreach( $wgFeedClasses as $format => $class ) {
204 $feeds[$format] = array(
206 'href' => $wgRequest->appendQuery( "feed=$format" ),
207 'ttip' => wfMsg('tooltip-'.$format)
210 $tpl->setRef( 'feeds', $feeds );
212 $tpl->set( 'feeds', false );
214 $tpl->setRef( 'mimetype', $wgMimeType );
215 $tpl->setRef( 'charset', $wgOutputEncoding );
216 $tpl->set( 'headlinks', $out->getHeadLinks() );
217 $tpl->setRef( 'wgScript', $wgScript );
218 $tpl->setRef( 'skinname', $this->skinname
);
219 $tpl->setRef( 'stylename', $this->stylename
);
220 $tpl->setRef( 'loggedin', $this->loggedin
);
221 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
222 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL
);
223 /* XXX currently unused, might get useful later
224 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
225 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
226 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
227 $tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" );
228 $tpl->set( "helppage", wfMsg('helppage'));
230 $tpl->set( 'searchaction', $this->escapeSearchLink() );
231 $tpl->setRef( 'stylepath', $wgStylePath );
232 $tpl->setRef( 'logopath', $wgLogo );
233 $tpl->setRef( "lang", $wgContLanguageCode );
234 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
235 $tpl->set( 'rtl', $wgContLang->isRTL() );
236 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
237 $tpl->setRef( 'username', $this->username
);
238 $tpl->setRef( 'userpage', $this->userpage
);
239 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
240 $tpl->setRef( 'usercss', $this->usercss
);
241 $tpl->setRef( 'userjs', $this->userjs
);
242 $tpl->setRef( 'userjsprev', $this->userjsprev
);
245 if($this->loggedin
) {
246 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
248 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
251 $tpl->set('jsvarurl', false);
253 if( $wgUser->getNewtalk() ) {
254 $usertitle = Title
::newFromText( $this->userpage
);
255 $usertalktitle = $usertitle->getTalkPage();
256 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
258 $ntl = wfMsg( 'newmessages',
259 $this->makeKnownLink(
260 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
261 . ':' . $this->username
,
262 wfMsg('newmessageslink') )
265 $wgOut->setSquidMaxage(0);
270 wfProfileOut( "$fname-stuff2" );
272 wfProfileIn( "$fname-stuff3" );
273 $tpl->setRef( 'newtalk', $ntl );
274 $tpl->setRef( 'skin', $this);
275 $tpl->set( 'logo', $this->logoText() );
276 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
277 if ( !$wgDisableCounters ) {
278 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
280 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
282 $tpl->set('viewcount', false);
285 $tpl->set('lastmod', $this->lastModified());
286 $tpl->set('copyright',$this->getCopyright());
288 $this->credits
= false;
290 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
291 require_once("Credits.php");
292 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
295 $tpl->setRef( 'credits', $this->credits
);
297 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
298 $tpl->set('copyright', $this->getCopyright());
299 $tpl->set('viewcount', false);
300 $tpl->set('lastmod', false);
301 $tpl->set('credits', false);
303 $tpl->set('copyright', false);
304 $tpl->set('viewcount', false);
305 $tpl->set('lastmod', false);
306 $tpl->set('credits', false);
308 wfProfileOut( "$fname-stuff3" );
310 wfProfileIn( "$fname-stuff4" );
311 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
312 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
313 $tpl->set( 'disclaimer', $this->disclaimerLink() );
314 $tpl->set( 'about', $this->aboutLink() );
316 $tpl->setRef( 'debug', $out->mDebugtext
);
317 $tpl->set( 'reporttime', $out->reportTime() );
318 $tpl->set( 'sitenotice', $wgSiteNotice );
320 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
321 $out->mBodytext
.= $printfooter ;
322 $tpl->setRef( 'bodytext', $out->mBodytext
);
325 $language_urls = array();
326 foreach( $wgOut->getLanguageLinks() as $l ) {
327 $nt = Title
::newFromText( $l );
328 $language_urls[] = array('href' => $nt->getFullURL(),
329 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
330 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
332 if(count($language_urls)) {
333 $tpl->setRef( 'language_urls', $language_urls);
335 $tpl->set('language_urls', false);
337 wfProfileOut( "$fname-stuff4" );
340 $tpl->set('personal_urls', $this->buildPersonalUrls());
341 $content_actions = $this->buildContentActionUrls();
342 $tpl->setRef('content_actions', $content_actions);
344 // XXX: attach this from javascript, same with section editing
345 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
347 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
349 $tpl->set('body_ondblclick', false);
351 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
352 $tpl->set( 'nav_urls', $this->buildNavUrls() );
355 wfProfileIn( "$fname-execute" );
356 $res = $tpl->execute();
357 wfProfileOut( "$fname-execute" );
359 // result may be an error
360 $this->printOrError( $res );
361 wfProfileOut( $fname );
365 * Output the string, or print error message if it's
366 * an error object of the appropriate type.
367 * For the base class, assume strings all around.
372 function printOrError( &$str ) {
377 * build array of urls for personal toolbar
381 function buildPersonalUrls() {
382 $fname = 'SkinTemplate::buildPersonalUrls';
383 wfProfileIn( $fname );
385 /* set up the default links for the personal toolbar */
386 global $wgShowIPinHeader;
387 $personal_urls = array();
388 if ($this->loggedin
) {
389 $personal_urls['userpage'] = array(
390 'text' => $this->username
,
391 'href' => &$this->userpageUrlDetails
['href'],
392 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
394 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
395 $personal_urls['mytalk'] = array(
396 'text' => wfMsg('mytalk'),
397 'href' => &$usertalkUrlDetails['href'],
398 'class' => $usertalkUrlDetails['exists']?
false:'new'
400 $personal_urls['preferences'] = array(
401 'text' => wfMsg('preferences'),
402 'href' => $this->makeSpecialUrl('Preferences')
404 $personal_urls['watchlist'] = array(
405 'text' => wfMsg('watchlist'),
406 'href' => $this->makeSpecialUrl('Watchlist')
408 $personal_urls['mycontris'] = array(
409 'text' => wfMsg('mycontris'),
410 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username
) )
412 $personal_urls['logout'] = array(
413 'text' => wfMsg('userlogout'),
414 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
417 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
418 $personal_urls['anonuserpage'] = array(
419 'text' => $this->username
,
420 'href' => &$this->userpageUrlDetails
['href'],
421 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
423 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
424 $personal_urls['anontalk'] = array(
425 'text' => wfMsg('anontalk'),
426 'href' => &$usertalkUrlDetails['href'],
427 'class' => $usertalkUrlDetails['exists']?
false:'new'
429 $personal_urls['anonlogin'] = array(
430 'text' => wfMsg('userlogin'),
431 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
435 $personal_urls['login'] = array(
436 'text' => wfMsg('userlogin'),
437 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
441 wfProfileOut( $fname );
442 return $personal_urls;
446 * an array of edit links by default used for the tabs
450 function buildContentActionUrls () {
451 $fname = 'SkinTemplate::buildContentActionUrls';
452 wfProfileIn( $fname );
454 global $wgTitle, $wgUser, $wgOut, $wgRequest, $wgUseValidation;
455 $action = $wgRequest->getText( 'action' );
456 $section = $wgRequest->getText( 'section' );
457 $oldid = $wgRequest->getVal( 'oldid' );
458 $diff = $wgRequest->getVal( 'diff' );
459 $content_actions = array();
461 if( $this->iscontent
and !$wgOut->isQuickbarSuppressed() ) {
463 $nskey = $this->getNameSpaceKey();
464 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
465 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
466 $content_actions[$nskey] = array('class' => ($is_active) ?
'selected' : false,
467 'text' => wfMsg($nskey),
468 'href' => $this->makeArticleUrl($this->thispage
));
470 /* set up the classes for the talk link */
471 wfProfileIn( "$fname-talk" );
472 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : false);
473 $talktitle = $wgTitle->getTalkPage();
474 if( $talktitle->getArticleId() != 0 ) {
475 $content_actions['talk'] = array(
476 'class' => $talk_class,
477 'text' => wfMsg('talk'),
478 'href' => $talktitle->getLocalUrl()
481 $content_actions['talk'] = array(
482 'class' => $talk_class ?
$talk_class.' new' : 'new',
483 'text' => wfMsg('talk'),
484 'href' => $talktitle->getLocalUrl( 'action=edit' )
487 wfProfileOut( "$fname-talk" );
489 wfProfileIn( "$fname-edit" );
490 if ( $wgTitle->userCanEdit() ) {
491 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
492 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
493 $istalkclass = $istalk?
' istalk':'';
494 $content_actions['edit'] = array(
495 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
496 'text' => wfMsg('edit'),
497 'href' => $wgTitle->getLocalUrl( 'action=edit'.$oid )
500 $content_actions['addsection'] = array(
501 'class' => $section == 'new'?
'selected':false,
502 'text' => wfMsg('addsection'),
503 'href' => $wgTitle->getLocalUrl( 'action=edit§ion=new' )
507 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
508 $content_actions['viewsource'] = array(
509 'class' => ($action == 'edit') ?
'selected' : false,
510 'text' => wfMsg('viewsource'),
511 'href' => $wgTitle->getLocalUrl( 'action=edit'.$oid )
514 wfProfileOut( "$fname-edit" );
516 wfProfileIn( "$fname-live" );
517 if ( $wgTitle->getArticleId() ) {
519 $content_actions['history'] = array(
520 'class' => ($action == 'history') ?
'selected' : false,
521 'text' => wfMsg('history_short'),
522 'href' => $wgTitle->getLocalUrl( 'action=history')
525 # XXX: is there a rollback action anywhere or is it planned?
526 # Don't recall where i got this from...
527 /*if( $wgUser->getNewtalk() ) {
528 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
529 'text' => wfMsg('rollback_short'),
530 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
531 'ttip' => wfMsg('tooltip-rollback'),
532 'akey' => wfMsg('accesskey-rollback'));
536 if($wgUser->isAllowed('protect')){
537 if(!$wgTitle->isProtected()){
538 $content_actions['protect'] = array(
539 'class' => ($action == 'protect') ?
'selected' : false,
540 'text' => wfMsg('protect'),
541 'href' => $wgTitle->getLocalUrl( 'action=protect' )
545 $content_actions['unprotect'] = array(
546 'class' => ($action == 'unprotect') ?
'selected' : false,
547 'text' => wfMsg('unprotect'),
548 'href' => $wgTitle->getLocalUrl( 'action=unprotect' )
552 if($wgUser->isAllowed('delete')){
553 $content_actions['delete'] = array(
554 'class' => ($action == 'delete') ?
'selected' : false,
555 'text' => wfMsg('delete'),
556 'href' => $wgTitle->getLocalUrl( 'action=delete' )
559 if ( $wgUser->getID() != 0 ) {
560 if ( $wgTitle->userCanMove()) {
561 $content_actions['move'] = array(
562 'class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : false,
563 'text' => wfMsg('move'),
564 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
) )
569 //article doesn't exist or is deleted
570 if($wgUser->isAllowed('delete')){
571 if( $n = $wgTitle->isDeleted() ) {
572 $content_actions['undelete'] = array(
574 'text' => wfMsg( "undelete_short", $n ),
575 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
580 wfProfileOut( "$fname-live" );
582 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
583 if( !$wgTitle->userIsWatching()) {
584 $content_actions['watch'] = array(
585 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
586 'text' => wfMsg('watch'),
587 'href' => $wgTitle->getLocalUrl( 'action=watch' )
590 $content_actions['unwatch'] = array(
591 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
592 'text' => wfMsg('unwatch'),
593 'href' => $wgTitle->getLocalUrl( 'action=unwatch' )
599 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
601 $article_time = "×tamp=" . $wgArticle->mTimestamp
;
602 $content_actions['validate'] = array(
603 'class' => ($action == 'validate') ?
'selected' : false ,
604 'text' => wfMsg('val_tab'),
605 'href' => $wgTitle->getLocalUrl( 'action=validate'.$article_time)
609 /* show special page tab */
611 $content_actions['article'] = array(
612 'class' => 'selected',
613 'text' => wfMsg('specialpage'),
618 wfProfileOut( $fname );
619 return $content_actions;
623 * build array of global navigation links
627 function buildNavigationUrls () {
628 $fname = 'SkinTemplate::buildNavigationUrls';
629 wfProfileIn( $fname );
631 global $wgNavigationLinks;
633 foreach ( $wgNavigationLinks as $link ) {
634 $text = wfMsg( $link['text'] );
635 wfProfileIn( "$fname-{$link['text']}" );
637 $dest = wfMsgForContent( $link['href'] );
638 wfProfileIn( "$fname-{$link['text']}2" );
641 'href' => $this->makeInternalOrExternalUrl( $dest ),
642 'id' => 'n-'.$link['text']
644 wfProfileOut( "$fname-{$link['text']}2" );
646 wfProfileOut( "$fname-{$link['text']}" );
648 wfProfileOut( $fname );
653 * build array of common navigation links
657 function buildNavUrls () {
658 $fname = 'SkinTemplate::buildNavUrls';
659 wfProfileIn( $fname );
661 global $wgTitle, $wgUser, $wgRequest;
662 global $wgSiteSupportPage, $wgDisableUploads;
664 $action = $wgRequest->getText( 'action' );
665 $oldid = $wgRequest->getVal( 'oldid' );
666 $diff = $wgRequest->getVal( 'diff' );
669 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
670 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
671 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
672 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
673 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
674 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
675 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
676 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
677 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
678 if( $this->loggedin
&& !$wgDisableUploads ) {
679 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
681 $nav_urls['upload'] = false;
683 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
685 if( $wgTitle->getNamespace() != NS_SPECIAL
) {
686 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
687 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
690 if( $wgTitle->getNamespace() == NS_USER ||
$wgTitle->getNamespace() == NS_USER_TALK
) {
691 $id = User
::idFromName($wgTitle->getText());
692 $ip = User
::isIP($wgTitle->getText());
698 if($id ||
$ip) { # both anons and non-anons have contri list
699 $nav_urls['contributions'] = array(
700 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
703 $nav_urls['contributions'] = false;
705 $nav_urls['emailuser'] = false;
706 if( $this->showEmailUser( $id ) ) {
707 $nav_urls['emailuser'] = array(
708 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
711 wfProfileOut( $fname );
716 * Generate strings used for xml 'id' names
720 function getNameSpaceKey () {
722 switch ($wgTitle->getNamespace()) {
730 return 'nstab-media';
732 return 'nstab-special';
734 case NS_PROJECT_TALK
:
738 return 'nstab-image';
740 case NS_MEDIAWIKI_TALK
:
741 return 'nstab-mediawiki';
743 case NS_TEMPLATE_TALK
:
744 return 'nstab-template';
749 case NS_CATEGORY_TALK
:
750 return 'nstab-category';
759 function setupUserCss() {
760 $fname = 'SkinTemplate::setupUserCss';
761 wfProfileIn( $fname );
763 global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss;
769 # Add user-specific code if this is a user and we allow that kind of thing
771 if ( $wgAllowUserCss && $this->loggedin
) {
772 $action = $wgRequest->getText('action');
774 # if we're previewing the CSS page, use it
775 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
776 $siteargs .= "&smaxage=0&maxage=0";
777 $usercss = $wgRequest->getText('wpTextbox1');
779 $siteargs .= "&maxage=0";
780 $usercss = '@import "' .
781 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
782 'action=raw&ctype=text/css') . '";' ."\n";
786 # If we use the site's dynamic CSS, throw that in, too
788 if ( $wgUseSiteCss ) {
789 $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n";
792 # If we use any dynamic CSS, make a little CDATA block out of it.
794 if ( !empty($sitecss) ||
!empty($usercss) ) {
795 $this->usercss
= '/*<![CDATA[*/ ' . $sitecss . ' ' . $usercss . ' /*]]>*/';
797 wfProfileOut( $fname );
803 function setupUserJs() {
804 $fname = 'SkinTemplate::setupUserJs';
805 wfProfileIn( $fname );
807 global $wgRequest, $wgTitle, $wgAllowUserJs;
808 $action = $wgRequest->getText('action');
810 if( $wgAllowUserJs && $this->loggedin
) {
811 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
812 # XXX: additional security check/prompt?
813 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
815 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
818 wfProfileOut( $fname );
822 * returns css with user-specific options
825 function getUserStylesheet() {
826 $fname = 'SkinTemplate::getUserStylesheet';
827 wfProfileIn( $fname );
829 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
830 $action = $wgRequest->getText('action');
831 $maxage = $wgRequest->getText('maxage');
832 $s = "/* generated user stylesheet */\n";
833 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename
.'/rtl.css";'."\n";
835 $this->makeNSUrl(ucfirst($this->skinname
).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI
)."\";\n";
836 if($wgUser->getID() != 0) {
837 if ( 1 == $wgUser->getOption( "underline" ) ) {
838 $s .= "a { text-decoration: underline; }\n";
840 $s .= "a { text-decoration: none; }\n";
843 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
844 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
846 if ( 1 == $wgUser->getOption( "justify" ) ) {
847 $s .= "#bodyContent { text-align: justify; }\n";
849 wfProfileOut( $fname );
856 function getUserJs() {
857 $fname = 'SkinTemplate::getUserJs';
858 wfProfileIn( $fname );
860 global $wgUser, $wgStylePath;
861 $s = '/* generated javascript */';
862 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
863 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
864 $s .= wfMsg(ucfirst($this->skinname
).'.js');
866 wfProfileOut( $fname );
872 * Generic wrapper for template functions, with interface
873 * compatible with what we use of PHPTAL 0.7.
875 class QuickTemplate
{
879 function QuickTemplate() {
880 $this->data
= array();
881 $this->translator
= new MediaWiki_I18N();
887 function set( $name, $value ) {
888 $this->data
[$name] = $value;
894 function setRef($name, &$value) {
895 $this->data
[$name] =& $value;
901 function setTranslator( &$t ) {
902 $this->translator
= &$t;
909 echo "Override this function.";
916 function text( $str ) {
917 echo htmlspecialchars( $this->data
[$str] );
923 function html( $str ) {
924 echo $this->data
[$str];
930 function msg( $str ) {
931 echo htmlspecialchars( $this->translator
->translate( $str ) );
937 function msgHtml( $str ) {
938 echo $this->translator
->translate( $str );
944 function haveData( $str ) {
945 return $this->data
[$str];
951 function haveMsg( $str ) {
952 $msg = $this->translator
->translate( $str );
953 return ($msg != '-') && ($msg != ''); # ????
957 } // end of if( defined( 'MEDIAWIKI' ) )