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