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