Integrating "User files" (via Special:Newimages) into the sidebar of the user page
[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 );
222 }
223 $tpl->setRef( 'feeds', $feeds );
224 } else {
225 $tpl->set( 'feeds', false );
226 }
227 if ($wgUseTrackbacks && $out->isArticleRelated())
228 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
229
230 $tpl->setRef( 'mimetype', $wgMimeType );
231 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
232 $tpl->setRef( 'charset', $wgOutputEncoding );
233 $tpl->set( 'headlinks', $out->getHeadLinks() );
234 $tpl->set('headscripts', $out->getScript() );
235 $tpl->setRef( 'wgScript', $wgScript );
236 $tpl->setRef( 'skinname', $this->skinname );
237 $tpl->setRef( 'stylename', $this->stylename );
238 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
239 $tpl->setRef( 'loggedin', $this->loggedin );
240 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
241 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
242 /* XXX currently unused, might get useful later
243 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
244 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
245 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
246 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
247 $tpl->set( "helppage", wfMsg('helppage'));
248 */
249 $tpl->set( 'searchaction', $this->escapeSearchLink() );
250 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
251 $tpl->setRef( 'stylepath', $wgStylePath );
252 $tpl->setRef( 'logopath', $wgLogo );
253 $tpl->setRef( "lang", $wgContLanguageCode );
254 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
255 $tpl->set( 'rtl', $wgContLang->isRTL() );
256 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
257 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
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( 'youhavenewmessages',
280 $this->makeKnownLinkObj(
281 $usertalktitle,
282 wfMsgHtml( 'newmessageslink' )
283 ),
284 $this->makeKnownLinkObj(
285 $usertalktitle,
286 wfMsgHtml( 'newmessagesdifflink' ),
287 'diff=cur'
288 )
289 );
290 # Disable Cache
291 $wgOut->setSquidMaxage(0);
292 }
293 } else {
294 $ntl = '';
295 }
296 wfProfileOut( "$fname-stuff2" );
297
298 wfProfileIn( "$fname-stuff3" );
299 $tpl->setRef( 'newtalk', $ntl );
300 $tpl->setRef( 'skin', $this);
301 $tpl->set( 'logo', $this->logoText() );
302 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
303 if ( !$wgDisableCounters ) {
304 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
305 if ( $viewcount ) {
306 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
307 } else {
308 $tpl->set('viewcount', false);
309 }
310 } else {
311 $tpl->set('viewcount', false);
312 }
313
314 if ($wgPageShowWatchingUsers) {
315 $dbr =& wfGetDB( DB_SLAVE );
316 extract( $dbr->tableNames( 'watchlist' ) );
317 $sql = "SELECT COUNT(*) AS n FROM $watchlist
318 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
319 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
320 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
321 $x = $dbr->fetchObject( $res );
322 $numberofwatchingusers = $x->n;
323 if ($numberofwatchingusers > 0) {
324 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
325 } else {
326 $tpl->set('numberofwatchingusers', false);
327 }
328 } else {
329 $tpl->set('numberofwatchingusers', false);
330 }
331
332 $tpl->set('copyright',$this->getCopyright());
333
334 $this->credits = false;
335
336 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
337 require_once("Credits.php");
338 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
339 } else {
340 $tpl->set('lastmod', $this->lastModified());
341 }
342
343 $tpl->setRef( 'credits', $this->credits );
344
345 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
346 $tpl->set('copyright', $this->getCopyright());
347 $tpl->set('viewcount', false);
348 $tpl->set('lastmod', false);
349 $tpl->set('credits', false);
350 $tpl->set('numberofwatchingusers', false);
351 } else {
352 $tpl->set('copyright', false);
353 $tpl->set('viewcount', false);
354 $tpl->set('lastmod', false);
355 $tpl->set('credits', false);
356 $tpl->set('numberofwatchingusers', false);
357 }
358 wfProfileOut( "$fname-stuff3" );
359
360 wfProfileIn( "$fname-stuff4" );
361 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
362 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
363 $tpl->set( 'disclaimer', $this->disclaimerLink() );
364 $tpl->set( 'privacy', $this->privacyLink() );
365 $tpl->set( 'about', $this->aboutLink() );
366
367 $tpl->setRef( 'debug', $out->mDebugtext );
368 $tpl->set( 'reporttime', $out->reportTime() );
369 $tpl->set( 'sitenotice', wfGetSiteNotice() );
370
371 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
372 $out->mBodytext .= $printfooter ;
373 $tpl->setRef( 'bodytext', $out->mBodytext );
374
375 # Language links
376 $language_urls = array();
377
378 if ( !$wgHideInterlanguageLinks ) {
379 foreach( $wgOut->getLanguageLinks() as $l ) {
380 $tmp = explode( ':', $l, 2 );
381 $class = 'interwiki-' . $tmp[0];
382 unset($tmp);
383 $nt = Title::newFromText( $l );
384 $language_urls[] = array(
385 'href' => $nt->getFullURL(),
386 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
387 'class' => $class
388 );
389 }
390 }
391 if(count($language_urls)) {
392 $tpl->setRef( 'language_urls', $language_urls);
393 } else {
394 $tpl->set('language_urls', false);
395 }
396 wfProfileOut( "$fname-stuff4" );
397
398 # Personal toolbar
399 $tpl->set('personal_urls', $this->buildPersonalUrls());
400 $content_actions = $this->buildContentActionUrls();
401 $tpl->setRef('content_actions', $content_actions);
402
403 // XXX: attach this from javascript, same with section editing
404 if($this->iseditable && $wgUser->getOption("editondblclick") )
405 {
406 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
407 } else {
408 $tpl->set('body_ondblclick', false);
409 }
410 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
411 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
412 } else {
413 $tpl->set( 'body_onload', false );
414 }
415 $tpl->set( 'sidebar', $this->buildSidebar() );
416 $tpl->set( 'nav_urls', $this->buildNavUrls() );
417
418 // execute template
419 wfProfileIn( "$fname-execute" );
420 $res = $tpl->execute();
421 wfProfileOut( "$fname-execute" );
422
423 // result may be an error
424 $this->printOrError( $res );
425 wfProfileOut( $fname );
426 }
427
428 /**
429 * Output the string, or print error message if it's
430 * an error object of the appropriate type.
431 * For the base class, assume strings all around.
432 *
433 * @param mixed $str
434 * @access private
435 */
436 function printOrError( &$str ) {
437 echo $str;
438 }
439
440 /**
441 * build array of urls for personal toolbar
442 * @return array
443 * @access private
444 */
445 function buildPersonalUrls() {
446 global $wgTitle, $wgShowIPinHeader, $wgContLang;
447
448 $fname = 'SkinTemplate::buildPersonalUrls';
449 $pageurl = $wgTitle->getLocalURL();
450 wfProfileIn( $fname );
451
452 /* set up the default links for the personal toolbar */
453 $personal_urls = array();
454 if ($this->loggedin) {
455 $personal_urls['userpage'] = array(
456 'text' => $this->username,
457 'href' => &$this->userpageUrlDetails['href'],
458 'class' => $this->userpageUrlDetails['exists']?false:'new',
459 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
460 );
461 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
462 $personal_urls['mytalk'] = array(
463 'text' => wfMsg('mytalk'),
464 'href' => &$usertalkUrlDetails['href'],
465 'class' => $usertalkUrlDetails['exists']?false:'new',
466 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
467 );
468 $href = $this->makeSpecialUrl('Preferences');
469 $personal_urls['preferences'] = array(
470 'text' => wfMsg('preferences'),
471 'href' => $this->makeSpecialUrl('Preferences'),
472 'active' => ( $href == $pageurl )
473 );
474 $href = $this->makeSpecialUrl('Watchlist');
475 $personal_urls['watchlist'] = array(
476 'text' => wfMsg('watchlist'),
477 'href' => $href,
478 'active' => ( $href == $pageurl )
479 );
480 $href = $this->makeSpecialUrl("Contributions/$this->username");
481 $personal_urls['mycontris'] = array(
482 'text' => wfMsg('mycontris'),
483 'href' => $href
484 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
485 );
486 $personal_urls['logout'] = array(
487 'text' => wfMsg('userlogout'),
488 'href' => $this->makeSpecialUrl( 'Userlogout',
489 $wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"
490 )
491 );
492 } else {
493 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
494 $href = &$this->userpageUrlDetails['href'];
495 $personal_urls['anonuserpage'] = array(
496 'text' => $this->username,
497 'href' => $href,
498 'class' => $this->userpageUrlDetails['exists']?false:'new',
499 'active' => ( $pageurl == $href )
500 );
501 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
502 $href = &$usertalkUrlDetails['href'];
503 $personal_urls['anontalk'] = array(
504 'text' => wfMsg('anontalk'),
505 'href' => $href,
506 'class' => $usertalkUrlDetails['exists']?false:'new',
507 'active' => ( $pageurl == $href )
508 );
509 $personal_urls['anonlogin'] = array(
510 'text' => wfMsg('userlogin'),
511 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
512 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
513 );
514 } else {
515
516 $personal_urls['login'] = array(
517 'text' => wfMsg('userlogin'),
518 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
519 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
520 );
521 }
522 }
523 wfProfileOut( $fname );
524 return $personal_urls;
525 }
526
527 /**
528 * Returns true if the IP should be shown in the header
529 */
530 function showIPinHeader() {
531 global $wgShowIPinHeader;
532 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
533 }
534
535 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
536 $classes = array();
537 if( $selected ) {
538 $classes[] = 'selected';
539 }
540 if( $checkEdit && $title->getArticleId() == 0 ) {
541 $classes[] = 'new';
542 $query = 'action=edit';
543 }
544
545 $text = wfMsg( $message );
546 if ( $text == "&lt;$message&gt;" ) {
547 $text = html_entity_decode($text);
548 }
549
550 return array(
551 'class' => implode( ' ', $classes ),
552 'text' => $text,
553 'href' => $title->getLocalUrl( $query ) );
554 }
555
556 function makeTalkUrlDetails( $name, $urlaction='' ) {
557 $title = Title::newFromText( $name );
558 $title = $title->getTalkPage();
559 $this->checkTitle($title, $name);
560 return array(
561 'href' => $title->getLocalURL( $urlaction ),
562 'exists' => $title->getArticleID() != 0?true:false
563 );
564 }
565
566 function makeArticleUrlDetails( $name, $urlaction='' ) {
567 $title = Title::newFromText( $name );
568 $title= $title->getSubjectPage();
569 $this->checkTitle($title, $name);
570 return array(
571 'href' => $title->getLocalURL( $urlaction ),
572 'exists' => $title->getArticleID() != 0?true:false
573 );
574 }
575
576 /**
577 * an array of edit links by default used for the tabs
578 * @return array
579 * @access private
580 */
581 function buildContentActionUrls () {
582 global $wgContLang, $wgDBprefix;
583 $fname = 'SkinTemplate::buildContentActionUrls';
584 wfProfileIn( $fname );
585
586 global $wgUser, $wgRequest;
587 $action = $wgRequest->getText( 'action' );
588 $section = $wgRequest->getText( 'section' );
589 $content_actions = array();
590
591 $prevent_active_tabs = false ;
592 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
593
594 if( $this->iscontent ) {
595 $subjpage = $this->mTitle->getSubjectPage();
596 $talkpage = $this->mTitle->getTalkPage();
597
598 $nskey = $this->getNameSpaceKey();
599 $content_actions[$nskey] = $this->tabAction(
600 $subjpage,
601 $nskey,
602 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
603 '', true);
604
605 $content_actions['talk'] = $this->tabAction(
606 $talkpage,
607 'talk',
608 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
609 '',
610 true);
611
612 wfProfileIn( "$fname-edit" );
613 if ( $this->mTitle->userCanEdit() ) {
614 $istalk = $this->mTitle->isTalkPage();
615 $istalkclass = $istalk?' istalk':'';
616 $content_actions['edit'] = array(
617 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
618 'text' => wfMsg('edit'),
619 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
620 );
621
622 if ( $istalk ) {
623 $content_actions['addsection'] = array(
624 'class' => $section == 'new'?'selected':false,
625 'text' => wfMsg('addsection'),
626 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
627 );
628 }
629 } else {
630 $content_actions['viewsource'] = array(
631 'class' => ($action == 'edit') ? 'selected' : false,
632 'text' => wfMsg('viewsource'),
633 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
634 );
635 }
636 wfProfileOut( "$fname-edit" );
637
638 wfProfileIn( "$fname-live" );
639 if ( $this->mTitle->getArticleId() ) {
640
641 $content_actions['history'] = array(
642 'class' => ($action == 'history') ? 'selected' : false,
643 'text' => wfMsg('history_short'),
644 'href' => $this->mTitle->getLocalUrl( 'action=history')
645 );
646
647 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
648 if(!$this->mTitle->isProtected()){
649 $content_actions['protect'] = array(
650 'class' => ($action == 'protect') ? 'selected' : false,
651 'text' => wfMsg('protect'),
652 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
653 );
654
655 } else {
656 $content_actions['unprotect'] = array(
657 'class' => ($action == 'unprotect') ? 'selected' : false,
658 'text' => wfMsg('unprotect'),
659 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
660 );
661 }
662 }
663 if($wgUser->isAllowed('delete')){
664 $content_actions['delete'] = array(
665 'class' => ($action == 'delete') ? 'selected' : false,
666 'text' => wfMsg('delete'),
667 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
668 );
669 }
670 if ( $this->mTitle->userCanMove()) {
671 $content_actions['move'] = array(
672 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
673 'text' => wfMsg('move'),
674 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
675 );
676 }
677 } else {
678 //article doesn't exist or is deleted
679 if($wgUser->isAllowed('delete')){
680 if( $n = $this->mTitle->isDeleted() ) {
681 $content_actions['undelete'] = array(
682 'class' => false,
683 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
684 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
685 );
686 }
687 }
688 }
689 wfProfileOut( "$fname-live" );
690
691 if( $this->loggedin ) {
692 if( !$this->mTitle->userIsWatching()) {
693 $content_actions['watch'] = array(
694 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
695 'text' => wfMsg('watch'),
696 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
697 );
698 } else {
699 $content_actions['unwatch'] = array(
700 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
701 'text' => wfMsg('unwatch'),
702 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
703 );
704 }
705 }
706
707 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
708 } else {
709 /* show special page tab */
710
711 $content_actions['article'] = array(
712 'class' => 'selected',
713 'text' => wfMsg('specialpage'),
714 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
715 );
716
717 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
718 }
719
720 /* show links to different language variants */
721 global $wgDisableLangConversion;
722 $variants = $wgContLang->getVariants();
723 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
724 $preferred = $wgContLang->getPreferredVariant();
725 $actstr = '';
726 if( $action )
727 $actstr = 'action=' . $action . '&';
728 $vcount=0;
729 foreach( $variants as $code ) {
730 $varname = $wgContLang->getVariantname( $code );
731 if( $varname == 'disable' )
732 continue;
733 $selected = ( $code == $preferred )? 'selected' : false;
734 $content_actions['varlang-' . $vcount] = array(
735 'class' => $selected,
736 'text' => $varname,
737 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
738 );
739 $vcount ++;
740 }
741 }
742
743 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
744
745 wfProfileOut( $fname );
746 return $content_actions;
747 }
748
749
750
751 /**
752 * build array of common navigation links
753 * @return array
754 * @access private
755 */
756 function buildNavUrls () {
757 global $wgUseTrackbacks, $wgTitle, $wgArticle;
758
759 $fname = 'SkinTemplate::buildNavUrls';
760 wfProfileIn( $fname );
761
762 global $wgUser, $wgRequest;
763 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
764
765 $action = $wgRequest->getText( 'action' );
766 $oldid = $wgRequest->getVal( 'oldid' );
767 $diff = $wgRequest->getVal( 'diff' );
768
769 $nav_urls = array();
770 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
771 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
772 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
773 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
774 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
775 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
776 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
777 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
778 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
779 if( $wgEnableUploads ) {
780 if ($wgUploadNavigationUrl) {
781 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
782 } else {
783 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
784 }
785 } else {
786 if ($wgUploadNavigationUrl)
787 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
788 else
789 $nav_urls['upload'] = false;
790 }
791 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
792
793
794 // A print stylesheet is attached to all pages, but nobody ever
795 // figures that out. :) Add a link...
796 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
797 $revid = $wgArticle->getRevIdFetched();
798 if ( !( $revid == 0 ) )
799 $nav_urls['print'] = array(
800 'text' => wfMsg( 'printableversion' ),
801 'href' => $wgRequest->appendQuery( 'printable=yes' )
802 );
803
804 // Also add a "permalink" while we're at it
805 if ( (int)$oldid ) {
806 $nav_urls['permalink'] = array(
807 'text' => wfMsg( 'permalink' ),
808 'href' => ''
809 );
810 } else {
811 if ( !( $revid == 0 ) )
812 $nav_urls['permalink'] = array(
813 'text' => wfMsg( 'permalink' ),
814 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
815 );
816 }
817
818 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
819 }
820
821 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
822 $nav_urls['whatlinkshere'] = array(
823 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
824 );
825 if( $this->mTitle->getArticleId() ) {
826 $nav_urls['recentchangeslinked'] = array(
827 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
828 );
829 }
830 if ($wgUseTrackbacks)
831 $nav_urls['trackbacklink'] = array(
832 'href' => $wgTitle->trackbackURL()
833 );
834 }
835
836 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
837 $id = User::idFromName($this->mTitle->getText());
838 $ip = User::isIP($this->mTitle->getText());
839 } else {
840 $id = 0;
841 $ip = false;
842 }
843
844 if($id || $ip) { # both anons and non-anons have contribution list
845 $nav_urls['contributions'] = array(
846 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
847 );
848 $nav_urls['userfiles'] = array(
849 'href' => $this->makeSpecialUrl('Newimages/' . $this->mTitle->getText() )
850 );
851 if ( $wgUser->isAllowed( 'protect' ) )
852 $nav_urls['blockip'] = array(
853 'href' => $this->makeSpecialUrl( 'Blockip/' . $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 * extensions/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;
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 ?>