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