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