2 if ( ! defined( 'MEDIAWIKI' ) )
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
34 require_once 'GlobalFunctions.php';
37 * Wrapper object for MediaWiki's localization functions,
38 * to be passed to the template engine.
43 class MediaWiki_I18N
{
44 var $_context = array();
46 function set($varName, $value) {
47 $this->_context
[$varName] = $value;
50 function translate($value) {
51 $fname = 'SkinTemplate-translate';
52 wfProfileIn( $fname );
54 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
55 $value = preg_replace( '/^string:/', '', $value );
57 $value = wfMsg( $value );
58 // interpolate variables
59 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
60 list($src, $var) = $m;
62 $varValue = $this->_context
[$var];
64 $value = str_replace($src, $varValue, $value);
66 wfProfileOut( $fname );
75 class SkinTemplate
extends Skin
{
81 * Name of our skin, set in initPage()
82 * It probably need to be all lower case.
87 * Stylesheets set to use
88 * Sub directory in ./skins/ where various stylesheets are located
93 * For QuickTemplate, the name of the subclass which
94 * will actually fill the template.
101 * Setup the base parameters...
102 * Child classes should override this to set the name,
103 * style subdirectory, and template filler callback.
105 * @param OutputPage $out
107 function initPage( &$out ) {
108 parent
::initPage( $out );
109 $this->skinname
= 'monobook';
110 $this->stylename
= 'monobook';
111 $this->template
= 'QuickTemplate';
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
119 * @param string $callback (or file)
120 * @param string $repository subdirectory where we keep template files
121 * @param string $cache_dir
125 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
126 return new $classname();
130 * initialize various variables and generate the template
132 * @param OutputPage $out
135 function outputPage( &$out ) {
136 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
137 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode;
138 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
139 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks;
145 $fname = 'SkinTemplate::outputPage';
146 wfProfileIn( $fname );
148 // Hook that allows last minute changes to the output page, e.g.
149 // adding of CSS or Javascript by extensions.
150 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
152 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
154 wfProfileIn( "$fname-init" );
155 $this->initPage( $out );
157 $this->mTitle
=& $wgTitle;
158 $this->mUser
=& $wgUser;
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
= $this->mTitle
->getPrefixedDbKey();
169 $this->thisurl
= $this->mTitle
->getPrefixedURL();
170 $this->loggedin
= $wgUser->isLoggedIn();
171 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
172 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
173 $this->username
= $wgUser->getName();
174 $userPage = $wgUser->getUserPage();
175 $this->userpage
= $userPage->getPrefixedText();
177 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
178 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
180 # This won't be used in the standard skins, but we define it to preserve the interface
181 # To save time, we check for existence
182 $this->userpageUrlDetails
= $this->makeKnownUrlDetails($this->userpage
);
185 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
186 $this->setupUserCss();
187 $this->setupUserJs();
188 $this->titletxt
= $this->mTitle
->getPrefixedText();
189 wfProfileOut( "$fname-stuff" );
191 wfProfileIn( "$fname-stuff2" );
192 $tpl->set( 'title', $wgOut->getPageTitle() );
193 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
194 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
196 $tpl->setRef( "thispage", $this->thispage
);
197 $subpagestr = $this->subPageSubtitle();
199 'subtitle', !empty($subpagestr)?
200 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
203 $undelete = $this->getUndeleteLink();
205 "undelete", !empty($undelete)?
206 '<span class="subpages">'.$undelete.'</span>':
210 $tpl->set( 'catlinks', $this->getCategories());
211 if( $wgOut->isSyndicated() ) {
213 foreach( $wgFeedClasses as $format => $class ) {
214 $feeds[$format] = array(
216 'href' => $wgRequest->appendQuery( "feed=$format" )
219 $tpl->setRef( 'feeds', $feeds );
221 $tpl->set( 'feeds', false );
223 if ($wgUseTrackbacks && $out->isArticleRelated())
224 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
226 $tpl->setRef( 'mimetype', $wgMimeType );
227 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
228 $tpl->setRef( 'charset', $wgOutputEncoding );
229 $tpl->set( 'headlinks', $out->getHeadLinks() );
230 $tpl->set('headscripts', $out->getScript() );
231 $tpl->setRef( 'wgScript', $wgScript );
232 $tpl->setRef( 'skinname', $this->skinname
);
233 $tpl->setRef( 'stylename', $this->stylename
);
234 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
235 $tpl->setRef( 'loggedin', $this->loggedin
);
236 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
237 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
238 /* XXX currently unused, might get useful later
239 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
240 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
241 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
242 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
243 $tpl->set( "helppage", wfMsg('helppage'));
245 $tpl->set( 'searchaction', $this->escapeSearchLink() );
246 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
247 $tpl->setRef( 'stylepath', $wgStylePath );
248 $tpl->setRef( 'logopath', $wgLogo );
249 $tpl->setRef( "lang", $wgContLanguageCode );
250 $tpl->setRef( 'uselang', $wgLanguageCode );
251 $tpl->set( 'dir', $wgLang->isRTL() ?
"rtl" : "ltr" );
252 $tpl->set( 'rtl', $wgLang->isRTL() );
253 /* display, if needed, dir=ltr or dir=rtl for the
254 firstHeading title. This is when the title is
255 content, eg a site-localized string;
256 that is the case for all the pages not in Special:
257 when action is view or history
259 $tpl->set( 'titledir',
260 ($this->mTitle
->getNamespace() != NS_SPECIAL
&&
261 ($action == 'view' ||
$action == 'history')) ?
264 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
265 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
266 $tpl->setRef( 'username', $this->username
);
267 $tpl->setRef( 'userpage', $this->userpage
);
268 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
269 $tpl->set( 'pagecss', $this->setupPageCss() );
270 $tpl->setRef( 'usercss', $this->usercss
);
271 $tpl->setRef( 'userjs', $this->userjs
);
272 $tpl->setRef( 'userjsprev', $this->userjsprev
);
275 if($this->loggedin
) {
276 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
278 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
281 $tpl->set('jsvarurl', false);
283 $newtalks = $wgUser->getNewMessageLinks();
285 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
286 $usertitle = $this->mUser
->getUserPage();
287 $usertalktitle = $usertitle->getTalkPage();
288 if( !$usertalktitle->equals( $this->mTitle
) ) {
289 $ntl = wfMsg( 'youhavenewmessages',
290 $this->makeKnownLinkObj(
292 wfMsgHtml( 'newmessageslink' ),
295 $this->makeKnownLinkObj(
297 wfMsgHtml( 'newmessagesdifflink' ),
302 $wgOut->setSquidMaxage(0);
304 } else if (count($newtalks)) {
305 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
307 foreach ($newtalks as $newtalk) {
308 $msgs[] = wfElement("a",
309 array('href' => $newtalk["link"]), $newtalk["wiki"]);
311 $parts = implode($sep, $msgs);
312 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
313 $wgOut->setSquidMaxage(0);
317 wfProfileOut( "$fname-stuff2" );
319 wfProfileIn( "$fname-stuff3" );
320 $tpl->setRef( 'newtalk', $ntl );
321 $tpl->setRef( 'skin', $this);
322 $tpl->set( 'logo', $this->logoText() );
323 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
324 if ( !$wgDisableCounters ) {
325 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
327 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
329 $tpl->set('viewcount', false);
332 $tpl->set('viewcount', false);
335 if ($wgPageShowWatchingUsers) {
336 $dbr =& wfGetDB( DB_SLAVE
);
337 extract( $dbr->tableNames( 'watchlist' ) );
338 $sql = "SELECT COUNT(*) AS n FROM $watchlist
339 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
340 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
341 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
342 $x = $dbr->fetchObject( $res );
343 $numberofwatchingusers = $x->n
;
344 if ($numberofwatchingusers > 0) {
345 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
347 $tpl->set('numberofwatchingusers', false);
350 $tpl->set('numberofwatchingusers', false);
353 $tpl->set('copyright',$this->getCopyright());
355 $this->credits
= false;
357 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
358 require_once("Credits.php");
359 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
361 $tpl->set('lastmod', $this->lastModified());
364 $tpl->setRef( 'credits', $this->credits
);
366 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
367 $tpl->set('copyright', $this->getCopyright());
368 $tpl->set('viewcount', false);
369 $tpl->set('lastmod', false);
370 $tpl->set('credits', false);
371 $tpl->set('numberofwatchingusers', false);
373 $tpl->set('copyright', false);
374 $tpl->set('viewcount', false);
375 $tpl->set('lastmod', false);
376 $tpl->set('credits', false);
377 $tpl->set('numberofwatchingusers', false);
379 wfProfileOut( "$fname-stuff3" );
381 wfProfileIn( "$fname-stuff4" );
382 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
383 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
384 $tpl->set( 'disclaimer', $this->disclaimerLink() );
385 $tpl->set( 'privacy', $this->privacyLink() );
386 $tpl->set( 'about', $this->aboutLink() );
388 $tpl->setRef( 'debug', $out->mDebugtext
);
389 $tpl->set( 'reporttime', $out->reportTime() );
390 $tpl->set( 'sitenotice', wfGetSiteNotice() );
392 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
393 $out->mBodytext
.= $printfooter ;
394 $tpl->setRef( 'bodytext', $out->mBodytext
);
397 $language_urls = array();
399 if ( !$wgHideInterlanguageLinks ) {
400 foreach( $wgOut->getLanguageLinks() as $l ) {
401 $tmp = explode( ':', $l, 2 );
402 $class = 'interwiki-' . $tmp[0];
404 $nt = Title
::newFromText( $l );
405 $language_urls[] = array(
406 'href' => $nt->getFullURL(),
407 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
412 if(count($language_urls)) {
413 $tpl->setRef( 'language_urls', $language_urls);
415 $tpl->set('language_urls', false);
417 wfProfileOut( "$fname-stuff4" );
420 $tpl->set('personal_urls', $this->buildPersonalUrls());
421 $content_actions = $this->buildContentActionUrls();
422 $tpl->setRef('content_actions', $content_actions);
424 // XXX: attach this from javascript, same with section editing
425 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
427 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
429 $tpl->set('body_ondblclick', false);
431 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
432 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
434 $tpl->set( 'body_onload', false );
436 $tpl->set( 'sidebar', $this->buildSidebar() );
437 $tpl->set( 'nav_urls', $this->buildNavUrls() );
440 wfProfileIn( "$fname-execute" );
441 $res = $tpl->execute();
442 wfProfileOut( "$fname-execute" );
444 // result may be an error
445 $this->printOrError( $res );
446 wfProfileOut( $fname );
450 * Output the string, or print error message if it's
451 * an error object of the appropriate type.
452 * For the base class, assume strings all around.
457 function printOrError( &$str ) {
462 * build array of urls for personal toolbar
466 function buildPersonalUrls() {
467 global $wgTitle, $wgShowIPinHeader;
469 $fname = 'SkinTemplate::buildPersonalUrls';
470 $pageurl = $wgTitle->getLocalURL();
471 wfProfileIn( $fname );
473 /* set up the default links for the personal toolbar */
474 $personal_urls = array();
475 if ($this->loggedin
) {
476 $personal_urls['userpage'] = array(
477 'text' => $this->username
,
478 'href' => &$this->userpageUrlDetails
['href'],
479 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
480 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
482 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
483 $personal_urls['mytalk'] = array(
484 'text' => wfMsg('mytalk'),
485 'href' => &$usertalkUrlDetails['href'],
486 'class' => $usertalkUrlDetails['exists']?
false:'new',
487 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
489 $href = $this->makeSpecialUrl('Preferences');
490 $personal_urls['preferences'] = array(
491 'text' => wfMsg('preferences'),
492 'href' => $this->makeSpecialUrl('Preferences'),
493 'active' => ( $href == $pageurl )
495 $href = $this->makeSpecialUrl('Watchlist');
496 $personal_urls['watchlist'] = array(
497 'text' => wfMsg('watchlist'),
499 'active' => ( $href == $pageurl )
501 $href = $this->makeSpecialUrl("Contributions/$this->username");
502 $personal_urls['mycontris'] = array(
503 'text' => wfMsg('mycontris'),
505 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
507 $personal_urls['logout'] = array(
508 'text' => wfMsg('userlogout'),
509 'href' => $this->makeSpecialUrl( 'Userlogout',
510 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
514 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
515 $href = &$this->userpageUrlDetails
['href'];
516 $personal_urls['anonuserpage'] = array(
517 'text' => $this->username
,
519 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
520 'active' => ( $pageurl == $href )
522 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
523 $href = &$usertalkUrlDetails['href'];
524 $personal_urls['anontalk'] = array(
525 'text' => wfMsg('anontalk'),
527 'class' => $usertalkUrlDetails['exists']?
false:'new',
528 'active' => ( $pageurl == $href )
530 $personal_urls['anonlogin'] = array(
531 'text' => wfMsg('userlogin'),
532 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
533 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
537 $personal_urls['login'] = array(
538 'text' => wfMsg('userlogin'),
539 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
540 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
545 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
546 wfProfileOut( $fname );
547 return $personal_urls;
551 * Returns true if the IP should be shown in the header
553 function showIPinHeader() {
554 global $wgShowIPinHeader;
555 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
558 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
561 $classes[] = 'selected';
563 if( $checkEdit && $title->getArticleId() == 0 ) {
565 $query = 'action=edit';
568 $text = wfMsg( $message );
569 if ( $text == "<$message>" ) {
571 $text = $wgContLang->getNsText( Namespace::getSubject( $title->getNamespace() ) );
575 'class' => implode( ' ', $classes ),
577 'href' => $title->getLocalUrl( $query ) );
580 function makeTalkUrlDetails( $name, $urlaction='' ) {
581 $title = Title
::newFromText( $name );
582 $title = $title->getTalkPage();
583 $this->checkTitle($title, $name);
585 'href' => $title->getLocalURL( $urlaction ),
586 'exists' => $title->getArticleID() != 0?
true:false
590 function makeArticleUrlDetails( $name, $urlaction='' ) {
591 $title = Title
::newFromText( $name );
592 $title= $title->getSubjectPage();
593 $this->checkTitle($title, $name);
595 'href' => $title->getLocalURL( $urlaction ),
596 'exists' => $title->getArticleID() != 0?
true:false
601 * an array of edit links by default used for the tabs
605 function buildContentActionUrls () {
606 global $wgContLang, $wgOut;
607 $fname = 'SkinTemplate::buildContentActionUrls';
608 wfProfileIn( $fname );
610 global $wgUser, $wgRequest;
611 $action = $wgRequest->getText( 'action' );
612 $section = $wgRequest->getText( 'section' );
613 $content_actions = array();
615 $prevent_active_tabs = false ;
616 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
618 if( $this->iscontent
) {
619 $subjpage = $this->mTitle
->getSubjectPage();
620 $talkpage = $this->mTitle
->getTalkPage();
622 $nskey = $this->mTitle
->getNamespaceKey();
623 $content_actions[$nskey] = $this->tabAction(
626 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
629 $content_actions['talk'] = $this->tabAction(
632 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
636 wfProfileIn( "$fname-edit" );
637 if ( $this->mTitle
->userCanEdit() ) {
638 $istalk = $this->mTitle
->isTalkPage();
639 $istalkclass = $istalk?
' istalk':'';
640 $content_actions['edit'] = array(
641 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
642 'text' => wfMsg('edit'),
643 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
646 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
647 $content_actions['addsection'] = array(
648 'class' => $section == 'new'?
'selected':false,
649 'text' => wfMsg('addsection'),
650 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
654 $content_actions['viewsource'] = array(
655 'class' => ($action == 'edit') ?
'selected' : false,
656 'text' => wfMsg('viewsource'),
657 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
660 wfProfileOut( "$fname-edit" );
662 wfProfileIn( "$fname-live" );
663 if ( $this->mTitle
->getArticleId() ) {
665 $content_actions['history'] = array(
666 'class' => ($action == 'history') ?
'selected' : false,
667 'text' => wfMsg('history_short'),
668 'href' => $this->mTitle
->getLocalUrl( 'action=history')
671 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
672 if(!$this->mTitle
->isProtected()){
673 $content_actions['protect'] = array(
674 'class' => ($action == 'protect') ?
'selected' : false,
675 'text' => wfMsg('protect'),
676 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
680 $content_actions['unprotect'] = array(
681 'class' => ($action == 'unprotect') ?
'selected' : false,
682 'text' => wfMsg('unprotect'),
683 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
687 if($wgUser->isAllowed('delete')){
688 $content_actions['delete'] = array(
689 'class' => ($action == 'delete') ?
'selected' : false,
690 'text' => wfMsg('delete'),
691 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
694 if ( $this->mTitle
->userCanMove()) {
695 $moveTitle = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
696 $content_actions['move'] = array(
697 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
698 'text' => wfMsg('move'),
699 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
703 //article doesn't exist or is deleted
704 if( $wgUser->isAllowed( 'delete' ) ) {
705 if( $n = $this->mTitle
->isDeleted() ) {
706 $undelTitle = Title
::makeTitle( NS_SPECIAL
, 'Undelete' );
707 $content_actions['undelete'] = array(
709 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
710 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
711 #'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
716 wfProfileOut( "$fname-live" );
718 if( $this->loggedin
) {
719 if( !$this->mTitle
->userIsWatching()) {
720 $content_actions['watch'] = array(
721 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
722 'text' => wfMsg('watch'),
723 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
726 $content_actions['unwatch'] = array(
727 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
728 'text' => wfMsg('unwatch'),
729 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
734 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
736 /* show special page tab */
738 $content_actions['article'] = array(
739 'class' => 'selected',
740 'text' => wfMsg('specialpage'),
741 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
744 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
747 /* show links to different language variants */
748 global $wgDisableLangConversion;
749 $variants = $wgContLang->getVariants();
750 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
751 $preferred = $wgContLang->getPreferredVariant();
754 $actstr = 'action=' . $action . '&';
756 foreach( $variants as $code ) {
757 $varname = $wgContLang->getVariantname( $code );
758 if( $varname == 'disable' )
760 $selected = ( $code == $preferred )?
'selected' : false;
761 $content_actions['varlang-' . $vcount] = array(
762 'class' => $selected,
764 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
770 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
772 wfProfileOut( $fname );
773 return $content_actions;
779 * build array of common navigation links
783 function buildNavUrls () {
784 global $wgUseTrackbacks, $wgTitle, $wgArticle;
786 $fname = 'SkinTemplate::buildNavUrls';
787 wfProfileIn( $fname );
789 global $wgUser, $wgRequest;
790 global $wgEnableUploads, $wgUploadNavigationUrl;
792 $action = $wgRequest->getText( 'action' );
793 $oldid = $wgRequest->getVal( 'oldid' );
794 $diff = $wgRequest->getVal( 'diff' );
797 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
798 if( $wgEnableUploads ) {
799 if ($wgUploadNavigationUrl) {
800 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
802 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
805 if ($wgUploadNavigationUrl)
806 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
808 $nav_urls['upload'] = false;
810 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
813 // A print stylesheet is attached to all pages, but nobody ever
814 // figures that out. :) Add a link...
815 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
816 $revid = $wgArticle->getLatest();
817 if ( !( $revid == 0 ) )
818 $nav_urls['print'] = array(
819 'text' => wfMsg( 'printableversion' ),
820 'href' => $wgRequest->appendQuery( 'printable=yes' )
823 // Also add a "permalink" while we're at it
825 $nav_urls['permalink'] = array(
826 'text' => wfMsg( 'permalink' ),
830 if ( !( $revid == 0 ) )
831 $nav_urls['permalink'] = array(
832 'text' => wfMsg( 'permalink' ),
833 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
837 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
840 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
841 $wlhTitle = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
842 $nav_urls['whatlinkshere'] = array(
843 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
845 if( $this->mTitle
->getArticleId() ) {
846 $rclTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchangeslinked' );
847 $nav_urls['recentchangeslinked'] = array(
848 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
851 if ($wgUseTrackbacks)
852 $nav_urls['trackbacklink'] = array(
853 'href' => $wgTitle->trackbackURL()
857 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
858 $id = User
::idFromName($this->mTitle
->getText());
859 $ip = User
::isIP($this->mTitle
->getText());
865 if($id ||
$ip) { # both anons and non-anons have contri list
866 $nav_urls['contributions'] = array(
867 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
869 if ( $wgUser->isAllowed( 'block' ) )
870 $nav_urls['blockip'] = array(
871 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
874 $nav_urls['contributions'] = false;
876 $nav_urls['emailuser'] = false;
877 if( $this->showEmailUser( $id ) ) {
878 $nav_urls['emailuser'] = array(
879 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
882 wfProfileOut( $fname );
887 * Generate strings used for xml 'id' names
891 function getNameSpaceKey () {
892 return $this->mTitle
->getNamespaceKey();
898 function setupUserCss() {
899 $fname = 'SkinTemplate::setupUserCss';
900 wfProfileIn( $fname );
902 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgLang, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
906 $siteargs = '&maxage=' . $wgSquidMaxage;
908 # Add user-specific code if this is a user and we allow that kind of thing
910 if ( $wgAllowUserCss && $this->loggedin
) {
911 $action = $wgRequest->getText('action');
913 # if we're previewing the CSS page, use it
914 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
915 $siteargs = "&smaxage=0&maxage=0";
916 $usercss = $wgRequest->getText('wpTextbox1');
918 $usercss = '@import "' .
919 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
920 'action=raw&ctype=text/css') . '";' ."\n";
923 $siteargs .= '&ts=' . $wgUser->mTouched
;
926 if ($wgLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
927 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/content_rtl.css";' . "\n";
929 # If we use the site's dynamic CSS, throw that in, too
930 if ( $wgUseSiteCss ) {
931 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
932 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
933 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
934 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
937 # If we use any dynamic CSS, make a little CDATA block out of it.
939 if ( !empty($sitecss) ||
!empty($usercss) ) {
940 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
942 wfProfileOut( $fname );
948 function setupUserJs() {
949 $fname = 'SkinTemplate::setupUserJs';
950 wfProfileIn( $fname );
952 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
953 $action = $wgRequest->getText('action');
955 if( $wgAllowUserJs && $this->loggedin
) {
956 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
957 # XXX: additional security check/prompt?
958 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
960 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
963 wfProfileOut( $fname );
967 * Code for extensions to hook into to provide per-page CSS, see
968 * extensions/PageCSS/PageCSS.php for an implementation of this.
972 function setupPageCss() {
973 $fname = 'SkinTemplate::setupPageCss';
974 wfProfileIn( $fname );
976 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
978 wfProfileOut( $fname );
983 * returns css with user-specific options
987 function getUserStylesheet() {
988 $fname = 'SkinTemplate::getUserStylesheet';
989 wfProfileIn( $fname );
991 $s = "/* generated user stylesheet */\n";
992 $s .= $this->reallyDoGetUserStyles();
993 wfProfileOut( $fname );
1000 function getUserJs() {
1001 $fname = 'SkinTemplate::getUserJs';
1002 wfProfileIn( $fname );
1004 global $wgStylePath;
1005 $s = '/* generated javascript */';
1006 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1007 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1009 // avoid inclusion of non defined user JavaScript (with custom skins only)
1010 // by checking for default message content
1011 $msgKey = ucfirst($this->skinname
).'.js';
1012 $userJS = wfMsg($msgKey);
1013 if ('<'.$msgKey.'>' != $userJS) {
1017 wfProfileOut( $fname );
1023 * Generic wrapper for template functions, with interface
1024 * compatible with what we use of PHPTAL 0.7.
1025 * @package MediaWiki
1028 class QuickTemplate
{
1032 function QuickTemplate() {
1033 $this->data
= array();
1034 $this->translator
= new MediaWiki_I18N();
1040 function set( $name, $value ) {
1041 $this->data
[$name] = $value;
1047 function setRef($name, &$value) {
1048 $this->data
[$name] =& $value;
1054 function setTranslator( &$t ) {
1055 $this->translator
= &$t;
1061 function execute() {
1062 echo "Override this function.";
1069 function text( $str ) {
1070 echo htmlspecialchars( $this->data
[$str] );
1076 function html( $str ) {
1077 echo $this->data
[$str];
1083 function msg( $str ) {
1084 echo htmlspecialchars( $this->translator
->translate( $str ) );
1090 function msgHtml( $str ) {
1091 echo $this->translator
->translate( $str );
1095 * An ugly, ugly hack.
1098 function msgWiki( $str ) {
1099 global $wgParser, $wgTitle, $wgOut;
1101 $text = $this->translator
->translate( $str );
1102 $parserOutput = $wgParser->parse( $text, $wgTitle,
1103 $wgOut->mParserOptions
, true );
1104 echo $parserOutput->getText();
1110 function haveData( $str ) {
1111 return $this->data
[$str];
1117 function haveMsg( $str ) {
1118 $msg = $this->translator
->translate( $str );
1119 return ($msg != '-') && ($msg != ''); # ????