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 );
160 $tpl =& $this->setupTemplate( $this->template
, 'skins' );
162 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
163 $tpl->setTranslator(new MediaWiki_I18N());
165 wfProfileOut( "$fname-init" );
167 wfProfileIn( "$fname-stuff" );
168 $this->thispage
= $wgTitle->getPrefixedDbKey();
169 $this->thisurl
= $wgTitle->getPrefixedURL();
170 $this->loggedin
= $wgUser->getID() != 0;
171 $this->iscontent
= ($wgTitle->getNamespace() != Namespace::getSpecial() );
172 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
173 $this->username
= $wgUser->getName();
174 $this->userpage
= $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
175 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
177 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
178 $this->setupUserCss();
179 $this->setupUserJs();
180 $this->titletxt
= $wgTitle->getPrefixedText();
181 wfProfileOut( "$fname-stuff" );
183 wfProfileIn( "$fname-stuff2" );
184 $tpl->set( 'title', $wgOut->getPageTitle() );
185 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
187 $tpl->setRef( "thispage", $this->thispage
);
188 $subpagestr = $this->subPageSubtitle();
190 'subtitle', !empty($subpagestr)?
191 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
194 $undelete = $this->getUndeleteLink();
196 "undelete", !empty($undelete)?
197 '<span class="subpages">'.$undelete.'</span>':
201 $tpl->set( 'catlinks', $this->getCategories());
202 if( $wgOut->isSyndicated() ) {
204 foreach( $wgFeedClasses as $format => $class ) {
205 $feeds[$format] = array(
207 'href' => $wgRequest->appendQuery( "feed=$format" ),
208 'ttip' => wfMsg('tooltip-'.$format)
211 $tpl->setRef( 'feeds', $feeds );
213 $tpl->set( 'feeds', false );
215 $tpl->setRef( 'mimetype', $wgMimeType );
216 $tpl->setRef( 'charset', $wgOutputEncoding );
217 $tpl->set( 'headlinks', $out->getHeadLinks() );
218 $tpl->setRef( 'wgScript', $wgScript );
219 $tpl->setRef( 'skinname', $this->skinname
);
220 $tpl->setRef( 'stylename', $this->stylename
);
221 $tpl->setRef( 'loggedin', $this->loggedin
);
222 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
223 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL
);
224 /* XXX currently unused, might get useful later
225 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
226 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
227 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
228 $tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" );
229 $tpl->set( "helppage", wfMsg('helppage'));
231 $tpl->set( 'searchaction', $this->escapeSearchLink() );
232 $tpl->setRef( 'stylepath', $wgStylePath );
233 $tpl->setRef( 'logopath', $wgLogo );
234 $tpl->setRef( "lang", $wgContLanguageCode );
235 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
236 $tpl->set( 'rtl', $wgContLang->isRTL() );
237 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
238 $tpl->setRef( 'username', $this->username
);
239 $tpl->setRef( 'userpage', $this->userpage
);
240 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
241 $tpl->setRef( 'usercss', $this->usercss
);
242 $tpl->setRef( 'userjs', $this->userjs
);
243 $tpl->setRef( 'userjsprev', $this->userjsprev
);
246 if($this->loggedin
) {
247 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
249 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
252 $tpl->set('jsvarurl', false);
254 if( $wgUser->getNewtalk() ) {
255 $usertitle = Title
::newFromText( $this->userpage
);
256 $usertalktitle = $usertitle->getTalkPage();
257 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
259 $ntl = wfMsg( 'newmessages',
260 $this->makeKnownLink(
261 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
262 . ':' . $this->username
,
263 wfMsg('newmessageslink') )
266 $wgOut->setSquidMaxage(0);
271 wfProfileOut( "$fname-stuff2" );
273 wfProfileIn( "$fname-stuff3" );
274 $tpl->setRef( 'newtalk', $ntl );
275 $tpl->setRef( 'skin', $this);
276 $tpl->set( 'logo', $this->logoText() );
277 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
278 if ( !$wgDisableCounters ) {
279 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
281 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
283 $tpl->set('viewcount', false);
287 if ($wgPageShowWatchingUsers) {
288 $dbr =& wfGetDB( DB_SLAVE
);
289 extract( $dbr->tableNames( 'watchlist' ) );
290 $sql = "SELECT COUNT(*) AS n FROM $watchlist
291 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
292 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
293 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
294 $x = $dbr->fetchObject( $res );
295 $numberofwatchingusers = $x->n
;
296 if ($numberofwatchingusers > 0) {
297 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
299 $tpl->set('numberofwatchingusers', false);
302 $tpl->set('numberofwatchingusers', false);
305 $tpl->set('lastmod', $this->lastModified());
306 $tpl->set('copyright',$this->getCopyright());
308 $this->credits
= false;
310 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
311 require_once("Credits.php");
312 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
315 $tpl->setRef( 'credits', $this->credits
);
317 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
318 $tpl->set('copyright', $this->getCopyright());
319 $tpl->set('viewcount', false);
320 $tpl->set('lastmod', false);
321 $tpl->set('credits', false);
322 $tpl->set('numberofwatchingusers', false);
324 $tpl->set('copyright', false);
325 $tpl->set('viewcount', false);
326 $tpl->set('lastmod', false);
327 $tpl->set('credits', false);
328 $tpl->set('numberofwatchingusers', false);
330 wfProfileOut( "$fname-stuff3" );
332 wfProfileIn( "$fname-stuff4" );
333 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
334 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
335 $tpl->set( 'disclaimer', $this->disclaimerLink() );
336 $tpl->set( 'about', $this->aboutLink() );
338 $tpl->setRef( 'debug', $out->mDebugtext
);
339 $tpl->set( 'reporttime', $out->reportTime() );
340 $tpl->set( 'sitenotice', $wgSiteNotice );
341 $tpl->set( 'tagline', wfMsg('tagline') );
343 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
344 $out->mBodytext
.= $printfooter ;
345 $tpl->setRef( 'bodytext', $out->mBodytext
);
348 $language_urls = array();
349 foreach( $wgOut->getLanguageLinks() as $l ) {
350 $nt = Title
::newFromText( $l );
351 $language_urls[] = array('href' => $nt->getFullURL(),
352 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
353 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
355 if(count($language_urls)) {
356 $tpl->setRef( 'language_urls', $language_urls);
358 $tpl->set('language_urls', false);
360 wfProfileOut( "$fname-stuff4" );
363 $tpl->set('personal_urls', $this->buildPersonalUrls());
364 $content_actions = $this->buildContentActionUrls();
365 $tpl->setRef('content_actions', $content_actions);
367 // XXX: attach this from javascript, same with section editing
368 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
370 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
372 $tpl->set('body_ondblclick', false);
374 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
375 $tpl->set( 'nav_urls', $this->buildNavUrls() );
378 wfProfileIn( "$fname-execute" );
379 $res = $tpl->execute();
380 wfProfileOut( "$fname-execute" );
382 // result may be an error
383 $this->printOrError( $res );
384 wfProfileOut( $fname );
388 * Output the string, or print error message if it's
389 * an error object of the appropriate type.
390 * For the base class, assume strings all around.
395 function printOrError( &$str ) {
400 * build array of urls for personal toolbar
404 function buildPersonalUrls() {
405 $fname = 'SkinTemplate::buildPersonalUrls';
406 wfProfileIn( $fname );
408 /* set up the default links for the personal toolbar */
409 global $wgShowIPinHeader;
410 $personal_urls = array();
411 if ($this->loggedin
) {
412 $personal_urls['userpage'] = array(
413 'text' => $this->username
,
414 'href' => &$this->userpageUrlDetails
['href'],
415 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
417 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
418 $personal_urls['mytalk'] = array(
419 'text' => wfMsg('mytalk'),
420 'href' => &$usertalkUrlDetails['href'],
421 'class' => $usertalkUrlDetails['exists']?
false:'new'
423 $personal_urls['preferences'] = array(
424 'text' => wfMsg('preferences'),
425 'href' => $this->makeSpecialUrl('Preferences')
427 $personal_urls['watchlist'] = array(
428 'text' => wfMsg('watchlist'),
429 'href' => $this->makeSpecialUrl('Watchlist')
431 $personal_urls['mycontris'] = array(
432 'text' => wfMsg('mycontris'),
433 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username
) )
435 $personal_urls['logout'] = array(
436 'text' => wfMsg('userlogout'),
437 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
440 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
441 $personal_urls['anonuserpage'] = array(
442 'text' => $this->username
,
443 'href' => &$this->userpageUrlDetails
['href'],
444 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
446 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
447 $personal_urls['anontalk'] = array(
448 'text' => wfMsg('anontalk'),
449 'href' => &$usertalkUrlDetails['href'],
450 'class' => $usertalkUrlDetails['exists']?
false:'new'
452 $personal_urls['anonlogin'] = array(
453 'text' => wfMsg('userlogin'),
454 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
458 $personal_urls['login'] = array(
459 'text' => wfMsg('userlogin'),
460 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
464 wfProfileOut( $fname );
465 return $personal_urls;
469 * an array of edit links by default used for the tabs
473 function buildContentActionUrls () {
474 $fname = 'SkinTemplate::buildContentActionUrls';
475 wfProfileIn( $fname );
477 global $wgTitle, $wgUser, $wgRequest, $wgUseValidation;
478 $action = $wgRequest->getText( 'action' );
479 $section = $wgRequest->getText( 'section' );
480 $oldid = $wgRequest->getVal( 'oldid' );
481 $diff = $wgRequest->getVal( 'diff' );
482 $content_actions = array();
484 if( $this->iscontent
) {
486 $nskey = $this->getNameSpaceKey();
487 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
488 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
489 $content_actions[$nskey] = array('class' => ($is_active) ?
'selected' : false,
490 'text' => wfMsg($nskey),
491 'href' => $this->makeArticleUrl($this->thispage
));
493 /* set up the classes for the talk link */
494 wfProfileIn( "$fname-talk" );
495 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : false);
496 $talktitle = $wgTitle->getTalkPage();
497 if( $talktitle->getArticleId() != 0 ) {
498 $content_actions['talk'] = array(
499 'class' => $talk_class,
500 'text' => wfMsg('talk'),
501 'href' => $talktitle->getLocalUrl()
504 $content_actions['talk'] = array(
505 'class' => $talk_class ?
$talk_class.' new' : 'new',
506 'text' => wfMsg('talk'),
507 'href' => $talktitle->getLocalUrl( 'action=edit' )
510 wfProfileOut( "$fname-talk" );
512 wfProfileIn( "$fname-edit" );
513 if ( $wgTitle->userCanEdit() ) {
514 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
515 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
516 $istalkclass = $istalk?
' istalk':'';
517 $content_actions['edit'] = array(
518 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
519 'text' => wfMsg('edit'),
520 'href' => $wgTitle->getLocalUrl( 'action=edit'.$oid )
523 $content_actions['addsection'] = array(
524 'class' => $section == 'new'?
'selected':false,
525 'text' => wfMsg('addsection'),
526 'href' => $wgTitle->getLocalUrl( 'action=edit§ion=new' )
530 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
531 $content_actions['viewsource'] = array(
532 'class' => ($action == 'edit') ?
'selected' : false,
533 'text' => wfMsg('viewsource'),
534 'href' => $wgTitle->getLocalUrl( 'action=edit'.$oid )
537 wfProfileOut( "$fname-edit" );
539 wfProfileIn( "$fname-live" );
540 if ( $wgTitle->getArticleId() ) {
542 $content_actions['history'] = array(
543 'class' => ($action == 'history') ?
'selected' : false,
544 'text' => wfMsg('history_short'),
545 'href' => $wgTitle->getLocalUrl( 'action=history')
548 # XXX: is there a rollback action anywhere or is it planned?
549 # Don't recall where i got this from...
550 /*if( $wgUser->getNewtalk() ) {
551 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
552 'text' => wfMsg('rollback_short'),
553 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
554 'ttip' => wfMsg('tooltip-rollback'),
555 'akey' => wfMsg('accesskey-rollback'));
559 if($wgUser->isAllowed('protect')){
560 if(!$wgTitle->isProtected()){
561 $content_actions['protect'] = array(
562 'class' => ($action == 'protect') ?
'selected' : false,
563 'text' => wfMsg('protect'),
564 'href' => $wgTitle->getLocalUrl( 'action=protect' )
568 $content_actions['unprotect'] = array(
569 'class' => ($action == 'unprotect') ?
'selected' : false,
570 'text' => wfMsg('unprotect'),
571 'href' => $wgTitle->getLocalUrl( 'action=unprotect' )
575 if($wgUser->isAllowed('delete')){
576 $content_actions['delete'] = array(
577 'class' => ($action == 'delete') ?
'selected' : false,
578 'text' => wfMsg('delete'),
579 'href' => $wgTitle->getLocalUrl( 'action=delete' )
582 if ( $wgUser->getID() != 0 ) {
583 if ( $wgTitle->userCanMove()) {
584 $content_actions['move'] = array(
585 'class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : false,
586 'text' => wfMsg('move'),
587 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
) )
592 //article doesn't exist or is deleted
593 if($wgUser->isAllowed('delete')){
594 if( $n = $wgTitle->isDeleted() ) {
595 $content_actions['undelete'] = array(
597 'text' => wfMsg( "undelete_short", $n ),
598 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
603 wfProfileOut( "$fname-live" );
605 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
606 if( !$wgTitle->userIsWatching()) {
607 $content_actions['watch'] = array(
608 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
609 'text' => wfMsg('watch'),
610 'href' => $wgTitle->getLocalUrl( 'action=watch' )
613 $content_actions['unwatch'] = array(
614 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
615 'text' => wfMsg('unwatch'),
616 'href' => $wgTitle->getLocalUrl( 'action=unwatch' )
622 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
624 $article_time = "×tamp=" . $wgArticle->mTimestamp
;
625 $content_actions['validate'] = array(
626 'class' => ($action == 'validate') ?
'selected' : false ,
627 'text' => wfMsg('val_tab'),
628 'href' => $wgTitle->getLocalUrl( 'action=validate'.$article_time)
632 /* show special page tab */
634 $content_actions['article'] = array(
635 'class' => 'selected',
636 'text' => wfMsg('specialpage'),
641 wfProfileOut( $fname );
642 return $content_actions;
646 * build array of global navigation links
650 function buildNavigationUrls () {
651 $fname = 'SkinTemplate::buildNavigationUrls';
652 wfProfileIn( $fname );
654 global $wgNavigationLinks;
656 foreach ( $wgNavigationLinks as $link ) {
657 $text = wfMsg( $link['text'] );
658 wfProfileIn( "$fname-{$link['text']}" );
660 $dest = wfMsgForContent( $link['href'] );
661 wfProfileIn( "$fname-{$link['text']}2" );
664 'href' => $this->makeInternalOrExternalUrl( $dest ),
665 'id' => 'n-'.$link['text']
667 wfProfileOut( "$fname-{$link['text']}2" );
669 wfProfileOut( "$fname-{$link['text']}" );
671 wfProfileOut( $fname );
676 * build array of common navigation links
680 function buildNavUrls () {
681 $fname = 'SkinTemplate::buildNavUrls';
682 wfProfileIn( $fname );
684 global $wgTitle, $wgUser, $wgRequest;
685 global $wgSiteSupportPage, $wgDisableUploads;
687 $action = $wgRequest->getText( 'action' );
688 $oldid = $wgRequest->getVal( 'oldid' );
689 $diff = $wgRequest->getVal( 'diff' );
692 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
693 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
694 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
695 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
696 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
697 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
698 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
699 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
700 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
701 if( $this->loggedin
&& !$wgDisableUploads ) {
702 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
704 $nav_urls['upload'] = false;
706 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
708 if( $wgTitle->getNamespace() != NS_SPECIAL
) {
709 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
710 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
713 if( $wgTitle->getNamespace() == NS_USER ||
$wgTitle->getNamespace() == NS_USER_TALK
) {
714 $id = User
::idFromName($wgTitle->getText());
715 $ip = User
::isIP($wgTitle->getText());
721 if($id ||
$ip) { # both anons and non-anons have contri list
722 $nav_urls['contributions'] = array(
723 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
726 $nav_urls['contributions'] = false;
728 $nav_urls['emailuser'] = false;
729 if( $this->showEmailUser( $id ) ) {
730 $nav_urls['emailuser'] = array(
731 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
734 wfProfileOut( $fname );
739 * Generate strings used for xml 'id' names
743 function getNameSpaceKey () {
745 switch ($wgTitle->getNamespace()) {
753 return 'nstab-media';
755 return 'nstab-special';
757 case NS_PROJECT_TALK
:
761 return 'nstab-image';
763 case NS_MEDIAWIKI_TALK
:
764 return 'nstab-mediawiki';
766 case NS_TEMPLATE_TALK
:
767 return 'nstab-template';
772 case NS_CATEGORY_TALK
:
773 return 'nstab-category';
782 function setupUserCss() {
783 $fname = 'SkinTemplate::setupUserCss';
784 wfProfileIn( $fname );
786 global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss;
792 # Add user-specific code if this is a user and we allow that kind of thing
794 if ( $wgAllowUserCss && $this->loggedin
) {
795 $action = $wgRequest->getText('action');
797 # if we're previewing the CSS page, use it
798 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
799 $siteargs .= "&smaxage=0&maxage=0";
800 $usercss = $wgRequest->getText('wpTextbox1');
802 $siteargs .= "&maxage=0";
803 $usercss = '@import "' .
804 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
805 'action=raw&ctype=text/css') . '";' ."\n";
809 # If we use the site's dynamic CSS, throw that in, too
811 if ( $wgUseSiteCss ) {
812 $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n";
815 # If we use any dynamic CSS, make a little CDATA block out of it.
817 if ( !empty($sitecss) ||
!empty($usercss) ) {
818 $this->usercss
= '/*<![CDATA[*/ ' . $sitecss . ' ' . $usercss . ' /*]]>*/';
820 wfProfileOut( $fname );
826 function setupUserJs() {
827 $fname = 'SkinTemplate::setupUserJs';
828 wfProfileIn( $fname );
830 global $wgRequest, $wgTitle, $wgAllowUserJs;
831 $action = $wgRequest->getText('action');
833 if( $wgAllowUserJs && $this->loggedin
) {
834 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
835 # XXX: additional security check/prompt?
836 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
838 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
841 wfProfileOut( $fname );
845 * returns css with user-specific options
848 function getUserStylesheet() {
849 $fname = 'SkinTemplate::getUserStylesheet';
850 wfProfileIn( $fname );
852 global $wgUser, $wgRequest, $wgTitle, $wgContLang, $wgSquidMaxage, $wgStylePath;
853 $action = $wgRequest->getText('action');
854 $maxage = $wgRequest->getText('maxage');
855 $s = "/* generated user stylesheet */\n";
856 if($wgContLang->isRTL()) $s .= '@import "'.$wgStylePath.'/'.$this->stylename
.'/rtl.css";'."\n";
858 $this->makeNSUrl(ucfirst($this->skinname
).'.css', 'action=raw&ctype=text/css&smaxage='.$wgSquidMaxage, NS_MEDIAWIKI
)."\";\n";
859 if($wgUser->getID() != 0) {
860 if ( 1 == $wgUser->getOption( "underline" ) ) {
861 $s .= "a { text-decoration: underline; }\n";
863 $s .= "a { text-decoration: none; }\n";
866 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
867 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
869 if ( 1 == $wgUser->getOption( "justify" ) ) {
870 $s .= "#bodyContent { text-align: justify; }\n";
872 wfProfileOut( $fname );
879 function getUserJs() {
880 $fname = 'SkinTemplate::getUserJs';
881 wfProfileIn( $fname );
883 global $wgUser, $wgStylePath;
884 $s = '/* generated javascript */';
885 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
886 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
887 $s .= wfMsg(ucfirst($this->skinname
).'.js');
889 wfProfileOut( $fname );
895 * Generic wrapper for template functions, with interface
896 * compatible with what we use of PHPTAL 0.7.
898 class QuickTemplate
{
902 function QuickTemplate() {
903 $this->data
= array();
904 $this->translator
= new MediaWiki_I18N();
910 function set( $name, $value ) {
911 $this->data
[$name] = $value;
917 function setRef($name, &$value) {
918 $this->data
[$name] =& $value;
924 function setTranslator( &$t ) {
925 $this->translator
= &$t;
932 echo "Override this function.";
939 function text( $str ) {
940 echo htmlspecialchars( $this->data
[$str] );
946 function html( $str ) {
947 echo $this->data
[$str];
953 function msg( $str ) {
954 echo htmlspecialchars( $this->translator
->translate( $str ) );
960 function msgHtml( $str ) {
961 echo $this->translator
->translate( $str );
967 function haveData( $str ) {
968 return $this->data
[$str];
974 function haveMsg( $str ) {
975 $msg = $this->translator
->translate( $str );
976 return ($msg != '-') && ($msg != ''); # ????
980 } // end of if( defined( 'MEDIAWIKI' ) )