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 stylesheet filenames (relative from skins path), with options
92 * for CSS media, IE conditions, and RTL/LTR direction.
93 * For internal use; add settings in the skin via $this->addStyle()
95 var $styles = array();
100 * Setup the base parameters...
101 * Child classes should override this to set the name,
102 * style subdirectory, and template filler callback.
104 * @param OutputPage $out
106 function initPage( &$out ) {
107 parent
::initPage( $out );
108 $this->skinname
= 'monobook';
109 $this->stylename
= 'monobook';
110 $this->template
= 'QuickTemplate';
112 $this->addStyle( 'common/shared.css', 'screen' );
113 $this->addStyle( 'common/commonPrint.css', 'print' );
117 * Create the template engine object; we feed it a bunch of data
118 * and eventually it spits out some HTML. Should have interface
119 * roughly equivalent to PHPTAL 0.7.
121 * @param string $callback (or file)
122 * @param string $repository subdirectory where we keep template files
123 * @param string $cache_dir
127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
128 return new $classname();
132 * initialize various variables and generate the template
134 * @param OutputPage $out
137 function outputPage( &$out ) {
138 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
139 global $wgScript, $wgStylePath, $wgContLanguageCode;
140 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
141 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
142 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
143 global $wgMaxCredits, $wgShowCreditsIfMax;
144 global $wgPageShowWatchingUsers;
145 global $wgUseTrackbacks, $wgUseSiteJs;
146 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
148 wfProfileIn( __METHOD__
);
150 $oldid = $wgRequest->getVal( 'oldid' );
151 $diff = $wgRequest->getVal( 'diff' );
153 wfProfileIn( __METHOD__
."-init" );
154 $this->initPage( $out );
156 $this->mTitle
=& $wgTitle;
157 $this->mUser
=& $wgUser;
159 $tpl = $this->setupTemplate( $this->template
, 'skins' );
161 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
162 $tpl->setTranslator(new MediaWiki_I18N());
164 wfProfileOut( __METHOD__
."-init" );
166 wfProfileIn( __METHOD__
."-stuff" );
167 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
168 $this->thisurl
= $this->mTitle
->getPrefixedURL();
169 $this->loggedin
= $wgUser->isLoggedIn();
170 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
171 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
172 $this->username
= $wgUser->getName();
173 $userPage = $wgUser->getUserPage();
174 $this->userpage
= $userPage->getPrefixedText();
176 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
177 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
179 # This won't be used in the standard skins, but we define it to preserve the interface
180 # To save time, we check for existence
181 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
184 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
185 $this->setupUserCss( $out->getExtStyle() );
186 $this->setupUserJs( $out->isUserJsAllowed() );
187 $this->titletxt
= $this->mTitle
->getPrefixedText();
188 wfProfileOut( __METHOD__
."-stuff" );
190 wfProfileIn( __METHOD__
."-stuff2" );
191 $tpl->set( 'title', $wgOut->getPageTitle() );
192 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
193 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
194 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
195 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer
::escapeClass( $this->getSkinName ( ) ) ) );
197 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
198 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
199 $this->mTitle
->getNsText();
201 $tpl->set( 'nscanonical', $nsname );
202 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
203 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
204 $tpl->set( 'titletext', $this->mTitle
->getText() );
205 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
206 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
208 $tpl->set( 'isarticle', $wgOut->isArticle() );
210 $tpl->setRef( "thispage", $this->thispage
);
211 $subpagestr = $this->subPageSubtitle();
213 'subtitle', !empty($subpagestr)?
214 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
217 $undelete = $this->getUndeleteLink();
219 "undelete", !empty($undelete)?
220 '<span class="subpages">'.$undelete.'</span>':
224 $tpl->set( 'catlinks', $this->getCategories());
225 if( $wgOut->isSyndicated() ) {
227 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
228 $feeds[$format] = array(
229 'text' => wfMsg( "feed-$format" ),
232 $tpl->setRef( 'feeds', $feeds );
234 $tpl->set( 'feeds', false );
236 if ($wgUseTrackbacks && $out->isArticleRelated()) {
237 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
239 $tpl->set( 'trackbackhtml', null );
242 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
243 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
244 $tpl->setRef( 'mimetype', $wgMimeType );
245 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
246 $tpl->setRef( 'charset', $wgOutputEncoding );
247 $tpl->set( 'headlinks', $out->getHeadLinks() );
248 $tpl->set('headscripts', $out->getScript() );
249 $tpl->setRef( 'wgScript', $wgScript );
250 $tpl->setRef( 'skinname', $this->skinname
);
251 $tpl->set( 'skinclass', get_class( $this ) );
252 $tpl->setRef( 'stylename', $this->stylename
);
253 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
254 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
255 $tpl->set( 'csslinks', $this->buildCssLinks() );
256 $tpl->setRef( 'loggedin', $this->loggedin
);
257 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
258 /* XXX currently unused, might get useful later
259 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
260 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
261 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
262 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
263 $tpl->set( "helppage", wfMsg('helppage'));
265 $tpl->set( 'searchaction', $this->escapeSearchLink() );
266 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
267 $tpl->setRef( 'stylepath', $wgStylePath );
268 $tpl->setRef( 'articlepath', $wgArticlePath );
269 $tpl->setRef( 'scriptpath', $wgScriptPath );
270 $tpl->setRef( 'serverurl', $wgServer );
271 $tpl->setRef( 'logopath', $wgLogo );
272 $tpl->setRef( "lang", $wgContLanguageCode );
273 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
274 $tpl->set( 'rtl', $wgContLang->isRTL() );
275 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
276 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
277 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
278 $tpl->setRef( 'userpage', $this->userpage
);
279 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
280 $tpl->set( 'userlang', $wgLang->getCode() );
281 $tpl->set( 'pagecss', $this->setupPageCss() );
282 $tpl->setRef( 'usercss', $this->usercss
);
283 $tpl->setRef( 'userjs', $this->userjs
);
284 $tpl->setRef( 'userjsprev', $this->userjsprev
);
286 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
287 $tpl->set( 'jsvarurl',
289 "action=raw$jsCache&gen=js&useskin=" .
290 urlencode( $this->getSkinName() ) ) );
292 $tpl->set('jsvarurl', false);
294 $newtalks = $wgUser->getNewMessageLinks();
296 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
297 $usertitle = $this->mUser
->getUserPage();
298 $usertalktitle = $usertitle->getTalkPage();
299 if( !$usertalktitle->equals( $this->mTitle
) ) {
300 $ntl = wfMsg( 'youhavenewmessages',
301 $this->makeKnownLinkObj(
303 wfMsgHtml( 'newmessageslink' ),
306 $this->makeKnownLinkObj(
308 wfMsgHtml( 'newmessagesdifflink' ),
313 $wgOut->setSquidMaxage(0);
315 } else if (count($newtalks)) {
316 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
318 foreach ($newtalks as $newtalk) {
319 $msgs[] = wfElement("a",
320 array('href' => $newtalk["link"]), $newtalk["wiki"]);
322 $parts = implode($sep, $msgs);
323 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
324 $wgOut->setSquidMaxage(0);
328 wfProfileOut( __METHOD__
."-stuff2" );
330 wfProfileIn( __METHOD__
."-stuff3" );
331 $tpl->setRef( 'newtalk', $ntl );
332 $tpl->setRef( 'skin', $this );
333 $tpl->set( 'logo', $this->logoText() );
334 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
335 $wgArticle and 0 != $wgArticle->getID() )
337 if ( !$wgDisableCounters ) {
338 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
340 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
342 $tpl->set('viewcount', false);
345 $tpl->set('viewcount', false);
348 if ($wgPageShowWatchingUsers) {
349 $dbr = wfGetDB( DB_SLAVE
);
350 $watchlist = $dbr->tableName( 'watchlist' );
351 $sql = "SELECT COUNT(*) AS n FROM $watchlist
352 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
353 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
354 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
355 $x = $dbr->fetchObject( $res );
356 $numberofwatchingusers = $x->n
;
357 if ($numberofwatchingusers > 0) {
358 $tpl->set('numberofwatchingusers',
359 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
360 $wgLang->formatNum($numberofwatchingusers))
363 $tpl->set('numberofwatchingusers', false);
366 $tpl->set('numberofwatchingusers', false);
369 $tpl->set('copyright',$this->getCopyright());
371 $this->credits
= false;
373 if( $wgMaxCredits != 0 ){
374 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
376 $tpl->set( 'lastmod', $this->lastModified() );
379 $tpl->setRef( 'credits', $this->credits
);
381 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
382 $tpl->set('copyright', $this->getCopyright());
383 $tpl->set('viewcount', false);
384 $tpl->set('lastmod', false);
385 $tpl->set('credits', false);
386 $tpl->set('numberofwatchingusers', false);
388 $tpl->set('copyright', false);
389 $tpl->set('viewcount', false);
390 $tpl->set('lastmod', false);
391 $tpl->set('credits', false);
392 $tpl->set('numberofwatchingusers', false);
394 wfProfileOut( __METHOD__
."-stuff3" );
396 wfProfileIn( __METHOD__
."-stuff4" );
397 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
398 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
399 $tpl->set( 'disclaimer', $this->disclaimerLink() );
400 $tpl->set( 'privacy', $this->privacyLink() );
401 $tpl->set( 'about', $this->aboutLink() );
403 $tpl->setRef( 'debug', $out->mDebugtext
);
404 $tpl->set( 'reporttime', wfReportTime() );
405 $tpl->set( 'sitenotice', wfGetSiteNotice() );
406 $tpl->set( 'bottomscripts', $this->bottomScripts() );
408 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
409 $out->mBodytext
.= $printfooter ;
410 $tpl->setRef( 'bodytext', $out->mBodytext
);
413 $language_urls = array();
415 if ( !$wgHideInterlanguageLinks ) {
416 foreach( $wgOut->getLanguageLinks() as $l ) {
417 $tmp = explode( ':', $l, 2 );
418 $class = 'interwiki-' . $tmp[0];
420 $nt = Title
::newFromText( $l );
421 $language_urls[] = array(
422 'href' => $nt->getFullURL(),
423 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
428 if(count($language_urls)) {
429 $tpl->setRef( 'language_urls', $language_urls);
431 $tpl->set('language_urls', false);
433 wfProfileOut( __METHOD__
."-stuff4" );
436 $tpl->set('personal_urls', $this->buildPersonalUrls());
437 $content_actions = $this->buildContentActionUrls();
438 $tpl->setRef('content_actions', $content_actions);
440 // XXX: attach this from javascript, same with section editing
441 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
443 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
444 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
446 $tpl->set('body_ondblclick', false);
448 $tpl->set( 'body_onload', false );
449 $tpl->set( 'sidebar', $this->buildSidebar() );
450 $tpl->set( 'nav_urls', $this->buildNavUrls() );
452 // original version by hansm
453 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
454 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
457 // allow extensions adding stuff after the page content.
458 // See Skin::afterContentHook() for further documentation.
459 $tpl->set ('dataAfterContent', $this->afterContentHook());
462 wfProfileIn( __METHOD__
."-execute" );
463 $res = $tpl->execute();
464 wfProfileOut( __METHOD__
."-execute" );
466 // result may be an error
467 $this->printOrError( $res );
468 wfProfileOut( __METHOD__
);
472 * Output the string, or print error message if it's
473 * an error object of the appropriate type.
474 * For the base class, assume strings all around.
479 function printOrError( $str ) {
484 * build array of urls for personal toolbar
488 function buildPersonalUrls() {
489 global $wgTitle, $wgRequest;
491 $pageurl = $wgTitle->getLocalURL();
492 wfProfileIn( __METHOD__
);
494 /* set up the default links for the personal toolbar */
495 $personal_urls = array();
496 if ($this->loggedin
) {
497 $personal_urls['userpage'] = array(
498 'text' => $this->username
,
499 'href' => &$this->userpageUrlDetails
['href'],
500 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
501 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
503 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
504 $personal_urls['mytalk'] = array(
505 'text' => wfMsg('mytalk'),
506 'href' => &$usertalkUrlDetails['href'],
507 'class' => $usertalkUrlDetails['exists']?
false:'new',
508 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
510 $href = self
::makeSpecialUrl( 'Preferences' );
511 $personal_urls['preferences'] = array(
512 'text' => wfMsg( 'mypreferences' ),
514 'active' => ( $href == $pageurl )
516 $href = self
::makeSpecialUrl( 'Watchlist' );
517 $personal_urls['watchlist'] = array(
518 'text' => wfMsg( 'mywatchlist' ),
520 'active' => ( $href == $pageurl )
523 # We need to do an explicit check for Special:Contributions, as we
524 # have to match both the title, and the target (which could come
525 # from request values or be specified in "sub page" form. The plot
526 # thickens, because $wgTitle is altered for special pages, so doesn't
527 # contain the original alias-with-subpage.
528 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
529 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
530 list( $spName, $spPar ) =
531 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
532 $active = $spName == 'Contributions'
533 && ( ( $spPar && $spPar == $this->username
)
534 ||
$wgRequest->getText( 'target' ) == $this->username
);
539 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
540 $personal_urls['mycontris'] = array(
541 'text' => wfMsg( 'mycontris' ),
545 $personal_urls['logout'] = array(
546 'text' => wfMsg( 'userlogout' ),
547 'href' => self
::makeSpecialUrl( 'Userlogout',
548 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
554 $loginlink = $wgUser->isAllowed( 'createaccount' )
555 ?
'nav-login-createaccount'
557 if( $this->showIPinHeader() ) {
558 $href = &$this->userpageUrlDetails
['href'];
559 $personal_urls['anonuserpage'] = array(
560 'text' => $this->username
,
562 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
563 'active' => ( $pageurl == $href )
565 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
566 $href = &$usertalkUrlDetails['href'];
567 $personal_urls['anontalk'] = array(
568 'text' => wfMsg('anontalk'),
570 'class' => $usertalkUrlDetails['exists']?
false:'new',
571 'active' => ( $pageurl == $href )
573 $personal_urls['anonlogin'] = array(
574 'text' => wfMsg( $loginlink ),
575 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
576 'active' => $wgTitle->isSpecial( 'Userlogin' )
580 $personal_urls['login'] = array(
581 'text' => wfMsg( $loginlink ),
582 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
583 'active' => $wgTitle->isSpecial( 'Userlogin' )
588 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
589 wfProfileOut( __METHOD__
);
590 return $personal_urls;
593 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
596 $classes[] = 'selected';
598 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
600 $query = 'action=edit';
603 $text = wfMsg( $message );
604 if ( wfEmptyMsg( $message, $text ) ) {
606 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
610 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
611 $title, $message, $selected, $checkEdit,
612 &$classes, &$query, &$text, &$result)) ) {
617 'class' => implode( ' ', $classes ),
619 'href' => $title->getLocalUrl( $query ) );
622 function makeTalkUrlDetails( $name, $urlaction = '' ) {
623 $title = Title
::newFromText( $name );
624 if( !is_object($title) ) {
625 throw new MWException( __METHOD__
." given invalid pagename $name" );
627 $title = $title->getTalkPage();
628 self
::checkTitle( $title, $name );
630 'href' => $title->getLocalURL( $urlaction ),
631 'exists' => $title->getArticleID() != 0 ?
true : false
635 function makeArticleUrlDetails( $name, $urlaction = '' ) {
636 $title = Title
::newFromText( $name );
637 $title= $title->getSubjectPage();
638 self
::checkTitle( $title, $name );
640 'href' => $title->getLocalURL( $urlaction ),
641 'exists' => $title->getArticleID() != 0 ?
true : false
646 * an array of edit links by default used for the tabs
650 function buildContentActionUrls () {
651 global $wgContLang, $wgLang, $wgOut;
652 wfProfileIn( __METHOD__
);
654 global $wgUser, $wgRequest;
655 $action = $wgRequest->getText( 'action' );
656 $section = $wgRequest->getText( 'section' );
657 $content_actions = array();
659 $prevent_active_tabs = false ;
660 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
662 if( $this->iscontent
) {
663 $subjpage = $this->mTitle
->getSubjectPage();
664 $talkpage = $this->mTitle
->getTalkPage();
666 $nskey = $this->mTitle
->getNamespaceKey();
667 $content_actions[$nskey] = $this->tabAction(
670 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
673 $content_actions['talk'] = $this->tabAction(
676 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
680 wfProfileIn( __METHOD__
."-edit" );
681 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
682 $istalk = $this->mTitle
->isTalkPage();
683 $istalkclass = $istalk?
' istalk':'';
684 $content_actions['edit'] = array(
685 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
686 'text' => $this->mTitle
->exists()
689 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
692 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
693 $content_actions['addsection'] = array(
694 'class' => $section == 'new'?
'selected':false,
695 'text' => wfMsg('addsection'),
696 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
699 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
700 $content_actions['viewsource'] = array(
701 'class' => ($action == 'edit') ?
'selected' : false,
702 'text' => wfMsg('viewsource'),
703 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
706 wfProfileOut( __METHOD__
."-edit" );
708 wfProfileIn( __METHOD__
."-live" );
709 if ( $this->mTitle
->exists() ) {
711 $content_actions['history'] = array(
712 'class' => ($action == 'history') ?
'selected' : false,
713 'text' => wfMsg('history_short'),
714 'href' => $this->mTitle
->getLocalUrl( 'action=history')
717 if($wgUser->isAllowed('delete')){
718 $content_actions['delete'] = array(
719 'class' => ($action == 'delete') ?
'selected' : false,
720 'text' => wfMsg('delete'),
721 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
724 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
725 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
726 $content_actions['move'] = array(
727 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
728 'text' => wfMsg('move'),
729 'href' => $moveTitle->getLocalUrl()
733 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
734 if( !$this->mTitle
->isProtected() ){
735 $content_actions['protect'] = array(
736 'class' => ($action == 'protect') ?
'selected' : false,
737 'text' => wfMsg('protect'),
738 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
742 $content_actions['unprotect'] = array(
743 'class' => ($action == 'unprotect') ?
'selected' : false,
744 'text' => wfMsg('unprotect'),
745 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
750 //article doesn't exist or is deleted
751 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
752 if( $n = $this->mTitle
->isDeleted() ) {
753 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
754 $content_actions['undelete'] = array(
756 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
757 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
758 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
763 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
764 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
765 $content_actions['protect'] = array(
766 'class' => ($action == 'protect') ?
'selected' : false,
767 'text' => wfMsg('protect'),
768 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
772 $content_actions['unprotect'] = array(
773 'class' => ($action == 'unprotect') ?
'selected' : false,
774 'text' => wfMsg('unprotect'),
775 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
781 wfProfileOut( __METHOD__
."-live" );
783 if( $this->loggedin
) {
784 if( !$this->mTitle
->userIsWatching()) {
785 $content_actions['watch'] = array(
786 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
787 'text' => wfMsg('watch'),
788 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
791 $content_actions['unwatch'] = array(
792 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
793 'text' => wfMsg('unwatch'),
794 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
800 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
802 /* show special page tab */
804 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
805 'class' => 'selected',
806 'text' => wfMsg('nstab-special'),
807 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
810 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
813 /* show links to different language variants */
814 global $wgDisableLangConversion;
815 $variants = $wgContLang->getVariants();
816 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
817 $preferred = $wgContLang->getPreferredVariant();
819 foreach( $variants as $code ) {
820 $varname = $wgContLang->getVariantname( $code );
821 if( $varname == 'disable' )
823 $selected = ( $code == $preferred )?
'selected' : false;
824 $content_actions['varlang-' . $vcount] = array(
825 'class' => $selected,
827 'href' => $this->mTitle
->getLocalURL('',$code)
833 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
835 wfProfileOut( __METHOD__
);
836 return $content_actions;
842 * build array of common navigation links
846 function buildNavUrls () {
847 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
848 global $wgEnableUploads, $wgUploadNavigationUrl;
850 wfProfileIn( __METHOD__
);
852 $action = $wgRequest->getText( 'action' );
855 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
856 if( $wgEnableUploads ) {
857 if ($wgUploadNavigationUrl) {
858 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
860 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
863 if ($wgUploadNavigationUrl)
864 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
866 $nav_urls['upload'] = false;
868 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
870 // default permalink to being off, will override it as required below.
871 $nav_urls['permalink'] = false;
873 // A print stylesheet is attached to all pages, but nobody ever
874 // figures that out. :) Add a link...
875 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
876 $nav_urls['print'] = array(
877 'text' => wfMsg( 'printableversion' ),
878 'href' => $wgRequest->appendQuery( 'printable=yes' )
881 // Also add a "permalink" while we're at it
882 if ( $this->mRevisionId
) {
883 $nav_urls['permalink'] = array(
884 'text' => wfMsg( 'permalink' ),
885 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
889 // Copy in case this undocumented, shady hook tries to mess with internals
890 $revid = $this->mRevisionId
;
891 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
894 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
895 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
896 $nav_urls['whatlinkshere'] = array(
897 'href' => $wlhTitle->getLocalUrl()
899 if( $this->mTitle
->getArticleId() ) {
900 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
901 $nav_urls['recentchangeslinked'] = array(
902 'href' => $rclTitle->getLocalUrl()
905 $nav_urls['recentchangeslinked'] = false;
907 if ($wgUseTrackbacks)
908 $nav_urls['trackbacklink'] = array(
909 'href' => $wgTitle->trackbackURL()
913 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
914 $id = User
::idFromName($this->mTitle
->getText());
915 $ip = User
::isIP($this->mTitle
->getText());
921 if($id ||
$ip) { # both anons and non-anons have contribs list
922 $nav_urls['contributions'] = array(
923 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
927 $logPage = SpecialPage
::getTitleFor( 'Log' );
928 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
929 . $this->mTitle
->getPartialUrl() ) );
931 $nav_urls['log'] = false;
934 if ( $wgUser->isAllowed( 'block' ) ) {
935 $nav_urls['blockip'] = array(
936 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
939 $nav_urls['blockip'] = false;
942 $nav_urls['contributions'] = false;
943 $nav_urls['log'] = false;
944 $nav_urls['blockip'] = false;
946 $nav_urls['emailuser'] = false;
947 if( $this->showEmailUser( $id ) ) {
948 $nav_urls['emailuser'] = array(
949 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
952 wfProfileOut( __METHOD__
);
957 * Generate strings used for xml 'id' names
961 function getNameSpaceKey () {
962 return $this->mTitle
->getNamespaceKey();
968 function setupUserCss( $extCSS = array() ) {
969 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
971 wfProfileIn( __METHOD__
);
975 'maxage' => $wgSquidMaxage,
977 if( $this->loggedin
) {
978 // Ensure that logged-in users' generated CSS isn't clobbered
979 // by anons' publicly cacheable generated CSS.
980 $siteargs['smaxage'] = '0';
981 $siteargs['ts'] = $wgUser->mTouched
;
984 // Add any extension CSS
985 foreach( $extCSS as $tag ) {
986 $this->addStyle( $tag['href'] );
989 // If we use the site's dynamic CSS, throw that in, too
990 // Per-site custom styles
991 if ( $wgUseSiteCss ) {
992 $query = wfArrayToCGI( array(
993 'usemsgcache' => 'yes',
994 'ctype' => 'text/css',
995 'smaxage' => $wgSquidMaxage
997 $this->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
998 $this->addStyle( self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
),
1002 // Per-user styles based on preferences
1003 $siteargs['gen'] = 'css';
1004 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' )
1005 $siteargs['useskin'] = $us;
1006 $this->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ), 'screen' );
1008 // Per-user custom style pages
1009 if ( $wgAllowUserCss && $this->loggedin
) {
1010 $action = $wgRequest->getVal('action');
1012 # if we're previewing the CSS page, use it
1013 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
1014 $previewCss = $wgRequest->getText('wpTextbox1');
1016 /// @fixme properly escape the cdata!
1017 $this->usercss
= "/*<![CDATA[*/\n" .
1021 $this->addStyle( self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
1022 'action=raw&ctype=text/css'), 'screen' );
1026 wfProfileOut( __METHOD__
);
1032 function setupUserJs( $allowUserJs ) {
1033 wfProfileIn( __METHOD__
);
1035 global $wgRequest, $wgJsMimeType;
1036 $action = $wgRequest->getText('action');
1038 if( $allowUserJs && $this->loggedin
) {
1039 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1040 # XXX: additional security check/prompt?
1041 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1043 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
1046 wfProfileOut( __METHOD__
);
1050 * Code for extensions to hook into to provide per-page CSS, see
1051 * extensions/PageCSS/PageCSS.php for an implementation of this.
1055 function setupPageCss() {
1056 wfProfileIn( __METHOD__
);
1058 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1060 wfProfileOut( __METHOD__
);
1065 * returns css with user-specific options
1067 public function getUserStylesheet() {
1068 wfProfileIn( __METHOD__
);
1070 $s = "/* generated user stylesheet */\n";
1071 $s .= $this->reallyDoGetUserStyles();
1072 wfProfileOut( __METHOD__
);
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__
);
1107 * Add a local or specified stylesheet, with the given media options.
1108 * Meant primarily for internal use...
1110 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1111 * @param $conditional -- for IE conditional comments, specifying an IE version
1112 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1114 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1117 $options['media'] = $media;
1119 $options['condition'] = $condition;
1121 $options['dir'] = $dir;
1122 $this->styles
[$style] = $options;
1126 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1127 * These will be applied to various media & IE conditionals.
1129 protected function buildCssLinks() {
1131 foreach( $this->styles
as $file => $options ) {
1132 $link = $this->styleLink( $file, $options );
1137 return implode( "\n\t\t", $links );
1140 protected function styleLink( $style, $options ) {
1143 if( isset( $options['dir'] ) ) {
1145 $siteDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
1146 if( $siteDir != $options['dir'] )
1150 if( isset( $options['media'] ) ) {
1151 $media = $this->transformCssMedia( $options['media'] );
1152 if( is_null( $media ) ) {
1159 if( substr( $style, 0, 1 ) == '/' ||
1160 substr( $style, 0, 5 ) == 'http:' ||
1161 substr( $style, 0, 6 ) == 'https:' ) {
1164 global $wgStylePath, $wgStyleVersion;
1165 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1169 'rel' => 'stylesheet',
1171 'type' => 'text/css' );
1173 $attribs['media'] = $media;
1176 $link = Xml
::element( 'link', $attribs );
1178 if( isset( $options['condition'] ) ) {
1179 $condition = htmlspecialchars( $options['condition'] );
1180 $link = "<!--[if $condition]>$link<![endif]-->";
1185 function transformCssMedia( $media ) {
1186 global $wgRequest, $wgHandheldForIPhone;
1188 // Switch in on-screen display for media testing
1190 'printable' => 'print',
1191 'handheld' => 'handheld',
1193 foreach( $switches as $switch => $targetMedia ) {
1194 if( $wgRequest->getBool( $switch ) ) {
1195 if( $media == $targetMedia ) {
1197 } elseif( $media == 'screen' ) {
1203 // Expand longer media queries as iPhone doesn't grok 'handheld'
1204 if( $wgHandheldForIPhone ) {
1205 $mediaAliases = array(
1206 'screen' => 'screen and (min-device-width: 481px)',
1207 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1210 if( isset( $mediaAliases[$media] ) ) {
1211 $media = $mediaAliases[$media];
1221 * Generic wrapper for template functions, with interface
1222 * compatible with what we use of PHPTAL 0.7.
1225 class QuickTemplate
{
1229 function QuickTemplate() {
1230 $this->data
= array();
1231 $this->translator
= new MediaWiki_I18N();
1237 function set( $name, $value ) {
1238 $this->data
[$name] = $value;
1244 function setRef($name, &$value) {
1245 $this->data
[$name] =& $value;
1251 function setTranslator( &$t ) {
1252 $this->translator
= &$t;
1258 function execute() {
1259 echo "Override this function.";
1266 function text( $str ) {
1267 echo htmlspecialchars( $this->data
[$str] );
1273 function jstext( $str ) {
1274 echo Xml
::escapeJsString( $this->data
[$str] );
1280 function html( $str ) {
1281 echo $this->data
[$str];
1287 function msg( $str ) {
1288 echo htmlspecialchars( $this->translator
->translate( $str ) );
1294 function msgHtml( $str ) {
1295 echo $this->translator
->translate( $str );
1299 * An ugly, ugly hack.
1302 function msgWiki( $str ) {
1303 global $wgParser, $wgTitle, $wgOut;
1305 $text = $this->translator
->translate( $str );
1306 $parserOutput = $wgParser->parse( $text, $wgTitle,
1307 $wgOut->parserOptions(), true );
1308 echo $parserOutput->getText();
1314 function haveData( $str ) {
1315 return isset( $this->data
[$str] );
1321 function haveMsg( $str ) {
1322 $msg = $this->translator
->translate( $str );
1323 return ($msg != '-') && ($msg != ''); # ????