cbf9b14c392c14bd63a6700ac5bfeb0c7dd32c2e
[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 * Create the template engine object; we feed it a bunch of data
104 * and eventually it spits out some HTML. Should have interface
105 * roughly equivalent to PHPTAL 0.7.
106 *
107 * @param $callback string (or file)
108 * @param $repository string: subdirectory where we keep template files
109 * @param $cache_dir string
110 * @return object
111 * @private
112 */
113 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
114 return new $classname();
115 }
116
117 /**
118 * initialize various variables and generate the template
119 *
120 * @param $out OutputPage
121 */
122 function outputPage( OutputPage $out ) {
123 global $wgArticle, $wgUser, $wgLang, $wgContLang;
124 global $wgScript, $wgStylePath, $wgContLanguageCode;
125 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
126 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
127 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
128 global $wgMaxCredits, $wgShowCreditsIfMax;
129 global $wgPageShowWatchingUsers;
130 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
131 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
132
133 wfProfileIn( __METHOD__ );
134
135 $oldid = $wgRequest->getVal( 'oldid' );
136 $diff = $wgRequest->getVal( 'diff' );
137 $action = $wgRequest->getVal( 'action', 'view' );
138
139 wfProfileIn( __METHOD__ . '-init' );
140 $this->initPage( $out );
141
142 $this->setMembers();
143 $tpl = $this->setupTemplate( $this->template, 'skins' );
144
145 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
146 $tpl->setTranslator( new MediaWiki_I18N() );
147 #}
148 wfProfileOut( __METHOD__ . '-init' );
149
150 wfProfileIn( __METHOD__ . '-stuff' );
151 $this->thispage = $this->mTitle->getPrefixedDBkey();
152 $this->thisurl = $this->mTitle->getPrefixedURL();
153 $query = array();
154 if ( !$wgRequest->wasPosted() ) {
155 $query = $wgRequest->getValues();
156 unset( $query['title'] );
157 unset( $query['returnto'] );
158 unset( $query['returntoquery'] );
159 }
160 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
161 $this->loggedin = $wgUser->isLoggedIn();
162 $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
163 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
164 $this->username = $wgUser->getName();
165
166 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
167 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
168 } else {
169 # This won't be used in the standard skins, but we define it to preserve the interface
170 # To save time, we check for existence
171 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
172 }
173
174 $this->userjs = $this->userjsprev = false;
175 $this->setupUserCss( $out );
176 $this->setupUserJs( $out->isUserJsAllowed() );
177 $this->titletxt = $this->mTitle->getPrefixedText();
178 wfProfileOut( __METHOD__ . '-stuff' );
179
180 wfProfileIn( __METHOD__ . '-stuff2' );
181 $tpl->set( 'title', $out->getPageTitle() );
182 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
183 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
184 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
185 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
186
187 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
188 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
189 $this->mTitle->getNsText();
190
191 $tpl->set( 'nscanonical', $nsname );
192 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
193 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
194 $tpl->set( 'titletext', $this->mTitle->getText() );
195 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
196 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
197
198 $tpl->set( 'isarticle', $out->isArticle() );
199
200 $tpl->setRef( 'thispage', $this->thispage );
201 $subpagestr = $this->subPageSubtitle();
202 $tpl->set(
203 'subtitle', !empty( $subpagestr ) ?
204 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
205 $out->getSubtitle()
206 );
207 $undelete = $this->getUndeleteLink();
208 $tpl->set(
209 'undelete', !empty( $undelete ) ?
210 '<span class="subpages">'.$undelete.'</span>' :
211 ''
212 );
213
214 $tpl->set( 'catlinks', $this->getCategories() );
215 if( $out->isSyndicated() ) {
216 $feeds = array();
217 foreach( $out->getSyndicationLinks() as $format => $link ) {
218 $feeds[$format] = array(
219 'text' => wfMsg( "feed-$format" ),
220 'href' => $link
221 );
222 }
223 $tpl->setRef( 'feeds', $feeds );
224 } else {
225 $tpl->set( 'feeds', false );
226 }
227 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
228 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
229 } else {
230 $tpl->set( 'trackbackhtml', null );
231 }
232
233 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
234 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
235 $tpl->setRef( 'mimetype', $wgMimeType );
236 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
237 $tpl->setRef( 'charset', $wgOutputEncoding );
238 $tpl->set( 'headlinks', $out->getHeadLinks() );
239 $tpl->set( 'csslinks', $out->buildCssLinks() );
240 $tpl->setRef( 'wgScript', $wgScript );
241 $tpl->setRef( 'skinname', $this->skinname );
242 $tpl->set( 'skinclass', get_class( $this ) );
243 $tpl->setRef( 'stylename', $this->stylename );
244 $tpl->set( 'printable', $out->isPrintable() );
245 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
246 $tpl->setRef( 'loggedin', $this->loggedin );
247 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
248 /* XXX currently unused, might get useful later
249 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
250 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
251 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
252 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
253 $tpl->set( "helppage", wfMsg('helppage'));
254 */
255 $tpl->set( 'searchaction', $this->escapeSearchLink() );
256 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
257 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
258 $tpl->setRef( 'stylepath', $wgStylePath );
259 $tpl->setRef( 'articlepath', $wgArticlePath );
260 $tpl->setRef( 'scriptpath', $wgScriptPath );
261 $tpl->setRef( 'serverurl', $wgServer );
262 $tpl->setRef( 'logopath', $wgLogo );
263 $tpl->setRef( 'lang', $wgContLanguageCode );
264 $tpl->set( 'dir', $wgContLang->getDir() );
265 $tpl->set( 'rtl', $wgContLang->isRTL() );
266 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
267 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
268 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
269 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
270 $tpl->setRef( 'userpage', $this->userpage );
271 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
272 $tpl->set( 'userlang', $wgLang->getCode() );
273 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
274 $tpl->set( 'pagecss', $this->setupPageCss() );
275 $tpl->setRef( 'usercss', $this->usercss );
276 $tpl->setRef( 'userjs', $this->userjs );
277 $tpl->setRef( 'userjsprev', $this->userjsprev );
278 if( $wgUseSiteJs ) {
279 $jsCache = $this->loggedin ? '&smaxage=0' : '';
280 $tpl->set( 'jsvarurl',
281 self::makeUrl( '-',
282 "action=raw$jsCache&gen=js&useskin=" .
283 urlencode( $this->getSkinName() ) ) );
284 } else {
285 $tpl->set( 'jsvarurl', false );
286 }
287
288 $newtalks = $wgUser->getNewMessageLinks();
289
290 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
291 $usertitle = $this->mUser->getUserPage();
292 $usertalktitle = $usertitle->getTalkPage();
293
294 if( !$usertalktitle->equals( $this->mTitle ) ) {
295 $newmessageslink = $this->link(
296 $usertalktitle,
297 wfMsgHtml( 'newmessageslink' ),
298 array(),
299 array( 'redirect' => 'no' ),
300 array( 'known', 'noclasses' )
301 );
302
303 $newmessagesdifflink = $this->link(
304 $usertalktitle,
305 wfMsgHtml( 'newmessagesdifflink' ),
306 array(),
307 array( 'diff' => 'cur' ),
308 array( 'known', 'noclasses' )
309 );
310
311 $ntl = wfMsg(
312 'youhavenewmessages',
313 $newmessageslink,
314 $newmessagesdifflink
315 );
316 # Disable Cache
317 $out->setSquidMaxage( 0 );
318 }
319 } else if( count( $newtalks ) ) {
320 // _>" " for BC <= 1.16
321 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
322 $msgs = array();
323 foreach( $newtalks as $newtalk ) {
324 $msgs[] = Xml::element('a',
325 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
326 }
327 $parts = implode( $sep, $msgs );
328 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
329 $out->setSquidMaxage( 0 );
330 } else {
331 $ntl = '';
332 }
333 wfProfileOut( __METHOD__ . '-stuff2' );
334
335 wfProfileIn( __METHOD__ . '-stuff3' );
336 $tpl->setRef( 'newtalk', $ntl );
337 $tpl->setRef( 'skin', $this );
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
340 $wgArticle and 0 != $wgArticle->getID() ){
341 if ( !$wgDisableCounters ) {
342 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
343 if ( $viewcount ) {
344 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
345 } else {
346 $tpl->set( 'viewcount', false );
347 }
348 } else {
349 $tpl->set( 'viewcount', false );
350 }
351
352 if( $wgPageShowWatchingUsers ) {
353 $dbr = wfGetDB( DB_SLAVE );
354 $watchlist = $dbr->tableName( 'watchlist' );
355 $res = $dbr->select( 'watchlist',
356 array( 'COUNT(*) AS n' ),
357 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
358 __METHOD__
359 );
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n;
362 if( $numberofwatchingusers > 0 ) {
363 $tpl->set( 'numberofwatchingusers',
364 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
365 $wgLang->formatNum( $numberofwatchingusers ) )
366 );
367 } else {
368 $tpl->set( 'numberofwatchingusers', false );
369 }
370 } else {
371 $tpl->set( 'numberofwatchingusers', false );
372 }
373
374 $tpl->set( 'copyright', $this->getCopyright() );
375
376 $this->credits = false;
377
378 if( $wgMaxCredits != 0 ){
379 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
380 } else {
381 $tpl->set( 'lastmod', $this->lastModified() );
382 }
383
384 $tpl->setRef( 'credits', $this->credits );
385
386 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
387 $tpl->set( 'copyright', $this->getCopyright() );
388 $tpl->set( 'viewcount', false );
389 $tpl->set( 'lastmod', false );
390 $tpl->set( 'credits', false );
391 $tpl->set( 'numberofwatchingusers', false );
392 } else {
393 $tpl->set( 'copyright', false );
394 $tpl->set( 'viewcount', false );
395 $tpl->set( 'lastmod', false );
396 $tpl->set( 'credits', false );
397 $tpl->set( 'numberofwatchingusers', false );
398 }
399 wfProfileOut( __METHOD__ . '-stuff3' );
400
401 wfProfileIn( __METHOD__ . '-stuff4' );
402 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
403 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
404 $tpl->set( 'disclaimer', $this->disclaimerLink() );
405 $tpl->set( 'privacy', $this->privacyLink() );
406 $tpl->set( 'about', $this->aboutLink() );
407
408 if ( $wgDebugComments ) {
409 $tpl->setRef( 'debug', $out->mDebugtext );
410 } else {
411 $tpl->set( 'debug', '' );
412 }
413
414 $tpl->set( 'reporttime', wfReportTime() );
415 $tpl->set( 'sitenotice', wfGetSiteNotice() );
416 $tpl->set( 'bottomscripts', $this->bottomScripts() );
417
418 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
419 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
420 $tpl->setRef( 'bodytext', $out->mBodytext );
421
422 # Language links
423 $language_urls = array();
424
425 if ( !$wgHideInterlanguageLinks ) {
426 foreach( $out->getLanguageLinks() as $l ) {
427 $tmp = explode( ':', $l, 2 );
428 $class = 'interwiki-' . $tmp[0];
429 unset( $tmp );
430 $nt = Title::newFromText( $l );
431 if ( $nt ) {
432 $language_urls[] = array(
433 'href' => $nt->getFullURL(),
434 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
435 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
436 'class' => $class
437 );
438 }
439 }
440 }
441 if( count( $language_urls ) ) {
442 $tpl->setRef( 'language_urls', $language_urls );
443 } else {
444 $tpl->set( 'language_urls', false );
445 }
446 wfProfileOut( __METHOD__ . '-stuff4' );
447
448 wfProfileIn( __METHOD__ . '-stuff5' );
449 # Personal toolbar
450 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
451 $content_actions = $this->buildContentActionUrls();
452 $tpl->setRef( 'content_actions', $content_actions );
453
454 // XXX: attach this from javascript, same with section editing
455 if( $this->iseditable && $wgUser->getOption( 'editondblclick' ) ){
456 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
457 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
458 } else {
459 $tpl->set( 'body_ondblclick', false );
460 }
461 $tpl->set( 'body_onload', false );
462 $tpl->set( 'sidebar', $this->buildSidebar() );
463 $tpl->set( 'nav_urls', $this->buildNavUrls() );
464
465 // Set the head scripts near the end, in case the above actions resulted in added scripts
466 $tpl->set( 'headscripts', $out->getScript() );
467
468 // original version by hansm
469 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
470 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
471 }
472
473 // allow extensions adding stuff after the page content.
474 // See Skin::afterContentHook() for further documentation.
475 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
476 wfProfileOut( __METHOD__ . '-stuff5' );
477
478 // execute template
479 wfProfileIn( __METHOD__ . '-execute' );
480 $res = $tpl->execute();
481 wfProfileOut( __METHOD__ . '-execute' );
482
483 // result may be an error
484 $this->printOrError( $res );
485 wfProfileOut( __METHOD__ );
486 }
487
488 /**
489 * Output the string, or print error message if it's
490 * an error object of the appropriate type.
491 * For the base class, assume strings all around.
492 *
493 * @param mixed $str
494 * @private
495 */
496 function printOrError( $str ) {
497 echo $str;
498 }
499
500 /**
501 * build array of urls for personal toolbar
502 * @return array
503 * @private
504 */
505 function buildPersonalUrls() {
506 global $wgOut, $wgRequest;
507
508 $title = $wgOut->getTitle();
509 $pageurl = $title->getLocalURL();
510 wfProfileIn( __METHOD__ );
511
512 /* set up the default links for the personal toolbar */
513 $personal_urls = array();
514 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
515 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
516 $returnto = "returnto=$page";
517 if( $this->thisquery != '' )
518 $returnto .= "&returntoquery=$query";
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
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 ),
599 'active' => $title->isSpecial( 'Userlogin' )
600 );
601 } else {
602 $personal_urls['login'] = array(
603 'text' => wfMsg( $loginlink ),
604 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
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 ( !$wgOut->isPrintable() ) {
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 abstract 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 abstract public function execute();
1075
1076 /**
1077 * @private
1078 */
1079 function text( $str ) {
1080 echo htmlspecialchars( $this->data[$str] );
1081 }
1082
1083 /**
1084 * @private
1085 */
1086 function jstext( $str ) {
1087 echo Xml::escapeJsString( $this->data[$str] );
1088 }
1089
1090 /**
1091 * @private
1092 */
1093 function html( $str ) {
1094 echo $this->data[$str];
1095 }
1096
1097 /**
1098 * @private
1099 */
1100 function msg( $str ) {
1101 echo htmlspecialchars( $this->translator->translate( $str ) );
1102 }
1103
1104 /**
1105 * @private
1106 */
1107 function msgHtml( $str ) {
1108 echo $this->translator->translate( $str );
1109 }
1110
1111 /**
1112 * An ugly, ugly hack.
1113 * @private
1114 */
1115 function msgWiki( $str ) {
1116 global $wgParser, $wgOut;
1117
1118 $text = $this->translator->translate( $str );
1119 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1120 $wgOut->parserOptions(), true );
1121 echo $parserOutput->getText();
1122 }
1123
1124 /**
1125 * @private
1126 */
1127 function haveData( $str ) {
1128 return isset( $this->data[$str] );
1129 }
1130
1131 /**
1132 * @private
1133 */
1134 function haveMsg( $str ) {
1135 $msg = $this->translator->translate( $str );
1136 return ( $msg != '-' ) && ( $msg != '' ); # ????
1137 }
1138 }