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