ddbc40b3f778db2586111b718d3e598bc008c128
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() );
394 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
395 $out->mBodytext
.= $printfooter ;
396 $tpl->setRef( 'bodytext', $out->mBodytext
);
399 $language_urls = array();
401 if ( !$wgHideInterlanguageLinks ) {
402 foreach( $wgOut->getLanguageLinks() as $l ) {
403 $tmp = explode( ':', $l, 2 );
404 $class = 'interwiki-' . $tmp[0];
406 $nt = Title
::newFromText( $l );
407 $language_urls[] = array(
408 'href' => $nt->getFullURL(),
409 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
414 if(count($language_urls)) {
415 $tpl->setRef( 'language_urls', $language_urls);
417 $tpl->set('language_urls', false);
419 wfProfileOut( "$fname-stuff4" );
422 $tpl->set('personal_urls', $this->buildPersonalUrls());
423 $content_actions = $this->buildContentActionUrls();
424 $tpl->setRef('content_actions', $content_actions);
426 // XXX: attach this from javascript, same with section editing
427 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
429 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
431 $tpl->set('body_ondblclick', false);
433 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
434 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
436 $tpl->set( 'body_onload', false );
438 $tpl->set( 'sidebar', $this->buildSidebar() );
439 $tpl->set( 'nav_urls', $this->buildNavUrls() );
442 wfProfileIn( "$fname-execute" );
443 $res = $tpl->execute();
444 wfProfileOut( "$fname-execute" );
446 // result may be an error
447 $this->printOrError( $res );
448 wfProfileOut( $fname );
452 * Output the string, or print error message if it's
453 * an error object of the appropriate type.
454 * For the base class, assume strings all around.
459 function printOrError( &$str ) {
464 * build array of urls for personal toolbar
468 function buildPersonalUrls() {
469 global $wgTitle, $wgShowIPinHeader;
471 $fname = 'SkinTemplate::buildPersonalUrls';
472 $pageurl = $wgTitle->getLocalURL();
473 wfProfileIn( $fname );
475 /* set up the default links for the personal toolbar */
476 $personal_urls = array();
477 if ($this->loggedin
) {
478 $personal_urls['userpage'] = array(
479 'text' => $this->username
,
480 'href' => &$this->userpageUrlDetails
['href'],
481 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
482 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
484 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
485 $personal_urls['mytalk'] = array(
486 'text' => wfMsg('mytalk'),
487 'href' => &$usertalkUrlDetails['href'],
488 'class' => $usertalkUrlDetails['exists']?
false:'new',
489 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
491 $href = $this->makeSpecialUrl('Preferences');
492 $personal_urls['preferences'] = array(
493 'text' => wfMsg('preferences'),
494 'href' => $this->makeSpecialUrl('Preferences'),
495 'active' => ( $href == $pageurl )
497 $href = $this->makeSpecialUrl('Watchlist');
498 $personal_urls['watchlist'] = array(
499 'text' => wfMsg('watchlist'),
501 'active' => ( $href == $pageurl )
503 $href = $this->makeSpecialUrl("Contributions/$this->username");
504 $personal_urls['mycontris'] = array(
505 'text' => wfMsg('mycontris'),
507 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
509 $personal_urls['logout'] = array(
510 'text' => wfMsg('userlogout'),
511 'href' => $this->makeSpecialUrl( 'Userlogout',
512 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
516 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
517 $href = &$this->userpageUrlDetails
['href'];
518 $personal_urls['anonuserpage'] = array(
519 'text' => $this->username
,
521 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
522 'active' => ( $pageurl == $href )
524 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
525 $href = &$usertalkUrlDetails['href'];
526 $personal_urls['anontalk'] = array(
527 'text' => wfMsg('anontalk'),
529 'class' => $usertalkUrlDetails['exists']?
false:'new',
530 'active' => ( $pageurl == $href )
532 $personal_urls['anonlogin'] = array(
533 'text' => wfMsg('userlogin'),
534 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
535 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
539 $personal_urls['login'] = array(
540 'text' => wfMsg('userlogin'),
541 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
542 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
547 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
548 wfProfileOut( $fname );
549 return $personal_urls;
553 * Returns true if the IP should be shown in the header
555 function showIPinHeader() {
556 global $wgShowIPinHeader;
557 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
560 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
563 $classes[] = 'selected';
565 if( $checkEdit && $title->getArticleId() == 0 ) {
567 $query = 'action=edit';
570 $text = wfMsg( $message );
571 if ( $text == "<$message>" ) {
573 $text = $wgContLang->getNsText( Namespace::getSubject( $title->getNamespace() ) );
577 'class' => implode( ' ', $classes ),
579 'href' => $title->getLocalUrl( $query ) );
582 function makeTalkUrlDetails( $name, $urlaction='' ) {
583 $title = Title
::newFromText( $name );
584 $title = $title->getTalkPage();
585 $this->checkTitle($title, $name);
587 'href' => $title->getLocalURL( $urlaction ),
588 'exists' => $title->getArticleID() != 0?
true:false
592 function makeArticleUrlDetails( $name, $urlaction='' ) {
593 $title = Title
::newFromText( $name );
594 $title= $title->getSubjectPage();
595 $this->checkTitle($title, $name);
597 'href' => $title->getLocalURL( $urlaction ),
598 'exists' => $title->getArticleID() != 0?
true:false
603 * an array of edit links by default used for the tabs
607 function buildContentActionUrls () {
608 global $wgContLang, $wgOut;
609 $fname = 'SkinTemplate::buildContentActionUrls';
610 wfProfileIn( $fname );
612 global $wgUser, $wgRequest;
613 $action = $wgRequest->getText( 'action' );
614 $section = $wgRequest->getText( 'section' );
615 $content_actions = array();
617 $prevent_active_tabs = false ;
618 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
620 if( $this->iscontent
) {
621 $subjpage = $this->mTitle
->getSubjectPage();
622 $talkpage = $this->mTitle
->getTalkPage();
624 $nskey = $this->mTitle
->getNamespaceKey();
625 $content_actions[$nskey] = $this->tabAction(
628 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
631 $content_actions['talk'] = $this->tabAction(
634 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
638 wfProfileIn( "$fname-edit" );
639 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
640 $istalk = $this->mTitle
->isTalkPage();
641 $istalkclass = $istalk?
' istalk':'';
642 $content_actions['edit'] = array(
643 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
644 'text' => wfMsg('edit'),
645 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
648 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
649 $content_actions['addsection'] = array(
650 'class' => $section == 'new'?
'selected':false,
651 'text' => wfMsg('addsection'),
652 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
656 $content_actions['viewsource'] = array(
657 'class' => ($action == 'edit') ?
'selected' : false,
658 'text' => wfMsg('viewsource'),
659 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
662 wfProfileOut( "$fname-edit" );
664 wfProfileIn( "$fname-live" );
665 if ( $this->mTitle
->getArticleId() ) {
667 $content_actions['history'] = array(
668 'class' => ($action == 'history') ?
'selected' : false,
669 'text' => wfMsg('history_short'),
670 'href' => $this->mTitle
->getLocalUrl( 'action=history')
673 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
674 if(!$this->mTitle
->isProtected()){
675 $content_actions['protect'] = array(
676 'class' => ($action == 'protect') ?
'selected' : false,
677 'text' => wfMsg('protect'),
678 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
682 $content_actions['unprotect'] = array(
683 'class' => ($action == 'unprotect') ?
'selected' : false,
684 'text' => wfMsg('unprotect'),
685 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
689 if($wgUser->isAllowed('delete')){
690 $content_actions['delete'] = array(
691 'class' => ($action == 'delete') ?
'selected' : false,
692 'text' => wfMsg('delete'),
693 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
696 if ( $this->mTitle
->userCanMove()) {
697 $moveTitle = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
698 $content_actions['move'] = array(
699 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
700 'text' => wfMsg('move'),
701 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
705 //article doesn't exist or is deleted
706 if( $wgUser->isAllowed( 'delete' ) ) {
707 if( $n = $this->mTitle
->isDeleted() ) {
708 $undelTitle = Title
::makeTitle( NS_SPECIAL
, 'Undelete' );
709 $content_actions['undelete'] = array(
711 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
712 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
713 #'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
718 wfProfileOut( "$fname-live" );
720 if( $this->loggedin
) {
721 if( !$this->mTitle
->userIsWatching()) {
722 $content_actions['watch'] = array(
723 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
724 'text' => wfMsg('watch'),
725 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
728 $content_actions['unwatch'] = array(
729 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
730 'text' => wfMsg('unwatch'),
731 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
736 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
738 /* show special page tab */
740 $content_actions['article'] = array(
741 'class' => 'selected',
742 'text' => wfMsg('specialpage'),
743 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
746 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
749 /* show links to different language variants */
750 global $wgDisableLangConversion;
751 $variants = $wgContLang->getVariants();
752 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
753 $preferred = $wgContLang->getPreferredVariant();
756 $actstr = 'action=' . $action . '&';
758 foreach( $variants as $code ) {
759 $varname = $wgContLang->getVariantname( $code );
760 if( $varname == 'disable' )
762 $selected = ( $code == $preferred )?
'selected' : false;
763 $content_actions['varlang-' . $vcount] = array(
764 'class' => $selected,
766 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
772 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
774 wfProfileOut( $fname );
775 return $content_actions;
781 * build array of common navigation links
785 function buildNavUrls () {
786 global $wgUseTrackbacks, $wgTitle, $wgArticle;
788 $fname = 'SkinTemplate::buildNavUrls';
789 wfProfileIn( $fname );
791 global $wgUser, $wgRequest;
792 global $wgEnableUploads, $wgUploadNavigationUrl;
794 $action = $wgRequest->getText( 'action' );
795 $oldid = $wgRequest->getVal( 'oldid' );
796 $diff = $wgRequest->getVal( 'diff' );
799 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
800 if( $wgEnableUploads ) {
801 if ($wgUploadNavigationUrl) {
802 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
804 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
807 if ($wgUploadNavigationUrl)
808 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
810 $nav_urls['upload'] = false;
812 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
815 // A print stylesheet is attached to all pages, but nobody ever
816 // figures that out. :) Add a link...
817 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
818 $revid = $wgArticle->getLatest();
819 if ( !( $revid == 0 ) )
820 $nav_urls['print'] = array(
821 'text' => wfMsg( 'printableversion' ),
822 'href' => $wgRequest->appendQuery( 'printable=yes' )
825 // Also add a "permalink" while we're at it
827 $nav_urls['permalink'] = array(
828 'text' => wfMsg( 'permalink' ),
832 if ( !( $revid == 0 ) )
833 $nav_urls['permalink'] = array(
834 'text' => wfMsg( 'permalink' ),
835 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
839 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
842 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
843 $wlhTitle = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
844 $nav_urls['whatlinkshere'] = array(
845 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
847 if( $this->mTitle
->getArticleId() ) {
848 $rclTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchangeslinked' );
849 $nav_urls['recentchangeslinked'] = array(
850 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
853 if ($wgUseTrackbacks)
854 $nav_urls['trackbacklink'] = array(
855 'href' => $wgTitle->trackbackURL()
859 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
860 $id = User
::idFromName($this->mTitle
->getText());
861 $ip = User
::isIP($this->mTitle
->getText());
867 if($id ||
$ip) { # both anons and non-anons have contri list
868 $nav_urls['contributions'] = array(
869 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
871 if ( $wgUser->isAllowed( 'block' ) )
872 $nav_urls['blockip'] = array(
873 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
876 $nav_urls['contributions'] = false;
878 $nav_urls['emailuser'] = false;
879 if( $this->showEmailUser( $id ) ) {
880 $nav_urls['emailuser'] = array(
881 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
884 wfProfileOut( $fname );
889 * Generate strings used for xml 'id' names
893 function getNameSpaceKey () {
894 return $this->mTitle
->getNamespaceKey();
900 function setupUserCss() {
901 $fname = 'SkinTemplate::setupUserCss';
902 wfProfileIn( $fname );
904 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
908 $siteargs = '&maxage=' . $wgSquidMaxage;
910 # Add user-specific code if this is a user and we allow that kind of thing
912 if ( $wgAllowUserCss && $this->loggedin
) {
913 $action = $wgRequest->getText('action');
915 # if we're previewing the CSS page, use it
916 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
917 $siteargs = "&smaxage=0&maxage=0";
918 $usercss = $wgRequest->getText('wpTextbox1');
920 $usercss = '@import "' .
921 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
922 'action=raw&ctype=text/css') . '";' ."\n";
925 $siteargs .= '&ts=' . $wgUser->mTouched
;
928 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
930 # If we use the site's dynamic CSS, throw that in, too
931 if ( $wgUseSiteCss ) {
932 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
933 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
934 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
935 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
938 # If we use any dynamic CSS, make a little CDATA block out of it.
940 if ( !empty($sitecss) ||
!empty($usercss) ) {
941 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
943 wfProfileOut( $fname );
949 function setupUserJs() {
950 $fname = 'SkinTemplate::setupUserJs';
951 wfProfileIn( $fname );
953 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
954 $action = $wgRequest->getText('action');
956 if( $wgAllowUserJs && $this->loggedin
) {
957 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
958 # XXX: additional security check/prompt?
959 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
961 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
964 wfProfileOut( $fname );
968 * Code for extensions to hook into to provide per-page CSS, see
969 * extensions/PageCSS/PageCSS.php for an implementation of this.
973 function setupPageCss() {
974 $fname = 'SkinTemplate::setupPageCss';
975 wfProfileIn( $fname );
977 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
979 wfProfileOut( $fname );
984 * returns css with user-specific options
988 function getUserStylesheet() {
989 $fname = 'SkinTemplate::getUserStylesheet';
990 wfProfileIn( $fname );
992 $s = "/* generated user stylesheet */\n";
993 $s .= $this->reallyDoGetUserStyles();
994 wfProfileOut( $fname );
1001 function getUserJs() {
1002 $fname = 'SkinTemplate::getUserJs';
1003 wfProfileIn( $fname );
1005 global $wgStylePath;
1006 $s = '/* generated javascript */';
1007 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1008 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1010 // avoid inclusion of non defined user JavaScript (with custom skins only)
1011 // by checking for default message content
1012 $msgKey = ucfirst($this->skinname
).'.js';
1013 $userJS = wfMsg($msgKey);
1014 if ('<'.$msgKey.'>' != $userJS) {
1018 wfProfileOut( $fname );
1024 * Generic wrapper for template functions, with interface
1025 * compatible with what we use of PHPTAL 0.7.
1026 * @package MediaWiki
1029 class QuickTemplate
{
1033 function QuickTemplate() {
1034 $this->data
= array();
1035 $this->translator
= new MediaWiki_I18N();
1041 function set( $name, $value ) {
1042 $this->data
[$name] = $value;
1048 function setRef($name, &$value) {
1049 $this->data
[$name] =& $value;
1055 function setTranslator( &$t ) {
1056 $this->translator
= &$t;
1062 function execute() {
1063 echo "Override this function.";
1070 function text( $str ) {
1071 echo htmlspecialchars( $this->data
[$str] );
1077 function jstext( $str ) {
1078 echo Xml
::escapeJsString( $this->data
[$str] );
1084 function html( $str ) {
1085 echo $this->data
[$str];
1091 function msg( $str ) {
1092 echo htmlspecialchars( $this->translator
->translate( $str ) );
1098 function msgHtml( $str ) {
1099 echo $this->translator
->translate( $str );
1103 * An ugly, ugly hack.
1106 function msgWiki( $str ) {
1107 global $wgParser, $wgTitle, $wgOut;
1109 $text = $this->translator
->translate( $str );
1110 $parserOutput = $wgParser->parse( $text, $wgTitle,
1111 $wgOut->parserOptions(), true );
1112 echo $parserOutput->getText();
1118 function haveData( $str ) {
1119 return $this->data
[$str];
1125 function haveMsg( $str ) {
1126 $msg = $this->translator
->translate( $str );
1127 return ($msg != '-') && ($msg != ''); # ????