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;
152 global $wgUseTrackbacks;
154 $fname = 'SkinTemplate::outputPage';
155 wfProfileIn( $fname );
157 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
159 wfProfileIn( "$fname-init" );
160 $this->initPage( $out );
162 $this->mTitle
=& $wgTitle;
163 $this->mUser
=& $wgUser;
165 $tpl = $this->setupTemplate( $this->template
, 'skins' );
167 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
168 $tpl->setTranslator(new MediaWiki_I18N());
170 wfProfileOut( "$fname-init" );
172 wfProfileIn( "$fname-stuff" );
173 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
174 $this->thisurl
= $this->mTitle
->getPrefixedURL();
175 $this->loggedin
= $wgUser->isLoggedIn();
176 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
177 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
178 $this->username
= $wgUser->getName();
179 $userPage = $wgUser->getUserPage();
180 $this->userpage
= $userPage->getPrefixedText();
181 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
183 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt
= $this->mTitle
->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
193 $tpl->setRef( "thispage", $this->thispage
);
194 $subpagestr = $this->subPageSubtitle();
196 'subtitle', !empty($subpagestr)?
197 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
200 $undelete = $this->getUndeleteLink();
202 "undelete", !empty($undelete)?
203 '<span class="subpages">'.$undelete.'</span>':
207 $tpl->set( 'catlinks', $this->getCategories());
208 if( $wgOut->isSyndicated() ) {
210 foreach( $wgFeedClasses as $format => $class ) {
211 $feeds[$format] = array(
213 'href' => $wgRequest->appendQuery( "feed=$format" ),
214 'ttip' => wfMsg('tooltip-'.$format)
217 $tpl->setRef( 'feeds', $feeds );
219 $tpl->set( 'feeds', false );
221 if ($wgUseTrackbacks && $out->isArticleRelated())
222 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
224 $tpl->setRef( 'mimetype', $wgMimeType );
225 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
226 $tpl->setRef( 'charset', $wgOutputEncoding );
227 $tpl->set( 'headlinks', $out->getHeadLinks() );
228 $tpl->setRef('headscripts', $out->getScript() );
229 $tpl->setRef( 'wgScript', $wgScript );
230 $tpl->setRef( 'skinname', $this->skinname
);
231 $tpl->setRef( 'stylename', $this->stylename
);
232 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
233 $tpl->setRef( 'loggedin', $this->loggedin
);
234 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
235 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
236 /* XXX currently unused, might get useful later
237 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
238 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
239 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
240 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
241 $tpl->set( "helppage", wfMsg('helppage'));
243 $tpl->set( 'searchaction', $this->escapeSearchLink() );
244 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
245 $tpl->setRef( 'stylepath', $wgStylePath );
246 $tpl->setRef( 'logopath', $wgLogo );
247 $tpl->setRef( "lang", $wgContLanguageCode );
248 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
249 $tpl->set( 'rtl', $wgContLang->isRTL() );
250 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
251 $tpl->setRef( 'username', $this->username
);
252 $tpl->setRef( 'userpage', $this->userpage
);
253 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
254 $tpl->setRef( 'usercss', $this->usercss
);
255 $tpl->setRef( 'userjs', $this->userjs
);
256 $tpl->setRef( 'userjsprev', $this->userjsprev
);
259 if($this->loggedin
) {
260 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
262 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
265 $tpl->set('jsvarurl', false);
267 if( $wgUser->getNewtalk() ) {
268 $usertitle = $this->mUser
->getUserPage();
269 $usertalktitle = $usertitle->getTalkPage();
270 if( !$usertalktitle->equals( $this->mTitle
) ) {
271 $ntl = wfMsg( 'newmessages',
272 $this->makeKnownLinkObj(
274 wfMsg('newmessageslink')
278 $wgOut->setSquidMaxage(0);
283 wfProfileOut( "$fname-stuff2" );
285 wfProfileIn( "$fname-stuff3" );
286 $tpl->setRef( 'newtalk', $ntl );
287 $tpl->setRef( 'skin', $this);
288 $tpl->set( 'logo', $this->logoText() );
289 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
290 if ( !$wgDisableCounters ) {
291 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
293 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
295 $tpl->set('viewcount', false);
298 $tpl->set('viewcount', false);
301 if ($wgPageShowWatchingUsers) {
302 $dbr =& wfGetDB( DB_SLAVE
);
303 extract( $dbr->tableNames( 'watchlist' ) );
304 $sql = "SELECT COUNT(*) AS n FROM $watchlist
305 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
306 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
307 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
308 $x = $dbr->fetchObject( $res );
309 $numberofwatchingusers = $x->n
;
310 if ($numberofwatchingusers > 0) {
311 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
313 $tpl->set('numberofwatchingusers', false);
316 $tpl->set('numberofwatchingusers', false);
319 $tpl->set('copyright',$this->getCopyright());
321 $this->credits
= false;
323 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
324 require_once("Credits.php");
325 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
327 $tpl->set('lastmod', $this->lastModified());
330 $tpl->setRef( 'credits', $this->credits
);
332 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
333 $tpl->set('copyright', $this->getCopyright());
334 $tpl->set('viewcount', false);
335 $tpl->set('lastmod', false);
336 $tpl->set('credits', false);
337 $tpl->set('numberofwatchingusers', false);
339 $tpl->set('copyright', false);
340 $tpl->set('viewcount', false);
341 $tpl->set('lastmod', false);
342 $tpl->set('credits', false);
343 $tpl->set('numberofwatchingusers', false);
345 wfProfileOut( "$fname-stuff3" );
347 wfProfileIn( "$fname-stuff4" );
348 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
349 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
350 $tpl->set( 'disclaimer', $this->disclaimerLink() );
351 $tpl->set( 'about', $this->aboutLink() );
353 $tpl->setRef( 'debug', $out->mDebugtext
);
354 $tpl->set( 'reporttime', $out->reportTime() );
355 $tpl->set( 'sitenotice', wfGetSiteNotice() );
357 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
358 $out->mBodytext
.= $printfooter ;
359 $tpl->setRef( 'bodytext', $out->mBodytext
);
362 $language_urls = array();
364 if ( !$wgHideInterlanguageLinks ) {
365 foreach( $wgOut->getLanguageLinks() as $l ) {
366 $tmp = explode( ':', $l, 2 );
367 $class = 'interwiki-' . $tmp[0];
369 $nt = Title
::newFromText( $l );
370 $language_urls[] = array(
371 'href' => $nt->getFullURL(),
372 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
377 if(count($language_urls)) {
378 $tpl->setRef( 'language_urls', $language_urls);
380 $tpl->set('language_urls', false);
382 wfProfileOut( "$fname-stuff4" );
385 $tpl->set('personal_urls', $this->buildPersonalUrls());
386 $content_actions = $this->buildContentActionUrls();
387 $tpl->setRef('content_actions', $content_actions);
389 // XXX: attach this from javascript, same with section editing
390 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
392 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
394 $tpl->set('body_ondblclick', false);
396 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
397 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
399 $tpl->set( 'body_onload', false );
401 $tpl->set( 'sidebar', $this->buildSidebar() );
402 $tpl->set( 'nav_urls', $this->buildNavUrls() );
405 wfProfileIn( "$fname-execute" );
406 $res = $tpl->execute();
407 wfProfileOut( "$fname-execute" );
409 // result may be an error
410 $this->printOrError( $res );
411 wfProfileOut( $fname );
415 * Output the string, or print error message if it's
416 * an error object of the appropriate type.
417 * For the base class, assume strings all around.
422 function printOrError( &$str ) {
427 * build array of urls for personal toolbar
431 function buildPersonalUrls() {
432 $fname = 'SkinTemplate::buildPersonalUrls';
433 wfProfileIn( $fname );
435 /* set up the default links for the personal toolbar */
436 global $wgShowIPinHeader;
437 $personal_urls = array();
438 if ($this->loggedin
) {
439 $personal_urls['userpage'] = array(
440 'text' => $this->username
,
441 'href' => &$this->userpageUrlDetails
['href'],
442 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
444 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
445 $personal_urls['mytalk'] = array(
446 'text' => wfMsg('mytalk'),
447 'href' => &$usertalkUrlDetails['href'],
448 'class' => $usertalkUrlDetails['exists']?
false:'new'
450 $personal_urls['preferences'] = array(
451 'text' => wfMsg('preferences'),
452 'href' => $this->makeSpecialUrl('Preferences')
454 $personal_urls['watchlist'] = array(
455 'text' => wfMsg('watchlist'),
456 'href' => $this->makeSpecialUrl('Watchlist')
458 $personal_urls['mycontris'] = array(
459 'text' => wfMsg('mycontris'),
460 'href' => $this->makeSpecialUrl("Contributions/$this->username")
462 $personal_urls['logout'] = array(
463 'text' => wfMsg('userlogout'),
464 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
467 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
468 $personal_urls['anonuserpage'] = array(
469 'text' => $this->username
,
470 'href' => &$this->userpageUrlDetails
['href'],
471 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
473 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
474 $personal_urls['anontalk'] = array(
475 'text' => wfMsg('anontalk'),
476 'href' => &$usertalkUrlDetails['href'],
477 'class' => $usertalkUrlDetails['exists']?
false:'new'
479 $personal_urls['anonlogin'] = array(
480 'text' => wfMsg('userlogin'),
481 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
485 $personal_urls['login'] = array(
486 'text' => wfMsg('userlogin'),
487 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
491 wfProfileOut( $fname );
492 return $personal_urls;
496 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
499 $classes[] = 'selected';
501 if( $checkEdit && $title->getArticleId() == 0 ) {
503 $query = 'action=edit';
506 'class' => implode( ' ', $classes ),
507 'text' => wfMsg( $message ),
508 'href' => $title->getLocalUrl( $query ) );
511 function makeTalkUrlDetails( $name, $urlaction='' ) {
512 $title = Title
::newFromText( $name );
513 $title = $title->getTalkPage();
514 $this->checkTitle($title, $name);
516 'href' => $title->getLocalURL( $urlaction ),
517 'exists' => $title->getArticleID() != 0?
true:false
521 function makeArticleUrlDetails( $name, $urlaction='' ) {
522 $title = Title
::newFromText( $name );
523 $title= $title->getSubjectPage();
524 $this->checkTitle($title, $name);
526 'href' => $title->getLocalURL( $urlaction ),
527 'exists' => $title->getArticleID() != 0?
true:false
532 * an array of edit links by default used for the tabs
536 function buildContentActionUrls () {
537 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
538 $fname = 'SkinTemplate::buildContentActionUrls';
539 wfProfileIn( $fname );
541 global $wgUser, $wgRequest;
542 $action = $wgRequest->getText( 'action' );
543 $section = $wgRequest->getText( 'section' );
544 $oldid = $wgRequest->getVal( 'oldid' );
545 $diff = $wgRequest->getVal( 'diff' );
546 $content_actions = array();
548 if( $this->iscontent
) {
549 $subjpage = $this->mTitle
->getSubjectPage();
550 $talkpage = $this->mTitle
->getTalkPage();
552 $nskey = $this->getNameSpaceKey();
553 $content_actions[$nskey] = $this->tabAction(
556 !$this->mTitle
->isTalkPage(),
559 $content_actions['talk'] = $this->tabAction(
562 $this->mTitle
->isTalkPage(),
566 wfProfileIn( "$fname-edit" );
567 if ( $this->mTitle
->userCanEdit() ) {
568 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : false;
569 $istalk = $this->mTitle
->isTalkPage();
570 $istalkclass = $istalk?
' istalk':'';
571 $content_actions['edit'] = array(
572 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
573 'text' => wfMsg('edit'),
574 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
578 $content_actions['addsection'] = array(
579 'class' => $section == 'new'?
'selected':false,
580 'text' => wfMsg('addsection'),
581 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
585 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : '';
586 $content_actions['viewsource'] = array(
587 'class' => ($action == 'edit') ?
'selected' : false,
588 'text' => wfMsg('viewsource'),
589 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
592 wfProfileOut( "$fname-edit" );
594 wfProfileIn( "$fname-live" );
595 if ( $this->mTitle
->getArticleId() ) {
597 $content_actions['history'] = array(
598 'class' => ($action == 'history') ?
'selected' : false,
599 'text' => wfMsg('history_short'),
600 'href' => $this->mTitle
->getLocalUrl( 'action=history')
603 if($wgUser->isAllowed('protect')){
604 if(!$this->mTitle
->isProtected()){
605 $content_actions['protect'] = array(
606 'class' => ($action == 'protect') ?
'selected' : false,
607 'text' => wfMsg('protect'),
608 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
612 $content_actions['unprotect'] = array(
613 'class' => ($action == 'unprotect') ?
'selected' : false,
614 'text' => wfMsg('unprotect'),
615 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
619 if($wgUser->isAllowed('delete')){
620 $content_actions['delete'] = array(
621 'class' => ($action == 'delete') ?
'selected' : false,
622 'text' => wfMsg('delete'),
623 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
626 if ( $wgUser->isLoggedIn() ) {
627 if ( $this->mTitle
->userCanMove()) {
628 $content_actions['move'] = array(
629 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
630 'text' => wfMsg('move'),
631 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
636 //article doesn't exist or is deleted
637 if($wgUser->isAllowed('delete')){
638 if( $n = $this->mTitle
->isDeleted() ) {
639 $content_actions['undelete'] = array(
641 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
642 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
647 wfProfileOut( "$fname-live" );
649 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
650 if( !$this->mTitle
->userIsWatching()) {
651 $content_actions['watch'] = array(
652 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
653 'text' => wfMsg('watch'),
654 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
657 $content_actions['unwatch'] = array(
658 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
659 'text' => wfMsg('unwatch'),
660 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
665 if( $wgUser->isLoggedIn() ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
666 # Validate tab. TODO: add validation to logged-in user rights
667 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
668 if ( $oldid ) $oid = intval( $oldid ) ; # Use the oldid
670 {# Trying to get the current article revision through this weird stunt
671 $tid = $this->mTitle
->getArticleID();
672 $tns = $this->mTitle
->getNamespace();
673 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
674 $res = wfQuery( $sql, DB_READ
);
675 if( $s = wfFetchObject( $res ) )
676 $oid = $s->page_latest
;
677 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
680 $oid = "&revision={$oid}" ;
681 $content_actions['validate'] = array(
682 'class' => ($action == 'validate') ?
'selected' : false,
683 'text' => wfMsg('val_tab'),
684 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
690 /* show special page tab */
692 $content_actions['article'] = array(
693 'class' => 'selected',
694 'text' => wfMsg('specialpage'),
695 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
699 /* show links to different language variants */
700 global $wgDisableLangConversion;
701 $variants = $wgContLang->getVariants();
702 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
703 $preferred = $wgContLang->getPreferredVariant();
706 $actstr = 'action=' . $action . '&';
708 foreach( $variants as $code ) {
709 $varname = $wgContLang->getVariantname( $code );
710 if( $varname == 'disable' )
712 $selected = ( $code == $preferred )?
'selected' : false;
713 $content_actions['varlang-' . $vcount] = array(
714 'class' => $selected,
716 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
722 wfRunHooks( 'SkinTemplateContentActions', array(&$content_actions) );
724 wfProfileOut( $fname );
725 return $content_actions;
731 * build array of common navigation links
735 function buildNavUrls () {
736 global $wgUseTrackbacks, $wgTitle;
738 $fname = 'SkinTemplate::buildNavUrls';
739 wfProfileIn( $fname );
741 global $wgUser, $wgRequest;
742 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
744 $action = $wgRequest->getText( 'action' );
745 $oldid = $wgRequest->getVal( 'oldid' );
746 $diff = $wgRequest->getVal( 'diff' );
749 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
750 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
751 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
752 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
753 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
754 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
755 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
756 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
757 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
758 if( $wgEnableUploads ) {
759 if ($wgUploadNavigationUrl) {
760 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
762 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
765 $nav_urls['upload'] = false;
767 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
770 // A print stylesheet is attached to all pages, but nobody ever
771 // figures that out. :) Add a link...
772 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
773 $nav_urls['print'] = array(
774 'text' => wfMsg( 'printableversion' ),
775 'href' => $wgRequest->appendQuery( 'printable=yes' ) );
778 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
779 $nav_urls['whatlinkshere'] = array(
780 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
782 $nav_urls['recentchangeslinked'] = array(
783 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
785 if ($wgUseTrackbacks)
786 $nav_urls['trackbacklink'] = array(
787 'href' => $wgTitle->trackbackURL()
791 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
792 $id = User
::idFromName($this->mTitle
->getText());
793 $ip = User
::isIP($this->mTitle
->getText());
799 if($id ||
$ip) { # both anons and non-anons have contri list
800 $nav_urls['contributions'] = array(
801 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
804 $nav_urls['contributions'] = false;
806 $nav_urls['emailuser'] = false;
807 if( $this->showEmailUser( $id ) ) {
808 $nav_urls['emailuser'] = array(
809 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
812 wfProfileOut( $fname );
817 * Generate strings used for xml 'id' names
821 function getNameSpaceKey () {
822 switch ($this->mTitle
->getNamespace()) {
830 return 'nstab-media';
832 return 'nstab-special';
834 case NS_PROJECT_TALK
:
838 return 'nstab-image';
840 case NS_MEDIAWIKI_TALK
:
841 return 'nstab-mediawiki';
843 case NS_TEMPLATE_TALK
:
844 return 'nstab-template';
849 case NS_CATEGORY_TALK
:
850 return 'nstab-category';
859 function setupUserCss() {
860 $fname = 'SkinTemplate::setupUserCss';
861 wfProfileIn( $fname );
863 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
867 $siteargs = '&maxage=' . $wgSquidMaxage;
869 # Add user-specific code if this is a user and we allow that kind of thing
871 if ( $wgAllowUserCss && $this->loggedin
) {
872 $action = $wgRequest->getText('action');
874 # if we're previewing the CSS page, use it
875 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
876 $siteargs = "&smaxage=0&maxage=0";
877 $usercss = $wgRequest->getText('wpTextbox1');
879 $usercss = '@import "' .
880 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
881 'action=raw&ctype=text/css') . '";' ."\n";
884 $siteargs .= '&ts=' . $wgUser->mTouched
;
887 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
889 # If we use the site's dynamic CSS, throw that in, too
890 if ( $wgUseSiteCss ) {
891 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
892 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
895 # If we use any dynamic CSS, make a little CDATA block out of it.
897 if ( !empty($sitecss) ||
!empty($usercss) ) {
898 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
900 wfProfileOut( $fname );
906 function setupUserJs() {
907 $fname = 'SkinTemplate::setupUserJs';
908 wfProfileIn( $fname );
910 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
911 $action = $wgRequest->getText('action');
913 if( $wgAllowUserJs && $this->loggedin
) {
914 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
915 # XXX: additional security check/prompt?
916 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
918 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
921 wfProfileOut( $fname );
925 * returns css with user-specific options
929 function getUserStylesheet() {
930 $fname = 'SkinTemplate::getUserStylesheet';
931 wfProfileIn( $fname );
934 $s = "/* generated user stylesheet */\n";
935 $s .= $this->reallyDoGetUserStyles();
936 wfProfileOut( $fname );
943 function getUserJs() {
944 $fname = 'SkinTemplate::getUserJs';
945 wfProfileIn( $fname );
948 $s = '/* generated javascript */';
949 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
950 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
952 // avoid inclusion of non defined user JavaScript (with custom skins only)
953 // by checking for default message content
954 $msgKey = ucfirst($this->skinname
).'.js';
955 $userJS = wfMsg($msgKey);
956 if ('<'.$msgKey.'>' != $userJS) {
960 wfProfileOut( $fname );
966 * Generic wrapper for template functions, with interface
967 * compatible with what we use of PHPTAL 0.7.
971 class QuickTemplate
{
975 function QuickTemplate() {
976 $this->data
= array();
977 $this->translator
= new MediaWiki_I18N();
983 function set( $name, $value ) {
984 $this->data
[$name] = $value;
990 function setRef($name, &$value) {
991 $this->data
[$name] =& $value;
997 function setTranslator( &$t ) {
998 $this->translator
= &$t;
1004 function execute() {
1005 echo "Override this function.";
1012 function text( $str ) {
1013 echo htmlspecialchars( $this->data
[$str] );
1019 function html( $str ) {
1020 echo $this->data
[$str];
1026 function msg( $str ) {
1027 echo htmlspecialchars( $this->translator
->translate( $str ) );
1033 function msgHtml( $str ) {
1034 echo $this->translator
->translate( $str );
1038 * An ugly, ugly hack.
1041 function msgWiki( $str ) {
1042 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1044 $text = $this->translator
->translate( $str );
1045 $parserOutput = $wgParser->parse( $text, $wgTitle,
1046 $wgOut->mParserOptions
, true );
1047 echo $parserOutput->getText();
1053 function haveData( $str ) {
1054 return $this->data
[$str];
1060 function haveMsg( $str ) {
1061 $msg = $this->translator
->translate( $str );
1062 return ($msg != '-') && ($msg != ''); # ????
1066 } // end of if( defined( 'MEDIAWIKI' ) )