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