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