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, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
160 $tpl =& $this->setupTemplate( $this->template
, 'skins' );
162 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
163 $tpl->setTranslator(new MediaWiki_I18N());
165 wfProfileOut( "$fname-init" );
167 wfProfileIn( "$fname-stuff" );
168 $this->thispage
= $wgTitle->getPrefixedDbKey();
169 $this->thisurl
= $wgTitle->getPrefixedURL();
170 $this->loggedin
= $wgUser->getID() != 0;
171 $this->iscontent
= ($wgTitle->getNamespace() != Namespace::getSpecial() );
172 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
173 $this->username
= $wgUser->getName();
174 $this->userpage
= $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
175 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
177 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
178 $this->setupUserCss();
179 $this->setupUserJs();
180 $this->titletxt
= $wgTitle->getPrefixedText();
181 wfProfileOut( "$fname-stuff" );
183 wfProfileIn( "$fname-stuff2" );
184 $tpl->set( 'title', $wgOut->getPageTitle() );
185 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
187 $tpl->setRef( "thispage", $this->thispage
);
188 $subpagestr = $this->subPageSubtitle();
190 'subtitle', !empty($subpagestr)?
191 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
194 $undelete = $this->getUndeleteLink();
196 "undelete", !empty($undelete)?
197 '<span class="subpages">'.$undelete.'</span>':
201 $tpl->set( 'catlinks', $this->getCategories());
202 if( $wgOut->isSyndicated() ) {
204 foreach( $wgFeedClasses as $format => $class ) {
205 $feeds[$format] = array(
207 'href' => $wgRequest->appendQuery( "feed=$format" ),
208 'ttip' => wfMsg('tooltip-'.$format)
211 $tpl->setRef( 'feeds', $feeds );
213 $tpl->set( 'feeds', false );
215 $tpl->setRef( 'mimetype', $wgMimeType );
216 $tpl->setRef( 'charset', $wgOutputEncoding );
217 $tpl->set( 'headlinks', $out->getHeadLinks() );
218 $tpl->setRef( 'wgScript', $wgScript );
219 $tpl->setRef( 'skinname', $this->skinname
);
220 $tpl->setRef( 'stylename', $this->stylename
);
221 $tpl->setRef( 'loggedin', $this->loggedin
);
222 $tpl->set('nsclass', 'ns-'.$wgTitle->getNamespace());
223 $tpl->set('notspecialpage', $wgTitle->getNamespace() != NS_SPECIAL
);
224 /* XXX currently unused, might get useful later
225 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
226 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
227 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
228 $tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" );
229 $tpl->set( "helppage", wfMsg('helppage'));
231 $tpl->set( 'searchaction', $this->escapeSearchLink() );
232 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
233 $tpl->setRef( 'stylepath', $wgStylePath );
234 $tpl->setRef( 'logopath', $wgLogo );
235 $tpl->setRef( "lang", $wgContLanguageCode );
236 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
237 $tpl->set( 'rtl', $wgContLang->isRTL() );
238 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
239 $tpl->setRef( 'username', $this->username
);
240 $tpl->setRef( 'userpage', $this->userpage
);
241 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
242 $tpl->setRef( 'usercss', $this->usercss
);
243 $tpl->setRef( 'userjs', $this->userjs
);
244 $tpl->setRef( 'userjsprev', $this->userjsprev
);
247 if($this->loggedin
) {
248 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
250 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
253 $tpl->set('jsvarurl', false);
255 if( $wgUser->getNewtalk() ) {
256 $usertitle = Title
::newFromText( $this->userpage
);
257 $usertalktitle = $usertitle->getTalkPage();
258 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
260 $ntl = wfMsg( 'newmessages',
261 $this->makeKnownLink(
262 $wgContLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
263 . ':' . $this->username
,
264 wfMsg('newmessageslink') )
267 $wgOut->setSquidMaxage(0);
272 wfProfileOut( "$fname-stuff2" );
274 wfProfileIn( "$fname-stuff3" );
275 $tpl->setRef( 'newtalk', $ntl );
276 $tpl->setRef( 'skin', $this);
277 $tpl->set( 'logo', $this->logoText() );
278 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
279 if ( !$wgDisableCounters ) {
280 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
282 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
284 $tpl->set('viewcount', false);
288 if ($wgPageShowWatchingUsers) {
289 $dbr =& wfGetDB( DB_SLAVE
);
290 extract( $dbr->tableNames( 'watchlist' ) );
291 $sql = "SELECT COUNT(*) AS n FROM $watchlist
292 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
293 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
294 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
295 $x = $dbr->fetchObject( $res );
296 $numberofwatchingusers = $x->n
;
297 if ($numberofwatchingusers > 0) {
298 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
300 $tpl->set('numberofwatchingusers', false);
303 $tpl->set('numberofwatchingusers', false);
306 $tpl->set('lastmod', $this->lastModified());
307 $tpl->set('copyright',$this->getCopyright());
309 $this->credits
= false;
311 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
312 require_once("Credits.php");
313 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
316 $tpl->setRef( 'credits', $this->credits
);
318 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
319 $tpl->set('copyright', $this->getCopyright());
320 $tpl->set('viewcount', false);
321 $tpl->set('lastmod', false);
322 $tpl->set('credits', false);
323 $tpl->set('numberofwatchingusers', false);
325 $tpl->set('copyright', false);
326 $tpl->set('viewcount', false);
327 $tpl->set('lastmod', false);
328 $tpl->set('credits', false);
329 $tpl->set('numberofwatchingusers', false);
331 wfProfileOut( "$fname-stuff3" );
333 wfProfileIn( "$fname-stuff4" );
334 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
335 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
336 $tpl->set( 'disclaimer', $this->disclaimerLink() );
337 $tpl->set( 'about', $this->aboutLink() );
339 $tpl->setRef( 'debug', $out->mDebugtext
);
340 $tpl->set( 'reporttime', $out->reportTime() );
341 $tpl->set( 'sitenotice', $wgSiteNotice );
342 $tpl->set( 'tagline', wfMsg('tagline') );
344 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
345 $out->mBodytext
.= $printfooter ;
346 $tpl->setRef( 'bodytext', $out->mBodytext
);
349 $language_urls = array();
350 foreach( $wgOut->getLanguageLinks() as $l ) {
351 $nt = Title
::newFromText( $l );
352 $language_urls[] = array('href' => $nt->getFullURL(),
353 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
354 'class' => $wgContLang->isRTL() ?
'rtl' : 'ltr');
356 if(count($language_urls)) {
357 $tpl->setRef( 'language_urls', $language_urls);
359 $tpl->set('language_urls', false);
361 wfProfileOut( "$fname-stuff4" );
364 $tpl->set('personal_urls', $this->buildPersonalUrls());
365 $content_actions = $this->buildContentActionUrls();
366 $tpl->setRef('content_actions', $content_actions);
368 // XXX: attach this from javascript, same with section editing
369 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
371 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
373 $tpl->set('body_ondblclick', false);
375 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
376 $tpl->set( 'nav_urls', $this->buildNavUrls() );
379 wfProfileIn( "$fname-execute" );
380 $res = $tpl->execute();
381 wfProfileOut( "$fname-execute" );
383 // result may be an error
384 $this->printOrError( $res );
385 wfProfileOut( $fname );
389 * Output the string, or print error message if it's
390 * an error object of the appropriate type.
391 * For the base class, assume strings all around.
396 function printOrError( &$str ) {
401 * build array of urls for personal toolbar
405 function buildPersonalUrls() {
406 $fname = 'SkinTemplate::buildPersonalUrls';
407 wfProfileIn( $fname );
409 /* set up the default links for the personal toolbar */
410 global $wgShowIPinHeader;
411 $personal_urls = array();
412 if ($this->loggedin
) {
413 /* Logged in users personal toolbar */
414 $personal_urls['userpage'] = array(
415 'text' => wfMsg('mypage'),
416 'href' => $this->makeSpecialUrl('Mypage')
418 $personal_urls['mytalk'] = array(
419 'text' => wfMsg('mytalk'),
420 'href' => $this->makeSpecialUrl('Mytalk')
422 $personal_urls['preferences'] = array(
423 'text' => wfMsg('preferences'),
424 'href' => $this->makeSpecialUrl('Preferences')
426 $personal_urls['watchlist'] = array(
427 'text' => wfMsg('watchlist'),
428 'href' => $this->makeSpecialUrl('Watchlist')
430 $personal_urls['mycontris'] = array(
431 'text' => wfMsg('mycontris'),
432 'href' => $this->makeSpecialUrl('Mycontributions')
434 $personal_urls['logout'] = array(
435 'text' => wfMsg('userlogout'),
436 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
)
439 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
440 /* Anonymous with session users personal toolbar */
441 $personal_urls['anonuserpage'] = array(
442 'text' => wfMsg('mypage'),
443 'href' => $this->makeSpecialUrl('Mypage')
445 $personal_urls['mytalk'] = array(
446 'text' => wfMsg('mytalk'),
447 'href' => $this->makeSpecialUrl('Mytalk')
450 $personal_urls['anonlogin'] = array(
451 'text' => wfMsg('userlogin'),
452 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
455 /* Anonymous users personal toolbar */
456 $personal_urls['login'] = array(
457 'text' => wfMsg('userlogin'),
458 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
)
462 wfProfileOut( $fname );
463 return $personal_urls;
467 * an array of edit links by default used for the tabs
471 function buildContentActionUrls () {
473 $fname = 'SkinTemplate::buildContentActionUrls';
474 wfProfileIn( $fname );
476 global $wgTitle, $wgUser, $wgRequest, $wgUseValidation;
477 $action = $wgRequest->getText( 'action' );
478 $section = $wgRequest->getText( 'section' );
479 $oldid = $wgRequest->getVal( 'oldid' );
480 $diff = $wgRequest->getVal( 'diff' );
481 $content_actions = array();
483 if( $this->iscontent
) {
485 $nskey = $this->getNameSpaceKey();
486 $is_active = !Namespace::isTalk( $wgTitle->getNamespace()) ;
487 if ( $action == 'validate' ) $is_active = false ; # Show article tab deselected when validating
489 $subjectTitle = $wgTitle->getSubjectPage();
490 if( $subjectTitle->getArticleId() != 0 ) {
491 $class = ($is_active) ?
'selected' : false;
493 $class = ($is_active) ?
'selected new' : 'new';
495 $content_actions[$nskey] = array('class' => $class,
496 'text' => wfMsg($nskey),
497 'href' => $this->makeArticleUrl($this->thispage
));
499 /* set up the classes for the talk link */
500 wfProfileIn( "$fname-talk" );
501 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : false);
502 $talktitle = $wgTitle->getTalkPage();
503 if( $talktitle->getArticleId() != 0 ) {
504 $content_actions['talk'] = array(
505 'class' => $talk_class,
506 'text' => wfMsg('talk'),
507 'href' => $talktitle->getLocalUrl()
510 $content_actions['talk'] = array(
511 'class' => $talk_class ?
$talk_class.' new' : 'new',
512 'text' => wfMsg('talk'),
513 'href' => $talktitle->getLocalUrl( 'action=edit' )
516 wfProfileOut( "$fname-talk" );
518 wfProfileIn( "$fname-edit" );
519 if ( $wgTitle->userCanEdit() ) {
520 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : false;
521 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
522 $istalkclass = $istalk?
' istalk':'';
523 $content_actions['edit'] = array(
524 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
525 'text' => wfMsg('edit'),
526 'href' => $wgTitle->getLocalUrl( 'action=edit'.$oid )
529 $content_actions['addsection'] = array(
530 'class' => $section == 'new'?
'selected':false,
531 'text' => wfMsg('addsection'),
532 'href' => $wgTitle->getLocalUrl( 'action=edit§ion=new' )
536 $oid = ( $oldid && ! isset( $diff ) ) ?
'&oldid='.IntVal( $oldid ) : '';
537 $content_actions['viewsource'] = array(
538 'class' => ($action == 'edit') ?
'selected' : false,
539 'text' => wfMsg('viewsource'),
540 'href' => $wgTitle->getLocalUrl( 'action=edit'.$oid )
543 wfProfileOut( "$fname-edit" );
545 wfProfileIn( "$fname-live" );
546 if ( $wgTitle->getArticleId() ) {
548 $content_actions['history'] = array(
549 'class' => ($action == 'history') ?
'selected' : false,
550 'text' => wfMsg('history_short'),
551 'href' => $wgTitle->getLocalUrl( 'action=history')
554 # XXX: is there a rollback action anywhere or is it planned?
555 # Don't recall where i got this from...
556 /*if( $wgUser->getNewtalk() ) {
557 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
558 'text' => wfMsg('rollback_short'),
559 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
560 'ttip' => wfMsg('tooltip-rollback'),
561 'akey' => wfMsg('accesskey-rollback'));
565 if($wgUser->isAllowed('protect')){
566 if(!$wgTitle->isProtected()){
567 $content_actions['protect'] = array(
568 'class' => ($action == 'protect') ?
'selected' : false,
569 'text' => wfMsg('protect'),
570 'href' => $wgTitle->getLocalUrl( 'action=protect' )
574 $content_actions['unprotect'] = array(
575 'class' => ($action == 'unprotect') ?
'selected' : false,
576 'text' => wfMsg('unprotect'),
577 'href' => $wgTitle->getLocalUrl( 'action=unprotect' )
581 if($wgUser->isAllowed('delete')){
582 $content_actions['delete'] = array(
583 'class' => ($action == 'delete') ?
'selected' : false,
584 'text' => wfMsg('delete'),
585 'href' => $wgTitle->getLocalUrl( 'action=delete' )
588 if ( $wgUser->getID() != 0 ) {
589 if ( $wgTitle->userCanMove()) {
590 $content_actions['move'] = array(
591 'class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : false,
592 'text' => wfMsg('move'),
593 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage
) )
598 //article doesn't exist or is deleted
599 if($wgUser->isAllowed('delete')){
600 if( $n = $wgTitle->isDeleted() ) {
601 $content_actions['undelete'] = array(
603 'text' => wfMsg( "undelete_short", $n ),
604 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
)
609 wfProfileOut( "$fname-live" );
611 if ( $wgUser->getID() != 0 and $action != 'submit' ) {
612 if( !$wgTitle->userIsWatching()) {
613 $content_actions['watch'] = array(
614 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
615 'text' => wfMsg('watch'),
616 'href' => $wgTitle->getLocalUrl( 'action=watch' )
619 $content_actions['unwatch'] = array(
620 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
621 'text' => wfMsg('unwatch'),
622 'href' => $wgTitle->getLocalUrl( 'action=unwatch' )
628 if ( $wgUseValidation && $wgTitle->getArticleId() && $wgTitle->getNamespace() == 0 ) {
630 $article_time = "×tamp=" . $wgArticle->mTimestamp
;
631 $content_actions['validate'] = array(
632 'class' => ($action == 'validate') ?
'selected' : false ,
633 'text' => wfMsg('val_tab'),
634 'href' => $wgTitle->getLocalUrl( 'action=validate'.$article_time)
639 /* show special page tab */
641 $content_actions['article'] = array(
642 'class' => 'selected',
643 'text' => wfMsg('specialpage'),
648 /* show links to different language variants */
649 global $wgDisableLangConversion;
650 $variants = $wgContLang->getVariants();
651 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
652 $preferred = $wgContLang->getPreferredVariant();
655 $actstr = 'action=' . $action . '&';
657 foreach( $variants as $code ) {
658 $varname = $wgContLang->getVariantname( $code );
659 if( $varname == 'disable' )
661 $selected = ( $code == $preferred )?
'selected' : false;
662 $content_actions['varlang-' . $vcount] = array(
663 'class' => $selected,
665 'href' => $wgTitle->getLocalUrl( $actstr . 'variant=' . $code )
671 wfProfileOut( $fname );
672 return $content_actions;
676 * build array of global navigation links
680 function buildNavigationUrls () {
681 $fname = 'SkinTemplate::buildNavigationUrls';
682 wfProfileIn( $fname );
684 global $wgNavigationLinks;
686 foreach ( $wgNavigationLinks as $link ) {
687 $text = wfMsg( $link['text'] );
688 wfProfileIn( "$fname-{$link['text']}" );
690 $dest = wfMsgForContent( $link['href'] );
691 wfProfileIn( "$fname-{$link['text']}2" );
694 'href' => $this->makeInternalOrExternalUrl( $dest ),
695 'id' => 'n-'.$link['text']
697 wfProfileOut( "$fname-{$link['text']}2" );
699 wfProfileOut( "$fname-{$link['text']}" );
701 wfProfileOut( $fname );
706 * build array of common navigation links
710 function buildNavUrls () {
711 $fname = 'SkinTemplate::buildNavUrls';
712 wfProfileIn( $fname );
714 global $wgTitle, $wgUser, $wgRequest;
715 global $wgSiteSupportPage, $wgDisableUploads;
717 $action = $wgRequest->getText( 'action' );
718 $oldid = $wgRequest->getVal( 'oldid' );
719 $diff = $wgRequest->getVal( 'diff' );
722 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
723 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
724 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
725 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ?
array('href' => $this->makeI18nUrl('currentevents')) : false;
726 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ?
array('href' => $this->makeI18nUrl('portal-url')) : false;
727 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
728 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
729 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
730 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
731 if( $this->loggedin
&& !$wgDisableUploads ) {
732 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
734 $nav_urls['upload'] = false;
736 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
738 if( $wgTitle->getNamespace() != NS_SPECIAL
) {
739 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage
)));
740 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage
)));
743 if( $wgTitle->getNamespace() == NS_USER ||
$wgTitle->getNamespace() == NS_USER_TALK
) {
744 $id = User
::idFromName($wgTitle->getText());
745 $ip = User
::isIP($wgTitle->getText());
751 if($id ||
$ip) { # both anons and non-anons have contri list
752 $nav_urls['contributions'] = array(
753 'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
756 $nav_urls['contributions'] = false;
758 $nav_urls['emailuser'] = false;
759 if( $this->showEmailUser( $id ) ) {
760 $nav_urls['emailuser'] = array(
761 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
764 wfProfileOut( $fname );
769 * Generate strings used for xml 'id' names
773 function getNameSpaceKey () {
775 switch ($wgTitle->getNamespace()) {
783 return 'nstab-media';
785 return 'nstab-special';
787 case NS_PROJECT_TALK
:
791 return 'nstab-image';
793 case NS_MEDIAWIKI_TALK
:
794 return 'nstab-mediawiki';
796 case NS_TEMPLATE_TALK
:
797 return 'nstab-template';
802 case NS_CATEGORY_TALK
:
803 return 'nstab-category';
812 function setupUserCss() {
813 $fname = 'SkinTemplate::setupUserCss';
814 wfProfileIn( $fname );
816 global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
820 $siteargs = '&maxage=' . $wgSquidMaxage;
822 # Add user-specific code if this is a user and we allow that kind of thing
824 if ( $wgAllowUserCss && $this->loggedin
) {
825 $action = $wgRequest->getText('action');
827 # if we're previewing the CSS page, use it
828 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
829 $siteargs = "&smaxage=0&maxage=0";
830 $usercss = $wgRequest->getText('wpTextbox1');
832 $usercss = '@import "' .
833 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
834 'action=raw&ctype=text/css') . '";' ."\n";
837 $siteargs .= '&ts=' . $wgUser->mTouched
;
840 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
842 # If we use the site's dynamic CSS, throw that in, too
843 if ( $wgUseSiteCss ) {
844 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI
) . '";' . "\n";
845 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
848 # If we use any dynamic CSS, make a little CDATA block out of it.
850 if ( !empty($sitecss) ||
!empty($usercss) ) {
851 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
853 wfProfileOut( $fname );
859 function setupUserJs() {
860 $fname = 'SkinTemplate::setupUserJs';
861 wfProfileIn( $fname );
863 global $wgRequest, $wgTitle, $wgAllowUserJs;
864 $action = $wgRequest->getText('action');
866 if( $wgAllowUserJs && $this->loggedin
) {
867 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
868 # XXX: additional security check/prompt?
869 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
871 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
874 wfProfileOut( $fname );
878 * returns css with user-specific options
881 function getUserStylesheet() {
882 $fname = 'SkinTemplate::getUserStylesheet';
883 wfProfileIn( $fname );
886 $s = "/* generated user stylesheet */\n";
888 if($wgUser->getID() != 0) {
889 if ( 1 == $wgUser->getOption( "underline" ) ) {
890 $s .= "a { text-decoration: underline; }\n";
892 $s .= "a { text-decoration: none; }\n";
895 if ( 1 != $wgUser->getOption( "highlightbroken" ) ) {
896 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
898 if ( 1 == $wgUser->getOption( "justify" ) ) {
899 $s .= "#bodyContent { text-align: justify; }\n";
901 wfProfileOut( $fname );
908 function getUserJs() {
909 $fname = 'SkinTemplate::getUserJs';
910 wfProfileIn( $fname );
912 global $wgUser, $wgStylePath;
913 $s = '/* generated javascript */';
914 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
915 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
916 $s .= wfMsg(ucfirst($this->skinname
).'.js');
918 wfProfileOut( $fname );
924 * Generic wrapper for template functions, with interface
925 * compatible with what we use of PHPTAL 0.7.
929 class QuickTemplate
{
933 function QuickTemplate() {
934 $this->data
= array();
935 $this->translator
= new MediaWiki_I18N();
941 function set( $name, $value ) {
942 $this->data
[$name] = $value;
948 function setRef($name, &$value) {
949 $this->data
[$name] =& $value;
955 function setTranslator( &$t ) {
956 $this->translator
= &$t;
963 echo "Override this function.";
970 function text( $str ) {
971 echo htmlspecialchars( $this->data
[$str] );
977 function html( $str ) {
978 echo $this->data
[$str];
984 function msg( $str ) {
985 echo htmlspecialchars( $this->translator
->translate( $str ) );
991 function msgHtml( $str ) {
992 echo $this->translator
->translate( $str );
996 * An ugly, ugly hack.
999 function msgWiki( $str ) {
1000 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1002 $text = $this->translator
->translate( $str );
1003 $parserOutput = $wgParser->parse( $text, $wgTitle,
1004 $wgOut->mParserOptions
, true );
1005 echo $parserOutput->getText();
1011 function haveData( $str ) {
1012 return $this->data
[$str];
1018 function haveMsg( $str ) {
1019 $msg = $this->translator
->translate( $str );
1020 return ($msg != '-') && ($msg != ''); # ????
1024 } // end of if( defined( 'MEDIAWIKI' ) )