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