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