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