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