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 $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
139 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
145 $fname = 'SkinTemplate::outputPage';
146 wfProfileIn( $fname );
148 // Hook that allows last minute changes to the output page, e.g.
149 // adding of CSS or Javascript by extensions.
150 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
152 $oldid = $wgRequest->getVal( 'oldid' );
153 $diff = $wgRequest->getVal( 'diff' );
155 wfProfileIn( "$fname-init" );
156 $this->initPage( $out );
158 $this->mTitle
=& $wgTitle;
159 $this->mUser
=& $wgUser;
161 $tpl = $this->setupTemplate( $this->template
, 'skins' );
163 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
164 $tpl->setTranslator(new MediaWiki_I18N());
166 wfProfileOut( "$fname-init" );
168 wfProfileIn( "$fname-stuff" );
169 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
170 $this->thisurl
= $this->mTitle
->getPrefixedURL();
171 $this->loggedin
= $wgUser->isLoggedIn();
172 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
173 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
174 $this->username
= $wgUser->getName();
175 $userPage = $wgUser->getUserPage();
176 $this->userpage
= $userPage->getPrefixedText();
178 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
179 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
181 # This won't be used in the standard skins, but we define it to preserve the interface
182 # To save time, we check for existence
183 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
186 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
187 $this->setupUserCss();
188 $this->setupUserJs();
189 $this->titletxt
= $this->mTitle
->getPrefixedText();
190 wfProfileOut( "$fname-stuff" );
192 wfProfileIn( "$fname-stuff2" );
193 $tpl->set( 'title', $wgOut->getPageTitle() );
194 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
195 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
196 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
198 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
199 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
200 $this->mTitle
->getNsText();
202 $tpl->set( 'nscanonical', $nsname );
203 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
204 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
205 $tpl->set( 'titletext', $this->mTitle
->getText() );
206 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
207 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
209 $tpl->set( 'isarticle', $wgOut->isArticle() );
211 $tpl->setRef( "thispage", $this->thispage
);
212 $subpagestr = $this->subPageSubtitle();
214 'subtitle', !empty($subpagestr)?
215 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
218 $undelete = $this->getUndeleteLink();
220 "undelete", !empty($undelete)?
221 '<span class="subpages">'.$undelete.'</span>':
225 $tpl->set( 'catlinks', $this->getCategories());
226 if( $wgOut->isSyndicated() ) {
228 foreach( $wgFeedClasses as $format => $class ) {
230 if ( $format == "atom" ) {
231 $linktext = wfMsg( 'feed-atom' );
232 } else if ( $format == "rss" ) {
233 $linktext = wfMsg( 'feed-rss' );
235 $feeds[$format] = array(
237 'href' => $wgRequest->appendQuery( "feed=$format" )
240 $tpl->setRef( 'feeds', $feeds );
242 $tpl->set( 'feeds', false );
244 if ($wgUseTrackbacks && $out->isArticleRelated()) {
245 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
247 $tpl->set( 'trackbackhtml', null );
250 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
251 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
252 $tpl->setRef( 'mimetype', $wgMimeType );
253 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
254 $tpl->setRef( 'charset', $wgOutputEncoding );
255 $tpl->set( 'headlinks', $out->getHeadLinks() );
256 $tpl->set('headscripts', $out->getScript() );
257 $tpl->setRef( 'wgScript', $wgScript );
258 $tpl->setRef( 'skinname', $this->skinname
);
259 $tpl->set( 'skinclass', get_class( $this ) );
260 $tpl->setRef( 'stylename', $this->stylename
);
261 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
262 $tpl->setRef( 'loggedin', $this->loggedin
);
263 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
264 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
265 /* XXX currently unused, might get useful later
266 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
267 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
268 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
269 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
270 $tpl->set( "helppage", wfMsg('helppage'));
272 $tpl->set( 'searchaction', $this->escapeSearchLink() );
273 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
274 $tpl->setRef( 'stylepath', $wgStylePath );
275 $tpl->setRef( 'articlepath', $wgArticlePath );
276 $tpl->setRef( 'scriptpath', $wgScriptPath );
277 $tpl->setRef( 'serverurl', $wgServer );
278 $tpl->setRef( 'logopath', $wgLogo );
279 $tpl->setRef( "lang", $wgContLanguageCode );
280 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
281 $tpl->set( 'rtl', $wgContLang->isRTL() );
282 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
283 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
284 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
285 $tpl->setRef( 'userpage', $this->userpage
);
286 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
287 $tpl->set( 'userlang', $wgLang->getCode() );
288 $tpl->set( 'pagecss', $this->setupPageCss() );
289 $tpl->setRef( 'usercss', $this->usercss
);
290 $tpl->setRef( 'userjs', $this->userjs
);
291 $tpl->setRef( 'userjsprev', $this->userjsprev
);
294 if($this->loggedin
) {
295 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
297 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
300 $tpl->set('jsvarurl', false);
302 $newtalks = $wgUser->getNewMessageLinks();
304 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
305 $usertitle = $this->mUser
->getUserPage();
306 $usertalktitle = $usertitle->getTalkPage();
307 if( !$usertalktitle->equals( $this->mTitle
) ) {
308 $ntl = wfMsg( 'youhavenewmessages',
309 $this->makeKnownLinkObj(
311 wfMsgHtml( 'newmessageslink' ),
314 $this->makeKnownLinkObj(
316 wfMsgHtml( 'newmessagesdifflink' ),
321 $wgOut->setSquidMaxage(0);
323 } else if (count($newtalks)) {
324 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
326 foreach ($newtalks as $newtalk) {
327 $msgs[] = wfElement("a",
328 array('href' => $newtalk["link"]), $newtalk["wiki"]);
330 $parts = implode($sep, $msgs);
331 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
332 $wgOut->setSquidMaxage(0);
336 wfProfileOut( "$fname-stuff2" );
338 wfProfileIn( "$fname-stuff3" );
339 $tpl->setRef( 'newtalk', $ntl );
340 $tpl->setRef( 'skin', $this);
341 $tpl->set( 'logo', $this->logoText() );
342 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
343 $wgArticle and 0 != $wgArticle->getID() )
345 if ( !$wgDisableCounters ) {
346 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
348 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
350 $tpl->set('viewcount', false);
353 $tpl->set('viewcount', false);
356 if ($wgPageShowWatchingUsers) {
357 $dbr =& wfGetDB( DB_SLAVE
);
358 $watchlist = $dbr->tableName( 'watchlist' );
359 $sql = "SELECT COUNT(*) AS n FROM $watchlist
360 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
361 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
362 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
363 $x = $dbr->fetchObject( $res );
364 $numberofwatchingusers = $x->n
;
365 if ($numberofwatchingusers > 0) {
366 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
368 $tpl->set('numberofwatchingusers', false);
371 $tpl->set('numberofwatchingusers', false);
374 $tpl->set('copyright',$this->getCopyright());
376 $this->credits
= false;
378 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
379 require_once("Credits.php");
380 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
382 $tpl->set('lastmod', $this->lastModified());
385 $tpl->setRef( 'credits', $this->credits
);
387 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
388 $tpl->set('copyright', $this->getCopyright());
389 $tpl->set('viewcount', false);
390 $tpl->set('lastmod', false);
391 $tpl->set('credits', false);
392 $tpl->set('numberofwatchingusers', false);
394 $tpl->set('copyright', false);
395 $tpl->set('viewcount', false);
396 $tpl->set('lastmod', false);
397 $tpl->set('credits', false);
398 $tpl->set('numberofwatchingusers', false);
400 wfProfileOut( "$fname-stuff3" );
402 wfProfileIn( "$fname-stuff4" );
403 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
404 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
405 $tpl->set( 'disclaimer', $this->disclaimerLink() );
406 $tpl->set( 'privacy', $this->privacyLink() );
407 $tpl->set( 'about', $this->aboutLink() );
409 $tpl->setRef( 'debug', $out->mDebugtext
);
410 $tpl->set( 'reporttime', $out->reportTime() );
411 $tpl->set( 'sitenotice', wfGetSiteNotice() );
412 $tpl->set( 'bottomscripts', $this->bottomScripts() );
414 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
415 $out->mBodytext
.= $printfooter ;
416 $tpl->setRef( 'bodytext', $out->mBodytext
);
419 $language_urls = array();
421 if ( !$wgHideInterlanguageLinks ) {
422 foreach( $wgOut->getLanguageLinks() as $l ) {
423 $tmp = explode( ':', $l, 2 );
424 $class = 'interwiki-' . $tmp[0];
426 $nt = Title
::newFromText( $l );
427 $language_urls[] = array(
428 'href' => $nt->getFullURL(),
429 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
434 if(count($language_urls)) {
435 $tpl->setRef( 'language_urls', $language_urls);
437 $tpl->set('language_urls', false);
439 wfProfileOut( "$fname-stuff4" );
442 $tpl->set('personal_urls', $this->buildPersonalUrls());
443 $content_actions = $this->buildContentActionUrls();
444 $tpl->setRef('content_actions', $content_actions);
446 // XXX: attach this from javascript, same with section editing
447 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
449 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
451 $tpl->set('body_ondblclick', false);
453 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
454 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
456 $tpl->set( 'body_onload', false );
458 $tpl->set( 'sidebar', $this->buildSidebar() );
459 $tpl->set( 'nav_urls', $this->buildNavUrls() );
462 wfProfileIn( "$fname-execute" );
463 $res = $tpl->execute();
464 wfProfileOut( "$fname-execute" );
466 // result may be an error
467 $this->printOrError( $res );
468 wfProfileOut( $fname );
472 * Output the string, or print error message if it's
473 * an error object of the appropriate type.
474 * For the base class, assume strings all around.
479 function printOrError( &$str ) {
484 * build array of urls for personal toolbar
488 function buildPersonalUrls() {
489 global $wgTitle, $wgShowIPinHeader;
491 $fname = 'SkinTemplate::buildPersonalUrls';
492 $pageurl = $wgTitle->getLocalURL();
493 wfProfileIn( $fname );
495 /* set up the default links for the personal toolbar */
496 $personal_urls = array();
497 if ($this->loggedin
) {
498 $personal_urls['userpage'] = array(
499 'text' => $this->username
,
500 'href' => &$this->userpageUrlDetails
['href'],
501 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
502 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
504 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
505 $personal_urls['mytalk'] = array(
506 'text' => wfMsg('mytalk'),
507 'href' => &$usertalkUrlDetails['href'],
508 'class' => $usertalkUrlDetails['exists']?
false:'new',
509 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
511 $href = self
::makeSpecialUrl( 'Preferences' );
512 $personal_urls['preferences'] = array(
513 'text' => wfMsg( 'mypreferences' ),
514 'href' => self
::makeSpecialUrl( 'Preferences' ),
515 'active' => ( $href == $pageurl )
517 $href = self
::makeSpecialUrl( 'Watchlist' );
518 $personal_urls['watchlist'] = array(
519 'text' => wfMsg( 'watchlist' ),
521 'active' => ( $href == $pageurl )
523 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
524 $personal_urls['mycontris'] = array(
525 'text' => wfMsg( 'mycontris' ),
527 // FIXME # 'active' was disabed in r11346 with message: "disable bold link to my contributions; link was bold on all
528 // Special:Contributions, not just current user's (fix me please!)". Until resolved, explicitly setting active to false.
529 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
531 $personal_urls['logout'] = array(
532 'text' => wfMsg( 'userlogout' ),
533 'href' => self
::makeSpecialUrl( 'Userlogout',
534 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
539 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
540 $href = &$this->userpageUrlDetails
['href'];
541 $personal_urls['anonuserpage'] = array(
542 'text' => $this->username
,
544 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
545 'active' => ( $pageurl == $href )
547 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
548 $href = &$usertalkUrlDetails['href'];
549 $personal_urls['anontalk'] = array(
550 'text' => wfMsg('anontalk'),
552 'class' => $usertalkUrlDetails['exists']?
false:'new',
553 'active' => ( $pageurl == $href )
555 $personal_urls['anonlogin'] = array(
556 'text' => wfMsg('userlogin'),
557 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
558 'active' => $wgTitle->isSpecial( 'Userlogin' )
562 $personal_urls['login'] = array(
563 'text' => wfMsg('userlogin'),
564 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
565 'active' => $wgTitle->isSpecial( 'Userlogin' )
570 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
571 wfProfileOut( $fname );
572 return $personal_urls;
576 * Returns true if the IP should be shown in the header
578 function showIPinHeader() {
579 global $wgShowIPinHeader;
580 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
583 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
586 $classes[] = 'selected';
588 if( $checkEdit && $title->getArticleId() == 0 ) {
590 $query = 'action=edit';
593 $text = wfMsg( $message );
594 if ( wfEmptyMsg( $message, $text ) ) {
596 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
600 'class' => implode( ' ', $classes ),
602 'href' => $title->getLocalUrl( $query ) );
605 function makeTalkUrlDetails( $name, $urlaction = '' ) {
606 $title = Title
::newFromText( $name );
607 $title = $title->getTalkPage();
608 self
::checkTitle( $title, $name );
610 'href' => $title->getLocalURL( $urlaction ),
611 'exists' => $title->getArticleID() != 0 ?
true : false
615 function makeArticleUrlDetails( $name, $urlaction = '' ) {
616 $title = Title
::newFromText( $name );
617 $title= $title->getSubjectPage();
618 self
::checkTitle( $title, $name );
620 'href' => $title->getLocalURL( $urlaction ),
621 'exists' => $title->getArticleID() != 0 ?
true : false
626 * an array of edit links by default used for the tabs
630 function buildContentActionUrls () {
631 global $wgContLang, $wgOut;
632 $fname = 'SkinTemplate::buildContentActionUrls';
633 wfProfileIn( $fname );
635 global $wgUser, $wgRequest;
636 $action = $wgRequest->getText( 'action' );
637 $section = $wgRequest->getText( 'section' );
638 $content_actions = array();
640 $prevent_active_tabs = false ;
641 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
643 if( $this->iscontent
) {
644 $subjpage = $this->mTitle
->getSubjectPage();
645 $talkpage = $this->mTitle
->getTalkPage();
647 $nskey = $this->mTitle
->getNamespaceKey();
648 $content_actions[$nskey] = $this->tabAction(
651 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
654 $content_actions['talk'] = $this->tabAction(
657 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
661 wfProfileIn( "$fname-edit" );
662 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
663 $istalk = $this->mTitle
->isTalkPage();
664 $istalkclass = $istalk?
' istalk':'';
665 $content_actions['edit'] = array(
666 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
667 'text' => wfMsg('edit'),
668 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
671 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
672 $content_actions['addsection'] = array(
673 'class' => $section == 'new'?
'selected':false,
674 'text' => wfMsg('addsection'),
675 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
679 $content_actions['viewsource'] = array(
680 'class' => ($action == 'edit') ?
'selected' : false,
681 'text' => wfMsg('viewsource'),
682 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
685 wfProfileOut( "$fname-edit" );
687 wfProfileIn( "$fname-live" );
688 if ( $this->mTitle
->getArticleId() ) {
690 $content_actions['history'] = array(
691 'class' => ($action == 'history') ?
'selected' : false,
692 'text' => wfMsg('history_short'),
693 'href' => $this->mTitle
->getLocalUrl( 'action=history')
696 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
697 if(!$this->mTitle
->isProtected()){
698 $content_actions['protect'] = array(
699 'class' => ($action == 'protect') ?
'selected' : false,
700 'text' => wfMsg('protect'),
701 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
705 $content_actions['unprotect'] = array(
706 'class' => ($action == 'unprotect') ?
'selected' : false,
707 'text' => wfMsg('unprotect'),
708 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
712 if($wgUser->isAllowed('delete')){
713 $content_actions['delete'] = array(
714 'class' => ($action == 'delete') ?
'selected' : false,
715 'text' => wfMsg('delete'),
716 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
719 if ( $this->mTitle
->userCanMove()) {
720 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
721 $content_actions['move'] = array(
722 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
723 'text' => wfMsg('move'),
724 'href' => $moveTitle->getLocalUrl()
728 //article doesn't exist or is deleted
729 if( $wgUser->isAllowed( 'delete' ) ) {
730 if( $n = $this->mTitle
->isDeleted() ) {
731 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
732 $content_actions['undelete'] = array(
734 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
735 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
736 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
741 wfProfileOut( "$fname-live" );
743 if( $this->loggedin
) {
744 if( !$this->mTitle
->userIsWatching()) {
745 $content_actions['watch'] = array(
746 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
747 'text' => wfMsg('watch'),
748 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
751 $content_actions['unwatch'] = array(
752 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
753 'text' => wfMsg('unwatch'),
754 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
759 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
761 /* show special page tab */
763 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
764 'class' => 'selected',
765 'text' => wfMsg('specialpage'),
766 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
769 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
772 /* show links to different language variants */
773 global $wgDisableLangConversion;
774 $variants = $wgContLang->getVariants();
775 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
776 $preferred = $wgContLang->getPreferredVariant();
778 foreach( $variants as $code ) {
779 $varname = $wgContLang->getVariantname( $code );
780 if( $varname == 'disable' )
782 $selected = ( $code == $preferred )?
'selected' : false;
783 $content_actions['varlang-' . $vcount] = array(
784 'class' => $selected,
786 'href' => $this->mTitle
->getLocalURL('',$code)
792 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
794 wfProfileOut( $fname );
795 return $content_actions;
801 * build array of common navigation links
805 function buildNavUrls () {
806 global $wgUseTrackbacks, $wgTitle, $wgArticle;
808 $fname = 'SkinTemplate::buildNavUrls';
809 wfProfileIn( $fname );
811 global $wgUser, $wgRequest;
812 global $wgEnableUploads, $wgUploadNavigationUrl;
814 $action = $wgRequest->getText( 'action' );
815 $oldid = $wgRequest->getVal( 'oldid' );
818 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
819 if( $wgEnableUploads ) {
820 if ($wgUploadNavigationUrl) {
821 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
823 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
826 if ($wgUploadNavigationUrl)
827 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
829 $nav_urls['upload'] = false;
831 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
833 // default permalink to being off, will override it as required below.
834 $nav_urls['permalink'] = false;
836 // A print stylesheet is attached to all pages, but nobody ever
837 // figures that out. :) Add a link...
838 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
839 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
840 if ( !( $revid == 0 ) )
841 $nav_urls['print'] = array(
842 'text' => wfMsg( 'printableversion' ),
843 'href' => $wgRequest->appendQuery( 'printable=yes' )
846 // Also add a "permalink" while we're at it
848 $nav_urls['permalink'] = array(
849 'text' => wfMsg( 'permalink' ),
853 if ( !( $revid == 0 ) )
854 $nav_urls['permalink'] = array(
855 'text' => wfMsg( 'permalink' ),
856 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
860 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
863 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
864 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
865 $nav_urls['whatlinkshere'] = array(
866 'href' => $wlhTitle->getLocalUrl()
868 if( $this->mTitle
->getArticleId() ) {
869 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
870 $nav_urls['recentchangeslinked'] = array(
871 'href' => $rclTitle->getLocalUrl()
874 $nav_urls['recentchangeslinked'] = false;
876 if ($wgUseTrackbacks)
877 $nav_urls['trackbacklink'] = array(
878 'href' => $wgTitle->trackbackURL()
882 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
883 $id = User
::idFromName($this->mTitle
->getText());
884 $ip = User
::isIP($this->mTitle
->getText());
890 if($id ||
$ip) { # both anons and non-anons have contri list
891 $nav_urls['contributions'] = array(
892 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
894 if ( $wgUser->isAllowed( 'block' ) ) {
895 $nav_urls['blockip'] = array(
896 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
899 $nav_urls['blockip'] = false;
902 $nav_urls['contributions'] = false;
903 $nav_urls['blockip'] = false;
905 $nav_urls['emailuser'] = false;
906 if( $this->showEmailUser( $id ) ) {
907 $nav_urls['emailuser'] = array(
908 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
911 wfProfileOut( $fname );
916 * Generate strings used for xml 'id' names
920 function getNameSpaceKey () {
921 return $this->mTitle
->getNamespaceKey();
927 function setupUserCss() {
928 $fname = 'SkinTemplate::setupUserCss';
929 wfProfileIn( $fname );
931 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
935 $siteargs = '&maxage=' . $wgSquidMaxage;
936 if( $this->loggedin
) {
937 // Ensure that logged-in users' generated CSS isn't clobbered
938 // by anons' publicly cacheable generated CSS.
939 $siteargs .= '&smaxage=0';
942 # Add user-specific code if this is a user and we allow that kind of thing
944 if ( $wgAllowUserCss && $this->loggedin
) {
945 $action = $wgRequest->getText('action');
947 # if we're previewing the CSS page, use it
948 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
949 $siteargs = "&smaxage=0&maxage=0";
950 $usercss = $wgRequest->getText('wpTextbox1');
952 $usercss = '@import "' .
953 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
954 'action=raw&ctype=text/css') . '";' ."\n";
957 $siteargs .= '&ts=' . $wgUser->mTouched
;
960 if( $wgContLang->isRTL() ) {
961 global $wgStyleVersion;
962 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
965 # If we use the site's dynamic CSS, throw that in, too
966 if ( $wgUseSiteCss ) {
967 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
968 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
969 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
970 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
973 # If we use any dynamic CSS, make a little CDATA block out of it.
975 if ( !empty($sitecss) ||
!empty($usercss) ) {
976 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
978 wfProfileOut( $fname );
984 function setupUserJs() {
985 $fname = 'SkinTemplate::setupUserJs';
986 wfProfileIn( $fname );
988 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
989 $action = $wgRequest->getText('action');
991 if( $wgAllowUserJs && $this->loggedin
) {
992 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
993 # XXX: additional security check/prompt?
994 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
996 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
999 wfProfileOut( $fname );
1003 * Code for extensions to hook into to provide per-page CSS, see
1004 * extensions/PageCSS/PageCSS.php for an implementation of this.
1008 function setupPageCss() {
1009 $fname = 'SkinTemplate::setupPageCss';
1010 wfProfileIn( $fname );
1012 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1014 wfProfileOut( $fname );
1019 * returns css with user-specific options
1023 function getUserStylesheet() {
1024 $fname = 'SkinTemplate::getUserStylesheet';
1025 wfProfileIn( $fname );
1027 $s = "/* generated user stylesheet */\n";
1028 $s .= $this->reallyDoGetUserStyles();
1029 wfProfileOut( $fname );
1034 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1035 * nated together. For some bizarre reason, it does *not* return any
1036 * custom user JS from subpages. Huh?
1038 * There's absolutely no reason to have separate Monobook/Common JSes.
1039 * Any JS that cares can just check the skin variable generated at the
1040 * top. For now Monobook.js will be maintained, but it should be consi-
1045 public function getUserJs() {
1046 $fname = 'SkinTemplate::getUserJs';
1047 wfProfileIn( $fname );
1049 $s = parent
::getUserJs();
1050 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1052 // avoid inclusion of non defined user JavaScript (with custom skins only)
1053 // by checking for default message content
1054 $msgKey = ucfirst($this->skinname
).'.js';
1055 $userJS = wfMsgForContent($msgKey);
1056 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1060 wfProfileOut( $fname );
1066 * Generic wrapper for template functions, with interface
1067 * compatible with what we use of PHPTAL 0.7.
1068 * @package MediaWiki
1071 class QuickTemplate
{
1075 function QuickTemplate() {
1076 $this->data
= array();
1077 $this->translator
= new MediaWiki_I18N();
1083 function set( $name, $value ) {
1084 $this->data
[$name] = $value;
1090 function setRef($name, &$value) {
1091 $this->data
[$name] =& $value;
1097 function setTranslator( &$t ) {
1098 $this->translator
= &$t;
1104 function execute() {
1105 echo "Override this function.";
1112 function text( $str ) {
1113 echo htmlspecialchars( $this->data
[$str] );
1119 function jstext( $str ) {
1120 echo Xml
::escapeJsString( $this->data
[$str] );
1126 function html( $str ) {
1127 echo $this->data
[$str];
1133 function msg( $str ) {
1134 echo htmlspecialchars( $this->translator
->translate( $str ) );
1140 function msgHtml( $str ) {
1141 echo $this->translator
->translate( $str );
1145 * An ugly, ugly hack.
1148 function msgWiki( $str ) {
1149 global $wgParser, $wgTitle, $wgOut;
1151 $text = $this->translator
->translate( $str );
1152 $parserOutput = $wgParser->parse( $text, $wgTitle,
1153 $wgOut->parserOptions(), true );
1154 echo $parserOutput->getText();
1160 function haveData( $str ) {
1161 return isset( $this->data
[$str] );
1167 function haveMsg( $str ) {
1168 $msg = $this->translator
->translate( $str );
1169 return ($msg != '-') && ($msg != ''); # ????