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
58 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
59 list($src, $var) = $m;
61 $varValue = $this->_context
[$var];
63 $value = str_replace($src, $varValue, $value);
65 wfProfileOut( $fname );
74 class SkinTemplate
extends Skin
{
80 * Name of our skin, set in initPage()
81 * It probably need to be all lower case.
86 * Stylesheets set to use
87 * Sub directory in ./skins/ where various stylesheets are located
92 * For QuickTemplate, the name of the subclass which
93 * will actually fill the template.
100 * Setup the base parameters...
101 * Child classes should override this to set the name,
102 * style subdirectory, and template filler callback.
104 * @param OutputPage $out
106 function initPage( &$out ) {
107 parent
::initPage( $out );
108 $this->skinname
= 'monobook';
109 $this->stylename
= 'monobook';
110 $this->template
= 'QuickTemplate';
114 * Create the template engine object; we feed it a bunch of data
115 * and eventually it spits out some HTML. Should have interface
116 * roughly equivalent to PHPTAL 0.7.
118 * @param string $callback (or file)
119 * @param string $repository subdirectory where we keep template files
120 * @param string $cache_dir
124 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
125 return new $classname();
129 * initialize various variables and generate the template
131 * @param OutputPage $out
134 function outputPage( &$out ) {
135 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
139 global $wgMaxCredits, $wgShowCreditsIfMax;
140 global $wgPageShowWatchingUsers;
141 global $wgUseTrackbacks;
142 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
144 $fname = 'SkinTemplate::outputPage';
145 wfProfileIn( $fname );
147 // Hook that allows last minute changes to the output page, e.g.
148 // adding of CSS or Javascript by extensions.
149 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
151 $oldid = $wgRequest->getVal( 'oldid' );
152 $diff = $wgRequest->getVal( 'diff' );
154 wfProfileIn( "$fname-init" );
155 $this->initPage( $out );
157 $this->mTitle
=& $wgTitle;
158 $this->mUser
=& $wgUser;
160 $tpl = $this->setupTemplate( $this->template
, 'skins' );
162 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
163 $tpl->setTranslator(new MediaWiki_I18N());
165 wfProfileOut( "$fname-init" );
167 wfProfileIn( "$fname-stuff" );
168 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
169 $this->thisurl
= $this->mTitle
->getPrefixedURL();
170 $this->loggedin
= $wgUser->isLoggedIn();
171 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
172 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
173 $this->username
= $wgUser->getName();
174 $userPage = $wgUser->getUserPage();
175 $this->userpage
= $userPage->getPrefixedText();
177 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
178 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
180 # This won't be used in the standard skins, but we define it to preserve the interface
181 # To save time, we check for existence
182 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
185 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
186 $this->setupUserCss();
187 $this->setupUserJs();
188 $this->titletxt
= $this->mTitle
->getPrefixedText();
189 wfProfileOut( "$fname-stuff" );
191 wfProfileIn( "$fname-stuff2" );
192 $tpl->set( 'title', $wgOut->getPageTitle() );
193 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
194 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
195 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
197 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
198 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
199 $this->mTitle
->getNsText();
201 $tpl->set( 'nscanonical', $nsname );
202 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
203 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
204 $tpl->set( 'titletext', $this->mTitle
->getText() );
205 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
206 $tpl->set( 'isarticle', $wgOut->isArticle() );
208 $tpl->setRef( "thispage", $this->thispage
);
209 $subpagestr = $this->subPageSubtitle();
211 'subtitle', !empty($subpagestr)?
212 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
215 $undelete = $this->getUndeleteLink();
217 "undelete", !empty($undelete)?
218 '<span class="subpages">'.$undelete.'</span>':
222 $tpl->set( 'catlinks', $this->getCategories());
223 if( $wgOut->isSyndicated() ) {
225 foreach( $wgFeedClasses as $format => $class ) {
227 if ( $format == "atom" ) {
228 $linktext = wfMsg( 'feed-atom' );
229 } else if ( $format == "rss" ) {
230 $linktext = wfMsg( 'feed-rss' );
232 $feeds[$format] = array(
234 'href' => $wgRequest->appendQuery( "feed=$format" )
237 $tpl->setRef( 'feeds', $feeds );
239 $tpl->set( 'feeds', false );
241 if ($wgUseTrackbacks && $out->isArticleRelated()) {
242 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
244 $tpl->set( 'trackbackhtml', null );
247 $tpl->setRef( 'mimetype', $wgMimeType );
248 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
249 $tpl->setRef( 'charset', $wgOutputEncoding );
250 $tpl->set( 'headlinks', $out->getHeadLinks() );
251 $tpl->set('headscripts', $out->getScript() );
252 $tpl->setRef( 'wgScript', $wgScript );
253 $tpl->setRef( 'skinname', $this->skinname
);
254 $tpl->set( 'skinclass', get_class( $this ) );
255 $tpl->setRef( 'stylename', $this->stylename
);
256 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
257 $tpl->setRef( 'loggedin', $this->loggedin
);
258 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
259 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
260 /* XXX currently unused, might get useful later
261 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
262 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
263 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
264 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
265 $tpl->set( "helppage", wfMsg('helppage'));
267 $tpl->set( 'searchaction', $this->escapeSearchLink() );
268 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
269 $tpl->setRef( 'stylepath', $wgStylePath );
270 $tpl->setRef( 'articlepath', $wgArticlePath );
271 $tpl->setRef( 'scriptpath', $wgScriptPath );
272 $tpl->setRef( 'serverurl', $wgServer );
273 $tpl->setRef( 'logopath', $wgLogo );
274 $tpl->setRef( "lang", $wgContLanguageCode );
275 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
276 $tpl->set( 'rtl', $wgContLang->isRTL() );
277 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
278 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
279 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
280 $tpl->setRef( 'userpage', $this->userpage
);
281 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
282 $tpl->set( 'userlang', $wgLang->getCode() );
283 $tpl->set( 'pagecss', $this->setupPageCss() );
284 $tpl->setRef( 'usercss', $this->usercss
);
285 $tpl->setRef( 'userjs', $this->userjs
);
286 $tpl->setRef( 'userjsprev', $this->userjsprev
);
289 if($this->loggedin
) {
290 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
292 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
295 $tpl->set('jsvarurl', false);
297 $newtalks = $wgUser->getNewMessageLinks();
299 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
300 $usertitle = $this->mUser
->getUserPage();
301 $usertalktitle = $usertitle->getTalkPage();
302 if( !$usertalktitle->equals( $this->mTitle
) ) {
303 $ntl = wfMsg( 'youhavenewmessages',
304 $this->makeKnownLinkObj(
306 wfMsgHtml( 'newmessageslink' ),
309 $this->makeKnownLinkObj(
311 wfMsgHtml( 'newmessagesdifflink' ),
316 $wgOut->setSquidMaxage(0);
318 } else if (count($newtalks)) {
319 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
321 foreach ($newtalks as $newtalk) {
322 $msgs[] = wfElement("a",
323 array('href' => $newtalk["link"]), $newtalk["wiki"]);
325 $parts = implode($sep, $msgs);
326 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
327 $wgOut->setSquidMaxage(0);
331 wfProfileOut( "$fname-stuff2" );
333 wfProfileIn( "$fname-stuff3" );
334 $tpl->setRef( 'newtalk', $ntl );
335 $tpl->setRef( 'skin', $this);
336 $tpl->set( 'logo', $this->logoText() );
337 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
338 $wgArticle and 0 != $wgArticle->getID() )
340 if ( !$wgDisableCounters ) {
341 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
343 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
345 $tpl->set('viewcount', false);
348 $tpl->set('viewcount', false);
351 if ($wgPageShowWatchingUsers) {
352 $dbr =& wfGetDB( DB_SLAVE
);
353 $watchlist = $dbr->tableName( 'watchlist' );
354 $sql = "SELECT COUNT(*) AS n FROM $watchlist
355 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
356 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
357 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
358 $x = $dbr->fetchObject( $res );
359 $numberofwatchingusers = $x->n
;
360 if ($numberofwatchingusers > 0) {
361 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
363 $tpl->set('numberofwatchingusers', false);
366 $tpl->set('numberofwatchingusers', false);
369 $tpl->set('copyright',$this->getCopyright());
371 $this->credits
= false;
373 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
374 require_once("Credits.php");
375 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
377 $tpl->set('lastmod', $this->lastModified());
380 $tpl->setRef( 'credits', $this->credits
);
382 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
383 $tpl->set('copyright', $this->getCopyright());
384 $tpl->set('viewcount', false);
385 $tpl->set('lastmod', false);
386 $tpl->set('credits', false);
387 $tpl->set('numberofwatchingusers', false);
389 $tpl->set('copyright', false);
390 $tpl->set('viewcount', false);
391 $tpl->set('lastmod', false);
392 $tpl->set('credits', false);
393 $tpl->set('numberofwatchingusers', false);
395 wfProfileOut( "$fname-stuff3" );
397 wfProfileIn( "$fname-stuff4" );
398 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
399 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
400 $tpl->set( 'disclaimer', $this->disclaimerLink() );
401 $tpl->set( 'privacy', $this->privacyLink() );
402 $tpl->set( 'about', $this->aboutLink() );
404 $tpl->setRef( 'debug', $out->mDebugtext
);
405 $tpl->set( 'reporttime', $out->reportTime() );
406 $tpl->set( 'sitenotice', wfGetSiteNotice() );
407 $tpl->set( 'bottomscripts', $this->bottomScripts() );
409 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
410 $out->mBodytext
.= $printfooter ;
411 $tpl->setRef( 'bodytext', $out->mBodytext
);
414 $language_urls = array();
416 if ( !$wgHideInterlanguageLinks ) {
417 foreach( $wgOut->getLanguageLinks() as $l ) {
418 $tmp = explode( ':', $l, 2 );
419 $class = 'interwiki-' . $tmp[0];
421 $nt = Title
::newFromText( $l );
422 $language_urls[] = array(
423 'href' => $nt->getFullURL(),
424 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
429 if(count($language_urls)) {
430 $tpl->setRef( 'language_urls', $language_urls);
432 $tpl->set('language_urls', false);
434 wfProfileOut( "$fname-stuff4" );
437 $tpl->set('personal_urls', $this->buildPersonalUrls());
438 $content_actions = $this->buildContentActionUrls();
439 $tpl->setRef('content_actions', $content_actions);
441 // XXX: attach this from javascript, same with section editing
442 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
444 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
446 $tpl->set('body_ondblclick', false);
448 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
449 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
451 $tpl->set( 'body_onload', false );
453 $tpl->set( 'sidebar', $this->buildSidebar() );
454 $tpl->set( 'nav_urls', $this->buildNavUrls() );
457 wfProfileIn( "$fname-execute" );
458 $res = $tpl->execute();
459 wfProfileOut( "$fname-execute" );
461 // result may be an error
462 $this->printOrError( $res );
463 wfProfileOut( $fname );
467 * Output the string, or print error message if it's
468 * an error object of the appropriate type.
469 * For the base class, assume strings all around.
474 function printOrError( &$str ) {
479 * build array of urls for personal toolbar
483 function buildPersonalUrls() {
484 global $wgTitle, $wgShowIPinHeader;
486 $fname = 'SkinTemplate::buildPersonalUrls';
487 $pageurl = $wgTitle->getLocalURL();
488 wfProfileIn( $fname );
490 /* set up the default links for the personal toolbar */
491 $personal_urls = array();
492 if ($this->loggedin
) {
493 $personal_urls['userpage'] = array(
494 'text' => $this->username
,
495 'href' => &$this->userpageUrlDetails
['href'],
496 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
497 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
499 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
500 $personal_urls['mytalk'] = array(
501 'text' => wfMsg('mytalk'),
502 'href' => &$usertalkUrlDetails['href'],
503 'class' => $usertalkUrlDetails['exists']?
false:'new',
504 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
506 $href = self
::makeSpecialUrl( 'Preferences' );
507 $personal_urls['preferences'] = array(
508 'text' => wfMsg( 'mypreferences' ),
509 'href' => self
::makeSpecialUrl( 'Preferences' ),
510 'active' => ( $href == $pageurl )
512 $href = self
::makeSpecialUrl( 'Watchlist' );
513 $personal_urls['watchlist'] = array(
514 'text' => wfMsg( 'watchlist' ),
516 'active' => ( $href == $pageurl )
518 $href = self
::makeSpecialUrl( "Contributions/$this->username" );
519 $personal_urls['mycontris'] = array(
520 'text' => wfMsg( 'mycontris' ),
522 // FIXME # 'active' was disabed in r11346 with message: "disable bold link to my contributions; link was bold on all
523 // Special:Contributions, not just current user's (fix me please!)". Until resolved, explicitly setting active to false.
524 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
526 $personal_urls['logout'] = array(
527 'text' => wfMsg( 'userlogout' ),
528 'href' => self
::makeSpecialUrl( 'Userlogout',
529 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
534 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
535 $href = &$this->userpageUrlDetails
['href'];
536 $personal_urls['anonuserpage'] = array(
537 'text' => $this->username
,
539 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
540 'active' => ( $pageurl == $href )
542 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
543 $href = &$usertalkUrlDetails['href'];
544 $personal_urls['anontalk'] = array(
545 'text' => wfMsg('anontalk'),
547 'class' => $usertalkUrlDetails['exists']?
false:'new',
548 'active' => ( $pageurl == $href )
550 $personal_urls['anonlogin'] = array(
551 'text' => wfMsg('userlogin'),
552 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
553 'active' => $wgTitle->isSpecial( 'Userlogin' )
557 $personal_urls['login'] = array(
558 'text' => wfMsg('userlogin'),
559 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
560 'active' => $wgTitle->isSpecial( 'Userlogin' )
565 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
566 wfProfileOut( $fname );
567 return $personal_urls;
571 * Returns true if the IP should be shown in the header
573 function showIPinHeader() {
574 global $wgShowIPinHeader;
575 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
578 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
581 $classes[] = 'selected';
583 if( $checkEdit && $title->getArticleId() == 0 ) {
585 $query = 'action=edit';
588 $text = wfMsg( $message );
589 if ( wfEmptyMsg( $message, $text ) ) {
591 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
595 'class' => implode( ' ', $classes ),
597 'href' => $title->getLocalUrl( $query ) );
600 function makeTalkUrlDetails( $name, $urlaction = '' ) {
601 $title = Title
::newFromText( $name );
602 $title = $title->getTalkPage();
603 self
::checkTitle( $title, $name );
605 'href' => $title->getLocalURL( $urlaction ),
606 'exists' => $title->getArticleID() != 0 ?
true : false
610 function makeArticleUrlDetails( $name, $urlaction = '' ) {
611 $title = Title
::newFromText( $name );
612 $title= $title->getSubjectPage();
613 self
::checkTitle( $title, $name );
615 'href' => $title->getLocalURL( $urlaction ),
616 'exists' => $title->getArticleID() != 0 ?
true : false
621 * an array of edit links by default used for the tabs
625 function buildContentActionUrls () {
626 global $wgContLang, $wgOut;
627 $fname = 'SkinTemplate::buildContentActionUrls';
628 wfProfileIn( $fname );
630 global $wgUser, $wgRequest;
631 $action = $wgRequest->getText( 'action' );
632 $section = $wgRequest->getText( 'section' );
633 $content_actions = array();
635 $prevent_active_tabs = false ;
636 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
638 if( $this->iscontent
) {
639 $subjpage = $this->mTitle
->getSubjectPage();
640 $talkpage = $this->mTitle
->getTalkPage();
642 $nskey = $this->mTitle
->getNamespaceKey();
643 $content_actions[$nskey] = $this->tabAction(
646 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
649 $content_actions['talk'] = $this->tabAction(
652 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
656 wfProfileIn( "$fname-edit" );
657 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
658 $istalk = $this->mTitle
->isTalkPage();
659 $istalkclass = $istalk?
' istalk':'';
660 $content_actions['edit'] = array(
661 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
662 'text' => wfMsg('edit'),
663 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
666 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
667 $content_actions['addsection'] = array(
668 'class' => $section == 'new'?
'selected':false,
669 'text' => wfMsg('addsection'),
670 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
674 $content_actions['viewsource'] = array(
675 'class' => ($action == 'edit') ?
'selected' : false,
676 'text' => wfMsg('viewsource'),
677 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
680 wfProfileOut( "$fname-edit" );
682 wfProfileIn( "$fname-live" );
683 if ( $this->mTitle
->getArticleId() ) {
685 $content_actions['history'] = array(
686 'class' => ($action == 'history') ?
'selected' : false,
687 'text' => wfMsg('history_short'),
688 'href' => $this->mTitle
->getLocalUrl( 'action=history')
691 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
692 if(!$this->mTitle
->isProtected()){
693 $content_actions['protect'] = array(
694 'class' => ($action == 'protect') ?
'selected' : false,
695 'text' => wfMsg('protect'),
696 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
700 $content_actions['unprotect'] = array(
701 'class' => ($action == 'unprotect') ?
'selected' : false,
702 'text' => wfMsg('unprotect'),
703 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
707 if($wgUser->isAllowed('delete')){
708 $content_actions['delete'] = array(
709 'class' => ($action == 'delete') ?
'selected' : false,
710 'text' => wfMsg('delete'),
711 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
714 if ( $this->mTitle
->userCanMove()) {
715 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
716 $content_actions['move'] = array(
717 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
718 'text' => wfMsg('move'),
719 'href' => $moveTitle->getLocalUrl()
723 //article doesn't exist or is deleted
724 if( $wgUser->isAllowed( 'delete' ) ) {
725 if( $n = $this->mTitle
->isDeleted() ) {
726 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
727 $content_actions['undelete'] = array(
729 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
730 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
731 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
736 wfProfileOut( "$fname-live" );
738 if( $this->loggedin
) {
739 if( !$this->mTitle
->userIsWatching()) {
740 $content_actions['watch'] = array(
741 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
742 'text' => wfMsg('watch'),
743 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
746 $content_actions['unwatch'] = array(
747 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
748 'text' => wfMsg('unwatch'),
749 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
754 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
756 /* show special page tab */
758 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
759 'class' => 'selected',
760 'text' => wfMsg('specialpage'),
761 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
764 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
767 /* show links to different language variants */
768 global $wgDisableLangConversion;
769 $variants = $wgContLang->getVariants();
770 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
771 $preferred = $wgContLang->getPreferredVariant();
773 foreach( $variants as $code ) {
774 $varname = $wgContLang->getVariantname( $code );
775 if( $varname == 'disable' )
777 $selected = ( $code == $preferred )?
'selected' : false;
778 $content_actions['varlang-' . $vcount] = array(
779 'class' => $selected,
781 'href' => $this->mTitle
->getLocalURL('',$code)
787 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
789 wfProfileOut( $fname );
790 return $content_actions;
796 * build array of common navigation links
800 function buildNavUrls () {
801 global $wgUseTrackbacks, $wgTitle, $wgArticle;
803 $fname = 'SkinTemplate::buildNavUrls';
804 wfProfileIn( $fname );
806 global $wgUser, $wgRequest;
807 global $wgEnableUploads, $wgUploadNavigationUrl;
809 $action = $wgRequest->getText( 'action' );
810 $oldid = $wgRequest->getVal( 'oldid' );
813 $nav_urls['mainpage'] = array( 'href' => self
::makeI18nUrl( 'mainpage') );
814 if( $wgEnableUploads ) {
815 if ($wgUploadNavigationUrl) {
816 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
818 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
821 if ($wgUploadNavigationUrl)
822 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
824 $nav_urls['upload'] = false;
826 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
828 // default permalink to being off, will override it as required below.
829 $nav_urls['permalink'] = false;
831 // A print stylesheet is attached to all pages, but nobody ever
832 // figures that out. :) Add a link...
833 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
834 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
835 if ( !( $revid == 0 ) )
836 $nav_urls['print'] = array(
837 'text' => wfMsg( 'printableversion' ),
838 'href' => $wgRequest->appendQuery( 'printable=yes' )
841 // Also add a "permalink" while we're at it
843 $nav_urls['permalink'] = array(
844 'text' => wfMsg( 'permalink' ),
848 if ( !( $revid == 0 ) )
849 $nav_urls['permalink'] = array(
850 'text' => wfMsg( 'permalink' ),
851 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
855 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
858 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
859 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
860 $nav_urls['whatlinkshere'] = array(
861 'href' => $wlhTitle->getLocalUrl()
863 if( $this->mTitle
->getArticleId() ) {
864 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
865 $nav_urls['recentchangeslinked'] = array(
866 'href' => $rclTitle->getLocalUrl()
869 $nav_urls['recentchangeslinked'] = false;
871 if ($wgUseTrackbacks)
872 $nav_urls['trackbacklink'] = array(
873 'href' => $wgTitle->trackbackURL()
877 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
878 $id = User
::idFromName($this->mTitle
->getText());
879 $ip = User
::isIP($this->mTitle
->getText());
885 if($id ||
$ip) { # both anons and non-anons have contri list
886 $nav_urls['contributions'] = array(
887 'href' => self
::makeSpecialUrl( 'Contributions/' . $this->mTitle
->getText() )
889 if ( $wgUser->isAllowed( 'block' ) ) {
890 $nav_urls['blockip'] = array(
891 'href' => self
::makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
894 $nav_urls['blockip'] = false;
897 $nav_urls['contributions'] = false;
898 $nav_urls['blockip'] = false;
900 $nav_urls['emailuser'] = false;
901 if( $this->showEmailUser( $id ) ) {
902 $nav_urls['emailuser'] = array(
903 'href' => self
::makeSpecialUrl( 'Emailuser/' . $this->mTitle
->getText() )
906 wfProfileOut( $fname );
911 * Generate strings used for xml 'id' names
915 function getNameSpaceKey () {
916 return $this->mTitle
->getNamespaceKey();
922 function setupUserCss() {
923 $fname = 'SkinTemplate::setupUserCss';
924 wfProfileIn( $fname );
926 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
930 $siteargs = '&maxage=' . $wgSquidMaxage;
931 if( $this->loggedin
) {
932 // Ensure that logged-in users' generated CSS isn't clobbered
933 // by anons' publicly cacheable generated CSS.
934 $siteargs .= '&smaxage=0';
937 # Add user-specific code if this is a user and we allow that kind of thing
939 if ( $wgAllowUserCss && $this->loggedin
) {
940 $action = $wgRequest->getText('action');
942 # if we're previewing the CSS page, use it
943 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
944 $siteargs = "&smaxage=0&maxage=0";
945 $usercss = $wgRequest->getText('wpTextbox1');
947 $usercss = '@import "' .
948 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
949 'action=raw&ctype=text/css') . '";' ."\n";
952 $siteargs .= '&ts=' . $wgUser->mTouched
;
955 if( $wgContLang->isRTL() ) {
956 global $wgStyleVersion;
957 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
960 # If we use the site's dynamic CSS, throw that in, too
961 if ( $wgUseSiteCss ) {
962 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
963 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
964 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
965 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
968 # If we use any dynamic CSS, make a little CDATA block out of it.
970 if ( !empty($sitecss) ||
!empty($usercss) ) {
971 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
973 wfProfileOut( $fname );
979 function setupUserJs() {
980 $fname = 'SkinTemplate::setupUserJs';
981 wfProfileIn( $fname );
983 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
984 $action = $wgRequest->getText('action');
986 if( $wgAllowUserJs && $this->loggedin
) {
987 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
988 # XXX: additional security check/prompt?
989 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
991 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
994 wfProfileOut( $fname );
998 * Code for extensions to hook into to provide per-page CSS, see
999 * extensions/PageCSS/PageCSS.php for an implementation of this.
1003 function setupPageCss() {
1004 $fname = 'SkinTemplate::setupPageCss';
1005 wfProfileIn( $fname );
1007 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1009 wfProfileOut( $fname );
1014 * returns css with user-specific options
1018 function getUserStylesheet() {
1019 $fname = 'SkinTemplate::getUserStylesheet';
1020 wfProfileIn( $fname );
1022 $s = "/* generated user stylesheet */\n";
1023 $s .= $this->reallyDoGetUserStyles();
1024 wfProfileOut( $fname );
1029 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1030 * nated together. For some bizarre reason, it does *not* return any
1031 * custom user JS from subpages. Huh?
1033 * There's absolutely no reason to have separate Monobook/Common JSes.
1034 * Any JS that cares can just check the skin variable generated at the
1035 * top. For now Monobook.js will be maintained, but it should be consi-
1040 public function getUserJs() {
1041 $fname = 'SkinTemplate::getUserJs';
1042 wfProfileIn( $fname );
1044 $s = parent
::getUserJs();
1045 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1047 // avoid inclusion of non defined user JavaScript (with custom skins only)
1048 // by checking for default message content
1049 $msgKey = ucfirst($this->skinname
).'.js';
1050 $userJS = wfMsgForContent($msgKey);
1051 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1055 wfProfileOut( $fname );
1061 * Generic wrapper for template functions, with interface
1062 * compatible with what we use of PHPTAL 0.7.
1063 * @package MediaWiki
1066 class QuickTemplate
{
1070 function QuickTemplate() {
1071 $this->data
= array();
1072 $this->translator
= new MediaWiki_I18N();
1078 function set( $name, $value ) {
1079 $this->data
[$name] = $value;
1085 function setRef($name, &$value) {
1086 $this->data
[$name] =& $value;
1092 function setTranslator( &$t ) {
1093 $this->translator
= &$t;
1099 function execute() {
1100 echo "Override this function.";
1107 function text( $str ) {
1108 echo htmlspecialchars( $this->data
[$str] );
1114 function jstext( $str ) {
1115 echo Xml
::escapeJsString( $this->data
[$str] );
1121 function html( $str ) {
1122 echo $this->data
[$str];
1128 function msg( $str ) {
1129 echo htmlspecialchars( $this->translator
->translate( $str ) );
1135 function msgHtml( $str ) {
1136 echo $this->translator
->translate( $str );
1140 * An ugly, ugly hack.
1143 function msgWiki( $str ) {
1144 global $wgParser, $wgTitle, $wgOut;
1146 $text = $this->translator
->translate( $str );
1147 $parserOutput = $wgParser->parse( $text, $wgTitle,
1148 $wgOut->parserOptions(), true );
1149 echo $parserOutput->getText();
1155 function haveData( $str ) {
1156 return isset( $this->data
[$str] );
1162 function haveMsg( $str ) {
1163 $msg = $this->translator
->translate( $str );
1164 return ($msg != '-') && ($msg != ''); # ????