trailing whitespace is unhappy
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( -1 );
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
25 *
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
29 *
30 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
31 * and is optional. You'll need to install PHPTAL manually to use
32 * skins that depend on it.
33 *
34 * @package MediaWiki
35 * @subpackage Skins
36 */
37
38 require_once 'GlobalFunctions.php';
39
40 /**
41 * Wrapper object for MediaWiki's localization functions,
42 * to be passed to the template engine.
43 *
44 * @access private
45 * @package MediaWiki
46 */
47 class MediaWiki_I18N {
48 var $_context = array();
49
50 function set($varName, $value) {
51 $this->_context[$varName] = $value;
52 }
53
54 function translate($value) {
55 $fname = 'SkinTemplate-translate';
56 wfProfileIn( $fname );
57
58 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
59 $value = preg_replace( '/^string:/', '', $value );
60
61 $value = wfMsg( $value );
62 // interpolate variables
63 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
64 list($src, $var) = $m;
65 wfSuppressWarnings();
66 $varValue = $this->_context[$var];
67 wfRestoreWarnings();
68 $value = str_replace($src, $varValue, $value);
69 }
70 wfProfileOut( $fname );
71 return $value;
72 }
73 }
74
75 /**
76 *
77 * @package MediaWiki
78 */
79 class SkinTemplate extends Skin {
80 /**#@+
81 * @access private
82 */
83
84 /**
85 * Name of our skin, set in initPage()
86 * It probably need to be all lower case.
87 */
88 var $skinname;
89
90 /**
91 * Stylesheets set to use
92 * Sub directory in ./skins/ where various stylesheets are located
93 */
94 var $stylename;
95
96 /**
97 * For QuickTemplate, the name of the subclass which
98 * will actually fill the template.
99 *
100 * In PHPTal mode, name of PHPTal template to be used.
101 * '.pt' will be automaticly added to it on PHPTAL object creation
102 */
103 var $template;
104
105 /**#@-*/
106
107 /**
108 * Setup the base parameters...
109 * Child classes should override this to set the name,
110 * style subdirectory, and template filler callback.
111 *
112 * @param OutputPage $out
113 */
114 function initPage( &$out ) {
115 parent::initPage( $out );
116 $this->skinname = 'monobook';
117 $this->stylename = 'monobook';
118 $this->template = 'QuickTemplate';
119 }
120
121 /**
122 * Create the template engine object; we feed it a bunch of data
123 * and eventually it spits out some HTML. Should have interface
124 * roughly equivalent to PHPTAL 0.7.
125 *
126 * @param string $callback (or file)
127 * @param string $repository subdirectory where we keep template files
128 * @param string $cache_dir
129 * @return object
130 * @access private
131 */
132 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
133 return new $classname();
134 }
135
136 /**
137 * initialize various variables and generate the template
138 *
139 * @param OutputPage $out
140 * @access public
141 */
142 function outputPage( &$out ) {
143 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
144 global $wgScript, $wgStylePath, $wgContLanguageCode;
145 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
146 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
147 global $wgMaxCredits, $wgShowCreditsIfMax;
148 global $wgPageShowWatchingUsers;
149 global $wgUseTrackbacks;
150 global $wgDBname;
151
152 $fname = 'SkinTemplate::outputPage';
153 wfProfileIn( $fname );
154
155 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
156
157 wfProfileIn( "$fname-init" );
158 $this->initPage( $out );
159
160 $this->mTitle =& $wgTitle;
161 $this->mUser =& $wgUser;
162
163 $tpl = $this->setupTemplate( $this->template, 'skins' );
164
165 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
166 $tpl->setTranslator(new MediaWiki_I18N());
167 #}
168 wfProfileOut( "$fname-init" );
169
170 wfProfileIn( "$fname-stuff" );
171 $this->thispage = $this->mTitle->getPrefixedDbKey();
172 $this->thisurl = $this->mTitle->getPrefixedURL();
173 $this->loggedin = $wgUser->isLoggedIn();
174 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
175 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
176 $this->username = $wgUser->getName();
177 $userPage = $wgUser->getUserPage();
178 $this->userpage = $userPage->getPrefixedText();
179
180 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
181 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
182 } else {
183 # This won't be used in the standard skins, but we define it to preserve the interface
184 # To save time, we check for existence
185 $this->userpageUrlDetails = $this->makeKnownUrlDetails($this->userpage);
186 }
187
188 $this->usercss = $this->userjs = $this->userjsprev = false;
189 $this->setupUserCss();
190 $this->setupUserJs();
191 $this->titletxt = $this->mTitle->getPrefixedText();
192 wfProfileOut( "$fname-stuff" );
193
194 wfProfileIn( "$fname-stuff2" );
195 $tpl->set( 'title', $wgOut->getPageTitle() );
196 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
197
198 $tpl->setRef( "thispage", $this->thispage );
199 $subpagestr = $this->subPageSubtitle();
200 $tpl->set(
201 'subtitle', !empty($subpagestr)?
202 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
203 $out->getSubtitle()
204 );
205 $undelete = $this->getUndeleteLink();
206 $tpl->set(
207 "undelete", !empty($undelete)?
208 '<span class="subpages">'.$undelete.'</span>':
209 ''
210 );
211
212 $tpl->set( 'catlinks', $this->getCategories());
213 if( $wgOut->isSyndicated() ) {
214 $feeds = array();
215 foreach( $wgFeedClasses as $format => $class ) {
216 $feeds[$format] = array(
217 'text' => $format,
218 'href' => $wgRequest->appendQuery( "feed=$format" )
219 );
220 }
221 $tpl->setRef( 'feeds', $feeds );
222 } else {
223 $tpl->set( 'feeds', false );
224 }
225 if ($wgUseTrackbacks && $out->isArticleRelated())
226 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
227
228 $tpl->setRef( 'mimetype', $wgMimeType );
229 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
230 $tpl->setRef( 'charset', $wgOutputEncoding );
231 $tpl->set( 'headlinks', $out->getHeadLinks() );
232 $tpl->set('headscripts', $out->getScript() );
233 $tpl->setRef( 'wgScript', $wgScript );
234 $tpl->setRef( 'skinname', $this->skinname );
235 $tpl->setRef( 'stylename', $this->stylename );
236 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
237 $tpl->setRef( 'loggedin', $this->loggedin );
238 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
239 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
240 /* XXX currently unused, might get useful later
241 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
242 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
243 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
244 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
245 $tpl->set( "helppage", wfMsg('helppage'));
246 */
247 $tpl->set( 'searchaction', $this->escapeSearchLink() );
248 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
249 $tpl->setRef( 'stylepath', $wgStylePath );
250 $tpl->setRef( 'logopath', $wgLogo );
251 $tpl->setRef( "lang", $wgContLanguageCode );
252 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
253 $tpl->set( 'rtl', $wgContLang->isRTL() );
254 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
255 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
256 $tpl->setRef( 'username', $this->username );
257 $tpl->setRef( 'userpage', $this->userpage);
258 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
259 $tpl->set( 'pagecss', $this->setupPageCss() );
260 $tpl->setRef( 'usercss', $this->usercss);
261 $tpl->setRef( 'userjs', $this->userjs);
262 $tpl->setRef( 'userjsprev', $this->userjsprev);
263 global $wgUseSiteJs;
264 if ($wgUseSiteJs) {
265 if($this->loggedin) {
266 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
267 } else {
268 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
269 }
270 } else {
271 $tpl->set('jsvarurl', false);
272 }
273 $newtalks = $wgUser->getNewMessageLinks();
274
275 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
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 if (count($newtalks)) {
294 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
295 $msgs = array();
296 foreach ($newtalks as $newtalk) {
297 $msgs[] = wfElement("a",
298 array('href' => $newtalk["link"]), $newtalk["wiki"]);
299 }
300 $parts = implode($sep, $msgs);
301 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
302 $wgOut->setSquidMaxage(0);
303 } else {
304 $ntl = '';
305 }
306 wfProfileOut( "$fname-stuff2" );
307
308 wfProfileIn( "$fname-stuff3" );
309 $tpl->setRef( 'newtalk', $ntl );
310 $tpl->setRef( 'skin', $this);
311 $tpl->set( 'logo', $this->logoText() );
312 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
313 if ( !$wgDisableCounters ) {
314 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
315 if ( $viewcount ) {
316 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
317 } else {
318 $tpl->set('viewcount', false);
319 }
320 } else {
321 $tpl->set('viewcount', false);
322 }
323
324 if ($wgPageShowWatchingUsers) {
325 $dbr =& wfGetDB( DB_SLAVE );
326 extract( $dbr->tableNames( 'watchlist' ) );
327 $sql = "SELECT COUNT(*) AS n FROM $watchlist
328 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
329 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
330 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
331 $x = $dbr->fetchObject( $res );
332 $numberofwatchingusers = $x->n;
333 if ($numberofwatchingusers > 0) {
334 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
335 } else {
336 $tpl->set('numberofwatchingusers', false);
337 }
338 } else {
339 $tpl->set('numberofwatchingusers', false);
340 }
341
342 $tpl->set('copyright',$this->getCopyright());
343
344 $this->credits = false;
345
346 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
347 require_once("Credits.php");
348 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
349 } else {
350 $tpl->set('lastmod', $this->lastModified());
351 }
352
353 $tpl->setRef( 'credits', $this->credits );
354
355 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
356 $tpl->set('copyright', $this->getCopyright());
357 $tpl->set('viewcount', false);
358 $tpl->set('lastmod', false);
359 $tpl->set('credits', false);
360 $tpl->set('numberofwatchingusers', false);
361 } else {
362 $tpl->set('copyright', false);
363 $tpl->set('viewcount', false);
364 $tpl->set('lastmod', false);
365 $tpl->set('credits', false);
366 $tpl->set('numberofwatchingusers', false);
367 }
368 wfProfileOut( "$fname-stuff3" );
369
370 wfProfileIn( "$fname-stuff4" );
371 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
372 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
373 $tpl->set( 'disclaimer', $this->disclaimerLink() );
374 $tpl->set( 'privacy', $this->privacyLink() );
375 $tpl->set( 'about', $this->aboutLink() );
376
377 $tpl->setRef( 'debug', $out->mDebugtext );
378 $tpl->set( 'reporttime', $out->reportTime() );
379 $tpl->set( 'sitenotice', wfGetSiteNotice() );
380
381 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
382 $out->mBodytext .= $printfooter ;
383 $tpl->setRef( 'bodytext', $out->mBodytext );
384
385 # Language links
386 $language_urls = array();
387
388 if ( !$wgHideInterlanguageLinks ) {
389 foreach( $wgOut->getLanguageLinks() as $l ) {
390 $tmp = explode( ':', $l, 2 );
391 $class = 'interwiki-' . $tmp[0];
392 unset($tmp);
393 $nt = Title::newFromText( $l );
394 $language_urls[] = array(
395 'href' => $nt->getFullURL(),
396 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
397 'class' => $class
398 );
399 }
400 }
401 if(count($language_urls)) {
402 $tpl->setRef( 'language_urls', $language_urls);
403 } else {
404 $tpl->set('language_urls', false);
405 }
406 wfProfileOut( "$fname-stuff4" );
407
408 # Personal toolbar
409 $tpl->set('personal_urls', $this->buildPersonalUrls());
410 $content_actions = $this->buildContentActionUrls();
411 $tpl->setRef('content_actions', $content_actions);
412
413 // XXX: attach this from javascript, same with section editing
414 if($this->iseditable && $wgUser->getOption("editondblclick") )
415 {
416 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
417 } else {
418 $tpl->set('body_ondblclick', false);
419 }
420 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
421 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
422 } else {
423 $tpl->set( 'body_onload', false );
424 }
425 $tpl->set( 'sidebar', $this->buildSidebar() );
426 $tpl->set( 'nav_urls', $this->buildNavUrls() );
427
428 // execute template
429 wfProfileIn( "$fname-execute" );
430 $res = $tpl->execute();
431 wfProfileOut( "$fname-execute" );
432
433 // result may be an error
434 $this->printOrError( $res );
435 wfProfileOut( $fname );
436 }
437
438 /**
439 * Output the string, or print error message if it's
440 * an error object of the appropriate type.
441 * For the base class, assume strings all around.
442 *
443 * @param mixed $str
444 * @access private
445 */
446 function printOrError( &$str ) {
447 echo $str;
448 }
449
450 /**
451 * build array of urls for personal toolbar
452 * @return array
453 * @access private
454 */
455 function buildPersonalUrls() {
456 global $wgTitle, $wgShowIPinHeader, $wgContLang;
457
458 $fname = 'SkinTemplate::buildPersonalUrls';
459 $pageurl = $wgTitle->getLocalURL();
460 wfProfileIn( $fname );
461
462 /* set up the default links for the personal toolbar */
463 $personal_urls = array();
464 if ($this->loggedin) {
465 $personal_urls['userpage'] = array(
466 'text' => $this->username,
467 'href' => &$this->userpageUrlDetails['href'],
468 'class' => $this->userpageUrlDetails['exists']?false:'new',
469 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
470 );
471 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
472 $personal_urls['mytalk'] = array(
473 'text' => wfMsg('mytalk'),
474 'href' => &$usertalkUrlDetails['href'],
475 'class' => $usertalkUrlDetails['exists']?false:'new',
476 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
477 );
478 $href = $this->makeSpecialUrl('Preferences');
479 $personal_urls['preferences'] = array(
480 'text' => wfMsg('preferences'),
481 'href' => $this->makeSpecialUrl('Preferences'),
482 'active' => ( $href == $pageurl )
483 );
484 $href = $this->makeSpecialUrl('Watchlist');
485 $personal_urls['watchlist'] = array(
486 'text' => wfMsg('watchlist'),
487 'href' => $href,
488 'active' => ( $href == $pageurl )
489 );
490 $href = $this->makeSpecialUrl("Contributions/$this->username");
491 $personal_urls['mycontris'] = array(
492 'text' => wfMsg('mycontris'),
493 'href' => $href
494 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
495 );
496 $personal_urls['logout'] = array(
497 'text' => wfMsg('userlogout'),
498 'href' => $this->makeSpecialUrl( 'Userlogout',
499 $wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"
500 )
501 );
502 } else {
503 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
504 $href = &$this->userpageUrlDetails['href'];
505 $personal_urls['anonuserpage'] = array(
506 'text' => $this->username,
507 'href' => $href,
508 'class' => $this->userpageUrlDetails['exists']?false:'new',
509 'active' => ( $pageurl == $href )
510 );
511 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
512 $href = &$usertalkUrlDetails['href'];
513 $personal_urls['anontalk'] = array(
514 'text' => wfMsg('anontalk'),
515 'href' => $href,
516 'class' => $usertalkUrlDetails['exists']?false:'new',
517 'active' => ( $pageurl == $href )
518 );
519 $personal_urls['anonlogin'] = array(
520 'text' => wfMsg('userlogin'),
521 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
522 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
523 );
524 } else {
525
526 $personal_urls['login'] = array(
527 'text' => wfMsg('userlogin'),
528 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
529 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
530 );
531 }
532 }
533 wfProfileOut( $fname );
534 return $personal_urls;
535 }
536
537 /**
538 * Returns true if the IP should be shown in the header
539 */
540 function showIPinHeader() {
541 global $wgShowIPinHeader;
542 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
543 }
544
545 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
546 $classes = array();
547 if( $selected ) {
548 $classes[] = 'selected';
549 }
550 if( $checkEdit && $title->getArticleId() == 0 ) {
551 $classes[] = 'new';
552 $query = 'action=edit';
553 }
554
555 $text = wfMsg( $message );
556 if ( $text == "&lt;$message&gt;" ) {
557 $text = html_entity_decode($text);
558 }
559
560 return array(
561 'class' => implode( ' ', $classes ),
562 'text' => $text,
563 'href' => $title->getLocalUrl( $query ) );
564 }
565
566 function makeTalkUrlDetails( $name, $urlaction='' ) {
567 $title = Title::newFromText( $name );
568 $title = $title->getTalkPage();
569 $this->checkTitle($title, $name);
570 return array(
571 'href' => $title->getLocalURL( $urlaction ),
572 'exists' => $title->getArticleID() != 0?true:false
573 );
574 }
575
576 function makeArticleUrlDetails( $name, $urlaction='' ) {
577 $title = Title::newFromText( $name );
578 $title= $title->getSubjectPage();
579 $this->checkTitle($title, $name);
580 return array(
581 'href' => $title->getLocalURL( $urlaction ),
582 'exists' => $title->getArticleID() != 0?true:false
583 );
584 }
585
586 /**
587 * an array of edit links by default used for the tabs
588 * @return array
589 * @access private
590 */
591 function buildContentActionUrls () {
592 global $wgContLang, $wgDBprefix;
593 $fname = 'SkinTemplate::buildContentActionUrls';
594 wfProfileIn( $fname );
595
596 global $wgUser, $wgRequest;
597 $action = $wgRequest->getText( 'action' );
598 $section = $wgRequest->getText( 'section' );
599 $content_actions = array();
600
601 $prevent_active_tabs = false ;
602 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
603
604 if( $this->iscontent ) {
605 $subjpage = $this->mTitle->getSubjectPage();
606 $talkpage = $this->mTitle->getTalkPage();
607
608 $nskey = $this->getNameSpaceKey();
609 $content_actions[$nskey] = $this->tabAction(
610 $subjpage,
611 $nskey,
612 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
613 '', true);
614
615 $content_actions['talk'] = $this->tabAction(
616 $talkpage,
617 'talk',
618 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
619 '',
620 true);
621
622 wfProfileIn( "$fname-edit" );
623 if ( $this->mTitle->userCanEdit() ) {
624 $istalk = $this->mTitle->isTalkPage();
625 $istalkclass = $istalk?' istalk':'';
626 $content_actions['edit'] = array(
627 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
628 'text' => wfMsg('edit'),
629 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
630 );
631
632 if ( $istalk ) {
633 $content_actions['addsection'] = array(
634 'class' => $section == 'new'?'selected':false,
635 'text' => wfMsg('addsection'),
636 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
637 );
638 }
639 } else {
640 $content_actions['viewsource'] = array(
641 'class' => ($action == 'edit') ? 'selected' : false,
642 'text' => wfMsg('viewsource'),
643 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
644 );
645 }
646 wfProfileOut( "$fname-edit" );
647
648 wfProfileIn( "$fname-live" );
649 if ( $this->mTitle->getArticleId() ) {
650
651 $content_actions['history'] = array(
652 'class' => ($action == 'history') ? 'selected' : false,
653 'text' => wfMsg('history_short'),
654 'href' => $this->mTitle->getLocalUrl( 'action=history')
655 );
656
657 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
658 if(!$this->mTitle->isProtected()){
659 $content_actions['protect'] = array(
660 'class' => ($action == 'protect') ? 'selected' : false,
661 'text' => wfMsg('protect'),
662 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
663 );
664
665 } else {
666 $content_actions['unprotect'] = array(
667 'class' => ($action == 'unprotect') ? 'selected' : false,
668 'text' => wfMsg('unprotect'),
669 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
670 );
671 }
672 }
673 if($wgUser->isAllowed('delete')){
674 $content_actions['delete'] = array(
675 'class' => ($action == 'delete') ? 'selected' : false,
676 'text' => wfMsg('delete'),
677 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
678 );
679 }
680 if ( $this->mTitle->userCanMove()) {
681 $content_actions['move'] = array(
682 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
683 'text' => wfMsg('move'),
684 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
685 );
686 }
687 } else {
688 //article doesn't exist or is deleted
689 if($wgUser->isAllowed('delete')){
690 if( $n = $this->mTitle->isDeleted() ) {
691 $content_actions['undelete'] = array(
692 'class' => false,
693 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
694 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
695 );
696 }
697 }
698 }
699 wfProfileOut( "$fname-live" );
700
701 if( $this->loggedin ) {
702 if( !$this->mTitle->userIsWatching()) {
703 $content_actions['watch'] = array(
704 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
705 'text' => wfMsg('watch'),
706 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
707 );
708 } else {
709 $content_actions['unwatch'] = array(
710 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
711 'text' => wfMsg('unwatch'),
712 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
713 );
714 }
715 }
716
717 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
718 } else {
719 /* show special page tab */
720
721 $content_actions['article'] = array(
722 'class' => 'selected',
723 'text' => wfMsg('specialpage'),
724 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
725 );
726
727 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
728 }
729
730 /* show links to different language variants */
731 global $wgDisableLangConversion;
732 $variants = $wgContLang->getVariants();
733 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
734 $preferred = $wgContLang->getPreferredVariant();
735 $actstr = '';
736 if( $action )
737 $actstr = 'action=' . $action . '&';
738 $vcount=0;
739 foreach( $variants as $code ) {
740 $varname = $wgContLang->getVariantname( $code );
741 if( $varname == 'disable' )
742 continue;
743 $selected = ( $code == $preferred )? 'selected' : false;
744 $content_actions['varlang-' . $vcount] = array(
745 'class' => $selected,
746 'text' => $varname,
747 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
748 );
749 $vcount ++;
750 }
751 }
752
753 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
754
755 wfProfileOut( $fname );
756 return $content_actions;
757 }
758
759
760
761 /**
762 * build array of common navigation links
763 * @return array
764 * @access private
765 */
766 function buildNavUrls () {
767 global $wgUseTrackbacks, $wgTitle, $wgArticle;
768
769 $fname = 'SkinTemplate::buildNavUrls';
770 wfProfileIn( $fname );
771
772 global $wgUser, $wgRequest;
773 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
774
775 $action = $wgRequest->getText( 'action' );
776 $oldid = $wgRequest->getVal( 'oldid' );
777 $diff = $wgRequest->getVal( 'diff' );
778
779 $nav_urls = array();
780 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
781 if( $wgEnableUploads ) {
782 if ($wgUploadNavigationUrl) {
783 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
784 } else {
785 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
786 }
787 } else {
788 if ($wgUploadNavigationUrl)
789 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
790 else
791 $nav_urls['upload'] = false;
792 }
793 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
794
795
796 // A print stylesheet is attached to all pages, but nobody ever
797 // figures that out. :) Add a link...
798 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
799 $revid = $wgArticle->getRevIdFetched();
800 if ( !( $revid == 0 ) )
801 $nav_urls['print'] = array(
802 'text' => wfMsg( 'printableversion' ),
803 'href' => $wgRequest->appendQuery( 'printable=yes' )
804 );
805
806 // Also add a "permalink" while we're at it
807 if ( (int)$oldid ) {
808 $nav_urls['permalink'] = array(
809 'text' => wfMsg( 'permalink' ),
810 'href' => ''
811 );
812 } else {
813 if ( !( $revid == 0 ) )
814 $nav_urls['permalink'] = array(
815 'text' => wfMsg( 'permalink' ),
816 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
817 );
818 }
819
820 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
821 }
822
823 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
824 $nav_urls['whatlinkshere'] = array(
825 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
826 );
827 if( $this->mTitle->getArticleId() ) {
828 $nav_urls['recentchangeslinked'] = array(
829 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
830 );
831 }
832 if ($wgUseTrackbacks)
833 $nav_urls['trackbacklink'] = array(
834 'href' => $wgTitle->trackbackURL()
835 );
836 }
837
838 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
839 $id = User::idFromName($this->mTitle->getText());
840 $ip = User::isIP($this->mTitle->getText());
841 } else {
842 $id = 0;
843 $ip = false;
844 }
845
846 if($id || $ip) { # both anons and non-anons have contri list
847 $nav_urls['contributions'] = array(
848 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
849 );
850 if ( $wgUser->isAllowed( 'block' ) )
851 $nav_urls['blockip'] = array(
852 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
853 );
854 } else {
855 $nav_urls['contributions'] = false;
856 }
857 $nav_urls['emailuser'] = false;
858 if( $this->showEmailUser( $id ) ) {
859 $nav_urls['emailuser'] = array(
860 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
861 );
862 }
863 wfProfileOut( $fname );
864 return $nav_urls;
865 }
866
867 /**
868 * Generate strings used for xml 'id' names
869 * @return string
870 * @access private
871 */
872 function getNameSpaceKey () {
873 switch ($this->mTitle->getNamespace()) {
874 case NS_MAIN:
875 case NS_TALK:
876 return 'nstab-main';
877 case NS_USER:
878 case NS_USER_TALK:
879 return 'nstab-user';
880 case NS_MEDIA:
881 return 'nstab-media';
882 case NS_SPECIAL:
883 return 'nstab-special';
884 case NS_PROJECT:
885 case NS_PROJECT_TALK:
886 return 'nstab-wp';
887 case NS_IMAGE:
888 case NS_IMAGE_TALK:
889 return 'nstab-image';
890 case NS_MEDIAWIKI:
891 case NS_MEDIAWIKI_TALK:
892 return 'nstab-mediawiki';
893 case NS_TEMPLATE:
894 case NS_TEMPLATE_TALK:
895 return 'nstab-template';
896 case NS_HELP:
897 case NS_HELP_TALK:
898 return 'nstab-help';
899 case NS_CATEGORY:
900 case NS_CATEGORY_TALK:
901 return 'nstab-category';
902 default:
903 return 'nstab-' . strtolower( $this->mTitle->getSubjectNsText() );
904 }
905 }
906
907 /**
908 * @access private
909 */
910 function setupUserCss() {
911 $fname = 'SkinTemplate::setupUserCss';
912 wfProfileIn( $fname );
913
914 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
915
916 $sitecss = '';
917 $usercss = '';
918 $siteargs = '&maxage=' . $wgSquidMaxage;
919
920 # Add user-specific code if this is a user and we allow that kind of thing
921
922 if ( $wgAllowUserCss && $this->loggedin ) {
923 $action = $wgRequest->getText('action');
924
925 # if we're previewing the CSS page, use it
926 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
927 $siteargs = "&smaxage=0&maxage=0";
928 $usercss = $wgRequest->getText('wpTextbox1');
929 } else {
930 $usercss = '@import "' .
931 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
932 'action=raw&ctype=text/css') . '";' ."\n";
933 }
934
935 $siteargs .= '&ts=' . $wgUser->mTouched;
936 }
937
938 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
939
940 # If we use the site's dynamic CSS, throw that in, too
941 if ( $wgUseSiteCss ) {
942 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
943 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
944 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', $query, NS_MEDIAWIKI) . '";' . "\n";
945 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
946 }
947
948 # If we use any dynamic CSS, make a little CDATA block out of it.
949
950 if ( !empty($sitecss) || !empty($usercss) ) {
951 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
952 }
953 wfProfileOut( $fname );
954 }
955
956 /**
957 * @access private
958 */
959 function setupUserJs() {
960 $fname = 'SkinTemplate::setupUserJs';
961 wfProfileIn( $fname );
962
963 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
964 $action = $wgRequest->getText('action');
965
966 if( $wgAllowUserJs && $this->loggedin ) {
967 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
968 # XXX: additional security check/prompt?
969 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
970 } else {
971 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
972 }
973 }
974 wfProfileOut( $fname );
975 }
976
977 /**
978 * Code for extensions to hook into to provide per-page CSS, see
979 * extensions/PageCSS/PageCSS.php for an implementation of this.
980 *
981 * @access private
982 */
983 function setupPageCss() {
984 $fname = 'SkinTemplate::setupPageCss';
985 wfProfileIn( $fname );
986 $out = false;
987 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
988
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 ?>