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