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