0f16c694e25a60bee4c4a6072f90ca827be89698
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!' );
459 wfProfileIn( __METHOD__
."-execute" );
460 $res = $tpl->execute();
461 wfProfileOut( __METHOD__
."-execute" );
463 // result may be an error
464 $this->printOrError( $res );
465 wfProfileOut( __METHOD__
);
469 * Output the string, or print error message if it's
470 * an error object of the appropriate type.
471 * For the base class, assume strings all around.
476 function printOrError( $str ) {
481 * build array of urls for personal toolbar
485 function buildPersonalUrls() {
486 global $wgTitle, $wgRequest;
488 $pageurl = $wgTitle->getLocalURL();
489 wfProfileIn( __METHOD__
);
491 /* set up the default links for the personal toolbar */
492 $personal_urls = array();
493 if ($this->loggedin
) {
494 $personal_urls['userpage'] = array(
495 'text' => $this->username
,
496 'href' => &$this->userpageUrlDetails
['href'],
497 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
498 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
500 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
501 $personal_urls['mytalk'] = array(
502 'text' => wfMsg('mytalk'),
503 'href' => &$usertalkUrlDetails['href'],
504 'class' => $usertalkUrlDetails['exists']?
false:'new',
505 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
507 $href = self
::makeSpecialUrl( 'Preferences' );
508 $personal_urls['preferences'] = array(
509 'text' => wfMsg( 'mypreferences' ),
511 'active' => ( $href == $pageurl )
513 $href = self
::makeSpecialUrl( 'Watchlist' );
514 $personal_urls['watchlist'] = array(
515 'text' => wfMsg( 'mywatchlist' ),
517 'active' => ( $href == $pageurl )
520 # We need to do an explicit check for Special:Contributions, as we
521 # have to match both the title, and the target (which could come
522 # from request values or be specified in "sub page" form. The plot
523 # thickens, because $wgTitle is altered for special pages, so doesn't
524 # contain the original alias-with-subpage.
525 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
526 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
527 list( $spName, $spPar ) =
528 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
529 $active = $spName == 'Contributions'
530 && ( ( $spPar && $spPar == $this->username
)
531 ||
$wgRequest->getText( 'target' ) == $this->username
);
536 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
537 $personal_urls['mycontris'] = array(
538 'text' => wfMsg( 'mycontris' ),
542 $personal_urls['logout'] = array(
543 'text' => wfMsg( 'userlogout' ),
544 'href' => self
::makeSpecialUrl( 'Userlogout',
545 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
551 $loginlink = $wgUser->isAllowed( 'createaccount' )
552 ?
'nav-login-createaccount'
554 if( $this->showIPinHeader() ) {
555 $href = &$this->userpageUrlDetails
['href'];
556 $personal_urls['anonuserpage'] = array(
557 'text' => $this->username
,
559 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
560 'active' => ( $pageurl == $href )
562 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
563 $href = &$usertalkUrlDetails['href'];
564 $personal_urls['anontalk'] = array(
565 'text' => wfMsg('anontalk'),
567 'class' => $usertalkUrlDetails['exists']?
false:'new',
568 'active' => ( $pageurl == $href )
570 $personal_urls['anonlogin'] = array(
571 'text' => wfMsg( $loginlink ),
572 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
573 'active' => $wgTitle->isSpecial( 'Userlogin' )
577 $personal_urls['login'] = array(
578 'text' => wfMsg( $loginlink ),
579 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
580 'active' => $wgTitle->isSpecial( 'Userlogin' )
585 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
586 wfProfileOut( __METHOD__
);
587 return $personal_urls;
590 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
593 $classes[] = 'selected';
595 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
597 $query = 'action=edit';
600 $text = wfMsg( $message );
601 if ( wfEmptyMsg( $message, $text ) ) {
603 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
607 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
608 $title, $message, $selected, $checkEdit,
609 &$classes, &$query, &$text, &$result)) ) {
614 'class' => implode( ' ', $classes ),
616 'href' => $title->getLocalUrl( $query ) );
619 function makeTalkUrlDetails( $name, $urlaction = '' ) {
620 $title = Title
::newFromText( $name );
621 if( !is_object($title) ) {
622 throw new MWException( __METHOD__
." given invalid pagename $name" );
624 $title = $title->getTalkPage();
625 self
::checkTitle( $title, $name );
627 'href' => $title->getLocalURL( $urlaction ),
628 'exists' => $title->getArticleID() != 0 ?
true : false
632 function makeArticleUrlDetails( $name, $urlaction = '' ) {
633 $title = Title
::newFromText( $name );
634 $title= $title->getSubjectPage();
635 self
::checkTitle( $title, $name );
637 'href' => $title->getLocalURL( $urlaction ),
638 'exists' => $title->getArticleID() != 0 ?
true : false
643 * an array of edit links by default used for the tabs
647 function buildContentActionUrls () {
648 global $wgContLang, $wgLang, $wgOut;
649 wfProfileIn( __METHOD__
);
651 global $wgUser, $wgRequest;
652 $action = $wgRequest->getText( 'action' );
653 $section = $wgRequest->getText( 'section' );
654 $content_actions = array();
656 $prevent_active_tabs = false ;
657 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
659 if( $this->iscontent
) {
660 $subjpage = $this->mTitle
->getSubjectPage();
661 $talkpage = $this->mTitle
->getTalkPage();
663 $nskey = $this->mTitle
->getNamespaceKey();
664 $content_actions[$nskey] = $this->tabAction(
667 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
670 $content_actions['talk'] = $this->tabAction(
673 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
677 wfProfileIn( __METHOD__
."-edit" );
678 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
679 $istalk = $this->mTitle
->isTalkPage();
680 $istalkclass = $istalk?
' istalk':'';
681 $content_actions['edit'] = array(
682 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
683 'text' => $this->mTitle
->exists()
686 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
689 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
690 $content_actions['addsection'] = array(
691 'class' => $section == 'new'?
'selected':false,
692 'text' => wfMsg('addsection'),
693 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
696 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
697 $content_actions['viewsource'] = array(
698 'class' => ($action == 'edit') ?
'selected' : false,
699 'text' => wfMsg('viewsource'),
700 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
703 wfProfileOut( __METHOD__
."-edit" );
705 wfProfileIn( __METHOD__
."-live" );
706 if ( $this->mTitle
->getArticleId() ) {
708 $content_actions['history'] = array(
709 'class' => ($action == 'history') ?
'selected' : false,
710 'text' => wfMsg('history_short'),
711 'href' => $this->mTitle
->getLocalUrl( 'action=history')
714 if($wgUser->isAllowed('delete')){
715 $content_actions['delete'] = array(
716 'class' => ($action == 'delete') ?
'selected' : false,
717 'text' => wfMsg('delete'),
718 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
721 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
722 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
723 $content_actions['move'] = array(
724 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
725 'text' => wfMsg('move'),
726 'href' => $moveTitle->getLocalUrl()
730 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
731 if(!$this->mTitle
->isProtected()){
732 $content_actions['protect'] = array(
733 'class' => ($action == 'protect') ?
'selected' : false,
734 'text' => wfMsg('protect'),
735 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
739 $content_actions['unprotect'] = array(
740 'class' => ($action == 'unprotect') ?
'selected' : false,
741 'text' => wfMsg('unprotect'),
742 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
747 //article doesn't exist or is deleted
748 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
749 if( $n = $this->mTitle
->isDeleted() ) {
750 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
751 $content_actions['undelete'] = array(
753 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
754 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
755 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
760 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
761 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
762 $content_actions['protect'] = array(
763 'class' => ($action == 'protect') ?
'selected' : false,
764 'text' => wfMsg('protect'),
765 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
769 $content_actions['unprotect'] = array(
770 'class' => ($action == 'unprotect') ?
'selected' : false,
771 'text' => wfMsg('unprotect'),
772 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
778 wfProfileOut( __METHOD__
."-live" );
780 if( $this->loggedin
) {
781 if( !$this->mTitle
->userIsWatching()) {
782 $content_actions['watch'] = array(
783 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
784 'text' => wfMsg('watch'),
785 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
788 $content_actions['unwatch'] = array(
789 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
790 'text' => wfMsg('unwatch'),
791 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
797 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
799 /* show special page tab */
801 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
802 'class' => 'selected',
803 'text' => wfMsg('nstab-special'),
804 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
807 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
810 /* show links to different language variants */
811 global $wgDisableLangConversion;
812 $variants = $wgContLang->getVariants();
813 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
814 $preferred = $wgContLang->getPreferredVariant();
816 foreach( $variants as $code ) {
817 $varname = $wgContLang->getVariantname( $code );
818 if( $varname == 'disable' )
820 $selected = ( $code == $preferred )?
'selected' : false;
821 $content_actions['varlang-' . $vcount] = array(
822 'class' => $selected,
824 'href' => $this->mTitle
->getLocalURL('',$code)
830 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
832 wfProfileOut( __METHOD__
);
833 return $content_actions;
839 * build array of common navigation links
843 function buildNavUrls () {
844 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
845 global $wgEnableUploads, $wgUploadNavigationUrl;
847 wfProfileIn( __METHOD__
);
849 $action = $wgRequest->getText( 'action' );
852 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
853 if( $wgEnableUploads ) {
854 if ($wgUploadNavigationUrl) {
855 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
857 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
860 if ($wgUploadNavigationUrl)
861 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
863 $nav_urls['upload'] = false;
865 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
867 // default permalink to being off, will override it as required below.
868 $nav_urls['permalink'] = false;
870 // A print stylesheet is attached to all pages, but nobody ever
871 // figures that out. :) Add a link...
872 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
873 $nav_urls['print'] = array(
874 'text' => wfMsg( 'printableversion' ),
875 'href' => $wgRequest->appendQuery( 'printable=yes' )
878 // Also add a "permalink" while we're at it
879 if ( $this->mRevisionId
) {
880 $nav_urls['permalink'] = array(
881 'text' => wfMsg( 'permalink' ),
882 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
886 // Copy in case this undocumented, shady hook tries to mess with internals
887 $revid = $this->mRevisionId
;
888 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
891 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
892 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
893 $nav_urls['whatlinkshere'] = array(
894 'href' => $wlhTitle->getLocalUrl()
896 if( $this->mTitle
->getArticleId() ) {
897 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
898 $nav_urls['recentchangeslinked'] = array(
899 'href' => $rclTitle->getLocalUrl()
902 $nav_urls['recentchangeslinked'] = false;
904 if ($wgUseTrackbacks)
905 $nav_urls['trackbacklink'] = array(
906 'href' => $wgTitle->trackbackURL()
910 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
911 $id = User
::idFromName($this->mTitle
->getText());
912 $ip = User
::isIP($this->mTitle
->getText());
918 if($id ||
$ip) { # both anons and non-anons have contribs list
919 $nav_urls['contributions'] = array(
920 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
924 $logPage = SpecialPage
::getTitleFor( 'Log' );
925 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
926 . $this->mTitle
->getPartialUrl() ) );
928 $nav_urls['log'] = false;
931 if ( $wgUser->isAllowed( 'block' ) ) {
932 $nav_urls['blockip'] = array(
933 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
936 $nav_urls['blockip'] = false;
939 $nav_urls['contributions'] = false;
940 $nav_urls['log'] = false;
941 $nav_urls['blockip'] = false;
943 $nav_urls['emailuser'] = false;
944 if( $this->showEmailUser( $id ) ) {
945 $nav_urls['emailuser'] = array(
946 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
949 wfProfileOut( __METHOD__
);
954 * Generate strings used for xml 'id' names
958 function getNameSpaceKey () {
959 return $this->mTitle
->getNamespaceKey();
965 function setupUserCss() {
966 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
968 wfProfileIn( __METHOD__
);
972 'maxage' => $wgSquidMaxage,
974 if( $this->loggedin
) {
975 // Ensure that logged-in users' generated CSS isn't clobbered
976 // by anons' publicly cacheable generated CSS.
977 $siteargs['smaxage'] = '0';
978 $siteargs['ts'] = $wgUser->mTouched
;
981 // If we use the site's dynamic CSS, throw that in, too
982 // Per-site custom styles
983 if ( $wgUseSiteCss ) {
984 $query = wfArrayToCGI( array(
985 'usemsgcache' => 'yes',
986 'ctype' => 'text/css',
987 'smaxage' => $wgSquidMaxage
989 $this->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
990 $this->addStyle( self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
),
994 // Per-user styles based on preferences
995 $siteargs['gen'] = 'css';
996 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' )
997 $siteargs['useskin'] = $us;
998 $this->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ), 'screen' );
1000 // Per-user custom style pages
1001 if ( $wgAllowUserCss && $this->loggedin
) {
1002 $action = $wgRequest->getVal('action');
1004 # if we're previewing the CSS page, use it
1005 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
1006 $previewCss = $wgRequest->getText('wpTextbox1');
1008 /// @fixme properly escape the cdata!
1009 $this->usercss
= "/*<![CDATA[*/\n" .
1013 $this->addStyle( self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
1014 'action=raw&ctype=text/css'), 'screen' );
1018 wfProfileOut( __METHOD__
);
1024 function setupUserJs( $allowUserJs ) {
1025 wfProfileIn( __METHOD__
);
1027 global $wgRequest, $wgJsMimeType;
1028 $action = $wgRequest->getText('action');
1030 if( $allowUserJs && $this->loggedin
) {
1031 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1032 # XXX: additional security check/prompt?
1033 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1035 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
1038 wfProfileOut( __METHOD__
);
1042 * Code for extensions to hook into to provide per-page CSS, see
1043 * extensions/PageCSS/PageCSS.php for an implementation of this.
1047 function setupPageCss() {
1048 wfProfileIn( __METHOD__
);
1050 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1052 wfProfileOut( __METHOD__
);
1057 * returns css with user-specific options
1059 public function getUserStylesheet() {
1060 wfProfileIn( __METHOD__
);
1062 $s = "/* generated user stylesheet */\n";
1063 $s .= $this->reallyDoGetUserStyles();
1064 wfProfileOut( __METHOD__
);
1069 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1070 * nated together. For some bizarre reason, it does *not* return any
1071 * custom user JS from subpages. Huh?
1073 * There's absolutely no reason to have separate Monobook/Common JSes.
1074 * Any JS that cares can just check the skin variable generated at the
1075 * top. For now Monobook.js will be maintained, but it should be consi-
1080 public function getUserJs() {
1081 wfProfileIn( __METHOD__
);
1083 $s = parent
::getUserJs();
1084 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js */\n";
1086 // avoid inclusion of non defined user JavaScript (with custom skins only)
1087 // by checking for default message content
1088 $msgKey = ucfirst($this->skinname
).'.js';
1089 $userJS = wfMsgForContent($msgKey);
1090 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1094 wfProfileOut( __METHOD__
);
1099 * Add a local or specified stylesheet, with the given media options.
1100 * Meant primarily for internal use...
1102 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1103 * @param $conditional -- for IE conditional comments, specifying an IE version
1104 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1106 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1109 $options['media'] = $media;
1111 $options['condition'] = $condition;
1113 $options['dir'] = $dir;
1114 $this->styles
[$style] = $options;
1118 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1119 * These will be applied to various media & IE conditionals.
1121 protected function buildCssLinks() {
1123 foreach( $this->styles
as $file => $options ) {
1124 $link = $this->styleLink( $file, $options );
1129 return implode( "\n\t\t", $links );
1132 protected function styleLink( $style, $options ) {
1135 if( isset( $options['dir'] ) ) {
1137 $siteDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
1138 if( $siteDir != $options['dir'] )
1142 if( isset( $options['media'] ) ) {
1143 $media = $this->transformCssMedia( $options['media'] );
1144 if( is_null( $media ) ) {
1151 if( substr( $style, 0, 1 ) == '/' ||
1152 substr( $style, 0, 5 ) == 'http:' ||
1153 substr( $style, 0, 6 ) == 'https:' ) {
1156 global $wgStylePath, $wgStyleVersion;
1157 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1161 'rel' => 'stylesheet',
1163 'type' => 'text/css' );
1165 $attribs['media'] = $media;
1168 $link = Xml
::element( 'link', $attribs );
1170 if( isset( $options['condition'] ) ) {
1171 $condition = htmlspecialchars( $options['condition'] );
1172 $link = "<!--[if $condition]>$link<![endif]-->";
1177 function transformCssMedia( $media ) {
1178 global $wgRequest, $wgHandheldForIPhone;
1180 // Switch in on-screen display for media testing
1182 'printable' => 'print',
1183 'handheld' => 'handheld',
1185 foreach( $switches as $switch => $targetMedia ) {
1186 if( $wgRequest->getBool( $switch ) ) {
1187 if( $media == $targetMedia ) {
1189 } elseif( $media == 'screen' ) {
1195 // Expand longer media queries as iPhone doesn't grok 'handheld'
1196 if( $wgHandheldForIPhone ) {
1197 $mediaAliases = array(
1198 'screen' => 'screen and (min-device-width: 481px)',
1199 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1202 if( isset( $mediaAliases[$media] ) ) {
1203 $media = $mediaAliases[$media];
1213 * Generic wrapper for template functions, with interface
1214 * compatible with what we use of PHPTAL 0.7.
1217 class QuickTemplate
{
1221 function QuickTemplate() {
1222 $this->data
= array();
1223 $this->translator
= new MediaWiki_I18N();
1229 function set( $name, $value ) {
1230 $this->data
[$name] = $value;
1236 function setRef($name, &$value) {
1237 $this->data
[$name] =& $value;
1243 function setTranslator( &$t ) {
1244 $this->translator
= &$t;
1250 function execute() {
1251 echo "Override this function.";
1258 function text( $str ) {
1259 echo htmlspecialchars( $this->data
[$str] );
1265 function jstext( $str ) {
1266 echo Xml
::escapeJsString( $this->data
[$str] );
1272 function html( $str ) {
1273 echo $this->data
[$str];
1279 function msg( $str ) {
1280 echo htmlspecialchars( $this->translator
->translate( $str ) );
1286 function msgHtml( $str ) {
1287 echo $this->translator
->translate( $str );
1291 * An ugly, ugly hack.
1294 function msgWiki( $str ) {
1295 global $wgParser, $wgTitle, $wgOut;
1297 $text = $this->translator
->translate( $str );
1298 $parserOutput = $wgParser->parse( $text, $wgTitle,
1299 $wgOut->parserOptions(), true );
1300 echo $parserOutput->getText();
1306 function haveData( $str ) {
1307 return isset( $this->data
[$str] );
1313 function haveMsg( $str ) {
1314 $msg = $this->translator
->translate( $str );
1315 return ($msg != '-') && ($msg != ''); # ????