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 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
27 class MediaWiki_I18N
{
28 var $_context = array();
30 function set($varName, $value) {
31 $this->_context
[$varName] = $value;
34 function translate($value) {
35 $fname = 'SkinTemplate-translate';
36 wfProfileIn( $fname );
38 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
39 $value = preg_replace( '/^string:/', '', $value );
41 $value = wfMsg( $value );
42 // interpolate variables
44 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
45 list($src, $var) = $m;
47 $varValue = $this->_context
[$var];
49 $value = str_replace($src, $varValue, $value);
51 wfProfileOut( $fname );
57 * Template-filler skin base class
58 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
59 * Based on Brion's smarty skin
60 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
62 * @todo Needs some serious refactoring into functions that correspond
63 * to the computations individual esi snippets need. Most importantly no body
64 * parsing for most of those of course.
68 class SkinTemplate
extends Skin
{
74 * Name of our skin, set in initPage()
75 * It probably need to be all lower case.
80 * Stylesheets set to use
81 * Sub directory in ./skins/ where various stylesheets are located
86 * For QuickTemplate, the name of the subclass which
87 * will actually fill the template.
94 * Setup the base parameters...
95 * Child classes should override this to set the name,
96 * style subdirectory, and template filler callback.
98 * @param OutputPage $out
100 function initPage( &$out ) {
101 parent
::initPage( $out );
102 $this->skinname
= 'monobook';
103 $this->stylename
= 'monobook';
104 $this->template
= 'QuickTemplate';
108 * Create the template engine object; we feed it a bunch of data
109 * and eventually it spits out some HTML. Should have interface
110 * roughly equivalent to PHPTAL 0.7.
112 * @param string $callback (or file)
113 * @param string $repository subdirectory where we keep template files
114 * @param string $cache_dir
118 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
119 return new $classname();
123 * initialize various variables and generate the template
125 * @param OutputPage $out
128 function outputPage( &$out ) {
129 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
130 global $wgScript, $wgStylePath, $wgContLanguageCode;
131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
133 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
134 global $wgMaxCredits, $wgShowCreditsIfMax;
135 global $wgPageShowWatchingUsers;
136 global $wgUseTrackbacks;
137 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
139 $fname = 'SkinTemplate::outputPage';
140 wfProfileIn( $fname );
142 // Hook that allows last minute changes to the output page, e.g.
143 // adding of CSS or Javascript by extensions.
144 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
146 $oldid = $wgRequest->getVal( 'oldid' );
147 $diff = $wgRequest->getVal( 'diff' );
149 wfProfileIn( "$fname-init" );
150 $this->initPage( $out );
152 $this->mTitle
=& $wgTitle;
153 $this->mUser
=& $wgUser;
155 $tpl = $this->setupTemplate( $this->template
, 'skins' );
157 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
158 $tpl->setTranslator(new MediaWiki_I18N());
160 wfProfileOut( "$fname-init" );
162 wfProfileIn( "$fname-stuff" );
163 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
164 $this->thisurl
= $this->mTitle
->getPrefixedURL();
165 $this->loggedin
= $wgUser->isLoggedIn();
166 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
167 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
168 $this->username
= $wgUser->getName();
169 $userPage = $wgUser->getUserPage();
170 $this->userpage
= $userPage->getPrefixedText();
172 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
173 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
175 # This won't be used in the standard skins, but we define it to preserve the interface
176 # To save time, we check for existence
177 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
180 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
181 $this->setupUserCss();
182 $this->setupUserJs( $out->isUserJsAllowed() );
183 $this->titletxt
= $this->mTitle
->getPrefixedText();
184 wfProfileOut( "$fname-stuff" );
186 wfProfileIn( "$fname-stuff2" );
187 $tpl->set( 'title', $wgOut->getPageTitle() );
188 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
189 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
190 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
192 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
193 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
194 $this->mTitle
->getNsText();
196 $tpl->set( 'nscanonical', $nsname );
197 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
198 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
199 $tpl->set( 'titletext', $this->mTitle
->getText() );
200 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
201 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
203 $tpl->set( 'isarticle', $wgOut->isArticle() );
205 $tpl->setRef( "thispage", $this->thispage
);
206 $subpagestr = $this->subPageSubtitle();
208 'subtitle', !empty($subpagestr)?
209 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
212 $undelete = $this->getUndeleteLink();
214 "undelete", !empty($undelete)?
215 '<span class="subpages">'.$undelete.'</span>':
219 $tpl->set( 'catlinks', $this->getCategories());
220 if( $wgOut->isSyndicated() ) {
222 foreach( $wgFeedClasses as $format => $class ) {
224 if ( $format == "atom" ) {
225 $linktext = wfMsg( 'feed-atom' );
226 } else if ( $format == "rss" ) {
227 $linktext = wfMsg( 'feed-rss' );
229 if( is_string( $wgOut->getFeedAppendQuery() ) ) {
230 $appendQuery = "&" . $wgOut->getFeedAppendQuery();
234 $feeds[$format] = array(
236 'href' => $wgRequest->appendQuery( "feed={$format}{$appendQuery}" )
239 $tpl->setRef( 'feeds', $feeds );
241 $tpl->set( 'feeds', false );
243 if ($wgUseTrackbacks && $out->isArticleRelated()) {
244 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
246 $tpl->set( 'trackbackhtml', null );
249 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
250 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
251 $tpl->setRef( 'mimetype', $wgMimeType );
252 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
253 $tpl->setRef( 'charset', $wgOutputEncoding );
254 $tpl->set( 'headlinks', $out->getHeadLinks() );
255 $tpl->set('headscripts', $out->getScript() );
256 $tpl->setRef( 'wgScript', $wgScript );
257 $tpl->setRef( 'skinname', $this->skinname
);
258 $tpl->set( 'skinclass', get_class( $this ) );
259 $tpl->setRef( 'stylename', $this->stylename
);
260 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
261 $tpl->setRef( 'loggedin', $this->loggedin
);
262 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
263 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
264 /* XXX currently unused, might get useful later
265 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
266 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
267 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
268 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
269 $tpl->set( "helppage", wfMsg('helppage'));
271 $tpl->set( 'searchaction', $this->escapeSearchLink() );
272 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
273 $tpl->setRef( 'stylepath', $wgStylePath );
274 $tpl->setRef( 'articlepath', $wgArticlePath );
275 $tpl->setRef( 'scriptpath', $wgScriptPath );
276 $tpl->setRef( 'serverurl', $wgServer );
277 $tpl->setRef( 'logopath', $wgLogo );
278 $tpl->setRef( "lang", $wgContLanguageCode );
279 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
280 $tpl->set( 'rtl', $wgContLang->isRTL() );
281 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
282 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
283 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
284 $tpl->setRef( 'userpage', $this->userpage
);
285 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
286 $tpl->set( 'userlang', $wgLang->getCode() );
287 $tpl->set( 'pagecss', $this->setupPageCss() );
288 $tpl->setRef( 'usercss', $this->usercss
);
289 $tpl->setRef( 'userjs', $this->userjs
);
290 $tpl->setRef( 'userjsprev', $this->userjsprev
);
293 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
294 $tpl->set( 'jsvarurl',
296 "action=raw$jsCache&gen=js&useskin=" .
297 urlencode( $this->getSkinName() ) ) );
299 $tpl->set('jsvarurl', false);
301 $newtalks = $wgUser->getNewMessageLinks();
303 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
304 $usertitle = $this->mUser
->getUserPage();
305 $usertalktitle = $usertitle->getTalkPage();
306 if( !$usertalktitle->equals( $this->mTitle
) ) {
307 $ntl = wfMsg( 'youhavenewmessages',
308 $this->makeKnownLinkObj(
310 wfMsgHtml( 'newmessageslink' ),
313 $this->makeKnownLinkObj(
315 wfMsgHtml( 'newmessagesdifflink' ),
320 $wgOut->setSquidMaxage(0);
322 } else if (count($newtalks)) {
323 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
325 foreach ($newtalks as $newtalk) {
326 $msgs[] = wfElement("a",
327 array('href' => $newtalk["link"]), $newtalk["wiki"]);
329 $parts = implode($sep, $msgs);
330 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
331 $wgOut->setSquidMaxage(0);
335 wfProfileOut( "$fname-stuff2" );
337 wfProfileIn( "$fname-stuff3" );
338 $tpl->setRef( 'newtalk', $ntl );
339 $tpl->setRef( 'skin', $this);
340 $tpl->set( 'logo', $this->logoText() );
341 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
342 $wgArticle and 0 != $wgArticle->getID() )
344 if ( !$wgDisableCounters ) {
345 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
347 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
349 $tpl->set('viewcount', false);
352 $tpl->set('viewcount', false);
355 if ($wgPageShowWatchingUsers) {
356 $dbr = wfGetDB( DB_SLAVE
);
357 $watchlist = $dbr->tableName( 'watchlist' );
358 $sql = "SELECT COUNT(*) AS n FROM $watchlist
359 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
360 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
361 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
362 $x = $dbr->fetchObject( $res );
363 $numberofwatchingusers = $x->n
;
364 if ($numberofwatchingusers > 0) {
365 $tpl->set('numberofwatchingusers',
366 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
367 $wgLang->formatNum($numberofwatchingusers))
370 $tpl->set('numberofwatchingusers', false);
373 $tpl->set('numberofwatchingusers', false);
376 $tpl->set('copyright',$this->getCopyright());
378 $this->credits
= false;
380 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
381 require_once("Credits.php");
382 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
384 $tpl->set('lastmod', $this->lastModified());
387 $tpl->setRef( 'credits', $this->credits
);
389 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
390 $tpl->set('copyright', $this->getCopyright());
391 $tpl->set('viewcount', false);
392 $tpl->set('lastmod', false);
393 $tpl->set('credits', false);
394 $tpl->set('numberofwatchingusers', false);
396 $tpl->set('copyright', false);
397 $tpl->set('viewcount', false);
398 $tpl->set('lastmod', false);
399 $tpl->set('credits', false);
400 $tpl->set('numberofwatchingusers', false);
402 wfProfileOut( "$fname-stuff3" );
404 wfProfileIn( "$fname-stuff4" );
405 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
406 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
407 $tpl->set( 'disclaimer', $this->disclaimerLink() );
408 $tpl->set( 'privacy', $this->privacyLink() );
409 $tpl->set( 'about', $this->aboutLink() );
411 $tpl->setRef( 'debug', $out->mDebugtext
);
412 $tpl->set( 'reporttime', $out->reportTime() );
413 $tpl->set( 'sitenotice', wfGetSiteNotice() );
414 $tpl->set( 'bottomscripts', $this->bottomScripts() );
416 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
417 $out->mBodytext
.= $printfooter ;
418 $tpl->setRef( 'bodytext', $out->mBodytext
);
421 $language_urls = array();
423 if ( !$wgHideInterlanguageLinks ) {
424 foreach( $wgOut->getLanguageLinks() as $l ) {
425 $tmp = explode( ':', $l, 2 );
426 $class = 'interwiki-' . $tmp[0];
428 $nt = Title
::newFromText( $l );
429 $language_urls[] = array(
430 'href' => $nt->getFullURL(),
431 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
436 if(count($language_urls)) {
437 $tpl->setRef( 'language_urls', $language_urls);
439 $tpl->set('language_urls', false);
441 wfProfileOut( "$fname-stuff4" );
444 $tpl->set('personal_urls', $this->buildPersonalUrls());
445 $content_actions = $this->buildContentActionUrls();
446 $tpl->setRef('content_actions', $content_actions);
448 // XXX: attach this from javascript, same with section editing
449 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
451 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
452 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
454 $tpl->set('body_ondblclick', false);
456 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
457 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
459 $tpl->set( 'body_onload', false );
461 $tpl->set( 'sidebar', $this->buildSidebar() );
462 $tpl->set( 'nav_urls', $this->buildNavUrls() );
464 // original version by hansm
465 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
466 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
470 wfProfileIn( "$fname-execute" );
471 $res = $tpl->execute();
472 wfProfileOut( "$fname-execute" );
474 // result may be an error
475 $this->printOrError( $res );
476 wfProfileOut( $fname );
480 * Output the string, or print error message if it's
481 * an error object of the appropriate type.
482 * For the base class, assume strings all around.
487 function printOrError( $str ) {
492 * build array of urls for personal toolbar
496 function buildPersonalUrls() {
497 global $wgTitle, $wgRequest;
499 $fname = 'SkinTemplate::buildPersonalUrls';
500 $pageurl = $wgTitle->getLocalURL();
501 wfProfileIn( $fname );
503 /* set up the default links for the personal toolbar */
504 $personal_urls = array();
505 if ($this->loggedin
) {
506 $personal_urls['userpage'] = array(
507 'text' => $this->username
,
508 'href' => &$this->userpageUrlDetails
['href'],
509 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
510 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
512 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
513 $personal_urls['mytalk'] = array(
514 'text' => wfMsg('mytalk'),
515 'href' => &$usertalkUrlDetails['href'],
516 'class' => $usertalkUrlDetails['exists']?
false:'new',
517 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
519 $href = self
::makeSpecialUrl( 'Preferences' );
520 $personal_urls['preferences'] = array(
521 'text' => wfMsg( 'mypreferences' ),
523 'active' => ( $href == $pageurl )
525 $href = self
::makeSpecialUrl( 'Watchlist' );
526 $personal_urls['watchlist'] = array(
527 'text' => wfMsg( 'mywatchlist' ),
529 'active' => ( $href == $pageurl )
532 # We need to do an explicit check for Special:Contributions, as we
533 # have to match both the title, and the target (which could come
534 # from request values or be specified in "sub page" form. The plot
535 # thickens, because $wgTitle is altered for special pages, so doesn't
536 # contain the original alias-with-subpage.
537 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
538 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
539 list( $spName, $spPar ) =
540 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
541 $active = $spName == 'Contributions'
542 && ( ( $spPar && $spPar == $this->username
)
543 ||
$wgRequest->getText( 'target' ) == $this->username
);
548 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
549 $personal_urls['mycontris'] = array(
550 'text' => wfMsg( 'mycontris' ),
554 $personal_urls['logout'] = array(
555 'text' => wfMsg( 'userlogout' ),
556 'href' => self
::makeSpecialUrl( 'Userlogout',
557 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
562 if( $this->showIPinHeader() ) {
563 $href = &$this->userpageUrlDetails
['href'];
564 $personal_urls['anonuserpage'] = array(
565 'text' => $this->username
,
567 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
568 'active' => ( $pageurl == $href )
570 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
571 $href = &$usertalkUrlDetails['href'];
572 $personal_urls['anontalk'] = array(
573 'text' => wfMsg('anontalk'),
575 'class' => $usertalkUrlDetails['exists']?
false:'new',
576 'active' => ( $pageurl == $href )
578 $personal_urls['anonlogin'] = array(
579 'text' => wfMsg('userlogin'),
580 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
581 'active' => $wgTitle->isSpecial( 'Userlogin' )
585 $personal_urls['login'] = array(
586 'text' => wfMsg('userlogin'),
587 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
588 'active' => $wgTitle->isSpecial( 'Userlogin' )
593 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
594 wfProfileOut( $fname );
595 return $personal_urls;
598 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
601 $classes[] = 'selected';
603 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
605 $query = 'action=edit';
608 $text = wfMsg( $message );
609 if ( wfEmptyMsg( $message, $text ) ) {
611 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
615 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
616 $title, $message, $selected, $checkEdit,
617 &$classes, &$query, &$text, &$result)) ) {
622 'class' => implode( ' ', $classes ),
624 'href' => $title->getLocalUrl( $query ) );
627 function makeTalkUrlDetails( $name, $urlaction = '' ) {
628 $title = Title
::newFromText( $name );
629 if( !is_object($title) ) {
630 throw new MWException( __METHOD__
." given invalid pagename $name" );
632 $title = $title->getTalkPage();
633 self
::checkTitle( $title, $name );
635 'href' => $title->getLocalURL( $urlaction ),
636 'exists' => $title->getArticleID() != 0 ?
true : false
640 function makeArticleUrlDetails( $name, $urlaction = '' ) {
641 $title = Title
::newFromText( $name );
642 $title= $title->getSubjectPage();
643 self
::checkTitle( $title, $name );
645 'href' => $title->getLocalURL( $urlaction ),
646 'exists' => $title->getArticleID() != 0 ?
true : false
651 * an array of edit links by default used for the tabs
655 function buildContentActionUrls () {
656 global $wgContLang, $wgLang, $wgOut;
657 $fname = 'SkinTemplate::buildContentActionUrls';
658 wfProfileIn( $fname );
660 global $wgUser, $wgRequest;
661 $action = $wgRequest->getText( 'action' );
662 $section = $wgRequest->getText( 'section' );
663 $content_actions = array();
665 $prevent_active_tabs = false ;
666 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
668 if( $this->iscontent
) {
669 $subjpage = $this->mTitle
->getSubjectPage();
670 $talkpage = $this->mTitle
->getTalkPage();
672 $nskey = $this->mTitle
->getNamespaceKey();
673 $content_actions[$nskey] = $this->tabAction(
676 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
679 $content_actions['talk'] = $this->tabAction(
682 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
686 wfProfileIn( "$fname-edit" );
687 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
688 $istalk = $this->mTitle
->isTalkPage();
689 $istalkclass = $istalk?
' istalk':'';
690 $content_actions['edit'] = array(
691 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
692 'text' => wfMsg('edit'),
693 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
696 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
697 $content_actions['addsection'] = array(
698 'class' => $section == 'new'?
'selected':false,
699 'text' => wfMsg('addsection'),
700 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
703 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
704 $content_actions['viewsource'] = array(
705 'class' => ($action == 'edit') ?
'selected' : false,
706 'text' => wfMsg('viewsource'),
707 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
710 wfProfileOut( "$fname-edit" );
712 wfProfileIn( "$fname-live" );
713 if ( $this->mTitle
->getArticleId() ) {
715 $content_actions['history'] = array(
716 'class' => ($action == 'history') ?
'selected' : false,
717 'text' => wfMsg('history_short'),
718 'href' => $this->mTitle
->getLocalUrl( 'action=history')
721 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
722 if(!$this->mTitle
->isProtected()){
723 $content_actions['protect'] = array(
724 'class' => ($action == 'protect') ?
'selected' : false,
725 'text' => wfMsg('protect'),
726 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
730 $content_actions['unprotect'] = array(
731 'class' => ($action == 'unprotect') ?
'selected' : false,
732 'text' => wfMsg('unprotect'),
733 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
737 if($wgUser->isAllowed('delete')){
738 $content_actions['delete'] = array(
739 'class' => ($action == 'delete') ?
'selected' : false,
740 'text' => wfMsg('delete'),
741 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
744 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
745 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
746 $content_actions['move'] = array(
747 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
748 'text' => wfMsg('move'),
749 'href' => $moveTitle->getLocalUrl()
753 //article doesn't exist or is deleted
754 if( $wgUser->isAllowed( 'delete' ) ) {
755 if( $n = $this->mTitle
->isDeleted() ) {
756 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
757 $content_actions['undelete'] = array(
759 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
760 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
761 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
766 wfProfileOut( "$fname-live" );
768 if( $this->loggedin
) {
769 if( !$this->mTitle
->userIsWatching()) {
770 $content_actions['watch'] = array(
771 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
772 'text' => wfMsg('watch'),
773 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
776 $content_actions['unwatch'] = array(
777 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
778 'text' => wfMsg('unwatch'),
779 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
785 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
787 /* show special page tab */
789 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
790 'class' => 'selected',
791 'text' => wfMsg('nstab-special'),
792 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
795 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
798 /* show links to different language variants */
799 global $wgDisableLangConversion;
800 $variants = $wgContLang->getVariants();
801 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
802 $preferred = $wgContLang->getPreferredVariant();
804 foreach( $variants as $code ) {
805 $varname = $wgContLang->getVariantname( $code );
806 if( $varname == 'disable' )
808 $selected = ( $code == $preferred )?
'selected' : false;
809 $content_actions['varlang-' . $vcount] = array(
810 'class' => $selected,
812 'href' => $this->mTitle
->getLocalURL('',$code)
818 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
820 wfProfileOut( $fname );
821 return $content_actions;
827 * build array of common navigation links
831 function buildNavUrls () {
832 global $wgUseTrackbacks, $wgTitle, $wgArticle;
834 $fname = 'SkinTemplate::buildNavUrls';
835 wfProfileIn( $fname );
837 global $wgUser, $wgRequest;
838 global $wgEnableUploads, $wgUploadNavigationUrl;
840 $action = $wgRequest->getText( 'action' );
843 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
844 if( $wgEnableUploads ) {
845 if ($wgUploadNavigationUrl) {
846 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
848 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
851 if ($wgUploadNavigationUrl)
852 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
854 $nav_urls['upload'] = false;
856 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
858 // default permalink to being off, will override it as required below.
859 $nav_urls['permalink'] = false;
861 // A print stylesheet is attached to all pages, but nobody ever
862 // figures that out. :) Add a link...
863 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
864 $nav_urls['print'] = array(
865 'text' => wfMsg( 'printableversion' ),
866 'href' => $wgRequest->appendQuery( 'printable=yes' )
869 // Also add a "permalink" while we're at it
870 if ( $this->mRevisionId
) {
871 $nav_urls['permalink'] = array(
872 'text' => wfMsg( 'permalink' ),
873 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
877 // Copy in case this undocumented, shady hook tries to mess with internals
878 $revid = $this->mRevisionId
;
879 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
882 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
883 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
884 $nav_urls['whatlinkshere'] = array(
885 'href' => $wlhTitle->getLocalUrl()
887 if( $this->mTitle
->getArticleId() ) {
888 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
889 $nav_urls['recentchangeslinked'] = array(
890 'href' => $rclTitle->getLocalUrl()
893 $nav_urls['recentchangeslinked'] = false;
895 if ($wgUseTrackbacks)
896 $nav_urls['trackbacklink'] = array(
897 'href' => $wgTitle->trackbackURL()
901 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
902 $id = User
::idFromName($this->mTitle
->getText());
903 $ip = User
::isIP($this->mTitle
->getText());
909 if($id ||
$ip) { # both anons and non-anons have contribs list
910 $nav_urls['contributions'] = array(
911 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
915 $logPage = SpecialPage
::getTitleFor( 'Log' );
916 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
917 . $this->mTitle
->getPartialUrl() ) );
919 $nav_urls['log'] = false;
922 if ( $wgUser->isAllowed( 'block' ) ) {
923 $nav_urls['blockip'] = array(
924 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
927 $nav_urls['blockip'] = false;
930 $nav_urls['contributions'] = false;
931 $nav_urls['log'] = false;
932 $nav_urls['blockip'] = false;
934 $nav_urls['emailuser'] = false;
935 if( $this->showEmailUser( $id ) ) {
936 $nav_urls['emailuser'] = array(
937 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
940 wfProfileOut( $fname );
945 * Generate strings used for xml 'id' names
949 function getNameSpaceKey () {
950 return $this->mTitle
->getNamespaceKey();
956 function setupUserCss() {
957 $fname = 'SkinTemplate::setupUserCss';
958 wfProfileIn( $fname );
960 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
964 $siteargs = '&maxage=' . $wgSquidMaxage;
965 if( $this->loggedin
) {
966 // Ensure that logged-in users' generated CSS isn't clobbered
967 // by anons' publicly cacheable generated CSS.
968 $siteargs .= '&smaxage=0';
971 # Add user-specific code if this is a user and we allow that kind of thing
973 if ( $wgAllowUserCss && $this->loggedin
) {
974 $action = $wgRequest->getText('action');
976 # if we're previewing the CSS page, use it
977 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
978 $siteargs = "&smaxage=0&maxage=0";
979 $usercss = $wgRequest->getText('wpTextbox1');
981 $usercss = '@import "' .
982 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
983 'action=raw&ctype=text/css') . '";' ."\n";
986 $siteargs .= '&ts=' . $wgUser->mTouched
;
989 if( $wgContLang->isRTL() ) {
990 global $wgStyleVersion;
991 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
994 # If we use the site's dynamic CSS, throw that in, too
995 if ( $wgUseSiteCss ) {
996 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
998 if (($us = $wgRequest->getVal('useskin', '')) !== '')
999 $skinquery = "&useskin=$us";
1000 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1001 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1002 $sitecss .= '@import "' . self
::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1005 # If we use any dynamic CSS, make a little CDATA block out of it.
1007 if ( !empty($sitecss) ||
!empty($usercss) ) {
1008 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1010 wfProfileOut( $fname );
1016 function setupUserJs( $allowUserJs ) {
1017 $fname = 'SkinTemplate::setupUserJs';
1018 wfProfileIn( $fname );
1020 global $wgRequest, $wgJsMimeType;
1021 $action = $wgRequest->getText('action');
1023 if( $allowUserJs && $this->loggedin
) {
1024 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1025 # XXX: additional security check/prompt?
1026 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1028 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1031 wfProfileOut( $fname );
1035 * Code for extensions to hook into to provide per-page CSS, see
1036 * extensions/PageCSS/PageCSS.php for an implementation of this.
1040 function setupPageCss() {
1041 $fname = 'SkinTemplate::setupPageCss';
1042 wfProfileIn( $fname );
1044 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1046 wfProfileOut( $fname );
1051 * returns css with user-specific options
1055 function getUserStylesheet() {
1056 $fname = 'SkinTemplate::getUserStylesheet';
1057 wfProfileIn( $fname );
1059 $s = "/* generated user stylesheet */\n";
1060 $s .= $this->reallyDoGetUserStyles();
1061 wfProfileOut( $fname );
1066 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1067 * nated together. For some bizarre reason, it does *not* return any
1068 * custom user JS from subpages. Huh?
1070 * There's absolutely no reason to have separate Monobook/Common JSes.
1071 * Any JS that cares can just check the skin variable generated at the
1072 * top. For now Monobook.js will be maintained, but it should be consi-
1077 public function getUserJs() {
1078 $fname = 'SkinTemplate::getUserJs';
1079 wfProfileIn( $fname );
1081 $s = parent
::getUserJs();
1082 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1084 // avoid inclusion of non defined user JavaScript (with custom skins only)
1085 // by checking for default message content
1086 $msgKey = ucfirst($this->skinname
).'.js';
1087 $userJS = wfMsgForContent($msgKey);
1088 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1092 wfProfileOut( $fname );
1098 * Generic wrapper for template functions, with interface
1099 * compatible with what we use of PHPTAL 0.7.
1102 class QuickTemplate
{
1106 function QuickTemplate() {
1107 $this->data
= array();
1108 $this->translator
= new MediaWiki_I18N();
1114 function set( $name, $value ) {
1115 $this->data
[$name] = $value;
1121 function setRef($name, &$value) {
1122 $this->data
[$name] =& $value;
1128 function setTranslator( &$t ) {
1129 $this->translator
= &$t;
1135 function execute() {
1136 echo "Override this function.";
1143 function text( $str ) {
1144 echo htmlspecialchars( $this->data
[$str] );
1150 function jstext( $str ) {
1151 echo Xml
::escapeJsString( $this->data
[$str] );
1157 function html( $str ) {
1158 echo $this->data
[$str];
1164 function msg( $str ) {
1165 echo htmlspecialchars( $this->translator
->translate( $str ) );
1171 function msgHtml( $str ) {
1172 echo $this->translator
->translate( $str );
1176 * An ugly, ugly hack.
1179 function msgWiki( $str ) {
1180 global $wgParser, $wgTitle, $wgOut;
1182 $text = $this->translator
->translate( $str );
1183 $parserOutput = $wgParser->parse( $text, $wgTitle,
1184 $wgOut->parserOptions(), true );
1185 echo $parserOutput->getText();
1191 function haveData( $str ) {
1192 return isset( $this->data
[$str] );
1198 function haveMsg( $str ) {
1199 $msg = $this->translator
->translate( $str );
1200 return ($msg != '-') && ($msg != ''); # ????