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