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