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