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, $wgHideInterlanguageLinks;
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->set( 'printable', $wgRequest->getBool( 'printable' ) );
228 $tpl->setRef( 'loggedin', $this->loggedin
);
229 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
230 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
231 /* XXX currently unused, might get useful later
232 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
233 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
234 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
235 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
236 $tpl->set( "helppage", wfMsg('helppage'));
238 $tpl->set( 'searchaction', $this->escapeSearchLink() );
239 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
240 $tpl->setRef( 'stylepath', $wgStylePath );
241 $tpl->setRef( 'logopath', $wgLogo );
242 $tpl->setRef( "lang", $wgContLanguageCode );
243 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
244 $tpl->set( 'rtl', $wgContLang->isRTL() );
245 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
246 $tpl->setRef( 'username', $this->username
);
247 $tpl->setRef( 'userpage', $this->userpage
);
248 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
249 $tpl->setRef( 'usercss', $this->usercss
);
250 $tpl->setRef( 'userjs', $this->userjs
);
251 $tpl->setRef( 'userjsprev', $this->userjsprev
);
254 if($this->loggedin
) {
255 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
257 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
260 $tpl->set('jsvarurl', false);
262 if( $wgUser->getNewtalk() ) {
263 $usertitle = $this->mUser
->getUserPage();
264 $usertalktitle = $usertitle->getTalkPage();
265 if( !$usertalktitle->equals( $this->mTitle
) ) {
266 $ntl = wfMsg( 'newmessages',
267 $this->makeKnownLinkObj(
269 wfMsg('newmessageslink')
273 $wgOut->setSquidMaxage(0);
278 wfProfileOut( "$fname-stuff2" );
280 wfProfileIn( "$fname-stuff3" );
281 $tpl->setRef( 'newtalk', $ntl );
282 $tpl->setRef( 'skin', $this);
283 $tpl->set( 'logo', $this->logoText() );
284 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
285 if ( !$wgDisableCounters ) {
286 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
288 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
290 $tpl->set('viewcount', false);
293 $tpl->set('viewcount', false);
296 if ($wgPageShowWatchingUsers) {
297 $dbr =& wfGetDB( DB_SLAVE
);
298 extract( $dbr->tableNames( 'watchlist' ) );
299 $sql = "SELECT COUNT(*) AS n FROM $watchlist
300 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
301 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
302 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
303 $x = $dbr->fetchObject( $res );
304 $numberofwatchingusers = $x->n
;
305 if ($numberofwatchingusers > 0) {
306 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
308 $tpl->set('numberofwatchingusers', false);
311 $tpl->set('numberofwatchingusers', false);
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);
322 $tpl->set('lastmod', $this->lastModified());
325 $tpl->setRef( 'credits', $this->credits
);
327 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
328 $tpl->set('copyright', $this->getCopyright());
329 $tpl->set('viewcount', false);
330 $tpl->set('lastmod', false);
331 $tpl->set('credits', false);
332 $tpl->set('numberofwatchingusers', false);
334 $tpl->set('copyright', false);
335 $tpl->set('viewcount', false);
336 $tpl->set('lastmod', false);
337 $tpl->set('credits', false);
338 $tpl->set('numberofwatchingusers', false);
340 wfProfileOut( "$fname-stuff3" );
342 wfProfileIn( "$fname-stuff4" );
343 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
344 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
345 $tpl->set( 'disclaimer', $this->disclaimerLink() );
346 $tpl->set( 'about', $this->aboutLink() );
348 $tpl->setRef( 'debug', $out->mDebugtext
);
349 $tpl->set( 'reporttime', $out->reportTime() );
350 $tpl->set( 'sitenotice', wfGetSiteNotice() );
352 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
353 $out->mBodytext
.= $printfooter ;
354 $tpl->setRef( 'bodytext', $out->mBodytext
);
357 $language_urls = array();
359 if ( !$wgHideInterlanguageLinks ) {
360 foreach( $wgOut->getLanguageLinks() as $l ) {
361 $nt = Title
::newFromText( $l );
362 $language_urls[] = array('href' => $nt->getFullURL(),
363 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
364 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
367 if(count($language_urls)) {
368 $tpl->setRef( 'language_urls', $language_urls);
370 $tpl->set('language_urls', false);
372 wfProfileOut( "$fname-stuff4" );
375 $tpl->set('personal_urls', $this->buildPersonalUrls());
376 $content_actions = $this->buildContentActionUrls();
377 $tpl->setRef('content_actions', $content_actions);
379 // XXX: attach this from javascript, same with section editing
380 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
382 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
384 $tpl->set('body_ondblclick', false);
386 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
387 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
389 $tpl->set( 'body_onload', false );
391 $tpl->set( 'sidebar', $this->buildSidebar() );
392 $tpl->set( 'nav_urls', $this->buildNavUrls() );
395 wfProfileIn( "$fname-execute" );
396 $res = $tpl->execute();
397 wfProfileOut( "$fname-execute" );
399 // result may be an error
400 $this->printOrError( $res );
401 wfProfileOut( $fname );
405 * Output the string, or print error message if it's
406 * an error object of the appropriate type.
407 * For the base class, assume strings all around.
412 function printOrError( &$str ) {
417 * build array of urls for personal toolbar
421 function buildPersonalUrls() {
422 $fname = 'SkinTemplate::buildPersonalUrls';
423 wfProfileIn( $fname );
425 /* set up the default links for the personal toolbar */
426 global $wgShowIPinHeader;
427 $personal_urls = array();
428 if ($this->loggedin
) {
429 $personal_urls['userpage'] = array(
430 'text' => $this->username
,
431 'href' => &$this->userpageUrlDetails
['href'],
432 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
434 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
435 $personal_urls['mytalk'] = array(
436 'text' => wfMsg('mytalk'),
437 'href' => &$usertalkUrlDetails['href'],
438 'class' => $usertalkUrlDetails['exists']?
false:'new'
440 $personal_urls['preferences'] = array(
441 'text' => wfMsg('preferences'),
442 'href' => $this->makeSpecialUrl('Preferences')
444 $personal_urls['watchlist'] = array(
445 'text' => wfMsg('watchlist'),
446 'href' => $this->makeSpecialUrl('Watchlist')
448 $personal_urls['mycontris'] = array(
449 'text' => wfMsg('mycontris'),
450 'href' => $this->makeSpecialUrl("Contributions/$this->username")
452 $personal_urls['logout'] = array(
453 'text' => wfMsg('userlogout'),
454 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
457 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
458 $personal_urls['anonuserpage'] = array(
459 'text' => $this->username
,
460 'href' => &$this->userpageUrlDetails
['href'],
461 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
463 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
464 $personal_urls['anontalk'] = array(
465 'text' => wfMsg('anontalk'),
466 'href' => &$usertalkUrlDetails['href'],
467 'class' => $usertalkUrlDetails['exists']?
false:'new'
469 $personal_urls['anonlogin'] = array(
470 'text' => wfMsg('userlogin'),
471 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
475 $personal_urls['login'] = array(
476 'text' => wfMsg('userlogin'),
477 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
481 wfProfileOut( $fname );
482 return $personal_urls;
486 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
489 $classes[] = 'selected';
491 if( $checkEdit && $title->getArticleId() == 0 ) {
495 'class' => implode( ' ', $classes ),
496 'text' => wfMsg( $message ),
497 'href' => $title->getLocalUrl( $query ) );
500 function makeTalkUrlDetails( $name, $urlaction='' ) {
501 $title = Title
::newFromText( $name );
502 $title = $title->getTalkPage();
503 $this->checkTitle($title, $name);
505 'href' => $title->getLocalURL( $urlaction ),
506 'exists' => $title->getArticleID() != 0?
true:false
510 function makeArticleUrlDetails( $name, $urlaction='' ) {
511 $title = Title
::newFromText( $name );
512 $title= $title->getSubjectPage();
513 $this->checkTitle($title, $name);
515 'href' => $title->getLocalURL( $urlaction ),
516 'exists' => $title->getArticleID() != 0?
true:false
521 * an array of edit links by default used for the tabs
525 function buildContentActionUrls () {
526 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
527 $fname = 'SkinTemplate::buildContentActionUrls';
528 wfProfileIn( $fname );
530 global $wgUser, $wgRequest;
531 $action = $wgRequest->getText( 'action' );
532 $section = $wgRequest->getText( 'section' );
533 $oldid = $wgRequest->getVal( 'oldid' );
534 $diff = $wgRequest->getVal( 'diff' );
535 $content_actions = array();
537 if( $this->iscontent
) {
539 $nskey = $this->getNameSpaceKey();
540 $content_actions[$nskey] = $this->tabAction(
541 $this->mTitle
->getSubjectPage(),
543 !$this->mTitle
->isTalkPage() );
545 $content_actions['talk'] = $this->tabAction(
546 $this->mTitle
->getTalkPage(),
548 $this->mTitle
->isTalkPage(),
552 wfProfileIn( "$fname-edit" );
553 if ( $this->mTitle
->userCanEdit() ) {
554 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
555 $istalk = $this->mTitle
->isTalkPage();
556 $istalkclass = $istalk?
' istalk':'';
557 $content_actions['edit'] = array(
558 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
559 'text' => wfMsg('edit'),
560 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
564 $content_actions['addsection'] = array(
565 'class' => $section == 'new'?
'selected':false,
566 'text' => wfMsg('addsection'),
567 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
571 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
572 $content_actions['viewsource'] = array(
573 'class' => ($action == 'edit') ?
'selected' : false,
574 'text' => wfMsg('viewsource'),
575 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
578 wfProfileOut( "$fname-edit" );
580 wfProfileIn( "$fname-live" );
581 if ( $this->mTitle
->getArticleId() ) {
583 $content_actions['history'] = array(
584 'class' => ($action == 'history') ?
'selected' : false,
585 'text' => wfMsg('history_short'),
586 'href' => $this->mTitle
->getLocalUrl( 'action=history')
589 if($wgUser->isAllowed('protect')){
590 if(!$this->mTitle
->isProtected()){
591 $content_actions['protect'] = array(
592 'class' => ($action == 'protect') ?
'selected' : false,
593 'text' => wfMsg('protect'),
594 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
598 $content_actions['unprotect'] = array(
599 'class' => ($action == 'unprotect') ?
'selected' : false,
600 'text' => wfMsg('unprotect'),
601 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
605 if($wgUser->isAllowed('delete')){
606 $content_actions['delete'] = array(
607 'class' => ($action == 'delete') ?
'selected' : false,
608 'text' => wfMsg('delete'),
609 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
612 if ( $wgUser->isLoggedIn() ) {
613 if ( $this->mTitle
->userCanMove()) {
614 $content_actions['move'] = array(
615 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
616 'text' => wfMsg('move'),
617 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
622 //article doesn't exist or is deleted
623 if($wgUser->isAllowed('delete')){
624 if( $n = $this->mTitle
->isDeleted() ) {
625 $content_actions['undelete'] = array(
627 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
628 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
633 wfProfileOut( "$fname-live" );
635 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
636 if( !$this->mTitle
->userIsWatching()) {
637 $content_actions['watch'] = array(
638 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
639 'text' => wfMsg('watch'),
640 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
643 $content_actions['unwatch'] = array(
644 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
645 'text' => wfMsg('unwatch'),
646 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
651 if( $wgUser->isLoggedIn() ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
652 # Validate tab. TODO: add validation to logged-in user rights
653 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
654 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
656 {# Trying to get the current article revision through this weird stunt
657 $tid = $this->mTitle
->getArticleID();
658 $tns = $this->mTitle
->getNamespace();
659 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
660 $res = wfQuery( $sql, DB_READ
);
661 if( $s = wfFetchObject( $res ) )
662 $oid = $s->page_latest
;
663 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
666 $oid = "&revision={$oid}" ;
667 $content_actions['validate'] = array(
668 'class' => ($action == 'validate') ?
'selected' : false,
669 'text' => wfMsg('val_tab'),
670 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
676 /* show special page tab */
678 $content_actions['article'] = array(
679 'class' => 'selected',
680 'text' => wfMsg('specialpage'),
681 'href' => $this->mTitle
->getLocalUrl(), // @bug 2457
685 /* show links to different language variants */
686 global $wgDisableLangConversion;
687 $variants = $wgContLang->getVariants();
688 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
689 $preferred = $wgContLang->getPreferredVariant();
692 $actstr = 'action=' . $action . '&';
694 foreach( $variants as $code ) {
695 $varname = $wgContLang->getVariantname( $code );
696 if( $varname == 'disable' )
698 $selected = ( $code == $preferred )?
'selected' : false;
699 $content_actions['varlang-' . $vcount] = array(
700 'class' => $selected,
702 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
708 // A print stylesheet is attached to all pages, but nobody ever
709 // figures that out. :) Add a link...
710 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
711 $content_actions['print'] = array(
713 'text' => wfMsg( 'printableversion' ),
714 'href' => $wgRequest->appendQuery( 'printable=yes' ) );
717 wfProfileOut( $fname );
718 return $content_actions;
722 * Build an array that represents the sidebar(s), the navigation bar among them
727 function buildSidebar() {
728 $fname = 'SkinTemplate::buildSidebar';
729 wfProfileIn( $fname );
732 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
733 foreach ($lines as $line) {
734 if (strpos($line, '*') !== 0)
736 if (strpos($line, '**') !== 0) {
737 $line = trim($line, '* ');
740 if (strpos($line, '|') !== false) { // sanity check
741 $line = explode( '|' , trim($line, '* '), 2 );
742 $bar[$heading][] = array(
743 'text' => wfMsg( $line[1] ),
744 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $line[0] ) ),
745 'id' => 'n-' . $line[1],
751 wfProfileOut( $fname );
756 * build array of common navigation links
760 function buildNavUrls () {
761 $fname = 'SkinTemplate::buildNavUrls';
762 wfProfileIn( $fname );
764 global $wgUser, $wgRequest;
765 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
767 $action = $wgRequest->getText( 'action' );
768 $oldid = $wgRequest->getVal( 'oldid' );
769 $diff = $wgRequest->getVal( 'diff' );
772 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
773 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
774 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
775 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
776 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
777 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
778 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
779 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
780 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
781 if( $wgEnableUploads ) {
782 if ($wgUploadNavigationUrl) {
783 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
785 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
788 $nav_urls['upload'] = false;
790 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
792 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
793 $nav_urls['whatlinkshere'] = array(
794 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
796 $nav_urls['recentchangeslinked'] = array(
797 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
801 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
802 $id = User
::idFromName($this->mTitle
->getText());
803 $ip = User
::isIP($this->mTitle
->getText());
809 if($id ||
$ip) { # both anons and non-anons have contri list
810 $nav_urls['contributions'] = array(
811 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
814 $nav_urls['contributions'] = false;
816 $nav_urls['emailuser'] = false;
817 if( $this->showEmailUser( $id ) ) {
818 $nav_urls['emailuser'] = array(
819 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
822 wfProfileOut( $fname );
827 * Generate strings used for xml 'id' names
831 function getNameSpaceKey () {
832 switch ($this->mTitle
->getNamespace()) {
840 return 'nstab-media';
842 return 'nstab-special';
844 case NS_PROJECT_TALK
:
848 return 'nstab-image';
850 case NS_MEDIAWIKI_TALK
:
851 return 'nstab-mediawiki';
853 case NS_TEMPLATE_TALK
:
854 return 'nstab-template';
859 case NS_CATEGORY_TALK
:
860 return 'nstab-category';
869 function setupUserCss() {
870 $fname = 'SkinTemplate::setupUserCss';
871 wfProfileIn( $fname );
873 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
877 $siteargs = '&maxage=' . $wgSquidMaxage;
879 # Add user-specific code if this is a user and we allow that kind of thing
881 if ( $wgAllowUserCss && $this->loggedin
) {
882 $action = $wgRequest->getText('action');
884 # if we're previewing the CSS page, use it
885 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
886 $siteargs = "&smaxage=0&maxage=0";
887 $usercss = $wgRequest->getText('wpTextbox1');
889 $usercss = '@import "' .
890 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
891 'action=raw&ctype=text/css') . '";' ."\n";
894 $siteargs .= '&ts=' . $wgUser->mTouched
;
897 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
899 # If we use the site's dynamic CSS, throw that in, too
900 if ( $wgUseSiteCss ) {
901 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
902 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
905 # If we use any dynamic CSS, make a little CDATA block out of it.
907 if ( !empty($sitecss) ||
!empty($usercss) ) {
908 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
910 wfProfileOut( $fname );
916 function setupUserJs() {
917 $fname = 'SkinTemplate::setupUserJs';
918 wfProfileIn( $fname );
920 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
921 $action = $wgRequest->getText('action');
923 if( $wgAllowUserJs && $this->loggedin
) {
924 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
925 # XXX: additional security check/prompt?
926 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
928 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
931 wfProfileOut( $fname );
935 * returns css with user-specific options
939 function getUserStylesheet() {
940 $fname = 'SkinTemplate::getUserStylesheet';
941 wfProfileIn( $fname );
944 $s = "/* generated user stylesheet */\n";
945 $s .= $this->reallyDoGetUserStyles();
946 wfProfileOut( $fname );
953 function getUserJs() {
954 $fname = 'SkinTemplate::getUserJs';
955 wfProfileIn( $fname );
958 $s = '/* generated javascript */';
959 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
960 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
962 // avoid inclusion of non defined user JavaScript (with custom skins only)
963 // by checking for default message content
964 $msgKey = ucfirst($this->skinname
).'.js';
965 $userJS = wfMsg($msgKey);
966 if ('<'.$msgKey.'>' != $userJS) {
970 wfProfileOut( $fname );
976 * Generic wrapper for template functions, with interface
977 * compatible with what we use of PHPTAL 0.7.
981 class QuickTemplate
{
985 function QuickTemplate() {
986 $this->data
= array();
987 $this->translator
= new MediaWiki_I18N();
993 function set( $name, $value ) {
994 $this->data
[$name] = $value;
1000 function setRef($name, &$value) {
1001 $this->data
[$name] =& $value;
1007 function setTranslator( &$t ) {
1008 $this->translator
= &$t;
1014 function execute() {
1015 echo "Override this function.";
1022 function text( $str ) {
1023 echo htmlspecialchars( $this->data
[$str] );
1029 function html( $str ) {
1030 echo $this->data
[$str];
1036 function msg( $str ) {
1037 echo htmlspecialchars( $this->translator
->translate( $str ) );
1043 function msgHtml( $str ) {
1044 echo $this->translator
->translate( $str );
1048 * An ugly, ugly hack.
1051 function msgWiki( $str ) {
1052 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1054 $text = $this->translator
->translate( $str );
1055 $parserOutput = $wgParser->parse( $text, $wgTitle,
1056 $wgOut->mParserOptions
, true );
1057 echo $parserOutput->getText();
1063 function haveData( $str ) {
1064 return $this->data
[$str];
1070 function haveMsg( $str ) {
1071 $msg = $this->translator
->translate( $str );
1072 return ($msg != '-') && ($msg != ''); # ????
1076 } // end of if( defined( 'MEDIAWIKI' ) )