* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @defgroup Skins Skins
*/
* @ingroup Skins
*/
abstract class Skin extends ContextSource {
+ /**
+ * @var string|null
+ */
protected $skinname = null;
+
protected $mRelevantTitle = null;
protected $mRelevantUser = null;
static function normalizeKey( $key ) {
global $wgDefaultSkin, $wgFallbackSkin;
- $skinNames = Skin::getSkinNames();
+ $skinNames = self::getSkinNames();
// Make keys lowercase for case-insensitive matching.
$skinNames = array_change_key_case( $skinNames, CASE_LOWER );
}
/**
- * @return string Skin name
+ * @since 1.31
+ * @param string|null $skinname
+ */
+ public function __construct( $skinname = null ) {
+ if ( is_string( $skinname ) ) {
+ $this->skinname = $skinname;
+ }
+ }
+
+ /**
+ * @return string|null Skin name
*/
public function getSkinName() {
return $this->skinname;
global $wgUseAjax, $wgEnableAPI, $wgEnableWriteAPI;
$out = $this->getOutput();
+ $config = $this->getConfig();
$user = $out->getUser();
$modules = [
+ // modules not specific to any specific skin or page
+ 'core' => [
+ // Enforce various default modules for all pages and all skins
+ // Keep this list as small as possible
+ 'site',
+ 'mediawiki.page.startup',
+ 'mediawiki.user',
+ ],
// modules that enhance the page content in some way
'content' => [
'mediawiki.page.ready',
'user' => [],
];
+ // Support for high-density display images if enabled
+ if ( $config->get( 'ResponsiveImages' ) ) {
+ $modules['core'][] = 'mediawiki.hidpi';
+ }
+
// Preload jquery.tablesorter for mediawiki.page.ready
if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
$modules['content'][] = 'jquery.tablesorter';
$modules['content'][] = 'jquery.makeCollapsible';
}
+ if ( $out->isTOCEnabled() ) {
+ $modules['content'][] = 'mediawiki.toc';
+ }
+
// Add various resources if required
if ( $wgUseAjax && $wgEnableAPI ) {
if ( $wgEnableWriteAPI && $user->isLoggedIn()
* "<body>" tag, skins can override it if they have a need to add in any
* body attributes or classes of their own.
* @param OutputPage $out
- * @param array $bodyAttrs
+ * @param array &$bodyAttrs
*/
function addToBodyAttributes( $out, &$bodyAttrs ) {
// does nothing by default
/**
* make sure we have some title to operate on
*
- * @param Title $title
+ * @param Title &$title
* @param string $name
*/
static function checkTitle( &$title, $name ) {
};
if ( $wgEnableSidebarCache ) {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$sidebar = $cache->getWithSetCallback(
$cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
MessageCache::singleton()->isDisabled()
*
* This is just a wrapper around addToSidebarPlain() for backwards compatibility
*
- * @param array $bar
+ * @param array &$bar
* @param string $message
*/
public function addToSidebar( &$bar, $message ) {
/**
* Add content from plain text
* @since 1.17
- * @param array $bar
+ * @param array &$bar
* @param string $text
* @return array
*/
$bar[$heading][] = array_merge( [
'text' => $text,
'href' => $href,
- 'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
- 'active' => false
+ 'id' => Sanitizer::escapeIdForAttribute( 'n-' . strtr( $line[1], ' ', '-' ) ),
+ 'active' => false,
], $extraAttribs );
} else {
continue;
* @return string
*/
function getNewtalks() {
-
$newMessagesAlert = '';
$user = $this->getUser();
$newtalks = $user->getNewMessageLinks();
* should fall back to the next notice in its sequence
*/
private function getCachedNotice( $name ) {
- global $wgRenderHashAppend, $parserMemc, $wgContLang;
+ global $wgRenderHashAppend, $wgContLang;
$needParse = false;
$notice = $msg->plain();
}
- // Use the extra hash appender to let eg SSL variants separately cache.
- $key = wfMemcKey( $name . $wgRenderHashAppend );
- $cachedNotice = $parserMemc->get( $key );
- if ( is_array( $cachedNotice ) ) {
- if ( md5( $notice ) == $cachedNotice['hash'] ) {
- $notice = $cachedNotice['html'];
- } else {
- $needParse = true;
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ $parsed = $cache->getWithSetCallback(
+ // Use the extra hash appender to let eg SSL variants separately cache
+ // Key is verified with md5 hash of unparsed wikitext
+ $cache->makeKey( $name, $wgRenderHashAppend, md5( $notice ) ),
+ // TTL in seconds
+ 600,
+ function () use ( $notice ) {
+ return $this->getOutput()->parse( $notice );
}
- } else {
- $needParse = true;
- }
-
- if ( $needParse ) {
- $parsed = $this->getOutput()->parse( $notice );
- $parserMemc->set( $key, [ 'html' => $parsed, 'hash' => md5( $notice ) ], 600 );
- $notice = $parsed;
- }
+ );
- $notice = Html::rawElement( 'div', [ 'id' => 'localNotice',
- 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ], $notice );
- return $notice;
+ return Html::rawElement(
+ 'div',
+ [
+ 'id' => 'localNotice',
+ 'lang' => $wgContLang->getHtmlCode(),
+ 'dir' => $wgContLang->getDir()
+ ],
+ $parsed
+ );
}
/**