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.
35 * Wrapper object for MediaWiki's localization functions,
36 * to be passed to the template engine.
41 class MediaWiki_I18N
{
42 var $_context = array();
44 function set($varName, $value) {
45 $this->_context
[$varName] = $value;
48 function translate($value) {
49 $fname = 'SkinTemplate-translate';
50 wfProfileIn( $fname );
52 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
53 $value = preg_replace( '/^string:/', '', $value );
55 $value = wfMsg( $value );
56 // interpolate variables
57 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
58 list($src, $var) = $m;
60 $varValue = $this->_context
[$var];
62 $value = str_replace($src, $varValue, $value);
64 wfProfileOut( $fname );
73 class SkinTemplate
extends Skin
{
79 * Name of our skin, set in initPage()
80 * It probably need to be all lower case.
85 * Stylesheets set to use
86 * Sub directory in ./skins/ where various stylesheets are located
91 * For QuickTemplate, the name of the subclass which
92 * will actually fill the template.
99 * Setup the base parameters...
100 * Child classes should override this to set the name,
101 * style subdirectory, and template filler callback.
103 * @param OutputPage $out
105 function initPage( &$out ) {
106 parent
::initPage( $out );
107 $this->skinname
= 'monobook';
108 $this->stylename
= 'monobook';
109 $this->template
= 'QuickTemplate';
113 * Create the template engine object; we feed it a bunch of data
114 * and eventually it spits out some HTML. Should have interface
115 * roughly equivalent to PHPTAL 0.7.
117 * @param string $callback (or file)
118 * @param string $repository subdirectory where we keep template files
119 * @param string $cache_dir
123 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
124 return new $classname();
128 * initialize various variables and generate the template
130 * @param OutputPage $out
133 function outputPage( &$out ) {
134 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
135 global $wgScript, $wgStylePath, $wgContLanguageCode;
136 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
137 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
138 global $wgMaxCredits, $wgShowCreditsIfMax;
139 global $wgPageShowWatchingUsers;
140 global $wgUseTrackbacks;
141 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
143 $fname = 'SkinTemplate::outputPage';
144 wfProfileIn( $fname );
146 // Hook that allows last minute changes to the output page, e.g.
147 // adding of CSS or Javascript by extensions.
148 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
150 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
152 wfProfileIn( "$fname-init" );
153 $this->initPage( $out );
155 $this->mTitle
=& $wgTitle;
156 $this->mUser
=& $wgUser;
158 $tpl = $this->setupTemplate( $this->template
, 'skins' );
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator(new MediaWiki_I18N());
163 wfProfileOut( "$fname-init" );
165 wfProfileIn( "$fname-stuff" );
166 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
167 $this->thisurl
= $this->mTitle
->getPrefixedURL();
168 $this->loggedin
= $wgUser->isLoggedIn();
169 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
170 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
171 $this->username
= $wgUser->getName();
172 $userPage = $wgUser->getUserPage();
173 $this->userpage
= $userPage->getPrefixedText();
175 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
176 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
178 # This won't be used in the standard skins, but we define it to preserve the interface
179 # To save time, we check for existence
180 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
183 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt
= $this->mTitle
->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
193 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
195 $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ];
196 if ( $nsname === NULL ) $nsname = $this->mTitle
->getNsText();
198 $tpl->set( 'nscanonical', $nsname );
199 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
200 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
201 $tpl->set( 'titletext', $this->mTitle
->getText() );
202 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
203 $tpl->set( 'isarticle', $wgOut->isArticle() );
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 ) {
224 if ( $format == "atom" ) {
225 $linktext = wfMsg( 'feed-atom' );
226 } else if ( $format == "rss" ) {
227 $linktext = wfMsg( 'feed-rss' );
229 $feeds[$format] = array(
231 'href' => $wgRequest->appendQuery( "feed=$format" )
234 $tpl->setRef( 'feeds', $feeds );
236 $tpl->set( 'feeds', false );
238 if ($wgUseTrackbacks && $out->isArticleRelated())
239 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
241 $tpl->setRef( 'mimetype', $wgMimeType );
242 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
243 $tpl->setRef( 'charset', $wgOutputEncoding );
244 $tpl->set( 'headlinks', $out->getHeadLinks() );
245 $tpl->set('headscripts', $out->getScript() );
246 $tpl->setRef( 'wgScript', $wgScript );
247 $tpl->setRef( 'skinname', $this->skinname
);
248 $tpl->set( 'skinclass', get_class( $this ) );
249 $tpl->setRef( 'stylename', $this->stylename
);
250 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
251 $tpl->setRef( 'loggedin', $this->loggedin
);
252 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
253 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
254 /* XXX currently unused, might get useful later
255 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
256 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
257 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
258 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
259 $tpl->set( "helppage", wfMsg('helppage'));
261 $tpl->set( 'searchaction', $this->escapeSearchLink() );
262 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
263 $tpl->setRef( 'stylepath', $wgStylePath );
264 $tpl->setRef( 'articlepath', $wgArticlePath );
265 $tpl->setRef( 'scriptpath', $wgScriptPath );
266 $tpl->setRef( 'serverurl', $wgServer );
267 $tpl->setRef( 'logopath', $wgLogo );
268 $tpl->setRef( "lang", $wgContLanguageCode );
269 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
270 $tpl->set( 'rtl', $wgContLang->isRTL() );
271 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
272 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
273 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
274 $tpl->setRef( 'userpage', $this->userpage
);
275 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
276 $tpl->set( 'userlang', $wgLang->getCode() );
277 $tpl->set( 'pagecss', $this->setupPageCss() );
278 $tpl->setRef( 'usercss', $this->usercss
);
279 $tpl->setRef( 'userjs', $this->userjs
);
280 $tpl->setRef( 'userjsprev', $this->userjsprev
);
283 if($this->loggedin
) {
284 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
286 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
289 $tpl->set('jsvarurl', false);
291 $newtalks = $wgUser->getNewMessageLinks();
293 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
294 $usertitle = $this->mUser
->getUserPage();
295 $usertalktitle = $usertitle->getTalkPage();
296 if( !$usertalktitle->equals( $this->mTitle
) ) {
297 $ntl = wfMsg( 'youhavenewmessages',
298 $this->makeKnownLinkObj(
300 wfMsgHtml( 'newmessageslink' ),
303 $this->makeKnownLinkObj(
305 wfMsgHtml( 'newmessagesdifflink' ),
310 $wgOut->setSquidMaxage(0);
312 } else if (count($newtalks)) {
313 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
315 foreach ($newtalks as $newtalk) {
316 $msgs[] = wfElement("a",
317 array('href' => $newtalk["link"]), $newtalk["wiki"]);
319 $parts = implode($sep, $msgs);
320 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
321 $wgOut->setSquidMaxage(0);
325 wfProfileOut( "$fname-stuff2" );
327 wfProfileIn( "$fname-stuff3" );
328 $tpl->setRef( 'newtalk', $ntl );
329 $tpl->setRef( 'skin', $this);
330 $tpl->set( 'logo', $this->logoText() );
331 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
332 $wgArticle and 0 != $wgArticle->getID() )
334 if ( !$wgDisableCounters ) {
335 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
337 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
339 $tpl->set('viewcount', false);
342 $tpl->set('viewcount', false);
345 if ($wgPageShowWatchingUsers) {
346 $dbr =& wfGetDB( DB_SLAVE
);
347 extract( $dbr->tableNames( 'watchlist' ) );
348 $sql = "SELECT COUNT(*) AS n FROM $watchlist
349 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
350 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
351 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
352 $x = $dbr->fetchObject( $res );
353 $numberofwatchingusers = $x->n
;
354 if ($numberofwatchingusers > 0) {
355 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
357 $tpl->set('numberofwatchingusers', false);
360 $tpl->set('numberofwatchingusers', false);
363 $tpl->set('copyright',$this->getCopyright());
365 $this->credits
= false;
367 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
368 require_once("Credits.php");
369 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
371 $tpl->set('lastmod', $this->lastModified());
374 $tpl->setRef( 'credits', $this->credits
);
376 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
377 $tpl->set('copyright', $this->getCopyright());
378 $tpl->set('viewcount', false);
379 $tpl->set('lastmod', false);
380 $tpl->set('credits', false);
381 $tpl->set('numberofwatchingusers', false);
383 $tpl->set('copyright', false);
384 $tpl->set('viewcount', false);
385 $tpl->set('lastmod', false);
386 $tpl->set('credits', false);
387 $tpl->set('numberofwatchingusers', false);
389 wfProfileOut( "$fname-stuff3" );
391 wfProfileIn( "$fname-stuff4" );
392 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
393 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
394 $tpl->set( 'disclaimer', $this->disclaimerLink() );
395 $tpl->set( 'privacy', $this->privacyLink() );
396 $tpl->set( 'about', $this->aboutLink() );
398 $tpl->setRef( 'debug', $out->mDebugtext
);
399 $tpl->set( 'reporttime', $out->reportTime() );
400 $tpl->set( 'sitenotice', wfGetSiteNotice() );
401 $tpl->set( 'bottomscripts', $this->bottomScripts() );
403 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
404 $out->mBodytext
.= $printfooter ;
405 $tpl->setRef( 'bodytext', $out->mBodytext
);
408 $language_urls = array();
410 if ( !$wgHideInterlanguageLinks ) {
411 foreach( $wgOut->getLanguageLinks() as $l ) {
412 $tmp = explode( ':', $l, 2 );
413 $class = 'interwiki-' . $tmp[0];
415 $nt = Title
::newFromText( $l );
416 $language_urls[] = array(
417 'href' => $nt->getFullURL(),
418 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
423 if(count($language_urls)) {
424 $tpl->setRef( 'language_urls', $language_urls);
426 $tpl->set('language_urls', false);
428 wfProfileOut( "$fname-stuff4" );
431 $tpl->set('personal_urls', $this->buildPersonalUrls());
432 $content_actions = $this->buildContentActionUrls();
433 $tpl->setRef('content_actions', $content_actions);
435 // XXX: attach this from javascript, same with section editing
436 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
438 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
440 $tpl->set('body_ondblclick', false);
442 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
443 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
445 $tpl->set( 'body_onload', false );
447 $tpl->set( 'sidebar', $this->buildSidebar() );
448 $tpl->set( 'nav_urls', $this->buildNavUrls() );
451 wfProfileIn( "$fname-execute" );
452 $res = $tpl->execute();
453 wfProfileOut( "$fname-execute" );
455 // result may be an error
456 $this->printOrError( $res );
457 wfProfileOut( $fname );
461 * Output the string, or print error message if it's
462 * an error object of the appropriate type.
463 * For the base class, assume strings all around.
468 function printOrError( &$str ) {
473 * build array of urls for personal toolbar
477 function buildPersonalUrls() {
478 global $wgTitle, $wgShowIPinHeader;
480 $fname = 'SkinTemplate::buildPersonalUrls';
481 $pageurl = $wgTitle->getLocalURL();
482 wfProfileIn( $fname );
484 /* set up the default links for the personal toolbar */
485 $personal_urls = array();
486 if ($this->loggedin
) {
487 $personal_urls['userpage'] = array(
488 'text' => $this->username
,
489 'href' => &$this->userpageUrlDetails
['href'],
490 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
491 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
493 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
494 $personal_urls['mytalk'] = array(
495 'text' => wfMsg('mytalk'),
496 'href' => &$usertalkUrlDetails['href'],
497 'class' => $usertalkUrlDetails['exists']?
false:'new',
498 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
500 $href = self
::makeSpecialUrl( 'Preferences' );
501 $personal_urls['preferences'] = array(
502 'text' => wfMsg( 'mypreferences' ),
503 'href' => self
::makeSpecialUrl( 'Preferences' ),
504 'active' => ( $href == $pageurl )
506 $href = self
::makeSpecialUrl( 'Watchlist' );
507 $personal_urls['watchlist'] = array(
508 'text' => wfMsg( 'watchlist' ),
510 'active' => ( $href == $pageurl )
512 $href = self
::makeSpecialUrl( "Contributions/$this->username" );
513 $personal_urls['mycontris'] = array(
514 'text' => wfMsg( 'mycontris' ),
516 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
518 $personal_urls['logout'] = array(
519 'text' => wfMsg( 'userlogout' ),
520 'href' => self
::makeSpecialUrl( 'Userlogout',
521 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
525 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
526 $href = &$this->userpageUrlDetails
['href'];
527 $personal_urls['anonuserpage'] = array(
528 'text' => $this->username
,
530 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
531 'active' => ( $pageurl == $href )
533 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
534 $href = &$usertalkUrlDetails['href'];
535 $personal_urls['anontalk'] = array(
536 'text' => wfMsg('anontalk'),
538 'class' => $usertalkUrlDetails['exists']?
false:'new',
539 'active' => ( $pageurl == $href )
541 $personal_urls['anonlogin'] = array(
542 'text' => wfMsg('userlogin'),
543 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
544 'active' => $wgTitle->isSpecial( 'Userlogin' )
548 $personal_urls['login'] = array(
549 'text' => wfMsg('userlogin'),
550 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
551 'active' => $wgTitle->isSpecial( 'Userlogin' )
556 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
557 wfProfileOut( $fname );
558 return $personal_urls;
562 * Returns true if the IP should be shown in the header
564 function showIPinHeader() {
565 global $wgShowIPinHeader;
566 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
569 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
572 $classes[] = 'selected';
574 if( $checkEdit && $title->getArticleId() == 0 ) {
576 $query = 'action=edit';
579 $text = wfMsg( $message );
580 if ( wfEmptyMsg( $message, $text ) ) {
582 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
586 'class' => implode( ' ', $classes ),
588 'href' => $title->getLocalUrl( $query ) );
591 function makeTalkUrlDetails( $name, $urlaction = '' ) {
592 $title = Title
::newFromText( $name );
593 $title = $title->getTalkPage();
594 self
::checkTitle( $title, $name );
596 'href' => $title->getLocalURL( $urlaction ),
597 'exists' => $title->getArticleID() != 0 ?
true : false
601 function makeArticleUrlDetails( $name, $urlaction = '' ) {
602 $title = Title
::newFromText( $name );
603 $title= $title->getSubjectPage();
604 self
::checkTitle( $title, $name );
606 'href' => $title->getLocalURL( $urlaction ),
607 'exists' => $title->getArticleID() != 0 ?
true : false
612 * an array of edit links by default used for the tabs
616 function buildContentActionUrls () {
617 global $wgContLang, $wgOut;
618 $fname = 'SkinTemplate::buildContentActionUrls';
619 wfProfileIn( $fname );
621 global $wgUser, $wgRequest;
622 $action = $wgRequest->getText( 'action' );
623 $section = $wgRequest->getText( 'section' );
624 $content_actions = array();
626 $prevent_active_tabs = false ;
627 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
629 if( $this->iscontent
) {
630 $subjpage = $this->mTitle
->getSubjectPage();
631 $talkpage = $this->mTitle
->getTalkPage();
633 $nskey = $this->mTitle
->getNamespaceKey();
634 $content_actions[$nskey] = $this->tabAction(
637 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
640 $content_actions['talk'] = $this->tabAction(
643 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
647 wfProfileIn( "$fname-edit" );
648 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
649 $istalk = $this->mTitle
->isTalkPage();
650 $istalkclass = $istalk?
' istalk':'';
651 $content_actions['edit'] = array(
652 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
653 'text' => wfMsg('edit'),
654 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
657 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
658 $content_actions['addsection'] = array(
659 'class' => $section == 'new'?
'selected':false,
660 'text' => wfMsg('addsection'),
661 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
665 $content_actions['viewsource'] = array(
666 'class' => ($action == 'edit') ?
'selected' : false,
667 'text' => wfMsg('viewsource'),
668 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
671 wfProfileOut( "$fname-edit" );
673 wfProfileIn( "$fname-live" );
674 if ( $this->mTitle
->getArticleId() ) {
676 $content_actions['history'] = array(
677 'class' => ($action == 'history') ?
'selected' : false,
678 'text' => wfMsg('history_short'),
679 'href' => $this->mTitle
->getLocalUrl( 'action=history')
682 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
683 if(!$this->mTitle
->isProtected()){
684 $content_actions['protect'] = array(
685 'class' => ($action == 'protect') ?
'selected' : false,
686 'text' => wfMsg('protect'),
687 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
691 $content_actions['unprotect'] = array(
692 'class' => ($action == 'unprotect') ?
'selected' : false,
693 'text' => wfMsg('unprotect'),
694 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
698 if($wgUser->isAllowed('delete')){
699 $content_actions['delete'] = array(
700 'class' => ($action == 'delete') ?
'selected' : false,
701 'text' => wfMsg('delete'),
702 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
705 if ( $this->mTitle
->userCanMove()) {
706 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
707 $content_actions['move'] = array(
708 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
709 'text' => wfMsg('move'),
710 'href' => $moveTitle->getLocalUrl()
714 //article doesn't exist or is deleted
715 if( $wgUser->isAllowed( 'delete' ) ) {
716 if( $n = $this->mTitle
->isDeleted() ) {
717 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
718 $content_actions['undelete'] = array(
720 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
721 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
722 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
727 wfProfileOut( "$fname-live" );
729 if( $this->loggedin
) {
730 if( !$this->mTitle
->userIsWatching()) {
731 $content_actions['watch'] = array(
732 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
733 'text' => wfMsg('watch'),
734 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
737 $content_actions['unwatch'] = array(
738 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
739 'text' => wfMsg('unwatch'),
740 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
745 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
747 /* show special page tab */
749 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
750 'class' => 'selected',
751 'text' => wfMsg('specialpage'),
752 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
755 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
758 /* show links to different language variants */
759 global $wgDisableLangConversion;
760 $variants = $wgContLang->getVariants();
761 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
762 $preferred = $wgContLang->getPreferredVariant();
765 $actstr = 'action=' . $action . '&';
767 foreach( $variants as $code ) {
768 $varname = $wgContLang->getVariantname( $code );
769 if( $varname == 'disable' )
771 $selected = ( $code == $preferred )?
'selected' : false;
772 $content_actions['varlang-' . $vcount] = array(
773 'class' => $selected,
775 'href' => $this->mTitle
->getLocalURL('',$code)
781 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
783 wfProfileOut( $fname );
784 return $content_actions;
790 * build array of common navigation links
794 function buildNavUrls () {
795 global $wgUseTrackbacks, $wgTitle, $wgArticle;
797 $fname = 'SkinTemplate::buildNavUrls';
798 wfProfileIn( $fname );
800 global $wgUser, $wgRequest;
801 global $wgEnableUploads, $wgUploadNavigationUrl;
803 $action = $wgRequest->getText( 'action' );
804 $oldid = $wgRequest->getVal( 'oldid' );
805 $diff = $wgRequest->getVal( 'diff' );
808 $nav_urls['mainpage'] = array( 'href' => self
::makeI18nUrl( 'mainpage') );
809 if( $wgEnableUploads ) {
810 if ($wgUploadNavigationUrl) {
811 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
813 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
816 if ($wgUploadNavigationUrl)
817 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
819 $nav_urls['upload'] = false;
821 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
824 // A print stylesheet is attached to all pages, but nobody ever
825 // figures that out. :) Add a link...
826 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
827 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
828 if ( !( $revid == 0 ) )
829 $nav_urls['print'] = array(
830 'text' => wfMsg( 'printableversion' ),
831 'href' => $wgRequest->appendQuery( 'printable=yes' )
834 // Also add a "permalink" while we're at it
836 $nav_urls['permalink'] = array(
837 'text' => wfMsg( 'permalink' ),
841 if ( !( $revid == 0 ) )
842 $nav_urls['permalink'] = array(
843 'text' => wfMsg( 'permalink' ),
844 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
848 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
851 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
852 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
853 $nav_urls['whatlinkshere'] = array(
854 'href' => $wlhTitle->getLocalUrl()
856 if( $this->mTitle
->getArticleId() ) {
857 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
858 $nav_urls['recentchangeslinked'] = array(
859 'href' => $rclTitle->getLocalUrl()
862 if ($wgUseTrackbacks)
863 $nav_urls['trackbacklink'] = array(
864 'href' => $wgTitle->trackbackURL()
868 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
869 $id = User
::idFromName($this->mTitle
->getText());
870 $ip = User
::isIP($this->mTitle
->getText());
876 if($id ||
$ip) { # both anons and non-anons have contri list
877 $nav_urls['contributions'] = array(
878 'href' => self
::makeSpecialUrl( 'Contributions/' . $this->mTitle
->getText() )
880 if ( $wgUser->isAllowed( 'block' ) )
881 $nav_urls['blockip'] = array(
882 'href' => self
::makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
885 $nav_urls['contributions'] = false;
887 $nav_urls['emailuser'] = false;
888 if( $this->showEmailUser( $id ) ) {
889 $nav_urls['emailuser'] = array(
890 'href' => self
::makeSpecialUrl( 'Emailuser/' . $this->mTitle
->getText() )
893 wfProfileOut( $fname );
898 * Generate strings used for xml 'id' names
902 function getNameSpaceKey () {
903 return $this->mTitle
->getNamespaceKey();
909 function setupUserCss() {
910 $fname = 'SkinTemplate::setupUserCss';
911 wfProfileIn( $fname );
913 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
917 $siteargs = '&maxage=' . $wgSquidMaxage;
918 if( $this->loggedin
) {
919 // Ensure that logged-in users' generated CSS isn't clobbered
920 // by anons' publicly cacheable generated CSS.
921 $siteargs .= '&smaxage=0';
924 # Add user-specific code if this is a user and we allow that kind of thing
926 if ( $wgAllowUserCss && $this->loggedin
) {
927 $action = $wgRequest->getText('action');
929 # if we're previewing the CSS page, use it
930 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
931 $siteargs = "&smaxage=0&maxage=0";
932 $usercss = $wgRequest->getText('wpTextbox1');
934 $usercss = '@import "' .
935 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
936 'action=raw&ctype=text/css') . '";' ."\n";
939 $siteargs .= '&ts=' . $wgUser->mTouched
;
942 if( $wgContLang->isRTL() ) {
943 global $wgStyleVersion;
944 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
947 # If we use the site's dynamic CSS, throw that in, too
948 if ( $wgUseSiteCss ) {
949 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
950 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
951 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
952 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
955 # If we use any dynamic CSS, make a little CDATA block out of it.
957 if ( !empty($sitecss) ||
!empty($usercss) ) {
958 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
960 wfProfileOut( $fname );
966 function setupUserJs() {
967 $fname = 'SkinTemplate::setupUserJs';
968 wfProfileIn( $fname );
970 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
971 $action = $wgRequest->getText('action');
973 if( $wgAllowUserJs && $this->loggedin
) {
974 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
975 # XXX: additional security check/prompt?
976 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
978 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
981 wfProfileOut( $fname );
985 * Code for extensions to hook into to provide per-page CSS, see
986 * extensions/PageCSS/PageCSS.php for an implementation of this.
990 function setupPageCss() {
991 $fname = 'SkinTemplate::setupPageCss';
992 wfProfileIn( $fname );
994 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
996 wfProfileOut( $fname );
1001 * returns css with user-specific options
1005 function getUserStylesheet() {
1006 $fname = 'SkinTemplate::getUserStylesheet';
1007 wfProfileIn( $fname );
1009 $s = "/* generated user stylesheet */\n";
1010 $s .= $this->reallyDoGetUserStyles();
1011 wfProfileOut( $fname );
1016 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1017 * nated together. For some bizarre reason, it does *not* return any
1018 * custom user JS from subpages. Huh?
1020 * There's absolutely no reason to have separate Monobook/Common JSes.
1021 * Any JS that cares can just check the skin variable generated at the
1022 * top. For now Monobook.js will be maintained, but it should be consi-
1027 public function getUserJs() {
1028 $fname = 'SkinTemplate::getUserJs';
1029 wfProfileIn( $fname );
1031 $s = parent
::getUserJs();
1032 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1034 // avoid inclusion of non defined user JavaScript (with custom skins only)
1035 // by checking for default message content
1036 $msgKey = ucfirst($this->skinname
).'.js';
1037 $userJS = wfMsgForContent($msgKey);
1038 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1042 wfProfileOut( $fname );
1048 * Generic wrapper for template functions, with interface
1049 * compatible with what we use of PHPTAL 0.7.
1050 * @package MediaWiki
1053 class QuickTemplate
{
1057 function QuickTemplate() {
1058 $this->data
= array();
1059 $this->translator
= new MediaWiki_I18N();
1065 function set( $name, $value ) {
1066 $this->data
[$name] = $value;
1072 function setRef($name, &$value) {
1073 $this->data
[$name] =& $value;
1079 function setTranslator( &$t ) {
1080 $this->translator
= &$t;
1086 function execute() {
1087 echo "Override this function.";
1094 function text( $str ) {
1095 echo htmlspecialchars( $this->data
[$str] );
1101 function jstext( $str ) {
1102 echo Xml
::escapeJsString( $this->data
[$str] );
1108 function html( $str ) {
1109 echo $this->data
[$str];
1115 function msg( $str ) {
1116 echo htmlspecialchars( $this->translator
->translate( $str ) );
1122 function msgHtml( $str ) {
1123 echo $this->translator
->translate( $str );
1127 * An ugly, ugly hack.
1130 function msgWiki( $str ) {
1131 global $wgParser, $wgTitle, $wgOut;
1133 $text = $this->translator
->translate( $str );
1134 $parserOutput = $wgParser->parse( $text, $wgTitle,
1135 $wgOut->parserOptions(), true );
1136 echo $parserOutput->getText();
1142 function haveData( $str ) {
1143 return $this->data
[$str];
1149 function haveMsg( $str ) {
1150 $msg = $this->translator
->translate( $str );
1151 return ($msg != '-') && ($msg != ''); # ????