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, $wgContLanguageCode;
138 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
139 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks;
144 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
146 $fname = 'SkinTemplate::outputPage';
147 wfProfileIn( $fname );
149 // Hook that allows last minute changes to the output page, e.g.
150 // adding of CSS or Javascript by extensions.
151 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
153 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
155 wfProfileIn( "$fname-init" );
156 $this->initPage( $out );
158 $this->mTitle
=& $wgTitle;
159 $this->mUser
=& $wgUser;
161 $tpl = $this->setupTemplate( $this->template
, 'skins' );
163 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
164 $tpl->setTranslator(new MediaWiki_I18N());
166 wfProfileOut( "$fname-init" );
168 wfProfileIn( "$fname-stuff" );
169 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
170 $this->thisurl
= $this->mTitle
->getPrefixedURL();
171 $this->loggedin
= $wgUser->isLoggedIn();
172 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
173 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
174 $this->username
= $wgUser->getName();
175 $userPage = $wgUser->getUserPage();
176 $this->userpage
= $userPage->getPrefixedText();
178 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
179 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
181 # This won't be used in the standard skins, but we define it to preserve the interface
182 # To save time, we check for existence
183 $this->userpageUrlDetails
= $this->makeKnownUrlDetails($this->userpage
);
186 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
187 $this->setupUserCss();
188 $this->setupUserJs();
189 $this->titletxt
= $this->mTitle
->getPrefixedText();
190 wfProfileOut( "$fname-stuff" );
192 wfProfileIn( "$fname-stuff2" );
193 $tpl->set( 'title', $wgOut->getPageTitle() );
194 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
195 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
197 $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ];
198 if ( $nsname === NULL ) $nsname = $this->mTitle
->getNsText();
200 $tpl->set( 'nscanonical', $nsname );
201 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
202 $tpl->set( 'titletext', $this->mTitle
->getText() );
203 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
205 $tpl->setRef( "thispage", $this->thispage
);
206 $subpagestr = $this->subPageSubtitle();
208 'subtitle', !empty($subpagestr)?
209 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
212 $undelete = $this->getUndeleteLink();
214 "undelete", !empty($undelete)?
215 '<span class="subpages">'.$undelete.'</span>':
219 $tpl->set( 'catlinks', $this->getCategories());
220 if( $wgOut->isSyndicated() ) {
222 foreach( $wgFeedClasses as $format => $class ) {
223 $feeds[$format] = array(
225 'href' => $wgRequest->appendQuery( "feed=$format" )
228 $tpl->setRef( 'feeds', $feeds );
230 $tpl->set( 'feeds', false );
232 if ($wgUseTrackbacks && $out->isArticleRelated())
233 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
235 $tpl->setRef( 'mimetype', $wgMimeType );
236 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
237 $tpl->setRef( 'charset', $wgOutputEncoding );
238 $tpl->set( 'headlinks', $out->getHeadLinks() );
239 $tpl->set('headscripts', $out->getScript() );
240 $tpl->setRef( 'wgScript', $wgScript );
241 $tpl->setRef( 'skinname', $this->skinname
);
242 $tpl->set( 'skinclass', get_class( $this ) );
243 $tpl->setRef( 'stylename', $this->stylename
);
244 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
245 $tpl->setRef( 'loggedin', $this->loggedin
);
246 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
247 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
248 /* XXX currently unused, might get useful later
249 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
250 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
251 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
252 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
253 $tpl->set( "helppage", wfMsg('helppage'));
255 $tpl->set( 'searchaction', $this->escapeSearchLink() );
256 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
257 $tpl->setRef( 'stylepath', $wgStylePath );
258 $tpl->setRef( 'articlepath', $wgArticlePath );
259 $tpl->setRef( 'scriptpath', $wgScriptPath );
260 $tpl->setRef( 'serverurl', $wgServer );
261 $tpl->setRef( 'logopath', $wgLogo );
262 $tpl->setRef( "lang", $wgContLanguageCode );
263 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
264 $tpl->set( 'rtl', $wgContLang->isRTL() );
265 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
266 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
267 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
268 $tpl->setRef( 'userpage', $this->userpage
);
269 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
270 $tpl->set( 'userlang', $wgLang->getCode() );
271 $tpl->set( 'pagecss', $this->setupPageCss() );
272 $tpl->setRef( 'usercss', $this->usercss
);
273 $tpl->setRef( 'userjs', $this->userjs
);
274 $tpl->setRef( 'userjsprev', $this->userjsprev
);
277 if($this->loggedin
) {
278 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
280 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
283 $tpl->set('jsvarurl', false);
285 $newtalks = $wgUser->getNewMessageLinks();
287 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
288 $usertitle = $this->mUser
->getUserPage();
289 $usertalktitle = $usertitle->getTalkPage();
290 if( !$usertalktitle->equals( $this->mTitle
) ) {
291 $ntl = wfMsg( 'youhavenewmessages',
292 $this->makeKnownLinkObj(
294 wfMsgHtml( 'newmessageslink' ),
297 $this->makeKnownLinkObj(
299 wfMsgHtml( 'newmessagesdifflink' ),
304 $wgOut->setSquidMaxage(0);
306 } else if (count($newtalks)) {
307 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
309 foreach ($newtalks as $newtalk) {
310 $msgs[] = wfElement("a",
311 array('href' => $newtalk["link"]), $newtalk["wiki"]);
313 $parts = implode($sep, $msgs);
314 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
315 $wgOut->setSquidMaxage(0);
319 wfProfileOut( "$fname-stuff2" );
321 wfProfileIn( "$fname-stuff3" );
322 $tpl->setRef( 'newtalk', $ntl );
323 $tpl->setRef( 'skin', $this);
324 $tpl->set( 'logo', $this->logoText() );
325 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
326 if ( !$wgDisableCounters ) {
327 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
329 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
331 $tpl->set('viewcount', false);
334 $tpl->set('viewcount', false);
337 if ($wgPageShowWatchingUsers) {
338 $dbr =& wfGetDB( DB_SLAVE
);
339 extract( $dbr->tableNames( 'watchlist' ) );
340 $sql = "SELECT COUNT(*) AS n FROM $watchlist
341 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
342 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
343 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
344 $x = $dbr->fetchObject( $res );
345 $numberofwatchingusers = $x->n
;
346 if ($numberofwatchingusers > 0) {
347 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
349 $tpl->set('numberofwatchingusers', false);
352 $tpl->set('numberofwatchingusers', false);
355 $tpl->set('copyright',$this->getCopyright());
357 $this->credits
= false;
359 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
360 require_once("Credits.php");
361 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
363 $tpl->set('lastmod', $this->lastModified());
366 $tpl->setRef( 'credits', $this->credits
);
368 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
369 $tpl->set('copyright', $this->getCopyright());
370 $tpl->set('viewcount', false);
371 $tpl->set('lastmod', false);
372 $tpl->set('credits', false);
373 $tpl->set('numberofwatchingusers', false);
375 $tpl->set('copyright', false);
376 $tpl->set('viewcount', false);
377 $tpl->set('lastmod', false);
378 $tpl->set('credits', false);
379 $tpl->set('numberofwatchingusers', false);
381 wfProfileOut( "$fname-stuff3" );
383 wfProfileIn( "$fname-stuff4" );
384 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
385 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
386 $tpl->set( 'disclaimer', $this->disclaimerLink() );
387 $tpl->set( 'privacy', $this->privacyLink() );
388 $tpl->set( 'about', $this->aboutLink() );
390 $tpl->setRef( 'debug', $out->mDebugtext
);
391 $tpl->set( 'reporttime', $out->reportTime() );
392 $tpl->set( 'sitenotice', wfGetSiteNotice() );
393 $tpl->set( 'bottomscripts', $this->bottomScripts() );
395 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
396 $out->mBodytext
.= $printfooter ;
397 $tpl->setRef( 'bodytext', $out->mBodytext
);
400 $language_urls = array();
402 if ( !$wgHideInterlanguageLinks ) {
403 foreach( $wgOut->getLanguageLinks() as $l ) {
404 $tmp = explode( ':', $l, 2 );
405 $class = 'interwiki-' . $tmp[0];
407 $nt = Title
::newFromText( $l );
408 $language_urls[] = array(
409 'href' => $nt->getFullURL(),
410 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
415 if(count($language_urls)) {
416 $tpl->setRef( 'language_urls', $language_urls);
418 $tpl->set('language_urls', false);
420 wfProfileOut( "$fname-stuff4" );
423 $tpl->set('personal_urls', $this->buildPersonalUrls());
424 $content_actions = $this->buildContentActionUrls();
425 $tpl->setRef('content_actions', $content_actions);
427 // XXX: attach this from javascript, same with section editing
428 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
430 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
432 $tpl->set('body_ondblclick', false);
434 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
435 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
437 $tpl->set( 'body_onload', false );
439 $tpl->set( 'sidebar', $this->buildSidebar() );
440 $tpl->set( 'nav_urls', $this->buildNavUrls() );
443 wfProfileIn( "$fname-execute" );
444 $res = $tpl->execute();
445 wfProfileOut( "$fname-execute" );
447 // result may be an error
448 $this->printOrError( $res );
449 wfProfileOut( $fname );
453 * Output the string, or print error message if it's
454 * an error object of the appropriate type.
455 * For the base class, assume strings all around.
460 function printOrError( &$str ) {
465 * build array of urls for personal toolbar
469 function buildPersonalUrls() {
470 global $wgTitle, $wgShowIPinHeader;
472 $fname = 'SkinTemplate::buildPersonalUrls';
473 $pageurl = $wgTitle->getLocalURL();
474 wfProfileIn( $fname );
476 /* set up the default links for the personal toolbar */
477 $personal_urls = array();
478 if ($this->loggedin
) {
479 $personal_urls['userpage'] = array(
480 'text' => $this->username
,
481 'href' => &$this->userpageUrlDetails
['href'],
482 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
483 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
485 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
486 $personal_urls['mytalk'] = array(
487 'text' => wfMsg('mytalk'),
488 'href' => &$usertalkUrlDetails['href'],
489 'class' => $usertalkUrlDetails['exists']?
false:'new',
490 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
492 $href = $this->makeSpecialUrl('Preferences');
493 $personal_urls['preferences'] = array(
494 'text' => wfMsg('preferences'),
495 'href' => $this->makeSpecialUrl('Preferences'),
496 'active' => ( $href == $pageurl )
498 $href = $this->makeSpecialUrl('Watchlist');
499 $personal_urls['watchlist'] = array(
500 'text' => wfMsg('watchlist'),
502 'active' => ( $href == $pageurl )
504 $href = $this->makeSpecialUrl("Contributions/$this->username");
505 $personal_urls['mycontris'] = array(
506 'text' => wfMsg('mycontris'),
508 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
510 $personal_urls['logout'] = array(
511 'text' => wfMsg('userlogout'),
512 'href' => $this->makeSpecialUrl( 'Userlogout',
513 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
517 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
518 $href = &$this->userpageUrlDetails
['href'];
519 $personal_urls['anonuserpage'] = array(
520 'text' => $this->username
,
522 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
523 'active' => ( $pageurl == $href )
525 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
526 $href = &$usertalkUrlDetails['href'];
527 $personal_urls['anontalk'] = array(
528 'text' => wfMsg('anontalk'),
530 'class' => $usertalkUrlDetails['exists']?
false:'new',
531 'active' => ( $pageurl == $href )
533 $personal_urls['anonlogin'] = array(
534 'text' => wfMsg('userlogin'),
535 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
536 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
540 $personal_urls['login'] = array(
541 'text' => wfMsg('userlogin'),
542 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
543 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
548 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
549 wfProfileOut( $fname );
550 return $personal_urls;
554 * Returns true if the IP should be shown in the header
556 function showIPinHeader() {
557 global $wgShowIPinHeader;
558 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
561 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
564 $classes[] = 'selected';
566 if( $checkEdit && $title->getArticleId() == 0 ) {
568 $query = 'action=edit';
571 $text = wfMsg( $message );
572 if ( $text == "<$message>" ) {
574 $text = $wgContLang->getNsText( Namespace::getSubject( $title->getNamespace() ) );
578 'class' => implode( ' ', $classes ),
580 'href' => $title->getLocalUrl( $query ) );
583 function makeTalkUrlDetails( $name, $urlaction='' ) {
584 $title = Title
::newFromText( $name );
585 $title = $title->getTalkPage();
586 $this->checkTitle($title, $name);
588 'href' => $title->getLocalURL( $urlaction ),
589 'exists' => $title->getArticleID() != 0?
true:false
593 function makeArticleUrlDetails( $name, $urlaction='' ) {
594 $title = Title
::newFromText( $name );
595 $title= $title->getSubjectPage();
596 $this->checkTitle($title, $name);
598 'href' => $title->getLocalURL( $urlaction ),
599 'exists' => $title->getArticleID() != 0?
true:false
604 * an array of edit links by default used for the tabs
608 function buildContentActionUrls () {
609 global $wgContLang, $wgOut;
610 $fname = 'SkinTemplate::buildContentActionUrls';
611 wfProfileIn( $fname );
613 global $wgUser, $wgRequest;
614 $action = $wgRequest->getText( 'action' );
615 $section = $wgRequest->getText( 'section' );
616 $content_actions = array();
618 $prevent_active_tabs = false ;
619 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
621 if( $this->iscontent
) {
622 $subjpage = $this->mTitle
->getSubjectPage();
623 $talkpage = $this->mTitle
->getTalkPage();
625 $nskey = $this->mTitle
->getNamespaceKey();
626 $content_actions[$nskey] = $this->tabAction(
629 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
632 $content_actions['talk'] = $this->tabAction(
635 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
639 wfProfileIn( "$fname-edit" );
640 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
641 $istalk = $this->mTitle
->isTalkPage();
642 $istalkclass = $istalk?
' istalk':'';
643 $content_actions['edit'] = array(
644 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
645 'text' => wfMsg('edit'),
646 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
649 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
650 $content_actions['addsection'] = array(
651 'class' => $section == 'new'?
'selected':false,
652 'text' => wfMsg('addsection'),
653 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
657 $content_actions['viewsource'] = array(
658 'class' => ($action == 'edit') ?
'selected' : false,
659 'text' => wfMsg('viewsource'),
660 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
663 wfProfileOut( "$fname-edit" );
665 wfProfileIn( "$fname-live" );
666 if ( $this->mTitle
->getArticleId() ) {
668 $content_actions['history'] = array(
669 'class' => ($action == 'history') ?
'selected' : false,
670 'text' => wfMsg('history_short'),
671 'href' => $this->mTitle
->getLocalUrl( 'action=history')
674 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
675 if(!$this->mTitle
->isProtected()){
676 $content_actions['protect'] = array(
677 'class' => ($action == 'protect') ?
'selected' : false,
678 'text' => wfMsg('protect'),
679 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
683 $content_actions['unprotect'] = array(
684 'class' => ($action == 'unprotect') ?
'selected' : false,
685 'text' => wfMsg('unprotect'),
686 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
690 if($wgUser->isAllowed('delete')){
691 $content_actions['delete'] = array(
692 'class' => ($action == 'delete') ?
'selected' : false,
693 'text' => wfMsg('delete'),
694 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
697 if ( $this->mTitle
->userCanMove()) {
698 $moveTitle = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
699 $content_actions['move'] = array(
700 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
701 'text' => wfMsg('move'),
702 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
706 //article doesn't exist or is deleted
707 if( $wgUser->isAllowed( 'delete' ) ) {
708 if( $n = $this->mTitle
->isDeleted() ) {
709 $undelTitle = Title
::makeTitle( NS_SPECIAL
, 'Undelete' );
710 $content_actions['undelete'] = array(
712 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
713 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
714 #'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
719 wfProfileOut( "$fname-live" );
721 if( $this->loggedin
) {
722 if( !$this->mTitle
->userIsWatching()) {
723 $content_actions['watch'] = array(
724 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
725 'text' => wfMsg('watch'),
726 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
729 $content_actions['unwatch'] = array(
730 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
731 'text' => wfMsg('unwatch'),
732 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
737 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
739 /* show special page tab */
741 $content_actions['article'] = array(
742 'class' => 'selected',
743 'text' => wfMsg('specialpage'),
744 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
747 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
750 /* show links to different language variants */
751 global $wgDisableLangConversion;
752 $variants = $wgContLang->getVariants();
753 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
754 $preferred = $wgContLang->getPreferredVariant();
757 $actstr = 'action=' . $action . '&';
759 foreach( $variants as $code ) {
760 $varname = $wgContLang->getVariantname( $code );
761 if( $varname == 'disable' )
763 $selected = ( $code == $preferred )?
'selected' : false;
764 $content_actions['varlang-' . $vcount] = array(
765 'class' => $selected,
767 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
773 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
775 wfProfileOut( $fname );
776 return $content_actions;
782 * build array of common navigation links
786 function buildNavUrls () {
787 global $wgUseTrackbacks, $wgTitle, $wgArticle;
789 $fname = 'SkinTemplate::buildNavUrls';
790 wfProfileIn( $fname );
792 global $wgUser, $wgRequest;
793 global $wgEnableUploads, $wgUploadNavigationUrl;
795 $action = $wgRequest->getText( 'action' );
796 $oldid = $wgRequest->getVal( 'oldid' );
797 $diff = $wgRequest->getVal( 'diff' );
800 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
801 if( $wgEnableUploads ) {
802 if ($wgUploadNavigationUrl) {
803 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
805 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
808 if ($wgUploadNavigationUrl)
809 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
811 $nav_urls['upload'] = false;
813 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
816 // A print stylesheet is attached to all pages, but nobody ever
817 // figures that out. :) Add a link...
818 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
819 $revid = $wgArticle->getLatest();
820 if ( !( $revid == 0 ) )
821 $nav_urls['print'] = array(
822 'text' => wfMsg( 'printableversion' ),
823 'href' => $wgRequest->appendQuery( 'printable=yes' )
826 // Also add a "permalink" while we're at it
828 $nav_urls['permalink'] = array(
829 'text' => wfMsg( 'permalink' ),
833 if ( !( $revid == 0 ) )
834 $nav_urls['permalink'] = array(
835 'text' => wfMsg( 'permalink' ),
836 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
840 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
843 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
844 $wlhTitle = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
845 $nav_urls['whatlinkshere'] = array(
846 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
848 if( $this->mTitle
->getArticleId() ) {
849 $rclTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchangeslinked' );
850 $nav_urls['recentchangeslinked'] = array(
851 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
854 if ($wgUseTrackbacks)
855 $nav_urls['trackbacklink'] = array(
856 'href' => $wgTitle->trackbackURL()
860 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
861 $id = User
::idFromName($this->mTitle
->getText());
862 $ip = User
::isIP($this->mTitle
->getText());
868 if($id ||
$ip) { # both anons and non-anons have contri list
869 $nav_urls['contributions'] = array(
870 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
872 if ( $wgUser->isAllowed( 'block' ) )
873 $nav_urls['blockip'] = array(
874 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
877 $nav_urls['contributions'] = false;
879 $nav_urls['emailuser'] = false;
880 if( $this->showEmailUser( $id ) ) {
881 $nav_urls['emailuser'] = array(
882 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
885 wfProfileOut( $fname );
890 * Generate strings used for xml 'id' names
894 function getNameSpaceKey () {
895 return $this->mTitle
->getNamespaceKey();
901 function setupUserCss() {
902 $fname = 'SkinTemplate::setupUserCss';
903 wfProfileIn( $fname );
905 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
909 $siteargs = '&maxage=' . $wgSquidMaxage;
911 # Add user-specific code if this is a user and we allow that kind of thing
913 if ( $wgAllowUserCss && $this->loggedin
) {
914 $action = $wgRequest->getText('action');
916 # if we're previewing the CSS page, use it
917 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
918 $siteargs = "&smaxage=0&maxage=0";
919 $usercss = $wgRequest->getText('wpTextbox1');
921 $usercss = '@import "' .
922 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
923 'action=raw&ctype=text/css') . '";' ."\n";
926 $siteargs .= '&ts=' . $wgUser->mTouched
;
929 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
931 # If we use the site's dynamic CSS, throw that in, too
932 if ( $wgUseSiteCss ) {
933 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
934 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
935 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
936 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
939 # If we use any dynamic CSS, make a little CDATA block out of it.
941 if ( !empty($sitecss) ||
!empty($usercss) ) {
942 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
944 wfProfileOut( $fname );
950 function setupUserJs() {
951 $fname = 'SkinTemplate::setupUserJs';
952 wfProfileIn( $fname );
954 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
955 $action = $wgRequest->getText('action');
957 if( $wgAllowUserJs && $this->loggedin
) {
958 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
959 # XXX: additional security check/prompt?
960 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
962 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
965 wfProfileOut( $fname );
969 * Code for extensions to hook into to provide per-page CSS, see
970 * extensions/PageCSS/PageCSS.php for an implementation of this.
974 function setupPageCss() {
975 $fname = 'SkinTemplate::setupPageCss';
976 wfProfileIn( $fname );
978 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
980 wfProfileOut( $fname );
985 * returns css with user-specific options
989 function getUserStylesheet() {
990 $fname = 'SkinTemplate::getUserStylesheet';
991 wfProfileIn( $fname );
993 $s = "/* generated user stylesheet */\n";
994 $s .= $this->reallyDoGetUserStyles();
995 wfProfileOut( $fname );
1002 function getUserJs() {
1003 $fname = 'SkinTemplate::getUserJs';
1004 wfProfileIn( $fname );
1006 global $wgStylePath;
1007 $s = '/* generated javascript */';
1008 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1009 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1011 // avoid inclusion of non defined user JavaScript (with custom skins only)
1012 // by checking for default message content
1013 $msgKey = ucfirst($this->skinname
).'.js';
1014 $userJS = wfMsg($msgKey);
1015 if ('<'.$msgKey.'>' != $userJS) {
1019 wfProfileOut( $fname );
1025 * Generic wrapper for template functions, with interface
1026 * compatible with what we use of PHPTAL 0.7.
1027 * @package MediaWiki
1030 class QuickTemplate
{
1034 function QuickTemplate() {
1035 $this->data
= array();
1036 $this->translator
= new MediaWiki_I18N();
1042 function set( $name, $value ) {
1043 $this->data
[$name] = $value;
1049 function setRef($name, &$value) {
1050 $this->data
[$name] =& $value;
1056 function setTranslator( &$t ) {
1057 $this->translator
= &$t;
1063 function execute() {
1064 echo "Override this function.";
1071 function text( $str ) {
1072 echo htmlspecialchars( $this->data
[$str] );
1078 function jstext( $str ) {
1079 echo Xml
::escapeJsString( $this->data
[$str] );
1085 function html( $str ) {
1086 echo $this->data
[$str];
1092 function msg( $str ) {
1093 echo htmlspecialchars( $this->translator
->translate( $str ) );
1099 function msgHtml( $str ) {
1100 echo $this->translator
->translate( $str );
1104 * An ugly, ugly hack.
1107 function msgWiki( $str ) {
1108 global $wgParser, $wgTitle, $wgOut;
1110 $text = $this->translator
->translate( $str );
1111 $parserOutput = $wgParser->parse( $text, $wgTitle,
1112 $wgOut->parserOptions(), true );
1113 echo $parserOutput->getText();
1119 function haveData( $str ) {
1120 return $this->data
[$str];
1126 function haveMsg( $str ) {
1127 $msg = $this->translator
->translate( $str );
1128 return ($msg != '-') && ($msg != ''); # ????