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();
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', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
196 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
197 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
198 $this->mTitle
->getNsText();
200 $tpl->set( 'nscanonical', $nsname );
201 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
202 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
203 $tpl->set( 'titletext', $this->mTitle
->getText() );
204 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
205 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
207 $tpl->set( 'isarticle', $wgOut->isArticle() );
209 $tpl->setRef( "thispage", $this->thispage
);
210 $subpagestr = $this->subPageSubtitle();
212 'subtitle', !empty($subpagestr)?
213 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
216 $undelete = $this->getUndeleteLink();
218 "undelete", !empty($undelete)?
219 '<span class="subpages">'.$undelete.'</span>':
223 $tpl->set( 'catlinks', $this->getCategories());
224 if( $wgOut->isSyndicated() ) {
226 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
227 $feeds[$format] = array(
228 'text' => wfMsg( "feed-$format" ),
231 $tpl->setRef( 'feeds', $feeds );
233 $tpl->set( 'feeds', false );
235 if ($wgUseTrackbacks && $out->isArticleRelated()) {
236 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
238 $tpl->set( 'trackbackhtml', null );
241 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
242 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
243 $tpl->setRef( 'mimetype', $wgMimeType );
244 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
245 $tpl->setRef( 'charset', $wgOutputEncoding );
246 $tpl->set( 'headlinks', $out->getHeadLinks() );
247 $tpl->set('headscripts', $out->getScript() );
248 $tpl->setRef( 'wgScript', $wgScript );
249 $tpl->setRef( 'skinname', $this->skinname
);
250 $tpl->set( 'skinclass', get_class( $this ) );
251 $tpl->setRef( 'stylename', $this->stylename
);
252 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
253 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
254 $tpl->set( 'csslinks', $this->buildCssLinks() );
255 $tpl->setRef( 'loggedin', $this->loggedin
);
256 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
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 (isset($wgMaxCredits) && $wgMaxCredits != 0) {
374 require_once("Credits.php");
375 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
377 $tpl->set('lastmod', $this->lastModified());
380 $tpl->setRef( 'credits', $this->credits
);
382 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
383 $tpl->set('copyright', $this->getCopyright());
384 $tpl->set('viewcount', false);
385 $tpl->set('lastmod', false);
386 $tpl->set('credits', false);
387 $tpl->set('numberofwatchingusers', false);
389 $tpl->set('copyright', false);
390 $tpl->set('viewcount', false);
391 $tpl->set('lastmod', false);
392 $tpl->set('credits', false);
393 $tpl->set('numberofwatchingusers', false);
395 wfProfileOut( __METHOD__
."-stuff3" );
397 wfProfileIn( __METHOD__
."-stuff4" );
398 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
399 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
400 $tpl->set( 'disclaimer', $this->disclaimerLink() );
401 $tpl->set( 'privacy', $this->privacyLink() );
402 $tpl->set( 'about', $this->aboutLink() );
404 $tpl->setRef( 'debug', $out->mDebugtext
);
405 $tpl->set( 'reporttime', wfReportTime() );
406 $tpl->set( 'sitenotice', wfGetSiteNotice() );
407 $tpl->set( 'bottomscripts', $this->bottomScripts() );
409 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
410 $out->mBodytext
.= $printfooter ;
411 $tpl->setRef( 'bodytext', $out->mBodytext
);
414 $language_urls = array();
416 if ( !$wgHideInterlanguageLinks ) {
417 foreach( $wgOut->getLanguageLinks() as $l ) {
418 $tmp = explode( ':', $l, 2 );
419 $class = 'interwiki-' . $tmp[0];
421 $nt = Title
::newFromText( $l );
422 $language_urls[] = array(
423 'href' => $nt->getFullURL(),
424 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
429 if(count($language_urls)) {
430 $tpl->setRef( 'language_urls', $language_urls);
432 $tpl->set('language_urls', false);
434 wfProfileOut( __METHOD__
."-stuff4" );
437 $tpl->set('personal_urls', $this->buildPersonalUrls());
438 $content_actions = $this->buildContentActionUrls();
439 $tpl->setRef('content_actions', $content_actions);
441 // XXX: attach this from javascript, same with section editing
442 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
444 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
445 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
447 $tpl->set('body_ondblclick', false);
449 $tpl->set( 'body_onload', false );
450 $tpl->set( 'sidebar', $this->buildSidebar() );
451 $tpl->set( 'nav_urls', $this->buildNavUrls() );
453 // original version by hansm
454 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
455 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
458 // allow extensions adding stuff after the page content.
459 // See Skin::afterContentHook() for further documentation.
460 $tpl->set ('dataAfterContent', $this->afterContentHook());
463 wfProfileIn( __METHOD__
."-execute" );
464 $res = $tpl->execute();
465 wfProfileOut( __METHOD__
."-execute" );
467 // result may be an error
468 $this->printOrError( $res );
469 wfProfileOut( __METHOD__
);
473 * Output the string, or print error message if it's
474 * an error object of the appropriate type.
475 * For the base class, assume strings all around.
480 function printOrError( $str ) {
485 * build array of urls for personal toolbar
489 function buildPersonalUrls() {
490 global $wgTitle, $wgRequest;
492 $pageurl = $wgTitle->getLocalURL();
493 wfProfileIn( __METHOD__
);
495 /* set up the default links for the personal toolbar */
496 $personal_urls = array();
497 if ($this->loggedin
) {
498 $personal_urls['userpage'] = array(
499 'text' => $this->username
,
500 'href' => &$this->userpageUrlDetails
['href'],
501 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
502 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
504 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
505 $personal_urls['mytalk'] = array(
506 'text' => wfMsg('mytalk'),
507 'href' => &$usertalkUrlDetails['href'],
508 'class' => $usertalkUrlDetails['exists']?
false:'new',
509 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
511 $href = self
::makeSpecialUrl( 'Preferences' );
512 $personal_urls['preferences'] = array(
513 'text' => wfMsg( 'mypreferences' ),
515 'active' => ( $href == $pageurl )
517 $href = self
::makeSpecialUrl( 'Watchlist' );
518 $personal_urls['watchlist'] = array(
519 'text' => wfMsg( 'mywatchlist' ),
521 'active' => ( $href == $pageurl )
524 # We need to do an explicit check for Special:Contributions, as we
525 # have to match both the title, and the target (which could come
526 # from request values or be specified in "sub page" form. The plot
527 # thickens, because $wgTitle is altered for special pages, so doesn't
528 # contain the original alias-with-subpage.
529 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
530 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
531 list( $spName, $spPar ) =
532 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
533 $active = $spName == 'Contributions'
534 && ( ( $spPar && $spPar == $this->username
)
535 ||
$wgRequest->getText( 'target' ) == $this->username
);
540 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
541 $personal_urls['mycontris'] = array(
542 'text' => wfMsg( 'mycontris' ),
546 $personal_urls['logout'] = array(
547 'text' => wfMsg( 'userlogout' ),
548 'href' => self
::makeSpecialUrl( 'Userlogout',
549 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
555 $loginlink = $wgUser->isAllowed( 'createaccount' )
556 ?
'nav-login-createaccount'
558 if( $this->showIPinHeader() ) {
559 $href = &$this->userpageUrlDetails
['href'];
560 $personal_urls['anonuserpage'] = array(
561 'text' => $this->username
,
563 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
564 'active' => ( $pageurl == $href )
566 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
567 $href = &$usertalkUrlDetails['href'];
568 $personal_urls['anontalk'] = array(
569 'text' => wfMsg('anontalk'),
571 'class' => $usertalkUrlDetails['exists']?
false:'new',
572 'active' => ( $pageurl == $href )
574 $personal_urls['anonlogin'] = array(
575 'text' => wfMsg( $loginlink ),
576 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
577 'active' => $wgTitle->isSpecial( 'Userlogin' )
581 $personal_urls['login'] = array(
582 'text' => wfMsg( $loginlink ),
583 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
584 'active' => $wgTitle->isSpecial( 'Userlogin' )
589 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
590 wfProfileOut( __METHOD__
);
591 return $personal_urls;
594 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
597 $classes[] = 'selected';
599 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
601 $query = 'action=edit';
604 $text = wfMsg( $message );
605 if ( wfEmptyMsg( $message, $text ) ) {
607 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
611 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
612 $title, $message, $selected, $checkEdit,
613 &$classes, &$query, &$text, &$result)) ) {
618 'class' => implode( ' ', $classes ),
620 'href' => $title->getLocalUrl( $query ) );
623 function makeTalkUrlDetails( $name, $urlaction = '' ) {
624 $title = Title
::newFromText( $name );
625 if( !is_object($title) ) {
626 throw new MWException( __METHOD__
." given invalid pagename $name" );
628 $title = $title->getTalkPage();
629 self
::checkTitle( $title, $name );
631 'href' => $title->getLocalURL( $urlaction ),
632 'exists' => $title->getArticleID() != 0 ?
true : false
636 function makeArticleUrlDetails( $name, $urlaction = '' ) {
637 $title = Title
::newFromText( $name );
638 $title= $title->getSubjectPage();
639 self
::checkTitle( $title, $name );
641 'href' => $title->getLocalURL( $urlaction ),
642 'exists' => $title->getArticleID() != 0 ?
true : false
647 * an array of edit links by default used for the tabs
651 function buildContentActionUrls () {
652 global $wgContLang, $wgLang, $wgOut;
653 wfProfileIn( __METHOD__
);
655 global $wgUser, $wgRequest;
656 $action = $wgRequest->getText( 'action' );
657 $section = $wgRequest->getText( 'section' );
658 $content_actions = array();
660 $prevent_active_tabs = false ;
661 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
663 if( $this->iscontent
) {
664 $subjpage = $this->mTitle
->getSubjectPage();
665 $talkpage = $this->mTitle
->getTalkPage();
667 $nskey = $this->mTitle
->getNamespaceKey();
668 $content_actions[$nskey] = $this->tabAction(
671 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
674 $content_actions['talk'] = $this->tabAction(
677 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
681 wfProfileIn( __METHOD__
."-edit" );
682 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
683 $istalk = $this->mTitle
->isTalkPage();
684 $istalkclass = $istalk?
' istalk':'';
685 $content_actions['edit'] = array(
686 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
687 'text' => $this->mTitle
->exists()
690 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
693 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
694 $content_actions['addsection'] = array(
695 'class' => $section == 'new'?
'selected':false,
696 'text' => wfMsg('addsection'),
697 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
700 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
701 $content_actions['viewsource'] = array(
702 'class' => ($action == 'edit') ?
'selected' : false,
703 'text' => wfMsg('viewsource'),
704 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
707 wfProfileOut( __METHOD__
."-edit" );
709 wfProfileIn( __METHOD__
."-live" );
710 if ( $this->mTitle
->getArticleId() ) {
712 $content_actions['history'] = array(
713 'class' => ($action == 'history') ?
'selected' : false,
714 'text' => wfMsg('history_short'),
715 'href' => $this->mTitle
->getLocalUrl( 'action=history')
718 if($wgUser->isAllowed('delete')){
719 $content_actions['delete'] = array(
720 'class' => ($action == 'delete') ?
'selected' : false,
721 'text' => wfMsg('delete'),
722 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
725 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
726 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
727 $content_actions['move'] = array(
728 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
729 'text' => wfMsg('move'),
730 'href' => $moveTitle->getLocalUrl()
734 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
735 if(!$this->mTitle
->isProtected()){
736 $content_actions['protect'] = array(
737 'class' => ($action == 'protect') ?
'selected' : false,
738 'text' => wfMsg('protect'),
739 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
743 $content_actions['unprotect'] = array(
744 'class' => ($action == 'unprotect') ?
'selected' : false,
745 'text' => wfMsg('unprotect'),
746 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
751 //article doesn't exist or is deleted
752 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
753 if( $n = $this->mTitle
->isDeleted() ) {
754 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
755 $content_actions['undelete'] = array(
757 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
758 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
759 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
764 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
765 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
766 $content_actions['protect'] = array(
767 'class' => ($action == 'protect') ?
'selected' : false,
768 'text' => wfMsg('protect'),
769 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
773 $content_actions['unprotect'] = array(
774 'class' => ($action == 'unprotect') ?
'selected' : false,
775 'text' => wfMsg('unprotect'),
776 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
782 wfProfileOut( __METHOD__
."-live" );
784 if( $this->loggedin
) {
785 if( !$this->mTitle
->userIsWatching()) {
786 $content_actions['watch'] = array(
787 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
788 'text' => wfMsg('watch'),
789 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
792 $content_actions['unwatch'] = array(
793 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
794 'text' => wfMsg('unwatch'),
795 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
801 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
803 /* show special page tab */
805 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
806 'class' => 'selected',
807 'text' => wfMsg('nstab-special'),
808 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
811 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
814 /* show links to different language variants */
815 global $wgDisableLangConversion;
816 $variants = $wgContLang->getVariants();
817 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
818 $preferred = $wgContLang->getPreferredVariant();
820 foreach( $variants as $code ) {
821 $varname = $wgContLang->getVariantname( $code );
822 if( $varname == 'disable' )
824 $selected = ( $code == $preferred )?
'selected' : false;
825 $content_actions['varlang-' . $vcount] = array(
826 'class' => $selected,
828 'href' => $this->mTitle
->getLocalURL('',$code)
834 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
836 wfProfileOut( __METHOD__
);
837 return $content_actions;
843 * build array of common navigation links
847 function buildNavUrls () {
848 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
849 global $wgEnableUploads, $wgUploadNavigationUrl;
851 wfProfileIn( __METHOD__
);
853 $action = $wgRequest->getText( 'action' );
856 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
857 if( $wgEnableUploads ) {
858 if ($wgUploadNavigationUrl) {
859 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
861 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
864 if ($wgUploadNavigationUrl)
865 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
867 $nav_urls['upload'] = false;
869 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
871 // default permalink to being off, will override it as required below.
872 $nav_urls['permalink'] = false;
874 // A print stylesheet is attached to all pages, but nobody ever
875 // figures that out. :) Add a link...
876 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
877 $nav_urls['print'] = array(
878 'text' => wfMsg( 'printableversion' ),
879 'href' => $wgRequest->appendQuery( 'printable=yes' )
882 // Also add a "permalink" while we're at it
883 if ( $this->mRevisionId
) {
884 $nav_urls['permalink'] = array(
885 'text' => wfMsg( 'permalink' ),
886 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
890 // Copy in case this undocumented, shady hook tries to mess with internals
891 $revid = $this->mRevisionId
;
892 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
895 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
896 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
897 $nav_urls['whatlinkshere'] = array(
898 'href' => $wlhTitle->getLocalUrl()
900 if( $this->mTitle
->getArticleId() ) {
901 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
902 $nav_urls['recentchangeslinked'] = array(
903 'href' => $rclTitle->getLocalUrl()
906 $nav_urls['recentchangeslinked'] = false;
908 if ($wgUseTrackbacks)
909 $nav_urls['trackbacklink'] = array(
910 'href' => $wgTitle->trackbackURL()
914 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
915 $id = User
::idFromName($this->mTitle
->getText());
916 $ip = User
::isIP($this->mTitle
->getText());
922 if($id ||
$ip) { # both anons and non-anons have contribs list
923 $nav_urls['contributions'] = array(
924 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
928 $logPage = SpecialPage
::getTitleFor( 'Log' );
929 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
930 . $this->mTitle
->getPartialUrl() ) );
932 $nav_urls['log'] = false;
935 if ( $wgUser->isAllowed( 'block' ) ) {
936 $nav_urls['blockip'] = array(
937 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
940 $nav_urls['blockip'] = false;
943 $nav_urls['contributions'] = false;
944 $nav_urls['log'] = false;
945 $nav_urls['blockip'] = false;
947 $nav_urls['emailuser'] = false;
948 if( $this->showEmailUser( $id ) ) {
949 $nav_urls['emailuser'] = array(
950 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
953 wfProfileOut( __METHOD__
);
958 * Generate strings used for xml 'id' names
962 function getNameSpaceKey () {
963 return $this->mTitle
->getNamespaceKey();
969 function setupUserCss() {
970 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
972 wfProfileIn( __METHOD__
);
976 'maxage' => $wgSquidMaxage,
978 if( $this->loggedin
) {
979 // Ensure that logged-in users' generated CSS isn't clobbered
980 // by anons' publicly cacheable generated CSS.
981 $siteargs['smaxage'] = '0';
982 $siteargs['ts'] = $wgUser->mTouched
;
985 // If we use the site's dynamic CSS, throw that in, too
986 // Per-site custom styles
987 if ( $wgUseSiteCss ) {
988 $query = wfArrayToCGI( array(
989 'usemsgcache' => 'yes',
990 'ctype' => 'text/css',
991 'smaxage' => $wgSquidMaxage
993 $this->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
994 $this->addStyle( self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
),
998 // Per-user styles based on preferences
999 $siteargs['gen'] = 'css';
1000 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' )
1001 $siteargs['useskin'] = $us;
1002 $this->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ), 'screen' );
1004 // Per-user custom style pages
1005 if ( $wgAllowUserCss && $this->loggedin
) {
1006 $action = $wgRequest->getVal('action');
1008 # if we're previewing the CSS page, use it
1009 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
1010 $previewCss = $wgRequest->getText('wpTextbox1');
1012 /// @fixme properly escape the cdata!
1013 $this->usercss
= "/*<![CDATA[*/\n" .
1017 $this->addStyle( self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
1018 'action=raw&ctype=text/css'), 'screen' );
1022 wfProfileOut( __METHOD__
);
1028 function setupUserJs( $allowUserJs ) {
1029 wfProfileIn( __METHOD__
);
1031 global $wgRequest, $wgJsMimeType;
1032 $action = $wgRequest->getText('action');
1034 if( $allowUserJs && $this->loggedin
) {
1035 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1036 # XXX: additional security check/prompt?
1037 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1039 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
1042 wfProfileOut( __METHOD__
);
1046 * Code for extensions to hook into to provide per-page CSS, see
1047 * extensions/PageCSS/PageCSS.php for an implementation of this.
1051 function setupPageCss() {
1052 wfProfileIn( __METHOD__
);
1054 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1056 wfProfileOut( __METHOD__
);
1061 * returns css with user-specific options
1063 public function getUserStylesheet() {
1064 wfProfileIn( __METHOD__
);
1066 $s = "/* generated user stylesheet */\n";
1067 $s .= $this->reallyDoGetUserStyles();
1068 wfProfileOut( __METHOD__
);
1073 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1074 * nated together. For some bizarre reason, it does *not* return any
1075 * custom user JS from subpages. Huh?
1077 * There's absolutely no reason to have separate Monobook/Common JSes.
1078 * Any JS that cares can just check the skin variable generated at the
1079 * top. For now Monobook.js will be maintained, but it should be consi-
1084 public function getUserJs() {
1085 wfProfileIn( __METHOD__
);
1087 $s = parent
::getUserJs();
1088 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js */\n";
1090 // avoid inclusion of non defined user JavaScript (with custom skins only)
1091 // by checking for default message content
1092 $msgKey = ucfirst($this->skinname
).'.js';
1093 $userJS = wfMsgForContent($msgKey);
1094 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1098 wfProfileOut( __METHOD__
);
1103 * Add a local or specified stylesheet, with the given media options.
1104 * Meant primarily for internal use...
1106 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1107 * @param $conditional -- for IE conditional comments, specifying an IE version
1108 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1110 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1113 $options['media'] = $media;
1115 $options['condition'] = $condition;
1117 $options['dir'] = $dir;
1118 $this->styles
[$style] = $options;
1122 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1123 * These will be applied to various media & IE conditionals.
1125 protected function buildCssLinks() {
1127 foreach( $this->styles
as $file => $options ) {
1128 $link = $this->styleLink( $file, $options );
1133 return implode( "\n\t\t", $links );
1136 protected function styleLink( $style, $options ) {
1139 if( isset( $options['dir'] ) ) {
1141 $siteDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
1142 if( $siteDir != $options['dir'] )
1146 if( isset( $options['media'] ) ) {
1147 $media = $this->transformCssMedia( $options['media'] );
1148 if( is_null( $media ) ) {
1155 if( substr( $style, 0, 1 ) == '/' ||
1156 substr( $style, 0, 5 ) == 'http:' ||
1157 substr( $style, 0, 6 ) == 'https:' ) {
1160 global $wgStylePath, $wgStyleVersion;
1161 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1165 'rel' => 'stylesheet',
1167 'type' => 'text/css' );
1169 $attribs['media'] = $media;
1172 $link = Xml
::element( 'link', $attribs );
1174 if( isset( $options['condition'] ) ) {
1175 $condition = htmlspecialchars( $options['condition'] );
1176 $link = "<!--[if $condition]>$link<![endif]-->";
1181 function transformCssMedia( $media ) {
1182 global $wgRequest, $wgHandheldForIPhone;
1184 // Switch in on-screen display for media testing
1186 'printable' => 'print',
1187 'handheld' => 'handheld',
1189 foreach( $switches as $switch => $targetMedia ) {
1190 if( $wgRequest->getBool( $switch ) ) {
1191 if( $media == $targetMedia ) {
1193 } elseif( $media == 'screen' ) {
1199 // Expand longer media queries as iPhone doesn't grok 'handheld'
1200 if( $wgHandheldForIPhone ) {
1201 $mediaAliases = array(
1202 'screen' => 'screen and (min-device-width: 481px)',
1203 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1206 if( isset( $mediaAliases[$media] ) ) {
1207 $media = $mediaAliases[$media];
1217 * Generic wrapper for template functions, with interface
1218 * compatible with what we use of PHPTAL 0.7.
1221 class QuickTemplate
{
1225 function QuickTemplate() {
1226 $this->data
= array();
1227 $this->translator
= new MediaWiki_I18N();
1233 function set( $name, $value ) {
1234 $this->data
[$name] = $value;
1240 function setRef($name, &$value) {
1241 $this->data
[$name] =& $value;
1247 function setTranslator( &$t ) {
1248 $this->translator
= &$t;
1254 function execute() {
1255 echo "Override this function.";
1262 function text( $str ) {
1263 echo htmlspecialchars( $this->data
[$str] );
1269 function jstext( $str ) {
1270 echo Xml
::escapeJsString( $this->data
[$str] );
1276 function html( $str ) {
1277 echo $this->data
[$str];
1283 function msg( $str ) {
1284 echo htmlspecialchars( $this->translator
->translate( $str ) );
1290 function msgHtml( $str ) {
1291 echo $this->translator
->translate( $str );
1295 * An ugly, ugly hack.
1298 function msgWiki( $str ) {
1299 global $wgParser, $wgTitle, $wgOut;
1301 $text = $this->translator
->translate( $str );
1302 $parserOutput = $wgParser->parse( $text, $wgTitle,
1303 $wgOut->parserOptions(), true );
1304 echo $parserOutput->getText();
1310 function haveData( $str ) {
1311 return isset( $this->data
[$str] );
1317 function haveMsg( $str ) {
1318 $msg = $this->translator
->translate( $str );
1319 return ($msg != '-') && ($msg != ''); # ????