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" ),
221 'ttip' => wfMsg('tooltip-'.$format)
224 $tpl->setRef( 'feeds', $feeds );
226 $tpl->set( 'feeds', false );
228 if ($wgUseTrackbacks && $out->isArticleRelated())
229 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
231 $tpl->setRef( 'mimetype', $wgMimeType );
232 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
233 $tpl->setRef( 'charset', $wgOutputEncoding );
234 $tpl->set( 'headlinks', $out->getHeadLinks() );
235 $tpl->set('headscripts', $out->getScript() );
236 $tpl->setRef( 'wgScript', $wgScript );
237 $tpl->setRef( 'skinname', $this->skinname
);
238 $tpl->setRef( 'stylename', $this->stylename
);
239 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
240 $tpl->setRef( 'loggedin', $this->loggedin
);
241 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
242 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
243 /* XXX currently unused, might get useful later
244 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
245 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
246 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
247 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
248 $tpl->set( "helppage", wfMsg('helppage'));
250 $tpl->set( 'searchaction', $this->escapeSearchLink() );
251 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
252 $tpl->setRef( 'stylepath', $wgStylePath );
253 $tpl->setRef( 'logopath', $wgLogo );
254 $tpl->setRef( "lang", $wgContLanguageCode );
255 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
256 $tpl->set( 'rtl', $wgContLang->isRTL() );
257 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
258 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
259 $tpl->setRef( 'username', $this->username
);
260 $tpl->setRef( 'userpage', $this->userpage
);
261 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
262 $tpl->set( 'pagecss', $this->setupPageCss() );
263 $tpl->setRef( 'usercss', $this->usercss
);
264 $tpl->setRef( 'userjs', $this->userjs
);
265 $tpl->setRef( 'userjsprev', $this->userjsprev
);
268 if($this->loggedin
) {
269 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
271 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
274 $tpl->set('jsvarurl', false);
276 if( $wgUser->getNewtalk() ) {
277 $usertitle = $this->mUser
->getUserPage();
278 $usertalktitle = $usertitle->getTalkPage();
279 if( !$usertalktitle->equals( $this->mTitle
) ) {
280 $ntl = wfMsg( 'newmessages',
281 $this->makeKnownLinkObj(
283 wfMsgHtml( 'newmessageslink' )
285 $this->makeKnownLinkObj(
287 wfMsgHtml( 'newmessagesdifflink' ),
292 $wgOut->setSquidMaxage(0);
297 wfProfileOut( "$fname-stuff2" );
299 wfProfileIn( "$fname-stuff3" );
300 $tpl->setRef( 'newtalk', $ntl );
301 $tpl->setRef( 'skin', $this);
302 $tpl->set( 'logo', $this->logoText() );
303 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
304 if ( !$wgDisableCounters ) {
305 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
307 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
309 $tpl->set('viewcount', false);
312 $tpl->set('viewcount', false);
315 if ($wgPageShowWatchingUsers) {
316 $dbr =& wfGetDB( DB_SLAVE
);
317 extract( $dbr->tableNames( 'watchlist' ) );
318 $sql = "SELECT COUNT(*) AS n FROM $watchlist
319 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
320 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
321 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
322 $x = $dbr->fetchObject( $res );
323 $numberofwatchingusers = $x->n
;
324 if ($numberofwatchingusers > 0) {
325 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
327 $tpl->set('numberofwatchingusers', false);
330 $tpl->set('numberofwatchingusers', false);
333 $tpl->set('copyright',$this->getCopyright());
335 $this->credits
= false;
337 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
338 require_once("Credits.php");
339 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
341 $tpl->set('lastmod', $this->lastModified());
344 $tpl->setRef( 'credits', $this->credits
);
346 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
347 $tpl->set('copyright', $this->getCopyright());
348 $tpl->set('viewcount', false);
349 $tpl->set('lastmod', false);
350 $tpl->set('credits', false);
351 $tpl->set('numberofwatchingusers', false);
353 $tpl->set('copyright', false);
354 $tpl->set('viewcount', false);
355 $tpl->set('lastmod', false);
356 $tpl->set('credits', false);
357 $tpl->set('numberofwatchingusers', false);
359 wfProfileOut( "$fname-stuff3" );
361 wfProfileIn( "$fname-stuff4" );
362 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
363 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
364 $tpl->set( 'disclaimer', $this->disclaimerLink() );
365 $tpl->set( 'privacy', $this->privacyLink() );
366 $tpl->set( 'about', $this->aboutLink() );
368 $tpl->setRef( 'debug', $out->mDebugtext
);
369 $tpl->set( 'reporttime', $out->reportTime() );
370 $tpl->set( 'sitenotice', wfGetSiteNotice() );
372 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
373 $out->mBodytext
.= $printfooter ;
374 $tpl->setRef( 'bodytext', $out->mBodytext
);
377 $language_urls = array();
379 if ( !$wgHideInterlanguageLinks ) {
380 foreach( $wgOut->getLanguageLinks() as $l ) {
381 $tmp = explode( ':', $l, 2 );
382 $class = 'interwiki-' . $tmp[0];
384 $nt = Title
::newFromText( $l );
385 $language_urls[] = array(
386 'href' => $nt->getFullURL(),
387 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
392 if(count($language_urls)) {
393 $tpl->setRef( 'language_urls', $language_urls);
395 $tpl->set('language_urls', false);
397 wfProfileOut( "$fname-stuff4" );
400 $tpl->set('personal_urls', $this->buildPersonalUrls());
401 $content_actions = $this->buildContentActionUrls();
402 $tpl->setRef('content_actions', $content_actions);
404 // XXX: attach this from javascript, same with section editing
405 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
407 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
409 $tpl->set('body_ondblclick', false);
411 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
412 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
414 $tpl->set( 'body_onload', false );
416 $tpl->set( 'sidebar', $this->buildSidebar() );
417 $tpl->set( 'nav_urls', $this->buildNavUrls() );
420 wfProfileIn( "$fname-execute" );
421 $res = $tpl->execute();
422 wfProfileOut( "$fname-execute" );
424 // result may be an error
425 $this->printOrError( $res );
426 wfProfileOut( $fname );
430 * Output the string, or print error message if it's
431 * an error object of the appropriate type.
432 * For the base class, assume strings all around.
437 function printOrError( &$str ) {
442 * build array of urls for personal toolbar
446 function buildPersonalUrls() {
447 global $wgTitle, $wgShowIPinHeader, $wgContLang;
449 $fname = 'SkinTemplate::buildPersonalUrls';
450 $pageurl = $wgTitle->getLocalURL();
451 wfProfileIn( $fname );
453 /* set up the default links for the personal toolbar */
454 $personal_urls = array();
455 if ($this->loggedin
) {
456 $personal_urls['userpage'] = array(
457 'text' => $this->username
,
458 'href' => &$this->userpageUrlDetails
['href'],
459 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
460 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
462 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
463 $personal_urls['mytalk'] = array(
464 'text' => wfMsg('mytalk'),
465 'href' => &$usertalkUrlDetails['href'],
466 'class' => $usertalkUrlDetails['exists']?
false:'new',
467 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
469 $href = $this->makeSpecialUrl('Preferences');
470 $personal_urls['preferences'] = array(
471 'text' => wfMsg('preferences'),
472 'href' => $this->makeSpecialUrl('Preferences'),
473 'active' => ( $href == $pageurl )
475 $href = $this->makeSpecialUrl('Watchlist');
476 $personal_urls['watchlist'] = array(
477 'text' => wfMsg('watchlist'),
479 'active' => ( $href == $pageurl )
481 $href = $this->makeSpecialUrl("Contributions/$this->username");
482 $personal_urls['mycontris'] = array(
483 'text' => wfMsg('mycontris'),
485 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
487 $personal_urls['logout'] = array(
488 'text' => wfMsg('userlogout'),
489 'href' => $this->makeSpecialUrl( 'Userlogout',
490 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
494 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
495 $href = &$this->userpageUrlDetails
['href'];
496 $personal_urls['anonuserpage'] = array(
497 'text' => $this->username
,
499 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
500 'active' => ( $pageurl == $href )
502 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
503 $href = &$usertalkUrlDetails['href'];
504 $personal_urls['anontalk'] = array(
505 'text' => wfMsg('anontalk'),
507 'class' => $usertalkUrlDetails['exists']?
false:'new',
508 'active' => ( $pageurl == $href )
510 $personal_urls['anonlogin'] = array(
511 'text' => wfMsg('userlogin'),
512 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
513 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
517 $personal_urls['login'] = array(
518 'text' => wfMsg('userlogin'),
519 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
520 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
524 wfProfileOut( $fname );
525 return $personal_urls;
529 * Returns true if the IP should be shown in the header
531 function showIPinHeader() {
532 global $wgShowIPinHeader;
533 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
536 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
539 $classes[] = 'selected';
541 if( $checkEdit && $title->getArticleId() == 0 ) {
543 $query = 'action=edit';
546 $text = wfMsg( $message );
547 if ( $text == "<$message>" ) {
548 $text = html_entity_decode($text);
552 'class' => implode( ' ', $classes ),
554 'href' => $title->getLocalUrl( $query ) );
557 function makeTalkUrlDetails( $name, $urlaction='' ) {
558 $title = Title
::newFromText( $name );
559 $title = $title->getTalkPage();
560 $this->checkTitle($title, $name);
562 'href' => $title->getLocalURL( $urlaction ),
563 'exists' => $title->getArticleID() != 0?
true:false
567 function makeArticleUrlDetails( $name, $urlaction='' ) {
568 $title = Title
::newFromText( $name );
569 $title= $title->getSubjectPage();
570 $this->checkTitle($title, $name);
572 'href' => $title->getLocalURL( $urlaction ),
573 'exists' => $title->getArticleID() != 0?
true:false
578 * an array of edit links by default used for the tabs
582 function buildContentActionUrls () {
583 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
584 $fname = 'SkinTemplate::buildContentActionUrls';
585 wfProfileIn( $fname );
587 global $wgUser, $wgRequest;
588 $action = $wgRequest->getText( 'action' );
589 $section = $wgRequest->getText( 'section' );
590 $content_actions = array();
592 $prevent_active_tabs = false ;
593 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
595 if( $this->iscontent
) {
596 $subjpage = $this->mTitle
->getSubjectPage();
597 $talkpage = $this->mTitle
->getTalkPage();
599 $nskey = $this->getNameSpaceKey();
600 $content_actions[$nskey] = $this->tabAction(
603 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
606 $content_actions['talk'] = $this->tabAction(
609 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
613 wfProfileIn( "$fname-edit" );
614 if ( $this->mTitle
->userCanEdit() ) {
615 $istalk = $this->mTitle
->isTalkPage();
616 $istalkclass = $istalk?
' istalk':'';
617 $content_actions['edit'] = array(
618 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
619 'text' => wfMsg('edit'),
620 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
624 $content_actions['addsection'] = array(
625 'class' => $section == 'new'?
'selected':false,
626 'text' => wfMsg('addsection'),
627 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
631 $content_actions['viewsource'] = array(
632 'class' => ($action == 'edit') ?
'selected' : false,
633 'text' => wfMsg('viewsource'),
634 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
637 wfProfileOut( "$fname-edit" );
639 wfProfileIn( "$fname-live" );
640 if ( $this->mTitle
->getArticleId() ) {
642 $content_actions['history'] = array(
643 'class' => ($action == 'history') ?
'selected' : false,
644 'text' => wfMsg('history_short'),
645 'href' => $this->mTitle
->getLocalUrl( 'action=history')
648 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
649 if(!$this->mTitle
->isProtected()){
650 $content_actions['protect'] = array(
651 'class' => ($action == 'protect') ?
'selected' : false,
652 'text' => wfMsg('protect'),
653 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
657 $content_actions['unprotect'] = array(
658 'class' => ($action == 'unprotect') ?
'selected' : false,
659 'text' => wfMsg('unprotect'),
660 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
664 if($wgUser->isAllowed('delete')){
665 $content_actions['delete'] = array(
666 'class' => ($action == 'delete') ?
'selected' : false,
667 'text' => wfMsg('delete'),
668 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
671 if ( $this->mTitle
->userCanMove()) {
672 $content_actions['move'] = array(
673 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
674 'text' => wfMsg('move'),
675 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
679 //article doesn't exist or is deleted
680 if($wgUser->isAllowed('delete')){
681 if( $n = $this->mTitle
->isDeleted() ) {
682 $content_actions['undelete'] = array(
684 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
685 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
690 wfProfileOut( "$fname-live" );
692 if( $this->loggedin
) {
693 if( !$this->mTitle
->userIsWatching()) {
694 $content_actions['watch'] = array(
695 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
696 'text' => wfMsg('watch'),
697 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
700 $content_actions['unwatch'] = array(
701 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
702 'text' => wfMsg('unwatch'),
703 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
708 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
710 if( $this->loggedin ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
711 # Validate tab. TODO: add validation to logged-in user rights
712 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
713 if ( $this->mRevisionId
) $oid = intval( $this->mRevisionId
) ; # Use the oldid
715 {# Trying to get the current article revision through this weird stunt
716 $tid = $this->mTitle
->getArticleID();
717 $tns = $this->mTitle
->getNamespace();
718 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
719 $res = wfQuery( $sql, DB_READ
);
720 if( $s = wfFetchObject( $res ) )
721 $oid = $s->page_latest
;
722 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
725 $oid = "&revision={$oid}" ;
726 $content_actions['validate'] = array(
727 'class' => ($action == 'validate') ?
'selected' : false,
728 'text' => wfMsg('val_tab'),
729 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
735 /* show special page tab */
737 $content_actions['article'] = array(
738 'class' => 'selected',
739 'text' => wfMsg('specialpage'),
740 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
743 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
746 /* show links to different language variants */
747 global $wgDisableLangConversion;
748 $variants = $wgContLang->getVariants();
749 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
750 $preferred = $wgContLang->getPreferredVariant();
753 $actstr = 'action=' . $action . '&';
755 foreach( $variants as $code ) {
756 $varname = $wgContLang->getVariantname( $code );
757 if( $varname == 'disable' )
759 $selected = ( $code == $preferred )?
'selected' : false;
760 $content_actions['varlang-' . $vcount] = array(
761 'class' => $selected,
763 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
769 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
771 wfProfileOut( $fname );
772 return $content_actions;
778 * build array of common navigation links
782 function buildNavUrls () {
783 global $wgUseTrackbacks, $wgTitle, $wgArticle;
785 $fname = 'SkinTemplate::buildNavUrls';
786 wfProfileIn( $fname );
788 global $wgUser, $wgRequest;
789 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
791 $action = $wgRequest->getText( 'action' );
792 $oldid = $wgRequest->getVal( 'oldid' );
793 $diff = $wgRequest->getVal( 'diff' );
796 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
797 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
798 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
799 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
800 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
801 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
802 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
803 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
804 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
805 if( $wgEnableUploads ) {
806 if ($wgUploadNavigationUrl) {
807 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
809 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
812 if ($wgUploadNavigationUrl)
813 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
815 $nav_urls['upload'] = false;
817 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
820 // A print stylesheet is attached to all pages, but nobody ever
821 // figures that out. :) Add a link...
822 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
823 $revid = $wgArticle->getRevIdFetched();
824 if ( !( $revid == 0 ) )
825 $nav_urls['print'] = array(
826 'text' => wfMsg( 'printableversion' ),
827 'href' => $wgRequest->appendQuery( 'printable=yes' )
830 // Also add a "permalink" while we're at it
832 $nav_urls['permalink'] = array(
833 'text' => wfMsg( 'permalink' ),
837 if ( !( $revid == 0 ) )
838 $nav_urls['permalink'] = array(
839 'text' => wfMsg( 'permalink' ),
840 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
844 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
847 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
848 $nav_urls['whatlinkshere'] = array(
849 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
851 if( $this->mTitle
->getArticleId() ) {
852 $nav_urls['recentchangeslinked'] = array(
853 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
856 if ($wgUseTrackbacks)
857 $nav_urls['trackbacklink'] = array(
858 'href' => $wgTitle->trackbackURL()
862 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
863 $id = User
::idFromName($this->mTitle
->getText());
864 $ip = User
::isIP($this->mTitle
->getText());
870 if($id ||
$ip) { # both anons and non-anons have contri list
871 $nav_urls['contributions'] = array(
872 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
874 if ( $wgUser->isAllowed( 'protect' ) )
875 $nav_urls['blockip'] = array(
876 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
879 $nav_urls['contributions'] = false;
881 $nav_urls['emailuser'] = false;
882 if( $this->showEmailUser( $id ) ) {
883 $nav_urls['emailuser'] = array(
884 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
887 wfProfileOut( $fname );
892 * Generate strings used for xml 'id' names
896 function getNameSpaceKey () {
897 switch ($this->mTitle
->getNamespace()) {
905 return 'nstab-media';
907 return 'nstab-special';
909 case NS_PROJECT_TALK
:
913 return 'nstab-image';
915 case NS_MEDIAWIKI_TALK
:
916 return 'nstab-mediawiki';
918 case NS_TEMPLATE_TALK
:
919 return 'nstab-template';
924 case NS_CATEGORY_TALK
:
925 return 'nstab-category';
927 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
934 function setupUserCss() {
935 $fname = 'SkinTemplate::setupUserCss';
936 wfProfileIn( $fname );
938 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
942 $siteargs = '&maxage=' . $wgSquidMaxage;
944 # Add user-specific code if this is a user and we allow that kind of thing
946 if ( $wgAllowUserCss && $this->loggedin
) {
947 $action = $wgRequest->getText('action');
949 # if we're previewing the CSS page, use it
950 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
951 $siteargs = "&smaxage=0&maxage=0";
952 $usercss = $wgRequest->getText('wpTextbox1');
954 $usercss = '@import "' .
955 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
956 'action=raw&ctype=text/css') . '";' ."\n";
959 $siteargs .= '&ts=' . $wgUser->mTouched
;
962 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
964 # If we use the site's dynamic CSS, throw that in, too
965 if ( $wgUseSiteCss ) {
966 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
967 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
968 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
969 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
972 # If we use any dynamic CSS, make a little CDATA block out of it.
974 if ( !empty($sitecss) ||
!empty($usercss) ) {
975 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
977 wfProfileOut( $fname );
983 function setupUserJs() {
984 $fname = 'SkinTemplate::setupUserJs';
985 wfProfileIn( $fname );
987 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
988 $action = $wgRequest->getText('action');
990 if( $wgAllowUserJs && $this->loggedin
) {
991 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
992 # XXX: additional security check/prompt?
993 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
995 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
998 wfProfileOut( $fname );
1002 * Code for extensions to hook into to provide per-page CSS, see
1003 * extensions/PageCSS/PageCSS.php for an implementation of this.
1007 function setupPageCss() {
1008 $fname = 'SkinTemplate::setupPageCss';
1009 wfProfileIn( $fname );
1011 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle
->isProtected() ) );
1012 wfProfileOut( $fname );
1017 * returns css with user-specific options
1021 function getUserStylesheet() {
1022 $fname = 'SkinTemplate::getUserStylesheet';
1023 wfProfileIn( $fname );
1026 $s = "/* generated user stylesheet */\n";
1027 $s .= $this->reallyDoGetUserStyles();
1028 wfProfileOut( $fname );
1035 function getUserJs() {
1036 $fname = 'SkinTemplate::getUserJs';
1037 wfProfileIn( $fname );
1039 global $wgStylePath;
1040 $s = '/* generated javascript */';
1041 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1042 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1044 // avoid inclusion of non defined user JavaScript (with custom skins only)
1045 // by checking for default message content
1046 $msgKey = ucfirst($this->skinname
).'.js';
1047 $userJS = wfMsg($msgKey);
1048 if ('<'.$msgKey.'>' != $userJS) {
1052 wfProfileOut( $fname );
1058 * Generic wrapper for template functions, with interface
1059 * compatible with what we use of PHPTAL 0.7.
1060 * @package MediaWiki
1063 class QuickTemplate
{
1067 function QuickTemplate() {
1068 $this->data
= array();
1069 $this->translator
= new MediaWiki_I18N();
1075 function set( $name, $value ) {
1076 $this->data
[$name] = $value;
1082 function setRef($name, &$value) {
1083 $this->data
[$name] =& $value;
1089 function setTranslator( &$t ) {
1090 $this->translator
= &$t;
1096 function execute() {
1097 echo "Override this function.";
1104 function text( $str ) {
1105 echo htmlspecialchars( $this->data
[$str] );
1111 function html( $str ) {
1112 echo $this->data
[$str];
1118 function msg( $str ) {
1119 echo htmlspecialchars( $this->translator
->translate( $str ) );
1125 function msgHtml( $str ) {
1126 echo $this->translator
->translate( $str );
1130 * An ugly, ugly hack.
1133 function msgWiki( $str ) {
1134 global $wgParser, $wgTitle, $wgOut;
1136 $text = $this->translator
->translate( $str );
1137 $parserOutput = $wgParser->parse( $text, $wgTitle,
1138 $wgOut->mParserOptions
, true );
1139 echo $parserOutput->getText();
1145 function haveData( $str ) {
1146 return $this->data
[$str];
1152 function haveMsg( $str ) {
1153 $msg = $this->translator
->translate( $str );
1154 return ($msg != '-') && ($msg != ''); # ????
1158 } // end of if( defined( 'MEDIAWIKI' ) )