Don't duplicate code, use wfAppendQuery
[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 $s = $this->printableLink();
917 $disclaimer = $this->disclaimerLink(); # may be empty
918 if( $disclaimer ) {
919 $s .= ' | ' . $disclaimer;
920 }
921 $privacy = $this->privacyLink(); # may be empty too
922 if( $privacy ) {
923 $s .= ' | ' . $privacy;
924 }
925
926 if ( $wgOut->isArticleRelated() ) {
927 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
928 $name = $wgTitle->getDBkey();
929 $image = wfFindFile( $wgTitle );
930 if( $image ) {
931 $link = htmlspecialchars( $image->getURL() );
932 $style = $this->getInternalLinkAttributes( $link, $name );
933 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
934 }
935 }
936 }
937 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
938 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
939 wfMsg( 'currentrev' ) );
940 }
941
942 if ( $wgUser->getNewtalk() ) {
943 # do not show "You have new messages" text when we are viewing our
944 # own talk page
945 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
946 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
947 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
948 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
949 # disable caching
950 $wgOut->setSquidMaxage(0);
951 $wgOut->enableClientCache(false);
952 }
953 }
954
955 $undelete = $this->getUndeleteLink();
956 if( !empty( $undelete ) ) {
957 $s .= ' | '.$undelete;
958 }
959 return $s;
960 }
961
962 function getUndeleteLink() {
963 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
964 if( $wgUser->isAllowed( 'deletedhistory' ) &&
965 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
966 ($n = $wgTitle->isDeleted() ) )
967 {
968 if ( $wgUser->isAllowed( 'undelete' ) ) {
969 $msg = 'thisisdeleted';
970 } else {
971 $msg = 'viewdeleted';
972 }
973 return wfMsg( $msg,
974 $this->makeKnownLinkObj(
975 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
976 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
977 }
978 return '';
979 }
980
981 function printableLink() {
982 global $wgOut, $wgFeedClasses, $wgRequest;
983
984 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
985
986 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
987 if( $wgOut->isSyndicated() ) {
988 foreach( $wgFeedClasses as $format => $class ) {
989 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
990 $s .= " | <a href=\"$feedurl\">{$format}</a>";
991 }
992 }
993 return $s;
994 }
995
996 function pageTitle() {
997 global $wgOut;
998 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
999 return $s;
1000 }
1001
1002 function pageSubtitle() {
1003 global $wgOut;
1004
1005 $sub = $wgOut->getSubtitle();
1006 if ( '' == $sub ) {
1007 global $wgExtraSubtitle;
1008 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
1009 }
1010 $subpages = $this->subPageSubtitle();
1011 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
1012 $s = "<p class='subtitle'>{$sub}</p>\n";
1013 return $s;
1014 }
1015
1016 function subPageSubtitle() {
1017 $subpages = '';
1018 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
1019 return $subpages;
1020
1021 global $wgOut, $wgTitle;
1022 if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) {
1023 $ptext=$wgTitle->getPrefixedText();
1024 if(preg_match('/\//',$ptext)) {
1025 $links = explode('/',$ptext);
1026 array_pop( $links );
1027 $c = 0;
1028 $growinglink = '';
1029 $display = '';
1030 foreach($links as $link) {
1031 $growinglink .= $link;
1032 $display .= $link;
1033 $linkObj = Title::newFromText( $growinglink );
1034 if( is_object( $linkObj ) && $linkObj->exists() ){
1035 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1036 $c++;
1037 if ($c>1) {
1038 $subpages .= ' | ';
1039 } else {
1040 $subpages .= '&lt; ';
1041 }
1042 $subpages .= $getlink;
1043 $display = '';
1044 } else {
1045 $display .= '/';
1046 }
1047 $growinglink .= '/';
1048 }
1049 }
1050 }
1051 return $subpages;
1052 }
1053
1054 /**
1055 * Returns true if the IP should be shown in the header
1056 */
1057 function showIPinHeader() {
1058 global $wgShowIPinHeader;
1059 return $wgShowIPinHeader && session_id() != '';
1060 }
1061
1062 function nameAndLogin() {
1063 global $wgUser, $wgTitle, $wgLang, $wgContLang;
1064
1065 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1066
1067 $ret = '';
1068 if ( $wgUser->isAnon() ) {
1069 if( $this->showIPinHeader() ) {
1070 $name = wfGetIP();
1071
1072 $talkLink = $this->link( $wgUser->getTalkPage(),
1073 $wgLang->getNsText( NS_TALK ) );
1074
1075 $ret .= "$name ($talkLink)";
1076 } else {
1077 $ret .= wfMsg( 'notloggedin' );
1078 }
1079
1080 $returnTo = $wgTitle->getPrefixedDBkey();
1081 $query = array();
1082 if ( $logoutPage != $returnTo ) {
1083 $query['returnto'] = $returnTo;
1084 }
1085
1086 $loginlink = $wgUser->isAllowed( 'createaccount' )
1087 ? 'nav-login-createaccount'
1088 : 'login';
1089 $ret .= "\n<br />" . $this->link(
1090 SpecialPage::getTitleFor( 'Userlogin' ),
1091 wfMsg( $loginlink ), array(), $query
1092 );
1093 } else {
1094 $returnTo = $wgTitle->getPrefixedDBkey();
1095 $talkLink = $this->link( $wgUser->getTalkPage(),
1096 $wgLang->getNsText( NS_TALK ) );
1097
1098 $ret .= $this->link( $wgUser->getUserPage(),
1099 htmlspecialchars( $wgUser->getName() ) );
1100 $ret .= " ($talkLink)<br />";
1101 $ret .= $this->link(
1102 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1103 array(), array( 'returnto' => $returnTo )
1104 );
1105 $ret .= ' | ' . $this->specialLink( 'preferences' );
1106 }
1107 $ret .= ' | ' . $this->link(
1108 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1109 wfMsg( 'help' )
1110 );
1111
1112 return $ret;
1113 }
1114
1115 function getSearchLink() {
1116 $searchPage = SpecialPage::getTitleFor( 'Search' );
1117 return $searchPage->getLocalURL();
1118 }
1119
1120 function escapeSearchLink() {
1121 return htmlspecialchars( $this->getSearchLink() );
1122 }
1123
1124 function searchForm() {
1125 global $wgRequest;
1126 $search = $wgRequest->getText( 'search' );
1127
1128 $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
1129 . $this->escapeSearchLink() . "\">\n"
1130 . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
1131 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
1132 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
1133 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
1134
1135 // Ensure unique id's for search boxes made after the first
1136 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1137
1138 return $s;
1139 }
1140
1141 function topLinks() {
1142 global $wgOut;
1143 $sep = " |\n";
1144
1145 $s = $this->mainPageLink() . $sep
1146 . $this->specialLink( 'recentchanges' );
1147
1148 if ( $wgOut->isArticleRelated() ) {
1149 $s .= $sep . $this->editThisPage()
1150 . $sep . $this->historyLink();
1151 }
1152 # Many people don't like this dropdown box
1153 #$s .= $sep . $this->specialPagesList();
1154
1155 $s .= $this->variantLinks();
1156
1157 $s .= $this->extensionTabLinks();
1158
1159 return $s;
1160 }
1161
1162 /**
1163 * Compatibility for extensions adding functionality through tabs.
1164 * Eventually these old skins should be replaced with SkinTemplate-based
1165 * versions, sigh...
1166 * @return string
1167 */
1168 function extensionTabLinks() {
1169 $tabs = array();
1170 $s = '';
1171 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1172 foreach( $tabs as $tab ) {
1173 $s .= ' | ' . Xml::element( 'a',
1174 array( 'href' => $tab['href'] ),
1175 $tab['text'] );
1176 }
1177 return $s;
1178 }
1179
1180 /**
1181 * Language/charset variant links for classic-style skins
1182 * @return string
1183 */
1184 function variantLinks() {
1185 $s = '';
1186 /* show links to different language variants */
1187 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1188 $variants = $wgContLang->getVariants();
1189 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1190 foreach( $variants as $code ) {
1191 $varname = $wgContLang->getVariantname( $code );
1192 if( $varname == 'disable' )
1193 continue;
1194 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1195 }
1196 }
1197 return $s;
1198 }
1199
1200 function bottomLinks() {
1201 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1202 $sep = " |\n";
1203
1204 $s = '';
1205 if ( $wgOut->isArticleRelated() ) {
1206 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1207 if ( $wgUser->isLoggedIn() ) {
1208 $s .= $sep . $this->watchThisPage();
1209 }
1210 $s .= $sep . $this->talkLink()
1211 . $sep . $this->historyLink()
1212 . $sep . $this->whatLinksHere()
1213 . $sep . $this->watchPageLinksLink();
1214
1215 if ($wgUseTrackbacks)
1216 $s .= $sep . $this->trackbackLink();
1217
1218 if ( $wgTitle->getNamespace() == NS_USER
1219 || $wgTitle->getNamespace() == NS_USER_TALK )
1220
1221 {
1222 $id=User::idFromName($wgTitle->getText());
1223 $ip=User::isIP($wgTitle->getText());
1224
1225 if($id || $ip) { # both anons and non-anons have contri list
1226 $s .= $sep . $this->userContribsLink();
1227 }
1228 if( $this->showEmailUser( $id ) ) {
1229 $s .= $sep . $this->emailUserLink();
1230 }
1231 }
1232 if ( $wgTitle->getArticleId() ) {
1233 $s .= "\n<br />";
1234 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1235 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1236 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1237 }
1238 $s .= "<br />\n" . $this->otherLanguages();
1239 }
1240 return $s;
1241 }
1242
1243 function pageStats() {
1244 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1245 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1246
1247 $oldid = $wgRequest->getVal( 'oldid' );
1248 $diff = $wgRequest->getVal( 'diff' );
1249 if ( ! $wgOut->isArticle() ) { return ''; }
1250 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1251 if ( 0 == $wgArticle->getID() ) { return ''; }
1252
1253 $s = '';
1254 if ( !$wgDisableCounters ) {
1255 $count = $wgLang->formatNum( $wgArticle->getCount() );
1256 if ( $count ) {
1257 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1258 }
1259 }
1260
1261 if( $wgMaxCredits != 0 ){
1262 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1263 } else {
1264 $s .= $this->lastModified();
1265 }
1266
1267 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1268 $dbr = wfGetDB( DB_SLAVE );
1269 $watchlist = $dbr->tableName( 'watchlist' );
1270 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1271 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1272 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1273 $res = $dbr->query( $sql, 'Skin::pageStats');
1274 $x = $dbr->fetchObject( $res );
1275
1276 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1277 array( 'parseinline' ), $wgLang->formatNum($x->n)
1278 );
1279 }
1280
1281 return $s . ' ' . $this->getCopyright();
1282 }
1283
1284 function getCopyright( $type = 'detect' ) {
1285 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1286
1287 if ( $type == 'detect' ) {
1288 $oldid = $wgRequest->getVal( 'oldid' );
1289 $diff = $wgRequest->getVal( 'diff' );
1290
1291 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1292 $type = 'history';
1293 } else {
1294 $type = 'normal';
1295 }
1296 }
1297
1298 if ( $type == 'history' ) {
1299 $msg = 'history_copyright';
1300 } else {
1301 $msg = 'copyright';
1302 }
1303
1304 $out = '';
1305 if( $wgRightsPage ) {
1306 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1307 } elseif( $wgRightsUrl ) {
1308 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1309 } elseif( $wgRightsText ) {
1310 $link = $wgRightsText;
1311 } else {
1312 # Give up now
1313 return $out;
1314 }
1315 $out .= wfMsgForContent( $msg, $link );
1316 return $out;
1317 }
1318
1319 function getCopyrightIcon() {
1320 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1321 $out = '';
1322 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1323 $out = $wgCopyrightIcon;
1324 } else if ( $wgRightsIcon ) {
1325 $icon = htmlspecialchars( $wgRightsIcon );
1326 if ( $wgRightsUrl ) {
1327 $url = htmlspecialchars( $wgRightsUrl );
1328 $out .= '<a href="'.$url.'">';
1329 }
1330 $text = htmlspecialchars( $wgRightsText );
1331 $out .= "<img src=\"$icon\" alt='$text' />";
1332 if ( $wgRightsUrl ) {
1333 $out .= '</a>';
1334 }
1335 }
1336 return $out;
1337 }
1338
1339 function getPoweredBy() {
1340 global $wgStylePath;
1341 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1342 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1343 return $img;
1344 }
1345
1346 function lastModified() {
1347 global $wgLang, $wgArticle;
1348 if( $this->mRevisionId ) {
1349 $timestamp = Revision::getTimestampFromId( $this->mRevisionId, $wgArticle->getId() );
1350 } else {
1351 $timestamp = $wgArticle->getTimestamp();
1352 }
1353 if ( $timestamp ) {
1354 $d = $wgLang->date( $timestamp, true );
1355 $t = $wgLang->time( $timestamp, true );
1356 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1357 } else {
1358 $s = '';
1359 }
1360 if ( wfGetLB()->getLaggedSlaveMode() ) {
1361 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1362 }
1363 return $s;
1364 }
1365
1366 function logoText( $align = '' ) {
1367 if ( '' != $align ) { $a = " align='{$align}'"; }
1368 else { $a = ''; }
1369
1370 $mp = wfMsg( 'mainpage' );
1371 $mptitle = Title::newMainPage();
1372 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1373
1374 $logourl = $this->getLogo();
1375 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1376 return $s;
1377 }
1378
1379 /**
1380 * show a drop-down box of special pages
1381 */
1382 function specialPagesList() {
1383 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1384 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1385 foreach ( $pages as $name => $page ) {
1386 $pages[$name] = $page->getDescription();
1387 }
1388
1389 $go = wfMsg( 'go' );
1390 $sp = wfMsg( 'specialpages' );
1391 $spp = $wgContLang->specialPage( 'Specialpages' );
1392
1393 $s = '<form id="specialpages" method="get" class="inline" ' .
1394 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1395 $s .= "<select name=\"wpDropdown\">\n";
1396 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1397
1398
1399 foreach ( $pages as $name => $desc ) {
1400 $p = $wgContLang->specialPage( $name );
1401 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1402 }
1403 $s .= "</select>\n";
1404 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1405 $s .= "</form>\n";
1406 return $s;
1407 }
1408
1409 function mainPageLink() {
1410 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1411 return $s;
1412 }
1413
1414 function copyrightLink() {
1415 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1416 wfMsg( 'copyrightpagename' ) );
1417 return $s;
1418 }
1419
1420 private function footerLink ( $desc, $page ) {
1421 // if the link description has been set to "-" in the default language,
1422 if ( wfMsgForContent( $desc ) == '-') {
1423 // then it is disabled, for all languages.
1424 return '';
1425 } else {
1426 // Otherwise, we display the link for the user, described in their
1427 // language (which may or may not be the same as the default language),
1428 // but we make the link target be the one site-wide page.
1429 return $this->makeKnownLink( wfMsgForContent( $page ),
1430 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1431 }
1432 }
1433
1434 function privacyLink() {
1435 return $this->footerLink( 'privacy', 'privacypage' );
1436 }
1437
1438 function aboutLink() {
1439 return $this->footerLink( 'aboutsite', 'aboutpage' );
1440 }
1441
1442 function disclaimerLink() {
1443 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1444 }
1445
1446 function editThisPage() {
1447 global $wgOut, $wgTitle;
1448
1449 if ( !$wgOut->isArticleRelated() ) {
1450 $s = wfMsg( 'protectedpage' );
1451 } else {
1452 if( $wgTitle->quickUserCan( 'edit' ) && $wgTitle->exists() ) {
1453 $t = wfMsg( 'editthispage' );
1454 } elseif( $wgTitle->quickUserCan( 'create' ) && !$wgTitle->exists() ) {
1455 $t = wfMsg( 'create-this-page' );
1456 } else {
1457 $t = wfMsg( 'viewsource' );
1458 }
1459
1460 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1461 }
1462 return $s;
1463 }
1464
1465 /**
1466 * Return URL options for the 'edit page' link.
1467 * This may include an 'oldid' specifier, if the current page view is such.
1468 *
1469 * @return string
1470 * @private
1471 */
1472 function editUrlOptions() {
1473 global $wgArticle;
1474
1475 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1476 return "action=edit&oldid=" . intval( $this->mRevisionId );
1477 } else {
1478 return "action=edit";
1479 }
1480 }
1481
1482 function deleteThisPage() {
1483 global $wgUser, $wgTitle, $wgRequest;
1484
1485 $diff = $wgRequest->getVal( 'diff' );
1486 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1487 $t = wfMsg( 'deletethispage' );
1488
1489 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1490 } else {
1491 $s = '';
1492 }
1493 return $s;
1494 }
1495
1496 function protectThisPage() {
1497 global $wgUser, $wgTitle, $wgRequest;
1498
1499 $diff = $wgRequest->getVal( 'diff' );
1500 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1501 if ( $wgTitle->isProtected() ) {
1502 $t = wfMsg( 'unprotectthispage' );
1503 $q = 'action=unprotect';
1504 } else {
1505 $t = wfMsg( 'protectthispage' );
1506 $q = 'action=protect';
1507 }
1508 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1509 } else {
1510 $s = '';
1511 }
1512 return $s;
1513 }
1514
1515 function watchThisPage() {
1516 global $wgOut, $wgTitle;
1517 ++$this->mWatchLinkNum;
1518
1519 if ( $wgOut->isArticleRelated() ) {
1520 if ( $wgTitle->userIsWatching() ) {
1521 $t = wfMsg( 'unwatchthispage' );
1522 $q = 'action=unwatch';
1523 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1524 } else {
1525 $t = wfMsg( 'watchthispage' );
1526 $q = 'action=watch';
1527 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1528 }
1529 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1530 } else {
1531 $s = wfMsg( 'notanarticle' );
1532 }
1533 return $s;
1534 }
1535
1536 function moveThisPage() {
1537 global $wgTitle;
1538
1539 if ( $wgTitle->quickUserCan( 'move' ) ) {
1540 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1541 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1542 } else {
1543 // no message if page is protected - would be redundant
1544 return '';
1545 }
1546 }
1547
1548 function historyLink() {
1549 global $wgTitle;
1550
1551 return $this->makeKnownLinkObj( $wgTitle,
1552 wfMsg( 'history' ), 'action=history' );
1553 }
1554
1555 function whatLinksHere() {
1556 global $wgTitle;
1557
1558 return $this->makeKnownLinkObj(
1559 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1560 wfMsg( 'whatlinkshere' ) );
1561 }
1562
1563 function userContribsLink() {
1564 global $wgTitle;
1565
1566 return $this->makeKnownLinkObj(
1567 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1568 wfMsg( 'contributions' ) );
1569 }
1570
1571 function showEmailUser( $id ) {
1572 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1573 return $wgEnableEmail &&
1574 $wgEnableUserEmail &&
1575 $wgUser->isLoggedIn() && # show only to signed in users
1576 0 != $id; # we can only email to non-anons ..
1577 # '' != $id->getEmail() && # who must have an email address stored ..
1578 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1579 # 1 != $wgUser->getOption('disablemail'); # and not disabled
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 }