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 global $wgTitle, $wgShowIPinHeader;
435 $fname = 'SkinTemplate::buildPersonalUrls';
436 $pageurl = $wgTitle->getLocalURL();
437 wfProfileIn( $fname );
439 /* set up the default links for the personal toolbar */
440 $personal_urls = array();
441 if ($this->loggedin
) {
442 $personal_urls['userpage'] = array(
443 'text' => $this->username
,
444 'href' => &$this->userpageUrlDetails
['href'],
445 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
446 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
448 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
449 $personal_urls['mytalk'] = array(
450 'text' => wfMsg('mytalk'),
451 'href' => &$usertalkUrlDetails['href'],
452 'class' => $usertalkUrlDetails['exists']?
false:'new',
453 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
455 $href = $this->makeSpecialUrl('Preferences');
456 $personal_urls['preferences'] = array(
457 'text' => wfMsg('preferences'),
458 'href' => $this->makeSpecialUrl('Preferences'),
459 'active' => ( $href == $pageurl )
461 $href = $this->makeSpecialUrl('Watchlist');
462 $personal_urls['watchlist'] = array(
463 'text' => wfMsg('watchlist'),
465 'active' => ( $href == $pageurl )
467 $href = $this->makeSpecialUrl("Contributions/$this->username");
468 $personal_urls['mycontris'] = array(
469 'text' => wfMsg('mycontris'),
471 'active' => ( $href == $pageurl . '/' . $this->username
)
473 $personal_urls['logout'] = array(
474 'text' => wfMsg('userlogout'),
475 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
478 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
479 $href = &$this->userpageUrlDetails
['href'];
480 $personal_urls['anonuserpage'] = array(
481 'text' => $this->username
,
483 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
484 'active' => ( $pageurl == $href )
486 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
487 $href = &$usertalkUrlDetails['href'];
488 $personal_urls['anontalk'] = array(
489 'text' => wfMsg('anontalk'),
491 'class' => $usertalkUrlDetails['exists']?
false:'new',
492 'active' => ( $pageurl == $href )
494 $personal_urls['anonlogin'] = array(
495 'text' => wfMsg('userlogin'),
496 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
497 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
501 $personal_urls['login'] = array(
502 'text' => wfMsg('userlogin'),
503 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
504 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
508 wfProfileOut( $fname );
509 return $personal_urls;
513 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
516 $classes[] = 'selected';
518 if( $checkEdit && $title->getArticleId() == 0 ) {
520 $query = 'action=edit';
523 $text = wfMsg( $message );
524 if ( $text == "<$message>" ) {
525 $text = wfMsg( 'nstab-main' );
529 'class' => implode( ' ', $classes ),
531 'href' => $title->getLocalUrl( $query ) );
534 function makeTalkUrlDetails( $name, $urlaction='' ) {
535 $title = Title
::newFromText( $name );
536 $title = $title->getTalkPage();
537 $this->checkTitle($title, $name);
539 'href' => $title->getLocalURL( $urlaction ),
540 'exists' => $title->getArticleID() != 0?
true:false
544 function makeArticleUrlDetails( $name, $urlaction='' ) {
545 $title = Title
::newFromText( $name );
546 $title= $title->getSubjectPage();
547 $this->checkTitle($title, $name);
549 'href' => $title->getLocalURL( $urlaction ),
550 'exists' => $title->getArticleID() != 0?
true:false
555 * an array of edit links by default used for the tabs
559 function buildContentActionUrls () {
560 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
561 $fname = 'SkinTemplate::buildContentActionUrls';
562 wfProfileIn( $fname );
564 global $wgUser, $wgRequest;
565 $action = $wgRequest->getText( 'action' );
566 $section = $wgRequest->getText( 'section' );
567 $oldid = $wgRequest->getVal( 'oldid' );
568 $diff = $wgRequest->getVal( 'diff' );
569 $content_actions = array();
571 if( $this->iscontent
) {
572 $subjpage = $this->mTitle
->getSubjectPage();
573 $talkpage = $this->mTitle
->getTalkPage();
575 $nskey = $this->getNameSpaceKey();
576 $content_actions[$nskey] = $this->tabAction(
579 !$this->mTitle
->isTalkPage(),
582 $content_actions['talk'] = $this->tabAction(
585 $this->mTitle
->isTalkPage(),
589 wfProfileIn( "$fname-edit" );
590 if ( $this->mTitle
->userCanEdit() ) {
591 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : false;
592 $istalk = $this->mTitle
->isTalkPage();
593 $istalkclass = $istalk?
' istalk':'';
594 $content_actions['edit'] = array(
595 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
596 'text' => wfMsg('edit'),
597 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
601 $content_actions['addsection'] = array(
602 'class' => $section == 'new'?
'selected':false,
603 'text' => wfMsg('addsection'),
604 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
608 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.intval( $oldid ) : '';
609 $content_actions['viewsource'] = array(
610 'class' => ($action == 'edit') ?
'selected' : false,
611 'text' => wfMsg('viewsource'),
612 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
615 wfProfileOut( "$fname-edit" );
617 wfProfileIn( "$fname-live" );
618 if ( $this->mTitle
->getArticleId() ) {
620 $content_actions['history'] = array(
621 'class' => ($action == 'history') ?
'selected' : false,
622 'text' => wfMsg('history_short'),
623 'href' => $this->mTitle
->getLocalUrl( 'action=history')
626 if($wgUser->isAllowed('protect')){
627 if(!$this->mTitle
->isProtected()){
628 $content_actions['protect'] = array(
629 'class' => ($action == 'protect') ?
'selected' : false,
630 'text' => wfMsg('protect'),
631 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
635 $content_actions['unprotect'] = array(
636 'class' => ($action == 'unprotect') ?
'selected' : false,
637 'text' => wfMsg('unprotect'),
638 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
642 if($wgUser->isAllowed('delete')){
643 $content_actions['delete'] = array(
644 'class' => ($action == 'delete') ?
'selected' : false,
645 'text' => wfMsg('delete'),
646 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
649 if ( $this->mTitle
->userCanMove()) {
650 $content_actions['move'] = array(
651 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
652 'text' => wfMsg('move'),
653 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
657 //article doesn't exist or is deleted
658 if($wgUser->isAllowed('delete')){
659 if( $n = $this->mTitle
->isDeleted() ) {
660 $content_actions['undelete'] = array(
662 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
663 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
668 wfProfileOut( "$fname-live" );
670 if( $this->loggedin
) {
671 if( !$this->mTitle
->userIsWatching()) {
672 $content_actions['watch'] = array(
673 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
674 'text' => wfMsg('watch'),
675 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
678 $content_actions['unwatch'] = array(
679 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
680 'text' => wfMsg('unwatch'),
681 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
686 if( $this->loggedin ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
687 # Validate tab. TODO: add validation to logged-in user rights
688 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
689 if ( $oldid ) $oid = intval( $oldid ) ; # Use the oldid
691 {# Trying to get the current article revision through this weird stunt
692 $tid = $this->mTitle
->getArticleID();
693 $tns = $this->mTitle
->getNamespace();
694 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
695 $res = wfQuery( $sql, DB_READ
);
696 if( $s = wfFetchObject( $res ) )
697 $oid = $s->page_latest
;
698 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
701 $oid = "&revision={$oid}" ;
702 $content_actions['validate'] = array(
703 'class' => ($action == 'validate') ?
'selected' : false,
704 'text' => wfMsg('val_tab'),
705 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
711 /* show special page tab */
713 $content_actions['article'] = array(
714 'class' => 'selected',
715 'text' => wfMsg('specialpage'),
716 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
720 /* show links to different language variants */
721 global $wgDisableLangConversion;
722 $variants = $wgContLang->getVariants();
723 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
724 $preferred = $wgContLang->getPreferredVariant();
727 $actstr = 'action=' . $action . '&';
729 foreach( $variants as $code ) {
730 $varname = $wgContLang->getVariantname( $code );
731 if( $varname == 'disable' )
733 $selected = ( $code == $preferred )?
'selected' : false;
734 $content_actions['varlang-' . $vcount] = array(
735 'class' => $selected,
737 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
743 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
745 wfProfileOut( $fname );
746 return $content_actions;
752 * build array of common navigation links
756 function buildNavUrls () {
757 global $wgUseTrackbacks, $wgTitle, $wgArticle;
759 $fname = 'SkinTemplate::buildNavUrls';
760 wfProfileIn( $fname );
762 global $wgUser, $wgRequest;
763 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
765 $action = $wgRequest->getText( 'action' );
766 $oldid = $wgRequest->getVal( 'oldid' );
767 $diff = $wgRequest->getVal( 'diff' );
770 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
771 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
772 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
773 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
774 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
775 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
776 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
777 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
778 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
779 if( $wgEnableUploads ) {
780 if ($wgUploadNavigationUrl) {
781 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
783 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
786 $nav_urls['upload'] = false;
788 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
791 // A print stylesheet is attached to all pages, but nobody ever
792 // figures that out. :) Add a link...
793 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
794 $revid = $wgArticle->getRevIdFetched();
795 if ( !( $revid == 0 ) )
796 $nav_urls['print'] = array(
797 'text' => wfMsg( 'printableversion' ),
798 'href' => $wgRequest->appendQuery( 'printable=yes' )
801 // Also add a "permalink" while we're at it
803 $nav_urls['permalink'] = array(
804 'text' => wfMsg( 'permalink' ),
808 if ( !( $revid == 0 ) )
809 $nav_urls['permalink'] = array(
810 'text' => wfMsg( 'permalink' ),
811 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
816 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
817 $nav_urls['whatlinkshere'] = array(
818 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
820 $nav_urls['recentchangeslinked'] = array(
821 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
823 if ($wgUseTrackbacks)
824 $nav_urls['trackbacklink'] = array(
825 'href' => $wgTitle->trackbackURL()
829 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
830 $id = User
::idFromName($this->mTitle
->getText());
831 $ip = User
::isIP($this->mTitle
->getText());
837 if($id ||
$ip) { # both anons and non-anons have contri list
838 $nav_urls['contributions'] = array(
839 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
842 $nav_urls['contributions'] = false;
844 $nav_urls['emailuser'] = false;
845 if( $this->showEmailUser( $id ) ) {
846 $nav_urls['emailuser'] = array(
847 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
850 wfProfileOut( $fname );
855 * Generate strings used for xml 'id' names
859 function getNameSpaceKey () {
860 switch ($this->mTitle
->getNamespace()) {
868 return 'nstab-media';
870 return 'nstab-special';
872 case NS_PROJECT_TALK
:
876 return 'nstab-image';
878 case NS_MEDIAWIKI_TALK
:
879 return 'nstab-mediawiki';
881 case NS_TEMPLATE_TALK
:
882 return 'nstab-template';
887 case NS_CATEGORY_TALK
:
888 return 'nstab-category';
890 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
897 function setupUserCss() {
898 $fname = 'SkinTemplate::setupUserCss';
899 wfProfileIn( $fname );
901 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
905 $siteargs = '&maxage=' . $wgSquidMaxage;
907 # Add user-specific code if this is a user and we allow that kind of thing
909 if ( $wgAllowUserCss && $this->loggedin
) {
910 $action = $wgRequest->getText('action');
912 # if we're previewing the CSS page, use it
913 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
914 $siteargs = "&smaxage=0&maxage=0";
915 $usercss = $wgRequest->getText('wpTextbox1');
917 $usercss = '@import "' .
918 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
919 'action=raw&ctype=text/css') . '";' ."\n";
922 $siteargs .= '&ts=' . $wgUser->mTouched
;
925 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
927 # If we use the site's dynamic CSS, throw that in, too
928 if ( $wgUseSiteCss ) {
929 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
930 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
933 # If we use any dynamic CSS, make a little CDATA block out of it.
935 if ( !empty($sitecss) ||
!empty($usercss) ) {
936 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
938 wfProfileOut( $fname );
944 function setupUserJs() {
945 $fname = 'SkinTemplate::setupUserJs';
946 wfProfileIn( $fname );
948 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
949 $action = $wgRequest->getText('action');
951 if( $wgAllowUserJs && $this->loggedin
) {
952 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
953 # XXX: additional security check/prompt?
954 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
956 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
959 wfProfileOut( $fname );
963 * Code for extensions to hook into to provide per-page CSS, see
964 * extension/PageCSS/PageCSS.php for an implementation of this.
968 function setupPageCss() {
969 $fname = 'SkinTemplate::setupPageCss';
970 wfProfileIn( $fname );
972 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle
->isProtected() ) );
973 wfProfileOut( $fname );
978 * returns css with user-specific options
982 function getUserStylesheet() {
983 $fname = 'SkinTemplate::getUserStylesheet';
984 wfProfileIn( $fname );
987 $s = "/* generated user stylesheet */\n";
988 $s .= $this->reallyDoGetUserStyles();
989 wfProfileOut( $fname );
996 function getUserJs() {
997 $fname = 'SkinTemplate::getUserJs';
998 wfProfileIn( $fname );
1000 global $wgStylePath;
1001 $s = '/* generated javascript */';
1002 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1003 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1005 // avoid inclusion of non defined user JavaScript (with custom skins only)
1006 // by checking for default message content
1007 $msgKey = ucfirst($this->skinname
).'.js';
1008 $userJS = wfMsg($msgKey);
1009 if ('<'.$msgKey.'>' != $userJS) {
1013 wfProfileOut( $fname );
1019 * Generic wrapper for template functions, with interface
1020 * compatible with what we use of PHPTAL 0.7.
1021 * @package MediaWiki
1024 class QuickTemplate
{
1028 function QuickTemplate() {
1029 $this->data
= array();
1030 $this->translator
= new MediaWiki_I18N();
1036 function set( $name, $value ) {
1037 $this->data
[$name] = $value;
1043 function setRef($name, &$value) {
1044 $this->data
[$name] =& $value;
1050 function setTranslator( &$t ) {
1051 $this->translator
= &$t;
1057 function execute() {
1058 echo "Override this function.";
1065 function text( $str ) {
1066 echo htmlspecialchars( $this->data
[$str] );
1072 function html( $str ) {
1073 echo $this->data
[$str];
1079 function msg( $str ) {
1080 echo htmlspecialchars( $this->translator
->translate( $str ) );
1086 function msgHtml( $str ) {
1087 echo $this->translator
->translate( $str );
1091 * An ugly, ugly hack.
1094 function msgWiki( $str ) {
1095 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1097 $text = $this->translator
->translate( $str );
1098 $parserOutput = $wgParser->parse( $text, $wgTitle,
1099 $wgOut->mParserOptions
, true );
1100 echo $parserOutput->getText();
1106 function haveData( $str ) {
1107 return $this->data
[$str];
1113 function haveMsg( $str ) {
1114 $msg = $this->translator
->translate( $str );
1115 return ($msg != '-') && ($msg != ''); # ????
1119 } // end of if( defined( 'MEDIAWIKI' ) )