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