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