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