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