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