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