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( 'wgScript', $wgScript );
229 $tpl->setRef( 'skinname', $this->skinname
);
230 $tpl->setRef( 'stylename', $this->stylename
);
231 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
232 $tpl->setRef( 'loggedin', $this->loggedin
);
233 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
234 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
235 /* XXX currently unused, might get useful later
236 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
237 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
238 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
239 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
240 $tpl->set( "helppage", wfMsg('helppage'));
242 $tpl->set( 'searchaction', $this->escapeSearchLink() );
243 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
244 $tpl->setRef( 'stylepath', $wgStylePath );
245 $tpl->setRef( 'logopath', $wgLogo );
246 $tpl->setRef( "lang", $wgContLanguageCode );
247 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
248 $tpl->set( 'rtl', $wgContLang->isRTL() );
249 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
250 $tpl->setRef( 'username', $this->username
);
251 $tpl->setRef( 'userpage', $this->userpage
);
252 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
253 $tpl->setRef( 'usercss', $this->usercss
);
254 $tpl->setRef( 'userjs', $this->userjs
);
255 $tpl->setRef( 'userjsprev', $this->userjsprev
);
258 if($this->loggedin
) {
259 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
261 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
264 $tpl->set('jsvarurl', false);
266 if( $wgUser->getNewtalk() ) {
267 $usertitle = $this->mUser
->getUserPage();
268 $usertalktitle = $usertitle->getTalkPage();
269 if( !$usertalktitle->equals( $this->mTitle
) ) {
270 $ntl = wfMsg( 'newmessages',
271 $this->makeKnownLinkObj(
273 wfMsg('newmessageslink')
277 $wgOut->setSquidMaxage(0);
282 wfProfileOut( "$fname-stuff2" );
284 wfProfileIn( "$fname-stuff3" );
285 $tpl->setRef( 'newtalk', $ntl );
286 $tpl->setRef( 'skin', $this);
287 $tpl->set( 'logo', $this->logoText() );
288 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
289 if ( !$wgDisableCounters ) {
290 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
292 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
294 $tpl->set('viewcount', false);
297 $tpl->set('viewcount', false);
300 if ($wgPageShowWatchingUsers) {
301 $dbr =& wfGetDB( DB_SLAVE
);
302 extract( $dbr->tableNames( 'watchlist' ) );
303 $sql = "SELECT COUNT(*) AS n FROM $watchlist
304 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
305 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
306 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
307 $x = $dbr->fetchObject( $res );
308 $numberofwatchingusers = $x->n
;
309 if ($numberofwatchingusers > 0) {
310 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
312 $tpl->set('numberofwatchingusers', false);
315 $tpl->set('numberofwatchingusers', false);
318 $tpl->set('copyright',$this->getCopyright());
320 $this->credits
= false;
322 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
323 require_once("Credits.php");
324 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
326 $tpl->set('lastmod', $this->lastModified());
329 $tpl->setRef( 'credits', $this->credits
);
331 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
332 $tpl->set('copyright', $this->getCopyright());
333 $tpl->set('viewcount', false);
334 $tpl->set('lastmod', false);
335 $tpl->set('credits', false);
336 $tpl->set('numberofwatchingusers', false);
338 $tpl->set('copyright', false);
339 $tpl->set('viewcount', false);
340 $tpl->set('lastmod', false);
341 $tpl->set('credits', false);
342 $tpl->set('numberofwatchingusers', false);
344 wfProfileOut( "$fname-stuff3" );
346 wfProfileIn( "$fname-stuff4" );
347 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
348 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
349 $tpl->set( 'disclaimer', $this->disclaimerLink() );
350 $tpl->set( 'about', $this->aboutLink() );
352 $tpl->setRef( 'debug', $out->mDebugtext
);
353 $tpl->set( 'reporttime', $out->reportTime() );
354 $tpl->set( 'sitenotice', wfGetSiteNotice() );
356 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
357 $out->mBodytext
.= $printfooter ;
358 $tpl->setRef( 'bodytext', $out->mBodytext
);
361 $language_urls = array();
363 if ( !$wgHideInterlanguageLinks ) {
364 foreach( $wgOut->getLanguageLinks() as $l ) {
365 $nt = Title
::newFromText( $l );
366 $language_urls[] = array('href' => $nt->getFullURL(),
367 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
368 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
371 if(count($language_urls)) {
372 $tpl->setRef( 'language_urls', $language_urls);
374 $tpl->set('language_urls', false);
376 wfProfileOut( "$fname-stuff4" );
379 $tpl->set('personal_urls', $this->buildPersonalUrls());
380 $content_actions = $this->buildContentActionUrls();
381 $tpl->setRef('content_actions', $content_actions);
383 // XXX: attach this from javascript, same with section editing
384 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
386 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
388 $tpl->set('body_ondblclick', false);
390 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
391 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
393 $tpl->set( 'body_onload', false );
395 $tpl->set( 'sidebar', $this->buildSidebar() );
396 $tpl->set( 'nav_urls', $this->buildNavUrls() );
399 wfProfileIn( "$fname-execute" );
400 $res = $tpl->execute();
401 wfProfileOut( "$fname-execute" );
403 // result may be an error
404 $this->printOrError( $res );
405 wfProfileOut( $fname );
409 * Output the string, or print error message if it's
410 * an error object of the appropriate type.
411 * For the base class, assume strings all around.
416 function printOrError( &$str ) {
421 * build array of urls for personal toolbar
425 function buildPersonalUrls() {
426 $fname = 'SkinTemplate::buildPersonalUrls';
427 wfProfileIn( $fname );
429 /* set up the default links for the personal toolbar */
430 global $wgShowIPinHeader;
431 $personal_urls = array();
432 if ($this->loggedin
) {
433 $personal_urls['userpage'] = array(
434 'text' => $this->username
,
435 'href' => &$this->userpageUrlDetails
['href'],
436 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
438 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
439 $personal_urls['mytalk'] = array(
440 'text' => wfMsg('mytalk'),
441 'href' => &$usertalkUrlDetails['href'],
442 'class' => $usertalkUrlDetails['exists']?
false:'new'
444 $personal_urls['preferences'] = array(
445 'text' => wfMsg('preferences'),
446 'href' => $this->makeSpecialUrl('Preferences')
448 $personal_urls['watchlist'] = array(
449 'text' => wfMsg('watchlist'),
450 'href' => $this->makeSpecialUrl('Watchlist')
452 $personal_urls['mycontris'] = array(
453 'text' => wfMsg('mycontris'),
454 'href' => $this->makeSpecialUrl("Contributions/$this->username")
456 $personal_urls['logout'] = array(
457 'text' => wfMsg('userlogout'),
458 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
461 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
462 $personal_urls['anonuserpage'] = array(
463 'text' => $this->username
,
464 'href' => &$this->userpageUrlDetails
['href'],
465 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
467 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
468 $personal_urls['anontalk'] = array(
469 'text' => wfMsg('anontalk'),
470 'href' => &$usertalkUrlDetails['href'],
471 'class' => $usertalkUrlDetails['exists']?
false:'new'
473 $personal_urls['anonlogin'] = array(
474 'text' => wfMsg('userlogin'),
475 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
479 $personal_urls['login'] = array(
480 'text' => wfMsg('userlogin'),
481 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
485 wfProfileOut( $fname );
486 return $personal_urls;
490 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
493 $classes[] = 'selected';
495 if( $checkEdit && $title->getArticleId() == 0 ) {
497 $query = 'action=edit';
500 'class' => implode( ' ', $classes ),
501 'text' => wfMsg( $message ),
502 'href' => $title->getLocalUrl( $query ) );
505 function makeTalkUrlDetails( $name, $urlaction='' ) {
506 $title = Title
::newFromText( $name );
507 $title = $title->getTalkPage();
508 $this->checkTitle($title, $name);
510 'href' => $title->getLocalURL( $urlaction ),
511 'exists' => $title->getArticleID() != 0?
true:false
515 function makeArticleUrlDetails( $name, $urlaction='' ) {
516 $title = Title
::newFromText( $name );
517 $title= $title->getSubjectPage();
518 $this->checkTitle($title, $name);
520 'href' => $title->getLocalURL( $urlaction ),
521 'exists' => $title->getArticleID() != 0?
true:false
526 * an array of edit links by default used for the tabs
530 function buildContentActionUrls () {
531 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
532 $fname = 'SkinTemplate::buildContentActionUrls';
533 wfProfileIn( $fname );
535 global $wgUser, $wgRequest;
536 $action = $wgRequest->getText( 'action' );
537 $section = $wgRequest->getText( 'section' );
538 $oldid = $wgRequest->getVal( 'oldid' );
539 $diff = $wgRequest->getVal( 'diff' );
540 $content_actions = array();
542 if( $this->iscontent
) {
544 $nskey = $this->getNameSpaceKey();
545 $content_actions[$nskey] = $this->tabAction(
546 $this->mTitle
->getSubjectPage(),
548 !$this->mTitle
->isTalkPage(),
551 $content_actions['talk'] = $this->tabAction(
552 $this->mTitle
->getTalkPage(),
554 $this->mTitle
->isTalkPage(),
558 wfProfileIn( "$fname-edit" );
559 if ( $this->mTitle
->userCanEdit() ) {
560 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
561 $istalk = $this->mTitle
->isTalkPage();
562 $istalkclass = $istalk?
' istalk':'';
563 $content_actions['edit'] = array(
564 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
565 'text' => wfMsg('edit'),
566 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
570 $content_actions['addsection'] = array(
571 'class' => $section == 'new'?
'selected':false,
572 'text' => wfMsg('addsection'),
573 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
577 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
578 $content_actions['viewsource'] = array(
579 'class' => ($action == 'edit') ?
'selected' : false,
580 'text' => wfMsg('viewsource'),
581 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
584 wfProfileOut( "$fname-edit" );
586 wfProfileIn( "$fname-live" );
587 if ( $this->mTitle
->getArticleId() ) {
589 $content_actions['history'] = array(
590 'class' => ($action == 'history') ?
'selected' : false,
591 'text' => wfMsg('history_short'),
592 'href' => $this->mTitle
->getLocalUrl( 'action=history')
595 if($wgUser->isAllowed('protect')){
596 if(!$this->mTitle
->isProtected()){
597 $content_actions['protect'] = array(
598 'class' => ($action == 'protect') ?
'selected' : false,
599 'text' => wfMsg('protect'),
600 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
604 $content_actions['unprotect'] = array(
605 'class' => ($action == 'unprotect') ?
'selected' : false,
606 'text' => wfMsg('unprotect'),
607 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
611 if($wgUser->isAllowed('delete')){
612 $content_actions['delete'] = array(
613 'class' => ($action == 'delete') ?
'selected' : false,
614 'text' => wfMsg('delete'),
615 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
618 if ( $wgUser->isLoggedIn() ) {
619 if ( $this->mTitle
->userCanMove()) {
620 $content_actions['move'] = array(
621 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
622 'text' => wfMsg('move'),
623 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
628 //article doesn't exist or is deleted
629 if($wgUser->isAllowed('delete')){
630 if( $n = $this->mTitle
->isDeleted() ) {
631 $content_actions['undelete'] = array(
633 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
634 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
639 wfProfileOut( "$fname-live" );
641 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
642 if( !$this->mTitle
->userIsWatching()) {
643 $content_actions['watch'] = array(
644 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
645 'text' => wfMsg('watch'),
646 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
649 $content_actions['unwatch'] = array(
650 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
651 'text' => wfMsg('unwatch'),
652 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
657 if( $wgUser->isLoggedIn() ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
658 # Validate tab. TODO: add validation to logged-in user rights
659 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
660 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
662 {# Trying to get the current article revision through this weird stunt
663 $tid = $this->mTitle
->getArticleID();
664 $tns = $this->mTitle
->getNamespace();
665 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
666 $res = wfQuery( $sql, DB_READ
);
667 if( $s = wfFetchObject( $res ) )
668 $oid = $s->page_latest
;
669 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
672 $oid = "&revision={$oid}" ;
673 $content_actions['validate'] = array(
674 'class' => ($action == 'validate') ?
'selected' : false,
675 'text' => wfMsg('val_tab'),
676 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
682 /* show special page tab */
684 $content_actions['article'] = array(
685 'class' => 'selected',
686 'text' => wfMsg('specialpage'),
687 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
691 /* show links to different language variants */
692 global $wgDisableLangConversion;
693 $variants = $wgContLang->getVariants();
694 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
695 $preferred = $wgContLang->getPreferredVariant();
698 $actstr = 'action=' . $action . '&';
700 foreach( $variants as $code ) {
701 $varname = $wgContLang->getVariantname( $code );
702 if( $varname == 'disable' )
704 $selected = ( $code == $preferred )?
'selected' : false;
705 $content_actions['varlang-' . $vcount] = array(
706 'class' => $selected,
708 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
714 wfProfileOut( $fname );
715 return $content_actions;
721 * build array of common navigation links
725 function buildNavUrls () {
726 global $wgUseTrackbacks, $wgTitle;
728 $fname = 'SkinTemplate::buildNavUrls';
729 wfProfileIn( $fname );
731 global $wgUser, $wgRequest;
732 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
734 $action = $wgRequest->getText( 'action' );
735 $oldid = $wgRequest->getVal( 'oldid' );
736 $diff = $wgRequest->getVal( 'diff' );
739 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
740 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
741 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
742 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
743 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
744 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
745 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
746 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
747 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
748 if( $wgEnableUploads ) {
749 if ($wgUploadNavigationUrl) {
750 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
752 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
755 $nav_urls['upload'] = false;
757 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
760 // A print stylesheet is attached to all pages, but nobody ever
761 // figures that out. :) Add a link...
762 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
763 $nav_urls['print'] = array(
764 'text' => wfMsg( 'printableversion' ),
765 'href' => $wgRequest->appendQuery( 'printable=yes' ) );
768 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
769 $nav_urls['whatlinkshere'] = array(
770 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
772 $nav_urls['recentchangeslinked'] = array(
773 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
775 if ($wgUseTrackbacks)
776 $nav_urls['trackbacklink'] = array(
777 'href' => $wgTitle->trackbackURL()
781 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
782 $id = User
::idFromName($this->mTitle
->getText());
783 $ip = User
::isIP($this->mTitle
->getText());
789 if($id ||
$ip) { # both anons and non-anons have contri list
790 $nav_urls['contributions'] = array(
791 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
794 $nav_urls['contributions'] = false;
796 $nav_urls['emailuser'] = false;
797 if( $this->showEmailUser( $id ) ) {
798 $nav_urls['emailuser'] = array(
799 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
802 wfProfileOut( $fname );
807 * Generate strings used for xml 'id' names
811 function getNameSpaceKey () {
812 switch ($this->mTitle
->getNamespace()) {
820 return 'nstab-media';
822 return 'nstab-special';
824 case NS_PROJECT_TALK
:
828 return 'nstab-image';
830 case NS_MEDIAWIKI_TALK
:
831 return 'nstab-mediawiki';
833 case NS_TEMPLATE_TALK
:
834 return 'nstab-template';
839 case NS_CATEGORY_TALK
:
840 return 'nstab-category';
849 function setupUserCss() {
850 $fname = 'SkinTemplate::setupUserCss';
851 wfProfileIn( $fname );
853 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
857 $siteargs = '&maxage=' . $wgSquidMaxage;
859 # Add user-specific code if this is a user and we allow that kind of thing
861 if ( $wgAllowUserCss && $this->loggedin
) {
862 $action = $wgRequest->getText('action');
864 # if we're previewing the CSS page, use it
865 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
866 $siteargs = "&smaxage=0&maxage=0";
867 $usercss = $wgRequest->getText('wpTextbox1');
869 $usercss = '@import "' .
870 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
871 'action=raw&ctype=text/css') . '";' ."\n";
874 $siteargs .= '&ts=' . $wgUser->mTouched
;
877 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
879 # If we use the site's dynamic CSS, throw that in, too
880 if ( $wgUseSiteCss ) {
881 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
882 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
885 # If we use any dynamic CSS, make a little CDATA block out of it.
887 if ( !empty($sitecss) ||
!empty($usercss) ) {
888 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
890 wfProfileOut( $fname );
896 function setupUserJs() {
897 $fname = 'SkinTemplate::setupUserJs';
898 wfProfileIn( $fname );
900 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
901 $action = $wgRequest->getText('action');
903 if( $wgAllowUserJs && $this->loggedin
) {
904 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
905 # XXX: additional security check/prompt?
906 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
908 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
911 wfProfileOut( $fname );
915 * returns css with user-specific options
919 function getUserStylesheet() {
920 $fname = 'SkinTemplate::getUserStylesheet';
921 wfProfileIn( $fname );
924 $s = "/* generated user stylesheet */\n";
925 $s .= $this->reallyDoGetUserStyles();
926 wfProfileOut( $fname );
933 function getUserJs() {
934 $fname = 'SkinTemplate::getUserJs';
935 wfProfileIn( $fname );
938 $s = '/* generated javascript */';
939 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
940 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
942 // avoid inclusion of non defined user JavaScript (with custom skins only)
943 // by checking for default message content
944 $msgKey = ucfirst($this->skinname
).'.js';
945 $userJS = wfMsg($msgKey);
946 if ('<'.$msgKey.'>' != $userJS) {
950 wfProfileOut( $fname );
956 * Generic wrapper for template functions, with interface
957 * compatible with what we use of PHPTAL 0.7.
961 class QuickTemplate
{
965 function QuickTemplate() {
966 $this->data
= array();
967 $this->translator
= new MediaWiki_I18N();
973 function set( $name, $value ) {
974 $this->data
[$name] = $value;
980 function setRef($name, &$value) {
981 $this->data
[$name] =& $value;
987 function setTranslator( &$t ) {
988 $this->translator
= &$t;
995 echo "Override this function.";
1002 function text( $str ) {
1003 echo htmlspecialchars( $this->data
[$str] );
1009 function html( $str ) {
1010 echo $this->data
[$str];
1016 function msg( $str ) {
1017 echo htmlspecialchars( $this->translator
->translate( $str ) );
1023 function msgHtml( $str ) {
1024 echo $this->translator
->translate( $str );
1028 * An ugly, ugly hack.
1031 function msgWiki( $str ) {
1032 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1034 $text = $this->translator
->translate( $str );
1035 $parserOutput = $wgParser->parse( $text, $wgTitle,
1036 $wgOut->mParserOptions
, true );
1037 echo $parserOutput->getText();
1043 function haveData( $str ) {
1044 return $this->data
[$str];
1050 function haveMsg( $str ) {
1051 $msg = $this->translator
->translate( $str );
1052 return ($msg != '-') && ($msg != ''); # ????
1056 } // end of if( defined( 'MEDIAWIKI' ) )