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