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;
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);
291 $tpl->set('viewcount', false);
294 if ($wgPageShowWatchingUsers) {
295 $dbr =& wfGetDB( DB_SLAVE
);
296 extract( $dbr->tableNames( 'watchlist' ) );
297 $sql = "SELECT COUNT(*) AS n FROM $watchlist
298 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
299 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
300 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
301 $x = $dbr->fetchObject( $res );
302 $numberofwatchingusers = $x->n
;
303 if ($numberofwatchingusers > 0) {
304 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
306 $tpl->set('numberofwatchingusers', false);
309 $tpl->set('numberofwatchingusers', false);
312 $tpl->set('lastmod', $this->lastModified());
313 $tpl->set('copyright',$this->getCopyright());
315 $this->credits
= false;
317 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
318 require_once("Credits.php");
319 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
322 $tpl->setRef( 'credits', $this->credits
);
324 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
325 $tpl->set('copyright', $this->getCopyright());
326 $tpl->set('viewcount', false);
327 $tpl->set('lastmod', false);
328 $tpl->set('credits', false);
329 $tpl->set('numberofwatchingusers', false);
331 $tpl->set('copyright', false);
332 $tpl->set('viewcount', false);
333 $tpl->set('lastmod', false);
334 $tpl->set('credits', false);
335 $tpl->set('numberofwatchingusers', false);
337 wfProfileOut( "$fname-stuff3" );
339 wfProfileIn( "$fname-stuff4" );
340 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
341 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
342 $tpl->set( 'disclaimer', $this->disclaimerLink() );
343 $tpl->set( 'about', $this->aboutLink() );
345 $tpl->setRef( 'debug', $out->mDebugtext
);
346 $tpl->set( 'reporttime', $out->reportTime() );
347 $tpl->set( 'sitenotice', wfGetSiteNotice() );
349 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
350 $out->mBodytext
.= $printfooter ;
351 $tpl->setRef( 'bodytext', $out->mBodytext
);
354 $language_urls = array();
355 foreach( $wgOut->getLanguageLinks() as $l ) {
356 $nt = Title
::newFromText( $l );
357 $language_urls[] = array('href' => $nt->getFullURL(),
358 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
359 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
361 if(count($language_urls)) {
362 $tpl->setRef( 'language_urls', $language_urls);
364 $tpl->set('language_urls', false);
366 wfProfileOut( "$fname-stuff4" );
369 $tpl->set('personal_urls', $this->buildPersonalUrls());
370 $content_actions = $this->buildContentActionUrls();
371 $tpl->setRef('content_actions', $content_actions);
373 // XXX: attach this from javascript, same with section editing
374 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
376 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
378 $tpl->set('body_ondblclick', false);
380 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
381 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
383 $tpl->set( 'body_onload', false );
385 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
386 $tpl->set( 'nav_urls', $this->buildNavUrls() );
389 wfProfileIn( "$fname-execute" );
390 $res = $tpl->execute();
391 wfProfileOut( "$fname-execute" );
393 // result may be an error
394 $this->printOrError( $res );
395 wfProfileOut( $fname );
399 * Output the string, or print error message if it's
400 * an error object of the appropriate type.
401 * For the base class, assume strings all around.
406 function printOrError( &$str ) {
411 * build array of urls for personal toolbar
415 function buildPersonalUrls() {
416 $fname = 'SkinTemplate::buildPersonalUrls';
417 wfProfileIn( $fname );
419 /* set up the default links for the personal toolbar */
420 global $wgShowIPinHeader;
421 $personal_urls = array();
422 if ($this->loggedin
) {
423 $personal_urls['userpage'] = array(
424 'text' => $this->username
,
425 'href' => &$this->userpageUrlDetails
['href'],
426 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
428 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
429 $personal_urls['mytalk'] = array(
430 'text' => wfMsg('mytalk'),
431 'href' => &$usertalkUrlDetails['href'],
432 'class' => $usertalkUrlDetails['exists']?
false:'new'
434 $personal_urls['preferences'] = array(
435 'text' => wfMsg('preferences'),
436 'href' => $this->makeSpecialUrl('Preferences')
438 $personal_urls['watchlist'] = array(
439 'text' => wfMsg('watchlist'),
440 'href' => $this->makeSpecialUrl('Watchlist')
442 $personal_urls['mycontris'] = array(
443 'text' => wfMsg('mycontris'),
444 'href' => $this->makeSpecialUrl('Contributions','target=' . urlencode( $this->username
) )
446 $personal_urls['logout'] = array(
447 'text' => wfMsg('userlogout'),
448 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
451 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
452 $personal_urls['anonuserpage'] = array(
453 'text' => $this->username
,
454 'href' => &$this->userpageUrlDetails
['href'],
455 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
457 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
458 $personal_urls['anontalk'] = array(
459 'text' => wfMsg('anontalk'),
460 'href' => &$usertalkUrlDetails['href'],
461 'class' => $usertalkUrlDetails['exists']?
false:'new'
463 $personal_urls['anonlogin'] = array(
464 'text' => wfMsg('userlogin'),
465 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
469 $personal_urls['login'] = array(
470 'text' => wfMsg('userlogin'),
471 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
475 wfProfileOut( $fname );
476 return $personal_urls;
480 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
483 $classes[] = 'selected';
485 if( $checkEdit && $title->getArticleId() == 0 ) {
489 'class' => implode( ' ', $classes ),
490 'text' => wfMsg( $message ),
491 'href' => $title->getLocalUrl( $query ) );
494 function makeTalkUrlDetails( $name, $urlaction='' ) {
495 $title = Title
::newFromText( $name );
496 $title = $title->getTalkPage();
497 $this->checkTitle($title, $name);
499 'href' => $title->getLocalURL( $urlaction ),
500 'exists' => $title->getArticleID() != 0?
true:false
504 function makeArticleUrlDetails( $name, $urlaction='' ) {
505 $title = Title
::newFromText( $name );
506 $title= $title->getSubjectPage();
507 $this->checkTitle($title, $name);
509 'href' => $title->getLocalURL( $urlaction ),
510 'exists' => $title->getArticleID() != 0?
true:false
515 * an array of edit links by default used for the tabs
519 function buildContentActionUrls () {
520 global $wgContLang, $wgUseValidation;
521 $fname = 'SkinTemplate::buildContentActionUrls';
522 wfProfileIn( $fname );
524 global $wgUser, $wgRequest;
525 $action = $wgRequest->getText( 'action' );
526 $section = $wgRequest->getText( 'section' );
527 $oldid = $wgRequest->getVal( 'oldid' );
528 $diff = $wgRequest->getVal( 'diff' );
529 $content_actions = array();
531 if( $this->iscontent
) {
533 $nskey = $this->getNameSpaceKey();
534 $content_actions[$nskey] = $this->tabAction(
535 $this->mTitle
->getSubjectPage(),
537 !$this->mTitle
->isTalkPage() );
539 $content_actions['talk'] = $this->tabAction(
540 $this->mTitle
->getTalkPage(),
542 $this->mTitle
->isTalkPage(),
546 wfProfileIn( "$fname-edit" );
547 if ( $this->mTitle
->userCanEdit() ) {
548 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
549 $istalk = $this->mTitle
->isTalkPage();
550 $istalkclass = $istalk?
' istalk':'';
551 $content_actions['edit'] = array(
552 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
553 'text' => wfMsg('edit'),
554 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
558 $content_actions['addsection'] = array(
559 'class' => $section == 'new'?
'selected':false,
560 'text' => wfMsg('addsection'),
561 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
565 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
566 $content_actions['viewsource'] = array(
567 'class' => ($action == 'edit') ?
'selected' : false,
568 'text' => wfMsg('viewsource'),
569 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
572 wfProfileOut( "$fname-edit" );
574 wfProfileIn( "$fname-live" );
575 if ( $this->mTitle
->getArticleId() ) {
577 $content_actions['history'] = array(
578 'class' => ($action == 'history') ?
'selected' : false,
579 'text' => wfMsg('history_short'),
580 'href' => $this->mTitle
->getLocalUrl( 'action=history')
583 if($wgUser->isAllowed('protect')){
584 if(!$this->mTitle
->isProtected()){
585 $content_actions['protect'] = array(
586 'class' => ($action == 'protect') ?
'selected' : false,
587 'text' => wfMsg('protect'),
588 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
592 $content_actions['unprotect'] = array(
593 'class' => ($action == 'unprotect') ?
'selected' : false,
594 'text' => wfMsg('unprotect'),
595 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
599 if($wgUser->isAllowed('delete')){
600 $content_actions['delete'] = array(
601 'class' => ($action == 'delete') ?
'selected' : false,
602 'text' => wfMsg('delete'),
603 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
606 if ( $wgUser->isLoggedIn() ) {
607 if ( $this->mTitle
->userCanMove()) {
608 $content_actions['move'] = array(
609 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
610 'text' => wfMsg('move'),
611 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
) )
616 //article doesn't exist or is deleted
617 if($wgUser->isAllowed('delete')){
618 if( $n = $this->mTitle
->isDeleted() ) {
619 $content_actions['undelete'] = array(
621 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
622 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
627 wfProfileOut( "$fname-live" );
629 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
630 if( !$this->mTitle
->userIsWatching()) {
631 $content_actions['watch'] = array(
632 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
633 'text' => wfMsg('watch'),
634 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
637 $content_actions['unwatch'] = array(
638 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
639 'text' => wfMsg('unwatch'),
640 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
644 # Validate tab. TODO: add validation to logged-in user rights
645 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
646 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
648 {# Trying to get the current article revision through this weird stunt
649 $tid = $this->mTitle
->getArticleID();
650 $tns = $this->mTitle
->getNamespace();
651 $sql = "SELECT page_latest FROM page WHERE page_id={$tid} AND page_namespace={$tns}" ;
652 $res = wfQuery( $sql, DB_READ
);
653 if( $s = wfFetchObject( $res ) )
654 $oid = $s->page_latest
;
655 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
658 $oid = "&revision={$oid}" ;
659 $content_actions['validate'] = array(
660 'class' => ($action == 'validate') ?
'selected' : false,
661 'text' => wfMsg('val_tab'),
662 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
668 /* show special page tab */
670 $content_actions['article'] = array(
671 'class' => 'selected',
672 'text' => wfMsg('specialpage'),
677 /* show links to different language variants */
678 global $wgDisableLangConversion;
679 $variants = $wgContLang->getVariants();
680 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
681 $preferred = $wgContLang->getPreferredVariant();
684 $actstr = 'action=' . $action . '&';
686 foreach( $variants as $code ) {
687 $varname = $wgContLang->getVariantname( $code );
688 if( $varname == 'disable' )
690 $selected = ( $code == $preferred )?
'selected' : false;
691 $content_actions['varlang-' . $vcount] = array(
692 'class' => $selected,
694 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
700 wfProfileOut( $fname );
701 return $content_actions;
704 function getNavigationLinks() {
705 global $wgNavigationLinks;
706 return $wgNavigationLinks;
710 * build array of global navigation links
714 function buildNavigationUrls () {
715 $fname = 'SkinTemplate::buildNavigationUrls';
716 wfProfileIn( $fname );
718 $links = $this->getNavigationLinks();
721 foreach ( $links as $link ) {
722 $text = wfMsg( $link['text'] );
723 wfProfileIn( "$fname-{$link['text']}" );
725 $dest = wfMsgForContent( $link['href'] );
726 wfProfileIn( "$fname-{$link['text']}2" );
729 'href' => $this->makeInternalOrExternalUrl( $dest ),
730 'id' => 'n-'.$link['text']
732 wfProfileOut( "$fname-{$link['text']}2" );
734 wfProfileOut( "$fname-{$link['text']}" );
736 wfProfileOut( $fname );
741 * build array of common navigation links
745 function buildNavUrls () {
746 $fname = 'SkinTemplate::buildNavUrls';
747 wfProfileIn( $fname );
749 global $wgUser, $wgRequest;
750 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
752 $action = $wgRequest->getText( 'action' );
753 $oldid = $wgRequest->getVal( 'oldid' );
754 $diff = $wgRequest->getVal( 'diff' );
757 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
758 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
759 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
760 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
761 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
762 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
763 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
764 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
765 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
766 if( $wgEnableUploads ) {
767 if ($wgUploadNavigationUrl) {
768 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
770 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
773 $nav_urls['upload'] = false;
775 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
777 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
778 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
779 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
782 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
783 $id = User
::idFromName($this->mTitle
->getText());
784 $ip = User
::isIP($this->mTitle
->getText());
790 if($id ||
$ip) { # both anons and non-anons have contri list
791 $nav_urls['contributions'] = array(
792 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle
->getPartialURL() )
795 $nav_urls['contributions'] = false;
797 $nav_urls['emailuser'] = false;
798 if( $this->showEmailUser( $id ) ) {
799 $nav_urls['emailuser'] = array(
800 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle
->getPartialURL() )
803 wfProfileOut( $fname );
808 * Generate strings used for xml 'id' names
812 function getNameSpaceKey () {
813 switch ($this->mTitle
->getNamespace()) {
821 return 'nstab-media';
823 return 'nstab-special';
825 case NS_PROJECT_TALK
:
829 return 'nstab-image';
831 case NS_MEDIAWIKI_TALK
:
832 return 'nstab-mediawiki';
834 case NS_TEMPLATE_TALK
:
835 return 'nstab-template';
840 case NS_CATEGORY_TALK
:
841 return 'nstab-category';
850 function setupUserCss() {
851 $fname = 'SkinTemplate::setupUserCss';
852 wfProfileIn( $fname );
854 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
858 $siteargs = '&maxage=' . $wgSquidMaxage;
860 # Add user-specific code if this is a user and we allow that kind of thing
862 if ( $wgAllowUserCss && $this->loggedin
) {
863 $action = $wgRequest->getText('action');
865 # if we're previewing the CSS page, use it
866 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
867 $siteargs = "&smaxage=0&maxage=0";
868 $usercss = $wgRequest->getText('wpTextbox1');
870 $usercss = '@import "' .
871 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
872 'action=raw&ctype=text/css') . '";' ."\n";
875 $siteargs .= '&ts=' . $wgUser->mTouched
;
878 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
880 # If we use the site's dynamic CSS, throw that in, too
881 if ( $wgUseSiteCss ) {
882 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
883 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
886 # If we use any dynamic CSS, make a little CDATA block out of it.
888 if ( !empty($sitecss) ||
!empty($usercss) ) {
889 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
891 wfProfileOut( $fname );
897 function setupUserJs() {
898 $fname = 'SkinTemplate::setupUserJs';
899 wfProfileIn( $fname );
901 global $wgRequest, $wgAllowUserJs;
902 $action = $wgRequest->getText('action');
904 if( $wgAllowUserJs && $this->loggedin
) {
905 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
906 # XXX: additional security check/prompt?
907 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
909 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
912 wfProfileOut( $fname );
916 * returns css with user-specific options
920 function getUserStylesheet() {
921 $fname = 'SkinTemplate::getUserStylesheet';
922 wfProfileIn( $fname );
925 $s = "/* generated user stylesheet */\n";
926 $s .= $this->reallyDoGetUserStyles();
927 wfProfileOut( $fname );
934 function getUserJs() {
935 $fname = 'SkinTemplate::getUserJs';
936 wfProfileIn( $fname );
939 $s = '/* generated javascript */';
940 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
941 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
943 // avoid inclusion of non defined user JavaScript (with custom skins only)
944 // by checking for default message content
945 $msgKey = ucfirst($this->skinname
).'.js';
946 $userJS = wfMsg($msgKey);
947 if ('<'.$msgKey.'>' != $userJS) {
951 wfProfileOut( $fname );
957 * Generic wrapper for template functions, with interface
958 * compatible with what we use of PHPTAL 0.7.
962 class QuickTemplate
{
966 function QuickTemplate() {
967 $this->data
= array();
968 $this->translator
= new MediaWiki_I18N();
974 function set( $name, $value ) {
975 $this->data
[$name] = $value;
981 function setRef($name, &$value) {
982 $this->data
[$name] =& $value;
988 function setTranslator( &$t ) {
989 $this->translator
= &$t;
996 echo "Override this function.";
1003 function text( $str ) {
1004 echo htmlspecialchars( $this->data
[$str] );
1010 function html( $str ) {
1011 echo $this->data
[$str];
1017 function msg( $str ) {
1018 echo htmlspecialchars( $this->translator
->translate( $str ) );
1024 function msgHtml( $str ) {
1025 echo $this->translator
->translate( $str );
1029 * An ugly, ugly hack.
1032 function msgWiki( $str ) {
1033 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1035 $text = $this->translator
->translate( $str );
1036 $parserOutput = $wgParser->parse( $text, $wgTitle,
1037 $wgOut->mParserOptions
, true );
1038 echo $parserOutput->getText();
1044 function haveData( $str ) {
1045 return $this->data
[$str];
1051 function haveMsg( $str ) {
1052 $msg = $this->translator
->translate( $str );
1053 return ($msg != '-') && ($msg != ''); # ????
1057 } // end of if( defined( 'MEDIAWIKI' ) )