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 ) {
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', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
280 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
283 $tpl->set('jsvarurl', false);
285 $newtalks = $wgUser->getNewMessageLinks();
287 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
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
326 $wgArticle and 0 != $wgArticle->getID() )
328 if ( !$wgDisableCounters ) {
329 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
331 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
333 $tpl->set('viewcount', false);
336 $tpl->set('viewcount', false);
339 if ($wgPageShowWatchingUsers) {
340 $dbr =& wfGetDB( DB_SLAVE
);
341 extract( $dbr->tableNames( 'watchlist' ) );
342 $sql = "SELECT COUNT(*) AS n FROM $watchlist
343 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
344 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
345 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
346 $x = $dbr->fetchObject( $res );
347 $numberofwatchingusers = $x->n
;
348 if ($numberofwatchingusers > 0) {
349 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
351 $tpl->set('numberofwatchingusers', false);
354 $tpl->set('numberofwatchingusers', false);
357 $tpl->set('copyright',$this->getCopyright());
359 $this->credits
= false;
361 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
362 require_once("Credits.php");
363 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
365 $tpl->set('lastmod', $this->lastModified());
368 $tpl->setRef( 'credits', $this->credits
);
370 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
371 $tpl->set('copyright', $this->getCopyright());
372 $tpl->set('viewcount', false);
373 $tpl->set('lastmod', false);
374 $tpl->set('credits', false);
375 $tpl->set('numberofwatchingusers', false);
377 $tpl->set('copyright', false);
378 $tpl->set('viewcount', false);
379 $tpl->set('lastmod', false);
380 $tpl->set('credits', false);
381 $tpl->set('numberofwatchingusers', false);
383 wfProfileOut( "$fname-stuff3" );
385 wfProfileIn( "$fname-stuff4" );
386 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
387 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
388 $tpl->set( 'disclaimer', $this->disclaimerLink() );
389 $tpl->set( 'privacy', $this->privacyLink() );
390 $tpl->set( 'about', $this->aboutLink() );
392 $tpl->setRef( 'debug', $out->mDebugtext
);
393 $tpl->set( 'reporttime', $out->reportTime() );
394 $tpl->set( 'sitenotice', wfGetSiteNotice() );
395 $tpl->set( 'bottomscripts', $this->bottomScripts() );
397 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
398 $out->mBodytext
.= $printfooter ;
399 $tpl->setRef( 'bodytext', $out->mBodytext
);
402 $language_urls = array();
404 if ( !$wgHideInterlanguageLinks ) {
405 foreach( $wgOut->getLanguageLinks() as $l ) {
406 $tmp = explode( ':', $l, 2 );
407 $class = 'interwiki-' . $tmp[0];
409 $nt = Title
::newFromText( $l );
410 $language_urls[] = array(
411 'href' => $nt->getFullURL(),
412 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
417 if(count($language_urls)) {
418 $tpl->setRef( 'language_urls', $language_urls);
420 $tpl->set('language_urls', false);
422 wfProfileOut( "$fname-stuff4" );
425 $tpl->set('personal_urls', $this->buildPersonalUrls());
426 $content_actions = $this->buildContentActionUrls();
427 $tpl->setRef('content_actions', $content_actions);
429 // XXX: attach this from javascript, same with section editing
430 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
432 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
434 $tpl->set('body_ondblclick', false);
436 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
437 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
439 $tpl->set( 'body_onload', false );
441 $tpl->set( 'sidebar', $this->buildSidebar() );
442 $tpl->set( 'nav_urls', $this->buildNavUrls() );
445 wfProfileIn( "$fname-execute" );
446 $res = $tpl->execute();
447 wfProfileOut( "$fname-execute" );
449 // result may be an error
450 $this->printOrError( $res );
451 wfProfileOut( $fname );
455 * Output the string, or print error message if it's
456 * an error object of the appropriate type.
457 * For the base class, assume strings all around.
462 function printOrError( &$str ) {
467 * build array of urls for personal toolbar
471 function buildPersonalUrls() {
472 global $wgTitle, $wgShowIPinHeader;
474 $fname = 'SkinTemplate::buildPersonalUrls';
475 $pageurl = $wgTitle->getLocalURL();
476 wfProfileIn( $fname );
478 /* set up the default links for the personal toolbar */
479 $personal_urls = array();
480 if ($this->loggedin
) {
481 $personal_urls['userpage'] = array(
482 'text' => $this->username
,
483 'href' => &$this->userpageUrlDetails
['href'],
484 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
485 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
487 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
488 $personal_urls['mytalk'] = array(
489 'text' => wfMsg('mytalk'),
490 'href' => &$usertalkUrlDetails['href'],
491 'class' => $usertalkUrlDetails['exists']?
false:'new',
492 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
494 $href = self
::makeSpecialUrl( 'Preferences' );
495 $personal_urls['preferences'] = array(
496 'text' => wfMsg( 'mypreferences' ),
497 'href' => self
::makeSpecialUrl( 'Preferences' ),
498 'active' => ( $href == $pageurl )
500 $href = self
::makeSpecialUrl( 'Watchlist' );
501 $personal_urls['watchlist'] = array(
502 'text' => wfMsg( 'watchlist' ),
504 'active' => ( $href == $pageurl )
506 $href = self
::makeSpecialUrl( "Contributions/$this->username" );
507 $personal_urls['mycontris'] = array(
508 'text' => wfMsg( 'mycontris' ),
510 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
512 $personal_urls['logout'] = array(
513 'text' => wfMsg( 'userlogout' ),
514 'href' => self
::makeSpecialUrl( 'Userlogout',
515 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
519 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
520 $href = &$this->userpageUrlDetails
['href'];
521 $personal_urls['anonuserpage'] = array(
522 'text' => $this->username
,
524 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
525 'active' => ( $pageurl == $href )
527 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
528 $href = &$usertalkUrlDetails['href'];
529 $personal_urls['anontalk'] = array(
530 'text' => wfMsg('anontalk'),
532 'class' => $usertalkUrlDetails['exists']?
false:'new',
533 'active' => ( $pageurl == $href )
535 $personal_urls['anonlogin'] = array(
536 'text' => wfMsg('userlogin'),
537 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
538 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
542 $personal_urls['login'] = array(
543 'text' => wfMsg('userlogin'),
544 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
545 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
550 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
551 wfProfileOut( $fname );
552 return $personal_urls;
556 * Returns true if the IP should be shown in the header
558 function showIPinHeader() {
559 global $wgShowIPinHeader;
560 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
563 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
566 $classes[] = 'selected';
568 if( $checkEdit && $title->getArticleId() == 0 ) {
570 $query = 'action=edit';
573 $text = wfMsg( $message );
574 if ( wfEmptyMsg( $message, $text ) ) {
576 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
580 'class' => implode( ' ', $classes ),
582 'href' => $title->getLocalUrl( $query ) );
585 function makeTalkUrlDetails( $name, $urlaction = '' ) {
586 $title = Title
::newFromText( $name );
587 $title = $title->getTalkPage();
588 self
::checkTitle( $title, $name );
590 'href' => $title->getLocalURL( $urlaction ),
591 'exists' => $title->getArticleID() != 0 ?
true : false
595 function makeArticleUrlDetails( $name, $urlaction = '' ) {
596 $title = Title
::newFromText( $name );
597 $title= $title->getSubjectPage();
598 self
::checkTitle( $title, $name );
600 'href' => $title->getLocalURL( $urlaction ),
601 'exists' => $title->getArticleID() != 0 ?
true : false
606 * an array of edit links by default used for the tabs
610 function buildContentActionUrls () {
611 global $wgContLang, $wgOut;
612 $fname = 'SkinTemplate::buildContentActionUrls';
613 wfProfileIn( $fname );
615 global $wgUser, $wgRequest;
616 $action = $wgRequest->getText( 'action' );
617 $section = $wgRequest->getText( 'section' );
618 $content_actions = array();
620 $prevent_active_tabs = false ;
621 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
623 if( $this->iscontent
) {
624 $subjpage = $this->mTitle
->getSubjectPage();
625 $talkpage = $this->mTitle
->getTalkPage();
627 $nskey = $this->mTitle
->getNamespaceKey();
628 $content_actions[$nskey] = $this->tabAction(
631 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
634 $content_actions['talk'] = $this->tabAction(
637 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
641 wfProfileIn( "$fname-edit" );
642 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
643 $istalk = $this->mTitle
->isTalkPage();
644 $istalkclass = $istalk?
' istalk':'';
645 $content_actions['edit'] = array(
646 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
647 'text' => wfMsg('edit'),
648 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
651 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
652 $content_actions['addsection'] = array(
653 'class' => $section == 'new'?
'selected':false,
654 'text' => wfMsg('addsection'),
655 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
659 $content_actions['viewsource'] = array(
660 'class' => ($action == 'edit') ?
'selected' : false,
661 'text' => wfMsg('viewsource'),
662 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
665 wfProfileOut( "$fname-edit" );
667 wfProfileIn( "$fname-live" );
668 if ( $this->mTitle
->getArticleId() ) {
670 $content_actions['history'] = array(
671 'class' => ($action == 'history') ?
'selected' : false,
672 'text' => wfMsg('history_short'),
673 'href' => $this->mTitle
->getLocalUrl( 'action=history')
676 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
677 if(!$this->mTitle
->isProtected()){
678 $content_actions['protect'] = array(
679 'class' => ($action == 'protect') ?
'selected' : false,
680 'text' => wfMsg('protect'),
681 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
685 $content_actions['unprotect'] = array(
686 'class' => ($action == 'unprotect') ?
'selected' : false,
687 'text' => wfMsg('unprotect'),
688 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
692 if($wgUser->isAllowed('delete')){
693 $content_actions['delete'] = array(
694 'class' => ($action == 'delete') ?
'selected' : false,
695 'text' => wfMsg('delete'),
696 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
699 if ( $this->mTitle
->userCanMove()) {
700 $moveTitle = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
701 $content_actions['move'] = array(
702 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
703 'text' => wfMsg('move'),
704 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
708 //article doesn't exist or is deleted
709 if( $wgUser->isAllowed( 'delete' ) ) {
710 if( $n = $this->mTitle
->isDeleted() ) {
711 $undelTitle = Title
::makeTitle( NS_SPECIAL
, 'Undelete' );
712 $content_actions['undelete'] = array(
714 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
715 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
716 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
721 wfProfileOut( "$fname-live" );
723 if( $this->loggedin
) {
724 if( !$this->mTitle
->userIsWatching()) {
725 $content_actions['watch'] = array(
726 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
727 'text' => wfMsg('watch'),
728 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
731 $content_actions['unwatch'] = array(
732 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
733 'text' => wfMsg('unwatch'),
734 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
739 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
741 /* show special page tab */
743 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
744 'class' => 'selected',
745 'text' => wfMsg('specialpage'),
746 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
749 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
752 /* show links to different language variants */
753 global $wgDisableLangConversion;
754 $variants = $wgContLang->getVariants();
755 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
756 $preferred = $wgContLang->getPreferredVariant();
759 $actstr = 'action=' . $action . '&';
761 foreach( $variants as $code ) {
762 $varname = $wgContLang->getVariantname( $code );
763 if( $varname == 'disable' )
765 $selected = ( $code == $preferred )?
'selected' : false;
766 $content_actions['varlang-' . $vcount] = array(
767 'class' => $selected,
769 'href' => $this->mTitle
->getLocalURL('',$code)
775 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
777 wfProfileOut( $fname );
778 return $content_actions;
784 * build array of common navigation links
788 function buildNavUrls () {
789 global $wgUseTrackbacks, $wgTitle, $wgArticle;
791 $fname = 'SkinTemplate::buildNavUrls';
792 wfProfileIn( $fname );
794 global $wgUser, $wgRequest;
795 global $wgEnableUploads, $wgUploadNavigationUrl;
797 $action = $wgRequest->getText( 'action' );
798 $oldid = $wgRequest->getVal( 'oldid' );
799 $diff = $wgRequest->getVal( 'diff' );
802 $nav_urls['mainpage'] = array( 'href' => self
::makeI18nUrl( 'mainpage') );
803 if( $wgEnableUploads ) {
804 if ($wgUploadNavigationUrl) {
805 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
807 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
810 if ($wgUploadNavigationUrl)
811 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
813 $nav_urls['upload'] = false;
815 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
818 // A print stylesheet is attached to all pages, but nobody ever
819 // figures that out. :) Add a link...
820 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
821 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
822 if ( !( $revid == 0 ) )
823 $nav_urls['print'] = array(
824 'text' => wfMsg( 'printableversion' ),
825 'href' => $wgRequest->appendQuery( 'printable=yes' )
828 // Also add a "permalink" while we're at it
830 $nav_urls['permalink'] = array(
831 'text' => wfMsg( 'permalink' ),
835 if ( !( $revid == 0 ) )
836 $nav_urls['permalink'] = array(
837 'text' => wfMsg( 'permalink' ),
838 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
842 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
845 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
846 $wlhTitle = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
847 $nav_urls['whatlinkshere'] = array(
848 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
850 if( $this->mTitle
->getArticleId() ) {
851 $rclTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchangeslinked' );
852 $nav_urls['recentchangeslinked'] = array(
853 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
856 if ($wgUseTrackbacks)
857 $nav_urls['trackbacklink'] = array(
858 'href' => $wgTitle->trackbackURL()
862 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
863 $id = User
::idFromName($this->mTitle
->getText());
864 $ip = User
::isIP($this->mTitle
->getText());
870 if($id ||
$ip) { # both anons and non-anons have contri list
871 $nav_urls['contributions'] = array(
872 'href' => self
::makeSpecialUrl( 'Contributions/' . $this->mTitle
->getText() )
874 if ( $wgUser->isAllowed( 'block' ) )
875 $nav_urls['blockip'] = array(
876 'href' => self
::makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
879 $nav_urls['contributions'] = false;
881 $nav_urls['emailuser'] = false;
882 if( $this->showEmailUser( $id ) ) {
883 $nav_urls['emailuser'] = array(
884 'href' => self
::makeSpecialUrl( 'Emailuser/' . $this->mTitle
->getText() )
887 wfProfileOut( $fname );
892 * Generate strings used for xml 'id' names
896 function getNameSpaceKey () {
897 return $this->mTitle
->getNamespaceKey();
903 function setupUserCss() {
904 $fname = 'SkinTemplate::setupUserCss';
905 wfProfileIn( $fname );
907 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
911 $siteargs = '&maxage=' . $wgSquidMaxage;
912 if( $this->loggedin
) {
913 // Ensure that logged-in users' generated CSS isn't clobbered
914 // by anons' publicly cacheable generated CSS.
915 $siteargs .= '&smaxage=0';
918 # Add user-specific code if this is a user and we allow that kind of thing
920 if ( $wgAllowUserCss && $this->loggedin
) {
921 $action = $wgRequest->getText('action');
923 # if we're previewing the CSS page, use it
924 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
925 $siteargs = "&smaxage=0&maxage=0";
926 $usercss = $wgRequest->getText('wpTextbox1');
928 $usercss = '@import "' .
929 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
930 'action=raw&ctype=text/css') . '";' ."\n";
933 $siteargs .= '&ts=' . $wgUser->mTouched
;
936 if( $wgContLang->isRTL() ) {
937 global $wgStyleVersion;
938 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
941 # If we use the site's dynamic CSS, throw that in, too
942 if ( $wgUseSiteCss ) {
943 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
944 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
945 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
946 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
949 # If we use any dynamic CSS, make a little CDATA block out of it.
951 if ( !empty($sitecss) ||
!empty($usercss) ) {
952 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
954 wfProfileOut( $fname );
960 function setupUserJs() {
961 $fname = 'SkinTemplate::setupUserJs';
962 wfProfileIn( $fname );
964 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
965 $action = $wgRequest->getText('action');
967 if( $wgAllowUserJs && $this->loggedin
) {
968 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
969 # XXX: additional security check/prompt?
970 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
972 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
975 wfProfileOut( $fname );
979 * Code for extensions to hook into to provide per-page CSS, see
980 * extensions/PageCSS/PageCSS.php for an implementation of this.
984 function setupPageCss() {
985 $fname = 'SkinTemplate::setupPageCss';
986 wfProfileIn( $fname );
988 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
990 wfProfileOut( $fname );
995 * returns css with user-specific options
999 function getUserStylesheet() {
1000 $fname = 'SkinTemplate::getUserStylesheet';
1001 wfProfileIn( $fname );
1003 $s = "/* generated user stylesheet */\n";
1004 $s .= $this->reallyDoGetUserStyles();
1005 wfProfileOut( $fname );
1012 function getUserJs() {
1013 $fname = 'SkinTemplate::getUserJs';
1014 wfProfileIn( $fname );
1016 global $wgStylePath;
1017 $s = '/* generated javascript */';
1018 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1019 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1021 // avoid inclusion of non defined user JavaScript (with custom skins only)
1022 // by checking for default message content
1023 $msgKey = ucfirst($this->skinname
).'.js';
1024 $userJS = wfMsgForContent($msgKey);
1025 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1029 wfProfileOut( $fname );
1035 * Generic wrapper for template functions, with interface
1036 * compatible with what we use of PHPTAL 0.7.
1037 * @package MediaWiki
1040 class QuickTemplate
{
1044 function QuickTemplate() {
1045 $this->data
= array();
1046 $this->translator
= new MediaWiki_I18N();
1052 function set( $name, $value ) {
1053 $this->data
[$name] = $value;
1059 function setRef($name, &$value) {
1060 $this->data
[$name] =& $value;
1066 function setTranslator( &$t ) {
1067 $this->translator
= &$t;
1073 function execute() {
1074 echo "Override this function.";
1081 function text( $str ) {
1082 echo htmlspecialchars( $this->data
[$str] );
1088 function jstext( $str ) {
1089 echo Xml
::escapeJsString( $this->data
[$str] );
1095 function html( $str ) {
1096 echo $this->data
[$str];
1102 function msg( $str ) {
1103 echo htmlspecialchars( $this->translator
->translate( $str ) );
1109 function msgHtml( $str ) {
1110 echo $this->translator
->translate( $str );
1114 * An ugly, ugly hack.
1117 function msgWiki( $str ) {
1118 global $wgParser, $wgTitle, $wgOut;
1120 $text = $this->translator
->translate( $str );
1121 $parserOutput = $wgParser->parse( $text, $wgTitle,
1122 $wgOut->parserOptions(), true );
1123 echo $parserOutput->getText();
1129 function haveData( $str ) {
1130 return $this->data
[$str];
1136 function haveMsg( $str ) {
1137 $msg = $this->translator
->translate( $str );
1138 return ($msg != '-') && ($msg != ''); # ????