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', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
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( 'nsclass', $this->getNamespaceClasses( $this->mTitle
) );
258 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
259 /* XXX currently unused, might get useful later
260 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
261 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
262 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
263 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
264 $tpl->set( "helppage", wfMsg('helppage'));
266 $tpl->set( 'searchaction', $this->escapeSearchLink() );
267 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
268 $tpl->setRef( 'stylepath', $wgStylePath );
269 $tpl->setRef( 'articlepath', $wgArticlePath );
270 $tpl->setRef( 'scriptpath', $wgScriptPath );
271 $tpl->setRef( 'serverurl', $wgServer );
272 $tpl->setRef( 'logopath', $wgLogo );
273 $tpl->setRef( "lang", $wgContLanguageCode );
274 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
275 $tpl->set( 'rtl', $wgContLang->isRTL() );
276 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
277 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
278 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
279 $tpl->setRef( 'userpage', $this->userpage
);
280 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
281 $tpl->set( 'userlang', $wgLang->getCode() );
282 $tpl->set( 'pagecss', $this->setupPageCss() );
283 $tpl->setRef( 'usercss', $this->usercss
);
284 $tpl->setRef( 'userjs', $this->userjs
);
285 $tpl->setRef( 'userjsprev', $this->userjsprev
);
287 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
288 $tpl->set( 'jsvarurl',
290 "action=raw$jsCache&gen=js&useskin=" .
291 urlencode( $this->getSkinName() ) ) );
293 $tpl->set('jsvarurl', false);
295 $newtalks = $wgUser->getNewMessageLinks();
297 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
298 $usertitle = $this->mUser
->getUserPage();
299 $usertalktitle = $usertitle->getTalkPage();
300 if( !$usertalktitle->equals( $this->mTitle
) ) {
301 $ntl = wfMsg( 'youhavenewmessages',
302 $this->makeKnownLinkObj(
304 wfMsgHtml( 'newmessageslink' ),
307 $this->makeKnownLinkObj(
309 wfMsgHtml( 'newmessagesdifflink' ),
314 $wgOut->setSquidMaxage(0);
316 } else if (count($newtalks)) {
317 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
319 foreach ($newtalks as $newtalk) {
320 $msgs[] = wfElement("a",
321 array('href' => $newtalk["link"]), $newtalk["wiki"]);
323 $parts = implode($sep, $msgs);
324 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
325 $wgOut->setSquidMaxage(0);
329 wfProfileOut( __METHOD__
."-stuff2" );
331 wfProfileIn( __METHOD__
."-stuff3" );
332 $tpl->setRef( 'newtalk', $ntl );
333 $tpl->setRef( 'skin', $this );
334 $tpl->set( 'logo', $this->logoText() );
335 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
336 $wgArticle and 0 != $wgArticle->getID() )
338 if ( !$wgDisableCounters ) {
339 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
341 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
343 $tpl->set('viewcount', false);
346 $tpl->set('viewcount', false);
349 if ($wgPageShowWatchingUsers) {
350 $dbr = wfGetDB( DB_SLAVE
);
351 $watchlist = $dbr->tableName( 'watchlist' );
352 $sql = "SELECT COUNT(*) AS n FROM $watchlist
353 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
354 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
355 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
356 $x = $dbr->fetchObject( $res );
357 $numberofwatchingusers = $x->n
;
358 if ($numberofwatchingusers > 0) {
359 $tpl->set('numberofwatchingusers',
360 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
361 $wgLang->formatNum($numberofwatchingusers))
364 $tpl->set('numberofwatchingusers', false);
367 $tpl->set('numberofwatchingusers', false);
370 $tpl->set('copyright',$this->getCopyright());
372 $this->credits
= false;
374 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
375 require_once("Credits.php");
376 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
378 $tpl->set('lastmod', $this->lastModified());
381 $tpl->setRef( 'credits', $this->credits
);
383 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
384 $tpl->set('copyright', $this->getCopyright());
385 $tpl->set('viewcount', false);
386 $tpl->set('lastmod', false);
387 $tpl->set('credits', false);
388 $tpl->set('numberofwatchingusers', false);
390 $tpl->set('copyright', false);
391 $tpl->set('viewcount', false);
392 $tpl->set('lastmod', false);
393 $tpl->set('credits', false);
394 $tpl->set('numberofwatchingusers', false);
396 wfProfileOut( __METHOD__
."-stuff3" );
398 wfProfileIn( __METHOD__
."-stuff4" );
399 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
400 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
401 $tpl->set( 'disclaimer', $this->disclaimerLink() );
402 $tpl->set( 'privacy', $this->privacyLink() );
403 $tpl->set( 'about', $this->aboutLink() );
405 $tpl->setRef( 'debug', $out->mDebugtext
);
406 $tpl->set( 'reporttime', wfReportTime() );
407 $tpl->set( 'sitenotice', wfGetSiteNotice() );
408 $tpl->set( 'bottomscripts', $this->bottomScripts() );
410 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
411 $out->mBodytext
.= $printfooter ;
412 $tpl->setRef( 'bodytext', $out->mBodytext
);
415 $language_urls = array();
417 if ( !$wgHideInterlanguageLinks ) {
418 foreach( $wgOut->getLanguageLinks() as $l ) {
419 $tmp = explode( ':', $l, 2 );
420 $class = 'interwiki-' . $tmp[0];
422 $nt = Title
::newFromText( $l );
423 $language_urls[] = array(
424 'href' => $nt->getFullURL(),
425 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
430 if(count($language_urls)) {
431 $tpl->setRef( 'language_urls', $language_urls);
433 $tpl->set('language_urls', false);
435 wfProfileOut( __METHOD__
."-stuff4" );
438 $tpl->set('personal_urls', $this->buildPersonalUrls());
439 $content_actions = $this->buildContentActionUrls();
440 $tpl->setRef('content_actions', $content_actions);
442 // XXX: attach this from javascript, same with section editing
443 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
445 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
446 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
448 $tpl->set('body_ondblclick', false);
450 $tpl->set( 'body_onload', false );
451 $tpl->set( 'sidebar', $this->buildSidebar() );
452 $tpl->set( 'nav_urls', $this->buildNavUrls() );
454 // original version by hansm
455 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
456 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
459 // allow extensions adding stuff after the page content.
460 // See Skin::afterContentHook() for further documentation.
461 $tpl->set ('dataAfterContent', $this->afterContentHook());
464 wfProfileIn( __METHOD__
."-execute" );
465 $res = $tpl->execute();
466 wfProfileOut( __METHOD__
."-execute" );
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( __METHOD__
);
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
481 function printOrError( $str ) {
486 * build array of urls for personal toolbar
490 function buildPersonalUrls() {
491 global $wgTitle, $wgRequest;
493 $pageurl = $wgTitle->getLocalURL();
494 wfProfileIn( __METHOD__
);
496 /* set up the default links for the personal toolbar */
497 $personal_urls = array();
498 if ($this->loggedin
) {
499 $personal_urls['userpage'] = array(
500 'text' => $this->username
,
501 'href' => &$this->userpageUrlDetails
['href'],
502 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
503 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
505 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
506 $personal_urls['mytalk'] = array(
507 'text' => wfMsg('mytalk'),
508 'href' => &$usertalkUrlDetails['href'],
509 'class' => $usertalkUrlDetails['exists']?
false:'new',
510 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
512 $href = self
::makeSpecialUrl( 'Preferences' );
513 $personal_urls['preferences'] = array(
514 'text' => wfMsg( 'mypreferences' ),
516 'active' => ( $href == $pageurl )
518 $href = self
::makeSpecialUrl( 'Watchlist' );
519 $personal_urls['watchlist'] = array(
520 'text' => wfMsg( 'mywatchlist' ),
522 'active' => ( $href == $pageurl )
525 # We need to do an explicit check for Special:Contributions, as we
526 # have to match both the title, and the target (which could come
527 # from request values or be specified in "sub page" form. The plot
528 # thickens, because $wgTitle is altered for special pages, so doesn't
529 # contain the original alias-with-subpage.
530 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
531 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
532 list( $spName, $spPar ) =
533 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
534 $active = $spName == 'Contributions'
535 && ( ( $spPar && $spPar == $this->username
)
536 ||
$wgRequest->getText( 'target' ) == $this->username
);
541 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
542 $personal_urls['mycontris'] = array(
543 'text' => wfMsg( 'mycontris' ),
547 $personal_urls['logout'] = array(
548 'text' => wfMsg( 'userlogout' ),
549 'href' => self
::makeSpecialUrl( 'Userlogout',
550 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
556 $loginlink = $wgUser->isAllowed( 'createaccount' )
557 ?
'nav-login-createaccount'
559 if( $this->showIPinHeader() ) {
560 $href = &$this->userpageUrlDetails
['href'];
561 $personal_urls['anonuserpage'] = array(
562 'text' => $this->username
,
564 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
565 'active' => ( $pageurl == $href )
567 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
568 $href = &$usertalkUrlDetails['href'];
569 $personal_urls['anontalk'] = array(
570 'text' => wfMsg('anontalk'),
572 'class' => $usertalkUrlDetails['exists']?
false:'new',
573 'active' => ( $pageurl == $href )
575 $personal_urls['anonlogin'] = array(
576 'text' => wfMsg( $loginlink ),
577 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
578 'active' => $wgTitle->isSpecial( 'Userlogin' )
582 $personal_urls['login'] = array(
583 'text' => wfMsg( $loginlink ),
584 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
585 'active' => $wgTitle->isSpecial( 'Userlogin' )
590 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
591 wfProfileOut( __METHOD__
);
592 return $personal_urls;
595 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
598 $classes[] = 'selected';
600 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
602 $query = 'action=edit';
605 $text = wfMsg( $message );
606 if ( wfEmptyMsg( $message, $text ) ) {
608 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
612 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
613 $title, $message, $selected, $checkEdit,
614 &$classes, &$query, &$text, &$result)) ) {
619 'class' => implode( ' ', $classes ),
621 'href' => $title->getLocalUrl( $query ) );
624 function makeTalkUrlDetails( $name, $urlaction = '' ) {
625 $title = Title
::newFromText( $name );
626 if( !is_object($title) ) {
627 throw new MWException( __METHOD__
." given invalid pagename $name" );
629 $title = $title->getTalkPage();
630 self
::checkTitle( $title, $name );
632 'href' => $title->getLocalURL( $urlaction ),
633 'exists' => $title->getArticleID() != 0 ?
true : false
637 function makeArticleUrlDetails( $name, $urlaction = '' ) {
638 $title = Title
::newFromText( $name );
639 $title= $title->getSubjectPage();
640 self
::checkTitle( $title, $name );
642 'href' => $title->getLocalURL( $urlaction ),
643 'exists' => $title->getArticleID() != 0 ?
true : false
648 * an array of edit links by default used for the tabs
652 function buildContentActionUrls () {
653 global $wgContLang, $wgLang, $wgOut;
654 wfProfileIn( __METHOD__
);
656 global $wgUser, $wgRequest;
657 $action = $wgRequest->getText( 'action' );
658 $section = $wgRequest->getText( 'section' );
659 $content_actions = array();
661 $prevent_active_tabs = false ;
662 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
664 if( $this->iscontent
) {
665 $subjpage = $this->mTitle
->getSubjectPage();
666 $talkpage = $this->mTitle
->getTalkPage();
668 $nskey = $this->mTitle
->getNamespaceKey();
669 $content_actions[$nskey] = $this->tabAction(
672 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
675 $content_actions['talk'] = $this->tabAction(
678 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
682 wfProfileIn( __METHOD__
."-edit" );
683 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
684 $istalk = $this->mTitle
->isTalkPage();
685 $istalkclass = $istalk?
' istalk':'';
686 $content_actions['edit'] = array(
687 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
688 'text' => $this->mTitle
->exists()
691 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
694 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
695 $content_actions['addsection'] = array(
696 'class' => $section == 'new'?
'selected':false,
697 'text' => wfMsg('addsection'),
698 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
701 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
702 $content_actions['viewsource'] = array(
703 'class' => ($action == 'edit') ?
'selected' : false,
704 'text' => wfMsg('viewsource'),
705 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
708 wfProfileOut( __METHOD__
."-edit" );
710 wfProfileIn( __METHOD__
."-live" );
711 if ( $this->mTitle
->getArticleId() ) {
713 $content_actions['history'] = array(
714 'class' => ($action == 'history') ?
'selected' : false,
715 'text' => wfMsg('history_short'),
716 'href' => $this->mTitle
->getLocalUrl( 'action=history')
719 if($wgUser->isAllowed('delete')){
720 $content_actions['delete'] = array(
721 'class' => ($action == 'delete') ?
'selected' : false,
722 'text' => wfMsg('delete'),
723 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
726 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
727 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
728 $content_actions['move'] = array(
729 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
730 'text' => wfMsg('move'),
731 'href' => $moveTitle->getLocalUrl()
735 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
736 if(!$this->mTitle
->isProtected()){
737 $content_actions['protect'] = array(
738 'class' => ($action == 'protect') ?
'selected' : false,
739 'text' => wfMsg('protect'),
740 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
744 $content_actions['unprotect'] = array(
745 'class' => ($action == 'unprotect') ?
'selected' : false,
746 'text' => wfMsg('unprotect'),
747 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
752 //article doesn't exist or is deleted
753 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
754 if( $n = $this->mTitle
->isDeleted() ) {
755 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
756 $content_actions['undelete'] = array(
758 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
759 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
760 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
765 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
766 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
767 $content_actions['protect'] = array(
768 'class' => ($action == 'protect') ?
'selected' : false,
769 'text' => wfMsg('protect'),
770 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
774 $content_actions['unprotect'] = array(
775 'class' => ($action == 'unprotect') ?
'selected' : false,
776 'text' => wfMsg('unprotect'),
777 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
783 wfProfileOut( __METHOD__
."-live" );
785 if( $this->loggedin
) {
786 if( !$this->mTitle
->userIsWatching()) {
787 $content_actions['watch'] = array(
788 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
789 'text' => wfMsg('watch'),
790 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
793 $content_actions['unwatch'] = array(
794 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
795 'text' => wfMsg('unwatch'),
796 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
802 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
804 /* show special page tab */
806 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
807 'class' => 'selected',
808 'text' => wfMsg('nstab-special'),
809 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
812 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
815 /* show links to different language variants */
816 global $wgDisableLangConversion;
817 $variants = $wgContLang->getVariants();
818 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
819 $preferred = $wgContLang->getPreferredVariant();
821 foreach( $variants as $code ) {
822 $varname = $wgContLang->getVariantname( $code );
823 if( $varname == 'disable' )
825 $selected = ( $code == $preferred )?
'selected' : false;
826 $content_actions['varlang-' . $vcount] = array(
827 'class' => $selected,
829 'href' => $this->mTitle
->getLocalURL('',$code)
835 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
837 wfProfileOut( __METHOD__
);
838 return $content_actions;
844 * build array of common navigation links
848 function buildNavUrls () {
849 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
850 global $wgEnableUploads, $wgUploadNavigationUrl;
852 wfProfileIn( __METHOD__
);
854 $action = $wgRequest->getText( 'action' );
857 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
858 if( $wgEnableUploads ) {
859 if ($wgUploadNavigationUrl) {
860 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
862 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
865 if ($wgUploadNavigationUrl)
866 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
868 $nav_urls['upload'] = false;
870 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
872 // default permalink to being off, will override it as required below.
873 $nav_urls['permalink'] = false;
875 // A print stylesheet is attached to all pages, but nobody ever
876 // figures that out. :) Add a link...
877 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
878 $nav_urls['print'] = array(
879 'text' => wfMsg( 'printableversion' ),
880 'href' => $wgRequest->appendQuery( 'printable=yes' )
883 // Also add a "permalink" while we're at it
884 if ( $this->mRevisionId
) {
885 $nav_urls['permalink'] = array(
886 'text' => wfMsg( 'permalink' ),
887 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
891 // Copy in case this undocumented, shady hook tries to mess with internals
892 $revid = $this->mRevisionId
;
893 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
896 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
897 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
898 $nav_urls['whatlinkshere'] = array(
899 'href' => $wlhTitle->getLocalUrl()
901 if( $this->mTitle
->getArticleId() ) {
902 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
903 $nav_urls['recentchangeslinked'] = array(
904 'href' => $rclTitle->getLocalUrl()
907 $nav_urls['recentchangeslinked'] = false;
909 if ($wgUseTrackbacks)
910 $nav_urls['trackbacklink'] = array(
911 'href' => $wgTitle->trackbackURL()
915 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
916 $id = User
::idFromName($this->mTitle
->getText());
917 $ip = User
::isIP($this->mTitle
->getText());
923 if($id ||
$ip) { # both anons and non-anons have contribs list
924 $nav_urls['contributions'] = array(
925 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
929 $logPage = SpecialPage
::getTitleFor( 'Log' );
930 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
931 . $this->mTitle
->getPartialUrl() ) );
933 $nav_urls['log'] = false;
936 if ( $wgUser->isAllowed( 'block' ) ) {
937 $nav_urls['blockip'] = array(
938 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
941 $nav_urls['blockip'] = false;
944 $nav_urls['contributions'] = false;
945 $nav_urls['log'] = false;
946 $nav_urls['blockip'] = false;
948 $nav_urls['emailuser'] = false;
949 if( $this->showEmailUser( $id ) ) {
950 $nav_urls['emailuser'] = array(
951 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
954 wfProfileOut( __METHOD__
);
959 * Generate strings used for xml 'id' names
963 function getNameSpaceKey () {
964 return $this->mTitle
->getNamespaceKey();
970 function setupUserCss( $extCSS = array() ) {
971 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
973 wfProfileIn( __METHOD__
);
977 'maxage' => $wgSquidMaxage,
979 if( $this->loggedin
) {
980 // Ensure that logged-in users' generated CSS isn't clobbered
981 // by anons' publicly cacheable generated CSS.
982 $siteargs['smaxage'] = '0';
983 $siteargs['ts'] = $wgUser->mTouched
;
986 // Add any extension CSS
987 foreach( $extCSS as $tag ) {
988 $this->addStyle( $tag['href'] );
991 // If we use the site's dynamic CSS, throw that in, too
992 // Per-site custom styles
993 if ( $wgUseSiteCss ) {
994 $query = wfArrayToCGI( array(
995 'usemsgcache' => 'yes',
996 'ctype' => 'text/css',
997 'smaxage' => $wgSquidMaxage
999 $this->addStyle( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) );
1000 $this->addStyle( self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
),
1004 // Per-user styles based on preferences
1005 $siteargs['gen'] = 'css';
1006 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' )
1007 $siteargs['useskin'] = $us;
1008 $this->addStyle( self
::makeUrl( '-', wfArrayToCGI( $siteargs ) ), 'screen' );
1010 // Per-user custom style pages
1011 if ( $wgAllowUserCss && $this->loggedin
) {
1012 $action = $wgRequest->getVal('action');
1014 # if we're previewing the CSS page, use it
1015 if( $this->mTitle
->isCssSubpage() && $this->userCanPreview( $action ) ) {
1016 $previewCss = $wgRequest->getText('wpTextbox1');
1018 /// @fixme properly escape the cdata!
1019 $this->usercss
= "/*<![CDATA[*/\n" .
1023 $this->addStyle( self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
1024 'action=raw&ctype=text/css'), 'screen' );
1028 wfProfileOut( __METHOD__
);
1034 function setupUserJs( $allowUserJs ) {
1035 wfProfileIn( __METHOD__
);
1037 global $wgRequest, $wgJsMimeType;
1038 $action = $wgRequest->getText('action');
1040 if( $allowUserJs && $this->loggedin
) {
1041 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1042 # XXX: additional security check/prompt?
1043 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1045 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
1048 wfProfileOut( __METHOD__
);
1052 * Code for extensions to hook into to provide per-page CSS, see
1053 * extensions/PageCSS/PageCSS.php for an implementation of this.
1057 function setupPageCss() {
1058 wfProfileIn( __METHOD__
);
1060 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1062 wfProfileOut( __METHOD__
);
1067 * returns css with user-specific options
1069 public function getUserStylesheet() {
1070 wfProfileIn( __METHOD__
);
1072 $s = "/* generated user stylesheet */\n";
1073 $s .= $this->reallyDoGetUserStyles();
1074 wfProfileOut( __METHOD__
);
1079 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1080 * nated together. For some bizarre reason, it does *not* return any
1081 * custom user JS from subpages. Huh?
1083 * There's absolutely no reason to have separate Monobook/Common JSes.
1084 * Any JS that cares can just check the skin variable generated at the
1085 * top. For now Monobook.js will be maintained, but it should be consi-
1090 public function getUserJs() {
1091 wfProfileIn( __METHOD__
);
1093 $s = parent
::getUserJs();
1094 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js */\n";
1096 // avoid inclusion of non defined user JavaScript (with custom skins only)
1097 // by checking for default message content
1098 $msgKey = ucfirst($this->skinname
).'.js';
1099 $userJS = wfMsgForContent($msgKey);
1100 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1104 wfProfileOut( __METHOD__
);
1109 * Add a local or specified stylesheet, with the given media options.
1110 * Meant primarily for internal use...
1112 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1113 * @param $conditional -- for IE conditional comments, specifying an IE version
1114 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1116 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1119 $options['media'] = $media;
1121 $options['condition'] = $condition;
1123 $options['dir'] = $dir;
1124 $this->styles
[$style] = $options;
1128 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1129 * These will be applied to various media & IE conditionals.
1131 protected function buildCssLinks() {
1133 foreach( $this->styles
as $file => $options ) {
1134 $link = $this->styleLink( $file, $options );
1139 return implode( "\n\t\t", $links );
1142 protected function styleLink( $style, $options ) {
1145 if( isset( $options['dir'] ) ) {
1147 $siteDir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
1148 if( $siteDir != $options['dir'] )
1152 if( isset( $options['media'] ) ) {
1153 $media = $this->transformCssMedia( $options['media'] );
1154 if( is_null( $media ) ) {
1161 if( substr( $style, 0, 1 ) == '/' ||
1162 substr( $style, 0, 5 ) == 'http:' ||
1163 substr( $style, 0, 6 ) == 'https:' ) {
1166 global $wgStylePath, $wgStyleVersion;
1167 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1171 'rel' => 'stylesheet',
1173 'type' => 'text/css' );
1175 $attribs['media'] = $media;
1178 $link = Xml
::element( 'link', $attribs );
1180 if( isset( $options['condition'] ) ) {
1181 $condition = htmlspecialchars( $options['condition'] );
1182 $link = "<!--[if $condition]>$link<![endif]-->";
1187 function transformCssMedia( $media ) {
1188 global $wgRequest, $wgHandheldForIPhone;
1190 // Switch in on-screen display for media testing
1192 'printable' => 'print',
1193 'handheld' => 'handheld',
1195 foreach( $switches as $switch => $targetMedia ) {
1196 if( $wgRequest->getBool( $switch ) ) {
1197 if( $media == $targetMedia ) {
1199 } elseif( $media == 'screen' ) {
1205 // Expand longer media queries as iPhone doesn't grok 'handheld'
1206 if( $wgHandheldForIPhone ) {
1207 $mediaAliases = array(
1208 'screen' => 'screen and (min-device-width: 481px)',
1209 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1212 if( isset( $mediaAliases[$media] ) ) {
1213 $media = $mediaAliases[$media];
1223 * Generic wrapper for template functions, with interface
1224 * compatible with what we use of PHPTAL 0.7.
1227 class QuickTemplate
{
1231 function QuickTemplate() {
1232 $this->data
= array();
1233 $this->translator
= new MediaWiki_I18N();
1239 function set( $name, $value ) {
1240 $this->data
[$name] = $value;
1246 function setRef($name, &$value) {
1247 $this->data
[$name] =& $value;
1253 function setTranslator( &$t ) {
1254 $this->translator
= &$t;
1260 function execute() {
1261 echo "Override this function.";
1268 function text( $str ) {
1269 echo htmlspecialchars( $this->data
[$str] );
1275 function jstext( $str ) {
1276 echo Xml
::escapeJsString( $this->data
[$str] );
1282 function html( $str ) {
1283 echo $this->data
[$str];
1289 function msg( $str ) {
1290 echo htmlspecialchars( $this->translator
->translate( $str ) );
1296 function msgHtml( $str ) {
1297 echo $this->translator
->translate( $str );
1301 * An ugly, ugly hack.
1304 function msgWiki( $str ) {
1305 global $wgParser, $wgTitle, $wgOut;
1307 $text = $this->translator
->translate( $str );
1308 $parserOutput = $wgParser->parse( $text, $wgTitle,
1309 $wgOut->parserOptions(), true );
1310 echo $parserOutput->getText();
1316 function haveData( $str ) {
1317 return isset( $this->data
[$str] );
1323 function haveMsg( $str ) {
1324 $msg = $this->translator
->translate( $str );
1325 return ($msg != '-') && ($msg != ''); # ????