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();
181 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
183 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt
= $this->mTitle
->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
193 $tpl->setRef( "thispage", $this->thispage
);
194 $subpagestr = $this->subPageSubtitle();
196 'subtitle', !empty($subpagestr)?
197 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
200 $undelete = $this->getUndeleteLink();
202 "undelete", !empty($undelete)?
203 '<span class="subpages">'.$undelete.'</span>':
207 $tpl->set( 'catlinks', $this->getCategories());
208 if( $wgOut->isSyndicated() ) {
210 foreach( $wgFeedClasses as $format => $class ) {
211 $feeds[$format] = array(
213 'href' => $wgRequest->appendQuery( "feed=$format" ),
214 'ttip' => wfMsg('tooltip-'.$format)
217 $tpl->setRef( 'feeds', $feeds );
219 $tpl->set( 'feeds', false );
221 if ($wgUseTrackbacks && $out->isArticleRelated())
222 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
224 $tpl->setRef( 'mimetype', $wgMimeType );
225 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
226 $tpl->setRef( 'charset', $wgOutputEncoding );
227 $tpl->set( 'headlinks', $out->getHeadLinks() );
228 $tpl->set('headscripts', $out->getScript() );
229 $tpl->setRef( 'wgScript', $wgScript );
230 $tpl->setRef( 'skinname', $this->skinname
);
231 $tpl->setRef( 'stylename', $this->stylename
);
232 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
233 $tpl->setRef( 'loggedin', $this->loggedin
);
234 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
235 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
236 /* XXX currently unused, might get useful later
237 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
238 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
239 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
240 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
241 $tpl->set( "helppage", wfMsg('helppage'));
243 $tpl->set( 'searchaction', $this->escapeSearchLink() );
244 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
245 $tpl->setRef( 'stylepath', $wgStylePath );
246 $tpl->setRef( 'logopath', $wgLogo );
247 $tpl->setRef( "lang", $wgContLanguageCode );
248 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
249 $tpl->set( 'rtl', $wgContLang->isRTL() );
250 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
251 $tpl->setRef( 'username', $this->username
);
252 $tpl->setRef( 'userpage', $this->userpage
);
253 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
254 $tpl->set( 'pagecss', $this->setupPageCss() );
255 $tpl->setRef( 'usercss', $this->usercss
);
256 $tpl->setRef( 'userjs', $this->userjs
);
257 $tpl->setRef( 'userjsprev', $this->userjsprev
);
260 if($this->loggedin
) {
261 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
263 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
266 $tpl->set('jsvarurl', false);
268 if( $wgUser->getNewtalk() ) {
269 $usertitle = $this->mUser
->getUserPage();
270 $usertalktitle = $usertitle->getTalkPage();
271 if( !$usertalktitle->equals( $this->mTitle
) ) {
272 $ntl = wfMsg( 'newmessages',
273 $this->makeKnownLinkObj(
275 wfMsg('newmessageslink')
279 $wgOut->setSquidMaxage(0);
284 wfProfileOut( "$fname-stuff2" );
286 wfProfileIn( "$fname-stuff3" );
287 $tpl->setRef( 'newtalk', $ntl );
288 $tpl->setRef( 'skin', $this);
289 $tpl->set( 'logo', $this->logoText() );
290 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
291 if ( !$wgDisableCounters ) {
292 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
294 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
296 $tpl->set('viewcount', false);
299 $tpl->set('viewcount', false);
302 if ($wgPageShowWatchingUsers) {
303 $dbr =& wfGetDB( DB_SLAVE
);
304 extract( $dbr->tableNames( 'watchlist' ) );
305 $sql = "SELECT COUNT(*) AS n FROM $watchlist
306 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
307 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
308 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
309 $x = $dbr->fetchObject( $res );
310 $numberofwatchingusers = $x->n
;
311 if ($numberofwatchingusers > 0) {
312 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
314 $tpl->set('numberofwatchingusers', false);
317 $tpl->set('numberofwatchingusers', false);
320 $tpl->set('copyright',$this->getCopyright());
322 $this->credits
= false;
324 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
325 require_once("Credits.php");
326 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
328 $tpl->set('lastmod', $this->lastModified());
331 $tpl->setRef( 'credits', $this->credits
);
333 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
334 $tpl->set('copyright', $this->getCopyright());
335 $tpl->set('viewcount', false);
336 $tpl->set('lastmod', false);
337 $tpl->set('credits', false);
338 $tpl->set('numberofwatchingusers', false);
340 $tpl->set('copyright', false);
341 $tpl->set('viewcount', false);
342 $tpl->set('lastmod', false);
343 $tpl->set('credits', false);
344 $tpl->set('numberofwatchingusers', false);
346 wfProfileOut( "$fname-stuff3" );
348 wfProfileIn( "$fname-stuff4" );
349 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
350 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
351 $tpl->set( 'disclaimer', $this->disclaimerLink() );
352 $tpl->set( 'about', $this->aboutLink() );
354 $tpl->setRef( 'debug', $out->mDebugtext
);
355 $tpl->set( 'reporttime', $out->reportTime() );
356 $tpl->set( 'sitenotice', wfGetSiteNotice() );
358 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
359 $out->mBodytext
.= $printfooter ;
360 $tpl->setRef( 'bodytext', $out->mBodytext
);
363 $language_urls = array();
365 if ( !$wgHideInterlanguageLinks ) {
366 foreach( $wgOut->getLanguageLinks() as $l ) {
367 $tmp = explode( ':', $l, 2 );
368 $class = 'interwiki-' . $tmp[0];
370 $nt = Title
::newFromText( $l );
371 $language_urls[] = array(
372 'href' => $nt->getFullURL(),
373 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
378 if(count($language_urls)) {
379 $tpl->setRef( 'language_urls', $language_urls);
381 $tpl->set('language_urls', false);
383 wfProfileOut( "$fname-stuff4" );
386 $tpl->set('personal_urls', $this->buildPersonalUrls());
387 $content_actions = $this->buildContentActionUrls();
388 $tpl->setRef('content_actions', $content_actions);
390 // XXX: attach this from javascript, same with section editing
391 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
393 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
395 $tpl->set('body_ondblclick', false);
397 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
398 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
400 $tpl->set( 'body_onload', false );
402 $tpl->set( 'sidebar', $this->buildSidebar() );
403 $tpl->set( 'nav_urls', $this->buildNavUrls() );
406 wfProfileIn( "$fname-execute" );
407 $res = $tpl->execute();
408 wfProfileOut( "$fname-execute" );
410 // result may be an error
411 $this->printOrError( $res );
412 wfProfileOut( $fname );
416 * Output the string, or print error message if it's
417 * an error object of the appropriate type.
418 * For the base class, assume strings all around.
423 function printOrError( &$str ) {
428 * build array of urls for personal toolbar
432 function buildPersonalUrls() {
433 $fname = 'SkinTemplate::buildPersonalUrls';
434 wfProfileIn( $fname );
436 /* set up the default links for the personal toolbar */
437 global $wgShowIPinHeader;
438 $personal_urls = array();
439 if ($this->loggedin
) {
440 $personal_urls['userpage'] = array(
441 'text' => $this->username
,
442 'href' => &$this->userpageUrlDetails
['href'],
443 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
445 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
446 $personal_urls['mytalk'] = array(
447 'text' => wfMsg('mytalk'),
448 'href' => &$usertalkUrlDetails['href'],
449 'class' => $usertalkUrlDetails['exists']?
false:'new'
451 $personal_urls['preferences'] = array(
452 'text' => wfMsg('preferences'),
453 'href' => $this->makeSpecialUrl('Preferences')
455 $personal_urls['watchlist'] = array(
456 'text' => wfMsg('watchlist'),
457 'href' => $this->makeSpecialUrl('Watchlist')
459 $personal_urls['mycontris'] = array(
460 'text' => wfMsg('mycontris'),
461 'href' => $this->makeSpecialUrl("Contributions/$this->username")
463 $personal_urls['logout'] = array(
464 'text' => wfMsg('userlogout'),
465 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
468 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
469 $personal_urls['anonuserpage'] = array(
470 'text' => $this->username
,
471 'href' => &$this->userpageUrlDetails
['href'],
472 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
474 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
475 $personal_urls['anontalk'] = array(
476 'text' => wfMsg('anontalk'),
477 'href' => &$usertalkUrlDetails['href'],
478 'class' => $usertalkUrlDetails['exists']?
false:'new'
480 $personal_urls['anonlogin'] = array(
481 'text' => wfMsg('userlogin'),
482 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
486 $personal_urls['login'] = array(
487 'text' => wfMsg('userlogin'),
488 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
492 wfProfileOut( $fname );
493 return $personal_urls;
497 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
500 $classes[] = 'selected';
502 if( $checkEdit && $title->getArticleId() == 0 ) {
504 $query = 'action=edit';
507 $text = wfMsg( $message );
508 if ( $text == "<$message>" ) {
509 $text = wfMsg( 'nstab-main' );
513 'class' => implode( ' ', $classes ),
515 'href' => $title->getLocalUrl( $query ) );
518 function makeTalkUrlDetails( $name, $urlaction='' ) {
519 $title = Title
::newFromText( $name );
520 $title = $title->getTalkPage();
521 $this->checkTitle($title, $name);
523 'href' => $title->getLocalURL( $urlaction ),
524 'exists' => $title->getArticleID() != 0?
true:false
528 function makeArticleUrlDetails( $name, $urlaction='' ) {
529 $title = Title
::newFromText( $name );
530 $title= $title->getSubjectPage();
531 $this->checkTitle($title, $name);
533 'href' => $title->getLocalURL( $urlaction ),
534 'exists' => $title->getArticleID() != 0?
true:false
539 * an array of edit links by default used for the tabs
543 function buildContentActionUrls () {
544 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
545 $fname = 'SkinTemplate::buildContentActionUrls';
546 wfProfileIn( $fname );
548 global $wgUser, $wgRequest;
549 $action = $wgRequest->getText( 'action' );
550 $section = $wgRequest->getText( 'section' );
551 $oldid = $wgRequest->getVal( 'oldid' );
552 $diff = $wgRequest->getVal( 'diff' );
553 $content_actions = array();
555 if( $this->iscontent
) {
556 $subjpage = $this->mTitle
->getSubjectPage();
557 $talkpage = $this->mTitle
->getTalkPage();
559 $nskey = $this->getNameSpaceKey();
560 $content_actions[$nskey] = $this->tabAction(
563 !$this->mTitle
->isTalkPage(),
566 $content_actions['talk'] = $this->tabAction(
569 $this->mTitle
->isTalkPage(),
573 wfProfileIn( "$fname-edit" );
574 if ( $this->mTitle
->userCanEdit() ) {
575 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : false;
576 $istalk = $this->mTitle
->isTalkPage();
577 $istalkclass = $istalk?
' istalk':'';
578 $content_actions['edit'] = array(
579 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
580 'text' => wfMsg('edit'),
581 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
585 $content_actions['addsection'] = array(
586 'class' => $section == 'new'?
'selected':false,
587 'text' => wfMsg('addsection'),
588 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
592 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : '';
593 $content_actions['viewsource'] = array(
594 'class' => ($action == 'edit') ?
'selected' : false,
595 'text' => wfMsg('viewsource'),
596 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
599 wfProfileOut( "$fname-edit" );
601 wfProfileIn( "$fname-live" );
602 if ( $this->mTitle
->getArticleId() ) {
604 $content_actions['history'] = array(
605 'class' => ($action == 'history') ?
'selected' : false,
606 'text' => wfMsg('history_short'),
607 'href' => $this->mTitle
->getLocalUrl( 'action=history')
610 if($wgUser->isAllowed('protect')){
611 if(!$this->mTitle
->isProtected()){
612 $content_actions['protect'] = array(
613 'class' => ($action == 'protect') ?
'selected' : false,
614 'text' => wfMsg('protect'),
615 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
619 $content_actions['unprotect'] = array(
620 'class' => ($action == 'unprotect') ?
'selected' : false,
621 'text' => wfMsg('unprotect'),
622 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
626 if($wgUser->isAllowed('delete')){
627 $content_actions['delete'] = array(
628 'class' => ($action == 'delete') ?
'selected' : false,
629 'text' => wfMsg('delete'),
630 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
633 if ( $this->mTitle
->userCanMove()) {
634 $content_actions['move'] = array(
635 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
636 'text' => wfMsg('move'),
637 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
641 //article doesn't exist or is deleted
642 if($wgUser->isAllowed('delete')){
643 if( $n = $this->mTitle
->isDeleted() ) {
644 $content_actions['undelete'] = array(
646 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
647 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
652 wfProfileOut( "$fname-live" );
654 if( $this->loggedin
) {
655 if( !$this->mTitle
->userIsWatching()) {
656 $content_actions['watch'] = array(
657 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
658 'text' => wfMsg('watch'),
659 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
662 $content_actions['unwatch'] = array(
663 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
664 'text' => wfMsg('unwatch'),
665 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
670 if( $this->loggedin ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
671 # Validate tab. TODO: add validation to logged-in user rights
672 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
673 if ( $oldid ) $oid = intval( $oldid ) ; # Use the oldid
675 {# Trying to get the current article revision through this weird stunt
676 $tid = $this->mTitle
->getArticleID();
677 $tns = $this->mTitle
->getNamespace();
678 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
679 $res = wfQuery( $sql, DB_READ
);
680 if( $s = wfFetchObject( $res ) )
681 $oid = $s->page_latest
;
682 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
685 $oid = "&revision={$oid}" ;
686 $content_actions['validate'] = array(
687 'class' => ($action == 'validate') ?
'selected' : false,
688 'text' => wfMsg('val_tab'),
689 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
695 /* show special page tab */
697 $content_actions['article'] = array(
698 'class' => 'selected',
699 'text' => wfMsg('specialpage'),
700 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
704 /* show links to different language variants */
705 global $wgDisableLangConversion;
706 $variants = $wgContLang->getVariants();
707 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
708 $preferred = $wgContLang->getPreferredVariant();
711 $actstr = 'action=' . $action . '&';
713 foreach( $variants as $code ) {
714 $varname = $wgContLang->getVariantname( $code );
715 if( $varname == 'disable' )
717 $selected = ( $code == $preferred )?
'selected' : false;
718 $content_actions['varlang-' . $vcount] = array(
719 'class' => $selected,
721 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
727 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
729 wfProfileOut( $fname );
730 return $content_actions;
736 * build array of common navigation links
740 function buildNavUrls () {
741 global $wgUseTrackbacks, $wgTitle, $wgArticle;
743 $fname = 'SkinTemplate::buildNavUrls';
744 wfProfileIn( $fname );
746 global $wgUser, $wgRequest;
747 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
749 $action = $wgRequest->getText( 'action' );
750 $oldid = $wgRequest->getVal( 'oldid' );
751 $diff = $wgRequest->getVal( 'diff' );
754 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
755 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
756 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
757 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
758 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
759 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
760 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
761 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
762 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
763 if( $wgEnableUploads ) {
764 if ($wgUploadNavigationUrl) {
765 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
767 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
770 $nav_urls['upload'] = false;
772 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
775 // A print stylesheet is attached to all pages, but nobody ever
776 // figures that out. :) Add a link...
777 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
778 $revid = $wgArticle->getRevIdFetched();
779 if ( !( $revid == 0 ) )
780 $nav_urls['print'] = array(
781 'text' => wfMsg( 'printableversion' ),
782 'href' => $wgRequest->appendQuery( 'printable=yes' )
785 // Also add a "permalink" while we're at it
787 $nav_urls['permalink'] = array(
788 'text' => wfMsg( 'permalink' ),
792 if ( !( $revid == 0 ) )
793 $nav_urls['permalink'] = array(
794 'text' => wfMsg( 'permalink' ),
795 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
800 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
801 $nav_urls['whatlinkshere'] = array(
802 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
804 $nav_urls['recentchangeslinked'] = array(
805 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
807 if ($wgUseTrackbacks)
808 $nav_urls['trackbacklink'] = array(
809 'href' => $wgTitle->trackbackURL()
813 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
814 $id = User
::idFromName($this->mTitle
->getText());
815 $ip = User
::isIP($this->mTitle
->getText());
821 if($id ||
$ip) { # both anons and non-anons have contri list
822 $nav_urls['contributions'] = array(
823 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
826 $nav_urls['contributions'] = false;
828 $nav_urls['emailuser'] = false;
829 if( $this->showEmailUser( $id ) ) {
830 $nav_urls['emailuser'] = array(
831 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
834 wfProfileOut( $fname );
839 * Generate strings used for xml 'id' names
843 function getNameSpaceKey () {
844 switch ($this->mTitle
->getNamespace()) {
852 return 'nstab-media';
854 return 'nstab-special';
856 case NS_PROJECT_TALK
:
860 return 'nstab-image';
862 case NS_MEDIAWIKI_TALK
:
863 return 'nstab-mediawiki';
865 case NS_TEMPLATE_TALK
:
866 return 'nstab-template';
871 case NS_CATEGORY_TALK
:
872 return 'nstab-category';
874 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
881 function setupUserCss() {
882 $fname = 'SkinTemplate::setupUserCss';
883 wfProfileIn( $fname );
885 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
889 $siteargs = '&maxage=' . $wgSquidMaxage;
891 # Add user-specific code if this is a user and we allow that kind of thing
893 if ( $wgAllowUserCss && $this->loggedin
) {
894 $action = $wgRequest->getText('action');
896 # if we're previewing the CSS page, use it
897 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
898 $siteargs = "&smaxage=0&maxage=0";
899 $usercss = $wgRequest->getText('wpTextbox1');
901 $usercss = '@import "' .
902 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
903 'action=raw&ctype=text/css') . '";' ."\n";
906 $siteargs .= '&ts=' . $wgUser->mTouched
;
909 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
911 # If we use the site's dynamic CSS, throw that in, too
912 if ( $wgUseSiteCss ) {
913 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
914 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
917 # If we use any dynamic CSS, make a little CDATA block out of it.
919 if ( !empty($sitecss) ||
!empty($usercss) ) {
920 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
922 wfProfileOut( $fname );
928 function setupUserJs() {
929 $fname = 'SkinTemplate::setupUserJs';
930 wfProfileIn( $fname );
932 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
933 $action = $wgRequest->getText('action');
935 if( $wgAllowUserJs && $this->loggedin
) {
936 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
937 # XXX: additional security check/prompt?
938 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
940 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
943 wfProfileOut( $fname );
947 * Code for extensions to hook into to provide per-page CSS, see
948 * extension/PageCSS/PageCSS.php for an implementation of this.
952 function setupPageCss() {
953 $fname = 'SkinTemplate::setupPageCss';
954 wfProfileIn( $fname );
956 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
957 wfProfileOut( $fname );
962 * returns css with user-specific options
966 function getUserStylesheet() {
967 $fname = 'SkinTemplate::getUserStylesheet';
968 wfProfileIn( $fname );
971 $s = "/* generated user stylesheet */\n";
972 $s .= $this->reallyDoGetUserStyles();
973 wfProfileOut( $fname );
980 function getUserJs() {
981 $fname = 'SkinTemplate::getUserJs';
982 wfProfileIn( $fname );
985 $s = '/* generated javascript */';
986 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
987 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
989 // avoid inclusion of non defined user JavaScript (with custom skins only)
990 // by checking for default message content
991 $msgKey = ucfirst($this->skinname
).'.js';
992 $userJS = wfMsg($msgKey);
993 if ('<'.$msgKey.'>' != $userJS) {
997 wfProfileOut( $fname );
1003 * Generic wrapper for template functions, with interface
1004 * compatible with what we use of PHPTAL 0.7.
1005 * @package MediaWiki
1008 class QuickTemplate
{
1012 function QuickTemplate() {
1013 $this->data
= array();
1014 $this->translator
= new MediaWiki_I18N();
1020 function set( $name, $value ) {
1021 $this->data
[$name] = $value;
1027 function setRef($name, &$value) {
1028 $this->data
[$name] =& $value;
1034 function setTranslator( &$t ) {
1035 $this->translator
= &$t;
1041 function execute() {
1042 echo "Override this function.";
1049 function text( $str ) {
1050 echo htmlspecialchars( $this->data
[$str] );
1056 function html( $str ) {
1057 echo $this->data
[$str];
1063 function msg( $str ) {
1064 echo htmlspecialchars( $this->translator
->translate( $str ) );
1070 function msgHtml( $str ) {
1071 echo $this->translator
->translate( $str );
1075 * An ugly, ugly hack.
1078 function msgWiki( $str ) {
1079 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1081 $text = $this->translator
->translate( $str );
1082 $parserOutput = $wgParser->parse( $text, $wgTitle,
1083 $wgOut->mParserOptions
, true );
1084 echo $parserOutput->getText();
1090 function haveData( $str ) {
1091 return $this->data
[$str];
1097 function haveMsg( $str ) {
1098 $msg = $this->translator
->translate( $str );
1099 return ($msg != '-') && ($msg != ''); # ????
1103 } // end of if( defined( 'MEDIAWIKI' ) )