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