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.
93 * Setup the base parameters...
94 * Child classes should override this to set the name,
95 * style subdirectory, and template filler callback.
97 * @param OutputPage $out
99 function initPage( &$out ) {
100 parent
::initPage( $out );
101 $this->skinname
= 'monobook';
102 $this->stylename
= 'monobook';
103 $this->template
= 'QuickTemplate';
107 * Create the template engine object; we feed it a bunch of data
108 * and eventually it spits out some HTML. Should have interface
109 * roughly equivalent to PHPTAL 0.7.
111 * @param string $callback (or file)
112 * @param string $repository subdirectory where we keep template files
113 * @param string $cache_dir
117 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
118 return new $classname();
122 * initialize various variables and generate the template
124 * @param OutputPage $out
127 function outputPage( &$out ) {
128 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
129 global $wgScript, $wgStylePath, $wgContLanguageCode;
130 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
131 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
132 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
133 global $wgMaxCredits, $wgShowCreditsIfMax;
134 global $wgPageShowWatchingUsers;
135 global $wgUseTrackbacks;
136 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
138 wfProfileIn( __METHOD__
);
140 $oldid = $wgRequest->getVal( 'oldid' );
141 $diff = $wgRequest->getVal( 'diff' );
143 wfProfileIn( __METHOD__
."-init" );
144 $this->initPage( $out );
146 $this->mTitle
=& $wgTitle;
147 $this->mUser
=& $wgUser;
149 $tpl = $this->setupTemplate( $this->template
, 'skins' );
151 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
152 $tpl->setTranslator(new MediaWiki_I18N());
154 wfProfileOut( __METHOD__
."-init" );
156 wfProfileIn( __METHOD__
."-stuff" );
157 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
158 $this->thisurl
= $this->mTitle
->getPrefixedURL();
159 $this->loggedin
= $wgUser->isLoggedIn();
160 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
161 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
162 $this->username
= $wgUser->getName();
163 $userPage = $wgUser->getUserPage();
164 $this->userpage
= $userPage->getPrefixedText();
166 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
167 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
169 # This won't be used in the standard skins, but we define it to preserve the interface
170 # To save time, we check for existence
171 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
174 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
175 $this->setupUserCss();
176 $this->setupUserJs( $out->isUserJsAllowed() );
177 $this->titletxt
= $this->mTitle
->getPrefixedText();
178 wfProfileOut( __METHOD__
."-stuff" );
180 wfProfileIn( __METHOD__
."-stuff2" );
181 $tpl->set( 'title', $wgOut->getPageTitle() );
182 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
183 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
184 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
186 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
187 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
188 $this->mTitle
->getNsText();
190 $tpl->set( 'nscanonical', $nsname );
191 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
192 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
193 $tpl->set( 'titletext', $this->mTitle
->getText() );
194 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
195 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
197 $tpl->set( 'isarticle', $wgOut->isArticle() );
199 $tpl->setRef( "thispage", $this->thispage
);
200 $subpagestr = $this->subPageSubtitle();
202 'subtitle', !empty($subpagestr)?
203 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
206 $undelete = $this->getUndeleteLink();
208 "undelete", !empty($undelete)?
209 '<span class="subpages">'.$undelete.'</span>':
213 $tpl->set( 'catlinks', $this->getCategories());
214 if( $wgOut->isSyndicated() ) {
216 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
217 $feeds[$format] = array(
218 'text' => wfMsg( "feed-$format" ),
221 $tpl->setRef( 'feeds', $feeds );
223 $tpl->set( 'feeds', false );
225 if ($wgUseTrackbacks && $out->isArticleRelated()) {
226 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
228 $tpl->set( 'trackbackhtml', null );
231 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
232 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
233 $tpl->setRef( 'mimetype', $wgMimeType );
234 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
235 $tpl->setRef( 'charset', $wgOutputEncoding );
236 $tpl->set( 'headlinks', $out->getHeadLinks() );
237 $tpl->set('headscripts', $out->getScript() );
238 $tpl->setRef( 'wgScript', $wgScript );
239 $tpl->setRef( 'skinname', $this->skinname
);
240 $tpl->set( 'skinclass', get_class( $this ) );
241 $tpl->setRef( 'stylename', $this->stylename
);
242 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
243 $tpl->setRef( 'loggedin', $this->loggedin
);
244 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
245 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
246 /* XXX currently unused, might get useful later
247 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
248 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
249 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
250 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
251 $tpl->set( "helppage", wfMsg('helppage'));
253 $tpl->set( 'searchaction', $this->escapeSearchLink() );
254 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
255 $tpl->setRef( 'stylepath', $wgStylePath );
256 $tpl->setRef( 'articlepath', $wgArticlePath );
257 $tpl->setRef( 'scriptpath', $wgScriptPath );
258 $tpl->setRef( 'serverurl', $wgServer );
259 $tpl->setRef( 'logopath', $wgLogo );
260 $tpl->setRef( "lang", $wgContLanguageCode );
261 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
262 $tpl->set( 'rtl', $wgContLang->isRTL() );
263 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
264 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
265 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
266 $tpl->setRef( 'userpage', $this->userpage
);
267 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
268 $tpl->set( 'userlang', $wgLang->getCode() );
269 $tpl->set( 'pagecss', $this->setupPageCss() );
270 $tpl->set( 'printcss', $this->getPrintCss() );
271 $tpl->setRef( 'usercss', $this->usercss
);
272 $tpl->setRef( 'userjs', $this->userjs
);
273 $tpl->setRef( 'userjsprev', $this->userjsprev
);
276 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
277 $tpl->set( 'jsvarurl',
279 "action=raw$jsCache&gen=js&useskin=" .
280 urlencode( $this->getSkinName() ) ) );
282 $tpl->set('jsvarurl', false);
284 $newtalks = $wgUser->getNewMessageLinks();
286 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
287 $usertitle = $this->mUser
->getUserPage();
288 $usertalktitle = $usertitle->getTalkPage();
289 if( !$usertalktitle->equals( $this->mTitle
) ) {
290 $ntl = wfMsg( 'youhavenewmessages',
291 $this->makeKnownLinkObj(
293 wfMsgHtml( 'newmessageslink' ),
296 $this->makeKnownLinkObj(
298 wfMsgHtml( 'newmessagesdifflink' ),
303 $wgOut->setSquidMaxage(0);
305 } else if (count($newtalks)) {
306 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
308 foreach ($newtalks as $newtalk) {
309 $msgs[] = wfElement("a",
310 array('href' => $newtalk["link"]), $newtalk["wiki"]);
312 $parts = implode($sep, $msgs);
313 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
314 $wgOut->setSquidMaxage(0);
318 wfProfileOut( __METHOD__
."-stuff2" );
320 wfProfileIn( __METHOD__
."-stuff3" );
321 $tpl->setRef( 'newtalk', $ntl );
322 $tpl->setRef( 'skin', $this);
323 $tpl->set( 'logo', $this->logoText() );
324 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
325 $wgArticle and 0 != $wgArticle->getID() )
327 if ( !$wgDisableCounters ) {
328 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
330 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
332 $tpl->set('viewcount', false);
335 $tpl->set('viewcount', false);
338 if ($wgPageShowWatchingUsers) {
339 $dbr = wfGetDB( DB_SLAVE
);
340 $watchlist = $dbr->tableName( 'watchlist' );
341 $sql = "SELECT COUNT(*) AS n FROM $watchlist
342 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
343 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
344 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
345 $x = $dbr->fetchObject( $res );
346 $numberofwatchingusers = $x->n
;
347 if ($numberofwatchingusers > 0) {
348 $tpl->set('numberofwatchingusers',
349 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
350 $wgLang->formatNum($numberofwatchingusers))
353 $tpl->set('numberofwatchingusers', false);
356 $tpl->set('numberofwatchingusers', false);
359 $tpl->set('copyright',$this->getCopyright());
361 $this->credits
= false;
363 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
364 require_once("Credits.php");
365 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
367 $tpl->set('lastmod', $this->lastModified());
370 $tpl->setRef( 'credits', $this->credits
);
372 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
373 $tpl->set('copyright', $this->getCopyright());
374 $tpl->set('viewcount', false);
375 $tpl->set('lastmod', false);
376 $tpl->set('credits', false);
377 $tpl->set('numberofwatchingusers', false);
379 $tpl->set('copyright', false);
380 $tpl->set('viewcount', false);
381 $tpl->set('lastmod', false);
382 $tpl->set('credits', false);
383 $tpl->set('numberofwatchingusers', false);
385 wfProfileOut( __METHOD__
."-stuff3" );
387 wfProfileIn( __METHOD__
."-stuff4" );
388 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
389 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
390 $tpl->set( 'disclaimer', $this->disclaimerLink() );
391 $tpl->set( 'privacy', $this->privacyLink() );
392 $tpl->set( 'about', $this->aboutLink() );
394 $tpl->setRef( 'debug', $out->mDebugtext
);
395 $tpl->set( 'reporttime', wfReportTime() );
396 $tpl->set( 'sitenotice', wfGetSiteNotice() );
397 $tpl->set( 'bottomscripts', $this->bottomScripts() );
399 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
400 $out->mBodytext
.= $printfooter ;
401 $tpl->setRef( 'bodytext', $out->mBodytext
);
404 $language_urls = array();
406 if ( !$wgHideInterlanguageLinks ) {
407 foreach( $wgOut->getLanguageLinks() as $l ) {
408 $tmp = explode( ':', $l, 2 );
409 $class = 'interwiki-' . $tmp[0];
411 $nt = Title
::newFromText( $l );
412 $language_urls[] = array(
413 'href' => $nt->getFullURL(),
414 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
419 if(count($language_urls)) {
420 $tpl->setRef( 'language_urls', $language_urls);
422 $tpl->set('language_urls', false);
424 wfProfileOut( __METHOD__
."-stuff4" );
427 $tpl->set('personal_urls', $this->buildPersonalUrls());
428 $content_actions = $this->buildContentActionUrls();
429 $tpl->setRef('content_actions', $content_actions);
431 // XXX: attach this from javascript, same with section editing
432 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
434 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
435 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
437 $tpl->set('body_ondblclick', false);
439 $tpl->set( 'body_onload', false );
440 $tpl->set( 'sidebar', $this->buildSidebar() );
441 $tpl->set( 'nav_urls', $this->buildNavUrls() );
443 // original version by hansm
444 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
445 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
449 wfProfileIn( __METHOD__
."-execute" );
450 $res = $tpl->execute();
451 wfProfileOut( __METHOD__
."-execute" );
453 // result may be an error
454 $this->printOrError( $res );
455 wfProfileOut( __METHOD__
);
459 * Output the string, or print error message if it's
460 * an error object of the appropriate type.
461 * For the base class, assume strings all around.
466 function printOrError( $str ) {
471 * build array of urls for personal toolbar
475 function buildPersonalUrls() {
476 global $wgTitle, $wgRequest;
478 $pageurl = $wgTitle->getLocalURL();
479 wfProfileIn( __METHOD__
);
481 /* set up the default links for the personal toolbar */
482 $personal_urls = array();
483 if ($this->loggedin
) {
484 $personal_urls['userpage'] = array(
485 'text' => $this->username
,
486 'href' => &$this->userpageUrlDetails
['href'],
487 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
488 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
490 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
491 $personal_urls['mytalk'] = array(
492 'text' => wfMsg('mytalk'),
493 'href' => &$usertalkUrlDetails['href'],
494 'class' => $usertalkUrlDetails['exists']?
false:'new',
495 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
497 $href = self
::makeSpecialUrl( 'Preferences' );
498 $personal_urls['preferences'] = array(
499 'text' => wfMsg( 'mypreferences' ),
501 'active' => ( $href == $pageurl )
503 $href = self
::makeSpecialUrl( 'Watchlist' );
504 $personal_urls['watchlist'] = array(
505 'text' => wfMsg( 'mywatchlist' ),
507 'active' => ( $href == $pageurl )
510 # We need to do an explicit check for Special:Contributions, as we
511 # have to match both the title, and the target (which could come
512 # from request values or be specified in "sub page" form. The plot
513 # thickens, because $wgTitle is altered for special pages, so doesn't
514 # contain the original alias-with-subpage.
515 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
516 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
517 list( $spName, $spPar ) =
518 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
519 $active = $spName == 'Contributions'
520 && ( ( $spPar && $spPar == $this->username
)
521 ||
$wgRequest->getText( 'target' ) == $this->username
);
526 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
527 $personal_urls['mycontris'] = array(
528 'text' => wfMsg( 'mycontris' ),
532 $personal_urls['logout'] = array(
533 'text' => wfMsg( 'userlogout' ),
534 'href' => self
::makeSpecialUrl( 'Userlogout',
535 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
541 $loginlink = $wgUser->isAllowed( 'createaccount' )
542 ?
'nav-login-createaccount'
544 if( $this->showIPinHeader() ) {
545 $href = &$this->userpageUrlDetails
['href'];
546 $personal_urls['anonuserpage'] = array(
547 'text' => $this->username
,
549 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
550 'active' => ( $pageurl == $href )
552 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
553 $href = &$usertalkUrlDetails['href'];
554 $personal_urls['anontalk'] = array(
555 'text' => wfMsg('anontalk'),
557 'class' => $usertalkUrlDetails['exists']?
false:'new',
558 'active' => ( $pageurl == $href )
560 $personal_urls['anonlogin'] = array(
561 'text' => wfMsg( $loginlink ),
562 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
563 'active' => $wgTitle->isSpecial( 'Userlogin' )
567 $personal_urls['login'] = array(
568 'text' => wfMsg( $loginlink ),
569 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
570 'active' => $wgTitle->isSpecial( 'Userlogin' )
575 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
576 wfProfileOut( __METHOD__
);
577 return $personal_urls;
580 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
583 $classes[] = 'selected';
585 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
587 $query = 'action=edit';
590 $text = wfMsg( $message );
591 if ( wfEmptyMsg( $message, $text ) ) {
593 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
597 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
598 $title, $message, $selected, $checkEdit,
599 &$classes, &$query, &$text, &$result)) ) {
604 'class' => implode( ' ', $classes ),
606 'href' => $title->getLocalUrl( $query ) );
609 function makeTalkUrlDetails( $name, $urlaction = '' ) {
610 $title = Title
::newFromText( $name );
611 if( !is_object($title) ) {
612 throw new MWException( __METHOD__
." given invalid pagename $name" );
614 $title = $title->getTalkPage();
615 self
::checkTitle( $title, $name );
617 'href' => $title->getLocalURL( $urlaction ),
618 'exists' => $title->getArticleID() != 0 ?
true : false
622 function makeArticleUrlDetails( $name, $urlaction = '' ) {
623 $title = Title
::newFromText( $name );
624 $title= $title->getSubjectPage();
625 self
::checkTitle( $title, $name );
627 'href' => $title->getLocalURL( $urlaction ),
628 'exists' => $title->getArticleID() != 0 ?
true : false
633 * an array of edit links by default used for the tabs
637 function buildContentActionUrls () {
638 global $wgContLang, $wgLang, $wgOut;
639 wfProfileIn( __METHOD__
);
641 global $wgUser, $wgRequest;
642 $action = $wgRequest->getText( 'action' );
643 $section = $wgRequest->getText( 'section' );
644 $content_actions = array();
646 $prevent_active_tabs = false ;
647 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
649 if( $this->iscontent
) {
650 $subjpage = $this->mTitle
->getSubjectPage();
651 $talkpage = $this->mTitle
->getTalkPage();
653 $nskey = $this->mTitle
->getNamespaceKey();
654 $content_actions[$nskey] = $this->tabAction(
657 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
660 $content_actions['talk'] = $this->tabAction(
663 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
667 wfProfileIn( __METHOD__
."-edit" );
668 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
669 $istalk = $this->mTitle
->isTalkPage();
670 $istalkclass = $istalk?
' istalk':'';
671 $content_actions['edit'] = array(
672 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
673 'text' => $this->mTitle
->exists()
676 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
679 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
680 $content_actions['addsection'] = array(
681 'class' => $section == 'new'?
'selected':false,
682 'text' => wfMsg('addsection'),
683 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
686 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
687 $content_actions['viewsource'] = array(
688 'class' => ($action == 'edit') ?
'selected' : false,
689 'text' => wfMsg('viewsource'),
690 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
693 wfProfileOut( __METHOD__
."-edit" );
695 wfProfileIn( __METHOD__
."-live" );
696 if ( $this->mTitle
->getArticleId() ) {
698 $content_actions['history'] = array(
699 'class' => ($action == 'history') ?
'selected' : false,
700 'text' => wfMsg('history_short'),
701 'href' => $this->mTitle
->getLocalUrl( 'action=history')
704 if($wgUser->isAllowed('delete')){
705 $content_actions['delete'] = array(
706 'class' => ($action == 'delete') ?
'selected' : false,
707 'text' => wfMsg('delete'),
708 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
711 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
712 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
713 $content_actions['move'] = array(
714 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
715 'text' => wfMsg('move'),
716 'href' => $moveTitle->getLocalUrl()
720 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
721 if(!$this->mTitle
->isProtected()){
722 $content_actions['protect'] = array(
723 'class' => ($action == 'protect') ?
'selected' : false,
724 'text' => wfMsg('protect'),
725 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
729 $content_actions['unprotect'] = array(
730 'class' => ($action == 'unprotect') ?
'selected' : false,
731 'text' => wfMsg('unprotect'),
732 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
737 //article doesn't exist or is deleted
738 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
739 if( $n = $this->mTitle
->isDeleted() ) {
740 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
741 $content_actions['undelete'] = array(
743 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
744 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
745 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
750 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
751 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
752 $content_actions['protect'] = array(
753 'class' => ($action == 'protect') ?
'selected' : false,
754 'text' => wfMsg('protect'),
755 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
759 $content_actions['unprotect'] = array(
760 'class' => ($action == 'unprotect') ?
'selected' : false,
761 'text' => wfMsg('unprotect'),
762 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
768 wfProfileOut( __METHOD__
."-live" );
770 if( $this->loggedin
) {
771 if( !$this->mTitle
->userIsWatching()) {
772 $content_actions['watch'] = array(
773 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
774 'text' => wfMsg('watch'),
775 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
778 $content_actions['unwatch'] = array(
779 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
780 'text' => wfMsg('unwatch'),
781 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
787 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
789 /* show special page tab */
791 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
792 'class' => 'selected',
793 'text' => wfMsg('nstab-special'),
794 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
797 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
800 /* show links to different language variants */
801 global $wgDisableLangConversion;
802 $variants = $wgContLang->getVariants();
803 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
804 $preferred = $wgContLang->getPreferredVariant();
806 foreach( $variants as $code ) {
807 $varname = $wgContLang->getVariantname( $code );
808 if( $varname == 'disable' )
810 $selected = ( $code == $preferred )?
'selected' : false;
811 $content_actions['varlang-' . $vcount] = array(
812 'class' => $selected,
814 'href' => $this->mTitle
->getLocalURL('',$code)
820 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
822 wfProfileOut( __METHOD__
);
823 return $content_actions;
829 * build array of common navigation links
833 function buildNavUrls () {
834 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
835 global $wgEnableUploads, $wgUploadNavigationUrl;
837 wfProfileIn( __METHOD__
);
839 $action = $wgRequest->getText( 'action' );
842 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
843 if( $wgEnableUploads ) {
844 if ($wgUploadNavigationUrl) {
845 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
847 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
850 if ($wgUploadNavigationUrl)
851 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
853 $nav_urls['upload'] = false;
855 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
857 // default permalink to being off, will override it as required below.
858 $nav_urls['permalink'] = false;
860 // A print stylesheet is attached to all pages, but nobody ever
861 // figures that out. :) Add a link...
862 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
863 $nav_urls['print'] = array(
864 'text' => wfMsg( 'printableversion' ),
865 'href' => $wgRequest->appendQuery( 'printable=yes' )
868 // Also add a "permalink" while we're at it
869 if ( $this->mRevisionId
) {
870 $nav_urls['permalink'] = array(
871 'text' => wfMsg( 'permalink' ),
872 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
876 // Copy in case this undocumented, shady hook tries to mess with internals
877 $revid = $this->mRevisionId
;
878 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
881 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
882 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
883 $nav_urls['whatlinkshere'] = array(
884 'href' => $wlhTitle->getLocalUrl()
886 if( $this->mTitle
->getArticleId() ) {
887 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
888 $nav_urls['recentchangeslinked'] = array(
889 'href' => $rclTitle->getLocalUrl()
892 $nav_urls['recentchangeslinked'] = false;
894 if ($wgUseTrackbacks)
895 $nav_urls['trackbacklink'] = array(
896 'href' => $wgTitle->trackbackURL()
900 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
901 $id = User
::idFromName($this->mTitle
->getText());
902 $ip = User
::isIP($this->mTitle
->getText());
908 if($id ||
$ip) { # both anons and non-anons have contribs list
909 $nav_urls['contributions'] = array(
910 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
914 $logPage = SpecialPage
::getTitleFor( 'Log' );
915 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
916 . $this->mTitle
->getPartialUrl() ) );
918 $nav_urls['log'] = false;
921 if ( $wgUser->isAllowed( 'block' ) ) {
922 $nav_urls['blockip'] = array(
923 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
926 $nav_urls['blockip'] = false;
929 $nav_urls['contributions'] = false;
930 $nav_urls['log'] = false;
931 $nav_urls['blockip'] = false;
933 $nav_urls['emailuser'] = false;
934 if( $this->showEmailUser( $id ) ) {
935 $nav_urls['emailuser'] = array(
936 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
939 wfProfileOut( __METHOD__
);
944 * Generate strings used for xml 'id' names
948 function getNameSpaceKey () {
949 return $this->mTitle
->getNamespaceKey();
955 function setupUserCss() {
956 wfProfileIn( __METHOD__
);
958 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
962 $siteargs = '&maxage=' . $wgSquidMaxage;
963 if( $this->loggedin
) {
964 // Ensure that logged-in users' generated CSS isn't clobbered
965 // by anons' publicly cacheable generated CSS.
966 $siteargs .= '&smaxage=0';
969 # Add user-specific code if this is a user and we allow that kind of thing
971 if ( $wgAllowUserCss && $this->loggedin
) {
972 $action = $wgRequest->getText('action');
974 # if we're previewing the CSS page, use it
975 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
976 $siteargs = "&smaxage=0&maxage=0";
977 $usercss = $wgRequest->getText('wpTextbox1');
979 $usercss = '@import "' .
980 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
981 'action=raw&ctype=text/css') . '";' ."\n";
984 $siteargs .= '&ts=' . $wgUser->mTouched
;
987 if( $wgContLang->isRTL() ) {
988 global $wgStyleVersion;
989 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
992 # If we use the site's dynamic CSS, throw that in, too
993 if ( $wgUseSiteCss ) {
994 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
996 if (($us = $wgRequest->getVal('useskin', '')) !== '')
997 $skinquery = "&useskin=$us";
998 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
999 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1000 $sitecss .= '@import "' . self
::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1003 # If we use any dynamic CSS, make a little CDATA block out of it.
1005 if ( !empty($sitecss) ||
!empty($usercss) ) {
1006 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1008 wfProfileOut( __METHOD__
);
1014 function setupUserJs( $allowUserJs ) {
1015 wfProfileIn( __METHOD__
);
1017 global $wgRequest, $wgJsMimeType;
1018 $action = $wgRequest->getText('action');
1020 if( $allowUserJs && $this->loggedin
) {
1021 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1022 # XXX: additional security check/prompt?
1023 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1025 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
1028 wfProfileOut( __METHOD__
);
1032 * Code for extensions to hook into to provide per-page CSS, see
1033 * extensions/PageCSS/PageCSS.php for an implementation of this.
1037 function setupPageCss() {
1038 wfProfileIn( __METHOD__
);
1040 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1042 wfProfileOut( __METHOD__
);
1047 * returns css with user-specific options
1049 public function getUserStylesheet() {
1050 wfProfileIn( __METHOD__
);
1052 $s = "/* generated user stylesheet */\n";
1053 $s .= $this->reallyDoGetUserStyles();
1054 wfProfileOut( __METHOD__
);
1059 * Returns the print stylesheet for this skin. In all default skins this
1060 * is just commonPrint.css, but third-party skins may want to modify it.
1064 protected function getPrintCss() {
1065 global $wgStylePath;
1066 return $wgStylePath . "/common/commonPrint.css";
1070 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1071 * nated together. For some bizarre reason, it does *not* return any
1072 * custom user JS from subpages. Huh?
1074 * There's absolutely no reason to have separate Monobook/Common JSes.
1075 * Any JS that cares can just check the skin variable generated at the
1076 * top. For now Monobook.js will be maintained, but it should be consi-
1081 public function getUserJs() {
1082 wfProfileIn( __METHOD__
);
1084 $s = parent
::getUserJs();
1085 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js */\n";
1087 // avoid inclusion of non defined user JavaScript (with custom skins only)
1088 // by checking for default message content
1089 $msgKey = ucfirst($this->skinname
).'.js';
1090 $userJS = wfMsgForContent($msgKey);
1091 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1095 wfProfileOut( __METHOD__
);
1101 * Generic wrapper for template functions, with interface
1102 * compatible with what we use of PHPTAL 0.7.
1105 class QuickTemplate
{
1109 function QuickTemplate() {
1110 $this->data
= array();
1111 $this->translator
= new MediaWiki_I18N();
1117 function set( $name, $value ) {
1118 $this->data
[$name] = $value;
1124 function setRef($name, &$value) {
1125 $this->data
[$name] =& $value;
1131 function setTranslator( &$t ) {
1132 $this->translator
= &$t;
1138 function execute() {
1139 echo "Override this function.";
1146 function text( $str ) {
1147 echo htmlspecialchars( $this->data
[$str] );
1153 function jstext( $str ) {
1154 echo Xml
::escapeJsString( $this->data
[$str] );
1160 function html( $str ) {
1161 echo $this->data
[$str];
1167 function msg( $str ) {
1168 echo htmlspecialchars( $this->translator
->translate( $str ) );
1174 function msgHtml( $str ) {
1175 echo $this->translator
->translate( $str );
1179 * An ugly, ugly hack.
1182 function msgWiki( $str ) {
1183 global $wgParser, $wgTitle, $wgOut;
1185 $text = $this->translator
->translate( $str );
1186 $parserOutput = $wgParser->parse( $text, $wgTitle,
1187 $wgOut->parserOptions(), true );
1188 echo $parserOutput->getText();
1194 function haveData( $str ) {
1195 return isset( $this->data
[$str] );
1201 function haveMsg( $str ) {
1202 $msg = $this->translator
->translate( $str );
1203 return ($msg != '-') && ($msg != ''); # ????