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 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( 'privacy', $this->privacyLink() );
361 $tpl->set( 'about', $this->aboutLink() );
363 $tpl->setRef( 'debug', $out->mDebugtext
);
364 $tpl->set( 'reporttime', $out->reportTime() );
365 $tpl->set( 'sitenotice', wfGetSiteNotice() );
367 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
368 $out->mBodytext
.= $printfooter ;
369 $tpl->setRef( 'bodytext', $out->mBodytext
);
372 $language_urls = array();
374 if ( !$wgHideInterlanguageLinks ) {
375 foreach( $wgOut->getLanguageLinks() as $l ) {
376 $tmp = explode( ':', $l, 2 );
377 $class = 'interwiki-' . $tmp[0];
379 $nt = Title
::newFromText( $l );
380 $language_urls[] = array(
381 'href' => $nt->getFullURL(),
382 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
387 if(count($language_urls)) {
388 $tpl->setRef( 'language_urls', $language_urls);
390 $tpl->set('language_urls', false);
392 wfProfileOut( "$fname-stuff4" );
395 $tpl->set('personal_urls', $this->buildPersonalUrls());
396 $content_actions = $this->buildContentActionUrls();
397 $tpl->setRef('content_actions', $content_actions);
399 // XXX: attach this from javascript, same with section editing
400 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
402 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
404 $tpl->set('body_ondblclick', false);
406 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
407 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
409 $tpl->set( 'body_onload', false );
411 $tpl->set( 'sidebar', $this->buildSidebar() );
412 $tpl->set( 'nav_urls', $this->buildNavUrls() );
415 wfProfileIn( "$fname-execute" );
416 $res = $tpl->execute();
417 wfProfileOut( "$fname-execute" );
419 // result may be an error
420 $this->printOrError( $res );
421 wfProfileOut( $fname );
425 * Output the string, or print error message if it's
426 * an error object of the appropriate type.
427 * For the base class, assume strings all around.
432 function printOrError( &$str ) {
437 * build array of urls for personal toolbar
441 function buildPersonalUrls() {
442 global $wgTitle, $wgShowIPinHeader, $wgContLang;
444 $fname = 'SkinTemplate::buildPersonalUrls';
445 $pageurl = $wgTitle->getLocalURL();
446 wfProfileIn( $fname );
448 /* set up the default links for the personal toolbar */
449 $personal_urls = array();
450 if ($this->loggedin
) {
451 $personal_urls['userpage'] = array(
452 'text' => $this->username
,
453 'href' => &$this->userpageUrlDetails
['href'],
454 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
455 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
457 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
458 $personal_urls['mytalk'] = array(
459 'text' => wfMsg('mytalk'),
460 'href' => &$usertalkUrlDetails['href'],
461 'class' => $usertalkUrlDetails['exists']?
false:'new',
462 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
464 $href = $this->makeSpecialUrl('Preferences');
465 $personal_urls['preferences'] = array(
466 'text' => wfMsg('preferences'),
467 'href' => $this->makeSpecialUrl('Preferences'),
468 'active' => ( $href == $pageurl )
470 $href = $this->makeSpecialUrl('Watchlist');
471 $personal_urls['watchlist'] = array(
472 'text' => wfMsg('watchlist'),
474 'active' => ( $href == $pageurl )
476 $href = $this->makeSpecialUrl("Contributions/$this->username");
477 $personal_urls['mycontris'] = array(
478 'text' => wfMsg('mycontris'),
480 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
482 $personal_urls['logout'] = array(
483 'text' => wfMsg('userlogout'),
484 'href' => $this->makeSpecialUrl( 'Userlogout',
485 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
489 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
490 $href = &$this->userpageUrlDetails
['href'];
491 $personal_urls['anonuserpage'] = array(
492 'text' => $this->username
,
494 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
495 'active' => ( $pageurl == $href )
497 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
498 $href = &$usertalkUrlDetails['href'];
499 $personal_urls['anontalk'] = array(
500 'text' => wfMsg('anontalk'),
502 'class' => $usertalkUrlDetails['exists']?
false:'new',
503 'active' => ( $pageurl == $href )
505 $personal_urls['anonlogin'] = array(
506 'text' => wfMsg('userlogin'),
507 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
508 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
512 $personal_urls['login'] = array(
513 'text' => wfMsg('userlogin'),
514 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
515 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
519 wfProfileOut( $fname );
520 return $personal_urls;
524 * Returns true if the IP should be shown in the header
526 function showIPinHeader() {
527 global $wgShowIPinHeader;
528 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
531 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
534 $classes[] = 'selected';
536 if( $checkEdit && $title->getArticleId() == 0 ) {
538 $query = 'action=edit';
541 $text = wfMsg( $message );
542 if ( $text == "<$message>" ) {
543 $text = wfMsg( 'nstab-main' );
547 'class' => implode( ' ', $classes ),
549 'href' => $title->getLocalUrl( $query ) );
552 function makeTalkUrlDetails( $name, $urlaction='' ) {
553 $title = Title
::newFromText( $name );
554 $title = $title->getTalkPage();
555 $this->checkTitle($title, $name);
557 'href' => $title->getLocalURL( $urlaction ),
558 'exists' => $title->getArticleID() != 0?
true:false
562 function makeArticleUrlDetails( $name, $urlaction='' ) {
563 $title = Title
::newFromText( $name );
564 $title= $title->getSubjectPage();
565 $this->checkTitle($title, $name);
567 'href' => $title->getLocalURL( $urlaction ),
568 'exists' => $title->getArticleID() != 0?
true:false
573 * an array of edit links by default used for the tabs
577 function buildContentActionUrls () {
578 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
579 $fname = 'SkinTemplate::buildContentActionUrls';
580 wfProfileIn( $fname );
582 global $wgUser, $wgRequest;
583 $action = $wgRequest->getText( 'action' );
584 $section = $wgRequest->getText( 'section' );
585 $content_actions = array();
587 if( $this->iscontent
) {
588 $subjpage = $this->mTitle
->getSubjectPage();
589 $talkpage = $this->mTitle
->getTalkPage();
591 $nskey = $this->getNameSpaceKey();
592 $content_actions[$nskey] = $this->tabAction(
595 !$this->mTitle
->isTalkPage(),
598 $content_actions['talk'] = $this->tabAction(
601 $this->mTitle
->isTalkPage(),
605 wfProfileIn( "$fname-edit" );
606 if ( $this->mTitle
->userCanEdit() ) {
607 $istalk = $this->mTitle
->isTalkPage();
608 $istalkclass = $istalk?
' istalk':'';
609 $content_actions['edit'] = array(
610 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
611 'text' => wfMsg('edit'),
612 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
616 $content_actions['addsection'] = array(
617 'class' => $section == 'new'?
'selected':false,
618 'text' => wfMsg('addsection'),
619 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
623 $content_actions['viewsource'] = array(
624 'class' => ($action == 'edit') ?
'selected' : false,
625 'text' => wfMsg('viewsource'),
626 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
629 wfProfileOut( "$fname-edit" );
631 wfProfileIn( "$fname-live" );
632 if ( $this->mTitle
->getArticleId() ) {
634 $content_actions['history'] = array(
635 'class' => ($action == 'history') ?
'selected' : false,
636 'text' => wfMsg('history_short'),
637 'href' => $this->mTitle
->getLocalUrl( 'action=history')
640 if($wgUser->isAllowed('protect')){
641 if(!$this->mTitle
->isProtected()){
642 $content_actions['protect'] = array(
643 'class' => ($action == 'protect') ?
'selected' : false,
644 'text' => wfMsg('protect'),
645 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
649 $content_actions['unprotect'] = array(
650 'class' => ($action == 'unprotect') ?
'selected' : false,
651 'text' => wfMsg('unprotect'),
652 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
656 if($wgUser->isAllowed('delete')){
657 $content_actions['delete'] = array(
658 'class' => ($action == 'delete') ?
'selected' : false,
659 'text' => wfMsg('delete'),
660 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
663 if ( $this->mTitle
->userCanMove()) {
664 $content_actions['move'] = array(
665 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
666 'text' => wfMsg('move'),
667 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
671 //article doesn't exist or is deleted
672 if($wgUser->isAllowed('delete')){
673 if( $n = $this->mTitle
->isDeleted() ) {
674 $content_actions['undelete'] = array(
676 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
677 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
682 wfProfileOut( "$fname-live" );
684 if( $this->loggedin
) {
685 if( !$this->mTitle
->userIsWatching()) {
686 $content_actions['watch'] = array(
687 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
688 'text' => wfMsg('watch'),
689 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
692 $content_actions['unwatch'] = array(
693 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
694 'text' => wfMsg('unwatch'),
695 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
700 if( $this->loggedin ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
701 # Validate tab. TODO: add validation to logged-in user rights
702 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
703 if ( $this->mRevisionId
) $oid = intval( $this->mRevisionId
) ; # Use the oldid
705 {# Trying to get the current article revision through this weird stunt
706 $tid = $this->mTitle
->getArticleID();
707 $tns = $this->mTitle
->getNamespace();
708 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
709 $res = wfQuery( $sql, DB_READ
);
710 if( $s = wfFetchObject( $res ) )
711 $oid = $s->page_latest
;
712 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
715 $oid = "&revision={$oid}" ;
716 $content_actions['validate'] = array(
717 'class' => ($action == 'validate') ?
'selected' : false,
718 'text' => wfMsg('val_tab'),
719 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
725 /* show special page tab */
727 $content_actions['article'] = array(
728 'class' => 'selected',
729 'text' => wfMsg('specialpage'),
730 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
734 /* show links to different language variants */
735 global $wgDisableLangConversion;
736 $variants = $wgContLang->getVariants();
737 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
738 $preferred = $wgContLang->getPreferredVariant();
741 $actstr = 'action=' . $action . '&';
743 foreach( $variants as $code ) {
744 $varname = $wgContLang->getVariantname( $code );
745 if( $varname == 'disable' )
747 $selected = ( $code == $preferred )?
'selected' : false;
748 $content_actions['varlang-' . $vcount] = array(
749 'class' => $selected,
751 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
757 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
759 wfProfileOut( $fname );
760 return $content_actions;
766 * build array of common navigation links
770 function buildNavUrls () {
771 global $wgUseTrackbacks, $wgTitle, $wgArticle;
773 $fname = 'SkinTemplate::buildNavUrls';
774 wfProfileIn( $fname );
776 global $wgUser, $wgRequest;
777 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
779 $action = $wgRequest->getText( 'action' );
780 $oldid = $wgRequest->getVal( 'oldid' );
781 $diff = $wgRequest->getVal( 'diff' );
784 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
785 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
786 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
787 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
788 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
789 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
790 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
791 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
792 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
793 if( $wgEnableUploads ) {
794 if ($wgUploadNavigationUrl) {
795 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
797 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
800 if ($wgUploadNavigationUrl)
801 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
803 $nav_urls['upload'] = false;
805 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
808 // A print stylesheet is attached to all pages, but nobody ever
809 // figures that out. :) Add a link...
810 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
811 $revid = $wgArticle->getRevIdFetched();
812 if ( !( $revid == 0 ) )
813 $nav_urls['print'] = array(
814 'text' => wfMsg( 'printableversion' ),
815 'href' => $wgRequest->appendQuery( 'printable=yes' )
818 // Also add a "permalink" while we're at it
820 $nav_urls['permalink'] = array(
821 'text' => wfMsg( 'permalink' ),
825 if ( !( $revid == 0 ) )
826 $nav_urls['permalink'] = array(
827 'text' => wfMsg( 'permalink' ),
828 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
832 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
835 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
836 $nav_urls['whatlinkshere'] = array(
837 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
839 $nav_urls['recentchangeslinked'] = array(
840 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
842 if ($wgUseTrackbacks)
843 $nav_urls['trackbacklink'] = array(
844 'href' => $wgTitle->trackbackURL()
848 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
849 $id = User
::idFromName($this->mTitle
->getText());
850 $ip = User
::isIP($this->mTitle
->getText());
856 if($id ||
$ip) { # both anons and non-anons have contri list
857 $nav_urls['contributions'] = array(
858 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
860 if ( $wgUser->isAllowed( 'protect' ) )
861 $nav_urls['blockip'] = array(
862 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
865 $nav_urls['contributions'] = false;
867 $nav_urls['emailuser'] = false;
868 if( $this->showEmailUser( $id ) ) {
869 $nav_urls['emailuser'] = array(
870 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
873 wfProfileOut( $fname );
878 * Generate strings used for xml 'id' names
882 function getNameSpaceKey () {
883 switch ($this->mTitle
->getNamespace()) {
891 return 'nstab-media';
893 return 'nstab-special';
895 case NS_PROJECT_TALK
:
899 return 'nstab-image';
901 case NS_MEDIAWIKI_TALK
:
902 return 'nstab-mediawiki';
904 case NS_TEMPLATE_TALK
:
905 return 'nstab-template';
910 case NS_CATEGORY_TALK
:
911 return 'nstab-category';
913 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
920 function setupUserCss() {
921 $fname = 'SkinTemplate::setupUserCss';
922 wfProfileIn( $fname );
924 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
928 $siteargs = '&maxage=' . $wgSquidMaxage;
930 # Add user-specific code if this is a user and we allow that kind of thing
932 if ( $wgAllowUserCss && $this->loggedin
) {
933 $action = $wgRequest->getText('action');
935 # if we're previewing the CSS page, use it
936 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
937 $siteargs = "&smaxage=0&maxage=0";
938 $usercss = $wgRequest->getText('wpTextbox1');
940 $usercss = '@import "' .
941 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
942 'action=raw&ctype=text/css') . '";' ."\n";
945 $siteargs .= '&ts=' . $wgUser->mTouched
;
948 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
950 # If we use the site's dynamic CSS, throw that in, too
951 if ( $wgUseSiteCss ) {
952 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
953 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
954 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
955 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
958 # If we use any dynamic CSS, make a little CDATA block out of it.
960 if ( !empty($sitecss) ||
!empty($usercss) ) {
961 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
963 wfProfileOut( $fname );
969 function setupUserJs() {
970 $fname = 'SkinTemplate::setupUserJs';
971 wfProfileIn( $fname );
973 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
974 $action = $wgRequest->getText('action');
976 if( $wgAllowUserJs && $this->loggedin
) {
977 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
978 # XXX: additional security check/prompt?
979 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
981 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
984 wfProfileOut( $fname );
988 * Code for extensions to hook into to provide per-page CSS, see
989 * extensions/PageCSS/PageCSS.php for an implementation of this.
993 function setupPageCss() {
994 $fname = 'SkinTemplate::setupPageCss';
995 wfProfileIn( $fname );
997 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle
->isProtected() ) );
998 wfProfileOut( $fname );
1003 * returns css with user-specific options
1007 function getUserStylesheet() {
1008 $fname = 'SkinTemplate::getUserStylesheet';
1009 wfProfileIn( $fname );
1012 $s = "/* generated user stylesheet */\n";
1013 $s .= $this->reallyDoGetUserStyles();
1014 wfProfileOut( $fname );
1021 function getUserJs() {
1022 $fname = 'SkinTemplate::getUserJs';
1023 wfProfileIn( $fname );
1025 global $wgStylePath;
1026 $s = '/* generated javascript */';
1027 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1028 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1030 // avoid inclusion of non defined user JavaScript (with custom skins only)
1031 // by checking for default message content
1032 $msgKey = ucfirst($this->skinname
).'.js';
1033 $userJS = wfMsg($msgKey);
1034 if ('<'.$msgKey.'>' != $userJS) {
1038 wfProfileOut( $fname );
1044 * Generic wrapper for template functions, with interface
1045 * compatible with what we use of PHPTAL 0.7.
1046 * @package MediaWiki
1049 class QuickTemplate
{
1053 function QuickTemplate() {
1054 $this->data
= array();
1055 $this->translator
= new MediaWiki_I18N();
1061 function set( $name, $value ) {
1062 $this->data
[$name] = $value;
1068 function setRef($name, &$value) {
1069 $this->data
[$name] =& $value;
1075 function setTranslator( &$t ) {
1076 $this->translator
= &$t;
1082 function execute() {
1083 echo "Override this function.";
1090 function text( $str ) {
1091 echo htmlspecialchars( $this->data
[$str] );
1097 function html( $str ) {
1098 echo $this->data
[$str];
1104 function msg( $str ) {
1105 echo htmlspecialchars( $this->translator
->translate( $str ) );
1111 function msgHtml( $str ) {
1112 echo $this->translator
->translate( $str );
1116 * An ugly, ugly hack.
1119 function msgWiki( $str ) {
1120 global $wgParser, $wgTitle, $wgOut;
1122 $text = $this->translator
->translate( $str );
1123 $parserOutput = $wgParser->parse( $text, $wgTitle,
1124 $wgOut->mParserOptions
, true );
1125 echo $parserOutput->getText();
1131 function haveData( $str ) {
1132 return $this->data
[$str];
1138 function haveMsg( $str ) {
1139 $msg = $this->translator
->translate( $str );
1140 return ($msg != '-') && ($msg != ''); # ????
1144 } // end of if( defined( 'MEDIAWIKI' ) )