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