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
);
194 $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ];
195 if ( $nsname === NULL ) $nsname = $this->mTitle
->getNsText();
197 $tpl->set( 'nscanonical', $nsname );
198 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle
->getText() );
201 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
202 $tpl->set( 'isarticle', $wgOut->isArticle() );
204 $tpl->setRef( "thispage", $this->thispage
);
205 $subpagestr = $this->subPageSubtitle();
207 'subtitle', !empty($subpagestr)?
208 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
211 $undelete = $this->getUndeleteLink();
213 "undelete", !empty($undelete)?
214 '<span class="subpages">'.$undelete.'</span>':
218 $tpl->set( 'catlinks', $this->getCategories());
219 if( $wgOut->isSyndicated() ) {
221 foreach( $wgFeedClasses as $format => $class ) {
222 $feeds[$format] = array(
224 'href' => $wgRequest->appendQuery( "feed=$format" )
227 $tpl->setRef( 'feeds', $feeds );
229 $tpl->set( 'feeds', false );
231 if ($wgUseTrackbacks && $out->isArticleRelated())
232 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
234 $tpl->setRef( 'mimetype', $wgMimeType );
235 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
236 $tpl->setRef( 'charset', $wgOutputEncoding );
237 $tpl->set( 'headlinks', $out->getHeadLinks() );
238 $tpl->set('headscripts', $out->getScript() );
239 $tpl->setRef( 'wgScript', $wgScript );
240 $tpl->setRef( 'skinname', $this->skinname
);
241 $tpl->set( 'skinclass', get_class( $this ) );
242 $tpl->setRef( 'stylename', $this->stylename
);
243 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
244 $tpl->setRef( 'loggedin', $this->loggedin
);
245 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
246 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
247 /* XXX currently unused, might get useful later
248 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
249 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
250 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
251 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
252 $tpl->set( "helppage", wfMsg('helppage'));
254 $tpl->set( 'searchaction', $this->escapeSearchLink() );
255 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
256 $tpl->setRef( 'stylepath', $wgStylePath );
257 $tpl->setRef( 'articlepath', $wgArticlePath );
258 $tpl->setRef( 'scriptpath', $wgScriptPath );
259 $tpl->setRef( 'serverurl', $wgServer );
260 $tpl->setRef( 'logopath', $wgLogo );
261 $tpl->setRef( "lang", $wgContLanguageCode );
262 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
263 $tpl->set( 'rtl', $wgContLang->isRTL() );
264 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
265 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
266 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
267 $tpl->setRef( 'userpage', $this->userpage
);
268 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
269 $tpl->set( 'userlang', $wgLang->getCode() );
270 $tpl->set( 'pagecss', $this->setupPageCss() );
271 $tpl->setRef( 'usercss', $this->usercss
);
272 $tpl->setRef( 'userjs', $this->userjs
);
273 $tpl->setRef( 'userjsprev', $this->userjsprev
);
276 if($this->loggedin
) {
277 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
279 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
282 $tpl->set('jsvarurl', false);
284 $newtalks = $wgUser->getNewMessageLinks();
286 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
287 $usertitle = $this->mUser
->getUserPage();
288 $usertalktitle = $usertitle->getTalkPage();
289 if( !$usertalktitle->equals( $this->mTitle
) ) {
290 $ntl = wfMsg( 'youhavenewmessages',
291 $this->makeKnownLinkObj(
293 wfMsgHtml( 'newmessageslink' ),
296 $this->makeKnownLinkObj(
298 wfMsgHtml( 'newmessagesdifflink' ),
303 $wgOut->setSquidMaxage(0);
305 } else if (count($newtalks)) {
306 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
308 foreach ($newtalks as $newtalk) {
309 $msgs[] = wfElement("a",
310 array('href' => $newtalk["link"]), $newtalk["wiki"]);
312 $parts = implode($sep, $msgs);
313 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
314 $wgOut->setSquidMaxage(0);
318 wfProfileOut( "$fname-stuff2" );
320 wfProfileIn( "$fname-stuff3" );
321 $tpl->setRef( 'newtalk', $ntl );
322 $tpl->setRef( 'skin', $this);
323 $tpl->set( 'logo', $this->logoText() );
324 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
325 $wgArticle and 0 != $wgArticle->getID() )
327 if ( !$wgDisableCounters ) {
328 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
330 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
332 $tpl->set('viewcount', false);
335 $tpl->set('viewcount', false);
338 if ($wgPageShowWatchingUsers) {
339 $dbr =& wfGetDB( DB_SLAVE
);
340 extract( $dbr->tableNames( 'watchlist' ) );
341 $sql = "SELECT COUNT(*) AS n FROM $watchlist
342 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
343 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
344 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
345 $x = $dbr->fetchObject( $res );
346 $numberofwatchingusers = $x->n
;
347 if ($numberofwatchingusers > 0) {
348 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
350 $tpl->set('numberofwatchingusers', false);
353 $tpl->set('numberofwatchingusers', false);
356 $tpl->set('copyright',$this->getCopyright());
358 $this->credits
= false;
360 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
361 require_once("Credits.php");
362 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
364 $tpl->set('lastmod', $this->lastModified());
367 $tpl->setRef( 'credits', $this->credits
);
369 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
370 $tpl->set('copyright', $this->getCopyright());
371 $tpl->set('viewcount', false);
372 $tpl->set('lastmod', false);
373 $tpl->set('credits', false);
374 $tpl->set('numberofwatchingusers', false);
376 $tpl->set('copyright', false);
377 $tpl->set('viewcount', false);
378 $tpl->set('lastmod', false);
379 $tpl->set('credits', false);
380 $tpl->set('numberofwatchingusers', false);
382 wfProfileOut( "$fname-stuff3" );
384 wfProfileIn( "$fname-stuff4" );
385 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
386 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
387 $tpl->set( 'disclaimer', $this->disclaimerLink() );
388 $tpl->set( 'privacy', $this->privacyLink() );
389 $tpl->set( 'about', $this->aboutLink() );
391 $tpl->setRef( 'debug', $out->mDebugtext
);
392 $tpl->set( 'reporttime', $out->reportTime() );
393 $tpl->set( 'sitenotice', wfGetSiteNotice() );
394 $tpl->set( 'bottomscripts', $this->bottomScripts() );
396 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
397 $out->mBodytext
.= $printfooter ;
398 $tpl->setRef( 'bodytext', $out->mBodytext
);
401 $language_urls = array();
403 if ( !$wgHideInterlanguageLinks ) {
404 foreach( $wgOut->getLanguageLinks() as $l ) {
405 $tmp = explode( ':', $l, 2 );
406 $class = 'interwiki-' . $tmp[0];
408 $nt = Title
::newFromText( $l );
409 $language_urls[] = array(
410 'href' => $nt->getFullURL(),
411 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
416 if(count($language_urls)) {
417 $tpl->setRef( 'language_urls', $language_urls);
419 $tpl->set('language_urls', false);
421 wfProfileOut( "$fname-stuff4" );
424 $tpl->set('personal_urls', $this->buildPersonalUrls());
425 $content_actions = $this->buildContentActionUrls();
426 $tpl->setRef('content_actions', $content_actions);
428 // XXX: attach this from javascript, same with section editing
429 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
431 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
433 $tpl->set('body_ondblclick', false);
435 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
436 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
438 $tpl->set( 'body_onload', false );
440 $tpl->set( 'sidebar', $this->buildSidebar() );
441 $tpl->set( 'nav_urls', $this->buildNavUrls() );
444 wfProfileIn( "$fname-execute" );
445 $res = $tpl->execute();
446 wfProfileOut( "$fname-execute" );
448 // result may be an error
449 $this->printOrError( $res );
450 wfProfileOut( $fname );
454 * Output the string, or print error message if it's
455 * an error object of the appropriate type.
456 * For the base class, assume strings all around.
461 function printOrError( &$str ) {
466 * build array of urls for personal toolbar
470 function buildPersonalUrls() {
471 global $wgTitle, $wgShowIPinHeader;
473 $fname = 'SkinTemplate::buildPersonalUrls';
474 $pageurl = $wgTitle->getLocalURL();
475 wfProfileIn( $fname );
477 /* set up the default links for the personal toolbar */
478 $personal_urls = array();
479 if ($this->loggedin
) {
480 $personal_urls['userpage'] = array(
481 'text' => $this->username
,
482 'href' => &$this->userpageUrlDetails
['href'],
483 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
484 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
486 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
487 $personal_urls['mytalk'] = array(
488 'text' => wfMsg('mytalk'),
489 'href' => &$usertalkUrlDetails['href'],
490 'class' => $usertalkUrlDetails['exists']?
false:'new',
491 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
493 $href = self
::makeSpecialUrl( 'Preferences' );
494 $personal_urls['preferences'] = array(
495 'text' => wfMsg( 'mypreferences' ),
496 'href' => self
::makeSpecialUrl( 'Preferences' ),
497 'active' => ( $href == $pageurl )
499 $href = self
::makeSpecialUrl( 'Watchlist' );
500 $personal_urls['watchlist'] = array(
501 'text' => wfMsg( 'watchlist' ),
503 'active' => ( $href == $pageurl )
505 $href = self
::makeSpecialUrl( "Contributions/$this->username" );
506 $personal_urls['mycontris'] = array(
507 'text' => wfMsg( 'mycontris' ),
509 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
511 $personal_urls['logout'] = array(
512 'text' => wfMsg( 'userlogout' ),
513 'href' => self
::makeSpecialUrl( 'Userlogout',
514 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
518 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
519 $href = &$this->userpageUrlDetails
['href'];
520 $personal_urls['anonuserpage'] = array(
521 'text' => $this->username
,
523 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
524 'active' => ( $pageurl == $href )
526 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
527 $href = &$usertalkUrlDetails['href'];
528 $personal_urls['anontalk'] = array(
529 'text' => wfMsg('anontalk'),
531 'class' => $usertalkUrlDetails['exists']?
false:'new',
532 'active' => ( $pageurl == $href )
534 $personal_urls['anonlogin'] = array(
535 'text' => wfMsg('userlogin'),
536 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
537 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
541 $personal_urls['login'] = array(
542 'text' => wfMsg('userlogin'),
543 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
544 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
549 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
550 wfProfileOut( $fname );
551 return $personal_urls;
555 * Returns true if the IP should be shown in the header
557 function showIPinHeader() {
558 global $wgShowIPinHeader;
559 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
562 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
565 $classes[] = 'selected';
567 if( $checkEdit && $title->getArticleId() == 0 ) {
569 $query = 'action=edit';
572 $text = wfMsg( $message );
573 if ( wfEmptyMsg( $message, $text ) ) {
575 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
579 'class' => implode( ' ', $classes ),
581 'href' => $title->getLocalUrl( $query ) );
584 function makeTalkUrlDetails( $name, $urlaction = '' ) {
585 $title = Title
::newFromText( $name );
586 $title = $title->getTalkPage();
587 self
::checkTitle( $title, $name );
589 'href' => $title->getLocalURL( $urlaction ),
590 'exists' => $title->getArticleID() != 0 ?
true : false
594 function makeArticleUrlDetails( $name, $urlaction = '' ) {
595 $title = Title
::newFromText( $name );
596 $title= $title->getSubjectPage();
597 self
::checkTitle( $title, $name );
599 'href' => $title->getLocalURL( $urlaction ),
600 'exists' => $title->getArticleID() != 0 ?
true : false
605 * an array of edit links by default used for the tabs
609 function buildContentActionUrls () {
610 global $wgContLang, $wgOut;
611 $fname = 'SkinTemplate::buildContentActionUrls';
612 wfProfileIn( $fname );
614 global $wgUser, $wgRequest;
615 $action = $wgRequest->getText( 'action' );
616 $section = $wgRequest->getText( 'section' );
617 $content_actions = array();
619 $prevent_active_tabs = false ;
620 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
622 if( $this->iscontent
) {
623 $subjpage = $this->mTitle
->getSubjectPage();
624 $talkpage = $this->mTitle
->getTalkPage();
626 $nskey = $this->mTitle
->getNamespaceKey();
627 $content_actions[$nskey] = $this->tabAction(
630 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
633 $content_actions['talk'] = $this->tabAction(
636 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
640 wfProfileIn( "$fname-edit" );
641 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
642 $istalk = $this->mTitle
->isTalkPage();
643 $istalkclass = $istalk?
' istalk':'';
644 $content_actions['edit'] = array(
645 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
646 'text' => wfMsg('edit'),
647 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
650 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
651 $content_actions['addsection'] = array(
652 'class' => $section == 'new'?
'selected':false,
653 'text' => wfMsg('addsection'),
654 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
658 $content_actions['viewsource'] = array(
659 'class' => ($action == 'edit') ?
'selected' : false,
660 'text' => wfMsg('viewsource'),
661 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
664 wfProfileOut( "$fname-edit" );
666 wfProfileIn( "$fname-live" );
667 if ( $this->mTitle
->getArticleId() ) {
669 $content_actions['history'] = array(
670 'class' => ($action == 'history') ?
'selected' : false,
671 'text' => wfMsg('history_short'),
672 'href' => $this->mTitle
->getLocalUrl( 'action=history')
675 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
676 if(!$this->mTitle
->isProtected()){
677 $content_actions['protect'] = array(
678 'class' => ($action == 'protect') ?
'selected' : false,
679 'text' => wfMsg('protect'),
680 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
684 $content_actions['unprotect'] = array(
685 'class' => ($action == 'unprotect') ?
'selected' : false,
686 'text' => wfMsg('unprotect'),
687 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
691 if($wgUser->isAllowed('delete')){
692 $content_actions['delete'] = array(
693 'class' => ($action == 'delete') ?
'selected' : false,
694 'text' => wfMsg('delete'),
695 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
698 if ( $this->mTitle
->userCanMove()) {
699 $moveTitle = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
700 $content_actions['move'] = array(
701 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
702 'text' => wfMsg('move'),
703 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
707 //article doesn't exist or is deleted
708 if( $wgUser->isAllowed( 'delete' ) ) {
709 if( $n = $this->mTitle
->isDeleted() ) {
710 $undelTitle = Title
::makeTitle( NS_SPECIAL
, 'Undelete' );
711 $content_actions['undelete'] = array(
713 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
714 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
715 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
720 wfProfileOut( "$fname-live" );
722 if( $this->loggedin
) {
723 if( !$this->mTitle
->userIsWatching()) {
724 $content_actions['watch'] = array(
725 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
726 'text' => wfMsg('watch'),
727 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
730 $content_actions['unwatch'] = array(
731 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
732 'text' => wfMsg('unwatch'),
733 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
738 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
740 /* show special page tab */
742 $content_actions['article'] = array(
743 'class' => 'selected',
744 'text' => wfMsg('specialpage'),
745 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
748 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
751 /* show links to different language variants */
752 global $wgDisableLangConversion;
753 $variants = $wgContLang->getVariants();
754 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
755 $preferred = $wgContLang->getPreferredVariant();
758 $actstr = 'action=' . $action . '&';
760 foreach( $variants as $code ) {
761 $varname = $wgContLang->getVariantname( $code );
762 if( $varname == 'disable' )
764 $selected = ( $code == $preferred )?
'selected' : false;
765 $content_actions['varlang-' . $vcount] = array(
766 'class' => $selected,
768 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
774 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
776 wfProfileOut( $fname );
777 return $content_actions;
783 * build array of common navigation links
787 function buildNavUrls () {
788 global $wgUseTrackbacks, $wgTitle, $wgArticle;
790 $fname = 'SkinTemplate::buildNavUrls';
791 wfProfileIn( $fname );
793 global $wgUser, $wgRequest;
794 global $wgEnableUploads, $wgUploadNavigationUrl;
796 $action = $wgRequest->getText( 'action' );
797 $oldid = $wgRequest->getVal( 'oldid' );
798 $diff = $wgRequest->getVal( 'diff' );
801 $nav_urls['mainpage'] = array( 'href' => self
::makeI18nUrl( 'mainpage') );
802 if( $wgEnableUploads ) {
803 if ($wgUploadNavigationUrl) {
804 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
806 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
809 if ($wgUploadNavigationUrl)
810 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
812 $nav_urls['upload'] = false;
814 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
817 // A print stylesheet is attached to all pages, but nobody ever
818 // figures that out. :) Add a link...
819 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
820 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
821 if ( !( $revid == 0 ) )
822 $nav_urls['print'] = array(
823 'text' => wfMsg( 'printableversion' ),
824 'href' => $wgRequest->appendQuery( 'printable=yes' )
827 // Also add a "permalink" while we're at it
829 $nav_urls['permalink'] = array(
830 'text' => wfMsg( 'permalink' ),
834 if ( !( $revid == 0 ) )
835 $nav_urls['permalink'] = array(
836 'text' => wfMsg( 'permalink' ),
837 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
841 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
844 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
845 $wlhTitle = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
846 $nav_urls['whatlinkshere'] = array(
847 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
849 if( $this->mTitle
->getArticleId() ) {
850 $rclTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchangeslinked' );
851 $nav_urls['recentchangeslinked'] = array(
852 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
855 if ($wgUseTrackbacks)
856 $nav_urls['trackbacklink'] = array(
857 'href' => $wgTitle->trackbackURL()
861 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
862 $id = User
::idFromName($this->mTitle
->getText());
863 $ip = User
::isIP($this->mTitle
->getText());
869 if($id ||
$ip) { # both anons and non-anons have contri list
870 $nav_urls['contributions'] = array(
871 'href' => self
::makeSpecialUrl( 'Contributions/' . $this->mTitle
->getText() )
873 if ( $wgUser->isAllowed( 'block' ) )
874 $nav_urls['blockip'] = array(
875 'href' => self
::makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
878 $nav_urls['contributions'] = false;
880 $nav_urls['emailuser'] = false;
881 if( $this->showEmailUser( $id ) ) {
882 $nav_urls['emailuser'] = array(
883 'href' => self
::makeSpecialUrl( 'Emailuser/' . $this->mTitle
->getText() )
886 wfProfileOut( $fname );
891 * Generate strings used for xml 'id' names
895 function getNameSpaceKey () {
896 return $this->mTitle
->getNamespaceKey();
902 function setupUserCss() {
903 $fname = 'SkinTemplate::setupUserCss';
904 wfProfileIn( $fname );
906 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
910 $siteargs = '&maxage=' . $wgSquidMaxage;
911 if( $this->loggedin
) {
912 // Ensure that logged-in users' generated CSS isn't clobbered
913 // by anons' publicly cacheable generated CSS.
914 $siteargs .= '&smaxage=0';
917 # Add user-specific code if this is a user and we allow that kind of thing
919 if ( $wgAllowUserCss && $this->loggedin
) {
920 $action = $wgRequest->getText('action');
922 # if we're previewing the CSS page, use it
923 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
924 $siteargs = "&smaxage=0&maxage=0";
925 $usercss = $wgRequest->getText('wpTextbox1');
927 $usercss = '@import "' .
928 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
929 'action=raw&ctype=text/css') . '";' ."\n";
932 $siteargs .= '&ts=' . $wgUser->mTouched
;
935 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
937 # If we use the site's dynamic CSS, throw that in, too
938 if ( $wgUseSiteCss ) {
939 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
940 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
941 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
942 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
945 # If we use any dynamic CSS, make a little CDATA block out of it.
947 if ( !empty($sitecss) ||
!empty($usercss) ) {
948 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
950 wfProfileOut( $fname );
956 function setupUserJs() {
957 $fname = 'SkinTemplate::setupUserJs';
958 wfProfileIn( $fname );
960 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
961 $action = $wgRequest->getText('action');
963 if( $wgAllowUserJs && $this->loggedin
) {
964 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
965 # XXX: additional security check/prompt?
966 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
968 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
971 wfProfileOut( $fname );
975 * Code for extensions to hook into to provide per-page CSS, see
976 * extensions/PageCSS/PageCSS.php for an implementation of this.
980 function setupPageCss() {
981 $fname = 'SkinTemplate::setupPageCss';
982 wfProfileIn( $fname );
984 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
986 wfProfileOut( $fname );
991 * returns css with user-specific options
995 function getUserStylesheet() {
996 $fname = 'SkinTemplate::getUserStylesheet';
997 wfProfileIn( $fname );
999 $s = "/* generated user stylesheet */\n";
1000 $s .= $this->reallyDoGetUserStyles();
1001 wfProfileOut( $fname );
1008 function getUserJs() {
1009 $fname = 'SkinTemplate::getUserJs';
1010 wfProfileIn( $fname );
1012 global $wgStylePath;
1013 $s = '/* generated javascript */';
1014 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1015 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1017 // avoid inclusion of non defined user JavaScript (with custom skins only)
1018 // by checking for default message content
1019 $msgKey = ucfirst($this->skinname
).'.js';
1020 $userJS = wfMsgForContent($msgKey);
1021 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1025 wfProfileOut( $fname );
1031 * Generic wrapper for template functions, with interface
1032 * compatible with what we use of PHPTAL 0.7.
1033 * @package MediaWiki
1036 class QuickTemplate
{
1040 function QuickTemplate() {
1041 $this->data
= array();
1042 $this->translator
= new MediaWiki_I18N();
1048 function set( $name, $value ) {
1049 $this->data
[$name] = $value;
1055 function setRef($name, &$value) {
1056 $this->data
[$name] =& $value;
1062 function setTranslator( &$t ) {
1063 $this->translator
= &$t;
1069 function execute() {
1070 echo "Override this function.";
1077 function text( $str ) {
1078 echo htmlspecialchars( $this->data
[$str] );
1084 function jstext( $str ) {
1085 echo Xml
::escapeJsString( $this->data
[$str] );
1091 function html( $str ) {
1092 echo $this->data
[$str];
1098 function msg( $str ) {
1099 echo htmlspecialchars( $this->translator
->translate( $str ) );
1105 function msgHtml( $str ) {
1106 echo $this->translator
->translate( $str );
1110 * An ugly, ugly hack.
1113 function msgWiki( $str ) {
1114 global $wgParser, $wgTitle, $wgOut;
1116 $text = $this->translator
->translate( $str );
1117 $parserOutput = $wgParser->parse( $text, $wgTitle,
1118 $wgOut->parserOptions(), true );
1119 echo $parserOutput->getText();
1125 function haveData( $str ) {
1126 return $this->data
[$str];
1132 function haveMsg( $str ) {
1133 $msg = $this->translator
->translate( $str );
1134 return ($msg != '-') && ($msg != ''); # ????