85de7638ef0c7fe8fdff5505bb67afea92204515
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
18 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
39 if( defined( 'MEDIAWIKI' ) ) {
41 require_once 'GlobalFunctions.php';
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
50 class MediaWiki_I18N
{
51 var $_context = array();
53 function set($varName, $value) {
54 $this->_context
[$varName] = $value;
57 function translate($value) {
58 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
69 $varValue = $this->_context
[$var];
71 $value = str_replace($src, $varValue, $value);
73 wfProfileOut( $fname );
82 class SkinTemplate
extends Skin
{
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
115 * @param OutputPage $out
117 function initPage( &$out ) {
118 parent
::initPage( $out );
119 $this->skinname
= 'monobook';
120 $this->stylename
= 'monobook';
121 $this->template
= 'QuickTemplate';
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
135 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
140 * initialize various variables and generate the template
142 * @param OutputPage $out
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152 global $wgUseTrackbacks;
154 $fname = 'SkinTemplate::outputPage';
155 wfProfileIn( $fname );
157 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
159 wfProfileIn( "$fname-init" );
160 $this->initPage( $out );
162 $this->mTitle
=& $wgTitle;
163 $this->mUser
=& $wgUser;
165 $tpl = $this->setupTemplate( $this->template
, 'skins' );
167 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
168 $tpl->setTranslator(new MediaWiki_I18N());
170 wfProfileOut( "$fname-init" );
172 wfProfileIn( "$fname-stuff" );
173 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
174 $this->thisurl
= $this->mTitle
->getPrefixedURL();
175 $this->loggedin
= $wgUser->isLoggedIn();
176 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
177 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
178 $this->username
= $wgUser->getName();
179 $userPage = $wgUser->getUserPage();
180 $this->userpage
= $userPage->getPrefixedText();
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 wfMsg('newmessageslink')
287 $wgOut->setSquidMaxage(0);
292 wfProfileOut( "$fname-stuff2" );
294 wfProfileIn( "$fname-stuff3" );
295 $tpl->setRef( 'newtalk', $ntl );
296 $tpl->setRef( 'skin', $this);
297 $tpl->set( 'logo', $this->logoText() );
298 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
299 if ( !$wgDisableCounters ) {
300 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
302 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
304 $tpl->set('viewcount', false);
307 $tpl->set('viewcount', false);
310 if ($wgPageShowWatchingUsers) {
311 $dbr =& wfGetDB( DB_SLAVE
);
312 extract( $dbr->tableNames( 'watchlist' ) );
313 $sql = "SELECT COUNT(*) AS n FROM $watchlist
314 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
315 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
316 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
317 $x = $dbr->fetchObject( $res );
318 $numberofwatchingusers = $x->n
;
319 if ($numberofwatchingusers > 0) {
320 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
322 $tpl->set('numberofwatchingusers', false);
325 $tpl->set('numberofwatchingusers', false);
328 $tpl->set('copyright',$this->getCopyright());
330 $this->credits
= false;
332 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
333 require_once("Credits.php");
334 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
336 $tpl->set('lastmod', $this->lastModified());
339 $tpl->setRef( 'credits', $this->credits
);
341 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
342 $tpl->set('copyright', $this->getCopyright());
343 $tpl->set('viewcount', false);
344 $tpl->set('lastmod', false);
345 $tpl->set('credits', false);
346 $tpl->set('numberofwatchingusers', false);
348 $tpl->set('copyright', false);
349 $tpl->set('viewcount', false);
350 $tpl->set('lastmod', false);
351 $tpl->set('credits', false);
352 $tpl->set('numberofwatchingusers', false);
354 wfProfileOut( "$fname-stuff3" );
356 wfProfileIn( "$fname-stuff4" );
357 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
358 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
359 $tpl->set( 'disclaimer', $this->disclaimerLink() );
360 $tpl->set( 'about', $this->aboutLink() );
362 $tpl->setRef( 'debug', $out->mDebugtext
);
363 $tpl->set( 'reporttime', $out->reportTime() );
364 $tpl->set( 'sitenotice', wfGetSiteNotice() );
366 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
367 $out->mBodytext
.= $printfooter ;
368 $tpl->setRef( 'bodytext', $out->mBodytext
);
371 $language_urls = array();
373 if ( !$wgHideInterlanguageLinks ) {
374 foreach( $wgOut->getLanguageLinks() as $l ) {
375 $tmp = explode( ':', $l, 2 );
376 $class = 'interwiki-' . $tmp[0];
378 $nt = Title
::newFromText( $l );
379 $language_urls[] = array(
380 'href' => $nt->getFullURL(),
381 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
386 if(count($language_urls)) {
387 $tpl->setRef( 'language_urls', $language_urls);
389 $tpl->set('language_urls', false);
391 wfProfileOut( "$fname-stuff4" );
394 $tpl->set('personal_urls', $this->buildPersonalUrls());
395 $content_actions = $this->buildContentActionUrls();
396 $tpl->setRef('content_actions', $content_actions);
398 // XXX: attach this from javascript, same with section editing
399 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
401 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
403 $tpl->set('body_ondblclick', false);
405 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
406 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
408 $tpl->set( 'body_onload', false );
410 $tpl->set( 'sidebar', $this->buildSidebar() );
411 $tpl->set( 'nav_urls', $this->buildNavUrls() );
414 wfProfileIn( "$fname-execute" );
415 $res = $tpl->execute();
416 wfProfileOut( "$fname-execute" );
418 // result may be an error
419 $this->printOrError( $res );
420 wfProfileOut( $fname );
424 * Output the string, or print error message if it's
425 * an error object of the appropriate type.
426 * For the base class, assume strings all around.
431 function printOrError( &$str ) {
436 * build array of urls for personal toolbar
440 function buildPersonalUrls() {
441 global $wgTitle, $wgShowIPinHeader, $wgContLang;
443 $fname = 'SkinTemplate::buildPersonalUrls';
444 $pageurl = $wgTitle->getLocalURL();
445 wfProfileIn( $fname );
447 /* set up the default links for the personal toolbar */
448 $personal_urls = array();
449 if ($this->loggedin
) {
450 $personal_urls['userpage'] = array(
451 'text' => $this->username
,
452 'href' => &$this->userpageUrlDetails
['href'],
453 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
454 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
456 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
457 $personal_urls['mytalk'] = array(
458 'text' => wfMsg('mytalk'),
459 'href' => &$usertalkUrlDetails['href'],
460 'class' => $usertalkUrlDetails['exists']?
false:'new',
461 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
463 $href = $this->makeSpecialUrl('Preferences');
464 $personal_urls['preferences'] = array(
465 'text' => wfMsg('preferences'),
466 'href' => $this->makeSpecialUrl('Preferences'),
467 'active' => ( $href == $pageurl )
469 $href = $this->makeSpecialUrl('Watchlist');
470 $personal_urls['watchlist'] = array(
471 'text' => wfMsg('watchlist'),
473 'active' => ( $href == $pageurl )
475 $href = $this->makeSpecialUrl("Contributions/$this->username");
476 $personal_urls['mycontris'] = array(
477 'text' => wfMsg('mycontris'),
479 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
481 $personal_urls['logout'] = array(
482 'text' => wfMsg('userlogout'),
483 'href' => $this->makeSpecialUrl( 'Userlogout',
484 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
488 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
489 $href = &$this->userpageUrlDetails
['href'];
490 $personal_urls['anonuserpage'] = array(
491 'text' => $this->username
,
493 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
494 'active' => ( $pageurl == $href )
496 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
497 $href = &$usertalkUrlDetails['href'];
498 $personal_urls['anontalk'] = array(
499 'text' => wfMsg('anontalk'),
501 'class' => $usertalkUrlDetails['exists']?
false:'new',
502 'active' => ( $pageurl == $href )
504 $personal_urls['anonlogin'] = array(
505 'text' => wfMsg('userlogin'),
506 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
507 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
511 $personal_urls['login'] = array(
512 'text' => wfMsg('userlogin'),
513 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
514 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
518 wfProfileOut( $fname );
519 return $personal_urls;
523 * Returns true if the IP should be shown in the header
525 function showIPinHeader() {
526 global $wgShowIPinHeader;
527 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
530 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
533 $classes[] = 'selected';
535 if( $checkEdit && $title->getArticleId() == 0 ) {
537 $query = 'action=edit';
540 $text = wfMsg( $message );
541 if ( $text == "<$message>" ) {
542 $text = wfMsg( 'nstab-main' );
546 'class' => implode( ' ', $classes ),
548 'href' => $title->getLocalUrl( $query ) );
551 function makeTalkUrlDetails( $name, $urlaction='' ) {
552 $title = Title
::newFromText( $name );
553 $title = $title->getTalkPage();
554 $this->checkTitle($title, $name);
556 'href' => $title->getLocalURL( $urlaction ),
557 'exists' => $title->getArticleID() != 0?
true:false
561 function makeArticleUrlDetails( $name, $urlaction='' ) {
562 $title = Title
::newFromText( $name );
563 $title= $title->getSubjectPage();
564 $this->checkTitle($title, $name);
566 'href' => $title->getLocalURL( $urlaction ),
567 'exists' => $title->getArticleID() != 0?
true:false
572 * an array of edit links by default used for the tabs
576 function buildContentActionUrls () {
577 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
578 $fname = 'SkinTemplate::buildContentActionUrls';
579 wfProfileIn( $fname );
581 global $wgUser, $wgRequest;
582 $action = $wgRequest->getText( 'action' );
583 $section = $wgRequest->getText( 'section' );
584 $oldid = $wgRequest->getVal( 'oldid' );
585 $diff = $wgRequest->getVal( 'diff' );
586 $content_actions = array();
588 if( $this->iscontent
) {
589 $subjpage = $this->mTitle
->getSubjectPage();
590 $talkpage = $this->mTitle
->getTalkPage();
592 $nskey = $this->getNameSpaceKey();
593 $content_actions[$nskey] = $this->tabAction(
596 !$this->mTitle
->isTalkPage(),
599 $content_actions['talk'] = $this->tabAction(
602 $this->mTitle
->isTalkPage(),
606 wfProfileIn( "$fname-edit" );
607 if ( $this->mTitle
->userCanEdit() ) {
608 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : false;
609 $istalk = $this->mTitle
->isTalkPage();
610 $istalkclass = $istalk?
' istalk':'';
611 $content_actions['edit'] = array(
612 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
613 'text' => wfMsg('edit'),
614 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
618 $content_actions['addsection'] = array(
619 'class' => $section == 'new'?
'selected':false,
620 'text' => wfMsg('addsection'),
621 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
625 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : '';
626 $content_actions['viewsource'] = array(
627 'class' => ($action == 'edit') ?
'selected' : false,
628 'text' => wfMsg('viewsource'),
629 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
632 wfProfileOut( "$fname-edit" );
634 wfProfileIn( "$fname-live" );
635 if ( $this->mTitle
->getArticleId() ) {
637 $content_actions['history'] = array(
638 'class' => ($action == 'history') ?
'selected' : false,
639 'text' => wfMsg('history_short'),
640 'href' => $this->mTitle
->getLocalUrl( 'action=history')
643 if($wgUser->isAllowed('protect')){
644 if(!$this->mTitle
->isProtected()){
645 $content_actions['protect'] = array(
646 'class' => ($action == 'protect') ?
'selected' : false,
647 'text' => wfMsg('protect'),
648 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
652 $content_actions['unprotect'] = array(
653 'class' => ($action == 'unprotect') ?
'selected' : false,
654 'text' => wfMsg('unprotect'),
655 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
659 if($wgUser->isAllowed('delete')){
660 $content_actions['delete'] = array(
661 'class' => ($action == 'delete') ?
'selected' : false,
662 'text' => wfMsg('delete'),
663 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
666 if ( $this->mTitle
->userCanMove()) {
667 $content_actions['move'] = array(
668 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
669 'text' => wfMsg('move'),
670 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
674 //article doesn't exist or is deleted
675 if($wgUser->isAllowed('delete')){
676 if( $n = $this->mTitle
->isDeleted() ) {
677 $content_actions['undelete'] = array(
679 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
680 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
685 wfProfileOut( "$fname-live" );
687 if( $this->loggedin
) {
688 if( !$this->mTitle
->userIsWatching()) {
689 $content_actions['watch'] = array(
690 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
691 'text' => wfMsg('watch'),
692 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
695 $content_actions['unwatch'] = array(
696 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
697 'text' => wfMsg('unwatch'),
698 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
703 if( $this->loggedin ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
704 # Validate tab. TODO: add validation to logged-in user rights
705 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
706 if ( $oldid ) $oid = intval( $oldid ) ; # Use the oldid
708 {# Trying to get the current article revision through this weird stunt
709 $tid = $this->mTitle
->getArticleID();
710 $tns = $this->mTitle
->getNamespace();
711 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
712 $res = wfQuery( $sql, DB_READ
);
713 if( $s = wfFetchObject( $res ) )
714 $oid = $s->page_latest
;
715 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
718 $oid = "&revision={$oid}" ;
719 $content_actions['validate'] = array(
720 'class' => ($action == 'validate') ?
'selected' : false,
721 'text' => wfMsg('val_tab'),
722 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
728 /* show special page tab */
730 $content_actions['article'] = array(
731 'class' => 'selected',
732 'text' => wfMsg('specialpage'),
733 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
737 /* show links to different language variants */
738 global $wgDisableLangConversion;
739 $variants = $wgContLang->getVariants();
740 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
741 $preferred = $wgContLang->getPreferredVariant();
744 $actstr = 'action=' . $action . '&';
746 foreach( $variants as $code ) {
747 $varname = $wgContLang->getVariantname( $code );
748 if( $varname == 'disable' )
750 $selected = ( $code == $preferred )?
'selected' : false;
751 $content_actions['varlang-' . $vcount] = array(
752 'class' => $selected,
754 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
760 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
762 wfProfileOut( $fname );
763 return $content_actions;
769 * build array of common navigation links
773 function buildNavUrls () {
774 global $wgUseTrackbacks, $wgTitle, $wgArticle;
776 $fname = 'SkinTemplate::buildNavUrls';
777 wfProfileIn( $fname );
779 global $wgUser, $wgRequest;
780 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
782 $action = $wgRequest->getText( 'action' );
783 $oldid = $wgRequest->getVal( 'oldid' );
784 $diff = $wgRequest->getVal( 'diff' );
787 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
788 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
789 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
790 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
791 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
792 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
793 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
794 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
795 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
796 if( $wgEnableUploads ) {
797 if ($wgUploadNavigationUrl) {
798 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
800 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
803 if ($wgUploadNavigationUrl)
804 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
806 $nav_urls['upload'] = false;
808 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
811 // A print stylesheet is attached to all pages, but nobody ever
812 // figures that out. :) Add a link...
813 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
814 $revid = $wgArticle->getRevIdFetched();
815 if ( !( $revid == 0 ) )
816 $nav_urls['print'] = array(
817 'text' => wfMsg( 'printableversion' ),
818 'href' => $wgRequest->appendQuery( 'printable=yes' )
821 // Also add a "permalink" while we're at it
823 $nav_urls['permalink'] = array(
824 'text' => wfMsg( 'permalink' ),
828 if ( !( $revid == 0 ) )
829 $nav_urls['permalink'] = array(
830 'text' => wfMsg( 'permalink' ),
831 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
836 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
837 $nav_urls['whatlinkshere'] = array(
838 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
840 $nav_urls['recentchangeslinked'] = array(
841 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
843 if ($wgUseTrackbacks)
844 $nav_urls['trackbacklink'] = array(
845 'href' => $wgTitle->trackbackURL()
849 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
850 $id = User
::idFromName($this->mTitle
->getText());
851 $ip = User
::isIP($this->mTitle
->getText());
857 if($id ||
$ip) { # both anons and non-anons have contri list
858 $nav_urls['contributions'] = array(
859 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
861 if ( $wgUser->isAllowed( 'protect' ) )
862 $nav_urls['blockip'] = array(
863 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
866 $nav_urls['contributions'] = false;
868 $nav_urls['emailuser'] = false;
869 if( $this->showEmailUser( $id ) ) {
870 $nav_urls['emailuser'] = array(
871 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
874 wfProfileOut( $fname );
879 * Generate strings used for xml 'id' names
883 function getNameSpaceKey () {
884 switch ($this->mTitle
->getNamespace()) {
892 return 'nstab-media';
894 return 'nstab-special';
896 case NS_PROJECT_TALK
:
900 return 'nstab-image';
902 case NS_MEDIAWIKI_TALK
:
903 return 'nstab-mediawiki';
905 case NS_TEMPLATE_TALK
:
906 return 'nstab-template';
911 case NS_CATEGORY_TALK
:
912 return 'nstab-category';
914 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
921 function setupUserCss() {
922 $fname = 'SkinTemplate::setupUserCss';
923 wfProfileIn( $fname );
925 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
929 $siteargs = '&maxage=' . $wgSquidMaxage;
931 # Add user-specific code if this is a user and we allow that kind of thing
933 if ( $wgAllowUserCss && $this->loggedin
) {
934 $action = $wgRequest->getText('action');
936 # if we're previewing the CSS page, use it
937 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
938 $siteargs = "&smaxage=0&maxage=0";
939 $usercss = $wgRequest->getText('wpTextbox1');
941 $usercss = '@import "' .
942 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
943 'action=raw&ctype=text/css') . '";' ."\n";
946 $siteargs .= '&ts=' . $wgUser->mTouched
;
949 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
951 # If we use the site's dynamic CSS, throw that in, too
952 if ( $wgUseSiteCss ) {
953 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
954 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
955 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
956 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
959 # If we use any dynamic CSS, make a little CDATA block out of it.
961 if ( !empty($sitecss) ||
!empty($usercss) ) {
962 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
964 wfProfileOut( $fname );
970 function setupUserJs() {
971 $fname = 'SkinTemplate::setupUserJs';
972 wfProfileIn( $fname );
974 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
975 $action = $wgRequest->getText('action');
977 if( $wgAllowUserJs && $this->loggedin
) {
978 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
979 # XXX: additional security check/prompt?
980 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
982 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
985 wfProfileOut( $fname );
989 * Code for extensions to hook into to provide per-page CSS, see
990 * extensions/PageCSS/PageCSS.php for an implementation of this.
994 function setupPageCss() {
995 $fname = 'SkinTemplate::setupPageCss';
996 wfProfileIn( $fname );
998 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle
->isProtected() ) );
999 wfProfileOut( $fname );
1004 * returns css with user-specific options
1008 function getUserStylesheet() {
1009 $fname = 'SkinTemplate::getUserStylesheet';
1010 wfProfileIn( $fname );
1013 $s = "/* generated user stylesheet */\n";
1014 $s .= $this->reallyDoGetUserStyles();
1015 wfProfileOut( $fname );
1022 function getUserJs() {
1023 $fname = 'SkinTemplate::getUserJs';
1024 wfProfileIn( $fname );
1026 global $wgStylePath;
1027 $s = '/* generated javascript */';
1028 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1029 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1031 // avoid inclusion of non defined user JavaScript (with custom skins only)
1032 // by checking for default message content
1033 $msgKey = ucfirst($this->skinname
).'.js';
1034 $userJS = wfMsg($msgKey);
1035 if ('<'.$msgKey.'>' != $userJS) {
1039 wfProfileOut( $fname );
1045 * Generic wrapper for template functions, with interface
1046 * compatible with what we use of PHPTAL 0.7.
1047 * @package MediaWiki
1050 class QuickTemplate
{
1054 function QuickTemplate() {
1055 $this->data
= array();
1056 $this->translator
= new MediaWiki_I18N();
1062 function set( $name, $value ) {
1063 $this->data
[$name] = $value;
1069 function setRef($name, &$value) {
1070 $this->data
[$name] =& $value;
1076 function setTranslator( &$t ) {
1077 $this->translator
= &$t;
1083 function execute() {
1084 echo "Override this function.";
1091 function text( $str ) {
1092 echo htmlspecialchars( $this->data
[$str] );
1098 function html( $str ) {
1099 echo $this->data
[$str];
1105 function msg( $str ) {
1106 echo htmlspecialchars( $this->translator
->translate( $str ) );
1112 function msgHtml( $str ) {
1113 echo $this->translator
->translate( $str );
1117 * An ugly, ugly hack.
1120 function msgWiki( $str ) {
1121 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1123 $text = $this->translator
->translate( $str );
1124 $parserOutput = $wgParser->parse( $text, $wgTitle,
1125 $wgOut->mParserOptions
, true );
1126 echo $parserOutput->getText();
1132 function haveData( $str ) {
1133 return $this->data
[$str];
1139 function haveMsg( $str ) {
1140 $msg = $this->translator
->translate( $str );
1141 return ($msg != '-') && ($msg != ''); # ????
1145 } // end of if( defined( 'MEDIAWIKI' ) )