call JS onload hooks at the end of the html body in all skins
[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 $tpl->set( 'bottomscripts', $this->bottomScripts() );
394
395 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
396 $out->mBodytext .= $printfooter ;
397 $tpl->setRef( 'bodytext', $out->mBodytext );
398
399 # Language links
400 $language_urls = array();
401
402 if ( !$wgHideInterlanguageLinks ) {
403 foreach( $wgOut->getLanguageLinks() as $l ) {
404 $tmp = explode( ':', $l, 2 );
405 $class = 'interwiki-' . $tmp[0];
406 unset($tmp);
407 $nt = Title::newFromText( $l );
408 $language_urls[] = array(
409 'href' => $nt->getFullURL(),
410 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
411 'class' => $class
412 );
413 }
414 }
415 if(count($language_urls)) {
416 $tpl->setRef( 'language_urls', $language_urls);
417 } else {
418 $tpl->set('language_urls', false);
419 }
420 wfProfileOut( "$fname-stuff4" );
421
422 # Personal toolbar
423 $tpl->set('personal_urls', $this->buildPersonalUrls());
424 $content_actions = $this->buildContentActionUrls();
425 $tpl->setRef('content_actions', $content_actions);
426
427 // XXX: attach this from javascript, same with section editing
428 if($this->iseditable && $wgUser->getOption("editondblclick") )
429 {
430 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
431 } else {
432 $tpl->set('body_ondblclick', false);
433 }
434 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
435 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
436 } else {
437 $tpl->set( 'body_onload', false );
438 }
439 $tpl->set( 'sidebar', $this->buildSidebar() );
440 $tpl->set( 'nav_urls', $this->buildNavUrls() );
441
442 // execute template
443 wfProfileIn( "$fname-execute" );
444 $res = $tpl->execute();
445 wfProfileOut( "$fname-execute" );
446
447 // result may be an error
448 $this->printOrError( $res );
449 wfProfileOut( $fname );
450 }
451
452 /**
453 * Output the string, or print error message if it's
454 * an error object of the appropriate type.
455 * For the base class, assume strings all around.
456 *
457 * @param mixed $str
458 * @private
459 */
460 function printOrError( &$str ) {
461 echo $str;
462 }
463
464 /**
465 * build array of urls for personal toolbar
466 * @return array
467 * @private
468 */
469 function buildPersonalUrls() {
470 global $wgTitle, $wgShowIPinHeader;
471
472 $fname = 'SkinTemplate::buildPersonalUrls';
473 $pageurl = $wgTitle->getLocalURL();
474 wfProfileIn( $fname );
475
476 /* set up the default links for the personal toolbar */
477 $personal_urls = array();
478 if ($this->loggedin) {
479 $personal_urls['userpage'] = array(
480 'text' => $this->username,
481 'href' => &$this->userpageUrlDetails['href'],
482 'class' => $this->userpageUrlDetails['exists']?false:'new',
483 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
484 );
485 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
486 $personal_urls['mytalk'] = array(
487 'text' => wfMsg('mytalk'),
488 'href' => &$usertalkUrlDetails['href'],
489 'class' => $usertalkUrlDetails['exists']?false:'new',
490 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
491 );
492 $href = $this->makeSpecialUrl('Preferences');
493 $personal_urls['preferences'] = array(
494 'text' => wfMsg('preferences'),
495 'href' => $this->makeSpecialUrl('Preferences'),
496 'active' => ( $href == $pageurl )
497 );
498 $href = $this->makeSpecialUrl('Watchlist');
499 $personal_urls['watchlist'] = array(
500 'text' => wfMsg('watchlist'),
501 'href' => $href,
502 'active' => ( $href == $pageurl )
503 );
504 $href = $this->makeSpecialUrl("Contributions/$this->username");
505 $personal_urls['mycontris'] = array(
506 'text' => wfMsg('mycontris'),
507 'href' => $href
508 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
509 );
510 $personal_urls['logout'] = array(
511 'text' => wfMsg('userlogout'),
512 'href' => $this->makeSpecialUrl( 'Userlogout',
513 $wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"
514 )
515 );
516 } else {
517 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
518 $href = &$this->userpageUrlDetails['href'];
519 $personal_urls['anonuserpage'] = array(
520 'text' => $this->username,
521 'href' => $href,
522 'class' => $this->userpageUrlDetails['exists']?false:'new',
523 'active' => ( $pageurl == $href )
524 );
525 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
526 $href = &$usertalkUrlDetails['href'];
527 $personal_urls['anontalk'] = array(
528 'text' => wfMsg('anontalk'),
529 'href' => $href,
530 'class' => $usertalkUrlDetails['exists']?false:'new',
531 'active' => ( $pageurl == $href )
532 );
533 $personal_urls['anonlogin'] = array(
534 'text' => wfMsg('userlogin'),
535 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
536 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
537 );
538 } else {
539
540 $personal_urls['login'] = array(
541 'text' => wfMsg('userlogin'),
542 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
543 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
544 );
545 }
546 }
547
548 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
549 wfProfileOut( $fname );
550 return $personal_urls;
551 }
552
553 /**
554 * Returns true if the IP should be shown in the header
555 */
556 function showIPinHeader() {
557 global $wgShowIPinHeader;
558 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
559 }
560
561 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
562 $classes = array();
563 if( $selected ) {
564 $classes[] = 'selected';
565 }
566 if( $checkEdit && $title->getArticleId() == 0 ) {
567 $classes[] = 'new';
568 $query = 'action=edit';
569 }
570
571 $text = wfMsg( $message );
572 if ( $text == "&lt;$message&gt;" ) {
573 global $wgContLang;
574 $text = $wgContLang->getNsText( Namespace::getSubject( $title->getNamespace() ) );
575 }
576
577 return array(
578 'class' => implode( ' ', $classes ),
579 'text' => $text,
580 'href' => $title->getLocalUrl( $query ) );
581 }
582
583 function makeTalkUrlDetails( $name, $urlaction='' ) {
584 $title = Title::newFromText( $name );
585 $title = $title->getTalkPage();
586 $this->checkTitle($title, $name);
587 return array(
588 'href' => $title->getLocalURL( $urlaction ),
589 'exists' => $title->getArticleID() != 0?true:false
590 );
591 }
592
593 function makeArticleUrlDetails( $name, $urlaction='' ) {
594 $title = Title::newFromText( $name );
595 $title= $title->getSubjectPage();
596 $this->checkTitle($title, $name);
597 return array(
598 'href' => $title->getLocalURL( $urlaction ),
599 'exists' => $title->getArticleID() != 0?true:false
600 );
601 }
602
603 /**
604 * an array of edit links by default used for the tabs
605 * @return array
606 * @private
607 */
608 function buildContentActionUrls () {
609 global $wgContLang, $wgOut;
610 $fname = 'SkinTemplate::buildContentActionUrls';
611 wfProfileIn( $fname );
612
613 global $wgUser, $wgRequest;
614 $action = $wgRequest->getText( 'action' );
615 $section = $wgRequest->getText( 'section' );
616 $content_actions = array();
617
618 $prevent_active_tabs = false ;
619 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
620
621 if( $this->iscontent ) {
622 $subjpage = $this->mTitle->getSubjectPage();
623 $talkpage = $this->mTitle->getTalkPage();
624
625 $nskey = $this->mTitle->getNamespaceKey();
626 $content_actions[$nskey] = $this->tabAction(
627 $subjpage,
628 $nskey,
629 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
630 '', true);
631
632 $content_actions['talk'] = $this->tabAction(
633 $talkpage,
634 'talk',
635 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
636 '',
637 true);
638
639 wfProfileIn( "$fname-edit" );
640 if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {
641 $istalk = $this->mTitle->isTalkPage();
642 $istalkclass = $istalk?' istalk':'';
643 $content_actions['edit'] = array(
644 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
645 'text' => wfMsg('edit'),
646 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
647 );
648
649 if ( $istalk || $wgOut->showNewSectionLink() ) {
650 $content_actions['addsection'] = array(
651 'class' => $section == 'new'?'selected':false,
652 'text' => wfMsg('addsection'),
653 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
654 );
655 }
656 } else {
657 $content_actions['viewsource'] = array(
658 'class' => ($action == 'edit') ? 'selected' : false,
659 'text' => wfMsg('viewsource'),
660 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
661 );
662 }
663 wfProfileOut( "$fname-edit" );
664
665 wfProfileIn( "$fname-live" );
666 if ( $this->mTitle->getArticleId() ) {
667
668 $content_actions['history'] = array(
669 'class' => ($action == 'history') ? 'selected' : false,
670 'text' => wfMsg('history_short'),
671 'href' => $this->mTitle->getLocalUrl( 'action=history')
672 );
673
674 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
675 if(!$this->mTitle->isProtected()){
676 $content_actions['protect'] = array(
677 'class' => ($action == 'protect') ? 'selected' : false,
678 'text' => wfMsg('protect'),
679 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
680 );
681
682 } else {
683 $content_actions['unprotect'] = array(
684 'class' => ($action == 'unprotect') ? 'selected' : false,
685 'text' => wfMsg('unprotect'),
686 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
687 );
688 }
689 }
690 if($wgUser->isAllowed('delete')){
691 $content_actions['delete'] = array(
692 'class' => ($action == 'delete') ? 'selected' : false,
693 'text' => wfMsg('delete'),
694 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
695 );
696 }
697 if ( $this->mTitle->userCanMove()) {
698 $moveTitle = Title::makeTitle( NS_SPECIAL, 'Movepage' );
699 $content_actions['move'] = array(
700 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
701 'text' => wfMsg('move'),
702 'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
703 );
704 }
705 } else {
706 //article doesn't exist or is deleted
707 if( $wgUser->isAllowed( 'delete' ) ) {
708 if( $n = $this->mTitle->isDeleted() ) {
709 $undelTitle = Title::makeTitle( NS_SPECIAL, 'Undelete' );
710 $content_actions['undelete'] = array(
711 'class' => false,
712 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
713 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
714 #'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
715 );
716 }
717 }
718 }
719 wfProfileOut( "$fname-live" );
720
721 if( $this->loggedin ) {
722 if( !$this->mTitle->userIsWatching()) {
723 $content_actions['watch'] = array(
724 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
725 'text' => wfMsg('watch'),
726 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
727 );
728 } else {
729 $content_actions['unwatch'] = array(
730 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
731 'text' => wfMsg('unwatch'),
732 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
733 );
734 }
735 }
736
737 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
738 } else {
739 /* show special page tab */
740
741 $content_actions['article'] = array(
742 'class' => 'selected',
743 'text' => wfMsg('specialpage'),
744 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
745 );
746
747 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
748 }
749
750 /* show links to different language variants */
751 global $wgDisableLangConversion;
752 $variants = $wgContLang->getVariants();
753 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
754 $preferred = $wgContLang->getPreferredVariant();
755 $actstr = '';
756 if( $action )
757 $actstr = 'action=' . $action . '&';
758 $vcount=0;
759 foreach( $variants as $code ) {
760 $varname = $wgContLang->getVariantname( $code );
761 if( $varname == 'disable' )
762 continue;
763 $selected = ( $code == $preferred )? 'selected' : false;
764 $content_actions['varlang-' . $vcount] = array(
765 'class' => $selected,
766 'text' => $varname,
767 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
768 );
769 $vcount ++;
770 }
771 }
772
773 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
774
775 wfProfileOut( $fname );
776 return $content_actions;
777 }
778
779
780
781 /**
782 * build array of common navigation links
783 * @return array
784 * @private
785 */
786 function buildNavUrls () {
787 global $wgUseTrackbacks, $wgTitle, $wgArticle;
788
789 $fname = 'SkinTemplate::buildNavUrls';
790 wfProfileIn( $fname );
791
792 global $wgUser, $wgRequest;
793 global $wgEnableUploads, $wgUploadNavigationUrl;
794
795 $action = $wgRequest->getText( 'action' );
796 $oldid = $wgRequest->getVal( 'oldid' );
797 $diff = $wgRequest->getVal( 'diff' );
798
799 $nav_urls = array();
800 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
801 if( $wgEnableUploads ) {
802 if ($wgUploadNavigationUrl) {
803 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
804 } else {
805 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
806 }
807 } else {
808 if ($wgUploadNavigationUrl)
809 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
810 else
811 $nav_urls['upload'] = false;
812 }
813 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
814
815
816 // A print stylesheet is attached to all pages, but nobody ever
817 // figures that out. :) Add a link...
818 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
819 $revid = $wgArticle->getLatest();
820 if ( !( $revid == 0 ) )
821 $nav_urls['print'] = array(
822 'text' => wfMsg( 'printableversion' ),
823 'href' => $wgRequest->appendQuery( 'printable=yes' )
824 );
825
826 // Also add a "permalink" while we're at it
827 if ( (int)$oldid ) {
828 $nav_urls['permalink'] = array(
829 'text' => wfMsg( 'permalink' ),
830 'href' => ''
831 );
832 } else {
833 if ( !( $revid == 0 ) )
834 $nav_urls['permalink'] = array(
835 'text' => wfMsg( 'permalink' ),
836 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
837 );
838 }
839
840 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
841 }
842
843 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
844 $wlhTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
845 $nav_urls['whatlinkshere'] = array(
846 'href' => $wlhTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
847 );
848 if( $this->mTitle->getArticleId() ) {
849 $rclTitle = Title::makeTitle( NS_SPECIAL, 'Recentchangeslinked' );
850 $nav_urls['recentchangeslinked'] = array(
851 'href' => $rclTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
852 );
853 }
854 if ($wgUseTrackbacks)
855 $nav_urls['trackbacklink'] = array(
856 'href' => $wgTitle->trackbackURL()
857 );
858 }
859
860 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
861 $id = User::idFromName($this->mTitle->getText());
862 $ip = User::isIP($this->mTitle->getText());
863 } else {
864 $id = 0;
865 $ip = false;
866 }
867
868 if($id || $ip) { # both anons and non-anons have contri list
869 $nav_urls['contributions'] = array(
870 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
871 );
872 if ( $wgUser->isAllowed( 'block' ) )
873 $nav_urls['blockip'] = array(
874 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
875 );
876 } else {
877 $nav_urls['contributions'] = false;
878 }
879 $nav_urls['emailuser'] = false;
880 if( $this->showEmailUser( $id ) ) {
881 $nav_urls['emailuser'] = array(
882 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
883 );
884 }
885 wfProfileOut( $fname );
886 return $nav_urls;
887 }
888
889 /**
890 * Generate strings used for xml 'id' names
891 * @return string
892 * @private
893 */
894 function getNameSpaceKey () {
895 return $this->mTitle->getNamespaceKey();
896 }
897
898 /**
899 * @private
900 */
901 function setupUserCss() {
902 $fname = 'SkinTemplate::setupUserCss';
903 wfProfileIn( $fname );
904
905 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
906
907 $sitecss = '';
908 $usercss = '';
909 $siteargs = '&maxage=' . $wgSquidMaxage;
910
911 # Add user-specific code if this is a user and we allow that kind of thing
912
913 if ( $wgAllowUserCss && $this->loggedin ) {
914 $action = $wgRequest->getText('action');
915
916 # if we're previewing the CSS page, use it
917 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
918 $siteargs = "&smaxage=0&maxage=0";
919 $usercss = $wgRequest->getText('wpTextbox1');
920 } else {
921 $usercss = '@import "' .
922 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
923 'action=raw&ctype=text/css') . '";' ."\n";
924 }
925
926 $siteargs .= '&ts=' . $wgUser->mTouched;
927 }
928
929 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
930
931 # If we use the site's dynamic CSS, throw that in, too
932 if ( $wgUseSiteCss ) {
933 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
934 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
935 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', $query, NS_MEDIAWIKI) . '";' . "\n";
936 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
937 }
938
939 # If we use any dynamic CSS, make a little CDATA block out of it.
940
941 if ( !empty($sitecss) || !empty($usercss) ) {
942 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
943 }
944 wfProfileOut( $fname );
945 }
946
947 /**
948 * @private
949 */
950 function setupUserJs() {
951 $fname = 'SkinTemplate::setupUserJs';
952 wfProfileIn( $fname );
953
954 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
955 $action = $wgRequest->getText('action');
956
957 if( $wgAllowUserJs && $this->loggedin ) {
958 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
959 # XXX: additional security check/prompt?
960 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
961 } else {
962 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
963 }
964 }
965 wfProfileOut( $fname );
966 }
967
968 /**
969 * Code for extensions to hook into to provide per-page CSS, see
970 * extensions/PageCSS/PageCSS.php for an implementation of this.
971 *
972 * @private
973 */
974 function setupPageCss() {
975 $fname = 'SkinTemplate::setupPageCss';
976 wfProfileIn( $fname );
977 $out = false;
978 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
979
980 wfProfileOut( $fname );
981 return $out;
982 }
983
984 /**
985 * returns css with user-specific options
986 * @public
987 */
988
989 function getUserStylesheet() {
990 $fname = 'SkinTemplate::getUserStylesheet';
991 wfProfileIn( $fname );
992
993 $s = "/* generated user stylesheet */\n";
994 $s .= $this->reallyDoGetUserStyles();
995 wfProfileOut( $fname );
996 return $s;
997 }
998
999 /**
1000 * @public
1001 */
1002 function getUserJs() {
1003 $fname = 'SkinTemplate::getUserJs';
1004 wfProfileIn( $fname );
1005
1006 global $wgStylePath;
1007 $s = '/* generated javascript */';
1008 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1009 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
1010
1011 // avoid inclusion of non defined user JavaScript (with custom skins only)
1012 // by checking for default message content
1013 $msgKey = ucfirst($this->skinname).'.js';
1014 $userJS = wfMsg($msgKey);
1015 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
1016 $s .= $userJS;
1017 }
1018
1019 wfProfileOut( $fname );
1020 return $s;
1021 }
1022 }
1023
1024 /**
1025 * Generic wrapper for template functions, with interface
1026 * compatible with what we use of PHPTAL 0.7.
1027 * @package MediaWiki
1028 * @subpackage Skins
1029 */
1030 class QuickTemplate {
1031 /**
1032 * @public
1033 */
1034 function QuickTemplate() {
1035 $this->data = array();
1036 $this->translator = new MediaWiki_I18N();
1037 }
1038
1039 /**
1040 * @public
1041 */
1042 function set( $name, $value ) {
1043 $this->data[$name] = $value;
1044 }
1045
1046 /**
1047 * @public
1048 */
1049 function setRef($name, &$value) {
1050 $this->data[$name] =& $value;
1051 }
1052
1053 /**
1054 * @public
1055 */
1056 function setTranslator( &$t ) {
1057 $this->translator = &$t;
1058 }
1059
1060 /**
1061 * @public
1062 */
1063 function execute() {
1064 echo "Override this function.";
1065 }
1066
1067
1068 /**
1069 * @private
1070 */
1071 function text( $str ) {
1072 echo htmlspecialchars( $this->data[$str] );
1073 }
1074
1075 /**
1076 * @private
1077 */
1078 function jstext( $str ) {
1079 echo Xml::escapeJsString( $this->data[$str] );
1080 }
1081
1082 /**
1083 * @private
1084 */
1085 function html( $str ) {
1086 echo $this->data[$str];
1087 }
1088
1089 /**
1090 * @private
1091 */
1092 function msg( $str ) {
1093 echo htmlspecialchars( $this->translator->translate( $str ) );
1094 }
1095
1096 /**
1097 * @private
1098 */
1099 function msgHtml( $str ) {
1100 echo $this->translator->translate( $str );
1101 }
1102
1103 /**
1104 * An ugly, ugly hack.
1105 * @private
1106 */
1107 function msgWiki( $str ) {
1108 global $wgParser, $wgTitle, $wgOut;
1109
1110 $text = $this->translator->translate( $str );
1111 $parserOutput = $wgParser->parse( $text, $wgTitle,
1112 $wgOut->parserOptions(), true );
1113 echo $parserOutput->getText();
1114 }
1115
1116 /**
1117 * @private
1118 */
1119 function haveData( $str ) {
1120 return $this->data[$str];
1121 }
1122
1123 /**
1124 * @private
1125 */
1126 function haveMsg( $str ) {
1127 $msg = $this->translator->translate( $str );
1128 return ($msg != '-') && ($msg != ''); # ????
1129 }
1130 }
1131 ?>