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