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