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