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