Forgot to commit Skin.php part
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2 /**
3 * @defgroup Skins Skins
4 */
5
6 if ( ! defined( 'MEDIAWIKI' ) )
7 die( 1 );
8
9 /**
10 * The main skin class that provide methods and properties for all other skins.
11 * This base class is also the "Standard" skin.
12 *
13 * See docs/skin.txt for more information.
14 *
15 * @ingroup Skins
16 */
17 class Skin extends Linker {
18 /**#@+
19 * @private
20 */
21 var $mWatchLinkNum = 0; // Appended to end of watch link id's
22 // How many search boxes have we made? Avoid duplicate id's.
23 protected $searchboxes = '';
24 /**#@-*/
25 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
26 protected $skinname = 'standard' ;
27
28 /** Constructor, call parent constructor */
29 function Skin() { parent::__construct(); }
30
31 /**
32 * Fetch the set of available skins.
33 * @return array of strings
34 * @static
35 */
36 static function getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
43 #
44 wfProfileIn( __METHOD__ . '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
47
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
51 $matches = array();
52 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
53 $aSkin = $matches[1];
54 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
55 }
56 }
57 $skinDir->close();
58 $skinsInitialised = true;
59 wfProfileOut( __METHOD__ . '-init' );
60 }
61 return $wgValidSkinNames;
62 }
63
64 /**
65 * Fetch the list of usable skins in regards to $wgSkipSkins.
66 * Useful for Special:Preferences and other places where you
67 * only want to show skins users _can_ use.
68 * @return array of strings
69 */
70 public static function getUsableSkins() {
71 global $wgSkipSkins;
72 $usableSkins = self::getSkinNames();
73 foreach ( $wgSkipSkins as $skip ) {
74 unset( $usableSkins[$skip] );
75 }
76 return $usableSkins;
77 }
78
79 /**
80 * Normalize a skin preference value to a form that can be loaded.
81 * If a skin can't be found, it will fall back to the configured
82 * default (or the old 'Classic' skin if that's broken).
83 * @param string $key
84 * @return string
85 * @static
86 */
87 static function normalizeKey( $key ) {
88 global $wgDefaultSkin;
89 $skinNames = Skin::getSkinNames();
90
91 if( $key == '' ) {
92 // Don't return the default immediately;
93 // in a misconfiguration we need to fall back.
94 $key = $wgDefaultSkin;
95 }
96
97 if( isset( $skinNames[$key] ) ) {
98 return $key;
99 }
100
101 // Older versions of the software used a numeric setting
102 // in the user preferences.
103 $fallback = array(
104 0 => $wgDefaultSkin,
105 1 => 'nostalgia',
106 2 => 'cologneblue' );
107
108 if( isset( $fallback[$key] ) ){
109 $key = $fallback[$key];
110 }
111
112 if( isset( $skinNames[$key] ) ) {
113 return $key;
114 } else {
115 return 'monobook';
116 }
117 }
118
119 /**
120 * Factory method for loading a skin of a given type
121 * @param string $key 'monobook', 'standard', etc
122 * @return Skin
123 * @static
124 */
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
127
128 $key = Skin::normalizeKey( $key );
129
130 $skinNames = Skin::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = 'Skin'.ucfirst($key);
133
134 # Grab the skin class and initialise it.
135 if ( !class_exists( $className ) ) {
136 // Preload base classes to work around APC/PHP5 bug
137 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
138 if( file_exists( $deps ) ) include_once( $deps );
139 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
140
141 # Check if we got if not failback to default skin
142 if( !class_exists( $className ) ) {
143 # DO NOT die if the class isn't found. This breaks maintenance
144 # scripts and can cause a user account to be unrecoverable
145 # except by SQL manipulation if a previously valid skin name
146 # is no longer valid.
147 wfDebug( "Skin class does not exist: $className\n" );
148 $className = 'SkinMonobook';
149 require_once( "{$wgStyleDirectory}/MonoBook.php" );
150 }
151 }
152 $skin = new $className;
153 return $skin;
154 }
155
156 /** @return string path to the skin stylesheet */
157 function getStylesheet() {
158 return 'common/wikistandard.css';
159 }
160
161 /** @return string skin name */
162 public function getSkinName() {
163 return $this->skinname;
164 }
165
166 function qbSetting() {
167 global $wgOut, $wgUser;
168
169 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
170 $q = $wgUser->getOption( 'quickbar', 0 );
171 return $q;
172 }
173
174 function initPage( OutputPage $out ) {
175 global $wgFavicon, $wgAppleTouchIcon;
176
177 wfProfileIn( __METHOD__ );
178
179 # Generally the order of the favicon and apple-touch-icon links
180 # should not matter, but Konqueror (3.5.9 at least) incorrectly
181 # uses whichever one appears later in the HTML source. Make sure
182 # apple-touch-icon is specified first to avoid this.
183 if( false !== $wgAppleTouchIcon ) {
184 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
185 }
186
187 if( false !== $wgFavicon ) {
188 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
189 }
190
191 # OpenSearch description link
192 $out->addLink( array(
193 'rel' => 'search',
194 'type' => 'application/opensearchdescription+xml',
195 'href' => wfScript( 'opensearch_desc' ),
196 'title' => wfMsgForContent( 'opensearch-desc' ),
197 ));
198
199 $this->addMetadataLinks($out);
200
201 $this->mRevisionId = $out->mRevisionId;
202
203 $this->preloadExistence();
204
205 wfProfileOut( __METHOD__ );
206 }
207
208 /**
209 * Preload the existence of three commonly-requested pages in a single query
210 */
211 function preloadExistence() {
212 global $wgUser, $wgTitle;
213
214 // User/talk link
215 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
216
217 // Other tab link
218 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
219 // nothing
220 } elseif ( $wgTitle->isTalkPage() ) {
221 $titles[] = $wgTitle->getSubjectPage();
222 } else {
223 $titles[] = $wgTitle->getTalkPage();
224 }
225
226 $lb = new LinkBatch( $titles );
227 $lb->execute();
228 }
229
230 function addMetadataLinks( OutputPage $out ) {
231 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
232 global $wgRightsPage, $wgRightsUrl;
233
234 if( $out->isArticleRelated() ) {
235 # note: buggy CC software only reads first "meta" link
236 if( $wgEnableCreativeCommonsRdf ) {
237 $out->addMetadataLink( array(
238 'title' => 'Creative Commons',
239 'type' => 'application/rdf+xml',
240 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
241 }
242 if( $wgEnableDublinCoreRdf ) {
243 $out->addMetadataLink( array(
244 'title' => 'Dublin Core',
245 'type' => 'application/rdf+xml',
246 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
247 }
248 }
249 $copyright = '';
250 if( $wgRightsPage ) {
251 $copy = Title::newFromText( $wgRightsPage );
252 if( $copy ) {
253 $copyright = $copy->getLocalURL();
254 }
255 }
256 if( !$copyright && $wgRightsUrl ) {
257 $copyright = $wgRightsUrl;
258 }
259 if( $copyright ) {
260 $out->addLink( array(
261 'rel' => 'copyright',
262 'href' => $copyright ) );
263 }
264 }
265
266 function setMembers(){
267 global $wgTitle, $wgUser;
268 $this->mTitle = $wgTitle;
269 $this->mUser = $wgUser;
270 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
271 $this->usercss = false;
272 }
273
274 function outputPage( OutputPage $out ) {
275 global $wgDebugComments;
276 wfProfileIn( __METHOD__ );
277
278 $this->setMembers();
279 $this->initPage( $out );
280
281 // See self::afterContentHook() for documentation
282 $afterContent = $this->afterContentHook();
283
284 $out->out( $out->headElement( $this ) );
285
286 $out->out( "\n<body" );
287 $ops = $this->getBodyOptions();
288 foreach ( $ops as $name => $val ) {
289 $out->out( " $name='$val'" );
290 }
291 $out->out( ">\n" );
292 if ( $wgDebugComments ) {
293 $out->out( "<!-- Wiki debugging output:\n" .
294 $out->mDebugtext . "-->\n" );
295 }
296
297 $out->out( $this->beforeContent() );
298
299 $out->out( $out->mBodytext . "\n" );
300
301 $out->out( $this->afterContent() );
302
303 $out->out( $afterContent );
304
305 $out->out( $this->bottomScripts() );
306
307 $out->out( wfReportTime() );
308
309 $out->out( "\n</body></html>" );
310 wfProfileOut( __METHOD__ );
311 }
312
313 static function makeVariablesScript( $data ) {
314 global $wgJsMimeType;
315
316 $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
317 foreach ( $data as $name => $value ) {
318 $encValue = Xml::encodeJsVar( $value );
319 $r[] = "var $name = $encValue;";
320 }
321 $r[] = "/*]]>*/</script>\n";
322
323 return implode( "\n\t\t", $r );
324 }
325
326 /**
327 * Make a <script> tag containing global variables
328 * @param array $data Associative array containing one element:
329 * skinname => the skin name
330 * The odd calling convention is for backwards compatibility
331 */
332 static function makeGlobalVariablesScript( $data ) {
333 global $wgScript, $wgStylePath, $wgUser;
334 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
335 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
336 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
337 global $wgUseAjax, $wgAjaxWatch;
338 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
339 global $wgRestrictionTypes, $wgLivePreview;
340 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
341
342 $ns = $wgTitle->getNamespace();
343 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
344 $separatorTransTable = $wgContLang->separatorTransformTable();
345 $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
346 $compactSeparatorTransTable = array(
347 implode( "\t", array_keys( $separatorTransTable ) ),
348 implode( "\t", $separatorTransTable ),
349 );
350 $digitTransTable = $wgContLang->digitTransformTable();
351 $digitTransTable = $digitTransTable ? $digitTransTable : array();
352 $compactDigitTransTable = array(
353 implode( "\t", array_keys( $digitTransTable ) ),
354 implode( "\t", $digitTransTable ),
355 );
356
357 $vars = array(
358 'skin' => $data['skinname'],
359 'stylepath' => $wgStylePath,
360 'wgArticlePath' => $wgArticlePath,
361 'wgScriptPath' => $wgScriptPath,
362 'wgScript' => $wgScript,
363 'wgVariantArticlePath' => $wgVariantArticlePath,
364 'wgActionPaths' => (object)$wgActionPaths,
365 'wgServer' => $wgServer,
366 'wgCanonicalNamespace' => $nsname,
367 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
368 'wgNamespaceNumber' => $wgTitle->getNamespace(),
369 'wgPageName' => $wgTitle->getPrefixedDBKey(),
370 'wgTitle' => $wgTitle->getText(),
371 'wgAction' => $wgRequest->getText( 'action', 'view' ),
372 'wgArticleId' => $wgTitle->getArticleId(),
373 'wgIsArticle' => $wgOut->isArticle(),
374 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
375 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
376 'wgUserLanguage' => $wgLang->getCode(),
377 'wgContentLanguage' => $wgContLang->getCode(),
378 'wgBreakFrames' => $wgBreakFrames,
379 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
380 'wgVersion' => $wgVersion,
381 'wgEnableAPI' => $wgEnableAPI,
382 'wgEnableWriteAPI' => $wgEnableWriteAPI,
383 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
384 'wgDigitTransformTable' => $compactDigitTransTable,
385 );
386
387 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
388 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
389 $vars['wgDBname'] = $wgDBname;
390 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
391 $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
392 }
393
394 foreach( $wgRestrictionTypes as $type )
395 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
396
397 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
398 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
399 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
400 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
401 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
402 }
403
404 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
405 $msgs = (object)array();
406 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
407 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
408 }
409 $vars['wgAjaxWatch'] = $msgs;
410 }
411
412 wfRunHooks('MakeGlobalVariablesScript', array(&$vars));
413
414 return self::makeVariablesScript( $vars );
415 }
416
417 function getHeadScripts( $allowUserJs ) {
418 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
419
420 $vars = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
421
422 $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
423 global $wgUseSiteJs;
424 if ($wgUseSiteJs) {
425 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
426 $r[] = "<script type=\"$wgJsMimeType\" src=\"".
427 htmlspecialchars(self::makeUrl('-',
428 "action=raw$jsCache&gen=js&useskin=" .
429 urlencode( $this->getSkinName() ) ) ) .
430 "\"><!-- site js --></script>";
431 }
432 if( $allowUserJs && $wgUser->isLoggedIn() ) {
433 $userpage = $wgUser->getUserPage();
434 $userjs = htmlspecialchars( self::makeUrl(
435 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
436 'action=raw&ctype='.$wgJsMimeType));
437 $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
438 }
439 return $vars . "\t\t" . implode ( "\n\t\t", $r );
440 }
441
442 /**
443 * To make it harder for someone to slip a user a fake
444 * user-JavaScript or user-CSS preview, a random token
445 * is associated with the login session. If it's not
446 * passed back with the preview request, we won't render
447 * the code.
448 *
449 * @param string $action
450 * @return bool
451 * @private
452 */
453 function userCanPreview( $action ) {
454 global $wgTitle, $wgRequest, $wgUser;
455
456 if( $action != 'submit' )
457 return false;
458 if( !$wgRequest->wasPosted() )
459 return false;
460 if( !$wgTitle->userCanEditCssJsSubpage() )
461 return false;
462 return $wgUser->matchEditToken(
463 $wgRequest->getVal( 'wpEditToken' ) );
464 }
465
466 /**
467 * generated JavaScript action=raw&gen=js
468 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
469 * nated together. For some bizarre reason, it does *not* return any
470 * custom user JS from subpages. Huh?
471 *
472 * There's absolutely no reason to have separate Monobook/Common JSes.
473 * Any JS that cares can just check the skin variable generated at the
474 * top. For now Monobook.js will be maintained, but it should be consi-
475 * dered deprecated.
476 *
477 * @return string
478 */
479 public function generateUserJs() {
480 global $wgStylePath;
481
482 wfProfileIn( __METHOD__ );
483
484 $s = "/* generated javascript */\n";
485 $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
486 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
487 $s .= "\n\n/* MediaWiki:Common.js */\n";
488 $commonJs = wfMsgForContent('common.js');
489 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
490 $s .= $commonJs;
491 }
492
493 $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n";
494 // avoid inclusion of non defined user JavaScript (with custom skins only)
495 // by checking for default message content
496 $msgKey = ucfirst( $this->getSkinName() ).'.js';
497 $userJS = wfMsgForContent($msgKey);
498 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
499 $s .= $userJS;
500 }
501
502 wfProfileOut( __METHOD__ );
503 return $s;
504 }
505
506 /**
507 * generate user stylesheet for action=raw&gen=css
508 */
509 public function generateUserStylesheet() {
510 wfProfileIn( __METHOD__ );
511 $s = "/* generated user stylesheet */\n" .
512 $this->reallyGenerateUserStylesheet();
513 wfProfileOut( __METHOD__ );
514 return $s;
515 }
516
517 /**
518 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
519 */
520 protected function reallyGenerateUserStylesheet(){
521 global $wgUser;
522 $s = '';
523 if (($undopt = $wgUser->getOption("underline")) < 2) {
524 $underline = $undopt ? 'underline' : 'none';
525 $s .= "a { text-decoration: $underline; }\n";
526 }
527 if( $wgUser->getOption( 'highlightbroken' ) ) {
528 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
529 } else {
530 $s .= <<<END
531 a.new, #quickbar a.new,
532 a.stub, #quickbar a.stub {
533 color: inherit;
534 }
535 a.new:after, #quickbar a.new:after {
536 content: "?";
537 color: #CC2200;
538 }
539 a.stub:after, #quickbar a.stub:after {
540 content: "!";
541 color: #772233;
542 }
543 END;
544 }
545 if( $wgUser->getOption( 'justify' ) ) {
546 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
547 }
548 if( !$wgUser->getOption( 'showtoc' ) ) {
549 $s .= "#toc { display: none; }\n";
550 }
551 if( !$wgUser->getOption( 'editsection' ) ) {
552 $s .= ".editsection { display: none; }\n";
553 }
554 return $s;
555 }
556
557 /**
558 * @private
559 */
560 function setupUserCss( OutputPage $out ) {
561 global $wgRequest, $wgContLang, $wgUser;
562 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
563
564 wfProfileIn( __METHOD__ );
565
566 $this->setupSkinUserCss( $out );
567
568 $siteargs = array(
569 'action' => 'raw',
570 'maxage' => $wgSquidMaxage,
571 );
572
573 // Add any extension CSS
574 foreach( $out->getExtStyle() as $tag ) {
575 $out->addStyle( $tag['href'] );
576 }
577
578 // If we use the site's dynamic CSS, throw that in, too
579 // Per-site custom styles
580 if( $wgUseSiteCss ) {
581 global $wgHandheldStyle;
582 $query = wfArrayToCGI( array(
583 'usemsgcache' => 'yes',
584 'ctype' => 'text/css',
585 'smaxage' => $wgSquidMaxage
586 ) + $siteargs );
587 # Site settings must override extension css! (bug 15025)
588 $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
589 $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
590 if( $wgHandheldStyle ) {
591 $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
592 }
593 $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
594 }
595
596 if( $wgUser->isLoggedIn() ) {
597 // Ensure that logged-in users' generated CSS isn't clobbered
598 // by anons' publicly cacheable generated CSS.
599 $siteargs['smaxage'] = '0';
600 $siteargs['ts'] = $wgUser->mTouched;
601 }
602 // Per-user styles based on preferences
603 $siteargs['gen'] = 'css';
604 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
605 $siteargs['useskin'] = $us;
606 }
607 $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
608
609 // Per-user custom style pages
610 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
611 $action = $wgRequest->getVal('action');
612 # If we're previewing the CSS page, use it
613 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
614 $previewCss = $wgRequest->getText('wpTextbox1');
615 // @FIXME: properly escape the cdata!
616 $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
617 } else {
618 $out->addStyle( self::makeUrl($this->userpage . '/' . $this->getSkinName() .'.css',
619 'action=raw&ctype=text/css' ) );
620 }
621 }
622
623 wfProfileOut( __METHOD__ );
624 }
625
626 /**
627 * Add skin specific stylesheets
628 * @param $out OutputPage
629 */
630 function setupSkinUserCss( OutputPage $out ) {
631 $out->addStyle( 'common/shared.css' );
632 $out->addStyle( 'common/oldshared.css' );
633 $out->addStyle( $this->getStylesheet() );
634 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
635 }
636
637 function getBodyOptions() {
638 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
639
640 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
641
642 if ( 0 != $wgTitle->getNamespace() ) {
643 $a = array( 'bgcolor' => '#ffffec' );
644 }
645 else $a = array( 'bgcolor' => '#FFFFFF' );
646 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
647 $wgTitle->quickUserCan( 'edit' ) ) {
648 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
649 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
650 $a += array ('ondblclick' => $s);
651
652 }
653 $a['onload'] = $wgOut->getOnloadHandler();
654 $a['class'] =
655 'mediawiki' .
656 ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ).
657 ' '.$this->getPageClasses( $wgTitle ) .
658 ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) );
659 return $a;
660 }
661
662 function getPageClasses( $title ) {
663 global $wgArticle;
664 $numeric = 'ns-'.$title->getNamespace();
665 if( $title->getNamespace() == NS_SPECIAL ) {
666 $type = "ns-special";
667 } elseif( $title->isTalkPage() ) {
668 $type = "ns-talk";
669 } else {
670 $type = "ns-subject";
671 }
672 $name = Sanitizer::escapeClass( 'page-'.$title->getPrefixedText() );
673 if( $wgArticle && $wgArticle->isDisambig() )
674 $disambig = ' disambiguationpage';
675 else
676 $disambig = '';
677 return "{$numeric} {$type} {$name}{$disambig}";
678 }
679
680 /**
681 * URL to the logo
682 */
683 function getLogo() {
684 global $wgLogo;
685 return $wgLogo;
686 }
687
688 /**
689 * This will be called immediately after the <body> tag. Split into
690 * two functions to make it easier to subclass.
691 */
692 function beforeContent() {
693 return $this->doBeforeContent();
694 }
695
696 function doBeforeContent() {
697 global $wgContLang;
698 $fname = 'Skin::doBeforeContent';
699 wfProfileIn( $fname );
700
701 $s = '';
702 $qb = $this->qbSetting();
703
704 if( $langlinks = $this->otherLanguages() ) {
705 $rows = 2;
706 $borderhack = '';
707 } else {
708 $rows = 1;
709 $langlinks = false;
710 $borderhack = 'class="top"';
711 }
712
713 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
714 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
715
716 $shove = ( $qb != 0 );
717 $left = ( $qb == 1 || $qb == 3 );
718 if( $wgContLang->isRTL() ) $left = !$left;
719
720 if( !$shove ) {
721 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
722 $this->logoText() . '</td>';
723 } elseif( $left ) {
724 $s .= $this->getQuickbarCompensator( $rows );
725 }
726 $l = $wgContLang->isRTL() ? 'right' : 'left';
727 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
728
729 $s .= $this->topLinks() ;
730 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
731
732 $r = $wgContLang->isRTL() ? "left" : "right";
733 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
734 $s .= $this->nameAndLogin();
735 $s .= "\n<br />" . $this->searchForm() . "</td>";
736
737 if ( $langlinks ) {
738 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
739 }
740
741 if ( $shove && !$left ) { # Right
742 $s .= $this->getQuickbarCompensator( $rows );
743 }
744 $s .= "</tr>\n</table>\n</div>\n";
745 $s .= "\n<div id='article'>\n";
746
747 $notice = wfGetSiteNotice();
748 if( $notice ) {
749 $s .= "\n<div id='siteNotice'>$notice</div>\n";
750 }
751 $s .= $this->pageTitle();
752 $s .= $this->pageSubtitle() ;
753 $s .= $this->getCategories();
754 wfProfileOut( $fname );
755 return $s;
756 }
757
758
759 function getCategoryLinks() {
760 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
761 global $wgContLang, $wgUser;
762
763 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
764
765 # Separator
766 $sep = wfMsgHtml( 'catseparator' );
767
768 // Use Unicode bidi embedding override characters,
769 // to make sure links don't smash each other up in ugly ways.
770 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
771 $embed = "<span dir='$dir'>";
772 $pop = '</span>';
773
774 $allCats = $wgOut->getCategoryLinks();
775 $s = '';
776 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
777 if ( !empty( $allCats['normal'] ) ) {
778 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
779
780 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
781 $s .= '<div id="mw-normal-catlinks">' .
782 $this->link( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
783 . $colon . $t . '</div>';
784 }
785
786 # Hidden categories
787 if ( isset( $allCats['hidden'] ) ) {
788 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
789 $class ='mw-hidden-cats-user-shown';
790 } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
791 $class = 'mw-hidden-cats-ns-shown';
792 } else {
793 $class = 'mw-hidden-cats-hidden';
794 }
795 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
796 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
797 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
798 "</div>";
799 }
800
801 # optional 'dmoz-like' category browser. Will be shown under the list
802 # of categories an article belong to
803 if( $wgUseCategoryBrowser ){
804 $s .= '<br /><hr />';
805
806 # get a big array of the parents tree
807 $parenttree = $wgTitle->getParentCategoryTree();
808 # Skin object passed by reference cause it can not be
809 # accessed under the method subfunction drawCategoryBrowser
810 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
811 # Clean out bogus first entry and sort them
812 unset($tempout[0]);
813 asort($tempout);
814 # Output one per line
815 $s .= implode("<br />\n", $tempout);
816 }
817
818 return $s;
819 }
820
821 /** Render the array as a serie of links.
822 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
823 * @param &skin Object: skin passed by reference
824 * @return String separated by &gt;, terminate with "\n"
825 */
826 function drawCategoryBrowser( $tree, &$skin ){
827 $return = '';
828 foreach ($tree as $element => $parent) {
829 if (empty($parent)) {
830 # element start a new list
831 $return .= "\n";
832 } else {
833 # grab the others elements
834 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
835 }
836 # add our current element to the list
837 $eltitle = Title::newFromText($element);
838 $return .= $skin->link( $eltitle, $eltitle->getText() ) ;
839 }
840 return $return;
841 }
842
843 function getCategories() {
844 $catlinks=$this->getCategoryLinks();
845
846 $classes = 'catlinks';
847
848 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
849 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
850 $classes .= ' catlinks-allhidden';
851 }
852
853 if( !empty( $catlinks ) ){
854 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
855 }
856 }
857
858 function getQuickbarCompensator( $rows = 1 ) {
859 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
860 }
861
862 /**
863 * This runs a hook to allow extensions placing their stuff after content
864 * and article metadata (e.g. categories).
865 * Note: This function has nothing to do with afterContent().
866 *
867 * This hook is placed here in order to allow using the same hook for all
868 * skins, both the SkinTemplate based ones and the older ones, which directly
869 * use this class to get their data.
870 *
871 * The output of this function gets processed in SkinTemplate::outputPage() for
872 * the SkinTemplate based skins, all other skins should directly echo it.
873 *
874 * Returns an empty string by default, if not changed by any hook function.
875 */
876 protected function afterContentHook() {
877 $data = "";
878
879 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
880 // adding just some spaces shouldn't toggle the output
881 // of the whole <div/>, so we use trim() here
882 if( trim( $data ) != '' ){
883 // Doing this here instead of in the skins to
884 // ensure that the div has the same ID in all
885 // skins
886 $data = "<div id='mw-data-after-content'>\n" .
887 "\t$data\n" .
888 "</div>\n";
889 }
890 } else {
891 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
892 }
893
894 return $data;
895 }
896
897 /**
898 * This gets called shortly before the </body> tag.
899 * @return String HTML to be put before </body>
900 */
901 function afterContent() {
902 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
903 return $printfooter . $this->doAfterContent();
904 }
905
906 /**
907 * This gets called shortly before the </body> tag.
908 * @return String HTML-wrapped JS code to be put before </body>
909 */
910 function bottomScripts() {
911 global $wgJsMimeType;
912 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
913 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
914 return $bottomScriptText;
915 }
916
917 /** @return string Retrievied from HTML text */
918 function printSource() {
919 global $wgTitle;
920 $url = htmlspecialchars( $wgTitle->getFullURL() );
921 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
922 }
923
924 function printFooter() {
925 return "<p>" . $this->printSource() .
926 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
927 }
928
929 /** overloaded by derived classes */
930 function doAfterContent() { return "</div></div>"; }
931
932 function pageTitleLinks() {
933 global $wgOut, $wgTitle, $wgUser, $wgRequest;
934
935 $oldid = $wgRequest->getVal( 'oldid' );
936 $diff = $wgRequest->getVal( 'diff' );
937 $action = $wgRequest->getText( 'action' );
938
939 $s = $this->printableLink();
940 $disclaimer = $this->disclaimerLink(); # may be empty
941 if( $disclaimer ) {
942 $s .= ' | ' . $disclaimer;
943 }
944 $privacy = $this->privacyLink(); # may be empty too
945 if( $privacy ) {
946 $s .= ' | ' . $privacy;
947 }
948
949 if ( $wgOut->isArticleRelated() ) {
950 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
951 $name = $wgTitle->getDBkey();
952 $image = wfFindFile( $wgTitle );
953 if( $image ) {
954 $link = htmlspecialchars( $image->getURL() );
955 $style = $this->getInternalLinkAttributes( $link, $name );
956 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
957 }
958 }
959 }
960 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
961 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
962 wfMsg( 'currentrev' ) );
963 }
964
965 if ( $wgUser->getNewtalk() ) {
966 # do not show "You have new messages" text when we are viewing our
967 # own talk page
968 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
969 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
970 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
971 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
972 # disable caching
973 $wgOut->setSquidMaxage(0);
974 $wgOut->enableClientCache(false);
975 }
976 }
977
978 $undelete = $this->getUndeleteLink();
979 if( !empty( $undelete ) ) {
980 $s .= ' | '.$undelete;
981 }
982 return $s;
983 }
984
985 function getUndeleteLink() {
986 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
987 if( $wgUser->isAllowed( 'deletedhistory' ) &&
988 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
989 ($n = $wgTitle->isDeleted() ) )
990 {
991 if ( $wgUser->isAllowed( 'undelete' ) ) {
992 $msg = 'thisisdeleted';
993 } else {
994 $msg = 'viewdeleted';
995 }
996 return wfMsg( $msg,
997 $this->makeKnownLinkObj(
998 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
999 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
1000 }
1001 return '';
1002 }
1003
1004 function printableLink() {
1005 global $wgOut, $wgFeedClasses, $wgRequest;
1006
1007 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1008
1009 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
1010 if( $wgOut->isSyndicated() ) {
1011 foreach( $wgFeedClasses as $format => $class ) {
1012 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1013 $s .= " | <a href=\"$feedurl\">{$format}</a>";
1014 }
1015 }
1016 return $s;
1017 }
1018
1019 function pageTitle() {
1020 global $wgOut;
1021 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
1022 return $s;
1023 }
1024
1025 function pageSubtitle() {
1026 global $wgOut;
1027
1028 $sub = $wgOut->getSubtitle();
1029 if ( '' == $sub ) {
1030 global $wgExtraSubtitle;
1031 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
1032 }
1033 $subpages = $this->subPageSubtitle();
1034 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
1035 $s = "<p class='subtitle'>{$sub}</p>\n";
1036 return $s;
1037 }
1038
1039 function subPageSubtitle() {
1040 $subpages = '';
1041 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
1042 return $subpages;
1043
1044 global $wgOut, $wgTitle;
1045 if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) {
1046 $ptext=$wgTitle->getPrefixedText();
1047 if(preg_match('/\//',$ptext)) {
1048 $links = explode('/',$ptext);
1049 array_pop( $links );
1050 $c = 0;
1051 $growinglink = '';
1052 $display = '';
1053 foreach($links as $link) {
1054 $growinglink .= $link;
1055 $display .= $link;
1056 $linkObj = Title::newFromText( $growinglink );
1057 if( is_object( $linkObj ) && $linkObj->exists() ){
1058 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1059 $c++;
1060 if ($c>1) {
1061 $subpages .= ' | ';
1062 } else {
1063 $subpages .= '&lt; ';
1064 }
1065 $subpages .= $getlink;
1066 $display = '';
1067 } else {
1068 $display .= '/';
1069 }
1070 $growinglink .= '/';
1071 }
1072 }
1073 }
1074 return $subpages;
1075 }
1076
1077 /**
1078 * Returns true if the IP should be shown in the header
1079 */
1080 function showIPinHeader() {
1081 global $wgShowIPinHeader;
1082 return $wgShowIPinHeader && session_id() != '';
1083 }
1084
1085 function nameAndLogin() {
1086 global $wgUser, $wgTitle, $wgLang, $wgContLang;
1087
1088 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1089
1090 $ret = '';
1091 if ( $wgUser->isAnon() ) {
1092 if( $this->showIPinHeader() ) {
1093 $name = wfGetIP();
1094
1095 $talkLink = $this->link( $wgUser->getTalkPage(),
1096 $wgLang->getNsText( NS_TALK ) );
1097
1098 $ret .= "$name ($talkLink)";
1099 } else {
1100 $ret .= wfMsg( 'notloggedin' );
1101 }
1102
1103 $returnTo = $wgTitle->getPrefixedDBkey();
1104 $query = array();
1105 if ( $logoutPage != $returnTo ) {
1106 $query['returnto'] = $returnTo;
1107 }
1108
1109 $loginlink = $wgUser->isAllowed( 'createaccount' )
1110 ? 'nav-login-createaccount'
1111 : 'login';
1112 $ret .= "\n<br />" . $this->link(
1113 SpecialPage::getTitleFor( 'Userlogin' ),
1114 wfMsg( $loginlink ), array(), $query
1115 );
1116 } else {
1117 $returnTo = $wgTitle->getPrefixedDBkey();
1118 $talkLink = $this->link( $wgUser->getTalkPage(),
1119 $wgLang->getNsText( NS_TALK ) );
1120
1121 $ret .= $this->link( $wgUser->getUserPage(),
1122 htmlspecialchars( $wgUser->getName() ) );
1123 $ret .= " ($talkLink)<br />";
1124 $ret .= $this->link(
1125 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1126 array(), array( 'returnto' => $returnTo )
1127 );
1128 $ret .= ' | ' . $this->specialLink( 'preferences' );
1129 }
1130 $ret .= ' | ' . $this->link(
1131 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1132 wfMsg( 'help' )
1133 );
1134
1135 return $ret;
1136 }
1137
1138 function getSearchLink() {
1139 $searchPage = SpecialPage::getTitleFor( 'Search' );
1140 return $searchPage->getLocalURL();
1141 }
1142
1143 function escapeSearchLink() {
1144 return htmlspecialchars( $this->getSearchLink() );
1145 }
1146
1147 function searchForm() {
1148 global $wgRequest;
1149 $search = $wgRequest->getText( 'search' );
1150
1151 $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
1152 . $this->escapeSearchLink() . "\">\n"
1153 . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
1154 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
1155 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
1156 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
1157
1158 // Ensure unique id's for search boxes made after the first
1159 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1160
1161 return $s;
1162 }
1163
1164 function topLinks() {
1165 global $wgOut;
1166 $sep = " |\n";
1167
1168 $s = $this->mainPageLink() . $sep
1169 . $this->specialLink( 'recentchanges' );
1170
1171 if ( $wgOut->isArticleRelated() ) {
1172 $s .= $sep . $this->editThisPage()
1173 . $sep . $this->historyLink();
1174 }
1175 # Many people don't like this dropdown box
1176 #$s .= $sep . $this->specialPagesList();
1177
1178 $s .= $this->variantLinks();
1179
1180 $s .= $this->extensionTabLinks();
1181
1182 return $s;
1183 }
1184
1185 /**
1186 * Compatibility for extensions adding functionality through tabs.
1187 * Eventually these old skins should be replaced with SkinTemplate-based
1188 * versions, sigh...
1189 * @return string
1190 */
1191 function extensionTabLinks() {
1192 $tabs = array();
1193 $s = '';
1194 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1195 foreach( $tabs as $tab ) {
1196 $s .= ' | ' . Xml::element( 'a',
1197 array( 'href' => $tab['href'] ),
1198 $tab['text'] );
1199 }
1200 return $s;
1201 }
1202
1203 /**
1204 * Language/charset variant links for classic-style skins
1205 * @return string
1206 */
1207 function variantLinks() {
1208 $s = '';
1209 /* show links to different language variants */
1210 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1211 $variants = $wgContLang->getVariants();
1212 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1213 foreach( $variants as $code ) {
1214 $varname = $wgContLang->getVariantname( $code );
1215 if( $varname == 'disable' )
1216 continue;
1217 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1218 }
1219 }
1220 return $s;
1221 }
1222
1223 function bottomLinks() {
1224 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1225 $sep = " |\n";
1226
1227 $s = '';
1228 if ( $wgOut->isArticleRelated() ) {
1229 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1230 if ( $wgUser->isLoggedIn() ) {
1231 $s .= $sep . $this->watchThisPage();
1232 }
1233 $s .= $sep . $this->talkLink()
1234 . $sep . $this->historyLink()
1235 . $sep . $this->whatLinksHere()
1236 . $sep . $this->watchPageLinksLink();
1237
1238 if ($wgUseTrackbacks)
1239 $s .= $sep . $this->trackbackLink();
1240
1241 if ( $wgTitle->getNamespace() == NS_USER
1242 || $wgTitle->getNamespace() == NS_USER_TALK )
1243
1244 {
1245 $id=User::idFromName($wgTitle->getText());
1246 $ip=User::isIP($wgTitle->getText());
1247
1248 if($id || $ip) { # both anons and non-anons have contri list
1249 $s .= $sep . $this->userContribsLink();
1250 }
1251 if( $this->showEmailUser( $id ) ) {
1252 $s .= $sep . $this->emailUserLink();
1253 }
1254 }
1255 if ( $wgTitle->getArticleId() ) {
1256 $s .= "\n<br />";
1257 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1258 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1259 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1260 }
1261 $s .= "<br />\n" . $this->otherLanguages();
1262 }
1263 return $s;
1264 }
1265
1266 function pageStats() {
1267 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1268 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1269
1270 $oldid = $wgRequest->getVal( 'oldid' );
1271 $diff = $wgRequest->getVal( 'diff' );
1272 if ( ! $wgOut->isArticle() ) { return ''; }
1273 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1274 if ( 0 == $wgArticle->getID() ) { return ''; }
1275
1276 $s = '';
1277 if ( !$wgDisableCounters ) {
1278 $count = $wgLang->formatNum( $wgArticle->getCount() );
1279 if ( $count ) {
1280 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1281 }
1282 }
1283
1284 if( $wgMaxCredits != 0 ){
1285 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1286 } else {
1287 $s .= $this->lastModified();
1288 }
1289
1290 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1291 $dbr = wfGetDB( DB_SLAVE );
1292 $watchlist = $dbr->tableName( 'watchlist' );
1293 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1294 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1295 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1296 $res = $dbr->query( $sql, 'Skin::pageStats');
1297 $x = $dbr->fetchObject( $res );
1298
1299 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1300 array( 'parseinline' ), $wgLang->formatNum($x->n)
1301 );
1302 }
1303
1304 return $s . ' ' . $this->getCopyright();
1305 }
1306
1307 function getCopyright( $type = 'detect' ) {
1308 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1309
1310 if ( $type == 'detect' ) {
1311 $diff = $wgRequest->getVal( 'diff' );
1312 $isCur = $wgArticle && $wgArticle->isCurrent();
1313 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1314 $type = 'history';
1315 } else {
1316 $type = 'normal';
1317 }
1318 }
1319
1320 if ( $type == 'history' ) {
1321 $msg = 'history_copyright';
1322 } else {
1323 $msg = 'copyright';
1324 }
1325
1326 $out = '';
1327 if( $wgRightsPage ) {
1328 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1329 } elseif( $wgRightsUrl ) {
1330 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1331 } elseif( $wgRightsText ) {
1332 $link = $wgRightsText;
1333 } else {
1334 # Give up now
1335 return $out;
1336 }
1337 $out .= wfMsgForContent( $msg, $link );
1338 return $out;
1339 }
1340
1341 function getCopyrightIcon() {
1342 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1343 $out = '';
1344 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1345 $out = $wgCopyrightIcon;
1346 } else if ( $wgRightsIcon ) {
1347 $icon = htmlspecialchars( $wgRightsIcon );
1348 if ( $wgRightsUrl ) {
1349 $url = htmlspecialchars( $wgRightsUrl );
1350 $out .= '<a href="'.$url.'">';
1351 }
1352 $text = htmlspecialchars( $wgRightsText );
1353 $out .= "<img src=\"$icon\" alt='$text' />";
1354 if ( $wgRightsUrl ) {
1355 $out .= '</a>';
1356 }
1357 }
1358 return $out;
1359 }
1360
1361 function getPoweredBy() {
1362 global $wgStylePath;
1363 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1364 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1365 return $img;
1366 }
1367
1368 function lastModified() {
1369 global $wgLang, $wgArticle;
1370 if( $this->mRevisionId ) {
1371 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1372 } else {
1373 $timestamp = $wgArticle->getTimestamp();
1374 }
1375 if ( $timestamp ) {
1376 $d = $wgLang->date( $timestamp, true );
1377 $t = $wgLang->time( $timestamp, true );
1378 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1379 } else {
1380 $s = '';
1381 }
1382 if ( wfGetLB()->getLaggedSlaveMode() ) {
1383 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1384 }
1385 return $s;
1386 }
1387
1388 function logoText( $align = '' ) {
1389 if ( '' != $align ) { $a = " align='{$align}'"; }
1390 else { $a = ''; }
1391
1392 $mp = wfMsg( 'mainpage' );
1393 $mptitle = Title::newMainPage();
1394 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1395
1396 $logourl = $this->getLogo();
1397 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1398 return $s;
1399 }
1400
1401 /**
1402 * show a drop-down box of special pages
1403 */
1404 function specialPagesList() {
1405 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1406 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1407 foreach ( $pages as $name => $page ) {
1408 $pages[$name] = $page->getDescription();
1409 }
1410
1411 $go = wfMsg( 'go' );
1412 $sp = wfMsg( 'specialpages' );
1413 $spp = $wgContLang->specialPage( 'Specialpages' );
1414
1415 $s = '<form id="specialpages" method="get" ' .
1416 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1417 $s .= "<select name=\"wpDropdown\">\n";
1418 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1419
1420
1421 foreach ( $pages as $name => $desc ) {
1422 $p = $wgContLang->specialPage( $name );
1423 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1424 }
1425 $s .= "</select>\n";
1426 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1427 $s .= "</form>\n";
1428 return $s;
1429 }
1430
1431 function mainPageLink() {
1432 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1433 return $s;
1434 }
1435
1436 function copyrightLink() {
1437 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1438 wfMsg( 'copyrightpagename' ) );
1439 return $s;
1440 }
1441
1442 private function footerLink ( $desc, $page ) {
1443 // if the link description has been set to "-" in the default language,
1444 if ( wfMsgForContent( $desc ) == '-') {
1445 // then it is disabled, for all languages.
1446 return '';
1447 } else {
1448 // Otherwise, we display the link for the user, described in their
1449 // language (which may or may not be the same as the default language),
1450 // but we make the link target be the one site-wide page.
1451 return $this->makeKnownLink( wfMsgForContent( $page ),
1452 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1453 }
1454 }
1455
1456 function privacyLink() {
1457 return $this->footerLink( 'privacy', 'privacypage' );
1458 }
1459
1460 function aboutLink() {
1461 return $this->footerLink( 'aboutsite', 'aboutpage' );
1462 }
1463
1464 function disclaimerLink() {
1465 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1466 }
1467
1468 function editThisPage() {
1469 global $wgOut, $wgTitle;
1470
1471 if ( !$wgOut->isArticleRelated() ) {
1472 $s = wfMsg( 'protectedpage' );
1473 } else {
1474 if( $wgTitle->quickUserCan( 'edit' ) && $wgTitle->exists() ) {
1475 $t = wfMsg( 'editthispage' );
1476 } elseif( $wgTitle->quickUserCan( 'create' ) && !$wgTitle->exists() ) {
1477 $t = wfMsg( 'create-this-page' );
1478 } else {
1479 $t = wfMsg( 'viewsource' );
1480 }
1481
1482 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1483 }
1484 return $s;
1485 }
1486
1487 /**
1488 * Return URL options for the 'edit page' link.
1489 * This may include an 'oldid' specifier, if the current page view is such.
1490 *
1491 * @return string
1492 * @private
1493 */
1494 function editUrlOptions() {
1495 global $wgArticle;
1496
1497 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1498 return "action=edit&oldid=" . intval( $this->mRevisionId );
1499 } else {
1500 return "action=edit";
1501 }
1502 }
1503
1504 function deleteThisPage() {
1505 global $wgUser, $wgTitle, $wgRequest;
1506
1507 $diff = $wgRequest->getVal( 'diff' );
1508 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1509 $t = wfMsg( 'deletethispage' );
1510
1511 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1512 } else {
1513 $s = '';
1514 }
1515 return $s;
1516 }
1517
1518 function protectThisPage() {
1519 global $wgUser, $wgTitle, $wgRequest;
1520
1521 $diff = $wgRequest->getVal( 'diff' );
1522 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1523 if ( $wgTitle->isProtected() ) {
1524 $t = wfMsg( 'unprotectthispage' );
1525 $q = 'action=unprotect';
1526 } else {
1527 $t = wfMsg( 'protectthispage' );
1528 $q = 'action=protect';
1529 }
1530 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1531 } else {
1532 $s = '';
1533 }
1534 return $s;
1535 }
1536
1537 function watchThisPage() {
1538 global $wgOut, $wgTitle;
1539 ++$this->mWatchLinkNum;
1540
1541 if ( $wgOut->isArticleRelated() ) {
1542 if ( $wgTitle->userIsWatching() ) {
1543 $t = wfMsg( 'unwatchthispage' );
1544 $q = 'action=unwatch';
1545 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1546 } else {
1547 $t = wfMsg( 'watchthispage' );
1548 $q = 'action=watch';
1549 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1550 }
1551 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1552 } else {
1553 $s = wfMsg( 'notanarticle' );
1554 }
1555 return $s;
1556 }
1557
1558 function moveThisPage() {
1559 global $wgTitle;
1560
1561 if ( $wgTitle->quickUserCan( 'move' ) ) {
1562 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1563 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1564 } else {
1565 // no message if page is protected - would be redundant
1566 return '';
1567 }
1568 }
1569
1570 function historyLink() {
1571 global $wgTitle;
1572
1573 return $this->makeKnownLinkObj( $wgTitle,
1574 wfMsg( 'history' ), 'action=history' );
1575 }
1576
1577 function whatLinksHere() {
1578 global $wgTitle;
1579
1580 return $this->makeKnownLinkObj(
1581 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1582 wfMsg( 'whatlinkshere' ) );
1583 }
1584
1585 function userContribsLink() {
1586 global $wgTitle;
1587
1588 return $this->makeKnownLinkObj(
1589 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1590 wfMsg( 'contributions' ) );
1591 }
1592
1593 function showEmailUser( $id ) {
1594 global $wgUser;
1595 $targetUser = User::newFromId( $id );
1596 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1597 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1598 }
1599
1600 function emailUserLink() {
1601 global $wgTitle;
1602
1603 return $this->makeKnownLinkObj(
1604 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1605 wfMsg( 'emailuser' ) );
1606 }
1607
1608 function watchPageLinksLink() {
1609 global $wgOut, $wgTitle;
1610
1611 if ( ! $wgOut->isArticleRelated() ) {
1612 return '(' . wfMsg( 'notanarticle' ) . ')';
1613 } else {
1614 return $this->makeKnownLinkObj(
1615 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1616 wfMsg( 'recentchangeslinked' ) );
1617 }
1618 }
1619
1620 function trackbackLink() {
1621 global $wgTitle;
1622
1623 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1624 . wfMsg('trackbacklink') . "</a>";
1625 }
1626
1627 function otherLanguages() {
1628 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1629
1630 if ( $wgHideInterlanguageLinks ) {
1631 return '';
1632 }
1633
1634 $a = $wgOut->getLanguageLinks();
1635 if ( 0 == count( $a ) ) {
1636 return '';
1637 }
1638
1639 $s = wfMsg( 'otherlanguages' ) . ': ';
1640 $first = true;
1641 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1642 foreach( $a as $l ) {
1643 if ( ! $first ) { $s .= ' | '; }
1644 $first = false;
1645
1646 $nt = Title::newFromText( $l );
1647 $url = $nt->escapeFullURL();
1648 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1649
1650 if ( '' == $text ) { $text = $l; }
1651 $style = $this->getExternalLinkAttributes( $l, $text );
1652 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1653 }
1654 if($wgContLang->isRTL()) $s .= '</span>';
1655 return $s;
1656 }
1657
1658 function bugReportsLink() {
1659 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1660 wfMsg( 'bugreports' ) );
1661 return $s;
1662 }
1663
1664 function talkLink() {
1665 global $wgTitle;
1666
1667 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1668 # No discussion links for special pages
1669 return '';
1670 }
1671
1672 $linkOptions = array();
1673
1674 if( $wgTitle->isTalkPage() ) {
1675 $link = $wgTitle->getSubjectPage();
1676 switch( $link->getNamespace() ) {
1677 case NS_MAIN:
1678 $text = wfMsg( 'articlepage' );
1679 break;
1680 case NS_USER:
1681 $text = wfMsg( 'userpage' );
1682 break;
1683 case NS_PROJECT:
1684 $text = wfMsg( 'projectpage' );
1685 break;
1686 case NS_IMAGE:
1687 $text = wfMsg( 'imagepage' );
1688 # Make link known if image exists, even if the desc. page doesn't.
1689 if( wfFindFile( $link ) )
1690 $linkOptions[] = 'known';
1691 break;
1692 case NS_MEDIAWIKI:
1693 $text = wfMsg( 'mediawikipage' );
1694 break;
1695 case NS_TEMPLATE:
1696 $text = wfMsg( 'templatepage' );
1697 break;
1698 case NS_HELP:
1699 $text = wfMsg( 'viewhelppage' );
1700 break;
1701 case NS_CATEGORY:
1702 $text = wfMsg( 'categorypage' );
1703 break;
1704 default:
1705 $text = wfMsg( 'articlepage' );
1706 }
1707 } else {
1708 $link = $wgTitle->getTalkPage();
1709 $text = wfMsg( 'talkpage' );
1710 }
1711
1712 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1713
1714 return $s;
1715 }
1716
1717 function commentLink() {
1718 global $wgTitle, $wgOut;
1719
1720 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1721 return '';
1722 }
1723
1724 # __NEWSECTIONLINK___ changes behaviour here
1725 # If it's present, the link points to this page, otherwise
1726 # it points to the talk page
1727 if( $wgTitle->isTalkPage() ) {
1728 $title = $wgTitle;
1729 } elseif( $wgOut->showNewSectionLink() ) {
1730 $title = $wgTitle;
1731 } else {
1732 $title = $wgTitle->getTalkPage();
1733 }
1734
1735 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1736 }
1737
1738 /* these are used extensively in SkinTemplate, but also some other places */
1739 static function makeMainPageUrl( $urlaction = '' ) {
1740 $title = Title::newMainPage();
1741 self::checkTitle( $title, '' );
1742 return $title->getLocalURL( $urlaction );
1743 }
1744
1745 static function makeSpecialUrl( $name, $urlaction = '' ) {
1746 $title = SpecialPage::getTitleFor( $name );
1747 return $title->getLocalURL( $urlaction );
1748 }
1749
1750 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1751 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1752 return $title->getLocalURL( $urlaction );
1753 }
1754
1755 static function makeI18nUrl( $name, $urlaction = '' ) {
1756 $title = Title::newFromText( wfMsgForContent( $name ) );
1757 self::checkTitle( $title, $name );
1758 return $title->getLocalURL( $urlaction );
1759 }
1760
1761 static function makeUrl( $name, $urlaction = '' ) {
1762 $title = Title::newFromText( $name );
1763 self::checkTitle( $title, $name );
1764 return $title->getLocalURL( $urlaction );
1765 }
1766
1767 # If url string starts with http, consider as external URL, else
1768 # internal
1769 static function makeInternalOrExternalUrl( $name ) {
1770 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1771 return $name;
1772 } else {
1773 return self::makeUrl( $name );
1774 }
1775 }
1776
1777 # this can be passed the NS number as defined in Language.php
1778 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1779 $title = Title::makeTitleSafe( $namespace, $name );
1780 self::checkTitle( $title, $name );
1781 return $title->getLocalURL( $urlaction );
1782 }
1783
1784 /* these return an array with the 'href' and boolean 'exists' */
1785 static function makeUrlDetails( $name, $urlaction = '' ) {
1786 $title = Title::newFromText( $name );
1787 self::checkTitle( $title, $name );
1788 return array(
1789 'href' => $title->getLocalURL( $urlaction ),
1790 'exists' => $title->getArticleID() != 0 ? true : false
1791 );
1792 }
1793
1794 /**
1795 * Make URL details where the article exists (or at least it's convenient to think so)
1796 */
1797 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1798 $title = Title::newFromText( $name );
1799 self::checkTitle( $title, $name );
1800 return array(
1801 'href' => $title->getLocalURL( $urlaction ),
1802 'exists' => true
1803 );
1804 }
1805
1806 # make sure we have some title to operate on
1807 static function checkTitle( &$title, $name ) {
1808 if( !is_object( $title ) ) {
1809 $title = Title::newFromText( $name );
1810 if( !is_object( $title ) ) {
1811 $title = Title::newFromText( '--error: link target missing--' );
1812 }
1813 }
1814 }
1815
1816 /**
1817 * Build an array that represents the sidebar(s), the navigation bar among them
1818 *
1819 * @return array
1820 */
1821 function buildSidebar() {
1822 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1823 global $wgLang;
1824 wfProfileIn( __METHOD__ );
1825
1826 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1827
1828 if ( $wgEnableSidebarCache ) {
1829 $cachedsidebar = $parserMemc->get( $key );
1830 if ( $cachedsidebar ) {
1831 wfProfileOut( __METHOD__ );
1832 return $cachedsidebar;
1833 }
1834 }
1835
1836 $bar = array();
1837 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1838 $heading = '';
1839 foreach ($lines as $line) {
1840 if (strpos($line, '*') !== 0)
1841 continue;
1842 if (strpos($line, '**') !== 0) {
1843 $line = trim($line, '* ');
1844 $heading = $line;
1845 if( !array_key_exists($heading, $bar) ) $bar[$heading] = array();
1846 } else {
1847 if (strpos($line, '|') !== false) { // sanity check
1848 $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
1849 $link = wfMsgForContent( $line[0] );
1850 if ($link == '-')
1851 continue;
1852 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1853 $text = $line[1];
1854 if (wfEmptyMsg($line[0], $link))
1855 $link = $line[0];
1856
1857 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1858 $href = $link;
1859 } else {
1860 $title = Title::newFromText( $link );
1861 if ( $title ) {
1862 $title = $title->fixSpecialName();
1863 $href = $title->getLocalURL();
1864 } else {
1865 $href = 'INVALID-TITLE';
1866 }
1867 }
1868
1869 $bar[$heading][] = array(
1870 'text' => $text,
1871 'href' => $href,
1872 'id' => 'n-' . strtr($line[1], ' ', '-'),
1873 'active' => false
1874 );
1875 } else { continue; }
1876 }
1877 }
1878 wfRunHooks('SkinBuildSidebar', array($this, &$bar));
1879 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1880 wfProfileOut( __METHOD__ );
1881 return $bar;
1882 }
1883 }