Per Tim's comment on r49782 (and fix for that rev): put the $n assignment out of...
[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, $wgRequest;
1017
1018 $action = $wgRequest->getVal( 'action', 'view' );
1019
1020 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1021 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
1022 $n = $this->mTitle->isDeleted();
1023 if ( $n ) {
1024 if ( $wgUser->isAllowed( 'undelete' ) ) {
1025 $msg = 'thisisdeleted';
1026 } else {
1027 $msg = 'viewdeleted';
1028 }
1029 return wfMsg( $msg,
1030 $this->makeKnownLinkObj(
1031 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
1032 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
1033 }
1034 }
1035 return '';
1036 }
1037
1038 function printableLink() {
1039 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1040
1041 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1042
1043 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1044 if( $wgOut->isSyndicated() ) {
1045 foreach( $wgFeedClasses as $format => $class ) {
1046 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1047 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1048 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1049 }
1050 }
1051 return $wgLang->pipeList( $s );
1052 }
1053
1054 function pageTitle() {
1055 global $wgOut;
1056 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1057 return $s;
1058 }
1059
1060 function pageSubtitle() {
1061 global $wgOut;
1062
1063 $sub = $wgOut->getSubtitle();
1064 if ( '' == $sub ) {
1065 global $wgExtraSubtitle;
1066 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1067 }
1068 $subpages = $this->subPageSubtitle();
1069 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1070 $s = "<p class='subtitle'>{$sub}</p>\n";
1071 return $s;
1072 }
1073
1074 function subPageSubtitle() {
1075 $subpages = '';
1076 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) )
1077 return $subpages;
1078
1079 global $wgOut;
1080 if( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1081 $ptext = $this->mTitle->getPrefixedText();
1082 if( preg_match( '/\//', $ptext ) ) {
1083 $links = explode( '/', $ptext );
1084 array_pop( $links );
1085 $c = 0;
1086 $growinglink = '';
1087 $display = '';
1088 foreach( $links as $link ) {
1089 $growinglink .= $link;
1090 $display .= $link;
1091 $linkObj = Title::newFromText( $growinglink );
1092 if( is_object( $linkObj ) && $linkObj->exists() ){
1093 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
1094 $c++;
1095 if( $c > 1 ) {
1096 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1097 } else {
1098 $subpages .= '&lt; ';
1099 }
1100 $subpages .= $getlink;
1101 $display = '';
1102 } else {
1103 $display .= '/';
1104 }
1105 $growinglink .= '/';
1106 }
1107 }
1108 }
1109 return $subpages;
1110 }
1111
1112 /**
1113 * Returns true if the IP should be shown in the header
1114 */
1115 function showIPinHeader() {
1116 global $wgShowIPinHeader;
1117 return $wgShowIPinHeader && session_id() != '';
1118 }
1119
1120 function nameAndLogin() {
1121 global $wgUser, $wgLang, $wgContLang;
1122
1123 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1124
1125 $ret = '';
1126 if ( $wgUser->isAnon() ) {
1127 if( $this->showIPinHeader() ) {
1128 $name = wfGetIP();
1129
1130 $talkLink = $this->link( $wgUser->getTalkPage(),
1131 $wgLang->getNsText( NS_TALK ) );
1132
1133 $ret .= "$name ($talkLink)";
1134 } else {
1135 $ret .= wfMsg( 'notloggedin' );
1136 }
1137
1138 $returnTo = $this->mTitle->getPrefixedDBkey();
1139 $query = array();
1140 if ( $logoutPage != $returnTo ) {
1141 $query['returnto'] = $returnTo;
1142 }
1143
1144 $loginlink = $wgUser->isAllowed( 'createaccount' )
1145 ? 'nav-login-createaccount'
1146 : 'login';
1147 $ret .= "\n<br />" . $this->link(
1148 SpecialPage::getTitleFor( 'Userlogin' ),
1149 wfMsg( $loginlink ), array(), $query
1150 );
1151 } else {
1152 $returnTo = $this->mTitle->getPrefixedDBkey();
1153 $talkLink = $this->link( $wgUser->getTalkPage(),
1154 $wgLang->getNsText( NS_TALK ) );
1155
1156 $ret .= $this->link( $wgUser->getUserPage(),
1157 htmlspecialchars( $wgUser->getName() ) );
1158 $ret .= " ($talkLink)<br />";
1159 $ret .= $wgLang->pipeList( array(
1160 $this->link(
1161 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1162 array(), array( 'returnto' => $returnTo )
1163 ),
1164 $this->specialLink( 'preferences' ),
1165 ) );
1166 }
1167 $ret = $wgLang->pipeList( array(
1168 $ret,
1169 $this->link(
1170 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1171 wfMsg( 'help' )
1172 ),
1173 ) );
1174
1175 return $ret;
1176 }
1177
1178 function getSearchLink() {
1179 $searchPage = SpecialPage::getTitleFor( 'Search' );
1180 return $searchPage->getLocalURL();
1181 }
1182
1183 function escapeSearchLink() {
1184 return htmlspecialchars( $this->getSearchLink() );
1185 }
1186
1187 function searchForm() {
1188 global $wgRequest, $wgUseTwoButtonsSearchForm;
1189 $search = $wgRequest->getText( 'search' );
1190
1191 $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
1192 . $this->escapeSearchLink() . "\">\n"
1193 . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
1194 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1195 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1196
1197 if( $wgUseTwoButtonsSearchForm )
1198 $s .= '&nbsp;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1199 else
1200 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1201
1202 $s .= '</form>';
1203
1204 // Ensure unique id's for search boxes made after the first
1205 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1206
1207 return $s;
1208 }
1209
1210 function topLinks() {
1211 global $wgOut;
1212
1213 $s = array(
1214 $this->mainPageLink(),
1215 $this->specialLink( 'recentchanges' )
1216 );
1217
1218 if ( $wgOut->isArticleRelated() ) {
1219 $s[] = $this->editThisPage();
1220 $s[] = $this->historyLink();
1221 }
1222 # Many people don't like this dropdown box
1223 #$s[] = $this->specialPagesList();
1224
1225 if( $this->variantLinks() ) {
1226 $s[] = $this->variantLinks();
1227 }
1228
1229 if( $this->extensionTabLinks() ) {
1230 $s[] = $this->extensionTabLinks();
1231 }
1232
1233 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1234 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1235 }
1236
1237 /**
1238 * Compatibility for extensions adding functionality through tabs.
1239 * Eventually these old skins should be replaced with SkinTemplate-based
1240 * versions, sigh...
1241 * @return string
1242 */
1243 function extensionTabLinks() {
1244 $tabs = array();
1245 $out = '';
1246 $s = array();
1247 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1248 foreach( $tabs as $tab ) {
1249 $s[] = Xml::element( 'a',
1250 array( 'href' => $tab['href'] ),
1251 $tab['text'] );
1252 }
1253
1254 if( count( $s ) ) {
1255 global $wgLang;
1256
1257 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1258 $out .= $wgLang->pipeList( $s );
1259 }
1260
1261 return $out;
1262 }
1263
1264 /**
1265 * Language/charset variant links for classic-style skins
1266 * @return string
1267 */
1268 function variantLinks() {
1269 $s = '';
1270 /* show links to different language variants */
1271 global $wgDisableLangConversion, $wgLang, $wgContLang;
1272 $variants = $wgContLang->getVariants();
1273 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1274 foreach( $variants as $code ) {
1275 $varname = $wgContLang->getVariantname( $code );
1276 if( $varname == 'disable' )
1277 continue;
1278 $s = $wgLang->pipeList( array(
1279 $s,
1280 '<a href="' . $this->mTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1281 ) );
1282 }
1283 }
1284 return $s;
1285 }
1286
1287 function bottomLinks() {
1288 global $wgOut, $wgUser, $wgUseTrackbacks;
1289 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1290
1291 $s = '';
1292 if ( $wgOut->isArticleRelated() ) {
1293 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1294 if ( $wgUser->isLoggedIn() ) {
1295 $element[] = $this->watchThisPage();
1296 }
1297 $element[] = $this->talkLink();
1298 $element[] = $this->historyLink();
1299 $element[] = $this->whatLinksHere();
1300 $element[] = $this->watchPageLinksLink();
1301
1302 if( $wgUseTrackbacks )
1303 $element[] = $this->trackbackLink();
1304
1305 if ( $this->mTitle->getNamespace() == NS_USER
1306 || $this->mTitle->getNamespace() == NS_USER_TALK ){
1307 $id = User::idFromName( $this->mTitle->getText() );
1308 $ip = User::isIP( $this->mTitle->getText() );
1309
1310 if( $id || $ip ) { # both anons and non-anons have contri list
1311 $element[] = $this->userContribsLink();
1312 }
1313 if( $this->showEmailUser( $id ) ) {
1314 $element[] = $this->emailUserLink();
1315 }
1316 }
1317
1318 $s = implode( $element, $sep );
1319
1320 if ( $this->mTitle->getArticleId() ) {
1321 $s .= "\n<br />";
1322 if( $wgUser->isAllowed( 'delete' ) ) { $s .= $this->deleteThisPage(); }
1323 if( $wgUser->isAllowed( 'protect' ) ) { $s .= $sep . $this->protectThisPage(); }
1324 if( $wgUser->isAllowed( 'move' ) ) { $s .= $sep . $this->moveThisPage(); }
1325 }
1326 $s .= "<br />\n" . $this->otherLanguages();
1327 }
1328
1329 return $s;
1330 }
1331
1332 function pageStats() {
1333 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1334 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1335
1336 $oldid = $wgRequest->getVal( 'oldid' );
1337 $diff = $wgRequest->getVal( 'diff' );
1338 if ( ! $wgOut->isArticle() ) { return ''; }
1339 if( !$wgArticle instanceOf Article ) { return ''; }
1340 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1341 if ( 0 == $wgArticle->getID() ) { return ''; }
1342
1343 $s = '';
1344 if ( !$wgDisableCounters ) {
1345 $count = $wgLang->formatNum( $wgArticle->getCount() );
1346 if ( $count ) {
1347 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1348 }
1349 }
1350
1351 if( $wgMaxCredits != 0 ){
1352 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1353 } else {
1354 $s .= $this->lastModified();
1355 }
1356
1357 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1358 $dbr = wfGetDB( DB_SLAVE );
1359 $res = $dbr->select( 'watchlist',
1360 array( 'COUNT(*) AS n' ),
1361 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
1362 __METHOD__
1363 );
1364 $x = $dbr->fetchObject( $res );
1365
1366 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1367 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1368 );
1369 }
1370
1371 return $s . ' ' . $this->getCopyright();
1372 }
1373
1374 function getCopyright( $type = 'detect' ) {
1375 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1376
1377 if ( $type == 'detect' ) {
1378 $diff = $wgRequest->getVal( 'diff' );
1379 $isCur = $wgArticle && $wgArticle->isCurrent();
1380 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1381 $type = 'history';
1382 } else {
1383 $type = 'normal';
1384 }
1385 }
1386
1387 if ( $type == 'history' ) {
1388 $msg = 'history_copyright';
1389 } else {
1390 $msg = 'copyright';
1391 }
1392
1393 $out = '';
1394 if( $wgRightsPage ) {
1395 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1396 } elseif( $wgRightsUrl ) {
1397 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1398 } elseif( $wgRightsText ) {
1399 $link = $wgRightsText;
1400 } else {
1401 # Give up now
1402 return $out;
1403 }
1404 $out .= wfMsgForContent( $msg, $link );
1405 return $out;
1406 }
1407
1408 function getCopyrightIcon() {
1409 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1410 $out = '';
1411 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1412 $out = $wgCopyrightIcon;
1413 } else if ( $wgRightsIcon ) {
1414 $icon = htmlspecialchars( $wgRightsIcon );
1415 if ( $wgRightsUrl ) {
1416 $url = htmlspecialchars( $wgRightsUrl );
1417 $out .= '<a href="'.$url.'">';
1418 }
1419 $text = htmlspecialchars( $wgRightsText );
1420 $out .= "<img src=\"$icon\" alt='$text' />";
1421 if ( $wgRightsUrl ) {
1422 $out .= '</a>';
1423 }
1424 }
1425 return $out;
1426 }
1427
1428 function getPoweredBy() {
1429 global $wgStylePath;
1430 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1431 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1432 return $img;
1433 }
1434
1435 function lastModified() {
1436 global $wgLang, $wgArticle;
1437 if( $this->mRevisionId ) {
1438 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1439 } else {
1440 $timestamp = $wgArticle->getTimestamp();
1441 }
1442 if ( $timestamp ) {
1443 $d = $wgLang->date( $timestamp, true );
1444 $t = $wgLang->time( $timestamp, true );
1445 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1446 } else {
1447 $s = '';
1448 }
1449 if ( wfGetLB()->getLaggedSlaveMode() ) {
1450 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1451 }
1452 return $s;
1453 }
1454
1455 function logoText( $align = '' ) {
1456 if ( '' != $align ) {
1457 $a = " align='{$align}'";
1458 } else {
1459 $a = '';
1460 }
1461
1462 $mp = wfMsg( 'mainpage' );
1463 $mptitle = Title::newMainPage();
1464 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1465
1466 $logourl = $this->getLogo();
1467 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1468 return $s;
1469 }
1470
1471 /**
1472 * show a drop-down box of special pages
1473 */
1474 function specialPagesList() {
1475 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1476 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1477 foreach ( $pages as $name => $page ) {
1478 $pages[$name] = $page->getDescription();
1479 }
1480
1481 $go = wfMsg( 'go' );
1482 $sp = wfMsg( 'specialpages' );
1483 $spp = $wgContLang->specialPage( 'Specialpages' );
1484
1485 $s = '<form id="specialpages" method="get" ' .
1486 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1487 $s .= "<select name=\"wpDropdown\">\n";
1488 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1489
1490
1491 foreach ( $pages as $name => $desc ) {
1492 $p = $wgContLang->specialPage( $name );
1493 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1494 }
1495 $s .= "</select>\n";
1496 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1497 $s .= "</form>\n";
1498 return $s;
1499 }
1500
1501 function mainPageLink() {
1502 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1503 return $s;
1504 }
1505
1506 function copyrightLink() {
1507 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1508 wfMsg( 'copyrightpagename' ) );
1509 return $s;
1510 }
1511
1512 private function footerLink ( $desc, $page ) {
1513 // if the link description has been set to "-" in the default language,
1514 if ( wfMsgForContent( $desc ) == '-') {
1515 // then it is disabled, for all languages.
1516 return '';
1517 } else {
1518 // Otherwise, we display the link for the user, described in their
1519 // language (which may or may not be the same as the default language),
1520 // but we make the link target be the one site-wide page.
1521 return $this->makeKnownLink( wfMsgForContent( $page ),
1522 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1523 }
1524 }
1525
1526 function privacyLink() {
1527 return $this->footerLink( 'privacy', 'privacypage' );
1528 }
1529
1530 function aboutLink() {
1531 return $this->footerLink( 'aboutsite', 'aboutpage' );
1532 }
1533
1534 function disclaimerLink() {
1535 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1536 }
1537
1538 function editThisPage() {
1539 global $wgOut;
1540
1541 if ( !$wgOut->isArticleRelated() ) {
1542 $s = wfMsg( 'protectedpage' );
1543 } else {
1544 if( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1545 $t = wfMsg( 'editthispage' );
1546 } elseif( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1547 $t = wfMsg( 'create-this-page' );
1548 } else {
1549 $t = wfMsg( 'viewsource' );
1550 }
1551
1552 $s = $this->makeKnownLinkObj( $this->mTitle, $t, $this->editUrlOptions() );
1553 }
1554 return $s;
1555 }
1556
1557 /**
1558 * Return URL options for the 'edit page' link.
1559 * This may include an 'oldid' specifier, if the current page view is such.
1560 *
1561 * @return string
1562 * @private
1563 */
1564 function editUrlOptions() {
1565 global $wgArticle;
1566
1567 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1568 return 'action=edit&oldid=' . intval( $this->mRevisionId );
1569 } else {
1570 return 'action=edit';
1571 }
1572 }
1573
1574 function deleteThisPage() {
1575 global $wgUser, $wgRequest;
1576
1577 $diff = $wgRequest->getVal( 'diff' );
1578 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1579 $t = wfMsg( 'deletethispage' );
1580
1581 $s = $this->makeKnownLinkObj( $this->mTitle, $t, 'action=delete' );
1582 } else {
1583 $s = '';
1584 }
1585 return $s;
1586 }
1587
1588 function protectThisPage() {
1589 global $wgUser, $wgRequest;
1590
1591 $diff = $wgRequest->getVal( 'diff' );
1592 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1593 if ( $this->mTitle->isProtected() ) {
1594 $t = wfMsg( 'unprotectthispage' );
1595 $q = 'action=unprotect';
1596 } else {
1597 $t = wfMsg( 'protectthispage' );
1598 $q = 'action=protect';
1599 }
1600 $s = $this->makeKnownLinkObj( $this->mTitle, $t, $q );
1601 } else {
1602 $s = '';
1603 }
1604 return $s;
1605 }
1606
1607 function watchThisPage() {
1608 global $wgOut;
1609 ++$this->mWatchLinkNum;
1610
1611 if ( $wgOut->isArticleRelated() ) {
1612 if ( $this->mTitle->userIsWatching() ) {
1613 $t = wfMsg( 'unwatchthispage' );
1614 $q = 'action=unwatch';
1615 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1616 } else {
1617 $t = wfMsg( 'watchthispage' );
1618 $q = 'action=watch';
1619 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1620 }
1621 $s = $this->makeKnownLinkObj( $this->mTitle, $t, $q, '', '', " id=\"$id\"" );
1622 } else {
1623 $s = wfMsg( 'notanarticle' );
1624 }
1625 return $s;
1626 }
1627
1628 function moveThisPage() {
1629 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1630 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1631 wfMsg( 'movethispage' ), 'target=' . $this->mTitle->getPrefixedURL() );
1632 } else {
1633 // no message if page is protected - would be redundant
1634 return '';
1635 }
1636 }
1637
1638 function historyLink() {
1639 return $this->link( $this->mTitle, wfMsgHtml( 'history' ),
1640 array( 'rel' => 'archives' ), array( 'action' => 'history' ) );
1641 }
1642
1643 function whatLinksHere() {
1644 return $this->makeKnownLinkObj(
1645 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1646 wfMsgHtml( 'whatlinkshere' ) );
1647 }
1648
1649 function userContribsLink() {
1650 return $this->makeKnownLinkObj(
1651 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1652 wfMsgHtml( 'contributions' ) );
1653 }
1654
1655 function showEmailUser( $id ) {
1656 global $wgUser;
1657 $targetUser = User::newFromId( $id );
1658 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1659 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1660 }
1661
1662 function emailUserLink() {
1663 return $this->makeKnownLinkObj(
1664 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1665 wfMsg( 'emailuser' ) );
1666 }
1667
1668 function watchPageLinksLink() {
1669 global $wgOut;
1670 if ( ! $wgOut->isArticleRelated() ) {
1671 return '(' . wfMsg( 'notanarticle' ) . ')';
1672 } else {
1673 return $this->makeKnownLinkObj(
1674 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1675 wfMsg( 'recentchangeslinked' ) );
1676 }
1677 }
1678
1679 function trackbackLink() {
1680 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1681 . wfMsg( 'trackbacklink' ) . '</a>';
1682 }
1683
1684 function otherLanguages() {
1685 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1686
1687 if ( $wgHideInterlanguageLinks ) {
1688 return '';
1689 }
1690
1691 $a = $wgOut->getLanguageLinks();
1692 if ( 0 == count( $a ) ) {
1693 return '';
1694 }
1695
1696 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1697 $first = true;
1698 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1699 foreach( $a as $l ) {
1700 if ( !$first ) {
1701 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1702 }
1703 $first = false;
1704
1705 $nt = Title::newFromText( $l );
1706 $url = $nt->escapeFullURL();
1707 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1708
1709 if ( '' == $text ) { $text = $l; }
1710 $style = $this->getExternalLinkAttributes( $l, $text );
1711 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1712 }
1713 if( $wgContLang->isRTL() ) $s .= '</span>';
1714 return $s;
1715 }
1716
1717 function talkLink() {
1718 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1719 # No discussion links for special pages
1720 return '';
1721 }
1722
1723 $linkOptions = array();
1724
1725 if( $this->mTitle->isTalkPage() ) {
1726 $link = $this->mTitle->getSubjectPage();
1727 switch( $link->getNamespace() ) {
1728 case NS_MAIN:
1729 $text = wfMsg( 'articlepage' );
1730 break;
1731 case NS_USER:
1732 $text = wfMsg( 'userpage' );
1733 break;
1734 case NS_PROJECT:
1735 $text = wfMsg( 'projectpage' );
1736 break;
1737 case NS_FILE:
1738 $text = wfMsg( 'imagepage' );
1739 # Make link known if image exists, even if the desc. page doesn't.
1740 if( wfFindFile( $link ) )
1741 $linkOptions[] = 'known';
1742 break;
1743 case NS_MEDIAWIKI:
1744 $text = wfMsg( 'mediawikipage' );
1745 break;
1746 case NS_TEMPLATE:
1747 $text = wfMsg( 'templatepage' );
1748 break;
1749 case NS_HELP:
1750 $text = wfMsg( 'viewhelppage' );
1751 break;
1752 case NS_CATEGORY:
1753 $text = wfMsg( 'categorypage' );
1754 break;
1755 default:
1756 $text = wfMsg( 'articlepage' );
1757 }
1758 } else {
1759 $link = $this->mTitle->getTalkPage();
1760 $text = wfMsg( 'talkpage' );
1761 }
1762
1763 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1764
1765 return $s;
1766 }
1767
1768 function commentLink() {
1769 global $wgOut;
1770
1771 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1772 return '';
1773 }
1774
1775 # __NEWSECTIONLINK___ changes behaviour here
1776 # If it's present, the link points to this page, otherwise
1777 # it points to the talk page
1778 if( $this->mTitle->isTalkPage() ) {
1779 $title = $this->mTitle;
1780 } elseif( $wgOut->showNewSectionLink() ) {
1781 $title = $this->mTitle;
1782 } else {
1783 $title = $this->mTitle->getTalkPage();
1784 }
1785
1786 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1787 }
1788
1789 /* these are used extensively in SkinTemplate, but also some other places */
1790 static function makeMainPageUrl( $urlaction = '' ) {
1791 $title = Title::newMainPage();
1792 self::checkTitle( $title, '' );
1793 return $title->getLocalURL( $urlaction );
1794 }
1795
1796 static function makeSpecialUrl( $name, $urlaction = '' ) {
1797 $title = SpecialPage::getTitleFor( $name );
1798 return $title->getLocalURL( $urlaction );
1799 }
1800
1801 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1802 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1803 return $title->getLocalURL( $urlaction );
1804 }
1805
1806 static function makeI18nUrl( $name, $urlaction = '' ) {
1807 $title = Title::newFromText( wfMsgForContent( $name ) );
1808 self::checkTitle( $title, $name );
1809 return $title->getLocalURL( $urlaction );
1810 }
1811
1812 static function makeUrl( $name, $urlaction = '' ) {
1813 $title = Title::newFromText( $name );
1814 self::checkTitle( $title, $name );
1815 return $title->getLocalURL( $urlaction );
1816 }
1817
1818 # If url string starts with http, consider as external URL, else
1819 # internal
1820 static function makeInternalOrExternalUrl( $name ) {
1821 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1822 return $name;
1823 } else {
1824 return self::makeUrl( $name );
1825 }
1826 }
1827
1828 # this can be passed the NS number as defined in Language.php
1829 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1830 $title = Title::makeTitleSafe( $namespace, $name );
1831 self::checkTitle( $title, $name );
1832 return $title->getLocalURL( $urlaction );
1833 }
1834
1835 /* these return an array with the 'href' and boolean 'exists' */
1836 static function makeUrlDetails( $name, $urlaction = '' ) {
1837 $title = Title::newFromText( $name );
1838 self::checkTitle( $title, $name );
1839 return array(
1840 'href' => $title->getLocalURL( $urlaction ),
1841 'exists' => $title->getArticleID() != 0 ? true : false
1842 );
1843 }
1844
1845 /**
1846 * Make URL details where the article exists (or at least it's convenient to think so)
1847 */
1848 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1849 $title = Title::newFromText( $name );
1850 self::checkTitle( $title, $name );
1851 return array(
1852 'href' => $title->getLocalURL( $urlaction ),
1853 'exists' => true
1854 );
1855 }
1856
1857 # make sure we have some title to operate on
1858 static function checkTitle( &$title, $name ) {
1859 if( !is_object( $title ) ) {
1860 $title = Title::newFromText( $name );
1861 if( !is_object( $title ) ) {
1862 $title = Title::newFromText( '--error: link target missing--' );
1863 }
1864 }
1865 }
1866
1867 /**
1868 * Build an array that represents the sidebar(s), the navigation bar among them
1869 *
1870 * @return array
1871 */
1872 function buildSidebar() {
1873 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1874 global $wgLang;
1875 wfProfileIn( __METHOD__ );
1876
1877 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1878
1879 if ( $wgEnableSidebarCache ) {
1880 $cachedsidebar = $parserMemc->get( $key );
1881 if ( $cachedsidebar ) {
1882 wfProfileOut( __METHOD__ );
1883 return $cachedsidebar;
1884 }
1885 }
1886
1887 $bar = array();
1888 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1889 $heading = '';
1890 foreach( $lines as $line ) {
1891 if( strpos( $line, '*' ) !== 0 )
1892 continue;
1893 if( strpos( $line, '**') !== 0 ) {
1894 $heading = trim( $line, '* ' );
1895 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
1896 } else {
1897 if( strpos( $line, '|' ) !== false ) { // sanity check
1898 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
1899 $link = wfMsgForContent( $line[0] );
1900 if( $link == '-' )
1901 continue;
1902
1903 $text = wfMsgExt( $line[1], 'parsemag' );
1904 if( wfEmptyMsg( $line[1], $text ) )
1905 $text = $line[1];
1906 if( wfEmptyMsg( $line[0], $link ) )
1907 $link = $line[0];
1908
1909 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1910 $href = $link;
1911 } else {
1912 $title = Title::newFromText( $link );
1913 if ( $title ) {
1914 $title = $title->fixSpecialName();
1915 $href = $title->getLocalURL();
1916 } else {
1917 $href = 'INVALID-TITLE';
1918 }
1919 }
1920
1921 $bar[$heading][] = array(
1922 'text' => $text,
1923 'href' => $href,
1924 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1925 'active' => false
1926 );
1927 } else { continue; }
1928 }
1929 }
1930 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1931 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1932 wfProfileOut( __METHOD__ );
1933 return $bar;
1934 }
1935 }