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->setRef( 'wgScript', $wgScript );
229 $tpl->setRef( 'skinname', $this->skinname
);
230 $tpl->setRef( 'stylename', $this->stylename
);
231 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
232 $tpl->setRef( 'loggedin', $this->loggedin
);
233 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
234 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
235 /* XXX currently unused, might get useful later
236 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
237 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
238 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
239 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
240 $tpl->set( "helppage", wfMsg('helppage'));
242 $tpl->set( 'searchaction', $this->escapeSearchLink() );
243 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
244 $tpl->setRef( 'stylepath', $wgStylePath );
245 $tpl->setRef( 'logopath', $wgLogo );
246 $tpl->setRef( "lang", $wgContLanguageCode );
247 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
248 $tpl->set( 'rtl', $wgContLang->isRTL() );
249 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
250 $tpl->setRef( 'username', $this->username
);
251 $tpl->setRef( 'userpage', $this->userpage
);
252 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
253 $tpl->setRef( 'usercss', $this->usercss
);
254 $tpl->setRef( 'userjs', $this->userjs
);
255 $tpl->setRef( 'userjsprev', $this->userjsprev
);
258 if($this->loggedin
) {
259 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
261 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
264 $tpl->set('jsvarurl', false);
266 if( $wgUser->getNewtalk() ) {
267 $usertitle = $this->mUser
->getUserPage();
268 $usertalktitle = $usertitle->getTalkPage();
269 if( !$usertalktitle->equals( $this->mTitle
) ) {
270 $ntl = wfMsg( 'newmessages',
271 $this->makeKnownLinkObj(
273 wfMsg('newmessageslink')
277 $wgOut->setSquidMaxage(0);
282 wfProfileOut( "$fname-stuff2" );
284 wfProfileIn( "$fname-stuff3" );
285 $tpl->setRef( 'newtalk', $ntl );
286 $tpl->setRef( 'skin', $this);
287 $tpl->set( 'logo', $this->logoText() );
288 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
289 if ( !$wgDisableCounters ) {
290 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
292 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
294 $tpl->set('viewcount', false);
297 $tpl->set('viewcount', false);
300 if ($wgPageShowWatchingUsers) {
301 $dbr =& wfGetDB( DB_SLAVE
);
302 extract( $dbr->tableNames( 'watchlist' ) );
303 $sql = "SELECT COUNT(*) AS n FROM $watchlist
304 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
305 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
306 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
307 $x = $dbr->fetchObject( $res );
308 $numberofwatchingusers = $x->n
;
309 if ($numberofwatchingusers > 0) {
310 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
312 $tpl->set('numberofwatchingusers', false);
315 $tpl->set('numberofwatchingusers', false);
318 $tpl->set('copyright',$this->getCopyright());
320 $this->credits
= false;
322 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
323 require_once("Credits.php");
324 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
326 $tpl->set('lastmod', $this->lastModified());
329 $tpl->setRef( 'credits', $this->credits
);
331 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
332 $tpl->set('copyright', $this->getCopyright());
333 $tpl->set('viewcount', false);
334 $tpl->set('lastmod', false);
335 $tpl->set('credits', false);
336 $tpl->set('numberofwatchingusers', false);
338 $tpl->set('copyright', false);
339 $tpl->set('viewcount', false);
340 $tpl->set('lastmod', false);
341 $tpl->set('credits', false);
342 $tpl->set('numberofwatchingusers', false);
344 wfProfileOut( "$fname-stuff3" );
346 wfProfileIn( "$fname-stuff4" );
347 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
348 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
349 $tpl->set( 'disclaimer', $this->disclaimerLink() );
350 $tpl->set( 'about', $this->aboutLink() );
352 $tpl->setRef( 'debug', $out->mDebugtext
);
353 $tpl->set( 'reporttime', $out->reportTime() );
354 $tpl->set( 'sitenotice', wfGetSiteNotice() );
356 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
357 $out->mBodytext
.= $printfooter ;
358 $tpl->setRef( 'bodytext', $out->mBodytext
);
361 $language_urls = array();
363 if ( !$wgHideInterlanguageLinks ) {
364 foreach( $wgOut->getLanguageLinks() as $l ) {
365 $tmp = explode( ':', $l, 2 );
366 $class = 'interwiki-' . $tmp[0];
368 $nt = Title
::newFromText( $l );
369 $language_urls[] = array(
370 'href' => $nt->getFullURL(),
371 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
376 if(count($language_urls)) {
377 $tpl->setRef( 'language_urls', $language_urls);
379 $tpl->set('language_urls', false);
381 wfProfileOut( "$fname-stuff4" );
384 $tpl->set('personal_urls', $this->buildPersonalUrls());
385 $content_actions = $this->buildContentActionUrls();
386 $tpl->setRef('content_actions', $content_actions);
388 // XXX: attach this from javascript, same with section editing
389 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
391 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
393 $tpl->set('body_ondblclick', false);
395 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
396 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
398 $tpl->set( 'body_onload', false );
400 $tpl->set( 'sidebar', $this->buildSidebar() );
401 $tpl->set( 'nav_urls', $this->buildNavUrls() );
404 wfProfileIn( "$fname-execute" );
405 $res = $tpl->execute();
406 wfProfileOut( "$fname-execute" );
408 // result may be an error
409 $this->printOrError( $res );
410 wfProfileOut( $fname );
414 * Output the string, or print error message if it's
415 * an error object of the appropriate type.
416 * For the base class, assume strings all around.
421 function printOrError( &$str ) {
426 * build array of urls for personal toolbar
430 function buildPersonalUrls() {
431 $fname = 'SkinTemplate::buildPersonalUrls';
432 wfProfileIn( $fname );
434 /* set up the default links for the personal toolbar */
435 global $wgShowIPinHeader;
436 $personal_urls = array();
437 if ($this->loggedin
) {
438 $personal_urls['userpage'] = array(
439 'text' => $this->username
,
440 'href' => &$this->userpageUrlDetails
['href'],
441 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
443 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
444 $personal_urls['mytalk'] = array(
445 'text' => wfMsg('mytalk'),
446 'href' => &$usertalkUrlDetails['href'],
447 'class' => $usertalkUrlDetails['exists']?
false:'new'
449 $personal_urls['preferences'] = array(
450 'text' => wfMsg('preferences'),
451 'href' => $this->makeSpecialUrl('Preferences')
453 $personal_urls['watchlist'] = array(
454 'text' => wfMsg('watchlist'),
455 'href' => $this->makeSpecialUrl('Watchlist')
457 $personal_urls['mycontris'] = array(
458 'text' => wfMsg('mycontris'),
459 'href' => $this->makeSpecialUrl("Contributions/$this->username")
461 $personal_urls['logout'] = array(
462 'text' => wfMsg('userlogout'),
463 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
466 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
467 $personal_urls['anonuserpage'] = array(
468 'text' => $this->username
,
469 'href' => &$this->userpageUrlDetails
['href'],
470 'class' => $this->userpageUrlDetails
['exists']?
false:'new'
472 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
473 $personal_urls['anontalk'] = array(
474 'text' => wfMsg('anontalk'),
475 'href' => &$usertalkUrlDetails['href'],
476 'class' => $usertalkUrlDetails['exists']?
false:'new'
478 $personal_urls['anonlogin'] = array(
479 'text' => wfMsg('userlogin'),
480 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
484 $personal_urls['login'] = array(
485 'text' => wfMsg('userlogin'),
486 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
490 wfProfileOut( $fname );
491 return $personal_urls;
495 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
498 $classes[] = 'selected';
500 if( $checkEdit && $title->getArticleId() == 0 ) {
502 $query = 'action=edit';
505 'class' => implode( ' ', $classes ),
506 'text' => wfMsg( $message ),
507 'href' => $title->getLocalUrl( $query ) );
510 function makeTalkUrlDetails( $name, $urlaction='' ) {
511 $title = Title
::newFromText( $name );
512 $title = $title->getTalkPage();
513 $this->checkTitle($title, $name);
515 'href' => $title->getLocalURL( $urlaction ),
516 'exists' => $title->getArticleID() != 0?
true:false
520 function makeArticleUrlDetails( $name, $urlaction='' ) {
521 $title = Title
::newFromText( $name );
522 $title= $title->getSubjectPage();
523 $this->checkTitle($title, $name);
525 'href' => $title->getLocalURL( $urlaction ),
526 'exists' => $title->getArticleID() != 0?
true:false
531 * an array of edit links by default used for the tabs
535 function buildContentActionUrls () {
536 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
537 $fname = 'SkinTemplate::buildContentActionUrls';
538 wfProfileIn( $fname );
540 global $wgUser, $wgRequest;
541 $action = $wgRequest->getText( 'action' );
542 $section = $wgRequest->getText( 'section' );
543 $oldid = $wgRequest->getVal( 'oldid' );
544 $diff = $wgRequest->getVal( 'diff' );
545 $content_actions = array();
547 if( $this->iscontent
) {
548 $subjpage = $this->mTitle
->getSubjectPage();
549 $talkpage = $this->mTitle
->getTalkPage();
551 $nskey = $this->getNameSpaceKey();
552 $content_actions[$nskey] = $this->tabAction(
555 !$this->mTitle
->isTalkPage(),
558 $content_actions['talk'] = $this->tabAction(
561 $this->mTitle
->isTalkPage(),
565 wfProfileIn( "$fname-edit" );
566 if ( $this->mTitle
->userCanEdit() ) {
567 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
568 $istalk = $this->mTitle
->isTalkPage();
569 $istalkclass = $istalk?
' istalk':'';
570 $content_actions['edit'] = array(
571 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
572 'text' => wfMsg('edit'),
573 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
577 $content_actions['addsection'] = array(
578 'class' => $section == 'new'?
'selected':false,
579 'text' => wfMsg('addsection'),
580 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
584 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
585 $content_actions['viewsource'] = array(
586 'class' => ($action == 'edit') ?
'selected' : false,
587 'text' => wfMsg('viewsource'),
588 'href' => $this->mTitle
->getLocalUrl( 'action=edit'.$oid )
591 wfProfileOut( "$fname-edit" );
593 wfProfileIn( "$fname-live" );
594 if ( $this->mTitle
->getArticleId() ) {
596 $content_actions['history'] = array(
597 'class' => ($action == 'history') ?
'selected' : false,
598 'text' => wfMsg('history_short'),
599 'href' => $this->mTitle
->getLocalUrl( 'action=history')
602 if($wgUser->isAllowed('protect')){
603 if(!$this->mTitle
->isProtected()){
604 $content_actions['protect'] = array(
605 'class' => ($action == 'protect') ?
'selected' : false,
606 'text' => wfMsg('protect'),
607 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
611 $content_actions['unprotect'] = array(
612 'class' => ($action == 'unprotect') ?
'selected' : false,
613 'text' => wfMsg('unprotect'),
614 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
618 if($wgUser->isAllowed('delete')){
619 $content_actions['delete'] = array(
620 'class' => ($action == 'delete') ?
'selected' : false,
621 'text' => wfMsg('delete'),
622 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
625 if ( $wgUser->isLoggedIn() ) {
626 if ( $this->mTitle
->userCanMove()) {
627 $content_actions['move'] = array(
628 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
629 'text' => wfMsg('move'),
630 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
635 //article doesn't exist or is deleted
636 if($wgUser->isAllowed('delete')){
637 if( $n = $this->mTitle
->isDeleted() ) {
638 $content_actions['undelete'] = array(
640 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
641 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
646 wfProfileOut( "$fname-live" );
648 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
649 if( !$this->mTitle
->userIsWatching()) {
650 $content_actions['watch'] = array(
651 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
652 'text' => wfMsg('watch'),
653 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
656 $content_actions['unwatch'] = array(
657 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
658 'text' => wfMsg('unwatch'),
659 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
664 if( $wgUser->isLoggedIn() ||
$wgValidationForAnons ) { # and $action != 'submit' ) {
665 # Validate tab. TODO: add validation to logged-in user rights
666 if($wgUseValidation && ( $action == "" ||
$action=='view' ) ){ # && $wgUser->isAllowed('validate')){
667 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
669 {# Trying to get the current article revision through this weird stunt
670 $tid = $this->mTitle
->getArticleID();
671 $tns = $this->mTitle
->getNamespace();
672 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
673 $res = wfQuery( $sql, DB_READ
);
674 if( $s = wfFetchObject( $res ) )
675 $oid = $s->page_latest
;
676 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
679 $oid = "&revision={$oid}" ;
680 $content_actions['validate'] = array(
681 'class' => ($action == 'validate') ?
'selected' : false,
682 'text' => wfMsg('val_tab'),
683 'href' => $this->mTitle
->getLocalUrl( "action=validate{$oid}" )
689 /* show special page tab */
691 $content_actions['article'] = array(
692 'class' => 'selected',
693 'text' => wfMsg('specialpage'),
694 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
698 /* show links to different language variants */
699 global $wgDisableLangConversion;
700 $variants = $wgContLang->getVariants();
701 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
702 $preferred = $wgContLang->getPreferredVariant();
705 $actstr = 'action=' . $action . '&';
707 foreach( $variants as $code ) {
708 $varname = $wgContLang->getVariantname( $code );
709 if( $varname == 'disable' )
711 $selected = ( $code == $preferred )?
'selected' : false;
712 $content_actions['varlang-' . $vcount] = array(
713 'class' => $selected,
715 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
721 wfRunHooks( 'SkinTemplateContentActions', array(&$content_actions) );
723 wfProfileOut( $fname );
724 return $content_actions;
730 * build array of common navigation links
734 function buildNavUrls () {
735 global $wgUseTrackbacks, $wgTitle;
737 $fname = 'SkinTemplate::buildNavUrls';
738 wfProfileIn( $fname );
740 global $wgUser, $wgRequest;
741 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
743 $action = $wgRequest->getText( 'action' );
744 $oldid = $wgRequest->getVal( 'oldid' );
745 $diff = $wgRequest->getVal( 'diff' );
748 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
749 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
750 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
751 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
752 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
753 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
754 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
755 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
756 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
757 if( $wgEnableUploads ) {
758 if ($wgUploadNavigationUrl) {
759 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
761 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
764 $nav_urls['upload'] = false;
766 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
769 // A print stylesheet is attached to all pages, but nobody ever
770 // figures that out. :) Add a link...
771 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
772 $nav_urls['print'] = array(
773 'text' => wfMsg( 'printableversion' ),
774 'href' => $wgRequest->appendQuery( 'printable=yes' ) );
777 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
778 $nav_urls['whatlinkshere'] = array(
779 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
781 $nav_urls['recentchangeslinked'] = array(
782 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
784 if ($wgUseTrackbacks)
785 $nav_urls['trackbacklink'] = array(
786 'href' => $wgTitle->trackbackURL()
790 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
791 $id = User
::idFromName($this->mTitle
->getText());
792 $ip = User
::isIP($this->mTitle
->getText());
798 if($id ||
$ip) { # both anons and non-anons have contri list
799 $nav_urls['contributions'] = array(
800 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
803 $nav_urls['contributions'] = false;
805 $nav_urls['emailuser'] = false;
806 if( $this->showEmailUser( $id ) ) {
807 $nav_urls['emailuser'] = array(
808 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
811 wfProfileOut( $fname );
816 * Generate strings used for xml 'id' names
820 function getNameSpaceKey () {
821 switch ($this->mTitle
->getNamespace()) {
829 return 'nstab-media';
831 return 'nstab-special';
833 case NS_PROJECT_TALK
:
837 return 'nstab-image';
839 case NS_MEDIAWIKI_TALK
:
840 return 'nstab-mediawiki';
842 case NS_TEMPLATE_TALK
:
843 return 'nstab-template';
848 case NS_CATEGORY_TALK
:
849 return 'nstab-category';
858 function setupUserCss() {
859 $fname = 'SkinTemplate::setupUserCss';
860 wfProfileIn( $fname );
862 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
866 $siteargs = '&maxage=' . $wgSquidMaxage;
868 # Add user-specific code if this is a user and we allow that kind of thing
870 if ( $wgAllowUserCss && $this->loggedin
) {
871 $action = $wgRequest->getText('action');
873 # if we're previewing the CSS page, use it
874 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
875 $siteargs = "&smaxage=0&maxage=0";
876 $usercss = $wgRequest->getText('wpTextbox1');
878 $usercss = '@import "' .
879 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
880 'action=raw&ctype=text/css') . '";' ."\n";
883 $siteargs .= '&ts=' . $wgUser->mTouched
;
886 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
888 # If we use the site's dynamic CSS, throw that in, too
889 if ( $wgUseSiteCss ) {
890 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
891 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
894 # If we use any dynamic CSS, make a little CDATA block out of it.
896 if ( !empty($sitecss) ||
!empty($usercss) ) {
897 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
899 wfProfileOut( $fname );
905 function setupUserJs() {
906 $fname = 'SkinTemplate::setupUserJs';
907 wfProfileIn( $fname );
909 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
910 $action = $wgRequest->getText('action');
912 if( $wgAllowUserJs && $this->loggedin
) {
913 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
914 # XXX: additional security check/prompt?
915 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
917 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
920 wfProfileOut( $fname );
924 * returns css with user-specific options
928 function getUserStylesheet() {
929 $fname = 'SkinTemplate::getUserStylesheet';
930 wfProfileIn( $fname );
933 $s = "/* generated user stylesheet */\n";
934 $s .= $this->reallyDoGetUserStyles();
935 wfProfileOut( $fname );
942 function getUserJs() {
943 $fname = 'SkinTemplate::getUserJs';
944 wfProfileIn( $fname );
947 $s = '/* generated javascript */';
948 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
949 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
951 // avoid inclusion of non defined user JavaScript (with custom skins only)
952 // by checking for default message content
953 $msgKey = ucfirst($this->skinname
).'.js';
954 $userJS = wfMsg($msgKey);
955 if ('<'.$msgKey.'>' != $userJS) {
959 wfProfileOut( $fname );
965 * Generic wrapper for template functions, with interface
966 * compatible with what we use of PHPTAL 0.7.
970 class QuickTemplate
{
974 function QuickTemplate() {
975 $this->data
= array();
976 $this->translator
= new MediaWiki_I18N();
982 function set( $name, $value ) {
983 $this->data
[$name] = $value;
989 function setRef($name, &$value) {
990 $this->data
[$name] =& $value;
996 function setTranslator( &$t ) {
997 $this->translator
= &$t;
1003 function execute() {
1004 echo "Override this function.";
1011 function text( $str ) {
1012 echo htmlspecialchars( $this->data
[$str] );
1018 function html( $str ) {
1019 echo $this->data
[$str];
1025 function msg( $str ) {
1026 echo htmlspecialchars( $this->translator
->translate( $str ) );
1032 function msgHtml( $str ) {
1033 echo $this->translator
->translate( $str );
1037 * An ugly, ugly hack.
1040 function msgWiki( $str ) {
1041 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1043 $text = $this->translator
->translate( $str );
1044 $parserOutput = $wgParser->parse( $text, $wgTitle,
1045 $wgOut->mParserOptions
, true );
1046 echo $parserOutput->getText();
1052 function haveData( $str ) {
1053 return $this->data
[$str];
1059 function haveMsg( $str ) {
1060 $msg = $this->translator
->translate( $str );
1061 return ($msg != '-') && ($msg != ''); # ????
1065 } // end of if( defined( 'MEDIAWIKI' ) )