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