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