176 'comma' =>
'commaList',
177 'semicolon' =>
'semicolonList',
178 'pipe' =>
'pipeList',
179 'text' =>
'listToText',
251 throw new InvalidArgumentException(
252 '$params must be empty if $key is a MessageSpecifier'
259 if ( !is_string(
$key ) && !is_array(
$key ) ) {
260 throw new InvalidArgumentException(
'$key must be a string or an array' );
265 if ( empty( $this->keysToTry ) ) {
266 throw new InvalidArgumentException(
'$key must not be an empty list' );
269 $this->
key = reset( $this->keysToTry );
271 $this->parameters = array_values(
$params );
284 'interface' => $this->interface,
285 'language' => $this->language ? $this->language->getCode() :
false,
287 'keysToTry' => $this->keysToTry,
288 'parameters' => $this->parameters,
289 'format' => $this->format,
290 'useDatabase' => $this->useDatabase,
291 'title' => $this->title,
302 $this->
interface = $data['interface'];
303 $this->
key = $data[
'key'];
304 $this->keysToTry = $data[
'keysToTry'];
305 $this->parameters = $data[
'parameters'];
306 $this->
format = $data[
'format'];
308 $this->language = $data[
'language'] ? Language::factory( $data[
'language'] ) :
false;
309 $this->
title = $data[
'title'];
319 return count( $this->keysToTry ) > 1;
329 return $this->keysToTry;
355 return $this->parameters;
368 return $this->format;
416 if ( is_array(
$value ) ) {
425 } elseif ( is_string(
$value ) ) {
428 throw new InvalidArgumentException( __METHOD__ .
': invalid argument type '
448 $keys = func_get_args();
449 if ( func_num_args() == 1 ) {
450 if ( is_array(
$keys[0] ) ) {
458 return new self(
$keys );
477 && in_array( $this->
key, (
array)$wgForceUIMsgAsContentMsg )
479 $code = $this->language->getCode();
497 $args = func_get_args();
503 if ( count(
$args ) === 1 && isset(
$args[0] ) && is_array(
$args[0] ) ) {
504 if (
$args[0] === [] ) {
508 if ( is_int(
$key ) ) {
516 $this->parameters = array_merge( $this->parameters, array_values(
$args ) );
539 $this->parameters[] = self::rawParam( $param );
561 $this->parameters[] = self::numParam( $param );
583 $this->parameters[] = self::durationParam( $param );
605 $this->parameters[] = self::expiryParam( $param );
627 $this->parameters[] = self::timeperiodParam( $param );
649 $this->parameters[] = self::sizeParam( $param );
671 $this->parameters[] = self::bitrateParam( $param );
695 $this->parameters[] = self::plaintextParam( $param );
712 $this->
interface =
true;
730 $this->language =
$lang;
731 } elseif ( is_string(
$lang ) ) {
733 $this->language = Language::factory(
$lang );
736 $this->language =
false;
740 .
"passed a String or Language object; $type given"
744 $this->
interface =
false;
759 if ( in_array( $this->
key, (
array)$wgForceUIMsgAsContentMsg ) ) {
779 $this->
interface = (bool)$interface;
822 return $this->content;
837 $ex =
new LogicException( __METHOD__ .
' using implicit format: ' . $this->
format );
838 \MediaWiki\Logger\LoggerFactory::getInstance(
'message-format' )->warning(
839 $ex->getMessage(), [
'exception' => $ex,
'format' => $this->format,
'key' => $this->key ] );
844 if ( $string ===
false ) {
852 return '⧼' . htmlspecialchars( $this->
key ) .
'⧽';
855 # Replace $* with a list of parameters for &uselang=qqx.
856 if ( strpos( $string,
'$*' ) !==
false ) {
858 if ( $this->parameters !== [] ) {
859 $paramlist =
': $' . implode(
', $', range( 1, count( $this->parameters ) ) );
861 $string = str_replace(
'$*', $paramlist, $string );
864 # Replace parameters before text parsing
867 # Maybe transform using the full parser
868 if (
$format === self::FORMAT_PARSE ) {
870 $string = Parser::stripOuterParagraph( $string );
871 } elseif (
$format === self::FORMAT_BLOCK_PARSE ) {
873 } elseif (
$format === self::FORMAT_TEXT ) {
875 } elseif (
$format === self::FORMAT_ESCAPED ) {
877 $string = htmlspecialchars( $string, ENT_QUOTES,
'UTF-8',
false );
880 # Raw parameter replacement
900 return $this->
toString( self::FORMAT_PARSE );
901 }
catch ( Exception $ex ) {
903 trigger_error(
"Exception caught in " . __METHOD__ .
" (message " . $this->
key .
"): "
904 . $ex, E_USER_WARNING );
905 }
catch ( Exception $ex ) {
909 return '⧼' . htmlspecialchars( $this->
key ) .
'⧽';
921 $this->
format = self::FORMAT_PARSE;
922 return $this->
toString( self::FORMAT_PARSE );
933 $this->
format = self::FORMAT_TEXT;
934 return $this->
toString( self::FORMAT_TEXT );
945 $this->
format = self::FORMAT_PLAIN;
946 return $this->
toString( self::FORMAT_PLAIN );
957 $this->
format = self::FORMAT_BLOCK_PARSE;
958 return $this->
toString( self::FORMAT_BLOCK_PARSE );
970 $this->
format = self::FORMAT_ESCAPED;
971 return $this->
toString( self::FORMAT_ESCAPED );
1018 return [
'raw' => $raw ];
1029 return [
'num' => $num ];
1040 return [
'duration' => $duration ];
1051 return [
'expiry' => $expiry ];
1062 return [
'period' => $period ];
1073 return [
'size' => $size ];
1084 return [
'bitrate' => $bitrate ];
1095 return [
'plaintext' => $plaintext ];
1106 if ( !isset( self::$listTypeMap[
$type] ) ) {
1107 throw new InvalidArgumentException(
1108 "Invalid type '$type'. Known types are: " . join(
', ', array_keys( self::$listTypeMap ) )
1111 return [
'list' => $list,
'type' =>
$type ];
1130 $marker =
$format === self::FORMAT_ESCAPED ?
'$' :
'$\'"';
1131 $replacementKeys = [];
1132 foreach ( $this->parameters
as $n => $param ) {
1134 if (
$type ===
'before' ) {
1135 if ( $paramType ===
'before' ) {
1136 $replacementKeys[
'$' . ( $n + 1 )] =
$value;
1143 $replacementKeys[
'$' . ( $n + 1 )] = $marker . ( $n + 1 );
1146 if ( $paramType ===
'after' ) {
1147 $replacementKeys[$marker . ( $n + 1 )] =
$value;
1166 if ( is_array( $param ) ) {
1167 if ( isset( $param[
'raw'] ) ) {
1168 return [
'after', $param[
'raw'] ];
1169 } elseif ( isset( $param[
'num'] ) ) {
1172 return [
'before', $this->
getLanguage()->formatNum( $param[
'num'] ) ];
1173 } elseif ( isset( $param[
'duration'] ) ) {
1174 return [
'before', $this->
getLanguage()->formatDuration( $param[
'duration'] ) ];
1175 } elseif ( isset( $param[
'expiry'] ) ) {
1176 return [
'before', $this->
getLanguage()->formatExpiry( $param[
'expiry'] ) ];
1177 } elseif ( isset( $param[
'period'] ) ) {
1178 return [
'before', $this->
getLanguage()->formatTimePeriod( $param[
'period'] ) ];
1179 } elseif ( isset( $param[
'size'] ) ) {
1180 return [
'before', $this->
getLanguage()->formatSize( $param[
'size'] ) ];
1181 } elseif ( isset( $param[
'bitrate'] ) ) {
1182 return [
'before', $this->
getLanguage()->formatBitrate( $param[
'bitrate'] ) ];
1183 } elseif ( isset( $param[
'plaintext'] ) ) {
1185 } elseif ( isset( $param[
'list'] ) ) {
1188 $warning =
'Invalid parameter for message "' . $this->
getKey() .
'": ' .
1189 htmlspecialchars(
serialize( $param ) );
1190 trigger_error( $warning, E_USER_WARNING );
1192 wfDebugLog(
'Bug58676', $warning .
"\n" .
$e->getTraceAsString() );
1194 return [
'before',
'[INVALID]' ];
1196 } elseif ( $param instanceof
Message ) {
1198 $msg = clone $param;
1199 if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1201 $msg->message =
null;
1203 $msg->interface = $this->interface;
1204 $msg->language = $this->language;
1205 $msg->useDatabase = $this->useDatabase;
1206 $msg->title = $this->title;
1209 if (
$format ===
'block-parse' ) {
1217 return [
'after', $msg->toString(
$format ) ];
1219 return [
'before', $param ];
1271 if ( $this->
message ===
null ) {
1274 foreach ( $this->keysToTry
as $key ) {
1286 return $this->message;
1303 case self::FORMAT_TEXT:
1304 case self::FORMAT_PLAIN:
1307 case self::FORMAT_PARSE:
1308 case self::FORMAT_BLOCK_PARSE:
1309 case self::FORMAT_ESCAPED:
1311 return htmlspecialchars( $plaintext, ENT_QUOTES );
1325 if ( !isset( self::$listTypeMap[$listType] ) ) {
1326 $warning =
'Invalid list type for message "' . $this->
getKey() .
'": '
1327 . htmlspecialchars( $listType )
1329 trigger_error( $warning, E_USER_WARNING );
1331 wfDebugLog(
'Bug58676', $warning .
"\n" .
$e->getTraceAsString() );
1332 return [
'before',
'[INVALID]' ];
1334 $func = self::$listTypeMap[$listType];
1338 return [
'before', $this->
getLanguage()->$func( [] ) ];
1347 $types[
$type] =
true;
1349 $vars[] =
'$' . ( $n + 1 );
1354 if ( count( $types ) === 1 ) {
unserialize( $serialized)
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Internationalisation code.
getCode()
Get the internal language code for this language object.
static singleton()
Get the signleton instance of this class.
Wrapper allowing us to handle a system message as a Content object.
The Message class provides methods which fulfil two basic services:
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
static listParam(array $list, $type='text')
timeperiodParams()
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
getParams()
Returns the message parameters.
durationParams()
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
static bitrateParam( $bitrate)
static newFromKey( $key)
Factory function that is just wrapper for the real constructor.
numParams()
Add parameters that are numeric and will be passed through Language::formatNum before substitution.
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
isBlank()
Check whether a message does not exist, or is an empty string.
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
__construct( $key, $params=[], Language $language=null)
bool $useDatabase
Whether database can be used.
parse()
Fully parse the text from wikitext to HTML.
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
__toString()
Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg: $foo = new Message( $k...
static newFallbackSequence()
Factory function accepting multiple message keys and returning a message instance for the first messa...
unserialize( $serialized)
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
static timeperiodParam( $period)
array $parameters
List of parameters which will be substituted into the message.
static plaintextParam( $plaintext)
const FORMAT_PLAIN
Use message text as-is.
static durationParam( $duration)
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
inLanguage( $lang)
Request the message in any language that is supported.
string $key
The message key.
sizeParams()
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
expiryParams()
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
replaceParameters( $message, $type='before', $format)
Substitutes any parameters into the message text.
inContentLanguage()
Request the message in the wiki's content language, unless it is disabled for this message.
plain()
Returns the message text as-is, only parameters are substituted.
exists()
Check whether a message key has been defined currently.
Content $content
Content object representing the message.
plaintextParams()
Add parameters that are plaintext and will be passed through without the content being evaluated.
rawParams()
Add parameters that are substituted after parsing or escaping.
title( $title)
Set the Title object to use as context when transforming the message.
Language bool $language
In which language to get this message.
getFormat()
Returns the message format.
useDatabase( $useDatabase)
Enable or disable database use.
fetchMessage()
Wrapper for what ever method we use to get message contents.
content()
Returns the message as a Content object.
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with 'plaintext'.
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
bitrateParams()
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
getKey()
Returns the message key.
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
escaped()
Returns the message text.
params()
Adds parameters to the parameter list of this message.
getLanguage()
Returns the Language of the Message.
string[] $keysToTry
List of keys to try when fetching the message.
setContext(IContextSource $context)
Set the language and the title from a context object.
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Title $title
Title object to use as context.
text()
Returns the message text.
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
bool $interface
In which language to get this message.
static expiryParam( $expiry)
Variant of the Message class.
static getMain()
Static methods.
Stub object for the user language.
Represents a title within MediaWiki.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
when a variable name is used in a it is silently declared as a new local masking the global
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
the array() calling protocol came about after MediaWiki 1.4rc1.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a message
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
namespace and then decline to actually register it file or subcat img or subcat $title
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
if the prop value should be in the metadata multi language array format
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Base interface for content objects.
Interface for objects which can provide a MediaWiki context on request.
foreach( $res as $row) $serialized
if(!isset( $args[0])) $lang