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 wfProfileIn( __METHOD__
);
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
40 $value = wfMsg( $value );
41 // interpolate variables
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
46 $varValue = $this->_context
[$var];
48 $value = str_replace($src, $varValue, $value);
50 wfProfileOut( __METHOD__
);
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
67 class SkinTemplate
extends Skin
{
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
91 * An array of strings representing extra CSS files to load. May include:
92 * 'IE', 'IE50', 'IE55', 'IE60', 'IE70', 'rtl'.
99 * Setup the base parameters...
100 * Child classes should override this to set the name,
101 * style subdirectory, and template filler callback.
103 * @param OutputPage $out
105 function initPage( &$out ) {
106 parent
::initPage( $out );
107 $this->skinname
= 'monobook';
108 $this->stylename
= 'monobook';
109 $this->template
= 'QuickTemplate';
110 $this->cssfiles
= array();
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 wfProfileIn( __METHOD__
);
147 $oldid = $wgRequest->getVal( 'oldid' );
148 $diff = $wgRequest->getVal( 'diff' );
150 wfProfileIn( __METHOD__
."-init" );
151 $this->initPage( $out );
153 $this->mTitle
=& $wgTitle;
154 $this->mUser
=& $wgUser;
156 $tpl = $this->setupTemplate( $this->template
, 'skins' );
158 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
159 $tpl->setTranslator(new MediaWiki_I18N());
161 wfProfileOut( __METHOD__
."-init" );
163 wfProfileIn( __METHOD__
."-stuff" );
164 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
165 $this->thisurl
= $this->mTitle
->getPrefixedURL();
166 $this->loggedin
= $wgUser->isLoggedIn();
167 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
168 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
169 $this->username
= $wgUser->getName();
170 $userPage = $wgUser->getUserPage();
171 $this->userpage
= $userPage->getPrefixedText();
173 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
174 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
176 # This won't be used in the standard skins, but we define it to preserve the interface
177 # To save time, we check for existence
178 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
181 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
182 $this->setupUserCss();
183 $this->setupUserJs( $out->isUserJsAllowed() );
184 $this->titletxt
= $this->mTitle
->getPrefixedText();
185 wfProfileOut( __METHOD__
."-stuff" );
187 wfProfileIn( __METHOD__
."-stuff2" );
188 $tpl->set( 'title', $wgOut->getPageTitle() );
189 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
190 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
191 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
193 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
194 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
195 $this->mTitle
->getNsText();
197 $tpl->set( 'nscanonical', $nsname );
198 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle
->getText() );
201 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
202 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
204 $tpl->set( 'isarticle', $wgOut->isArticle() );
206 $tpl->setRef( "thispage", $this->thispage
);
207 $subpagestr = $this->subPageSubtitle();
209 'subtitle', !empty($subpagestr)?
210 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
213 $undelete = $this->getUndeleteLink();
215 "undelete", !empty($undelete)?
216 '<span class="subpages">'.$undelete.'</span>':
220 $tpl->set( 'catlinks', $this->getCategories());
221 if( $wgOut->isSyndicated() ) {
223 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
224 $feeds[$format] = array(
225 'text' => wfMsg( "feed-$format" ),
228 $tpl->setRef( 'feeds', $feeds );
230 $tpl->set( 'feeds', false );
232 if ($wgUseTrackbacks && $out->isArticleRelated()) {
233 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
235 $tpl->set( 'trackbackhtml', null );
238 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
239 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
240 $tpl->setRef( 'mimetype', $wgMimeType );
241 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
242 $tpl->setRef( 'charset', $wgOutputEncoding );
243 $tpl->set( 'headlinks', $out->getHeadLinks() );
244 $tpl->set('headscripts', $out->getScript() );
245 $tpl->setRef( 'wgScript', $wgScript );
246 $tpl->setRef( 'skinname', $this->skinname
);
247 $tpl->set( 'skinclass', get_class( $this ) );
248 $tpl->setRef( 'stylename', $this->stylename
);
249 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
250 $tpl->setRef( 'loggedin', $this->loggedin
);
251 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
252 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
253 /* XXX currently unused, might get useful later
254 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
255 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
256 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
257 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
258 $tpl->set( "helppage", wfMsg('helppage'));
260 $tpl->set( 'searchaction', $this->escapeSearchLink() );
261 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
262 $tpl->setRef( 'stylepath', $wgStylePath );
263 $tpl->setRef( 'articlepath', $wgArticlePath );
264 $tpl->setRef( 'scriptpath', $wgScriptPath );
265 $tpl->setRef( 'serverurl', $wgServer );
266 $tpl->setRef( 'logopath', $wgLogo );
267 $tpl->setRef( "lang", $wgContLanguageCode );
268 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
269 $tpl->set( 'rtl', $wgContLang->isRTL() );
270 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
271 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
272 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
273 $tpl->setRef( 'userpage', $this->userpage
);
274 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
275 $tpl->set( 'userlang', $wgLang->getCode() );
276 $tpl->set( 'pagecss', $this->setupPageCss() );
277 $tpl->set( 'printcss', $this->getPrintCss() );
278 $tpl->setRef( 'usercss', $this->usercss
);
279 $tpl->setRef( 'userjs', $this->userjs
);
280 $tpl->setRef( 'userjsprev', $this->userjsprev
);
283 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
284 $tpl->set( 'jsvarurl',
286 "action=raw$jsCache&gen=js&useskin=" .
287 urlencode( $this->getSkinName() ) ) );
289 $tpl->set('jsvarurl', false);
291 $newtalks = $wgUser->getNewMessageLinks();
293 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
294 $usertitle = $this->mUser
->getUserPage();
295 $usertalktitle = $usertitle->getTalkPage();
296 if( !$usertalktitle->equals( $this->mTitle
) ) {
297 $ntl = wfMsg( 'youhavenewmessages',
298 $this->makeKnownLinkObj(
300 wfMsgHtml( 'newmessageslink' ),
303 $this->makeKnownLinkObj(
305 wfMsgHtml( 'newmessagesdifflink' ),
310 $wgOut->setSquidMaxage(0);
312 } else if (count($newtalks)) {
313 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
315 foreach ($newtalks as $newtalk) {
316 $msgs[] = wfElement("a",
317 array('href' => $newtalk["link"]), $newtalk["wiki"]);
319 $parts = implode($sep, $msgs);
320 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
321 $wgOut->setSquidMaxage(0);
325 wfProfileOut( __METHOD__
."-stuff2" );
327 wfProfileIn( __METHOD__
."-stuff3" );
328 $tpl->setRef( 'newtalk', $ntl );
329 $tpl->setRef( 'skin', $this);
330 $tpl->set( 'logo', $this->logoText() );
331 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
332 $wgArticle and 0 != $wgArticle->getID() )
334 if ( !$wgDisableCounters ) {
335 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
337 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
339 $tpl->set('viewcount', false);
342 $tpl->set('viewcount', false);
345 if ($wgPageShowWatchingUsers) {
346 $dbr = wfGetDB( DB_SLAVE
);
347 $watchlist = $dbr->tableName( 'watchlist' );
348 $sql = "SELECT COUNT(*) AS n FROM $watchlist
349 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
350 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
351 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
352 $x = $dbr->fetchObject( $res );
353 $numberofwatchingusers = $x->n
;
354 if ($numberofwatchingusers > 0) {
355 $tpl->set('numberofwatchingusers',
356 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
357 $wgLang->formatNum($numberofwatchingusers))
360 $tpl->set('numberofwatchingusers', false);
363 $tpl->set('numberofwatchingusers', false);
366 $tpl->set('copyright',$this->getCopyright());
368 $this->credits
= false;
370 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
371 require_once("Credits.php");
372 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
374 $tpl->set('lastmod', $this->lastModified());
377 $tpl->setRef( 'credits', $this->credits
);
379 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
380 $tpl->set('copyright', $this->getCopyright());
381 $tpl->set('viewcount', false);
382 $tpl->set('lastmod', false);
383 $tpl->set('credits', false);
384 $tpl->set('numberofwatchingusers', false);
386 $tpl->set('copyright', false);
387 $tpl->set('viewcount', false);
388 $tpl->set('lastmod', false);
389 $tpl->set('credits', false);
390 $tpl->set('numberofwatchingusers', false);
392 wfProfileOut( __METHOD__
."-stuff3" );
394 wfProfileIn( __METHOD__
."-stuff4" );
395 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
396 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
397 $tpl->set( 'disclaimer', $this->disclaimerLink() );
398 $tpl->set( 'privacy', $this->privacyLink() );
399 $tpl->set( 'about', $this->aboutLink() );
401 $tpl->setRef( 'debug', $out->mDebugtext
);
402 $tpl->set( 'reporttime', wfReportTime() );
403 $tpl->set( 'sitenotice', wfGetSiteNotice() );
404 $tpl->set( 'bottomscripts', $this->bottomScripts() );
406 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
407 $out->mBodytext
.= $printfooter ;
408 $tpl->setRef( 'bodytext', $out->mBodytext
);
411 $language_urls = array();
413 if ( !$wgHideInterlanguageLinks ) {
414 foreach( $wgOut->getLanguageLinks() as $l ) {
415 $tmp = explode( ':', $l, 2 );
416 $class = 'interwiki-' . $tmp[0];
418 $nt = Title
::newFromText( $l );
419 $language_urls[] = array(
420 'href' => $nt->getFullURL(),
421 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
426 if(count($language_urls)) {
427 $tpl->setRef( 'language_urls', $language_urls);
429 $tpl->set('language_urls', false);
431 wfProfileOut( __METHOD__
."-stuff4" );
434 $tpl->set('personal_urls', $this->buildPersonalUrls());
435 $content_actions = $this->buildContentActionUrls();
436 $tpl->setRef('content_actions', $content_actions);
438 // XXX: attach this from javascript, same with section editing
439 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
441 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
442 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
444 $tpl->set('body_ondblclick', false);
446 $tpl->set( 'body_onload', false );
447 $tpl->set( 'sidebar', $this->buildSidebar() );
448 $tpl->set( 'nav_urls', $this->buildNavUrls() );
450 // original version by hansm
451 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
452 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
456 wfProfileIn( __METHOD__
."-execute" );
457 $res = $tpl->execute();
458 wfProfileOut( __METHOD__
."-execute" );
460 // result may be an error
461 $this->printOrError( $res );
462 wfProfileOut( __METHOD__
);
466 * Output the string, or print error message if it's
467 * an error object of the appropriate type.
468 * For the base class, assume strings all around.
473 function printOrError( $str ) {
478 * build array of urls for personal toolbar
482 function buildPersonalUrls() {
483 global $wgTitle, $wgRequest;
485 $pageurl = $wgTitle->getLocalURL();
486 wfProfileIn( __METHOD__
);
488 /* set up the default links for the personal toolbar */
489 $personal_urls = array();
490 if ($this->loggedin
) {
491 $personal_urls['userpage'] = array(
492 'text' => $this->username
,
493 'href' => &$this->userpageUrlDetails
['href'],
494 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
495 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
497 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
498 $personal_urls['mytalk'] = array(
499 'text' => wfMsg('mytalk'),
500 'href' => &$usertalkUrlDetails['href'],
501 'class' => $usertalkUrlDetails['exists']?
false:'new',
502 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
504 $href = self
::makeSpecialUrl( 'Preferences' );
505 $personal_urls['preferences'] = array(
506 'text' => wfMsg( 'mypreferences' ),
508 'active' => ( $href == $pageurl )
510 $href = self
::makeSpecialUrl( 'Watchlist' );
511 $personal_urls['watchlist'] = array(
512 'text' => wfMsg( 'mywatchlist' ),
514 'active' => ( $href == $pageurl )
517 # We need to do an explicit check for Special:Contributions, as we
518 # have to match both the title, and the target (which could come
519 # from request values or be specified in "sub page" form. The plot
520 # thickens, because $wgTitle is altered for special pages, so doesn't
521 # contain the original alias-with-subpage.
522 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
523 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
524 list( $spName, $spPar ) =
525 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
526 $active = $spName == 'Contributions'
527 && ( ( $spPar && $spPar == $this->username
)
528 ||
$wgRequest->getText( 'target' ) == $this->username
);
533 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
534 $personal_urls['mycontris'] = array(
535 'text' => wfMsg( 'mycontris' ),
539 $personal_urls['logout'] = array(
540 'text' => wfMsg( 'userlogout' ),
541 'href' => self
::makeSpecialUrl( 'Userlogout',
542 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
548 $loginlink = $wgUser->isAllowed( 'createaccount' )
549 ?
'nav-login-createaccount'
551 if( $this->showIPinHeader() ) {
552 $href = &$this->userpageUrlDetails
['href'];
553 $personal_urls['anonuserpage'] = array(
554 'text' => $this->username
,
556 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
557 'active' => ( $pageurl == $href )
559 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
560 $href = &$usertalkUrlDetails['href'];
561 $personal_urls['anontalk'] = array(
562 'text' => wfMsg('anontalk'),
564 'class' => $usertalkUrlDetails['exists']?
false:'new',
565 'active' => ( $pageurl == $href )
567 $personal_urls['anonlogin'] = array(
568 'text' => wfMsg( $loginlink ),
569 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
570 'active' => $wgTitle->isSpecial( 'Userlogin' )
574 $personal_urls['login'] = array(
575 'text' => wfMsg( $loginlink ),
576 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
577 'active' => $wgTitle->isSpecial( 'Userlogin' )
582 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
583 wfProfileOut( __METHOD__
);
584 return $personal_urls;
587 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
590 $classes[] = 'selected';
592 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
594 $query = 'action=edit';
597 $text = wfMsg( $message );
598 if ( wfEmptyMsg( $message, $text ) ) {
600 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
604 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
605 $title, $message, $selected, $checkEdit,
606 &$classes, &$query, &$text, &$result)) ) {
611 'class' => implode( ' ', $classes ),
613 'href' => $title->getLocalUrl( $query ) );
616 function makeTalkUrlDetails( $name, $urlaction = '' ) {
617 $title = Title
::newFromText( $name );
618 if( !is_object($title) ) {
619 throw new MWException( __METHOD__
." given invalid pagename $name" );
621 $title = $title->getTalkPage();
622 self
::checkTitle( $title, $name );
624 'href' => $title->getLocalURL( $urlaction ),
625 'exists' => $title->getArticleID() != 0 ?
true : false
629 function makeArticleUrlDetails( $name, $urlaction = '' ) {
630 $title = Title
::newFromText( $name );
631 $title= $title->getSubjectPage();
632 self
::checkTitle( $title, $name );
634 'href' => $title->getLocalURL( $urlaction ),
635 'exists' => $title->getArticleID() != 0 ?
true : false
640 * an array of edit links by default used for the tabs
644 function buildContentActionUrls () {
645 global $wgContLang, $wgLang, $wgOut;
646 wfProfileIn( __METHOD__
);
648 global $wgUser, $wgRequest;
649 $action = $wgRequest->getText( 'action' );
650 $section = $wgRequest->getText( 'section' );
651 $content_actions = array();
653 $prevent_active_tabs = false ;
654 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
656 if( $this->iscontent
) {
657 $subjpage = $this->mTitle
->getSubjectPage();
658 $talkpage = $this->mTitle
->getTalkPage();
660 $nskey = $this->mTitle
->getNamespaceKey();
661 $content_actions[$nskey] = $this->tabAction(
664 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
667 $content_actions['talk'] = $this->tabAction(
670 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
674 wfProfileIn( __METHOD__
."-edit" );
675 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
676 $istalk = $this->mTitle
->isTalkPage();
677 $istalkclass = $istalk?
' istalk':'';
678 $content_actions['edit'] = array(
679 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
680 'text' => $this->mTitle
->exists()
683 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
686 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
687 $content_actions['addsection'] = array(
688 'class' => $section == 'new'?
'selected':false,
689 'text' => wfMsg('addsection'),
690 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
693 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
694 $content_actions['viewsource'] = array(
695 'class' => ($action == 'edit') ?
'selected' : false,
696 'text' => wfMsg('viewsource'),
697 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
700 wfProfileOut( __METHOD__
."-edit" );
702 wfProfileIn( __METHOD__
."-live" );
703 if ( $this->mTitle
->getArticleId() ) {
705 $content_actions['history'] = array(
706 'class' => ($action == 'history') ?
'selected' : false,
707 'text' => wfMsg('history_short'),
708 'href' => $this->mTitle
->getLocalUrl( 'action=history')
711 if($wgUser->isAllowed('delete')){
712 $content_actions['delete'] = array(
713 'class' => ($action == 'delete') ?
'selected' : false,
714 'text' => wfMsg('delete'),
715 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
718 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
719 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
720 $content_actions['move'] = array(
721 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
722 'text' => wfMsg('move'),
723 'href' => $moveTitle->getLocalUrl()
727 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
728 if(!$this->mTitle
->isProtected()){
729 $content_actions['protect'] = array(
730 'class' => ($action == 'protect') ?
'selected' : false,
731 'text' => wfMsg('protect'),
732 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
736 $content_actions['unprotect'] = array(
737 'class' => ($action == 'unprotect') ?
'selected' : false,
738 'text' => wfMsg('unprotect'),
739 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
744 //article doesn't exist or is deleted
745 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
746 if( $n = $this->mTitle
->isDeleted() ) {
747 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
748 $content_actions['undelete'] = array(
750 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
751 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
752 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
757 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
758 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
759 $content_actions['protect'] = array(
760 'class' => ($action == 'protect') ?
'selected' : false,
761 'text' => wfMsg('protect'),
762 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
766 $content_actions['unprotect'] = array(
767 'class' => ($action == 'unprotect') ?
'selected' : false,
768 'text' => wfMsg('unprotect'),
769 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
775 wfProfileOut( __METHOD__
."-live" );
777 if( $this->loggedin
) {
778 if( !$this->mTitle
->userIsWatching()) {
779 $content_actions['watch'] = array(
780 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
781 'text' => wfMsg('watch'),
782 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
785 $content_actions['unwatch'] = array(
786 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
787 'text' => wfMsg('unwatch'),
788 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
794 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
796 /* show special page tab */
798 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
799 'class' => 'selected',
800 'text' => wfMsg('nstab-special'),
801 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
804 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
807 /* show links to different language variants */
808 global $wgDisableLangConversion;
809 $variants = $wgContLang->getVariants();
810 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
811 $preferred = $wgContLang->getPreferredVariant();
813 foreach( $variants as $code ) {
814 $varname = $wgContLang->getVariantname( $code );
815 if( $varname == 'disable' )
817 $selected = ( $code == $preferred )?
'selected' : false;
818 $content_actions['varlang-' . $vcount] = array(
819 'class' => $selected,
821 'href' => $this->mTitle
->getLocalURL('',$code)
827 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
829 wfProfileOut( __METHOD__
);
830 return $content_actions;
836 * build array of common navigation links
840 function buildNavUrls () {
841 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
842 global $wgEnableUploads, $wgUploadNavigationUrl;
844 wfProfileIn( __METHOD__
);
846 $action = $wgRequest->getText( 'action' );
849 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
850 if( $wgEnableUploads ) {
851 if ($wgUploadNavigationUrl) {
852 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
854 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
857 if ($wgUploadNavigationUrl)
858 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
860 $nav_urls['upload'] = false;
862 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
864 // default permalink to being off, will override it as required below.
865 $nav_urls['permalink'] = false;
867 // A print stylesheet is attached to all pages, but nobody ever
868 // figures that out. :) Add a link...
869 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
870 $nav_urls['print'] = array(
871 'text' => wfMsg( 'printableversion' ),
872 'href' => $wgRequest->appendQuery( 'printable=yes' )
875 // Also add a "permalink" while we're at it
876 if ( $this->mRevisionId
) {
877 $nav_urls['permalink'] = array(
878 'text' => wfMsg( 'permalink' ),
879 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
883 // Copy in case this undocumented, shady hook tries to mess with internals
884 $revid = $this->mRevisionId
;
885 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
888 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
889 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
890 $nav_urls['whatlinkshere'] = array(
891 'href' => $wlhTitle->getLocalUrl()
893 if( $this->mTitle
->getArticleId() ) {
894 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
895 $nav_urls['recentchangeslinked'] = array(
896 'href' => $rclTitle->getLocalUrl()
899 $nav_urls['recentchangeslinked'] = false;
901 if ($wgUseTrackbacks)
902 $nav_urls['trackbacklink'] = array(
903 'href' => $wgTitle->trackbackURL()
907 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
908 $id = User
::idFromName($this->mTitle
->getText());
909 $ip = User
::isIP($this->mTitle
->getText());
915 if($id ||
$ip) { # both anons and non-anons have contribs list
916 $nav_urls['contributions'] = array(
917 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
921 $logPage = SpecialPage
::getTitleFor( 'Log' );
922 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
923 . $this->mTitle
->getPartialUrl() ) );
925 $nav_urls['log'] = false;
928 if ( $wgUser->isAllowed( 'block' ) ) {
929 $nav_urls['blockip'] = array(
930 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
933 $nav_urls['blockip'] = false;
936 $nav_urls['contributions'] = false;
937 $nav_urls['log'] = false;
938 $nav_urls['blockip'] = false;
940 $nav_urls['emailuser'] = false;
941 if( $this->showEmailUser( $id ) ) {
942 $nav_urls['emailuser'] = array(
943 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
946 wfProfileOut( __METHOD__
);
951 * Generate strings used for xml 'id' names
955 function getNameSpaceKey () {
956 return $this->mTitle
->getNamespaceKey();
962 function setupUserCss() {
963 wfProfileIn( __METHOD__
);
965 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
969 $siteargs = '&maxage=' . $wgSquidMaxage;
970 if( $this->loggedin
) {
971 // Ensure that logged-in users' generated CSS isn't clobbered
972 // by anons' publicly cacheable generated CSS.
973 $siteargs .= '&smaxage=0';
976 # Add user-specific code if this is a user and we allow that kind of thing
978 if ( $wgAllowUserCss && $this->loggedin
) {
979 $action = $wgRequest->getText('action');
981 # if we're previewing the CSS page, use it
982 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
983 $siteargs = "&smaxage=0&maxage=0";
984 $usercss = $wgRequest->getText('wpTextbox1');
986 $usercss = '@import "' .
987 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
988 'action=raw&ctype=text/css') . '";' ."\n";
991 $siteargs .= '&ts=' . $wgUser->mTouched
;
994 if( $wgContLang->isRTL() && in_array( 'rtl', $this->cssfiles
) ) {
995 global $wgStyleVersion;
996 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
999 # If we use the site's dynamic CSS, throw that in, too
1000 if ( $wgUseSiteCss ) {
1001 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
1003 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1004 $skinquery = "&useskin=$us";
1005 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1006 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1007 $sitecss .= '@import "' . self
::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1010 # If we use any dynamic CSS, make a little CDATA block out of it.
1012 if ( !empty($sitecss) ||
!empty($usercss) ) {
1013 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1015 wfProfileOut( __METHOD__
);
1021 function setupUserJs( $allowUserJs ) {
1022 wfProfileIn( __METHOD__
);
1024 global $wgRequest, $wgJsMimeType;
1025 $action = $wgRequest->getText('action');
1027 if( $allowUserJs && $this->loggedin
) {
1028 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1029 # XXX: additional security check/prompt?
1030 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1032 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
1035 wfProfileOut( __METHOD__
);
1039 * Code for extensions to hook into to provide per-page CSS, see
1040 * extensions/PageCSS/PageCSS.php for an implementation of this.
1044 function setupPageCss() {
1045 wfProfileIn( __METHOD__
);
1047 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1049 wfProfileOut( __METHOD__
);
1054 * returns css with user-specific options
1056 public function getUserStylesheet() {
1057 wfProfileIn( __METHOD__
);
1059 $s = "/* generated user stylesheet */\n";
1060 $s .= $this->reallyDoGetUserStyles();
1061 wfProfileOut( __METHOD__
);
1066 * Returns the print stylesheet for this skin. In all default skins this
1067 * is just commonPrint.css, but third-party skins may want to modify it.
1071 protected function getPrintCss() {
1072 global $wgStylePath;
1073 return $wgStylePath . "/common/commonPrint.css";
1077 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1078 * nated together. For some bizarre reason, it does *not* return any
1079 * custom user JS from subpages. Huh?
1081 * There's absolutely no reason to have separate Monobook/Common JSes.
1082 * Any JS that cares can just check the skin variable generated at the
1083 * top. For now Monobook.js will be maintained, but it should be consi-
1088 public function getUserJs() {
1089 wfProfileIn( __METHOD__
);
1091 $s = parent
::getUserJs();
1092 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js */\n";
1094 // avoid inclusion of non defined user JavaScript (with custom skins only)
1095 // by checking for default message content
1096 $msgKey = ucfirst($this->skinname
).'.js';
1097 $userJS = wfMsgForContent($msgKey);
1098 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1102 wfProfileOut( __METHOD__
);
1108 * Generic wrapper for template functions, with interface
1109 * compatible with what we use of PHPTAL 0.7.
1112 class QuickTemplate
{
1116 function QuickTemplate() {
1117 $this->data
= array();
1118 $this->translator
= new MediaWiki_I18N();
1124 function set( $name, $value ) {
1125 $this->data
[$name] = $value;
1131 function setRef($name, &$value) {
1132 $this->data
[$name] =& $value;
1138 function setTranslator( &$t ) {
1139 $this->translator
= &$t;
1145 function execute() {
1146 echo "Override this function.";
1153 function text( $str ) {
1154 echo htmlspecialchars( $this->data
[$str] );
1160 function jstext( $str ) {
1161 echo Xml
::escapeJsString( $this->data
[$str] );
1167 function html( $str ) {
1168 echo $this->data
[$str];
1174 function msg( $str ) {
1175 echo htmlspecialchars( $this->translator
->translate( $str ) );
1181 function msgHtml( $str ) {
1182 echo $this->translator
->translate( $str );
1186 * An ugly, ugly hack.
1189 function msgWiki( $str ) {
1190 global $wgParser, $wgTitle, $wgOut;
1192 $text = $this->translator
->translate( $str );
1193 $parserOutput = $wgParser->parse( $text, $wgTitle,
1194 $wgOut->parserOptions(), true );
1195 echo $parserOutput->getText();
1201 function haveData( $str ) {
1202 return isset( $this->data
[$str] );
1208 function haveMsg( $str ) {
1209 $msg = $this->translator
->translate( $str );
1210 return ($msg != '-') && ($msg != ''); # ????