Fix when nothing is passed to listToText (eg: no author)
[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 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
25 *
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
29 *
30 * @package MediaWiki
31 * @subpackage Skins
32 */
33
34 /**
35 * Wrapper object for MediaWiki's localization functions,
36 * to be passed to the template engine.
37 *
38 * @private
39 * @package MediaWiki
40 */
41 class MediaWiki_I18N {
42 var $_context = array();
43
44 function set($varName, $value) {
45 $this->_context[$varName] = $value;
46 }
47
48 function translate($value) {
49 $fname = 'SkinTemplate-translate';
50 wfProfileIn( $fname );
51
52 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
53 $value = preg_replace( '/^string:/', '', $value );
54
55 $value = wfMsg( $value );
56 // interpolate variables
57 $m = array();
58 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
59 list($src, $var) = $m;
60 wfSuppressWarnings();
61 $varValue = $this->_context[$var];
62 wfRestoreWarnings();
63 $value = str_replace($src, $varValue, $value);
64 }
65 wfProfileOut( $fname );
66 return $value;
67 }
68 }
69
70 /**
71 *
72 * @package MediaWiki
73 */
74 class SkinTemplate extends Skin {
75 /**#@+
76 * @private
77 */
78
79 /**
80 * Name of our skin, set in initPage()
81 * It probably need to be all lower case.
82 */
83 var $skinname;
84
85 /**
86 * Stylesheets set to use
87 * Sub directory in ./skins/ where various stylesheets are located
88 */
89 var $stylename;
90
91 /**
92 * For QuickTemplate, the name of the subclass which
93 * will actually fill the template.
94 */
95 var $template;
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
113 /**
114 * Create the template engine object; we feed it a bunch of data
115 * and eventually it spits out some HTML. Should have interface
116 * roughly equivalent to PHPTAL 0.7.
117 *
118 * @param string $callback (or file)
119 * @param string $repository subdirectory where we keep template files
120 * @param string $cache_dir
121 * @return object
122 * @private
123 */
124 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
125 return new $classname();
126 }
127
128 /**
129 * initialize various variables and generate the template
130 *
131 * @param OutputPage $out
132 * @public
133 */
134 function outputPage( &$out ) {
135 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
139 global $wgMaxCredits, $wgShowCreditsIfMax;
140 global $wgPageShowWatchingUsers;
141 global $wgUseTrackbacks;
142 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
143
144 $fname = 'SkinTemplate::outputPage';
145 wfProfileIn( $fname );
146
147 // Hook that allows last minute changes to the output page, e.g.
148 // adding of CSS or Javascript by extensions.
149 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
150
151 $oldid = $wgRequest->getVal( 'oldid' );
152 $diff = $wgRequest->getVal( 'diff' );
153
154 wfProfileIn( "$fname-init" );
155 $this->initPage( $out );
156
157 $this->mTitle =& $wgTitle;
158 $this->mUser =& $wgUser;
159
160 $tpl = $this->setupTemplate( $this->template, 'skins' );
161
162 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
163 $tpl->setTranslator(new MediaWiki_I18N());
164 #}
165 wfProfileOut( "$fname-init" );
166
167 wfProfileIn( "$fname-stuff" );
168 $this->thispage = $this->mTitle->getPrefixedDbKey();
169 $this->thisurl = $this->mTitle->getPrefixedURL();
170 $this->loggedin = $wgUser->isLoggedIn();
171 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
172 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
173 $this->username = $wgUser->getName();
174 $userPage = $wgUser->getUserPage();
175 $this->userpage = $userPage->getPrefixedText();
176
177 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
178 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
179 } else {
180 # This won't be used in the standard skins, but we define it to preserve the interface
181 # To save time, we check for existence
182 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
183 }
184
185 $this->usercss = $this->userjs = $this->userjsprev = false;
186 $this->setupUserCss();
187 $this->setupUserJs();
188 $this->titletxt = $this->mTitle->getPrefixedText();
189 wfProfileOut( "$fname-stuff" );
190
191 wfProfileIn( "$fname-stuff2" );
192 $tpl->set( 'title', $wgOut->getPageTitle() );
193 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
194 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
195 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
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( $wgFeedClasses as $format => $class ) {
228 $linktext = $format;
229 if ( $format == "atom" ) {
230 $linktext = wfMsg( 'feed-atom' );
231 } else if ( $format == "rss" ) {
232 $linktext = wfMsg( 'feed-rss' );
233 }
234 $feeds[$format] = array(
235 'text' => $linktext,
236 'href' => $wgRequest->appendQuery( "feed=$format" )
237 );
238 }
239 $tpl->setRef( 'feeds', $feeds );
240 } else {
241 $tpl->set( 'feeds', false );
242 }
243 if ($wgUseTrackbacks && $out->isArticleRelated()) {
244 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
245 } else {
246 $tpl->set( 'trackbackhtml', null );
247 }
248
249 $tpl->setRef( 'mimetype', $wgMimeType );
250 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
251 $tpl->setRef( 'charset', $wgOutputEncoding );
252 $tpl->set( 'headlinks', $out->getHeadLinks() );
253 $tpl->set('headscripts', $out->getScript() );
254 $tpl->setRef( 'wgScript', $wgScript );
255 $tpl->setRef( 'skinname', $this->skinname );
256 $tpl->set( 'skinclass', get_class( $this ) );
257 $tpl->setRef( 'stylename', $this->stylename );
258 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
259 $tpl->setRef( 'loggedin', $this->loggedin );
260 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
261 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
262 /* XXX currently unused, might get useful later
263 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
264 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
265 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
266 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
267 $tpl->set( "helppage", wfMsg('helppage'));
268 */
269 $tpl->set( 'searchaction', $this->escapeSearchLink() );
270 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
271 $tpl->setRef( 'stylepath', $wgStylePath );
272 $tpl->setRef( 'articlepath', $wgArticlePath );
273 $tpl->setRef( 'scriptpath', $wgScriptPath );
274 $tpl->setRef( 'serverurl', $wgServer );
275 $tpl->setRef( 'logopath', $wgLogo );
276 $tpl->setRef( "lang", $wgContLanguageCode );
277 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
278 $tpl->set( 'rtl', $wgContLang->isRTL() );
279 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
280 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
281 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
282 $tpl->setRef( 'userpage', $this->userpage);
283 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
284 $tpl->set( 'userlang', $wgLang->getCode() );
285 $tpl->set( 'pagecss', $this->setupPageCss() );
286 $tpl->setRef( 'usercss', $this->usercss);
287 $tpl->setRef( 'userjs', $this->userjs);
288 $tpl->setRef( 'userjsprev', $this->userjsprev);
289 global $wgUseSiteJs;
290 if ($wgUseSiteJs) {
291 if($this->loggedin) {
292 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&smaxage=0&gen=js') );
293 } else {
294 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&gen=js') );
295 }
296 } else {
297 $tpl->set('jsvarurl', false);
298 }
299 $newtalks = $wgUser->getNewMessageLinks();
300
301 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
302 $usertitle = $this->mUser->getUserPage();
303 $usertalktitle = $usertitle->getTalkPage();
304 if( !$usertalktitle->equals( $this->mTitle ) ) {
305 $ntl = wfMsg( 'youhavenewmessages',
306 $this->makeKnownLinkObj(
307 $usertalktitle,
308 wfMsgHtml( 'newmessageslink' ),
309 'redirect=no'
310 ),
311 $this->makeKnownLinkObj(
312 $usertalktitle,
313 wfMsgHtml( 'newmessagesdifflink' ),
314 'diff=cur'
315 )
316 );
317 # Disable Cache
318 $wgOut->setSquidMaxage(0);
319 }
320 } else if (count($newtalks)) {
321 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
322 $msgs = array();
323 foreach ($newtalks as $newtalk) {
324 $msgs[] = wfElement("a",
325 array('href' => $newtalk["link"]), $newtalk["wiki"]);
326 }
327 $parts = implode($sep, $msgs);
328 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
329 $wgOut->setSquidMaxage(0);
330 } else {
331 $ntl = '';
332 }
333 wfProfileOut( "$fname-stuff2" );
334
335 wfProfileIn( "$fname-stuff3" );
336 $tpl->setRef( 'newtalk', $ntl );
337 $tpl->setRef( 'skin', $this);
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
340 $wgArticle and 0 != $wgArticle->getID() )
341 {
342 if ( !$wgDisableCounters ) {
343 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
344 if ( $viewcount ) {
345 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
346 } else {
347 $tpl->set('viewcount', false);
348 }
349 } else {
350 $tpl->set('viewcount', false);
351 }
352
353 if ($wgPageShowWatchingUsers) {
354 $dbr =& wfGetDB( DB_SLAVE );
355 $watchlist = $dbr->tableName( 'watchlist' );
356 $sql = "SELECT COUNT(*) AS n FROM $watchlist
357 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
358 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
359 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n;
362 if ($numberofwatchingusers > 0) {
363 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
364 } else {
365 $tpl->set('numberofwatchingusers', false);
366 }
367 } else {
368 $tpl->set('numberofwatchingusers', false);
369 }
370
371 $tpl->set('copyright',$this->getCopyright());
372
373 $this->credits = false;
374
375 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
376 require_once("Credits.php");
377 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
378 } else {
379 $tpl->set('lastmod', $this->lastModified());
380 }
381
382 $tpl->setRef( 'credits', $this->credits );
383
384 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
385 $tpl->set('copyright', $this->getCopyright());
386 $tpl->set('viewcount', false);
387 $tpl->set('lastmod', false);
388 $tpl->set('credits', false);
389 $tpl->set('numberofwatchingusers', false);
390 } else {
391 $tpl->set('copyright', false);
392 $tpl->set('viewcount', false);
393 $tpl->set('lastmod', false);
394 $tpl->set('credits', false);
395 $tpl->set('numberofwatchingusers', false);
396 }
397 wfProfileOut( "$fname-stuff3" );
398
399 wfProfileIn( "$fname-stuff4" );
400 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
401 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
402 $tpl->set( 'disclaimer', $this->disclaimerLink() );
403 $tpl->set( 'privacy', $this->privacyLink() );
404 $tpl->set( 'about', $this->aboutLink() );
405
406 $tpl->setRef( 'debug', $out->mDebugtext );
407 $tpl->set( 'reporttime', $out->reportTime() );
408 $tpl->set( 'sitenotice', wfGetSiteNotice() );
409 $tpl->set( 'bottomscripts', $this->bottomScripts() );
410
411 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
412 $out->mBodytext .= $printfooter ;
413 $tpl->setRef( 'bodytext', $out->mBodytext );
414
415 # Language links
416 $language_urls = array();
417
418 if ( !$wgHideInterlanguageLinks ) {
419 foreach( $wgOut->getLanguageLinks() as $l ) {
420 $tmp = explode( ':', $l, 2 );
421 $class = 'interwiki-' . $tmp[0];
422 unset($tmp);
423 $nt = Title::newFromText( $l );
424 $language_urls[] = array(
425 'href' => $nt->getFullURL(),
426 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
427 'class' => $class
428 );
429 }
430 }
431 if(count($language_urls)) {
432 $tpl->setRef( 'language_urls', $language_urls);
433 } else {
434 $tpl->set('language_urls', false);
435 }
436 wfProfileOut( "$fname-stuff4" );
437
438 # Personal toolbar
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
442
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable && $wgUser->getOption("editondblclick") )
445 {
446 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
447 } else {
448 $tpl->set('body_ondblclick', false);
449 }
450 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
451 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
452 } else {
453 $tpl->set( 'body_onload', false );
454 }
455 $tpl->set( 'sidebar', $this->buildSidebar() );
456 $tpl->set( 'nav_urls', $this->buildNavUrls() );
457
458 // execute template
459 wfProfileIn( "$fname-execute" );
460 $res = $tpl->execute();
461 wfProfileOut( "$fname-execute" );
462
463 // result may be an error
464 $this->printOrError( $res );
465 wfProfileOut( $fname );
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, $wgShowIPinHeader;
487
488 $fname = 'SkinTemplate::buildPersonalUrls';
489 $pageurl = $wgTitle->getLocalURL();
490 wfProfileIn( $fname );
491
492 /* set up the default links for the personal toolbar */
493 $personal_urls = array();
494 if ($this->loggedin) {
495 $personal_urls['userpage'] = array(
496 'text' => $this->username,
497 'href' => &$this->userpageUrlDetails['href'],
498 'class' => $this->userpageUrlDetails['exists']?false:'new',
499 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
500 );
501 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
502 $personal_urls['mytalk'] = array(
503 'text' => wfMsg('mytalk'),
504 'href' => &$usertalkUrlDetails['href'],
505 'class' => $usertalkUrlDetails['exists']?false:'new',
506 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
507 );
508 $href = self::makeSpecialUrl( 'Preferences' );
509 $personal_urls['preferences'] = array(
510 'text' => wfMsg( 'mypreferences' ),
511 'href' => self::makeSpecialUrl( 'Preferences' ),
512 'active' => ( $href == $pageurl )
513 );
514 $href = self::makeSpecialUrl( 'Watchlist' );
515 $personal_urls['watchlist'] = array(
516 'text' => wfMsg( 'watchlist' ),
517 'href' => $href,
518 'active' => ( $href == $pageurl )
519 );
520 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
521 $personal_urls['mycontris'] = array(
522 'text' => wfMsg( 'mycontris' ),
523 'href' => $href,
524 // FIXME # 'active' was disabed in r11346 with message: "disable bold link to my contributions; link was bold on all
525 // Special:Contributions, not just current user's (fix me please!)". Until resolved, explicitly setting active to false.
526 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
527 );
528 $personal_urls['logout'] = array(
529 'text' => wfMsg( 'userlogout' ),
530 'href' => self::makeSpecialUrl( 'Userlogout',
531 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
532 ),
533 'active' => false
534 );
535 } else {
536 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
537 $href = &$this->userpageUrlDetails['href'];
538 $personal_urls['anonuserpage'] = array(
539 'text' => $this->username,
540 'href' => $href,
541 'class' => $this->userpageUrlDetails['exists']?false:'new',
542 'active' => ( $pageurl == $href )
543 );
544 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
545 $href = &$usertalkUrlDetails['href'];
546 $personal_urls['anontalk'] = array(
547 'text' => wfMsg('anontalk'),
548 'href' => $href,
549 'class' => $usertalkUrlDetails['exists']?false:'new',
550 'active' => ( $pageurl == $href )
551 );
552 $personal_urls['anonlogin'] = array(
553 'text' => wfMsg('userlogin'),
554 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
555 'active' => $wgTitle->isSpecial( 'Userlogin' )
556 );
557 } else {
558
559 $personal_urls['login'] = array(
560 'text' => wfMsg('userlogin'),
561 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
562 'active' => $wgTitle->isSpecial( 'Userlogin' )
563 );
564 }
565 }
566
567 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
568 wfProfileOut( $fname );
569 return $personal_urls;
570 }
571
572 /**
573 * Returns true if the IP should be shown in the header
574 */
575 function showIPinHeader() {
576 global $wgShowIPinHeader;
577 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
578 }
579
580 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
581 $classes = array();
582 if( $selected ) {
583 $classes[] = 'selected';
584 }
585 if( $checkEdit && $title->getArticleId() == 0 ) {
586 $classes[] = 'new';
587 $query = 'action=edit';
588 }
589
590 $text = wfMsg( $message );
591 if ( wfEmptyMsg( $message, $text ) ) {
592 global $wgContLang;
593 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
594 }
595
596 return array(
597 'class' => implode( ' ', $classes ),
598 'text' => $text,
599 'href' => $title->getLocalUrl( $query ) );
600 }
601
602 function makeTalkUrlDetails( $name, $urlaction = '' ) {
603 $title = Title::newFromText( $name );
604 $title = $title->getTalkPage();
605 self::checkTitle( $title, $name );
606 return array(
607 'href' => $title->getLocalURL( $urlaction ),
608 'exists' => $title->getArticleID() != 0 ? true : false
609 );
610 }
611
612 function makeArticleUrlDetails( $name, $urlaction = '' ) {
613 $title = Title::newFromText( $name );
614 $title= $title->getSubjectPage();
615 self::checkTitle( $title, $name );
616 return array(
617 'href' => $title->getLocalURL( $urlaction ),
618 'exists' => $title->getArticleID() != 0 ? true : false
619 );
620 }
621
622 /**
623 * an array of edit links by default used for the tabs
624 * @return array
625 * @private
626 */
627 function buildContentActionUrls () {
628 global $wgContLang, $wgOut;
629 $fname = 'SkinTemplate::buildContentActionUrls';
630 wfProfileIn( $fname );
631
632 global $wgUser, $wgRequest;
633 $action = $wgRequest->getText( 'action' );
634 $section = $wgRequest->getText( 'section' );
635 $content_actions = array();
636
637 $prevent_active_tabs = false ;
638 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
639
640 if( $this->iscontent ) {
641 $subjpage = $this->mTitle->getSubjectPage();
642 $talkpage = $this->mTitle->getTalkPage();
643
644 $nskey = $this->mTitle->getNamespaceKey();
645 $content_actions[$nskey] = $this->tabAction(
646 $subjpage,
647 $nskey,
648 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
649 '', true);
650
651 $content_actions['talk'] = $this->tabAction(
652 $talkpage,
653 'talk',
654 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
655 '',
656 true);
657
658 wfProfileIn( "$fname-edit" );
659 if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {
660 $istalk = $this->mTitle->isTalkPage();
661 $istalkclass = $istalk?' istalk':'';
662 $content_actions['edit'] = array(
663 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
664 'text' => wfMsg('edit'),
665 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
666 );
667
668 if ( $istalk || $wgOut->showNewSectionLink() ) {
669 $content_actions['addsection'] = array(
670 'class' => $section == 'new'?'selected':false,
671 'text' => wfMsg('addsection'),
672 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
673 );
674 }
675 } else {
676 $content_actions['viewsource'] = array(
677 'class' => ($action == 'edit') ? 'selected' : false,
678 'text' => wfMsg('viewsource'),
679 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
680 );
681 }
682 wfProfileOut( "$fname-edit" );
683
684 wfProfileIn( "$fname-live" );
685 if ( $this->mTitle->getArticleId() ) {
686
687 $content_actions['history'] = array(
688 'class' => ($action == 'history') ? 'selected' : false,
689 'text' => wfMsg('history_short'),
690 'href' => $this->mTitle->getLocalUrl( 'action=history')
691 );
692
693 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
694 if(!$this->mTitle->isProtected()){
695 $content_actions['protect'] = array(
696 'class' => ($action == 'protect') ? 'selected' : false,
697 'text' => wfMsg('protect'),
698 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
699 );
700
701 } else {
702 $content_actions['unprotect'] = array(
703 'class' => ($action == 'unprotect') ? 'selected' : false,
704 'text' => wfMsg('unprotect'),
705 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
706 );
707 }
708 }
709 if($wgUser->isAllowed('delete')){
710 $content_actions['delete'] = array(
711 'class' => ($action == 'delete') ? 'selected' : false,
712 'text' => wfMsg('delete'),
713 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
714 );
715 }
716 if ( $this->mTitle->userCanMove()) {
717 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
718 $content_actions['move'] = array(
719 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
720 'text' => wfMsg('move'),
721 'href' => $moveTitle->getLocalUrl()
722 );
723 }
724 } else {
725 //article doesn't exist or is deleted
726 if( $wgUser->isAllowed( 'delete' ) ) {
727 if( $n = $this->mTitle->isDeleted() ) {
728 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
729 $content_actions['undelete'] = array(
730 'class' => false,
731 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
732 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
733 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
734 );
735 }
736 }
737 }
738 wfProfileOut( "$fname-live" );
739
740 if( $this->loggedin ) {
741 if( !$this->mTitle->userIsWatching()) {
742 $content_actions['watch'] = array(
743 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
744 'text' => wfMsg('watch'),
745 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
746 );
747 } else {
748 $content_actions['unwatch'] = array(
749 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
750 'text' => wfMsg('unwatch'),
751 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
752 );
753 }
754 }
755
756 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
757 } else {
758 /* show special page tab */
759
760 $content_actions[$this->mTitle->getNamespaceKey()] = array(
761 'class' => 'selected',
762 'text' => wfMsg('specialpage'),
763 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
764 );
765
766 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
767 }
768
769 /* show links to different language variants */
770 global $wgDisableLangConversion;
771 $variants = $wgContLang->getVariants();
772 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
773 $preferred = $wgContLang->getPreferredVariant();
774 $vcount=0;
775 foreach( $variants as $code ) {
776 $varname = $wgContLang->getVariantname( $code );
777 if( $varname == 'disable' )
778 continue;
779 $selected = ( $code == $preferred )? 'selected' : false;
780 $content_actions['varlang-' . $vcount] = array(
781 'class' => $selected,
782 'text' => $varname,
783 'href' => $this->mTitle->getLocalURL('',$code)
784 );
785 $vcount ++;
786 }
787 }
788
789 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
790
791 wfProfileOut( $fname );
792 return $content_actions;
793 }
794
795
796
797 /**
798 * build array of common navigation links
799 * @return array
800 * @private
801 */
802 function buildNavUrls () {
803 global $wgUseTrackbacks, $wgTitle, $wgArticle;
804
805 $fname = 'SkinTemplate::buildNavUrls';
806 wfProfileIn( $fname );
807
808 global $wgUser, $wgRequest;
809 global $wgEnableUploads, $wgUploadNavigationUrl;
810
811 $action = $wgRequest->getText( 'action' );
812 $oldid = $wgRequest->getVal( 'oldid' );
813
814 $nav_urls = array();
815 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
816 if( $wgEnableUploads ) {
817 if ($wgUploadNavigationUrl) {
818 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
819 } else {
820 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
821 }
822 } else {
823 if ($wgUploadNavigationUrl)
824 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
825 else
826 $nav_urls['upload'] = false;
827 }
828 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
829
830 // default permalink to being off, will override it as required below.
831 $nav_urls['permalink'] = false;
832
833 // A print stylesheet is attached to all pages, but nobody ever
834 // figures that out. :) Add a link...
835 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
836 $revid = $wgArticle ? $wgArticle->getLatest() : 0;
837 if ( !( $revid == 0 ) )
838 $nav_urls['print'] = array(
839 'text' => wfMsg( 'printableversion' ),
840 'href' => $wgRequest->appendQuery( 'printable=yes' )
841 );
842
843 // Also add a "permalink" while we're at it
844 if ( (int)$oldid ) {
845 $nav_urls['permalink'] = array(
846 'text' => wfMsg( 'permalink' ),
847 'href' => ''
848 );
849 } else {
850 if ( !( $revid == 0 ) )
851 $nav_urls['permalink'] = array(
852 'text' => wfMsg( 'permalink' ),
853 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
854 );
855 }
856
857 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
858 }
859
860 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
861 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
862 $nav_urls['whatlinkshere'] = array(
863 'href' => $wlhTitle->getLocalUrl()
864 );
865 if( $this->mTitle->getArticleId() ) {
866 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
867 $nav_urls['recentchangeslinked'] = array(
868 'href' => $rclTitle->getLocalUrl()
869 );
870 } else {
871 $nav_urls['recentchangeslinked'] = false;
872 }
873 if ($wgUseTrackbacks)
874 $nav_urls['trackbacklink'] = array(
875 'href' => $wgTitle->trackbackURL()
876 );
877 }
878
879 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
880 $id = User::idFromName($this->mTitle->getText());
881 $ip = User::isIP($this->mTitle->getText());
882 } else {
883 $id = 0;
884 $ip = false;
885 }
886
887 if($id || $ip) { # both anons and non-anons have contri list
888 $nav_urls['contributions'] = array(
889 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
890 );
891 if ( $wgUser->isAllowed( 'block' ) ) {
892 $nav_urls['blockip'] = array(
893 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
894 );
895 } else {
896 $nav_urls['blockip'] = false;
897 }
898 } else {
899 $nav_urls['contributions'] = false;
900 $nav_urls['blockip'] = false;
901 }
902 $nav_urls['emailuser'] = false;
903 if( $this->showEmailUser( $id ) ) {
904 $nav_urls['emailuser'] = array(
905 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
906 );
907 }
908 wfProfileOut( $fname );
909 return $nav_urls;
910 }
911
912 /**
913 * Generate strings used for xml 'id' names
914 * @return string
915 * @private
916 */
917 function getNameSpaceKey () {
918 return $this->mTitle->getNamespaceKey();
919 }
920
921 /**
922 * @private
923 */
924 function setupUserCss() {
925 $fname = 'SkinTemplate::setupUserCss';
926 wfProfileIn( $fname );
927
928 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
929
930 $sitecss = '';
931 $usercss = '';
932 $siteargs = '&maxage=' . $wgSquidMaxage;
933 if( $this->loggedin ) {
934 // Ensure that logged-in users' generated CSS isn't clobbered
935 // by anons' publicly cacheable generated CSS.
936 $siteargs .= '&smaxage=0';
937 }
938
939 # Add user-specific code if this is a user and we allow that kind of thing
940
941 if ( $wgAllowUserCss && $this->loggedin ) {
942 $action = $wgRequest->getText('action');
943
944 # if we're previewing the CSS page, use it
945 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
946 $siteargs = "&smaxage=0&maxage=0";
947 $usercss = $wgRequest->getText('wpTextbox1');
948 } else {
949 $usercss = '@import "' .
950 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
951 'action=raw&ctype=text/css') . '";' ."\n";
952 }
953
954 $siteargs .= '&ts=' . $wgUser->mTouched;
955 }
956
957 if( $wgContLang->isRTL() ) {
958 global $wgStyleVersion;
959 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
960 }
961
962 # If we use the site's dynamic CSS, throw that in, too
963 if ( $wgUseSiteCss ) {
964 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
965 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
966 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
967 $sitecss .= '@import "' . self::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
968 }
969
970 # If we use any dynamic CSS, make a little CDATA block out of it.
971
972 if ( !empty($sitecss) || !empty($usercss) ) {
973 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
974 }
975 wfProfileOut( $fname );
976 }
977
978 /**
979 * @private
980 */
981 function setupUserJs() {
982 $fname = 'SkinTemplate::setupUserJs';
983 wfProfileIn( $fname );
984
985 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
986 $action = $wgRequest->getText('action');
987
988 if( $wgAllowUserJs && $this->loggedin ) {
989 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
990 # XXX: additional security check/prompt?
991 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
992 } else {
993 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
994 }
995 }
996 wfProfileOut( $fname );
997 }
998
999 /**
1000 * Code for extensions to hook into to provide per-page CSS, see
1001 * extensions/PageCSS/PageCSS.php for an implementation of this.
1002 *
1003 * @private
1004 */
1005 function setupPageCss() {
1006 $fname = 'SkinTemplate::setupPageCss';
1007 wfProfileIn( $fname );
1008 $out = false;
1009 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1010
1011 wfProfileOut( $fname );
1012 return $out;
1013 }
1014
1015 /**
1016 * returns css with user-specific options
1017 * @public
1018 */
1019
1020 function getUserStylesheet() {
1021 $fname = 'SkinTemplate::getUserStylesheet';
1022 wfProfileIn( $fname );
1023
1024 $s = "/* generated user stylesheet */\n";
1025 $s .= $this->reallyDoGetUserStyles();
1026 wfProfileOut( $fname );
1027 return $s;
1028 }
1029
1030 /**
1031 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1032 * nated together. For some bizarre reason, it does *not* return any
1033 * custom user JS from subpages. Huh?
1034 *
1035 * There's absolutely no reason to have separate Monobook/Common JSes.
1036 * Any JS that cares can just check the skin variable generated at the
1037 * top. For now Monobook.js will be maintained, but it should be consi-
1038 * dered deprecated.
1039 *
1040 * @return string
1041 */
1042 public function getUserJs() {
1043 $fname = 'SkinTemplate::getUserJs';
1044 wfProfileIn( $fname );
1045
1046 $s = parent::getUserJs();
1047 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1048
1049 // avoid inclusion of non defined user JavaScript (with custom skins only)
1050 // by checking for default message content
1051 $msgKey = ucfirst($this->skinname).'.js';
1052 $userJS = wfMsgForContent($msgKey);
1053 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1054 $s .= $userJS;
1055 }
1056
1057 wfProfileOut( $fname );
1058 return $s;
1059 }
1060 }
1061
1062 /**
1063 * Generic wrapper for template functions, with interface
1064 * compatible with what we use of PHPTAL 0.7.
1065 * @package MediaWiki
1066 * @subpackage Skins
1067 */
1068 class QuickTemplate {
1069 /**
1070 * @public
1071 */
1072 function QuickTemplate() {
1073 $this->data = array();
1074 $this->translator = new MediaWiki_I18N();
1075 }
1076
1077 /**
1078 * @public
1079 */
1080 function set( $name, $value ) {
1081 $this->data[$name] = $value;
1082 }
1083
1084 /**
1085 * @public
1086 */
1087 function setRef($name, &$value) {
1088 $this->data[$name] =& $value;
1089 }
1090
1091 /**
1092 * @public
1093 */
1094 function setTranslator( &$t ) {
1095 $this->translator = &$t;
1096 }
1097
1098 /**
1099 * @public
1100 */
1101 function execute() {
1102 echo "Override this function.";
1103 }
1104
1105
1106 /**
1107 * @private
1108 */
1109 function text( $str ) {
1110 echo htmlspecialchars( $this->data[$str] );
1111 }
1112
1113 /**
1114 * @private
1115 */
1116 function jstext( $str ) {
1117 echo Xml::escapeJsString( $this->data[$str] );
1118 }
1119
1120 /**
1121 * @private
1122 */
1123 function html( $str ) {
1124 echo $this->data[$str];
1125 }
1126
1127 /**
1128 * @private
1129 */
1130 function msg( $str ) {
1131 echo htmlspecialchars( $this->translator->translate( $str ) );
1132 }
1133
1134 /**
1135 * @private
1136 */
1137 function msgHtml( $str ) {
1138 echo $this->translator->translate( $str );
1139 }
1140
1141 /**
1142 * An ugly, ugly hack.
1143 * @private
1144 */
1145 function msgWiki( $str ) {
1146 global $wgParser, $wgTitle, $wgOut;
1147
1148 $text = $this->translator->translate( $str );
1149 $parserOutput = $wgParser->parse( $text, $wgTitle,
1150 $wgOut->parserOptions(), true );
1151 echo $parserOutput->getText();
1152 }
1153
1154 /**
1155 * @private
1156 */
1157 function haveData( $str ) {
1158 return isset( $this->data[$str] );
1159 }
1160
1161 /**
1162 * @private
1163 */
1164 function haveMsg( $str ) {
1165 $msg = $this->translator->translate( $str );
1166 return ($msg != '-') && ($msg != ''); # ????
1167 }
1168 }
1169 ?>