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