2 if ( ! defined( 'MEDIAWIKI' ) )
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
30 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
31 * and is optional. You'll need to install PHPTAL manually to use
32 * skins that depend on it.
38 require_once 'GlobalFunctions.php';
41 * Wrapper object for MediaWiki's localization functions,
42 * to be passed to the template engine.
47 class MediaWiki_I18N
{
48 var $_context = array();
50 function set($varName, $value) {
51 $this->_context
[$varName] = $value;
54 function translate($value) {
55 $fname = 'SkinTemplate-translate';
56 wfProfileIn( $fname );
58 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
59 $value = preg_replace( '/^string:/', '', $value );
61 $value = wfMsg( $value );
62 // interpolate variables
63 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
64 list($src, $var) = $m;
66 $varValue = $this->_context
[$var];
68 $value = str_replace($src, $varValue, $value);
70 wfProfileOut( $fname );
79 class SkinTemplate
extends Skin
{
85 * Name of our skin, set in initPage()
86 * It probably need to be all lower case.
91 * Stylesheets set to use
92 * Sub directory in ./skins/ where various stylesheets are located
97 * For QuickTemplate, the name of the subclass which
98 * will actually fill the template.
100 * In PHPTal mode, name of PHPTal template to be used.
101 * '.pt' will be automaticly added to it on PHPTAL object creation
108 * Setup the base parameters...
109 * Child classes should override this to set the name,
110 * style subdirectory, and template filler callback.
112 * @param OutputPage $out
114 function initPage( &$out ) {
115 parent
::initPage( $out );
116 $this->skinname
= 'monobook';
117 $this->stylename
= 'monobook';
118 $this->template
= 'QuickTemplate';
122 * Create the template engine object; we feed it a bunch of data
123 * and eventually it spits out some HTML. Should have interface
124 * roughly equivalent to PHPTAL 0.7.
126 * @param string $callback (or file)
127 * @param string $repository subdirectory where we keep template files
128 * @param string $cache_dir
132 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
133 return new $classname();
137 * initialize various variables and generate the template
139 * @param OutputPage $out
142 function outputPage( &$out ) {
143 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
144 global $wgScript, $wgStylePath, $wgContLanguageCode;
145 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
146 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
147 global $wgMaxCredits, $wgShowCreditsIfMax;
148 global $wgPageShowWatchingUsers;
149 global $wgUseTrackbacks;
151 $fname = 'SkinTemplate::outputPage';
152 wfProfileIn( $fname );
154 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
156 wfProfileIn( "$fname-init" );
157 $this->initPage( $out );
159 $this->mTitle
=& $wgTitle;
160 $this->mUser
=& $wgUser;
162 $tpl = $this->setupTemplate( $this->template
, 'skins' );
164 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
165 $tpl->setTranslator(new MediaWiki_I18N());
167 wfProfileOut( "$fname-init" );
169 wfProfileIn( "$fname-stuff" );
170 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
171 $this->thisurl
= $this->mTitle
->getPrefixedURL();
172 $this->loggedin
= $wgUser->isLoggedIn();
173 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
174 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
175 $this->username
= $wgUser->getName();
176 $userPage = $wgUser->getUserPage();
177 $this->userpage
= $userPage->getPrefixedText();
179 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
180 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
182 # This won't be used in the standard skins, but we define it to preserve the interface
183 # To save time, we check for existence
184 $this->userpageUrlDetails
= $this->makeKnownUrlDetails($this->userpage
);
187 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
188 $this->setupUserCss();
189 $this->setupUserJs();
190 $this->titletxt
= $this->mTitle
->getPrefixedText();
191 wfProfileOut( "$fname-stuff" );
193 wfProfileIn( "$fname-stuff2" );
194 $tpl->set( 'title', $wgOut->getPageTitle() );
195 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
197 $tpl->setRef( "thispage", $this->thispage
);
198 $subpagestr = $this->subPageSubtitle();
200 'subtitle', !empty($subpagestr)?
201 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
204 $undelete = $this->getUndeleteLink();
206 "undelete", !empty($undelete)?
207 '<span class="subpages">'.$undelete.'</span>':
211 $tpl->set( 'catlinks', $this->getCategories());
212 if( $wgOut->isSyndicated() ) {
214 foreach( $wgFeedClasses as $format => $class ) {
215 $feeds[$format] = array(
217 'href' => $wgRequest->appendQuery( "feed=$format" )
220 $tpl->setRef( 'feeds', $feeds );
222 $tpl->set( 'feeds', false );
224 if ($wgUseTrackbacks && $out->isArticleRelated())
225 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
227 $tpl->setRef( 'mimetype', $wgMimeType );
228 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
229 $tpl->setRef( 'charset', $wgOutputEncoding );
230 $tpl->set( 'headlinks', $out->getHeadLinks() );
231 $tpl->set('headscripts', $out->getScript() );
232 $tpl->setRef( 'wgScript', $wgScript );
233 $tpl->setRef( 'skinname', $this->skinname
);
234 $tpl->setRef( 'stylename', $this->stylename
);
235 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
236 $tpl->setRef( 'loggedin', $this->loggedin
);
237 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
238 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
239 /* XXX currently unused, might get useful later
240 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
241 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
242 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
243 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
244 $tpl->set( "helppage", wfMsg('helppage'));
246 $tpl->set( 'searchaction', $this->escapeSearchLink() );
247 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
248 $tpl->setRef( 'stylepath', $wgStylePath );
249 $tpl->setRef( 'logopath', $wgLogo );
250 $tpl->setRef( "lang", $wgContLanguageCode );
251 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
252 $tpl->set( 'rtl', $wgContLang->isRTL() );
253 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
254 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
255 $tpl->setRef( 'username', $this->username
);
256 $tpl->setRef( 'userpage', $this->userpage
);
257 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
258 $tpl->set( 'pagecss', $this->setupPageCss() );
259 $tpl->setRef( 'usercss', $this->usercss
);
260 $tpl->setRef( 'userjs', $this->userjs
);
261 $tpl->setRef( 'userjsprev', $this->userjsprev
);
264 if($this->loggedin
) {
265 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
267 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
270 $tpl->set('jsvarurl', false);
272 if( $wgUser->getNewtalk() ) {
273 $usertitle = $this->mUser
->getUserPage();
274 $usertalktitle = $usertitle->getTalkPage();
275 if( !$usertalktitle->equals( $this->mTitle
) ) {
276 $ntl = wfMsg( 'youhavenewmessages',
277 $this->makeKnownLinkObj(
279 wfMsgHtml( 'newmessageslink' )
281 $this->makeKnownLinkObj(
283 wfMsgHtml( 'newmessagesdifflink' ),
288 $wgOut->setSquidMaxage(0);
293 wfProfileOut( "$fname-stuff2" );
295 wfProfileIn( "$fname-stuff3" );
296 $tpl->setRef( 'newtalk', $ntl );
297 $tpl->setRef( 'skin', $this);
298 $tpl->set( 'logo', $this->logoText() );
299 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
300 if ( !$wgDisableCounters ) {
301 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
303 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
305 $tpl->set('viewcount', false);
308 $tpl->set('viewcount', false);
311 if ($wgPageShowWatchingUsers) {
312 $dbr =& wfGetDB( DB_SLAVE
);
313 extract( $dbr->tableNames( 'watchlist' ) );
314 $sql = "SELECT COUNT(*) AS n FROM $watchlist
315 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
316 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
317 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
318 $x = $dbr->fetchObject( $res );
319 $numberofwatchingusers = $x->n
;
320 if ($numberofwatchingusers > 0) {
321 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
323 $tpl->set('numberofwatchingusers', false);
326 $tpl->set('numberofwatchingusers', false);
329 $tpl->set('copyright',$this->getCopyright());
331 $this->credits
= false;
333 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
334 require_once("Credits.php");
335 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
337 $tpl->set('lastmod', $this->lastModified());
340 $tpl->setRef( 'credits', $this->credits
);
342 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
343 $tpl->set('copyright', $this->getCopyright());
344 $tpl->set('viewcount', false);
345 $tpl->set('lastmod', false);
346 $tpl->set('credits', false);
347 $tpl->set('numberofwatchingusers', false);
349 $tpl->set('copyright', false);
350 $tpl->set('viewcount', false);
351 $tpl->set('lastmod', false);
352 $tpl->set('credits', false);
353 $tpl->set('numberofwatchingusers', false);
355 wfProfileOut( "$fname-stuff3" );
357 wfProfileIn( "$fname-stuff4" );
358 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
359 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
360 $tpl->set( 'disclaimer', $this->disclaimerLink() );
361 $tpl->set( 'privacy', $this->privacyLink() );
362 $tpl->set( 'about', $this->aboutLink() );
364 $tpl->setRef( 'debug', $out->mDebugtext
);
365 $tpl->set( 'reporttime', $out->reportTime() );
366 $tpl->set( 'sitenotice', wfGetSiteNotice() );
368 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
369 $out->mBodytext
.= $printfooter ;
370 $tpl->setRef( 'bodytext', $out->mBodytext
);
373 $language_urls = array();
375 if ( !$wgHideInterlanguageLinks ) {
376 foreach( $wgOut->getLanguageLinks() as $l ) {
377 $tmp = explode( ':', $l, 2 );
378 $class = 'interwiki-' . $tmp[0];
380 $nt = Title
::newFromText( $l );
381 $language_urls[] = array(
382 'href' => $nt->getFullURL(),
383 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
388 if(count($language_urls)) {
389 $tpl->setRef( 'language_urls', $language_urls);
391 $tpl->set('language_urls', false);
393 wfProfileOut( "$fname-stuff4" );
396 $tpl->set('personal_urls', $this->buildPersonalUrls());
397 $content_actions = $this->buildContentActionUrls();
398 $tpl->setRef('content_actions', $content_actions);
400 // XXX: attach this from javascript, same with section editing
401 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
403 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
405 $tpl->set('body_ondblclick', false);
407 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
408 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
410 $tpl->set( 'body_onload', false );
412 $tpl->set( 'sidebar', $this->buildSidebar() );
413 $tpl->set( 'nav_urls', $this->buildNavUrls() );
416 wfProfileIn( "$fname-execute" );
417 $res = $tpl->execute();
418 wfProfileOut( "$fname-execute" );
420 // result may be an error
421 $this->printOrError( $res );
422 wfProfileOut( $fname );
426 * Output the string, or print error message if it's
427 * an error object of the appropriate type.
428 * For the base class, assume strings all around.
433 function printOrError( &$str ) {
438 * build array of urls for personal toolbar
442 function buildPersonalUrls() {
443 global $wgTitle, $wgShowIPinHeader, $wgContLang;
445 $fname = 'SkinTemplate::buildPersonalUrls';
446 $pageurl = $wgTitle->getLocalURL();
447 wfProfileIn( $fname );
449 /* set up the default links for the personal toolbar */
450 $personal_urls = array();
451 if ($this->loggedin
) {
452 $personal_urls['userpage'] = array(
453 'text' => $this->username
,
454 'href' => &$this->userpageUrlDetails
['href'],
455 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
456 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
458 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
459 $personal_urls['mytalk'] = array(
460 'text' => wfMsg('mytalk'),
461 'href' => &$usertalkUrlDetails['href'],
462 'class' => $usertalkUrlDetails['exists']?
false:'new',
463 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
465 $href = $this->makeSpecialUrl('Preferences');
466 $personal_urls['preferences'] = array(
467 'text' => wfMsg('preferences'),
468 'href' => $this->makeSpecialUrl('Preferences'),
469 'active' => ( $href == $pageurl )
471 $href = $this->makeSpecialUrl('Watchlist');
472 $personal_urls['watchlist'] = array(
473 'text' => wfMsg('watchlist'),
475 'active' => ( $href == $pageurl )
477 $href = $this->makeSpecialUrl("Contributions/$this->username");
478 $personal_urls['mycontris'] = array(
479 'text' => wfMsg('mycontris'),
481 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
483 $personal_urls['logout'] = array(
484 'text' => wfMsg('userlogout'),
485 'href' => $this->makeSpecialUrl( 'Userlogout',
486 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
490 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
491 $href = &$this->userpageUrlDetails
['href'];
492 $personal_urls['anonuserpage'] = array(
493 'text' => $this->username
,
495 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
496 'active' => ( $pageurl == $href )
498 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
499 $href = &$usertalkUrlDetails['href'];
500 $personal_urls['anontalk'] = array(
501 'text' => wfMsg('anontalk'),
503 'class' => $usertalkUrlDetails['exists']?
false:'new',
504 'active' => ( $pageurl == $href )
506 $personal_urls['anonlogin'] = array(
507 'text' => wfMsg('userlogin'),
508 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
509 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
513 $personal_urls['login'] = array(
514 'text' => wfMsg('userlogin'),
515 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
516 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
520 wfProfileOut( $fname );
521 return $personal_urls;
525 * Returns true if the IP should be shown in the header
527 function showIPinHeader() {
528 global $wgShowIPinHeader;
529 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
532 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
535 $classes[] = 'selected';
537 if( $checkEdit && $title->getArticleId() == 0 ) {
539 $query = 'action=edit';
542 $text = wfMsg( $message );
543 if ( $text == "<$message>" ) {
544 $text = html_entity_decode($text);
548 'class' => implode( ' ', $classes ),
550 'href' => $title->getLocalUrl( $query ) );
553 function makeTalkUrlDetails( $name, $urlaction='' ) {
554 $title = Title
::newFromText( $name );
555 $title = $title->getTalkPage();
556 $this->checkTitle($title, $name);
558 'href' => $title->getLocalURL( $urlaction ),
559 'exists' => $title->getArticleID() != 0?
true:false
563 function makeArticleUrlDetails( $name, $urlaction='' ) {
564 $title = Title
::newFromText( $name );
565 $title= $title->getSubjectPage();
566 $this->checkTitle($title, $name);
568 'href' => $title->getLocalURL( $urlaction ),
569 'exists' => $title->getArticleID() != 0?
true:false
574 * an array of edit links by default used for the tabs
578 function buildContentActionUrls () {
579 global $wgContLang, $wgDBprefix;
580 $fname = 'SkinTemplate::buildContentActionUrls';
581 wfProfileIn( $fname );
583 global $wgUser, $wgRequest;
584 $action = $wgRequest->getText( 'action' );
585 $section = $wgRequest->getText( 'section' );
586 $content_actions = array();
588 $prevent_active_tabs = false ;
589 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
591 if( $this->iscontent
) {
592 $subjpage = $this->mTitle
->getSubjectPage();
593 $talkpage = $this->mTitle
->getTalkPage();
595 $nskey = $this->getNameSpaceKey();
596 $content_actions[$nskey] = $this->tabAction(
599 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
602 $content_actions['talk'] = $this->tabAction(
605 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
609 wfProfileIn( "$fname-edit" );
610 if ( $this->mTitle
->userCanEdit() ) {
611 $istalk = $this->mTitle
->isTalkPage();
612 $istalkclass = $istalk?
' istalk':'';
613 $content_actions['edit'] = array(
614 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
615 'text' => wfMsg('edit'),
616 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
620 $content_actions['addsection'] = array(
621 'class' => $section == 'new'?
'selected':false,
622 'text' => wfMsg('addsection'),
623 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
627 $content_actions['viewsource'] = array(
628 'class' => ($action == 'edit') ?
'selected' : false,
629 'text' => wfMsg('viewsource'),
630 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
633 wfProfileOut( "$fname-edit" );
635 wfProfileIn( "$fname-live" );
636 if ( $this->mTitle
->getArticleId() ) {
638 $content_actions['history'] = array(
639 'class' => ($action == 'history') ?
'selected' : false,
640 'text' => wfMsg('history_short'),
641 'href' => $this->mTitle
->getLocalUrl( 'action=history')
644 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
645 if(!$this->mTitle
->isProtected()){
646 $content_actions['protect'] = array(
647 'class' => ($action == 'protect') ?
'selected' : false,
648 'text' => wfMsg('protect'),
649 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
653 $content_actions['unprotect'] = array(
654 'class' => ($action == 'unprotect') ?
'selected' : false,
655 'text' => wfMsg('unprotect'),
656 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
660 if($wgUser->isAllowed('delete')){
661 $content_actions['delete'] = array(
662 'class' => ($action == 'delete') ?
'selected' : false,
663 'text' => wfMsg('delete'),
664 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
667 if ( $this->mTitle
->userCanMove()) {
668 $content_actions['move'] = array(
669 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
670 'text' => wfMsg('move'),
671 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
675 //article doesn't exist or is deleted
676 if($wgUser->isAllowed('delete')){
677 if( $n = $this->mTitle
->isDeleted() ) {
678 $content_actions['undelete'] = array(
680 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
681 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
686 wfProfileOut( "$fname-live" );
688 if( $this->loggedin
) {
689 if( !$this->mTitle
->userIsWatching()) {
690 $content_actions['watch'] = array(
691 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
692 'text' => wfMsg('watch'),
693 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
696 $content_actions['unwatch'] = array(
697 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
698 'text' => wfMsg('unwatch'),
699 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
704 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
706 /* show special page tab */
708 $content_actions['article'] = array(
709 'class' => 'selected',
710 'text' => wfMsg('specialpage'),
711 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
714 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
717 /* show links to different language variants */
718 global $wgDisableLangConversion;
719 $variants = $wgContLang->getVariants();
720 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
721 $preferred = $wgContLang->getPreferredVariant();
724 $actstr = 'action=' . $action . '&';
726 foreach( $variants as $code ) {
727 $varname = $wgContLang->getVariantname( $code );
728 if( $varname == 'disable' )
730 $selected = ( $code == $preferred )?
'selected' : false;
731 $content_actions['varlang-' . $vcount] = array(
732 'class' => $selected,
734 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
740 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
742 wfProfileOut( $fname );
743 return $content_actions;
749 * build array of common navigation links
753 function buildNavUrls () {
754 global $wgUseTrackbacks, $wgTitle, $wgArticle;
756 $fname = 'SkinTemplate::buildNavUrls';
757 wfProfileIn( $fname );
759 global $wgUser, $wgRequest;
760 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
762 $action = $wgRequest->getText( 'action' );
763 $oldid = $wgRequest->getVal( 'oldid' );
764 $diff = $wgRequest->getVal( 'diff' );
767 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
768 if( $wgEnableUploads ) {
769 if ($wgUploadNavigationUrl) {
770 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
772 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
775 if ($wgUploadNavigationUrl)
776 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
778 $nav_urls['upload'] = false;
780 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
783 // A print stylesheet is attached to all pages, but nobody ever
784 // figures that out. :) Add a link...
785 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
786 $revid = $wgArticle->getRevIdFetched();
787 if ( !( $revid == 0 ) )
788 $nav_urls['print'] = array(
789 'text' => wfMsg( 'printableversion' ),
790 'href' => $wgRequest->appendQuery( 'printable=yes' )
793 // Also add a "permalink" while we're at it
795 $nav_urls['permalink'] = array(
796 'text' => wfMsg( 'permalink' ),
800 if ( !( $revid == 0 ) )
801 $nav_urls['permalink'] = array(
802 'text' => wfMsg( 'permalink' ),
803 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
807 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
810 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
811 $nav_urls['whatlinkshere'] = array(
812 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
814 if( $this->mTitle
->getArticleId() ) {
815 $nav_urls['recentchangeslinked'] = array(
816 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
819 if ($wgUseTrackbacks)
820 $nav_urls['trackbacklink'] = array(
821 'href' => $wgTitle->trackbackURL()
825 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
826 $id = User
::idFromName($this->mTitle
->getText());
827 $ip = User
::isIP($this->mTitle
->getText());
833 if($id ||
$ip) { # both anons and non-anons have contri list
834 $nav_urls['contributions'] = array(
835 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
837 if ( $wgUser->isAllowed( 'block' ) )
838 $nav_urls['blockip'] = array(
839 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
842 $nav_urls['contributions'] = false;
844 $nav_urls['emailuser'] = false;
845 if( $this->showEmailUser( $id ) ) {
846 $nav_urls['emailuser'] = array(
847 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
850 wfProfileOut( $fname );
855 * Generate strings used for xml 'id' names
859 function getNameSpaceKey () {
860 switch ($this->mTitle
->getNamespace()) {
868 return 'nstab-media';
870 return 'nstab-special';
872 case NS_PROJECT_TALK
:
876 return 'nstab-image';
878 case NS_MEDIAWIKI_TALK
:
879 return 'nstab-mediawiki';
881 case NS_TEMPLATE_TALK
:
882 return 'nstab-template';
887 case NS_CATEGORY_TALK
:
888 return 'nstab-category';
890 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
897 function setupUserCss() {
898 $fname = 'SkinTemplate::setupUserCss';
899 wfProfileIn( $fname );
901 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
905 $siteargs = '&maxage=' . $wgSquidMaxage;
907 # Add user-specific code if this is a user and we allow that kind of thing
909 if ( $wgAllowUserCss && $this->loggedin
) {
910 $action = $wgRequest->getText('action');
912 # if we're previewing the CSS page, use it
913 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
914 $siteargs = "&smaxage=0&maxage=0";
915 $usercss = $wgRequest->getText('wpTextbox1');
917 $usercss = '@import "' .
918 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
919 'action=raw&ctype=text/css') . '";' ."\n";
922 $siteargs .= '&ts=' . $wgUser->mTouched
;
925 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
927 # If we use the site's dynamic CSS, throw that in, too
928 if ( $wgUseSiteCss ) {
929 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
930 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
931 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
932 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
935 # If we use any dynamic CSS, make a little CDATA block out of it.
937 if ( !empty($sitecss) ||
!empty($usercss) ) {
938 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
940 wfProfileOut( $fname );
946 function setupUserJs() {
947 $fname = 'SkinTemplate::setupUserJs';
948 wfProfileIn( $fname );
950 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
951 $action = $wgRequest->getText('action');
953 if( $wgAllowUserJs && $this->loggedin
) {
954 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
955 # XXX: additional security check/prompt?
956 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
958 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
961 wfProfileOut( $fname );
965 * Code for extensions to hook into to provide per-page CSS, see
966 * extensions/PageCSS/PageCSS.php for an implementation of this.
970 function setupPageCss() {
971 $fname = 'SkinTemplate::setupPageCss';
972 wfProfileIn( $fname );
974 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
976 wfProfileOut( $fname );
981 * returns css with user-specific options
985 function getUserStylesheet() {
986 $fname = 'SkinTemplate::getUserStylesheet';
987 wfProfileIn( $fname );
990 $s = "/* generated user stylesheet */\n";
991 $s .= $this->reallyDoGetUserStyles();
992 wfProfileOut( $fname );
999 function getUserJs() {
1000 $fname = 'SkinTemplate::getUserJs';
1001 wfProfileIn( $fname );
1003 global $wgStylePath;
1004 $s = '/* generated javascript */';
1005 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1006 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1008 // avoid inclusion of non defined user JavaScript (with custom skins only)
1009 // by checking for default message content
1010 $msgKey = ucfirst($this->skinname
).'.js';
1011 $userJS = wfMsg($msgKey);
1012 if ('<'.$msgKey.'>' != $userJS) {
1016 wfProfileOut( $fname );
1022 * Generic wrapper for template functions, with interface
1023 * compatible with what we use of PHPTAL 0.7.
1024 * @package MediaWiki
1027 class QuickTemplate
{
1031 function QuickTemplate() {
1032 $this->data
= array();
1033 $this->translator
= new MediaWiki_I18N();
1039 function set( $name, $value ) {
1040 $this->data
[$name] = $value;
1046 function setRef($name, &$value) {
1047 $this->data
[$name] =& $value;
1053 function setTranslator( &$t ) {
1054 $this->translator
= &$t;
1060 function execute() {
1061 echo "Override this function.";
1068 function text( $str ) {
1069 echo htmlspecialchars( $this->data
[$str] );
1075 function html( $str ) {
1076 echo $this->data
[$str];
1082 function msg( $str ) {
1083 echo htmlspecialchars( $this->translator
->translate( $str ) );
1089 function msgHtml( $str ) {
1090 echo $this->translator
->translate( $str );
1094 * An ugly, ugly hack.
1097 function msgWiki( $str ) {
1098 global $wgParser, $wgTitle, $wgOut;
1100 $text = $this->translator
->translate( $str );
1101 $parserOutput = $wgParser->parse( $text, $wgTitle,
1102 $wgOut->mParserOptions
, true );
1103 echo $parserOutput->getText();
1109 function haveData( $str ) {
1110 return $this->data
[$str];
1116 function haveMsg( $str ) {
1117 $msg = $this->translator
->translate( $str );
1118 return ($msg != '-') && ($msg != ''); # ????