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, $wgJsMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses;
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( 'jsmimetype', $wgJsMimeType );
222 $tpl->setRef( 'charset', $wgOutputEncoding );
223 $tpl->set( 'headlinks', $out->getHeadLinks() );
224 $tpl->setRef( 'wgScript', $wgScript );
225 $tpl->setRef( 'skinname', $this->skinname
);
226 $tpl->setRef( 'stylename', $this->stylename
);
227 $tpl->setRef( 'loggedin', $this->loggedin
);
228 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
229 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
230 /* XXX currently unused, might get useful later
231 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
232 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
233 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
234 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
235 $tpl->set( "helppage", wfMsg('helppage'));
237 $tpl->set( 'searchaction', $this->escapeSearchLink() );
238 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
239 $tpl->setRef( 'stylepath', $wgStylePath );
240 $tpl->setRef( 'logopath', $wgLogo );
241 $tpl->setRef( "lang", $wgContLanguageCode );
242 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
243 $tpl->set( 'rtl', $wgContLang->isRTL() );
244 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
245 $tpl->setRef( 'username', $this->username
);
246 $tpl->setRef( 'userpage', $this->userpage
);
247 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
248 $tpl->setRef( 'usercss', $this->usercss
);
249 $tpl->setRef( 'userjs', $this->userjs
);
250 $tpl->setRef( 'userjsprev', $this->userjsprev
);
253 if($this->loggedin
) {
254 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
256 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
259 $tpl->set('jsvarurl', false);
261 if( $wgUser->getNewtalk() ) {
262 $usertitle = $this->mUser
->getUserPage();
263 $usertalktitle = $usertitle->getTalkPage();
264 if( !$usertalktitle->equals( $this->mTitle
) ) {
265 $ntl = wfMsg( 'newmessages',
266 $this->makeKnownLinkObj(
268 wfMsg('newmessageslink')
272 $wgOut->setSquidMaxage(0);
277 wfProfileOut( "$fname-stuff2" );
279 wfProfileIn( "$fname-stuff3" );
280 $tpl->setRef( 'newtalk', $ntl );
281 $tpl->setRef( 'skin', $this);
282 $tpl->set( 'logo', $this->logoText() );
283 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
284 if ( !$wgDisableCounters ) {
285 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
287 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
289 $tpl->set('viewcount', false);
292 $tpl->set('viewcount', false);
295 if ($wgPageShowWatchingUsers) {
296 $dbr =& wfGetDB( DB_SLAVE
);
297 extract( $dbr->tableNames( 'watchlist' ) );
298 $sql = "SELECT COUNT(*) AS n FROM $watchlist
299 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
300 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
301 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
302 $x = $dbr->fetchObject( $res );
303 $numberofwatchingusers = $x->n
;
304 if ($numberofwatchingusers > 0) {
305 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
307 $tpl->set('numberofwatchingusers', false);
310 $tpl->set('numberofwatchingusers', false);
313 $tpl->set('lastmod', $this->lastModified());
314 $tpl->set('copyright',$this->getCopyright());
316 $this->credits
= false;
318 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
319 require_once("Credits.php");
320 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
323 $tpl->setRef( 'credits', $this->credits
);
325 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
326 $tpl->set('copyright', $this->getCopyright());
327 $tpl->set('viewcount', false);
328 $tpl->set('lastmod', false);
329 $tpl->set('credits', false);
330 $tpl->set('numberofwatchingusers', false);
332 $tpl->set('copyright', false);
333 $tpl->set('viewcount', false);
334 $tpl->set('lastmod', false);
335 $tpl->set('credits', false);
336 $tpl->set('numberofwatchingusers', false);
338 wfProfileOut( "$fname-stuff3" );
340 wfProfileIn( "$fname-stuff4" );
341 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
342 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
343 $tpl->set( 'disclaimer', $this->disclaimerLink() );
344 $tpl->set( 'about', $this->aboutLink() );
346 $tpl->setRef( 'debug', $out->mDebugtext
);
347 $tpl->set( 'reporttime', $out->reportTime() );
348 $tpl->set( 'sitenotice', wfGetSiteNotice() );
350 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
351 $out->mBodytext
.= $printfooter ;
352 $tpl->setRef( 'bodytext', $out->mBodytext
);
355 $language_urls = array();
356 foreach( $wgOut->getLanguageLinks() as $l ) {
357 $nt = Title
::newFromText( $l );
358 $language_urls[] = array('href' => $nt->getFullURL(),
359 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
360 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
362 if(count($language_urls)) {
363 $tpl->setRef( 'language_urls', $language_urls);
365 $tpl->set('language_urls', false);
367 wfProfileOut( "$fname-stuff4" );
370 $tpl->set('personal_urls', $this->buildPersonalUrls());
371 $content_actions = $this->buildContentActionUrls();
372 $tpl->setRef('content_actions', $content_actions);
374 // XXX: attach this from javascript, same with section editing
375 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
377 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
379 $tpl->set('body_ondblclick', false);
381 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
382 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
384 $tpl->set( 'body_onload', false );
386 $tpl->set( 'navigation_urls', $this->getNavigationLinks() );
387 $tpl->set( 'nav_urls', $this->buildNavUrls() );
390 wfProfileIn( "$fname-execute" );
391 $res = $tpl->execute();
392 wfProfileOut( "$fname-execute" );
394 // result may be an error
395 $this->printOrError( $res );
396 wfProfileOut( $fname );
400 * Output the string, or print error message if it's
401 * an error object of the appropriate type.
402 * For the base class, assume strings all around.
407 function printOrError( &$str ) {
412 * build array of urls for personal toolbar
416 function buildPersonalUrls() {
417 $fname = 'SkinTemplate::buildPersonalUrls';
418 wfProfileIn( $fname );
420 /* set up the default links for the personal toolbar */
421 global $wgShowIPinHeader;
422 $personal_urls = array();
423 if ($this->loggedin
) {
424 $personal_urls['userpage'] = array(
425 'text' => $this->username
,
426 'href' => &$this->userpageUrlDetails
['href'],
427 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
429 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
430 $personal_urls['mytalk'] = array(
431 'text' => wfMsg('mytalk'),
432 'href' => &$usertalkUrlDetails['href'],
433 'class' => $usertalkUrlDetails['exists']?
false:'new'
435 $personal_urls['preferences'] = array(
436 'text' => wfMsg('preferences'),
437 'href' => $this->makeSpecialUrl('Preferences')
439 $personal_urls['watchlist'] = array(
440 'text' => wfMsg('watchlist'),
441 'href' => $this->makeSpecialUrl('Watchlist')
443 $personal_urls['mycontris'] = array(
444 'text' => wfMsg('mycontris'),
445 'href' => $this->makeSpecialUrl("Contributions/$this->username")
447 $personal_urls['logout'] = array(
448 'text' => wfMsg('userlogout'),
449 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
452 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
453 $personal_urls['anonuserpage'] = array(
454 'text' => $this->username
,
455 'href' => &$this->userpageUrlDetails
['href'],
456 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
458 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
459 $personal_urls['anontalk'] = array(
460 'text' => wfMsg('anontalk'),
461 'href' => &$usertalkUrlDetails['href'],
462 'class' => $usertalkUrlDetails['exists']?
false:'new'
464 $personal_urls['anonlogin'] = array(
465 'text' => wfMsg('userlogin'),
466 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
470 $personal_urls['login'] = array(
471 'text' => wfMsg('userlogin'),
472 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
476 wfProfileOut( $fname );
477 return $personal_urls;
481 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
484 $classes[] = 'selected';
486 if( $checkEdit && $title->getArticleId() == 0 ) {
490 'class' => implode( ' ', $classes ),
491 'text' => wfMsg( $message ),
492 'href' => $title->getLocalUrl( $query ) );
495 function makeTalkUrlDetails( $name, $urlaction='' ) {
496 $title = Title
::newFromText( $name );
497 $title = $title->getTalkPage();
498 $this->checkTitle($title, $name);
500 'href' => $title->getLocalURL( $urlaction ),
501 'exists' => $title->getArticleID() != 0?
true:false
505 function makeArticleUrlDetails( $name, $urlaction='' ) {
506 $title = Title
::newFromText( $name );
507 $title= $title->getSubjectPage();
508 $this->checkTitle($title, $name);
510 'href' => $title->getLocalURL( $urlaction ),
511 'exists' => $title->getArticleID() != 0?
true:false
516 * an array of edit links by default used for the tabs
520 function buildContentActionUrls () {
521 global $wgContLang, $wgUseValidation, $wgDBprefix;
522 $fname = 'SkinTemplate::buildContentActionUrls';
523 wfProfileIn( $fname );
525 global $wgUser, $wgRequest;
526 $action = $wgRequest->getText( 'action' );
527 $section = $wgRequest->getText( 'section' );
528 $oldid = $wgRequest->getVal( 'oldid' );
529 $diff = $wgRequest->getVal( 'diff' );
530 $content_actions = array();
532 if( $this->iscontent
) {
534 $nskey = $this->getNameSpaceKey();
535 $content_actions[$nskey] = $this->tabAction(
536 $this->mTitle
->getSubjectPage(),
538 !$this->mTitle
->isTalkPage() );
540 $content_actions['talk'] = $this->tabAction(
541 $this->mTitle
->getTalkPage(),
543 $this->mTitle
->isTalkPage(),
547 wfProfileIn( "$fname-edit" );
548 if ( $this->mTitle
->userCanEdit() ) {
549 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
550 $istalk = $this->mTitle
->isTalkPage();
551 $istalkclass = $istalk?
' istalk':'';
552 $content_actions['edit'] = array(
553 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
554 'text' => wfMsg('edit'),
555 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
559 $content_actions['addsection'] = array(
560 'class' => $section == 'new'?
'selected':false,
561 'text' => wfMsg('addsection'),
562 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
566 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
567 $content_actions['viewsource'] = array(
568 'class' => ($action == 'edit') ?
'selected' : false,
569 'text' => wfMsg('viewsource'),
570 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
573 wfProfileOut( "$fname-edit" );
575 wfProfileIn( "$fname-live" );
576 if ( $this->mTitle
->getArticleId() ) {
578 $content_actions['history'] = array(
579 'class' => ($action == 'history') ?
'selected' : false,
580 'text' => wfMsg('history_short'),
581 'href' => $this->mTitle
->getLocalUrl( 'action=history')
584 if($wgUser->isAllowed('protect')){
585 if(!$this->mTitle
->isProtected()){
586 $content_actions['protect'] = array(
587 'class' => ($action == 'protect') ?
'selected' : false,
588 'text' => wfMsg('protect'),
589 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
593 $content_actions['unprotect'] = array(
594 'class' => ($action == 'unprotect') ?
'selected' : false,
595 'text' => wfMsg('unprotect'),
596 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
600 if($wgUser->isAllowed('delete')){
601 $content_actions['delete'] = array(
602 'class' => ($action == 'delete') ?
'selected' : false,
603 'text' => wfMsg('delete'),
604 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
607 if ( $wgUser->isLoggedIn() ) {
608 if ( $this->mTitle
->userCanMove()) {
609 $content_actions['move'] = array(
610 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
611 'text' => wfMsg('move'),
612 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
617 //article doesn't exist or is deleted
618 if($wgUser->isAllowed('delete')){
619 if( $n = $this->mTitle
->isDeleted() ) {
620 $content_actions['undelete'] = array(
622 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
623 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
628 wfProfileOut( "$fname-live" );
630 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
631 if( !$this->mTitle
->userIsWatching()) {
632 $content_actions['watch'] = array(
633 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
634 'text' => wfMsg('watch'),
635 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
638 $content_actions['unwatch'] = array(
639 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
640 'text' => wfMsg('unwatch'),
641 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
645 # Validate tab. TODO: add validation to logged-in user rights
646 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
647 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
649 {# Trying to get the current article revision through this weird stunt
650 $tid = $this->mTitle
->getArticleID();
651 $tns = $this->mTitle
->getNamespace();
652 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
653 $res = wfQuery( $sql, DB_READ
);
654 if( $s = wfFetchObject( $res ) )
655 $oid = $s->page_latest
;
656 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
659 $oid = "&revision={$oid}" ;
660 $content_actions['validate'] = array(
661 'class' => ($action == 'validate') ?
'selected' : false,
662 'text' => wfMsg('val_tab'),
663 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
669 /* show special page tab */
671 $content_actions['article'] = array(
672 'class' => 'selected',
673 'text' => wfMsg('specialpage'),
678 /* show links to different language variants */
679 global $wgDisableLangConversion;
680 $variants = $wgContLang->getVariants();
681 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
682 $preferred = $wgContLang->getPreferredVariant();
685 $actstr = 'action=' . $action . '&';
687 foreach( $variants as $code ) {
688 $varname = $wgContLang->getVariantname( $code );
689 if( $varname == 'disable' )
691 $selected = ( $code == $preferred )?
'selected' : false;
692 $content_actions['varlang-' . $vcount] = array(
693 'class' => $selected,
695 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
701 wfProfileOut( $fname );
702 return $content_actions;
705 function getNavigationLinks() {
706 global $wgParser, $wgTitle;
707 $text = wfMsgForContent( 'navbar' );
708 $options = ParserOptions
::newFromUser( $temp = NULL );
709 $parserOutput = $wgParser->parse( $text, $wgTitle, $options, true );
710 return $parserOutput->getText();
714 * build array of common navigation links
718 function buildNavUrls () {
719 $fname = 'SkinTemplate::buildNavUrls';
720 wfProfileIn( $fname );
722 global $wgUser, $wgRequest;
723 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
725 $action = $wgRequest->getText( 'action' );
726 $oldid = $wgRequest->getVal( 'oldid' );
727 $diff = $wgRequest->getVal( 'diff' );
730 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
731 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
732 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
733 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
734 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
735 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
736 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
737 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
738 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
739 if( $wgEnableUploads ) {
740 if ($wgUploadNavigationUrl) {
741 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
743 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
746 $nav_urls['upload'] = false;
748 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
750 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
751 $nav_urls['whatlinkshere'] = array(
752 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
754 $nav_urls['recentchangeslinked'] = array(
755 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
759 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
760 $id = User
::idFromName($this->mTitle
->getText());
761 $ip = User
::isIP($this->mTitle
->getText());
767 if($id ||
$ip) { # both anons and non-anons have contri list
768 $nav_urls['contributions'] = array(
769 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
772 $nav_urls['contributions'] = false;
774 $nav_urls['emailuser'] = false;
775 if( $this->showEmailUser( $id ) ) {
776 $nav_urls['emailuser'] = array(
777 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
780 wfProfileOut( $fname );
785 * Generate strings used for xml 'id' names
789 function getNameSpaceKey () {
790 switch ($this->mTitle
->getNamespace()) {
798 return 'nstab-media';
800 return 'nstab-special';
802 case NS_PROJECT_TALK
:
806 return 'nstab-image';
808 case NS_MEDIAWIKI_TALK
:
809 return 'nstab-mediawiki';
811 case NS_TEMPLATE_TALK
:
812 return 'nstab-template';
817 case NS_CATEGORY_TALK
:
818 return 'nstab-category';
827 function setupUserCss() {
828 $fname = 'SkinTemplate::setupUserCss';
829 wfProfileIn( $fname );
831 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
835 $siteargs = '&maxage=' . $wgSquidMaxage;
837 # Add user-specific code if this is a user and we allow that kind of thing
839 if ( $wgAllowUserCss && $this->loggedin
) {
840 $action = $wgRequest->getText('action');
842 # if we're previewing the CSS page, use it
843 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
844 $siteargs = "&smaxage=0&maxage=0";
845 $usercss = $wgRequest->getText('wpTextbox1');
847 $usercss = '@import "' .
848 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
849 'action=raw&ctype=text/css') . '";' ."\n";
852 $siteargs .= '&ts=' . $wgUser->mTouched
;
855 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
857 # If we use the site's dynamic CSS, throw that in, too
858 if ( $wgUseSiteCss ) {
859 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
860 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
863 # If we use any dynamic CSS, make a little CDATA block out of it.
865 if ( !empty($sitecss) ||
!empty($usercss) ) {
866 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
868 wfProfileOut( $fname );
874 function setupUserJs() {
875 $fname = 'SkinTemplate::setupUserJs';
876 wfProfileIn( $fname );
878 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
879 $action = $wgRequest->getText('action');
881 if( $wgAllowUserJs && $this->loggedin
) {
882 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
883 # XXX: additional security check/prompt?
884 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
886 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
889 wfProfileOut( $fname );
893 * returns css with user-specific options
897 function getUserStylesheet() {
898 $fname = 'SkinTemplate::getUserStylesheet';
899 wfProfileIn( $fname );
902 $s = "/* generated user stylesheet */\n";
903 $s .= $this->reallyDoGetUserStyles();
904 wfProfileOut( $fname );
911 function getUserJs() {
912 $fname = 'SkinTemplate::getUserJs';
913 wfProfileIn( $fname );
916 $s = '/* generated javascript */';
917 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
918 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
920 // avoid inclusion of non defined user JavaScript (with custom skins only)
921 // by checking for default message content
922 $msgKey = ucfirst($this->skinname
).'.js';
923 $userJS = wfMsg($msgKey);
924 if ('<'.$msgKey.'>' != $userJS) {
928 wfProfileOut( $fname );
934 * Generic wrapper for template functions, with interface
935 * compatible with what we use of PHPTAL 0.7.
939 class QuickTemplate
{
943 function QuickTemplate() {
944 $this->data
= array();
945 $this->translator
= new MediaWiki_I18N();
951 function set( $name, $value ) {
952 $this->data
[$name] = $value;
958 function setRef($name, &$value) {
959 $this->data
[$name] =& $value;
965 function setTranslator( &$t ) {
966 $this->translator
= &$t;
973 echo "Override this function.";
980 function text( $str ) {
981 echo htmlspecialchars( $this->data
[$str] );
987 function html( $str ) {
988 echo $this->data
[$str];
994 function msg( $str ) {
995 echo htmlspecialchars( $this->translator
->translate( $str ) );
1001 function msgHtml( $str ) {
1002 echo $this->translator
->translate( $str );
1006 * An ugly, ugly hack.
1009 function msgWiki( $str ) {
1010 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1012 $text = $this->translator
->translate( $str );
1013 $parserOutput = $wgParser->parse( $text, $wgTitle,
1014 $wgOut->mParserOptions
, true );
1015 echo $parserOutput->getText();
1021 function haveData( $str ) {
1022 return $this->data
[$str];
1028 function haveMsg( $str ) {
1029 $msg = $this->translator
->translate( $str );
1030 return ($msg != '-') && ($msg != ''); # ????
1034 } // end of if( defined( 'MEDIAWIKI' ) )