Localisation updates for core messages from Betawiki (2008-03-14 18:02 CET)
[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 * @addtogroup 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 $fname = 'SkinTemplate-translate';
36 wfProfileIn( $fname );
37
38 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
39 $value = preg_replace( '/^string:/', '', $value );
40
41 $value = wfMsg( $value );
42 // interpolate variables
43 $m = array();
44 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
45 list($src, $var) = $m;
46 wfSuppressWarnings();
47 $varValue = $this->_context[$var];
48 wfRestoreWarnings();
49 $value = str_replace($src, $varValue, $value);
50 }
51 wfProfileOut( $fname );
52 return $value;
53 }
54 }
55
56 /**
57 * Template-filler skin base class
58 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
59 * Based on Brion's smarty skin
60 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
61 *
62 * @todo Needs some serious refactoring into functions that correspond
63 * to the computations individual esi snippets need. Most importantly no body
64 * parsing for most of those of course.
65 *
66 * @addtogroup Skins
67 */
68 class SkinTemplate extends Skin {
69 /**#@+
70 * @private
71 */
72
73 /**
74 * Name of our skin, set in initPage()
75 * It probably need to be all lower case.
76 */
77 var $skinname;
78
79 /**
80 * Stylesheets set to use
81 * Sub directory in ./skins/ where various stylesheets are located
82 */
83 var $stylename;
84
85 /**
86 * For QuickTemplate, the name of the subclass which
87 * will actually fill the template.
88 */
89 var $template;
90
91 /**#@-*/
92
93 /**
94 * Setup the base parameters...
95 * Child classes should override this to set the name,
96 * style subdirectory, and template filler callback.
97 *
98 * @param OutputPage $out
99 */
100 function initPage( &$out ) {
101 parent::initPage( $out );
102 $this->skinname = 'monobook';
103 $this->stylename = 'monobook';
104 $this->template = 'QuickTemplate';
105 }
106
107 /**
108 * Create the template engine object; we feed it a bunch of data
109 * and eventually it spits out some HTML. Should have interface
110 * roughly equivalent to PHPTAL 0.7.
111 *
112 * @param string $callback (or file)
113 * @param string $repository subdirectory where we keep template files
114 * @param string $cache_dir
115 * @return object
116 * @private
117 */
118 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
119 return new $classname();
120 }
121
122 /**
123 * initialize various variables and generate the template
124 *
125 * @param OutputPage $out
126 * @public
127 */
128 function outputPage( &$out ) {
129 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
130 global $wgScript, $wgStylePath, $wgContLanguageCode;
131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
133 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
134 global $wgMaxCredits, $wgShowCreditsIfMax;
135 global $wgPageShowWatchingUsers;
136 global $wgUseTrackbacks;
137 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
138
139 $fname = 'SkinTemplate::outputPage';
140 wfProfileIn( $fname );
141
142 // Hook that allows last minute changes to the output page, e.g.
143 // adding of CSS or Javascript by extensions.
144 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
145
146 $oldid = $wgRequest->getVal( 'oldid' );
147 $diff = $wgRequest->getVal( 'diff' );
148
149 wfProfileIn( "$fname-init" );
150 $this->initPage( $out );
151
152 $this->mTitle =& $wgTitle;
153 $this->mUser =& $wgUser;
154
155 $tpl = $this->setupTemplate( $this->template, 'skins' );
156
157 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
158 $tpl->setTranslator(new MediaWiki_I18N());
159 #}
160 wfProfileOut( "$fname-init" );
161
162 wfProfileIn( "$fname-stuff" );
163 $this->thispage = $this->mTitle->getPrefixedDbKey();
164 $this->thisurl = $this->mTitle->getPrefixedURL();
165 $this->loggedin = $wgUser->isLoggedIn();
166 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
167 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
168 $this->username = $wgUser->getName();
169 $userPage = $wgUser->getUserPage();
170 $this->userpage = $userPage->getPrefixedText();
171
172 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
173 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
174 } else {
175 # This won't be used in the standard skins, but we define it to preserve the interface
176 # To save time, we check for existence
177 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
178 }
179
180 $this->usercss = $this->userjs = $this->userjsprev = false;
181 $this->setupUserCss();
182 $this->setupUserJs( $out->isUserJsAllowed() );
183 $this->titletxt = $this->mTitle->getPrefixedText();
184 wfProfileOut( "$fname-stuff" );
185
186 wfProfileIn( "$fname-stuff2" );
187 $tpl->set( 'title', $wgOut->getPageTitle() );
188 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
189 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
190 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
191
192 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
193 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
194 $this->mTitle->getNsText();
195
196 $tpl->set( 'nscanonical', $nsname );
197 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
198 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
199 $tpl->set( 'titletext', $this->mTitle->getText() );
200 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
201 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
202
203 $tpl->set( 'isarticle', $wgOut->isArticle() );
204
205 $tpl->setRef( "thispage", $this->thispage );
206 $subpagestr = $this->subPageSubtitle();
207 $tpl->set(
208 'subtitle', !empty($subpagestr)?
209 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
210 $out->getSubtitle()
211 );
212 $undelete = $this->getUndeleteLink();
213 $tpl->set(
214 "undelete", !empty($undelete)?
215 '<span class="subpages">'.$undelete.'</span>':
216 ''
217 );
218
219 $tpl->set( 'catlinks', $this->getCategories());
220 if( $wgOut->isSyndicated() ) {
221 $feeds = array();
222 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
223 $feeds[$format] = array(
224 'text' => wfMsg( "feed-$format" ),
225 'href' => $link );
226 }
227 $tpl->setRef( 'feeds', $feeds );
228 } else {
229 $tpl->set( 'feeds', false );
230 }
231 if ($wgUseTrackbacks && $out->isArticleRelated()) {
232 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
233 } else {
234 $tpl->set( 'trackbackhtml', null );
235 }
236
237 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
238 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
239 $tpl->setRef( 'mimetype', $wgMimeType );
240 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
241 $tpl->setRef( 'charset', $wgOutputEncoding );
242 $tpl->set( 'headlinks', $out->getHeadLinks() );
243 $tpl->set('headscripts', $out->getScript() );
244 $tpl->setRef( 'wgScript', $wgScript );
245 $tpl->setRef( 'skinname', $this->skinname );
246 $tpl->set( 'skinclass', get_class( $this ) );
247 $tpl->setRef( 'stylename', $this->stylename );
248 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
249 $tpl->setRef( 'loggedin', $this->loggedin );
250 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
251 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
252 /* XXX currently unused, might get useful later
253 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
254 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
255 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
256 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
257 $tpl->set( "helppage", wfMsg('helppage'));
258 */
259 $tpl->set( 'searchaction', $this->escapeSearchLink() );
260 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
261 $tpl->setRef( 'stylepath', $wgStylePath );
262 $tpl->setRef( 'articlepath', $wgArticlePath );
263 $tpl->setRef( 'scriptpath', $wgScriptPath );
264 $tpl->setRef( 'serverurl', $wgServer );
265 $tpl->setRef( 'logopath', $wgLogo );
266 $tpl->setRef( "lang", $wgContLanguageCode );
267 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
268 $tpl->set( 'rtl', $wgContLang->isRTL() );
269 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
270 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
271 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
272 $tpl->setRef( 'userpage', $this->userpage);
273 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
274 $tpl->set( 'userlang', $wgLang->getCode() );
275 $tpl->set( 'pagecss', $this->setupPageCss() );
276 $tpl->setRef( 'usercss', $this->usercss);
277 $tpl->setRef( 'userjs', $this->userjs);
278 $tpl->setRef( 'userjsprev', $this->userjsprev);
279 global $wgUseSiteJs;
280 if ($wgUseSiteJs) {
281 $jsCache = $this->loggedin ? '&smaxage=0' : '';
282 $tpl->set( 'jsvarurl',
283 self::makeUrl('-',
284 "action=raw$jsCache&gen=js&useskin=" .
285 urlencode( $this->getSkinName() ) ) );
286 } else {
287 $tpl->set('jsvarurl', false);
288 }
289 $newtalks = $wgUser->getNewMessageLinks();
290
291 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
292 $usertitle = $this->mUser->getUserPage();
293 $usertalktitle = $usertitle->getTalkPage();
294 if( !$usertalktitle->equals( $this->mTitle ) ) {
295 $ntl = wfMsg( 'youhavenewmessages',
296 $this->makeKnownLinkObj(
297 $usertalktitle,
298 wfMsgHtml( 'newmessageslink' ),
299 'redirect=no'
300 ),
301 $this->makeKnownLinkObj(
302 $usertalktitle,
303 wfMsgHtml( 'newmessagesdifflink' ),
304 'diff=cur'
305 )
306 );
307 # Disable Cache
308 $wgOut->setSquidMaxage(0);
309 }
310 } else if (count($newtalks)) {
311 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
312 $msgs = array();
313 foreach ($newtalks as $newtalk) {
314 $msgs[] = wfElement("a",
315 array('href' => $newtalk["link"]), $newtalk["wiki"]);
316 }
317 $parts = implode($sep, $msgs);
318 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
319 $wgOut->setSquidMaxage(0);
320 } else {
321 $ntl = '';
322 }
323 wfProfileOut( "$fname-stuff2" );
324
325 wfProfileIn( "$fname-stuff3" );
326 $tpl->setRef( 'newtalk', $ntl );
327 $tpl->setRef( 'skin', $this);
328 $tpl->set( 'logo', $this->logoText() );
329 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
330 $wgArticle and 0 != $wgArticle->getID() )
331 {
332 if ( !$wgDisableCounters ) {
333 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
334 if ( $viewcount ) {
335 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
336 } else {
337 $tpl->set('viewcount', false);
338 }
339 } else {
340 $tpl->set('viewcount', false);
341 }
342
343 if ($wgPageShowWatchingUsers) {
344 $dbr = wfGetDB( DB_SLAVE );
345 $watchlist = $dbr->tableName( 'watchlist' );
346 $sql = "SELECT COUNT(*) AS n FROM $watchlist
347 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
348 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
349 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
350 $x = $dbr->fetchObject( $res );
351 $numberofwatchingusers = $x->n;
352 if ($numberofwatchingusers > 0) {
353 $tpl->set('numberofwatchingusers',
354 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
355 $wgLang->formatNum($numberofwatchingusers))
356 );
357 } else {
358 $tpl->set('numberofwatchingusers', false);
359 }
360 } else {
361 $tpl->set('numberofwatchingusers', false);
362 }
363
364 $tpl->set('copyright',$this->getCopyright());
365
366 $this->credits = false;
367
368 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
369 require_once("Credits.php");
370 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
371 } else {
372 $tpl->set('lastmod', $this->lastModified());
373 }
374
375 $tpl->setRef( 'credits', $this->credits );
376
377 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
378 $tpl->set('copyright', $this->getCopyright());
379 $tpl->set('viewcount', false);
380 $tpl->set('lastmod', false);
381 $tpl->set('credits', false);
382 $tpl->set('numberofwatchingusers', false);
383 } else {
384 $tpl->set('copyright', false);
385 $tpl->set('viewcount', false);
386 $tpl->set('lastmod', false);
387 $tpl->set('credits', false);
388 $tpl->set('numberofwatchingusers', false);
389 }
390 wfProfileOut( "$fname-stuff3" );
391
392 wfProfileIn( "$fname-stuff4" );
393 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
394 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
395 $tpl->set( 'disclaimer', $this->disclaimerLink() );
396 $tpl->set( 'privacy', $this->privacyLink() );
397 $tpl->set( 'about', $this->aboutLink() );
398
399 $tpl->setRef( 'debug', $out->mDebugtext );
400 $tpl->set( 'reporttime', $out->reportTime() );
401 $tpl->set( 'sitenotice', wfGetSiteNotice() );
402 $tpl->set( 'bottomscripts', $this->bottomScripts() );
403
404 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
405 $out->mBodytext .= $printfooter ;
406 $tpl->setRef( 'bodytext', $out->mBodytext );
407
408 # Language links
409 $language_urls = array();
410
411 if ( !$wgHideInterlanguageLinks ) {
412 foreach( $wgOut->getLanguageLinks() as $l ) {
413 $tmp = explode( ':', $l, 2 );
414 $class = 'interwiki-' . $tmp[0];
415 unset($tmp);
416 $nt = Title::newFromText( $l );
417 $language_urls[] = array(
418 'href' => $nt->getFullURL(),
419 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
420 'class' => $class
421 );
422 }
423 }
424 if(count($language_urls)) {
425 $tpl->setRef( 'language_urls', $language_urls);
426 } else {
427 $tpl->set('language_urls', false);
428 }
429 wfProfileOut( "$fname-stuff4" );
430
431 # Personal toolbar
432 $tpl->set('personal_urls', $this->buildPersonalUrls());
433 $content_actions = $this->buildContentActionUrls();
434 $tpl->setRef('content_actions', $content_actions);
435
436 // XXX: attach this from javascript, same with section editing
437 if($this->iseditable && $wgUser->getOption("editondblclick") )
438 {
439 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
440 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
441 } else {
442 $tpl->set('body_ondblclick', false);
443 }
444 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
445 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
446 } else {
447 $tpl->set( 'body_onload', false );
448 }
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 // execute template
458 wfProfileIn( "$fname-execute" );
459 $res = $tpl->execute();
460 wfProfileOut( "$fname-execute" );
461
462 // result may be an error
463 $this->printOrError( $res );
464 wfProfileOut( $fname );
465 }
466
467 /**
468 * Output the string, or print error message if it's
469 * an error object of the appropriate type.
470 * For the base class, assume strings all around.
471 *
472 * @param mixed $str
473 * @private
474 */
475 function printOrError( $str ) {
476 echo $str;
477 }
478
479 /**
480 * build array of urls for personal toolbar
481 * @return array
482 * @private
483 */
484 function buildPersonalUrls() {
485 global $wgTitle, $wgRequest;
486
487 $fname = 'SkinTemplate::buildPersonalUrls';
488 $pageurl = $wgTitle->getLocalURL();
489 wfProfileIn( $fname );
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 if( $this->showIPinHeader() ) {
551 $href = &$this->userpageUrlDetails['href'];
552 $personal_urls['anonuserpage'] = array(
553 'text' => $this->username,
554 'href' => $href,
555 'class' => $this->userpageUrlDetails['exists']?false:'new',
556 'active' => ( $pageurl == $href )
557 );
558 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
559 $href = &$usertalkUrlDetails['href'];
560 $personal_urls['anontalk'] = array(
561 'text' => wfMsg('anontalk'),
562 'href' => $href,
563 'class' => $usertalkUrlDetails['exists']?false:'new',
564 'active' => ( $pageurl == $href )
565 );
566 $personal_urls['anonlogin'] = array(
567 'text' => wfMsg('userlogin'),
568 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
569 'active' => $wgTitle->isSpecial( 'Userlogin' )
570 );
571 } else {
572
573 $personal_urls['login'] = array(
574 'text' => wfMsg('userlogin'),
575 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
576 'active' => $wgTitle->isSpecial( 'Userlogin' )
577 );
578 }
579 }
580
581 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
582 wfProfileOut( $fname );
583 return $personal_urls;
584 }
585
586 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
587 $classes = array();
588 if( $selected ) {
589 $classes[] = 'selected';
590 }
591 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
592 $classes[] = 'new';
593 $query = 'action=edit';
594 }
595
596 $text = wfMsg( $message );
597 if ( wfEmptyMsg( $message, $text ) ) {
598 global $wgContLang;
599 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
600 }
601
602 $result = array();
603 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
604 $title, $message, $selected, $checkEdit,
605 &$classes, &$query, &$text, &$result)) ) {
606 return $result;
607 }
608
609 return array(
610 'class' => implode( ' ', $classes ),
611 'text' => $text,
612 'href' => $title->getLocalUrl( $query ) );
613 }
614
615 function makeTalkUrlDetails( $name, $urlaction = '' ) {
616 $title = Title::newFromText( $name );
617 if( !is_object($title) ) {
618 throw new MWException( __METHOD__." given invalid pagename $name" );
619 }
620 $title = $title->getTalkPage();
621 self::checkTitle( $title, $name );
622 return array(
623 'href' => $title->getLocalURL( $urlaction ),
624 'exists' => $title->getArticleID() != 0 ? true : false
625 );
626 }
627
628 function makeArticleUrlDetails( $name, $urlaction = '' ) {
629 $title = Title::newFromText( $name );
630 $title= $title->getSubjectPage();
631 self::checkTitle( $title, $name );
632 return array(
633 'href' => $title->getLocalURL( $urlaction ),
634 'exists' => $title->getArticleID() != 0 ? true : false
635 );
636 }
637
638 /**
639 * an array of edit links by default used for the tabs
640 * @return array
641 * @private
642 */
643 function buildContentActionUrls () {
644 global $wgContLang, $wgLang, $wgOut;
645 $fname = 'SkinTemplate::buildContentActionUrls';
646 wfProfileIn( $fname );
647
648 global $wgUser, $wgRequest;
649 $action = $wgRequest->getText( 'action' );
650 $section = $wgRequest->getText( 'section' );
651 $content_actions = array();
652
653 $prevent_active_tabs = false ;
654 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
655
656 if( $this->iscontent ) {
657 $subjpage = $this->mTitle->getSubjectPage();
658 $talkpage = $this->mTitle->getTalkPage();
659
660 $nskey = $this->mTitle->getNamespaceKey();
661 $content_actions[$nskey] = $this->tabAction(
662 $subjpage,
663 $nskey,
664 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
665 '', true);
666
667 $content_actions['talk'] = $this->tabAction(
668 $talkpage,
669 'talk',
670 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
671 '',
672 true);
673
674 wfProfileIn( "$fname-edit" );
675 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
676 $istalk = $this->mTitle->isTalkPage();
677 $istalkclass = $istalk?' istalk':'';
678 $content_actions['edit'] = array(
679 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
680 'text' => $this->mTitle->exists()
681 ? wfMsg( 'edit' )
682 : wfMsg( 'create' ),
683 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
684 );
685
686 if ( $istalk || $wgOut->showNewSectionLink() ) {
687 $content_actions['addsection'] = array(
688 'class' => $section == 'new'?'selected':false,
689 'text' => wfMsg('addsection'),
690 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
691 );
692 }
693 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
694 $content_actions['viewsource'] = array(
695 'class' => ($action == 'edit') ? 'selected' : false,
696 'text' => wfMsg('viewsource'),
697 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
698 );
699 }
700 wfProfileOut( "$fname-edit" );
701
702 wfProfileIn( "$fname-live" );
703 if ( $this->mTitle->getArticleId() ) {
704
705 $content_actions['history'] = array(
706 'class' => ($action == 'history') ? 'selected' : false,
707 'text' => wfMsg('history_short'),
708 'href' => $this->mTitle->getLocalUrl( 'action=history')
709 );
710
711 if($wgUser->isAllowed('delete')){
712 $content_actions['delete'] = array(
713 'class' => ($action == 'delete') ? 'selected' : false,
714 'text' => wfMsg('delete'),
715 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
716 );
717 }
718 if ( $this->mTitle->quickUserCan( 'move' ) ) {
719 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
720 $content_actions['move'] = array(
721 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
722 'text' => wfMsg('move'),
723 'href' => $moveTitle->getLocalUrl()
724 );
725 }
726
727 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
728 if(!$this->mTitle->isProtected()){
729 $content_actions['protect'] = array(
730 'class' => ($action == 'protect') ? 'selected' : false,
731 'text' => wfMsg('protect'),
732 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
733 );
734
735 } else {
736 $content_actions['unprotect'] = array(
737 'class' => ($action == 'unprotect') ? 'selected' : false,
738 'text' => wfMsg('unprotect'),
739 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
740 );
741 }
742 }
743 } else {
744 //article doesn't exist or is deleted
745 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
746 if( $n = $this->mTitle->isDeleted() ) {
747 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
748 $content_actions['undelete'] = array(
749 'class' => false,
750 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
751 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
752 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
753 );
754 }
755 }
756
757 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
758 if( !$this->mTitle->getRestrictions( 'create' ) ) {
759 $content_actions['protect'] = array(
760 'class' => ($action == 'protect') ? 'selected' : false,
761 'text' => wfMsg('protect'),
762 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
763 );
764
765 } else {
766 $content_actions['unprotect'] = array(
767 'class' => ($action == 'unprotect') ? 'selected' : false,
768 'text' => wfMsg('unprotect'),
769 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
770 );
771 }
772 }
773 }
774
775 wfProfileOut( "$fname-live" );
776
777 if( $this->loggedin ) {
778 if( !$this->mTitle->userIsWatching()) {
779 $content_actions['watch'] = array(
780 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
781 'text' => wfMsg('watch'),
782 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
783 );
784 } else {
785 $content_actions['unwatch'] = array(
786 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
787 'text' => wfMsg('unwatch'),
788 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
789 );
790 }
791 }
792
793
794 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
795 } else {
796 /* show special page tab */
797
798 $content_actions[$this->mTitle->getNamespaceKey()] = array(
799 'class' => 'selected',
800 'text' => wfMsg('nstab-special'),
801 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
802 );
803
804 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
805 }
806
807 /* show links to different language variants */
808 global $wgDisableLangConversion;
809 $variants = $wgContLang->getVariants();
810 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
811 $preferred = $wgContLang->getPreferredVariant();
812 $vcount=0;
813 foreach( $variants as $code ) {
814 $varname = $wgContLang->getVariantname( $code );
815 if( $varname == 'disable' )
816 continue;
817 $selected = ( $code == $preferred )? 'selected' : false;
818 $content_actions['varlang-' . $vcount] = array(
819 'class' => $selected,
820 'text' => $varname,
821 'href' => $this->mTitle->getLocalURL('',$code)
822 );
823 $vcount ++;
824 }
825 }
826
827 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
828
829 wfProfileOut( $fname );
830 return $content_actions;
831 }
832
833
834
835 /**
836 * build array of common navigation links
837 * @return array
838 * @private
839 */
840 function buildNavUrls () {
841 global $wgUseTrackbacks, $wgTitle, $wgArticle;
842
843 $fname = 'SkinTemplate::buildNavUrls';
844 wfProfileIn( $fname );
845
846 global $wgUser, $wgRequest;
847 global $wgEnableUploads, $wgUploadNavigationUrl;
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( $fname );
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 $fname = 'SkinTemplate::setupUserCss';
967 wfProfileIn( $fname );
968
969 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
970
971 $sitecss = '';
972 $usercss = '';
973 $siteargs = '&maxage=' . $wgSquidMaxage;
974 if( $this->loggedin ) {
975 // Ensure that logged-in users' generated CSS isn't clobbered
976 // by anons' publicly cacheable generated CSS.
977 $siteargs .= '&smaxage=0';
978 }
979
980 # Add user-specific code if this is a user and we allow that kind of thing
981
982 if ( $wgAllowUserCss && $this->loggedin ) {
983 $action = $wgRequest->getText('action');
984
985 # if we're previewing the CSS page, use it
986 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
987 $siteargs = "&smaxage=0&maxage=0";
988 $usercss = $wgRequest->getText('wpTextbox1');
989 } else {
990 $usercss = '@import "' .
991 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
992 'action=raw&ctype=text/css') . '";' ."\n";
993 }
994
995 $siteargs .= '&ts=' . $wgUser->mTouched;
996 }
997
998 if( $wgContLang->isRTL() ) {
999 global $wgStyleVersion;
1000 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
1001 }
1002
1003 # If we use the site's dynamic CSS, throw that in, too
1004 if ( $wgUseSiteCss ) {
1005 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
1006 $skinquery = '';
1007 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1008 $skinquery = "&useskin=$us";
1009 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
1010 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
1011 $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1012 }
1013
1014 # If we use any dynamic CSS, make a little CDATA block out of it.
1015
1016 if ( !empty($sitecss) || !empty($usercss) ) {
1017 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1018 }
1019 wfProfileOut( $fname );
1020 }
1021
1022 /**
1023 * @private
1024 */
1025 function setupUserJs( $allowUserJs ) {
1026 $fname = 'SkinTemplate::setupUserJs';
1027 wfProfileIn( $fname );
1028
1029 global $wgRequest, $wgJsMimeType;
1030 $action = $wgRequest->getText('action');
1031
1032 if( $allowUserJs && $this->loggedin ) {
1033 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1034 # XXX: additional security check/prompt?
1035 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1036 } else {
1037 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1038 }
1039 }
1040 wfProfileOut( $fname );
1041 }
1042
1043 /**
1044 * Code for extensions to hook into to provide per-page CSS, see
1045 * extensions/PageCSS/PageCSS.php for an implementation of this.
1046 *
1047 * @private
1048 */
1049 function setupPageCss() {
1050 $fname = 'SkinTemplate::setupPageCss';
1051 wfProfileIn( $fname );
1052 $out = false;
1053 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1054
1055 wfProfileOut( $fname );
1056 return $out;
1057 }
1058
1059 /**
1060 * returns css with user-specific options
1061 * @public
1062 */
1063
1064 function getUserStylesheet() {
1065 $fname = 'SkinTemplate::getUserStylesheet';
1066 wfProfileIn( $fname );
1067
1068 $s = "/* generated user stylesheet */\n";
1069 $s .= $this->reallyDoGetUserStyles();
1070 wfProfileOut( $fname );
1071 return $s;
1072 }
1073
1074 /**
1075 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1076 * nated together. For some bizarre reason, it does *not* return any
1077 * custom user JS from subpages. Huh?
1078 *
1079 * There's absolutely no reason to have separate Monobook/Common JSes.
1080 * Any JS that cares can just check the skin variable generated at the
1081 * top. For now Monobook.js will be maintained, but it should be consi-
1082 * dered deprecated.
1083 *
1084 * @return string
1085 */
1086 public function getUserJs() {
1087 $fname = 'SkinTemplate::getUserJs';
1088 wfProfileIn( $fname );
1089
1090 $s = parent::getUserJs();
1091 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1092
1093 // avoid inclusion of non defined user JavaScript (with custom skins only)
1094 // by checking for default message content
1095 $msgKey = ucfirst($this->skinname).'.js';
1096 $userJS = wfMsgForContent($msgKey);
1097 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1098 $s .= $userJS;
1099 }
1100
1101 wfProfileOut( $fname );
1102 return $s;
1103 }
1104 }
1105
1106 /**
1107 * Generic wrapper for template functions, with interface
1108 * compatible with what we use of PHPTAL 0.7.
1109 * @addtogroup Skins
1110 */
1111 class QuickTemplate {
1112 /**
1113 * @public
1114 */
1115 function QuickTemplate() {
1116 $this->data = array();
1117 $this->translator = new MediaWiki_I18N();
1118 }
1119
1120 /**
1121 * @public
1122 */
1123 function set( $name, $value ) {
1124 $this->data[$name] = $value;
1125 }
1126
1127 /**
1128 * @public
1129 */
1130 function setRef($name, &$value) {
1131 $this->data[$name] =& $value;
1132 }
1133
1134 /**
1135 * @public
1136 */
1137 function setTranslator( &$t ) {
1138 $this->translator = &$t;
1139 }
1140
1141 /**
1142 * @public
1143 */
1144 function execute() {
1145 echo "Override this function.";
1146 }
1147
1148
1149 /**
1150 * @private
1151 */
1152 function text( $str ) {
1153 echo htmlspecialchars( $this->data[$str] );
1154 }
1155
1156 /**
1157 * @private
1158 */
1159 function jstext( $str ) {
1160 echo Xml::escapeJsString( $this->data[$str] );
1161 }
1162
1163 /**
1164 * @private
1165 */
1166 function html( $str ) {
1167 echo $this->data[$str];
1168 }
1169
1170 /**
1171 * @private
1172 */
1173 function msg( $str ) {
1174 echo htmlspecialchars( $this->translator->translate( $str ) );
1175 }
1176
1177 /**
1178 * @private
1179 */
1180 function msgHtml( $str ) {
1181 echo $this->translator->translate( $str );
1182 }
1183
1184 /**
1185 * An ugly, ugly hack.
1186 * @private
1187 */
1188 function msgWiki( $str ) {
1189 global $wgParser, $wgTitle, $wgOut;
1190
1191 $text = $this->translator->translate( $str );
1192 $parserOutput = $wgParser->parse( $text, $wgTitle,
1193 $wgOut->parserOptions(), true );
1194 echo $parserOutput->getText();
1195 }
1196
1197 /**
1198 * @private
1199 */
1200 function haveData( $str ) {
1201 return isset( $this->data[$str] );
1202 }
1203
1204 /**
1205 * @private
1206 */
1207 function haveMsg( $str ) {
1208 $msg = $this->translator->translate( $str );
1209 return ($msg != '-') && ($msg != ''); # ????
1210 }
1211 }
1212
1213
1214
1215