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