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.
34 * Wrapper object for MediaWiki's localization functions,
35 * to be passed to the template engine.
39 class MediaWiki_I18N
{
40 var $_context = array();
42 function set($varName, $value) {
43 $this->_context
[$varName] = $value;
46 function translate($value) {
47 $fname = 'SkinTemplate-translate';
48 wfProfileIn( $fname );
50 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
51 $value = preg_replace( '/^string:/', '', $value );
53 $value = wfMsg( $value );
54 // interpolate variables
56 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
57 list($src, $var) = $m;
59 $varValue = $this->_context
[$var];
61 $value = str_replace($src, $varValue, $value);
63 wfProfileOut( $fname );
69 * @todo document with one-sentence top-level class description.
71 class SkinTemplate
extends Skin
{
77 * Name of our skin, set in initPage()
78 * It probably need to be all lower case.
83 * Stylesheets set to use
84 * Sub directory in ./skins/ where various stylesheets are located
89 * For QuickTemplate, the name of the subclass which
90 * will actually fill the template.
97 * Setup the base parameters...
98 * Child classes should override this to set the name,
99 * style subdirectory, and template filler callback.
101 * @param OutputPage $out
103 function initPage( &$out ) {
104 parent
::initPage( $out );
105 $this->skinname
= 'monobook';
106 $this->stylename
= 'monobook';
107 $this->template
= 'QuickTemplate';
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
115 * @param string $callback (or file)
116 * @param string $repository subdirectory where we keep template files
117 * @param string $cache_dir
121 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
122 return new $classname();
126 * initialize various variables and generate the template
128 * @param OutputPage $out
131 function outputPage( &$out ) {
132 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
133 global $wgScript, $wgStylePath, $wgContLanguageCode;
134 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
135 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
136 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
137 global $wgMaxCredits, $wgShowCreditsIfMax;
138 global $wgPageShowWatchingUsers;
139 global $wgUseTrackbacks;
140 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
142 $fname = 'SkinTemplate::outputPage';
143 wfProfileIn( $fname );
145 // Hook that allows last minute changes to the output page, e.g.
146 // adding of CSS or Javascript by extensions.
147 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
152 wfProfileIn( "$fname-init" );
153 $this->initPage( $out );
155 $this->mTitle
=& $wgTitle;
156 $this->mUser
=& $wgUser;
158 $tpl = $this->setupTemplate( $this->template
, 'skins' );
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator(new MediaWiki_I18N());
163 wfProfileOut( "$fname-init" );
165 wfProfileIn( "$fname-stuff" );
166 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
167 $this->thisurl
= $this->mTitle
->getPrefixedURL();
168 $this->loggedin
= $wgUser->isLoggedIn();
169 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
170 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
171 $this->username
= $wgUser->getName();
172 $userPage = $wgUser->getUserPage();
173 $this->userpage
= $userPage->getPrefixedText();
175 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
176 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
178 # This won't be used in the standard skins, but we define it to preserve the interface
179 # To save time, we check for existence
180 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
183 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt
= $this->mTitle
->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
193 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
195 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
196 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
197 $this->mTitle
->getNsText();
199 $tpl->set( 'nscanonical', $nsname );
200 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
201 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
202 $tpl->set( 'titletext', $this->mTitle
->getText() );
203 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
204 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
206 $tpl->set( 'isarticle', $wgOut->isArticle() );
208 $tpl->setRef( "thispage", $this->thispage
);
209 $subpagestr = $this->subPageSubtitle();
211 'subtitle', !empty($subpagestr)?
212 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
215 $undelete = $this->getUndeleteLink();
217 "undelete", !empty($undelete)?
218 '<span class="subpages">'.$undelete.'</span>':
222 $tpl->set( 'catlinks', $this->getCategories());
223 if( $wgOut->isSyndicated() ) {
225 foreach( $wgFeedClasses as $format => $class ) {
227 if ( $format == "atom" ) {
228 $linktext = wfMsg( 'feed-atom' );
229 } else if ( $format == "rss" ) {
230 $linktext = wfMsg( 'feed-rss' );
232 $feeds[$format] = array(
234 'href' => $wgRequest->appendQuery( "feed=$format" )
237 $tpl->setRef( 'feeds', $feeds );
239 $tpl->set( 'feeds', false );
241 if ($wgUseTrackbacks && $out->isArticleRelated()) {
242 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
244 $tpl->set( 'trackbackhtml', null );
247 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
248 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
249 $tpl->setRef( 'mimetype', $wgMimeType );
250 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
251 $tpl->setRef( 'charset', $wgOutputEncoding );
252 $tpl->set( 'headlinks', $out->getHeadLinks() );
253 $tpl->set('headscripts', $out->getScript() );
254 $tpl->setRef( 'wgScript', $wgScript );
255 $tpl->setRef( 'skinname', $this->skinname
);
256 $tpl->set( 'skinclass', get_class( $this ) );
257 $tpl->setRef( 'stylename', $this->stylename
);
258 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
259 $tpl->setRef( 'loggedin', $this->loggedin
);
260 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
261 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
262 /* XXX currently unused, might get useful later
263 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
264 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
265 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
266 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
267 $tpl->set( "helppage", wfMsg('helppage'));
269 $tpl->set( 'searchaction', $this->escapeSearchLink() );
270 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
271 $tpl->setRef( 'stylepath', $wgStylePath );
272 $tpl->setRef( 'articlepath', $wgArticlePath );
273 $tpl->setRef( 'scriptpath', $wgScriptPath );
274 $tpl->setRef( 'serverurl', $wgServer );
275 $tpl->setRef( 'logopath', $wgLogo );
276 $tpl->setRef( "lang", $wgContLanguageCode );
277 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
278 $tpl->set( 'rtl', $wgContLang->isRTL() );
279 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
280 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
281 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
282 $tpl->setRef( 'userpage', $this->userpage
);
283 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
284 $tpl->set( 'userlang', $wgLang->getCode() );
285 $tpl->set( 'pagecss', $this->setupPageCss() );
286 $tpl->setRef( 'usercss', $this->usercss
);
287 $tpl->setRef( 'userjs', $this->userjs
);
288 $tpl->setRef( 'userjsprev', $this->userjsprev
);
291 if($this->loggedin
) {
292 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
294 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
297 $tpl->set('jsvarurl', false);
299 $newtalks = $wgUser->getNewMessageLinks();
301 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
302 $usertitle = $this->mUser
->getUserPage();
303 $usertalktitle = $usertitle->getTalkPage();
304 if( !$usertalktitle->equals( $this->mTitle
) ) {
305 $ntl = wfMsg( 'youhavenewmessages',
306 $this->makeKnownLinkObj(
308 wfMsgHtml( 'newmessageslink' ),
311 $this->makeKnownLinkObj(
313 wfMsgHtml( 'newmessagesdifflink' ),
318 $wgOut->setSquidMaxage(0);
320 } else if (count($newtalks)) {
321 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
323 foreach ($newtalks as $newtalk) {
324 $msgs[] = wfElement("a",
325 array('href' => $newtalk["link"]), $newtalk["wiki"]);
327 $parts = implode($sep, $msgs);
328 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
329 $wgOut->setSquidMaxage(0);
333 wfProfileOut( "$fname-stuff2" );
335 wfProfileIn( "$fname-stuff3" );
336 $tpl->setRef( 'newtalk', $ntl );
337 $tpl->setRef( 'skin', $this);
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
340 $wgArticle and 0 != $wgArticle->getID() )
342 if ( !$wgDisableCounters ) {
343 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
345 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
347 $tpl->set('viewcount', false);
350 $tpl->set('viewcount', false);
353 if ($wgPageShowWatchingUsers) {
354 $dbr = wfGetDB( DB_SLAVE
);
355 $watchlist = $dbr->tableName( 'watchlist' );
356 $sql = "SELECT COUNT(*) AS n FROM $watchlist
357 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
358 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
359 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n
;
362 if ($numberofwatchingusers > 0) {
363 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
365 $tpl->set('numberofwatchingusers', false);
368 $tpl->set('numberofwatchingusers', false);
371 $tpl->set('copyright',$this->getCopyright());
373 $this->credits
= false;
375 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
376 require_once("Credits.php");
377 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
379 $tpl->set('lastmod', $this->lastModified());
382 $tpl->setRef( 'credits', $this->credits
);
384 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
385 $tpl->set('copyright', $this->getCopyright());
386 $tpl->set('viewcount', false);
387 $tpl->set('lastmod', false);
388 $tpl->set('credits', false);
389 $tpl->set('numberofwatchingusers', false);
391 $tpl->set('copyright', false);
392 $tpl->set('viewcount', false);
393 $tpl->set('lastmod', false);
394 $tpl->set('credits', false);
395 $tpl->set('numberofwatchingusers', false);
397 wfProfileOut( "$fname-stuff3" );
399 wfProfileIn( "$fname-stuff4" );
400 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
401 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
402 $tpl->set( 'disclaimer', $this->disclaimerLink() );
403 $tpl->set( 'privacy', $this->privacyLink() );
404 $tpl->set( 'about', $this->aboutLink() );
406 $tpl->setRef( 'debug', $out->mDebugtext
);
407 $tpl->set( 'reporttime', $out->reportTime() );
408 $tpl->set( 'sitenotice', wfGetSiteNotice() );
409 $tpl->set( 'bottomscripts', $this->bottomScripts() );
411 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
412 $out->mBodytext
.= $printfooter ;
413 $tpl->setRef( 'bodytext', $out->mBodytext
);
416 $language_urls = array();
418 if ( !$wgHideInterlanguageLinks ) {
419 foreach( $wgOut->getLanguageLinks() as $l ) {
420 $tmp = explode( ':', $l, 2 );
421 $class = 'interwiki-' . $tmp[0];
423 $nt = Title
::newFromText( $l );
424 $language_urls[] = array(
425 'href' => $nt->getFullURL(),
426 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
431 if(count($language_urls)) {
432 $tpl->setRef( 'language_urls', $language_urls);
434 $tpl->set('language_urls', false);
436 wfProfileOut( "$fname-stuff4" );
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
446 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
448 $tpl->set('body_ondblclick', false);
450 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
451 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
453 $tpl->set( 'body_onload', false );
455 $tpl->set( 'sidebar', $this->buildSidebar() );
456 $tpl->set( 'nav_urls', $this->buildNavUrls() );
458 // original version by hansm
459 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
460 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
464 wfProfileIn( "$fname-execute" );
465 $res = $tpl->execute();
466 wfProfileOut( "$fname-execute" );
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( $fname );
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
481 function printOrError( $str ) {
486 * build array of urls for personal toolbar
490 function buildPersonalUrls() {
491 global $wgTitle, $wgRequest;
493 $fname = 'SkinTemplate::buildPersonalUrls';
494 $pageurl = $wgTitle->getLocalURL();
495 wfProfileIn( $fname );
497 /* set up the default links for the personal toolbar */
498 $personal_urls = array();
499 if ($this->loggedin
) {
500 $personal_urls['userpage'] = array(
501 'text' => $this->username
,
502 'href' => &$this->userpageUrlDetails
['href'],
503 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
504 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
506 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
507 $personal_urls['mytalk'] = array(
508 'text' => wfMsg('mytalk'),
509 'href' => &$usertalkUrlDetails['href'],
510 'class' => $usertalkUrlDetails['exists']?
false:'new',
511 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
513 $href = self
::makeSpecialUrl( 'Preferences' );
514 $personal_urls['preferences'] = array(
515 'text' => wfMsg( 'mypreferences' ),
517 'active' => ( $href == $pageurl )
519 $href = self
::makeSpecialUrl( 'Watchlist' );
520 $personal_urls['watchlist'] = array(
521 'text' => wfMsg( 'mywatchlist' ),
523 'active' => ( $href == $pageurl )
526 # We need to do an explicit check for Special:Contributions, as we
527 # have to match both the title, and the target (which could come
528 # from request values or be specified in "sub page" form. The plot
529 # thickens, because $wgTitle is altered for special pages, so doesn't
530 # contain the original alias-with-subpage.
531 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
532 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
533 list( $spName, $spPar ) =
534 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
535 $active = $spName == 'Contributions'
536 && ( ( $spPar && $spPar == $this->username
)
537 ||
$wgRequest->getText( 'target' ) == $this->username
);
542 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
543 $personal_urls['mycontris'] = array(
544 'text' => wfMsg( 'mycontris' ),
548 $personal_urls['logout'] = array(
549 'text' => wfMsg( 'userlogout' ),
550 'href' => self
::makeSpecialUrl( 'Userlogout',
551 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
556 if( $this->showIPinHeader() ) {
557 $href = &$this->userpageUrlDetails
['href'];
558 $personal_urls['anonuserpage'] = array(
559 'text' => $this->username
,
561 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
562 'active' => ( $pageurl == $href )
564 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
565 $href = &$usertalkUrlDetails['href'];
566 $personal_urls['anontalk'] = array(
567 'text' => wfMsg('anontalk'),
569 'class' => $usertalkUrlDetails['exists']?
false:'new',
570 'active' => ( $pageurl == $href )
572 $personal_urls['anonlogin'] = array(
573 'text' => wfMsg('userlogin'),
574 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
575 'active' => $wgTitle->isSpecial( 'Userlogin' )
579 $personal_urls['login'] = array(
580 'text' => wfMsg('userlogin'),
581 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
582 'active' => $wgTitle->isSpecial( 'Userlogin' )
587 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
588 wfProfileOut( $fname );
589 return $personal_urls;
592 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
595 $classes[] = 'selected';
597 if( $checkEdit && $title->getArticleId() == 0 ) {
599 $query = 'action=edit';
602 $text = wfMsg( $message );
603 if ( wfEmptyMsg( $message, $text ) ) {
605 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
609 'class' => implode( ' ', $classes ),
611 'href' => $title->getLocalUrl( $query ) );
614 function makeTalkUrlDetails( $name, $urlaction = '' ) {
615 $title = Title
::newFromText( $name );
616 if( !is_object($title) ) {
617 throw new MWException( __METHOD__
." given invalid pagename $name" );
619 $title = $title->getTalkPage();
620 self
::checkTitle( $title, $name );
622 'href' => $title->getLocalURL( $urlaction ),
623 'exists' => $title->getArticleID() != 0 ?
true : false
627 function makeArticleUrlDetails( $name, $urlaction = '' ) {
628 $title = Title
::newFromText( $name );
629 $title= $title->getSubjectPage();
630 self
::checkTitle( $title, $name );
632 'href' => $title->getLocalURL( $urlaction ),
633 'exists' => $title->getArticleID() != 0 ?
true : false
638 * an array of edit links by default used for the tabs
642 function buildContentActionUrls () {
643 global $wgContLang, $wgOut;
644 $fname = 'SkinTemplate::buildContentActionUrls';
645 wfProfileIn( $fname );
647 global $wgUser, $wgRequest;
648 $action = $wgRequest->getText( 'action' );
649 $section = $wgRequest->getText( 'section' );
650 $content_actions = array();
652 $prevent_active_tabs = false ;
653 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
655 if( $this->iscontent
) {
656 $subjpage = $this->mTitle
->getSubjectPage();
657 $talkpage = $this->mTitle
->getTalkPage();
659 $nskey = $this->mTitle
->getNamespaceKey();
660 $content_actions[$nskey] = $this->tabAction(
663 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
666 $content_actions['talk'] = $this->tabAction(
669 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
673 wfProfileIn( "$fname-edit" );
674 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
675 $istalk = $this->mTitle
->isTalkPage();
676 $istalkclass = $istalk?
' istalk':'';
677 $content_actions['edit'] = array(
678 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
679 'text' => wfMsg('edit'),
680 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
683 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
684 $content_actions['addsection'] = array(
685 'class' => $section == 'new'?
'selected':false,
686 'text' => wfMsg('addsection'),
687 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
691 $content_actions['viewsource'] = array(
692 'class' => ($action == 'edit') ?
'selected' : false,
693 'text' => wfMsg('viewsource'),
694 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
697 wfProfileOut( "$fname-edit" );
699 wfProfileIn( "$fname-live" );
700 if ( $this->mTitle
->getArticleId() ) {
702 $content_actions['history'] = array(
703 'class' => ($action == 'history') ?
'selected' : false,
704 'text' => wfMsg('history_short'),
705 'href' => $this->mTitle
->getLocalUrl( 'action=history')
708 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
709 if(!$this->mTitle
->isProtected()){
710 $content_actions['protect'] = array(
711 'class' => ($action == 'protect') ?
'selected' : false,
712 'text' => wfMsg('protect'),
713 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
717 $content_actions['unprotect'] = array(
718 'class' => ($action == 'unprotect') ?
'selected' : false,
719 'text' => wfMsg('unprotect'),
720 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
724 if($wgUser->isAllowed('delete')){
725 $content_actions['delete'] = array(
726 'class' => ($action == 'delete') ?
'selected' : false,
727 'text' => wfMsg('delete'),
728 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
731 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
732 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
733 $content_actions['move'] = array(
734 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
735 'text' => wfMsg('move'),
736 'href' => $moveTitle->getLocalUrl()
740 //article doesn't exist or is deleted
741 if( $wgUser->isAllowed( 'delete' ) ) {
742 if( $n = $this->mTitle
->isDeleted() ) {
743 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
744 $content_actions['undelete'] = array(
746 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
747 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
748 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
753 wfProfileOut( "$fname-live" );
755 if( $this->loggedin
) {
756 if( !$this->mTitle
->userIsWatching()) {
757 $content_actions['watch'] = array(
758 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
759 'text' => wfMsg('watch'),
760 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
763 $content_actions['unwatch'] = array(
764 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
765 'text' => wfMsg('unwatch'),
766 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
772 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
774 /* show special page tab */
776 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
777 'class' => 'selected',
778 'text' => wfMsg('nstab-special'),
779 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
782 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
785 /* show links to different language variants */
786 global $wgDisableLangConversion;
787 $variants = $wgContLang->getVariants();
788 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
789 $preferred = $wgContLang->getPreferredVariant();
791 foreach( $variants as $code ) {
792 $varname = $wgContLang->getVariantname( $code );
793 if( $varname == 'disable' )
795 $selected = ( $code == $preferred )?
'selected' : false;
796 $content_actions['varlang-' . $vcount] = array(
797 'class' => $selected,
799 'href' => $this->mTitle
->getLocalURL('',$code)
805 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
807 wfProfileOut( $fname );
808 return $content_actions;
814 * build array of common navigation links
818 function buildNavUrls () {
819 global $wgUseTrackbacks, $wgTitle, $wgArticle;
821 $fname = 'SkinTemplate::buildNavUrls';
822 wfProfileIn( $fname );
824 global $wgUser, $wgRequest;
825 global $wgEnableUploads, $wgUploadNavigationUrl;
827 $action = $wgRequest->getText( 'action' );
828 $oldid = $wgRequest->getVal( 'oldid' );
831 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
832 if( $wgEnableUploads ) {
833 if ($wgUploadNavigationUrl) {
834 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
836 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
839 if ($wgUploadNavigationUrl)
840 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
842 $nav_urls['upload'] = false;
844 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
846 // default permalink to being off, will override it as required below.
847 $nav_urls['permalink'] = false;
849 // A print stylesheet is attached to all pages, but nobody ever
850 // figures that out. :) Add a link...
851 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
852 $nav_urls['print'] = array(
853 'text' => wfMsg( 'printableversion' ),
854 'href' => $wgRequest->appendQuery( 'printable=yes' )
857 // Also add a "permalink" while we're at it
859 $nav_urls['permalink'] = array(
860 'text' => wfMsg( 'permalink' ),
864 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
865 if ( !( $revid == 0 ) )
866 $nav_urls['permalink'] = array(
867 'text' => wfMsg( 'permalink' ),
868 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
872 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
875 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
876 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
877 $nav_urls['whatlinkshere'] = array(
878 'href' => $wlhTitle->getLocalUrl()
880 if( $this->mTitle
->getArticleId() ) {
881 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
882 $nav_urls['recentchangeslinked'] = array(
883 'href' => $rclTitle->getLocalUrl()
886 $nav_urls['recentchangeslinked'] = false;
888 if ($wgUseTrackbacks)
889 $nav_urls['trackbacklink'] = array(
890 'href' => $wgTitle->trackbackURL()
894 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
895 $id = User
::idFromName($this->mTitle
->getText());
896 $ip = User
::isIP($this->mTitle
->getText());
902 if($id ||
$ip) { # both anons and non-anons have contri list
903 $nav_urls['contributions'] = array(
904 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
906 if ( $wgUser->isAllowed( 'block' ) ) {
907 $nav_urls['blockip'] = array(
908 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
911 $nav_urls['blockip'] = false;
914 $nav_urls['contributions'] = false;
915 $nav_urls['blockip'] = false;
917 $nav_urls['emailuser'] = false;
918 if( $this->showEmailUser( $id ) ) {
919 $nav_urls['emailuser'] = array(
920 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
923 wfProfileOut( $fname );
928 * Generate strings used for xml 'id' names
932 function getNameSpaceKey () {
933 return $this->mTitle
->getNamespaceKey();
939 function setupUserCss() {
940 $fname = 'SkinTemplate::setupUserCss';
941 wfProfileIn( $fname );
943 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
947 $siteargs = '&maxage=' . $wgSquidMaxage;
948 if( $this->loggedin
) {
949 // Ensure that logged-in users' generated CSS isn't clobbered
950 // by anons' publicly cacheable generated CSS.
951 $siteargs .= '&smaxage=0';
954 # Add user-specific code if this is a user and we allow that kind of thing
956 if ( $wgAllowUserCss && $this->loggedin
) {
957 $action = $wgRequest->getText('action');
959 # if we're previewing the CSS page, use it
960 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
961 $siteargs = "&smaxage=0&maxage=0";
962 $usercss = $wgRequest->getText('wpTextbox1');
964 $usercss = '@import "' .
965 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
966 'action=raw&ctype=text/css') . '";' ."\n";
969 $siteargs .= '&ts=' . $wgUser->mTouched
;
972 if( $wgContLang->isRTL() ) {
973 global $wgStyleVersion;
974 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
977 # If we use the site's dynamic CSS, throw that in, too
978 if ( $wgUseSiteCss ) {
979 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
980 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
981 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
982 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
985 # If we use any dynamic CSS, make a little CDATA block out of it.
987 if ( !empty($sitecss) ||
!empty($usercss) ) {
988 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
990 wfProfileOut( $fname );
996 function setupUserJs() {
997 $fname = 'SkinTemplate::setupUserJs';
998 wfProfileIn( $fname );
1000 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
1001 $action = $wgRequest->getText('action');
1003 if( $wgAllowUserJs && $this->loggedin
) {
1004 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1005 # XXX: additional security check/prompt?
1006 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1008 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1011 wfProfileOut( $fname );
1015 * Code for extensions to hook into to provide per-page CSS, see
1016 * extensions/PageCSS/PageCSS.php for an implementation of this.
1020 function setupPageCss() {
1021 $fname = 'SkinTemplate::setupPageCss';
1022 wfProfileIn( $fname );
1024 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1026 wfProfileOut( $fname );
1031 * returns css with user-specific options
1035 function getUserStylesheet() {
1036 $fname = 'SkinTemplate::getUserStylesheet';
1037 wfProfileIn( $fname );
1039 $s = "/* generated user stylesheet */\n";
1040 $s .= $this->reallyDoGetUserStyles();
1041 wfProfileOut( $fname );
1046 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1047 * nated together. For some bizarre reason, it does *not* return any
1048 * custom user JS from subpages. Huh?
1050 * There's absolutely no reason to have separate Monobook/Common JSes.
1051 * Any JS that cares can just check the skin variable generated at the
1052 * top. For now Monobook.js will be maintained, but it should be consi-
1057 public function getUserJs() {
1058 $fname = 'SkinTemplate::getUserJs';
1059 wfProfileIn( $fname );
1061 $s = parent
::getUserJs();
1062 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1064 // avoid inclusion of non defined user JavaScript (with custom skins only)
1065 // by checking for default message content
1066 $msgKey = ucfirst($this->skinname
).'.js';
1067 $userJS = wfMsgForContent($msgKey);
1068 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1072 wfProfileOut( $fname );
1078 * Generic wrapper for template functions, with interface
1079 * compatible with what we use of PHPTAL 0.7.
1082 class QuickTemplate
{
1086 function QuickTemplate() {
1087 $this->data
= array();
1088 $this->translator
= new MediaWiki_I18N();
1094 function set( $name, $value ) {
1095 $this->data
[$name] = $value;
1101 function setRef($name, &$value) {
1102 $this->data
[$name] =& $value;
1108 function setTranslator( &$t ) {
1109 $this->translator
= &$t;
1115 function execute() {
1116 echo "Override this function.";
1123 function text( $str ) {
1124 echo htmlspecialchars( $this->data
[$str] );
1130 function jstext( $str ) {
1131 echo Xml
::escapeJsString( $this->data
[$str] );
1137 function html( $str ) {
1138 echo $this->data
[$str];
1144 function msg( $str ) {
1145 echo htmlspecialchars( $this->translator
->translate( $str ) );
1151 function msgHtml( $str ) {
1152 echo $this->translator
->translate( $str );
1156 * An ugly, ugly hack.
1159 function msgWiki( $str ) {
1160 global $wgParser, $wgTitle, $wgOut;
1162 $text = $this->translator
->translate( $str );
1163 $parserOutput = $wgParser->parse( $text, $wgTitle,
1164 $wgOut->parserOptions(), true );
1165 echo $parserOutput->getText();
1171 function haveData( $str ) {
1172 return isset( $this->data
[$str] );
1178 function haveMsg( $str ) {
1179 $msg = $this->translator
->translate( $str );
1180 return ($msg != '-') && ($msg != ''); # ????