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