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, $wgContLanguageCode;
148 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $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();
182 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
183 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
185 # This won't be used in the standard skins, but we define it to preserve the interface
186 # To save time, we check for existence
187 $this->userpageUrlDetails
= $this->makeKnownUrlDetails($this->userpage
);
190 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
191 $this->setupUserCss();
192 $this->setupUserJs();
193 $this->titletxt
= $this->mTitle
->getPrefixedText();
194 wfProfileOut( "$fname-stuff" );
196 wfProfileIn( "$fname-stuff2" );
197 $tpl->set( 'title', $wgOut->getPageTitle() );
198 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
200 $tpl->setRef( "thispage", $this->thispage
);
201 $subpagestr = $this->subPageSubtitle();
203 'subtitle', !empty($subpagestr)?
204 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
207 $undelete = $this->getUndeleteLink();
209 "undelete", !empty($undelete)?
210 '<span class="subpages">'.$undelete.'</span>':
214 $tpl->set( 'catlinks', $this->getCategories());
215 if( $wgOut->isSyndicated() ) {
217 foreach( $wgFeedClasses as $format => $class ) {
218 $feeds[$format] = array(
220 'href' => $wgRequest->appendQuery( "feed=$format" )
223 $tpl->setRef( 'feeds', $feeds );
225 $tpl->set( 'feeds', false );
227 if ($wgUseTrackbacks && $out->isArticleRelated())
228 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
230 $tpl->setRef( 'mimetype', $wgMimeType );
231 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
232 $tpl->setRef( 'charset', $wgOutputEncoding );
233 $tpl->set( 'headlinks', $out->getHeadLinks() );
234 $tpl->set('headscripts', $out->getScript() );
235 $tpl->setRef( 'wgScript', $wgScript );
236 $tpl->setRef( 'skinname', $this->skinname
);
237 $tpl->setRef( 'stylename', $this->stylename
);
238 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
239 $tpl->setRef( 'loggedin', $this->loggedin
);
240 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
241 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
242 /* XXX currently unused, might get useful later
243 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
244 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
245 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
246 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
247 $tpl->set( "helppage", wfMsg('helppage'));
249 $tpl->set( 'searchaction', $this->escapeSearchLink() );
250 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
251 $tpl->setRef( 'stylepath', $wgStylePath );
252 $tpl->setRef( 'logopath', $wgLogo );
253 $tpl->setRef( "lang", $wgContLanguageCode );
254 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
255 $tpl->set( 'rtl', $wgContLang->isRTL() );
256 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
257 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
258 $tpl->setRef( 'username', $this->username
);
259 $tpl->setRef( 'userpage', $this->userpage
);
260 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
261 $tpl->set( 'pagecss', $this->setupPageCss() );
262 $tpl->setRef( 'usercss', $this->usercss
);
263 $tpl->setRef( 'userjs', $this->userjs
);
264 $tpl->setRef( 'userjsprev', $this->userjsprev
);
267 if($this->loggedin
) {
268 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
270 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
273 $tpl->set('jsvarurl', false);
275 if( $wgUser->getNewtalk() ) {
276 $usertitle = $this->mUser
->getUserPage();
277 $usertalktitle = $usertitle->getTalkPage();
278 if( !$usertalktitle->equals( $this->mTitle
) ) {
279 $ntl = wfMsg( 'youhavenewmessages',
280 $this->makeKnownLinkObj(
282 wfMsgHtml( 'newmessageslink' )
284 $this->makeKnownLinkObj(
286 wfMsgHtml( 'newmessagesdifflink' ),
291 $wgOut->setSquidMaxage(0);
296 wfProfileOut( "$fname-stuff2" );
298 wfProfileIn( "$fname-stuff3" );
299 $tpl->setRef( 'newtalk', $ntl );
300 $tpl->setRef( 'skin', $this);
301 $tpl->set( 'logo', $this->logoText() );
302 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
303 if ( !$wgDisableCounters ) {
304 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
306 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
308 $tpl->set('viewcount', false);
311 $tpl->set('viewcount', false);
314 if ($wgPageShowWatchingUsers) {
315 $dbr =& wfGetDB( DB_SLAVE
);
316 extract( $dbr->tableNames( 'watchlist' ) );
317 $sql = "SELECT COUNT(*) AS n FROM $watchlist
318 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
319 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
320 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
321 $x = $dbr->fetchObject( $res );
322 $numberofwatchingusers = $x->n
;
323 if ($numberofwatchingusers > 0) {
324 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
326 $tpl->set('numberofwatchingusers', false);
329 $tpl->set('numberofwatchingusers', false);
332 $tpl->set('copyright',$this->getCopyright());
334 $this->credits
= false;
336 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
337 require_once("Credits.php");
338 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
340 $tpl->set('lastmod', $this->lastModified());
343 $tpl->setRef( 'credits', $this->credits
);
345 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
346 $tpl->set('copyright', $this->getCopyright());
347 $tpl->set('viewcount', false);
348 $tpl->set('lastmod', false);
349 $tpl->set('credits', false);
350 $tpl->set('numberofwatchingusers', false);
352 $tpl->set('copyright', false);
353 $tpl->set('viewcount', false);
354 $tpl->set('lastmod', false);
355 $tpl->set('credits', false);
356 $tpl->set('numberofwatchingusers', false);
358 wfProfileOut( "$fname-stuff3" );
360 wfProfileIn( "$fname-stuff4" );
361 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
362 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
363 $tpl->set( 'disclaimer', $this->disclaimerLink() );
364 $tpl->set( 'privacy', $this->privacyLink() );
365 $tpl->set( 'about', $this->aboutLink() );
367 $tpl->setRef( 'debug', $out->mDebugtext
);
368 $tpl->set( 'reporttime', $out->reportTime() );
369 $tpl->set( 'sitenotice', wfGetSiteNotice() );
371 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
372 $out->mBodytext
.= $printfooter ;
373 $tpl->setRef( 'bodytext', $out->mBodytext
);
376 $language_urls = array();
378 if ( !$wgHideInterlanguageLinks ) {
379 foreach( $wgOut->getLanguageLinks() as $l ) {
380 $tmp = explode( ':', $l, 2 );
381 $class = 'interwiki-' . $tmp[0];
383 $nt = Title
::newFromText( $l );
384 $language_urls[] = array(
385 'href' => $nt->getFullURL(),
386 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
391 if(count($language_urls)) {
392 $tpl->setRef( 'language_urls', $language_urls);
394 $tpl->set('language_urls', false);
396 wfProfileOut( "$fname-stuff4" );
399 $tpl->set('personal_urls', $this->buildPersonalUrls());
400 $content_actions = $this->buildContentActionUrls();
401 $tpl->setRef('content_actions', $content_actions);
403 // XXX: attach this from javascript, same with section editing
404 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
406 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
408 $tpl->set('body_ondblclick', false);
410 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
411 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
413 $tpl->set( 'body_onload', false );
415 $tpl->set( 'sidebar', $this->buildSidebar() );
416 $tpl->set( 'nav_urls', $this->buildNavUrls() );
419 wfProfileIn( "$fname-execute" );
420 $res = $tpl->execute();
421 wfProfileOut( "$fname-execute" );
423 // result may be an error
424 $this->printOrError( $res );
425 wfProfileOut( $fname );
429 * Output the string, or print error message if it's
430 * an error object of the appropriate type.
431 * For the base class, assume strings all around.
436 function printOrError( &$str ) {
441 * build array of urls for personal toolbar
445 function buildPersonalUrls() {
446 global $wgTitle, $wgShowIPinHeader, $wgContLang;
448 $fname = 'SkinTemplate::buildPersonalUrls';
449 $pageurl = $wgTitle->getLocalURL();
450 wfProfileIn( $fname );
452 /* set up the default links for the personal toolbar */
453 $personal_urls = array();
454 if ($this->loggedin
) {
455 $personal_urls['userpage'] = array(
456 'text' => $this->username
,
457 'href' => &$this->userpageUrlDetails
['href'],
458 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
459 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
461 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
462 $personal_urls['mytalk'] = array(
463 'text' => wfMsg('mytalk'),
464 'href' => &$usertalkUrlDetails['href'],
465 'class' => $usertalkUrlDetails['exists']?
false:'new',
466 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
468 $href = $this->makeSpecialUrl('Preferences');
469 $personal_urls['preferences'] = array(
470 'text' => wfMsg('preferences'),
471 'href' => $this->makeSpecialUrl('Preferences'),
472 'active' => ( $href == $pageurl )
474 $href = $this->makeSpecialUrl('Watchlist');
475 $personal_urls['watchlist'] = array(
476 'text' => wfMsg('watchlist'),
478 'active' => ( $href == $pageurl )
480 $href = $this->makeSpecialUrl("Contributions/$this->username");
481 $personal_urls['mycontris'] = array(
482 'text' => wfMsg('mycontris'),
484 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
486 $personal_urls['logout'] = array(
487 'text' => wfMsg('userlogout'),
488 'href' => $this->makeSpecialUrl( 'Userlogout',
489 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
493 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
494 $href = &$this->userpageUrlDetails
['href'];
495 $personal_urls['anonuserpage'] = array(
496 'text' => $this->username
,
498 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
499 'active' => ( $pageurl == $href )
501 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
502 $href = &$usertalkUrlDetails['href'];
503 $personal_urls['anontalk'] = array(
504 'text' => wfMsg('anontalk'),
506 'class' => $usertalkUrlDetails['exists']?
false:'new',
507 'active' => ( $pageurl == $href )
509 $personal_urls['anonlogin'] = array(
510 'text' => wfMsg('userlogin'),
511 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
512 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
516 $personal_urls['login'] = array(
517 'text' => wfMsg('userlogin'),
518 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
519 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
523 wfProfileOut( $fname );
524 return $personal_urls;
528 * Returns true if the IP should be shown in the header
530 function showIPinHeader() {
531 global $wgShowIPinHeader;
532 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
535 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
538 $classes[] = 'selected';
540 if( $checkEdit && $title->getArticleId() == 0 ) {
542 $query = 'action=edit';
545 $text = wfMsg( $message );
546 if ( $text == "<$message>" ) {
547 $text = html_entity_decode($text);
551 'class' => implode( ' ', $classes ),
553 'href' => $title->getLocalUrl( $query ) );
556 function makeTalkUrlDetails( $name, $urlaction='' ) {
557 $title = Title
::newFromText( $name );
558 $title = $title->getTalkPage();
559 $this->checkTitle($title, $name);
561 'href' => $title->getLocalURL( $urlaction ),
562 'exists' => $title->getArticleID() != 0?
true:false
566 function makeArticleUrlDetails( $name, $urlaction='' ) {
567 $title = Title
::newFromText( $name );
568 $title= $title->getSubjectPage();
569 $this->checkTitle($title, $name);
571 'href' => $title->getLocalURL( $urlaction ),
572 'exists' => $title->getArticleID() != 0?
true:false
577 * an array of edit links by default used for the tabs
581 function buildContentActionUrls () {
582 global $wgContLang, $wgDBprefix;
583 $fname = 'SkinTemplate::buildContentActionUrls';
584 wfProfileIn( $fname );
586 global $wgUser, $wgRequest;
587 $action = $wgRequest->getText( 'action' );
588 $section = $wgRequest->getText( 'section' );
589 $content_actions = array();
591 $prevent_active_tabs = false ;
592 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
594 if( $this->iscontent
) {
595 $subjpage = $this->mTitle
->getSubjectPage();
596 $talkpage = $this->mTitle
->getTalkPage();
598 $nskey = $this->getNameSpaceKey();
599 $content_actions[$nskey] = $this->tabAction(
602 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
605 $content_actions['talk'] = $this->tabAction(
608 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
612 wfProfileIn( "$fname-edit" );
613 if ( $this->mTitle
->userCanEdit() ) {
614 $istalk = $this->mTitle
->isTalkPage();
615 $istalkclass = $istalk?
' istalk':'';
616 $content_actions['edit'] = array(
617 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
618 'text' => wfMsg('edit'),
619 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
623 $content_actions['addsection'] = array(
624 'class' => $section == 'new'?
'selected':false,
625 'text' => wfMsg('addsection'),
626 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
630 $content_actions['viewsource'] = array(
631 'class' => ($action == 'edit') ?
'selected' : false,
632 'text' => wfMsg('viewsource'),
633 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
636 wfProfileOut( "$fname-edit" );
638 wfProfileIn( "$fname-live" );
639 if ( $this->mTitle
->getArticleId() ) {
641 $content_actions['history'] = array(
642 'class' => ($action == 'history') ?
'selected' : false,
643 'text' => wfMsg('history_short'),
644 'href' => $this->mTitle
->getLocalUrl( 'action=history')
647 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
648 if(!$this->mTitle
->isProtected()){
649 $content_actions['protect'] = array(
650 'class' => ($action == 'protect') ?
'selected' : false,
651 'text' => wfMsg('protect'),
652 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
656 $content_actions['unprotect'] = array(
657 'class' => ($action == 'unprotect') ?
'selected' : false,
658 'text' => wfMsg('unprotect'),
659 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
663 if($wgUser->isAllowed('delete')){
664 $content_actions['delete'] = array(
665 'class' => ($action == 'delete') ?
'selected' : false,
666 'text' => wfMsg('delete'),
667 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
670 if ( $this->mTitle
->userCanMove()) {
671 $content_actions['move'] = array(
672 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
673 'text' => wfMsg('move'),
674 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
678 //article doesn't exist or is deleted
679 if($wgUser->isAllowed('delete')){
680 if( $n = $this->mTitle
->isDeleted() ) {
681 $content_actions['undelete'] = array(
683 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
684 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
689 wfProfileOut( "$fname-live" );
691 if( $this->loggedin
) {
692 if( !$this->mTitle
->userIsWatching()) {
693 $content_actions['watch'] = array(
694 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
695 'text' => wfMsg('watch'),
696 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
699 $content_actions['unwatch'] = array(
700 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
701 'text' => wfMsg('unwatch'),
702 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
707 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
709 /* show special page tab */
711 $content_actions['article'] = array(
712 'class' => 'selected',
713 'text' => wfMsg('specialpage'),
714 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
717 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
720 /* show links to different language variants */
721 global $wgDisableLangConversion;
722 $variants = $wgContLang->getVariants();
723 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
724 $preferred = $wgContLang->getPreferredVariant();
727 $actstr = 'action=' . $action . '&';
729 foreach( $variants as $code ) {
730 $varname = $wgContLang->getVariantname( $code );
731 if( $varname == 'disable' )
733 $selected = ( $code == $preferred )?
'selected' : false;
734 $content_actions['varlang-' . $vcount] = array(
735 'class' => $selected,
737 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
743 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
745 wfProfileOut( $fname );
746 return $content_actions;
752 * build array of common navigation links
756 function buildNavUrls () {
757 global $wgUseTrackbacks, $wgTitle, $wgArticle;
759 $fname = 'SkinTemplate::buildNavUrls';
760 wfProfileIn( $fname );
762 global $wgUser, $wgRequest;
763 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
765 $action = $wgRequest->getText( 'action' );
766 $oldid = $wgRequest->getVal( 'oldid' );
767 $diff = $wgRequest->getVal( 'diff' );
770 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
771 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
772 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
773 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
774 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
775 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
776 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
777 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
778 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
779 if( $wgEnableUploads ) {
780 if ($wgUploadNavigationUrl) {
781 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
783 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
786 if ($wgUploadNavigationUrl)
787 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
789 $nav_urls['upload'] = false;
791 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
794 // A print stylesheet is attached to all pages, but nobody ever
795 // figures that out. :) Add a link...
796 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
797 $revid = $wgArticle->getRevIdFetched();
798 if ( !( $revid == 0 ) )
799 $nav_urls['print'] = array(
800 'text' => wfMsg( 'printableversion' ),
801 'href' => $wgRequest->appendQuery( 'printable=yes' )
804 // Also add a "permalink" while we're at it
806 $nav_urls['permalink'] = array(
807 'text' => wfMsg( 'permalink' ),
811 if ( !( $revid == 0 ) )
812 $nav_urls['permalink'] = array(
813 'text' => wfMsg( 'permalink' ),
814 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
818 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
821 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
822 $nav_urls['whatlinkshere'] = array(
823 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
825 if( $this->mTitle
->getArticleId() ) {
826 $nav_urls['recentchangeslinked'] = array(
827 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
830 if ($wgUseTrackbacks)
831 $nav_urls['trackbacklink'] = array(
832 'href' => $wgTitle->trackbackURL()
836 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
837 $id = User
::idFromName($this->mTitle
->getText());
838 $ip = User
::isIP($this->mTitle
->getText());
844 if($id ||
$ip) { # both anons and non-anons have contribution list
845 $nav_urls['contributions'] = array(
846 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
848 $nav_urls['userfiles'] = array(
849 'href' => $this->makeSpecialUrl('Newimages/' . $this->mTitle
->getText() )
851 if ( $wgUser->isAllowed( 'protect' ) )
852 $nav_urls['blockip'] = array(
853 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
856 $nav_urls['contributions'] = false;
858 $nav_urls['emailuser'] = false;
859 if( $this->showEmailUser( $id ) ) {
860 $nav_urls['emailuser'] = array(
861 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
864 wfProfileOut( $fname );
869 * Generate strings used for xml 'id' names
873 function getNameSpaceKey () {
874 switch ($this->mTitle
->getNamespace()) {
882 return 'nstab-media';
884 return 'nstab-special';
886 case NS_PROJECT_TALK
:
890 return 'nstab-image';
892 case NS_MEDIAWIKI_TALK
:
893 return 'nstab-mediawiki';
895 case NS_TEMPLATE_TALK
:
896 return 'nstab-template';
901 case NS_CATEGORY_TALK
:
902 return 'nstab-category';
904 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
911 function setupUserCss() {
912 $fname = 'SkinTemplate::setupUserCss';
913 wfProfileIn( $fname );
915 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
919 $siteargs = '&maxage=' . $wgSquidMaxage;
921 # Add user-specific code if this is a user and we allow that kind of thing
923 if ( $wgAllowUserCss && $this->loggedin
) {
924 $action = $wgRequest->getText('action');
926 # if we're previewing the CSS page, use it
927 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
928 $siteargs = "&smaxage=0&maxage=0";
929 $usercss = $wgRequest->getText('wpTextbox1');
931 $usercss = '@import "' .
932 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
933 'action=raw&ctype=text/css') . '";' ."\n";
936 $siteargs .= '&ts=' . $wgUser->mTouched
;
939 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
941 # If we use the site's dynamic CSS, throw that in, too
942 if ( $wgUseSiteCss ) {
943 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
944 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
945 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
946 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
949 # If we use any dynamic CSS, make a little CDATA block out of it.
951 if ( !empty($sitecss) ||
!empty($usercss) ) {
952 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
954 wfProfileOut( $fname );
960 function setupUserJs() {
961 $fname = 'SkinTemplate::setupUserJs';
962 wfProfileIn( $fname );
964 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
965 $action = $wgRequest->getText('action');
967 if( $wgAllowUserJs && $this->loggedin
) {
968 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
969 # XXX: additional security check/prompt?
970 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
972 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
975 wfProfileOut( $fname );
979 * Code for extensions to hook into to provide per-page CSS, see
980 * extensions/PageCSS/PageCSS.php for an implementation of this.
984 function setupPageCss() {
985 $fname = 'SkinTemplate::setupPageCss';
986 wfProfileIn( $fname );
988 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle
->isProtected() ) );
989 wfProfileOut( $fname );
994 * returns css with user-specific options
998 function getUserStylesheet() {
999 $fname = 'SkinTemplate::getUserStylesheet';
1000 wfProfileIn( $fname );
1003 $s = "/* generated user stylesheet */\n";
1004 $s .= $this->reallyDoGetUserStyles();
1005 wfProfileOut( $fname );
1012 function getUserJs() {
1013 $fname = 'SkinTemplate::getUserJs';
1014 wfProfileIn( $fname );
1016 global $wgStylePath;
1017 $s = '/* generated javascript */';
1018 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1019 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1021 // avoid inclusion of non defined user JavaScript (with custom skins only)
1022 // by checking for default message content
1023 $msgKey = ucfirst($this->skinname
).'.js';
1024 $userJS = wfMsg($msgKey);
1025 if ('<'.$msgKey.'>' != $userJS) {
1029 wfProfileOut( $fname );
1035 * Generic wrapper for template functions, with interface
1036 * compatible with what we use of PHPTAL 0.7.
1037 * @package MediaWiki
1040 class QuickTemplate
{
1044 function QuickTemplate() {
1045 $this->data
= array();
1046 $this->translator
= new MediaWiki_I18N();
1052 function set( $name, $value ) {
1053 $this->data
[$name] = $value;
1059 function setRef($name, &$value) {
1060 $this->data
[$name] =& $value;
1066 function setTranslator( &$t ) {
1067 $this->translator
= &$t;
1073 function execute() {
1074 echo "Override this function.";
1081 function text( $str ) {
1082 echo htmlspecialchars( $this->data
[$str] );
1088 function html( $str ) {
1089 echo $this->data
[$str];
1095 function msg( $str ) {
1096 echo htmlspecialchars( $this->translator
->translate( $str ) );
1102 function msgHtml( $str ) {
1103 echo $this->translator
->translate( $str );
1107 * An ugly, ugly hack.
1110 function msgWiki( $str ) {
1111 global $wgParser, $wgTitle, $wgOut;
1113 $text = $this->translator
->translate( $str );
1114 $parserOutput = $wgParser->parse( $text, $wgTitle,
1115 $wgOut->mParserOptions
, true );
1116 echo $parserOutput->getText();
1122 function haveData( $str ) {
1123 return $this->data
[$str];
1129 function haveMsg( $str ) {
1130 $msg = $this->translator
->translate( $str );
1131 return ($msg != '-') && ($msg != ''); # ????
1135 } // end of if( defined( 'MEDIAWIKI' ) )