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