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