Start on some cleanup of how CSS stylesheets are loaded. Initially addressing only...
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
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.
9 #
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.
14 #
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
19
20 /**
21 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
23 *
24 * @private
25 * @ingroup Skins
26 */
27 class MediaWiki_I18N {
28 var $_context = array();
29
30 function set($varName, $value) {
31 $this->_context[$varName] = $value;
32 }
33
34 function translate($value) {
35 wfProfileIn( __METHOD__ );
36
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
39
40 $value = wfMsg( $value );
41 // interpolate variables
42 $m = array();
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
45 wfSuppressWarnings();
46 $varValue = $this->_context[$var];
47 wfRestoreWarnings();
48 $value = str_replace($src, $varValue, $value);
49 }
50 wfProfileOut( __METHOD__ );
51 return $value;
52 }
53 }
54
55 /**
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/
60 *
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.
64 *
65 * @ingroup Skins
66 */
67 class SkinTemplate extends Skin {
68 /**#@+
69 * @private
70 */
71
72 /**
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
75 */
76 var $skinname;
77
78 /**
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
81 */
82 var $stylename;
83
84 /**
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
87 */
88 var $template;
89
90 /**
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()
94 */
95 var $styles = array();
96
97 /**#@-*/
98
99 /**
100 * Setup the base parameters...
101 * Child classes should override this to set the name,
102 * style subdirectory, and template filler callback.
103 *
104 * @param OutputPage $out
105 */
106 function initPage( &$out ) {
107 parent::initPage( $out );
108 $this->skinname = 'monobook';
109 $this->stylename = 'monobook';
110 $this->template = 'QuickTemplate';
111
112 $this->addStyle( 'common/shared.css', 'screen' );
113 $this->addStyle( 'common/commonPrint.css', 'print' );
114 }
115
116 /**
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.
120 *
121 * @param string $callback (or file)
122 * @param string $repository subdirectory where we keep template files
123 * @param string $cache_dir
124 * @return object
125 * @private
126 */
127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
128 return new $classname();
129 }
130
131 /**
132 * initialize various variables and generate the template
133 *
134 * @param OutputPage $out
135 * @public
136 */
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;
146 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
147
148 wfProfileIn( __METHOD__ );
149
150 $oldid = $wgRequest->getVal( 'oldid' );
151 $diff = $wgRequest->getVal( 'diff' );
152
153 wfProfileIn( __METHOD__."-init" );
154 $this->initPage( $out );
155
156 $this->mTitle =& $wgTitle;
157 $this->mUser =& $wgUser;
158
159 $tpl = $this->setupTemplate( $this->template, 'skins' );
160
161 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
162 $tpl->setTranslator(new MediaWiki_I18N());
163 #}
164 wfProfileOut( __METHOD__."-init" );
165
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();
175
176 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
177 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
178 } else {
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 );
182 }
183
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" );
189
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
196 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
197 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
198 $this->mTitle->getNsText();
199
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 );
206
207 $tpl->set( 'isarticle', $wgOut->isArticle() );
208
209 $tpl->setRef( "thispage", $this->thispage );
210 $subpagestr = $this->subPageSubtitle();
211 $tpl->set(
212 'subtitle', !empty($subpagestr)?
213 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
214 $out->getSubtitle()
215 );
216 $undelete = $this->getUndeleteLink();
217 $tpl->set(
218 "undelete", !empty($undelete)?
219 '<span class="subpages">'.$undelete.'</span>':
220 ''
221 );
222
223 $tpl->set( 'catlinks', $this->getCategories());
224 if( $wgOut->isSyndicated() ) {
225 $feeds = array();
226 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
227 $feeds[$format] = array(
228 'text' => wfMsg( "feed-$format" ),
229 'href' => $link );
230 }
231 $tpl->setRef( 'feeds', $feeds );
232 } else {
233 $tpl->set( 'feeds', false );
234 }
235 if ($wgUseTrackbacks && $out->isArticleRelated()) {
236 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
237 } else {
238 $tpl->set( 'trackbackhtml', null );
239 }
240
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'));
264 */
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);
285 global $wgUseSiteJs;
286 if ($wgUseSiteJs) {
287 $jsCache = $this->loggedin ? '&smaxage=0' : '';
288 $tpl->set( 'jsvarurl',
289 self::makeUrl('-',
290 "action=raw$jsCache&gen=js&useskin=" .
291 urlencode( $this->getSkinName() ) ) );
292 } else {
293 $tpl->set('jsvarurl', false);
294 }
295 $newtalks = $wgUser->getNewMessageLinks();
296
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(
303 $usertalktitle,
304 wfMsgHtml( 'newmessageslink' ),
305 'redirect=no'
306 ),
307 $this->makeKnownLinkObj(
308 $usertalktitle,
309 wfMsgHtml( 'newmessagesdifflink' ),
310 'diff=cur'
311 )
312 );
313 # Disable Cache
314 $wgOut->setSquidMaxage(0);
315 }
316 } else if (count($newtalks)) {
317 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
318 $msgs = array();
319 foreach ($newtalks as $newtalk) {
320 $msgs[] = wfElement("a",
321 array('href' => $newtalk["link"]), $newtalk["wiki"]);
322 }
323 $parts = implode($sep, $msgs);
324 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
325 $wgOut->setSquidMaxage(0);
326 } else {
327 $ntl = '';
328 }
329 wfProfileOut( __METHOD__."-stuff2" );
330
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() )
337 {
338 if ( !$wgDisableCounters ) {
339 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
340 if ( $viewcount ) {
341 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
342 } else {
343 $tpl->set('viewcount', false);
344 }
345 } else {
346 $tpl->set('viewcount', false);
347 }
348
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))
362 );
363 } else {
364 $tpl->set('numberofwatchingusers', false);
365 }
366 } else {
367 $tpl->set('numberofwatchingusers', false);
368 }
369
370 $tpl->set('copyright',$this->getCopyright());
371
372 $this->credits = false;
373
374 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
375 require_once("Credits.php");
376 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
377 } else {
378 $tpl->set('lastmod', $this->lastModified());
379 }
380
381 $tpl->setRef( 'credits', $this->credits );
382
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);
389 } else {
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);
395 }
396 wfProfileOut( __METHOD__."-stuff3" );
397
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() );
404
405 $tpl->setRef( 'debug', $out->mDebugtext );
406 $tpl->set( 'reporttime', wfReportTime() );
407 $tpl->set( 'sitenotice', wfGetSiteNotice() );
408 $tpl->set( 'bottomscripts', $this->bottomScripts() );
409
410 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
411 $out->mBodytext .= $printfooter ;
412 $tpl->setRef( 'bodytext', $out->mBodytext );
413
414 # Language links
415 $language_urls = array();
416
417 if ( !$wgHideInterlanguageLinks ) {
418 foreach( $wgOut->getLanguageLinks() as $l ) {
419 $tmp = explode( ':', $l, 2 );
420 $class = 'interwiki-' . $tmp[0];
421 unset($tmp);
422 $nt = Title::newFromText( $l );
423 $language_urls[] = array(
424 'href' => $nt->getFullURL(),
425 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
426 'class' => $class
427 );
428 }
429 }
430 if(count($language_urls)) {
431 $tpl->setRef( 'language_urls', $language_urls);
432 } else {
433 $tpl->set('language_urls', false);
434 }
435 wfProfileOut( __METHOD__."-stuff4" );
436
437 # Personal toolbar
438 $tpl->set('personal_urls', $this->buildPersonalUrls());
439 $content_actions = $this->buildContentActionUrls();
440 $tpl->setRef('content_actions', $content_actions);
441
442 // XXX: attach this from javascript, same with section editing
443 if($this->iseditable && $wgUser->getOption("editondblclick") )
444 {
445 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
446 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
447 } else {
448 $tpl->set('body_ondblclick', false);
449 }
450 $tpl->set( 'body_onload', false );
451 $tpl->set( 'sidebar', $this->buildSidebar() );
452 $tpl->set( 'nav_urls', $this->buildNavUrls() );
453
454 // original version by hansm
455 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
456 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
457 }
458
459 // execute template
460 wfProfileIn( __METHOD__."-execute" );
461 $res = $tpl->execute();
462 wfProfileOut( __METHOD__."-execute" );
463
464 // result may be an error
465 $this->printOrError( $res );
466 wfProfileOut( __METHOD__ );
467 }
468
469 /**
470 * Output the string, or print error message if it's
471 * an error object of the appropriate type.
472 * For the base class, assume strings all around.
473 *
474 * @param mixed $str
475 * @private
476 */
477 function printOrError( $str ) {
478 echo $str;
479 }
480
481 /**
482 * build array of urls for personal toolbar
483 * @return array
484 * @private
485 */
486 function buildPersonalUrls() {
487 global $wgTitle, $wgRequest;
488
489 $pageurl = $wgTitle->getLocalURL();
490 wfProfileIn( __METHOD__ );
491
492 /* set up the default links for the personal toolbar */
493 $personal_urls = array();
494 if ($this->loggedin) {
495 $personal_urls['userpage'] = array(
496 'text' => $this->username,
497 'href' => &$this->userpageUrlDetails['href'],
498 'class' => $this->userpageUrlDetails['exists']?false:'new',
499 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
500 );
501 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
502 $personal_urls['mytalk'] = array(
503 'text' => wfMsg('mytalk'),
504 'href' => &$usertalkUrlDetails['href'],
505 'class' => $usertalkUrlDetails['exists']?false:'new',
506 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
507 );
508 $href = self::makeSpecialUrl( 'Preferences' );
509 $personal_urls['preferences'] = array(
510 'text' => wfMsg( 'mypreferences' ),
511 'href' => $href,
512 'active' => ( $href == $pageurl )
513 );
514 $href = self::makeSpecialUrl( 'Watchlist' );
515 $personal_urls['watchlist'] = array(
516 'text' => wfMsg( 'mywatchlist' ),
517 'href' => $href,
518 'active' => ( $href == $pageurl )
519 );
520
521 # We need to do an explicit check for Special:Contributions, as we
522 # have to match both the title, and the target (which could come
523 # from request values or be specified in "sub page" form. The plot
524 # thickens, because $wgTitle is altered for special pages, so doesn't
525 # contain the original alias-with-subpage.
526 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
527 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
528 list( $spName, $spPar ) =
529 SpecialPage::resolveAliasWithSubpage( $title->getText() );
530 $active = $spName == 'Contributions'
531 && ( ( $spPar && $spPar == $this->username )
532 || $wgRequest->getText( 'target' ) == $this->username );
533 } else {
534 $active = false;
535 }
536
537 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
538 $personal_urls['mycontris'] = array(
539 'text' => wfMsg( 'mycontris' ),
540 'href' => $href,
541 'active' => $active
542 );
543 $personal_urls['logout'] = array(
544 'text' => wfMsg( 'userlogout' ),
545 'href' => self::makeSpecialUrl( 'Userlogout',
546 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
547 ),
548 'active' => false
549 );
550 } else {
551 global $wgUser;
552 $loginlink = $wgUser->isAllowed( 'createaccount' )
553 ? 'nav-login-createaccount'
554 : 'login';
555 if( $this->showIPinHeader() ) {
556 $href = &$this->userpageUrlDetails['href'];
557 $personal_urls['anonuserpage'] = array(
558 'text' => $this->username,
559 'href' => $href,
560 'class' => $this->userpageUrlDetails['exists']?false:'new',
561 'active' => ( $pageurl == $href )
562 );
563 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
564 $href = &$usertalkUrlDetails['href'];
565 $personal_urls['anontalk'] = array(
566 'text' => wfMsg('anontalk'),
567 'href' => $href,
568 'class' => $usertalkUrlDetails['exists']?false:'new',
569 'active' => ( $pageurl == $href )
570 );
571 $personal_urls['anonlogin'] = array(
572 'text' => wfMsg( $loginlink ),
573 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
574 'active' => $wgTitle->isSpecial( 'Userlogin' )
575 );
576 } else {
577
578 $personal_urls['login'] = array(
579 'text' => wfMsg( $loginlink ),
580 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
581 'active' => $wgTitle->isSpecial( 'Userlogin' )
582 );
583 }
584 }
585
586 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
587 wfProfileOut( __METHOD__ );
588 return $personal_urls;
589 }
590
591 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
592 $classes = array();
593 if( $selected ) {
594 $classes[] = 'selected';
595 }
596 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
597 $classes[] = 'new';
598 $query = 'action=edit';
599 }
600
601 $text = wfMsg( $message );
602 if ( wfEmptyMsg( $message, $text ) ) {
603 global $wgContLang;
604 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
605 }
606
607 $result = array();
608 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
609 $title, $message, $selected, $checkEdit,
610 &$classes, &$query, &$text, &$result)) ) {
611 return $result;
612 }
613
614 return array(
615 'class' => implode( ' ', $classes ),
616 'text' => $text,
617 'href' => $title->getLocalUrl( $query ) );
618 }
619
620 function makeTalkUrlDetails( $name, $urlaction = '' ) {
621 $title = Title::newFromText( $name );
622 if( !is_object($title) ) {
623 throw new MWException( __METHOD__." given invalid pagename $name" );
624 }
625 $title = $title->getTalkPage();
626 self::checkTitle( $title, $name );
627 return array(
628 'href' => $title->getLocalURL( $urlaction ),
629 'exists' => $title->getArticleID() != 0 ? true : false
630 );
631 }
632
633 function makeArticleUrlDetails( $name, $urlaction = '' ) {
634 $title = Title::newFromText( $name );
635 $title= $title->getSubjectPage();
636 self::checkTitle( $title, $name );
637 return array(
638 'href' => $title->getLocalURL( $urlaction ),
639 'exists' => $title->getArticleID() != 0 ? true : false
640 );
641 }
642
643 /**
644 * an array of edit links by default used for the tabs
645 * @return array
646 * @private
647 */
648 function buildContentActionUrls () {
649 global $wgContLang, $wgLang, $wgOut;
650 wfProfileIn( __METHOD__ );
651
652 global $wgUser, $wgRequest;
653 $action = $wgRequest->getText( 'action' );
654 $section = $wgRequest->getText( 'section' );
655 $content_actions = array();
656
657 $prevent_active_tabs = false ;
658 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
659
660 if( $this->iscontent ) {
661 $subjpage = $this->mTitle->getSubjectPage();
662 $talkpage = $this->mTitle->getTalkPage();
663
664 $nskey = $this->mTitle->getNamespaceKey();
665 $content_actions[$nskey] = $this->tabAction(
666 $subjpage,
667 $nskey,
668 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
669 '', true);
670
671 $content_actions['talk'] = $this->tabAction(
672 $talkpage,
673 'talk',
674 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
675 '',
676 true);
677
678 wfProfileIn( __METHOD__."-edit" );
679 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
680 $istalk = $this->mTitle->isTalkPage();
681 $istalkclass = $istalk?' istalk':'';
682 $content_actions['edit'] = array(
683 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
684 'text' => $this->mTitle->exists()
685 ? wfMsg( 'edit' )
686 : wfMsg( 'create' ),
687 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
688 );
689
690 if ( $istalk || $wgOut->showNewSectionLink() ) {
691 $content_actions['addsection'] = array(
692 'class' => $section == 'new'?'selected':false,
693 'text' => wfMsg('addsection'),
694 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
695 );
696 }
697 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
698 $content_actions['viewsource'] = array(
699 'class' => ($action == 'edit') ? 'selected' : false,
700 'text' => wfMsg('viewsource'),
701 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
702 );
703 }
704 wfProfileOut( __METHOD__."-edit" );
705
706 wfProfileIn( __METHOD__."-live" );
707 if ( $this->mTitle->getArticleId() ) {
708
709 $content_actions['history'] = array(
710 'class' => ($action == 'history') ? 'selected' : false,
711 'text' => wfMsg('history_short'),
712 'href' => $this->mTitle->getLocalUrl( 'action=history')
713 );
714
715 if($wgUser->isAllowed('delete')){
716 $content_actions['delete'] = array(
717 'class' => ($action == 'delete') ? 'selected' : false,
718 'text' => wfMsg('delete'),
719 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
720 );
721 }
722 if ( $this->mTitle->quickUserCan( 'move' ) ) {
723 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
724 $content_actions['move'] = array(
725 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
726 'text' => wfMsg('move'),
727 'href' => $moveTitle->getLocalUrl()
728 );
729 }
730
731 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
732 if(!$this->mTitle->isProtected()){
733 $content_actions['protect'] = array(
734 'class' => ($action == 'protect') ? 'selected' : false,
735 'text' => wfMsg('protect'),
736 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
737 );
738
739 } else {
740 $content_actions['unprotect'] = array(
741 'class' => ($action == 'unprotect') ? 'selected' : false,
742 'text' => wfMsg('unprotect'),
743 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
744 );
745 }
746 }
747 } else {
748 //article doesn't exist or is deleted
749 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
750 if( $n = $this->mTitle->isDeleted() ) {
751 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
752 $content_actions['undelete'] = array(
753 'class' => false,
754 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
755 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
756 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
757 );
758 }
759 }
760
761 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
762 if( !$this->mTitle->getRestrictions( 'create' ) ) {
763 $content_actions['protect'] = array(
764 'class' => ($action == 'protect') ? 'selected' : false,
765 'text' => wfMsg('protect'),
766 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
767 );
768
769 } else {
770 $content_actions['unprotect'] = array(
771 'class' => ($action == 'unprotect') ? 'selected' : false,
772 'text' => wfMsg('unprotect'),
773 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
774 );
775 }
776 }
777 }
778
779 wfProfileOut( __METHOD__."-live" );
780
781 if( $this->loggedin ) {
782 if( !$this->mTitle->userIsWatching()) {
783 $content_actions['watch'] = array(
784 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
785 'text' => wfMsg('watch'),
786 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
787 );
788 } else {
789 $content_actions['unwatch'] = array(
790 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
791 'text' => wfMsg('unwatch'),
792 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
793 );
794 }
795 }
796
797
798 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
799 } else {
800 /* show special page tab */
801
802 $content_actions[$this->mTitle->getNamespaceKey()] = array(
803 'class' => 'selected',
804 'text' => wfMsg('nstab-special'),
805 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
806 );
807
808 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
809 }
810
811 /* show links to different language variants */
812 global $wgDisableLangConversion;
813 $variants = $wgContLang->getVariants();
814 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
815 $preferred = $wgContLang->getPreferredVariant();
816 $vcount=0;
817 foreach( $variants as $code ) {
818 $varname = $wgContLang->getVariantname( $code );
819 if( $varname == 'disable' )
820 continue;
821 $selected = ( $code == $preferred )? 'selected' : false;
822 $content_actions['varlang-' . $vcount] = array(
823 'class' => $selected,
824 'text' => $varname,
825 'href' => $this->mTitle->getLocalURL('',$code)
826 );
827 $vcount ++;
828 }
829 }
830
831 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
832
833 wfProfileOut( __METHOD__ );
834 return $content_actions;
835 }
836
837
838
839 /**
840 * build array of common navigation links
841 * @return array
842 * @private
843 */
844 function buildNavUrls () {
845 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
846 global $wgEnableUploads, $wgUploadNavigationUrl;
847
848 wfProfileIn( __METHOD__ );
849
850 $action = $wgRequest->getText( 'action' );
851
852 $nav_urls = array();
853 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
854 if( $wgEnableUploads ) {
855 if ($wgUploadNavigationUrl) {
856 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
857 } else {
858 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
859 }
860 } else {
861 if ($wgUploadNavigationUrl)
862 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
863 else
864 $nav_urls['upload'] = false;
865 }
866 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
867
868 // default permalink to being off, will override it as required below.
869 $nav_urls['permalink'] = false;
870
871 // A print stylesheet is attached to all pages, but nobody ever
872 // figures that out. :) Add a link...
873 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
874 $nav_urls['print'] = array(
875 'text' => wfMsg( 'printableversion' ),
876 'href' => $wgRequest->appendQuery( 'printable=yes' )
877 );
878
879 // Also add a "permalink" while we're at it
880 if ( $this->mRevisionId ) {
881 $nav_urls['permalink'] = array(
882 'text' => wfMsg( 'permalink' ),
883 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
884 );
885 }
886
887 // Copy in case this undocumented, shady hook tries to mess with internals
888 $revid = $this->mRevisionId;
889 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
890 }
891
892 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
893 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
894 $nav_urls['whatlinkshere'] = array(
895 'href' => $wlhTitle->getLocalUrl()
896 );
897 if( $this->mTitle->getArticleId() ) {
898 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
899 $nav_urls['recentchangeslinked'] = array(
900 'href' => $rclTitle->getLocalUrl()
901 );
902 } else {
903 $nav_urls['recentchangeslinked'] = false;
904 }
905 if ($wgUseTrackbacks)
906 $nav_urls['trackbacklink'] = array(
907 'href' => $wgTitle->trackbackURL()
908 );
909 }
910
911 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
912 $id = User::idFromName($this->mTitle->getText());
913 $ip = User::isIP($this->mTitle->getText());
914 } else {
915 $id = 0;
916 $ip = false;
917 }
918
919 if($id || $ip) { # both anons and non-anons have contribs list
920 $nav_urls['contributions'] = array(
921 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
922 );
923
924 if( $id ) {
925 $logPage = SpecialPage::getTitleFor( 'Log' );
926 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
927 . $this->mTitle->getPartialUrl() ) );
928 } else {
929 $nav_urls['log'] = false;
930 }
931
932 if ( $wgUser->isAllowed( 'block' ) ) {
933 $nav_urls['blockip'] = array(
934 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
935 );
936 } else {
937 $nav_urls['blockip'] = false;
938 }
939 } else {
940 $nav_urls['contributions'] = false;
941 $nav_urls['log'] = false;
942 $nav_urls['blockip'] = false;
943 }
944 $nav_urls['emailuser'] = false;
945 if( $this->showEmailUser( $id ) ) {
946 $nav_urls['emailuser'] = array(
947 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
948 );
949 }
950 wfProfileOut( __METHOD__ );
951 return $nav_urls;
952 }
953
954 /**
955 * Generate strings used for xml 'id' names
956 * @return string
957 * @private
958 */
959 function getNameSpaceKey () {
960 return $this->mTitle->getNamespaceKey();
961 }
962
963 /**
964 * @private
965 */
966 function setupUserCss() {
967 wfProfileIn( __METHOD__ );
968
969 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
970
971 $usercss = '';
972 $siteargs = '&maxage=' . $wgSquidMaxage;
973 if( $this->loggedin ) {
974 // Ensure that logged-in users' generated CSS isn't clobbered
975 // by anons' publicly cacheable generated CSS.
976 $siteargs .= '&smaxage=0';
977 $siteargs .= '&ts=' . $wgUser->mTouched;
978 }
979
980 # If we use the site's dynamic CSS, throw that in, too
981 // Per-site custom styles
982 if ( $wgUseSiteCss ) {
983 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
984 $skinquery = '';
985 if (($us = $wgRequest->getVal('useskin', '')) !== '')
986 $skinquery = "&useskin=$us";
987
988 $this->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) );
989 $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ),
990 'screen' );
991 }
992
993 // Per-user styles based on preferences
994 $this->addStyle( self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ), 'screen' );
995
996 // Per-user custom style pages
997 if ( $wgAllowUserCss && $this->loggedin ) {
998 $action = $wgRequest->getVal('action');
999
1000 # if we're previewing the CSS page, use it
1001 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
1002 $previewCss = $wgRequest->getText('wpTextbox1');
1003
1004 /// @fixme properly escape the cdata!
1005 $this->usercss = "/*<![CDATA[*/\n" .
1006 $previewCss .
1007 "/*]]>*/";
1008 } else {
1009 $this->addStyle( self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
1010 'action=raw&ctype=text/css'), 'screen' );
1011 }
1012 }
1013
1014 wfProfileOut( __METHOD__ );
1015 }
1016
1017 /**
1018 * @private
1019 */
1020 function setupUserJs( $allowUserJs ) {
1021 wfProfileIn( __METHOD__ );
1022
1023 global $wgRequest, $wgJsMimeType;
1024 $action = $wgRequest->getText('action');
1025
1026 if( $allowUserJs && $this->loggedin ) {
1027 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1028 # XXX: additional security check/prompt?
1029 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1030 } else {
1031 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
1032 }
1033 }
1034 wfProfileOut( __METHOD__ );
1035 }
1036
1037 /**
1038 * Code for extensions to hook into to provide per-page CSS, see
1039 * extensions/PageCSS/PageCSS.php for an implementation of this.
1040 *
1041 * @private
1042 */
1043 function setupPageCss() {
1044 wfProfileIn( __METHOD__ );
1045 $out = false;
1046 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1047
1048 wfProfileOut( __METHOD__ );
1049 return $out;
1050 }
1051
1052 /**
1053 * returns css with user-specific options
1054 */
1055 public function getUserStylesheet() {
1056 wfProfileIn( __METHOD__ );
1057
1058 $s = "/* generated user stylesheet */\n";
1059 $s .= $this->reallyDoGetUserStyles();
1060 wfProfileOut( __METHOD__ );
1061 return $s;
1062 }
1063
1064 /**
1065 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1066 * nated together. For some bizarre reason, it does *not* return any
1067 * custom user JS from subpages. Huh?
1068 *
1069 * There's absolutely no reason to have separate Monobook/Common JSes.
1070 * Any JS that cares can just check the skin variable generated at the
1071 * top. For now Monobook.js will be maintained, but it should be consi-
1072 * dered deprecated.
1073 *
1074 * @return string
1075 */
1076 public function getUserJs() {
1077 wfProfileIn( __METHOD__ );
1078
1079 $s = parent::getUserJs();
1080 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js */\n";
1081
1082 // avoid inclusion of non defined user JavaScript (with custom skins only)
1083 // by checking for default message content
1084 $msgKey = ucfirst($this->skinname).'.js';
1085 $userJS = wfMsgForContent($msgKey);
1086 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1087 $s .= $userJS;
1088 }
1089
1090 wfProfileOut( __METHOD__ );
1091 return $s;
1092 }
1093
1094 /**
1095 * Add a local or specified stylesheet, with the given media options.
1096 * Meant primarily for internal use...
1097 *
1098 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1099 * @param $conditional -- for IE conditional comments, specifying an IE version
1100 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1101 */
1102 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1103 $options = array();
1104 if( $media )
1105 $options['media'] = $media;
1106 if( $condition )
1107 $options['condition'] = $condition;
1108 if( $dir )
1109 $options['dir'] = $dir;
1110 $this->styles[$style] = $options;
1111 }
1112
1113 /**
1114 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1115 * These will be applied to various media & IE conditionals.
1116 */
1117 protected function buildCssLinks() {
1118 global $wgContLang;
1119
1120 foreach( $this->styles as $file => $options ) {
1121 $links[] = $this->styleLink( $file, $options );
1122 }
1123
1124 return implode( "\n", $links );
1125 }
1126
1127 protected function styleLink( $style, $options ) {
1128 global $wgRequest;
1129
1130 if( isset( $options['dir'] ) ) {
1131 global $wgContLang;
1132 $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
1133 if( $siteDir != $options['dir'] )
1134 return '';
1135 }
1136
1137 if( isset( $options['media'] ) ) {
1138 $media = $this->transformCssMedia( $options['media'] );
1139 if( is_null( $media ) ) {
1140 return '';
1141 }
1142 } else {
1143 $media = '';
1144 }
1145
1146 if( substr( $style, 0, 1 ) == '/' ||
1147 substr( $style, 0, 5 ) == 'http:' ||
1148 substr( $style, 0, 6 ) == 'https:' ) {
1149 $url = $style;
1150 } else {
1151 global $wgStylePath, $wgStyleVersion;
1152 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1153 }
1154
1155 $attribs = array(
1156 'rel' => 'stylesheet',
1157 'href' => $url,
1158 'type' => 'text/css' );
1159 if( $media ) {
1160 $attribs['media'] = $media;
1161 }
1162
1163 $link = Xml::element( 'link', $attribs );
1164
1165 if( isset( $options['condition'] ) ) {
1166 $condition = htmlspecialchars( $options['condition'] );
1167 $link = "<!--[if $condition]>$link<![endif]-->";
1168 }
1169 return $link;
1170 }
1171
1172 function transformCssMedia( $media ) {
1173 global $wgRequest, $wgHandheldForIPhone;
1174
1175 // Switch in on-screen display for media testing
1176 $switches = array(
1177 'printable' => 'print',
1178 'handheld' => 'handheld',
1179 );
1180 foreach( $switches as $switch => $targetMedia ) {
1181 if( $wgRequest->getBool( $switch ) ) {
1182 if( $media == $targetMedia ) {
1183 $media = '';
1184 } elseif( $media == 'screen' ) {
1185 return null;
1186 }
1187 }
1188 }
1189
1190 // Expand longer media queries as iPhone doesn't grok 'handheld'
1191 if( $wgHandheldForIPhone ) {
1192 $mediaAliases = array(
1193 'screen' => 'screen and (min-device-width: 481px)',
1194 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1195 );
1196
1197 if( isset( $mediaAliases[$media] ) ) {
1198 $media = $mediaAliases[$media];
1199 }
1200 }
1201
1202 return $media;
1203 }
1204
1205 }
1206
1207 /**
1208 * Generic wrapper for template functions, with interface
1209 * compatible with what we use of PHPTAL 0.7.
1210 * @ingroup Skins
1211 */
1212 class QuickTemplate {
1213 /**
1214 * @public
1215 */
1216 function QuickTemplate() {
1217 $this->data = array();
1218 $this->translator = new MediaWiki_I18N();
1219 }
1220
1221 /**
1222 * @public
1223 */
1224 function set( $name, $value ) {
1225 $this->data[$name] = $value;
1226 }
1227
1228 /**
1229 * @public
1230 */
1231 function setRef($name, &$value) {
1232 $this->data[$name] =& $value;
1233 }
1234
1235 /**
1236 * @public
1237 */
1238 function setTranslator( &$t ) {
1239 $this->translator = &$t;
1240 }
1241
1242 /**
1243 * @public
1244 */
1245 function execute() {
1246 echo "Override this function.";
1247 }
1248
1249
1250 /**
1251 * @private
1252 */
1253 function text( $str ) {
1254 echo htmlspecialchars( $this->data[$str] );
1255 }
1256
1257 /**
1258 * @private
1259 */
1260 function jstext( $str ) {
1261 echo Xml::escapeJsString( $this->data[$str] );
1262 }
1263
1264 /**
1265 * @private
1266 */
1267 function html( $str ) {
1268 echo $this->data[$str];
1269 }
1270
1271 /**
1272 * @private
1273 */
1274 function msg( $str ) {
1275 echo htmlspecialchars( $this->translator->translate( $str ) );
1276 }
1277
1278 /**
1279 * @private
1280 */
1281 function msgHtml( $str ) {
1282 echo $this->translator->translate( $str );
1283 }
1284
1285 /**
1286 * An ugly, ugly hack.
1287 * @private
1288 */
1289 function msgWiki( $str ) {
1290 global $wgParser, $wgTitle, $wgOut;
1291
1292 $text = $this->translator->translate( $str );
1293 $parserOutput = $wgParser->parse( $text, $wgTitle,
1294 $wgOut->parserOptions(), true );
1295 echo $parserOutput->getText();
1296 }
1297
1298 /**
1299 * @private
1300 */
1301 function haveData( $str ) {
1302 return isset( $this->data[$str] );
1303 }
1304
1305 /**
1306 * @private
1307 */
1308 function haveMsg( $str ) {
1309 $msg = $this->translator->translate( $str );
1310 return ($msg != '-') && ($msg != ''); # ????
1311 }
1312 }