Adding messages for new global group 'sysadmin'. Brion, Tim, Kate and JeLuF are all...
[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, $wgUseSiteJs;
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 if( $wgUseSiteJs ) {
286 $jsCache = $this->loggedin ? '&smaxage=0' : '';
287 $tpl->set( 'jsvarurl',
288 self::makeUrl('-',
289 "action=raw$jsCache&gen=js&useskin=" .
290 urlencode( $this->getSkinName() ) ) );
291 } else {
292 $tpl->set('jsvarurl', false);
293 }
294 $newtalks = $wgUser->getNewMessageLinks();
295
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(
302 $usertalktitle,
303 wfMsgHtml( 'newmessageslink' ),
304 'redirect=no'
305 ),
306 $this->makeKnownLinkObj(
307 $usertalktitle,
308 wfMsgHtml( 'newmessagesdifflink' ),
309 'diff=cur'
310 )
311 );
312 # Disable Cache
313 $wgOut->setSquidMaxage(0);
314 }
315 } else if (count($newtalks)) {
316 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
317 $msgs = array();
318 foreach ($newtalks as $newtalk) {
319 $msgs[] = wfElement("a",
320 array('href' => $newtalk["link"]), $newtalk["wiki"]);
321 }
322 $parts = implode($sep, $msgs);
323 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
324 $wgOut->setSquidMaxage(0);
325 } else {
326 $ntl = '';
327 }
328 wfProfileOut( __METHOD__."-stuff2" );
329
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() )
336 {
337 if ( !$wgDisableCounters ) {
338 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
339 if ( $viewcount ) {
340 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
341 } else {
342 $tpl->set('viewcount', false);
343 }
344 } else {
345 $tpl->set('viewcount', false);
346 }
347
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))
361 );
362 } else {
363 $tpl->set('numberofwatchingusers', false);
364 }
365 } else {
366 $tpl->set('numberofwatchingusers', false);
367 }
368
369 $tpl->set('copyright',$this->getCopyright());
370
371 $this->credits = false;
372
373 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
374 require_once("Credits.php");
375 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
376 } else {
377 $tpl->set('lastmod', $this->lastModified());
378 }
379
380 $tpl->setRef( 'credits', $this->credits );
381
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);
388 } else {
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);
394 }
395 wfProfileOut( __METHOD__."-stuff3" );
396
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() );
403
404 $tpl->setRef( 'debug', $out->mDebugtext );
405 $tpl->set( 'reporttime', wfReportTime() );
406 $tpl->set( 'sitenotice', wfGetSiteNotice() );
407 $tpl->set( 'bottomscripts', $this->bottomScripts() );
408
409 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
410 $out->mBodytext .= $printfooter ;
411 $tpl->setRef( 'bodytext', $out->mBodytext );
412
413 # Language links
414 $language_urls = array();
415
416 if ( !$wgHideInterlanguageLinks ) {
417 foreach( $wgOut->getLanguageLinks() as $l ) {
418 $tmp = explode( ':', $l, 2 );
419 $class = 'interwiki-' . $tmp[0];
420 unset($tmp);
421 $nt = Title::newFromText( $l );
422 $language_urls[] = array(
423 'href' => $nt->getFullURL(),
424 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
425 'class' => $class
426 );
427 }
428 }
429 if(count($language_urls)) {
430 $tpl->setRef( 'language_urls', $language_urls);
431 } else {
432 $tpl->set('language_urls', false);
433 }
434 wfProfileOut( __METHOD__."-stuff4" );
435
436 # Personal toolbar
437 $tpl->set('personal_urls', $this->buildPersonalUrls());
438 $content_actions = $this->buildContentActionUrls();
439 $tpl->setRef('content_actions', $content_actions);
440
441 // XXX: attach this from javascript, same with section editing
442 if($this->iseditable && $wgUser->getOption("editondblclick") )
443 {
444 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
445 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
446 } else {
447 $tpl->set('body_ondblclick', false);
448 }
449 $tpl->set( 'body_onload', false );
450 $tpl->set( 'sidebar', $this->buildSidebar() );
451 $tpl->set( 'nav_urls', $this->buildNavUrls() );
452
453 // original version by hansm
454 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
455 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
456 }
457
458 // execute template
459 wfProfileIn( __METHOD__."-execute" );
460 $res = $tpl->execute();
461 wfProfileOut( __METHOD__."-execute" );
462
463 // result may be an error
464 $this->printOrError( $res );
465 wfProfileOut( __METHOD__ );
466 }
467
468 /**
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.
472 *
473 * @param mixed $str
474 * @private
475 */
476 function printOrError( $str ) {
477 echo $str;
478 }
479
480 /**
481 * build array of urls for personal toolbar
482 * @return array
483 * @private
484 */
485 function buildPersonalUrls() {
486 global $wgTitle, $wgRequest;
487
488 $pageurl = $wgTitle->getLocalURL();
489 wfProfileIn( __METHOD__ );
490
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 )
499 );
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 )
506 );
507 $href = self::makeSpecialUrl( 'Preferences' );
508 $personal_urls['preferences'] = array(
509 'text' => wfMsg( 'mypreferences' ),
510 'href' => $href,
511 'active' => ( $href == $pageurl )
512 );
513 $href = self::makeSpecialUrl( 'Watchlist' );
514 $personal_urls['watchlist'] = array(
515 'text' => wfMsg( 'mywatchlist' ),
516 'href' => $href,
517 'active' => ( $href == $pageurl )
518 );
519
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 );
532 } else {
533 $active = false;
534 }
535
536 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
537 $personal_urls['mycontris'] = array(
538 'text' => wfMsg( 'mycontris' ),
539 'href' => $href,
540 'active' => $active
541 );
542 $personal_urls['logout'] = array(
543 'text' => wfMsg( 'userlogout' ),
544 'href' => self::makeSpecialUrl( 'Userlogout',
545 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
546 ),
547 'active' => false
548 );
549 } else {
550 global $wgUser;
551 $loginlink = $wgUser->isAllowed( 'createaccount' )
552 ? 'nav-login-createaccount'
553 : 'login';
554 if( $this->showIPinHeader() ) {
555 $href = &$this->userpageUrlDetails['href'];
556 $personal_urls['anonuserpage'] = array(
557 'text' => $this->username,
558 'href' => $href,
559 'class' => $this->userpageUrlDetails['exists']?false:'new',
560 'active' => ( $pageurl == $href )
561 );
562 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
563 $href = &$usertalkUrlDetails['href'];
564 $personal_urls['anontalk'] = array(
565 'text' => wfMsg('anontalk'),
566 'href' => $href,
567 'class' => $usertalkUrlDetails['exists']?false:'new',
568 'active' => ( $pageurl == $href )
569 );
570 $personal_urls['anonlogin'] = array(
571 'text' => wfMsg( $loginlink ),
572 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
573 'active' => $wgTitle->isSpecial( 'Userlogin' )
574 );
575 } else {
576
577 $personal_urls['login'] = array(
578 'text' => wfMsg( $loginlink ),
579 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
580 'active' => $wgTitle->isSpecial( 'Userlogin' )
581 );
582 }
583 }
584
585 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
586 wfProfileOut( __METHOD__ );
587 return $personal_urls;
588 }
589
590 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
591 $classes = array();
592 if( $selected ) {
593 $classes[] = 'selected';
594 }
595 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
596 $classes[] = 'new';
597 $query = 'action=edit';
598 }
599
600 $text = wfMsg( $message );
601 if ( wfEmptyMsg( $message, $text ) ) {
602 global $wgContLang;
603 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
604 }
605
606 $result = array();
607 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
608 $title, $message, $selected, $checkEdit,
609 &$classes, &$query, &$text, &$result)) ) {
610 return $result;
611 }
612
613 return array(
614 'class' => implode( ' ', $classes ),
615 'text' => $text,
616 'href' => $title->getLocalUrl( $query ) );
617 }
618
619 function makeTalkUrlDetails( $name, $urlaction = '' ) {
620 $title = Title::newFromText( $name );
621 if( !is_object($title) ) {
622 throw new MWException( __METHOD__." given invalid pagename $name" );
623 }
624 $title = $title->getTalkPage();
625 self::checkTitle( $title, $name );
626 return array(
627 'href' => $title->getLocalURL( $urlaction ),
628 'exists' => $title->getArticleID() != 0 ? true : false
629 );
630 }
631
632 function makeArticleUrlDetails( $name, $urlaction = '' ) {
633 $title = Title::newFromText( $name );
634 $title= $title->getSubjectPage();
635 self::checkTitle( $title, $name );
636 return array(
637 'href' => $title->getLocalURL( $urlaction ),
638 'exists' => $title->getArticleID() != 0 ? true : false
639 );
640 }
641
642 /**
643 * an array of edit links by default used for the tabs
644 * @return array
645 * @private
646 */
647 function buildContentActionUrls () {
648 global $wgContLang, $wgLang, $wgOut;
649 wfProfileIn( __METHOD__ );
650
651 global $wgUser, $wgRequest;
652 $action = $wgRequest->getText( 'action' );
653 $section = $wgRequest->getText( 'section' );
654 $content_actions = array();
655
656 $prevent_active_tabs = false ;
657 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
658
659 if( $this->iscontent ) {
660 $subjpage = $this->mTitle->getSubjectPage();
661 $talkpage = $this->mTitle->getTalkPage();
662
663 $nskey = $this->mTitle->getNamespaceKey();
664 $content_actions[$nskey] = $this->tabAction(
665 $subjpage,
666 $nskey,
667 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
668 '', true);
669
670 $content_actions['talk'] = $this->tabAction(
671 $talkpage,
672 'talk',
673 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
674 '',
675 true);
676
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()
684 ? wfMsg( 'edit' )
685 : wfMsg( 'create' ),
686 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
687 );
688
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&section=new' )
694 );
695 }
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() )
701 );
702 }
703 wfProfileOut( __METHOD__."-edit" );
704
705 wfProfileIn( __METHOD__."-live" );
706 if ( $this->mTitle->getArticleId() ) {
707
708 $content_actions['history'] = array(
709 'class' => ($action == 'history') ? 'selected' : false,
710 'text' => wfMsg('history_short'),
711 'href' => $this->mTitle->getLocalUrl( 'action=history')
712 );
713
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' )
719 );
720 }
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()
727 );
728 }
729
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' )
736 );
737
738 } else {
739 $content_actions['unprotect'] = array(
740 'class' => ($action == 'unprotect') ? 'selected' : false,
741 'text' => wfMsg('unprotect'),
742 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
743 );
744 }
745 }
746 } else {
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(
752 'class' => false,
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" )
756 );
757 }
758 }
759
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' )
766 );
767
768 } else {
769 $content_actions['unprotect'] = array(
770 'class' => ($action == 'unprotect') ? 'selected' : false,
771 'text' => wfMsg('unprotect'),
772 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
773 );
774 }
775 }
776 }
777
778 wfProfileOut( __METHOD__."-live" );
779
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' )
786 );
787 } else {
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' )
792 );
793 }
794 }
795
796
797 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
798 } else {
799 /* show special page tab */
800
801 $content_actions[$this->mTitle->getNamespaceKey()] = array(
802 'class' => 'selected',
803 'text' => wfMsg('nstab-special'),
804 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
805 );
806
807 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
808 }
809
810 /* show links to different language variants */
811 global $wgDisableLangConversion;
812 $variants = $wgContLang->getVariants();
813 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
814 $preferred = $wgContLang->getPreferredVariant();
815 $vcount=0;
816 foreach( $variants as $code ) {
817 $varname = $wgContLang->getVariantname( $code );
818 if( $varname == 'disable' )
819 continue;
820 $selected = ( $code == $preferred )? 'selected' : false;
821 $content_actions['varlang-' . $vcount] = array(
822 'class' => $selected,
823 'text' => $varname,
824 'href' => $this->mTitle->getLocalURL('',$code)
825 );
826 $vcount ++;
827 }
828 }
829
830 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
831
832 wfProfileOut( __METHOD__ );
833 return $content_actions;
834 }
835
836
837
838 /**
839 * build array of common navigation links
840 * @return array
841 * @private
842 */
843 function buildNavUrls () {
844 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
845 global $wgEnableUploads, $wgUploadNavigationUrl;
846
847 wfProfileIn( __METHOD__ );
848
849 $action = $wgRequest->getText( 'action' );
850
851 $nav_urls = array();
852 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
853 if( $wgEnableUploads ) {
854 if ($wgUploadNavigationUrl) {
855 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
856 } else {
857 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
858 }
859 } else {
860 if ($wgUploadNavigationUrl)
861 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
862 else
863 $nav_urls['upload'] = false;
864 }
865 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
866
867 // default permalink to being off, will override it as required below.
868 $nav_urls['permalink'] = false;
869
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' )
876 );
877
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" )
883 );
884 }
885
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 ) );
889 }
890
891 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
892 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
893 $nav_urls['whatlinkshere'] = array(
894 'href' => $wlhTitle->getLocalUrl()
895 );
896 if( $this->mTitle->getArticleId() ) {
897 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
898 $nav_urls['recentchangeslinked'] = array(
899 'href' => $rclTitle->getLocalUrl()
900 );
901 } else {
902 $nav_urls['recentchangeslinked'] = false;
903 }
904 if ($wgUseTrackbacks)
905 $nav_urls['trackbacklink'] = array(
906 'href' => $wgTitle->trackbackURL()
907 );
908 }
909
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());
913 } else {
914 $id = 0;
915 $ip = false;
916 }
917
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() )
921 );
922
923 if( $id ) {
924 $logPage = SpecialPage::getTitleFor( 'Log' );
925 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
926 . $this->mTitle->getPartialUrl() ) );
927 } else {
928 $nav_urls['log'] = false;
929 }
930
931 if ( $wgUser->isAllowed( 'block' ) ) {
932 $nav_urls['blockip'] = array(
933 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
934 );
935 } else {
936 $nav_urls['blockip'] = false;
937 }
938 } else {
939 $nav_urls['contributions'] = false;
940 $nav_urls['log'] = false;
941 $nav_urls['blockip'] = false;
942 }
943 $nav_urls['emailuser'] = false;
944 if( $this->showEmailUser( $id ) ) {
945 $nav_urls['emailuser'] = array(
946 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
947 );
948 }
949 wfProfileOut( __METHOD__ );
950 return $nav_urls;
951 }
952
953 /**
954 * Generate strings used for xml 'id' names
955 * @return string
956 * @private
957 */
958 function getNameSpaceKey () {
959 return $this->mTitle->getNamespaceKey();
960 }
961
962 /**
963 * @private
964 */
965 function setupUserCss() {
966 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
967
968 wfProfileIn( __METHOD__ );
969
970 $siteargs = array(
971 'action' => 'raw',
972 'maxage' => $wgSquidMaxage,
973 );
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;
979 }
980
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
988 ) + $siteargs );
989 $this->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
990 $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ),
991 'screen' );
992 }
993
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' );
999
1000 // Per-user custom style pages
1001 if ( $wgAllowUserCss && $this->loggedin ) {
1002 $action = $wgRequest->getVal('action');
1003
1004 # if we're previewing the CSS page, use it
1005 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
1006 $previewCss = $wgRequest->getText('wpTextbox1');
1007
1008 /// @fixme properly escape the cdata!
1009 $this->usercss = "/*<![CDATA[*/\n" .
1010 $previewCss .
1011 "/*]]>*/";
1012 } else {
1013 $this->addStyle( self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
1014 'action=raw&ctype=text/css'), 'screen' );
1015 }
1016 }
1017
1018 wfProfileOut( __METHOD__ );
1019 }
1020
1021 /**
1022 * @private
1023 */
1024 function setupUserJs( $allowUserJs ) {
1025 wfProfileIn( __METHOD__ );
1026
1027 global $wgRequest, $wgJsMimeType;
1028 $action = $wgRequest->getText('action');
1029
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') . ' /*]]>*/';
1034 } else {
1035 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
1036 }
1037 }
1038 wfProfileOut( __METHOD__ );
1039 }
1040
1041 /**
1042 * Code for extensions to hook into to provide per-page CSS, see
1043 * extensions/PageCSS/PageCSS.php for an implementation of this.
1044 *
1045 * @private
1046 */
1047 function setupPageCss() {
1048 wfProfileIn( __METHOD__ );
1049 $out = false;
1050 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1051
1052 wfProfileOut( __METHOD__ );
1053 return $out;
1054 }
1055
1056 /**
1057 * returns css with user-specific options
1058 */
1059 public function getUserStylesheet() {
1060 wfProfileIn( __METHOD__ );
1061
1062 $s = "/* generated user stylesheet */\n";
1063 $s .= $this->reallyDoGetUserStyles();
1064 wfProfileOut( __METHOD__ );
1065 return $s;
1066 }
1067
1068 /**
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?
1072 *
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-
1076 * dered deprecated.
1077 *
1078 * @return string
1079 */
1080 public function getUserJs() {
1081 wfProfileIn( __METHOD__ );
1082
1083 $s = parent::getUserJs();
1084 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js */\n";
1085
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 ) ) {
1091 $s .= $userJS;
1092 }
1093
1094 wfProfileOut( __METHOD__ );
1095 return $s;
1096 }
1097
1098 /**
1099 * Add a local or specified stylesheet, with the given media options.
1100 * Meant primarily for internal use...
1101 *
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
1105 */
1106 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1107 $options = array();
1108 if( $media )
1109 $options['media'] = $media;
1110 if( $condition )
1111 $options['condition'] = $condition;
1112 if( $dir )
1113 $options['dir'] = $dir;
1114 $this->styles[$style] = $options;
1115 }
1116
1117 /**
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.
1120 */
1121 protected function buildCssLinks() {
1122 foreach( $this->styles as $file => $options ) {
1123 $link = $this->styleLink( $file, $options );
1124 if( $link )
1125 $links[] = $link;
1126 }
1127
1128 return implode( "\n\t\t", $links );
1129 }
1130
1131 protected function styleLink( $style, $options ) {
1132 global $wgRequest;
1133
1134 if( isset( $options['dir'] ) ) {
1135 global $wgContLang;
1136 $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
1137 if( $siteDir != $options['dir'] )
1138 return '';
1139 }
1140
1141 if( isset( $options['media'] ) ) {
1142 $media = $this->transformCssMedia( $options['media'] );
1143 if( is_null( $media ) ) {
1144 return '';
1145 }
1146 } else {
1147 $media = '';
1148 }
1149
1150 if( substr( $style, 0, 1 ) == '/' ||
1151 substr( $style, 0, 5 ) == 'http:' ||
1152 substr( $style, 0, 6 ) == 'https:' ) {
1153 $url = $style;
1154 } else {
1155 global $wgStylePath, $wgStyleVersion;
1156 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1157 }
1158
1159 $attribs = array(
1160 'rel' => 'stylesheet',
1161 'href' => $url,
1162 'type' => 'text/css' );
1163 if( $media ) {
1164 $attribs['media'] = $media;
1165 }
1166
1167 $link = Xml::element( 'link', $attribs );
1168
1169 if( isset( $options['condition'] ) ) {
1170 $condition = htmlspecialchars( $options['condition'] );
1171 $link = "<!--[if $condition]>$link<![endif]-->";
1172 }
1173 return $link;
1174 }
1175
1176 function transformCssMedia( $media ) {
1177 global $wgRequest, $wgHandheldForIPhone;
1178
1179 // Switch in on-screen display for media testing
1180 $switches = array(
1181 'printable' => 'print',
1182 'handheld' => 'handheld',
1183 );
1184 foreach( $switches as $switch => $targetMedia ) {
1185 if( $wgRequest->getBool( $switch ) ) {
1186 if( $media == $targetMedia ) {
1187 $media = '';
1188 } elseif( $media == 'screen' ) {
1189 return null;
1190 }
1191 }
1192 }
1193
1194 // Expand longer media queries as iPhone doesn't grok 'handheld'
1195 if( $wgHandheldForIPhone ) {
1196 $mediaAliases = array(
1197 'screen' => 'screen and (min-device-width: 481px)',
1198 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1199 );
1200
1201 if( isset( $mediaAliases[$media] ) ) {
1202 $media = $mediaAliases[$media];
1203 }
1204 }
1205
1206 return $media;
1207 }
1208
1209 }
1210
1211 /**
1212 * Generic wrapper for template functions, with interface
1213 * compatible with what we use of PHPTAL 0.7.
1214 * @ingroup Skins
1215 */
1216 class QuickTemplate {
1217 /**
1218 * @public
1219 */
1220 function QuickTemplate() {
1221 $this->data = array();
1222 $this->translator = new MediaWiki_I18N();
1223 }
1224
1225 /**
1226 * @public
1227 */
1228 function set( $name, $value ) {
1229 $this->data[$name] = $value;
1230 }
1231
1232 /**
1233 * @public
1234 */
1235 function setRef($name, &$value) {
1236 $this->data[$name] =& $value;
1237 }
1238
1239 /**
1240 * @public
1241 */
1242 function setTranslator( &$t ) {
1243 $this->translator = &$t;
1244 }
1245
1246 /**
1247 * @public
1248 */
1249 function execute() {
1250 echo "Override this function.";
1251 }
1252
1253
1254 /**
1255 * @private
1256 */
1257 function text( $str ) {
1258 echo htmlspecialchars( $this->data[$str] );
1259 }
1260
1261 /**
1262 * @private
1263 */
1264 function jstext( $str ) {
1265 echo Xml::escapeJsString( $this->data[$str] );
1266 }
1267
1268 /**
1269 * @private
1270 */
1271 function html( $str ) {
1272 echo $this->data[$str];
1273 }
1274
1275 /**
1276 * @private
1277 */
1278 function msg( $str ) {
1279 echo htmlspecialchars( $this->translator->translate( $str ) );
1280 }
1281
1282 /**
1283 * @private
1284 */
1285 function msgHtml( $str ) {
1286 echo $this->translator->translate( $str );
1287 }
1288
1289 /**
1290 * An ugly, ugly hack.
1291 * @private
1292 */
1293 function msgWiki( $str ) {
1294 global $wgParser, $wgTitle, $wgOut;
1295
1296 $text = $this->translator->translate( $str );
1297 $parserOutput = $wgParser->parse( $text, $wgTitle,
1298 $wgOut->parserOptions(), true );
1299 echo $parserOutput->getText();
1300 }
1301
1302 /**
1303 * @private
1304 */
1305 function haveData( $str ) {
1306 return isset( $this->data[$str] );
1307 }
1308
1309 /**
1310 * @private
1311 */
1312 function haveMsg( $str ) {
1313 $msg = $this->translator->translate( $str );
1314 return ($msg != '-') && ($msg != ''); # ????
1315 }
1316 }