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