MediaWiki REL1_31
Message.php
Go to the documentation of this file.
1<?php
159class Message implements MessageSpecifier, Serializable {
161 const FORMAT_PLAIN = 'plain';
163 const FORMAT_BLOCK_PARSE = 'block-parse';
165 const FORMAT_PARSE = 'parse';
167 const FORMAT_TEXT = 'text';
169 const FORMAT_ESCAPED = 'escaped';
170
175 protected static $listTypeMap = [
176 'comma' => 'commaList',
177 'semicolon' => 'semicolonList',
178 'pipe' => 'pipeList',
179 'text' => 'listToText',
180 ];
181
188 protected $interface = true;
189
195 protected $language = false;
196
201 protected $key;
202
206 protected $keysToTry;
207
211 protected $parameters = [];
212
217 protected $format = 'parse';
218
222 protected $useDatabase = true;
223
227 protected $title = null;
228
232 protected $content = null;
233
237 protected $message;
238
248 public function __construct( $key, $params = [], Language $language = null ) {
249 if ( $key instanceof MessageSpecifier ) {
250 if ( $params ) {
251 throw new InvalidArgumentException(
252 '$params must be empty if $key is a MessageSpecifier'
253 );
254 }
255 $params = $key->getParams();
256 $key = $key->getKey();
257 }
258
259 if ( !is_string( $key ) && !is_array( $key ) ) {
260 throw new InvalidArgumentException( '$key must be a string or an array' );
261 }
262
263 $this->keysToTry = (array)$key;
264
265 if ( empty( $this->keysToTry ) ) {
266 throw new InvalidArgumentException( '$key must not be an empty list' );
267 }
268
269 $this->key = reset( $this->keysToTry );
270
271 $this->parameters = array_values( $params );
272 // User language is only resolved in getLanguage(). This helps preserve the
273 // semantic intent of "user language" across serialize() and unserialize().
274 $this->language = $language ?: false;
275 }
276
282 public function serialize() {
283 return serialize( [
284 'interface' => $this->interface,
285 'language' => $this->language ? $this->language->getCode() : false,
286 'key' => $this->key,
287 'keysToTry' => $this->keysToTry,
288 'parameters' => $this->parameters,
289 'format' => $this->format,
290 'useDatabase' => $this->useDatabase,
291 'title' => $this->title,
292 ] );
293 }
294
300 public function unserialize( $serialized ) {
301 $data = unserialize( $serialized );
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'];
307 $this->useDatabase = $data['useDatabase'];
308 $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
309 $this->title = $data['title'];
310 }
311
318 public function isMultiKey() {
319 return count( $this->keysToTry ) > 1;
320 }
321
328 public function getKeysToTry() {
329 return $this->keysToTry;
330 }
331
343 public function getKey() {
344 return $this->key;
345 }
346
354 public function getParams() {
355 return $this->parameters;
356 }
357
366 public function getFormat() {
367 wfDeprecated( __METHOD__, '1.29' );
368 return $this->format;
369 }
370
378 public function getLanguage() {
379 // Defaults to false which means current user language
380 return $this->language ?: RequestContext::getMain()->getLanguage();
381 }
382
395 public static function newFromKey( $key /*...*/ ) {
396 $params = func_get_args();
397 array_shift( $params );
398 return new self( $key, $params );
399 }
400
414 public static function newFromSpecifier( $value ) {
415 $params = [];
416 if ( is_array( $value ) ) {
417 $params = $value;
418 $value = array_shift( $params );
419 }
420
421 if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
422 $message = clone $value;
423 } elseif ( $value instanceof MessageSpecifier ) {
424 $message = new Message( $value );
425 } elseif ( is_string( $value ) ) {
426 $message = new Message( $value, $params );
427 } else {
428 throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
429 . gettype( $value ) );
430 }
431
432 return $message;
433 }
434
447 public static function newFallbackSequence( /*...*/ ) {
448 $keys = func_get_args();
449 if ( func_num_args() == 1 ) {
450 if ( is_array( $keys[0] ) ) {
451 // Allow an array to be passed as the first argument instead
452 $keys = array_values( $keys[0] );
453 } else {
454 // Optimize a single string to not need special fallback handling
455 $keys = $keys[0];
456 }
457 }
458 return new self( $keys );
459 }
460
471 public function getTitle() {
473
474 $title = $this->key;
475 if (
476 !$this->language->equals( $wgContLang )
477 && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
478 ) {
479 $code = $this->language->getCode();
480 $title .= '/' . $code;
481 }
482
483 return Title::makeTitle( NS_MEDIAWIKI, $wgContLang->ucfirst( strtr( $title, ' ', '_' ) ) );
484 }
485
496 public function params( /*...*/ ) {
497 $args = func_get_args();
498
499 // If $args has only one entry and it's an array, then it's either a
500 // non-varargs call or it happens to be a call with just a single
501 // "special" parameter. Since the "special" parameters don't have any
502 // numeric keys, we'll test that to differentiate the cases.
503 if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
504 if ( $args[0] === [] ) {
505 $args = [];
506 } else {
507 foreach ( $args[0] as $key => $value ) {
508 if ( is_int( $key ) ) {
509 $args = $args[0];
510 break;
511 }
512 }
513 }
514 }
515
516 $this->parameters = array_merge( $this->parameters, array_values( $args ) );
517 return $this;
518 }
519
533 public function rawParams( /*...*/ ) {
534 $params = func_get_args();
535 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
536 $params = $params[0];
537 }
538 foreach ( $params as $param ) {
539 $this->parameters[] = self::rawParam( $param );
540 }
541 return $this;
542 }
543
555 public function numParams( /*...*/ ) {
556 $params = func_get_args();
557 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
558 $params = $params[0];
559 }
560 foreach ( $params as $param ) {
561 $this->parameters[] = self::numParam( $param );
562 }
563 return $this;
564 }
565
577 public function durationParams( /*...*/ ) {
578 $params = func_get_args();
579 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
580 $params = $params[0];
581 }
582 foreach ( $params as $param ) {
583 $this->parameters[] = self::durationParam( $param );
584 }
585 return $this;
586 }
587
599 public function expiryParams( /*...*/ ) {
600 $params = func_get_args();
601 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
602 $params = $params[0];
603 }
604 foreach ( $params as $param ) {
605 $this->parameters[] = self::expiryParam( $param );
606 }
607 return $this;
608 }
609
621 public function timeperiodParams( /*...*/ ) {
622 $params = func_get_args();
623 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
624 $params = $params[0];
625 }
626 foreach ( $params as $param ) {
627 $this->parameters[] = self::timeperiodParam( $param );
628 }
629 return $this;
630 }
631
643 public function sizeParams( /*...*/ ) {
644 $params = func_get_args();
645 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
646 $params = $params[0];
647 }
648 foreach ( $params as $param ) {
649 $this->parameters[] = self::sizeParam( $param );
650 }
651 return $this;
652 }
653
665 public function bitrateParams( /*...*/ ) {
666 $params = func_get_args();
667 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
668 $params = $params[0];
669 }
670 foreach ( $params as $param ) {
671 $this->parameters[] = self::bitrateParam( $param );
672 }
673 return $this;
674 }
675
689 public function plaintextParams( /*...*/ ) {
690 $params = func_get_args();
691 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
692 $params = $params[0];
693 }
694 foreach ( $params as $param ) {
695 $this->parameters[] = self::plaintextParam( $param );
696 }
697 return $this;
698 }
699
709 public function setContext( IContextSource $context ) {
710 $this->inLanguage( $context->getLanguage() );
711 $this->title( $context->getTitle() );
712 $this->interface = true;
713
714 return $this;
715 }
716
728 public function inLanguage( $lang ) {
729 if ( $lang instanceof Language ) {
730 $this->language = $lang;
731 } elseif ( is_string( $lang ) ) {
732 if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
733 $this->language = Language::factory( $lang );
734 }
735 } elseif ( $lang instanceof StubUserLang ) {
736 $this->language = false;
737 } else {
738 $type = gettype( $lang );
739 throw new MWException( __METHOD__ . " must be "
740 . "passed a String or Language object; $type given"
741 );
742 }
743 $this->message = null;
744 $this->interface = false;
745 return $this;
746 }
747
757 public function inContentLanguage() {
759 if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
760 return $this;
761 }
762
764 $this->inLanguage( $wgContLang );
765 return $this;
766 }
767
778 public function setInterfaceMessageFlag( $interface ) {
779 $this->interface = (bool)$interface;
780 return $this;
781 }
782
792 public function useDatabase( $useDatabase ) {
793 $this->useDatabase = (bool)$useDatabase;
794 $this->message = null;
795 return $this;
796 }
797
807 public function title( $title ) {
808 $this->title = $title;
809 return $this;
810 }
811
817 public function content() {
818 if ( !$this->content ) {
819 $this->content = new MessageContent( $this );
820 }
821
822 return $this->content;
823 }
824
835 public function toString( $format = null ) {
836 if ( $format === null ) {
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 ] );
840 $format = $this->format;
841 }
842 $string = $this->fetchMessage();
843
844 if ( $string === false ) {
845 // Err on the side of safety, ensure that the output
846 // is always html safe in the event the message key is
847 // missing, since in that case its highly likely the
848 // message key is user-controlled.
849 // '⧼' is used instead of '<' to side-step any
850 // double-escaping issues.
851 // (Keep synchronised with mw.Message#toString in JS.)
852 return '⧼' . htmlspecialchars( $this->key ) . '⧽';
853 }
854
855 # Replace $* with a list of parameters for &uselang=qqx.
856 if ( strpos( $string, '$*' ) !== false ) {
857 $paramlist = '';
858 if ( $this->parameters !== [] ) {
859 $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
860 }
861 $string = str_replace( '$*', $paramlist, $string );
862 }
863
864 # Replace parameters before text parsing
865 $string = $this->replaceParameters( $string, 'before', $format );
866
867 # Maybe transform using the full parser
868 if ( $format === self::FORMAT_PARSE ) {
869 $string = $this->parseText( $string );
870 $string = Parser::stripOuterParagraph( $string );
871 } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
872 $string = $this->parseText( $string );
873 } elseif ( $format === self::FORMAT_TEXT ) {
874 $string = $this->transformText( $string );
875 } elseif ( $format === self::FORMAT_ESCAPED ) {
876 $string = $this->transformText( $string );
877 $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
878 }
879
880 # Raw parameter replacement
881 $string = $this->replaceParameters( $string, 'after', $format );
882
883 return $string;
884 }
885
895 public function __toString() {
896 // PHP doesn't allow __toString to throw exceptions and will
897 // trigger a fatal error if it does. So, catch any exceptions.
898
899 try {
900 return $this->toString( self::FORMAT_PARSE );
901 } catch ( Exception $ex ) {
902 try {
903 trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
904 . $ex, E_USER_WARNING );
905 } catch ( Exception $ex ) {
906 // Doh! Cause a fatal error after all?
907 }
908
909 return '⧼' . htmlspecialchars( $this->key ) . '⧽';
910 }
911 }
912
920 public function parse() {
921 $this->format = self::FORMAT_PARSE;
922 return $this->toString( self::FORMAT_PARSE );
923 }
924
932 public function text() {
933 $this->format = self::FORMAT_TEXT;
934 return $this->toString( self::FORMAT_TEXT );
935 }
936
944 public function plain() {
945 $this->format = self::FORMAT_PLAIN;
946 return $this->toString( self::FORMAT_PLAIN );
947 }
948
956 public function parseAsBlock() {
957 $this->format = self::FORMAT_BLOCK_PARSE;
958 return $this->toString( self::FORMAT_BLOCK_PARSE );
959 }
960
969 public function escaped() {
970 $this->format = self::FORMAT_ESCAPED;
971 return $this->toString( self::FORMAT_ESCAPED );
972 }
973
981 public function exists() {
982 return $this->fetchMessage() !== false;
983 }
984
993 public function isBlank() {
994 $message = $this->fetchMessage();
995 return $message === false || $message === '';
996 }
997
1005 public function isDisabled() {
1006 $message = $this->fetchMessage();
1007 return $message === false || $message === '' || $message === '-';
1008 }
1009
1017 public static function rawParam( $raw ) {
1018 return [ 'raw' => $raw ];
1019 }
1020
1028 public static function numParam( $num ) {
1029 return [ 'num' => $num ];
1030 }
1031
1039 public static function durationParam( $duration ) {
1040 return [ 'duration' => $duration ];
1041 }
1042
1050 public static function expiryParam( $expiry ) {
1051 return [ 'expiry' => $expiry ];
1052 }
1053
1061 public static function timeperiodParam( $period ) {
1062 return [ 'period' => $period ];
1063 }
1064
1072 public static function sizeParam( $size ) {
1073 return [ 'size' => $size ];
1074 }
1075
1083 public static function bitrateParam( $bitrate ) {
1084 return [ 'bitrate' => $bitrate ];
1085 }
1086
1094 public static function plaintextParam( $plaintext ) {
1095 return [ 'plaintext' => $plaintext ];
1096 }
1097
1105 public static function listParam( array $list, $type = 'text' ) {
1106 if ( !isset( self::$listTypeMap[$type] ) ) {
1107 throw new InvalidArgumentException(
1108 "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1109 );
1110 }
1111 return [ 'list' => $list, 'type' => $type ];
1112 }
1113
1125 protected function replaceParameters( $message, $type = 'before', $format ) {
1126 // A temporary marker for $1 parameters that is only valid
1127 // in non-attribute contexts. However if the entire message is escaped
1128 // then we don't want to use it because it will be mangled in all contexts
1129 // and its unnessary as ->escaped() messages aren't html.
1130 $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1131 $replacementKeys = [];
1132 foreach ( $this->parameters as $n => $param ) {
1133 list( $paramType, $value ) = $this->extractParam( $param, $format );
1134 if ( $type === 'before' ) {
1135 if ( $paramType === 'before' ) {
1136 $replacementKeys['$' . ( $n + 1 )] = $value;
1137 } else /* $paramType === 'after' */ {
1138 // To protect against XSS from replacing parameters
1139 // inside html attributes, we convert $1 to $'"1.
1140 // In the event that one of the parameters ends up
1141 // in an attribute, either the ' or the " will be
1142 // escaped, breaking the replacement and avoiding XSS.
1143 $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1144 }
1145 } else {
1146 if ( $paramType === 'after' ) {
1147 $replacementKeys[$marker . ( $n + 1 )] = $value;
1148 }
1149 }
1150 }
1151 $message = strtr( $message, $replacementKeys );
1152 return $message;
1153 }
1154
1165 protected function extractParam( $param, $format ) {
1166 if ( is_array( $param ) ) {
1167 if ( isset( $param['raw'] ) ) {
1168 return [ 'after', $param['raw'] ];
1169 } elseif ( isset( $param['num'] ) ) {
1170 // Replace number params always in before step for now.
1171 // No support for combined raw and num params
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'] ) ) {
1184 return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1185 } elseif ( isset( $param['list'] ) ) {
1186 return $this->formatListParam( $param['list'], $param['type'], $format );
1187 } else {
1188 if ( !is_scalar( $param ) ) {
1189 $param = serialize( $param );
1190 }
1191 \MediaWiki\Logger\LoggerFactory::getInstance( 'Bug58676' )->warning(
1192 'Invalid parameter for message "{msgkey}": {param}',
1193 [
1194 'exception' => new Exception,
1195 'msgkey' => $this->getKey(),
1196 'param' => htmlspecialchars( $param ),
1197 ]
1198 );
1199
1200 return [ 'before', '[INVALID]' ];
1201 }
1202 } elseif ( $param instanceof Message ) {
1203 // Match language, flags, etc. to the current message.
1204 $msg = clone $param;
1205 if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1206 // Cache depends on these parameters
1207 $msg->message = null;
1208 }
1209 $msg->interface = $this->interface;
1210 $msg->language = $this->language;
1211 $msg->useDatabase = $this->useDatabase;
1212 $msg->title = $this->title;
1213
1214 // DWIM
1215 if ( $format === 'block-parse' ) {
1216 $format = 'parse';
1217 }
1218 $msg->format = $format;
1219
1220 // Message objects should not be before parameters because
1221 // then they'll get double escaped. If the message needs to be
1222 // escaped, it'll happen right here when we call toString().
1223 return [ 'after', $msg->toString( $format ) ];
1224 } else {
1225 return [ 'before', $param ];
1226 }
1227 }
1228
1238 protected function parseText( $string ) {
1239 $out = MessageCache::singleton()->parse(
1240 $string,
1241 $this->title,
1242 /*linestart*/true,
1243 $this->interface,
1244 $this->getLanguage()
1245 );
1246
1247 return $out instanceof ParserOutput
1248 ? $out->getText( [
1249 'enableSectionEditLinks' => false,
1250 // Wrapping messages in an extra <div> is probably not expected. If
1251 // they're outside the content area they probably shouldn't be
1252 // targeted by CSS that's targeting the parser output, and if
1253 // they're inside they already are from the outer div.
1254 'unwrap' => true,
1255 ] )
1256 : $out;
1257 }
1258
1268 protected function transformText( $string ) {
1269 return MessageCache::singleton()->transform(
1270 $string,
1271 $this->interface,
1272 $this->getLanguage(),
1273 $this->title
1274 );
1275 }
1276
1285 protected function fetchMessage() {
1286 if ( $this->message === null ) {
1288
1289 foreach ( $this->keysToTry as $key ) {
1290 $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1291 if ( $message !== false && $message !== '' ) {
1292 break;
1293 }
1294 }
1295
1296 // NOTE: The constructor makes sure keysToTry isn't empty,
1297 // so we know that $key and $message are initialized.
1298 $this->key = $key;
1299 $this->message = $message;
1300 }
1301 return $this->message;
1302 }
1303
1316 protected function formatPlaintext( $plaintext, $format ) {
1317 switch ( $format ) {
1318 case self::FORMAT_TEXT:
1319 case self::FORMAT_PLAIN:
1320 return $plaintext;
1321
1322 case self::FORMAT_PARSE:
1323 case self::FORMAT_BLOCK_PARSE:
1324 case self::FORMAT_ESCAPED:
1325 default:
1326 return htmlspecialchars( $plaintext, ENT_QUOTES );
1327 }
1328 }
1329
1338 protected function formatListParam( array $params, $listType, $format ) {
1339 if ( !isset( self::$listTypeMap[$listType] ) ) {
1340 $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1341 . htmlspecialchars( $listType )
1342 . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1343 trigger_error( $warning, E_USER_WARNING );
1344 $e = new Exception;
1345 wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1346 return [ 'before', '[INVALID]' ];
1347 }
1348 $func = self::$listTypeMap[$listType];
1349
1350 // Handle an empty list sensibly
1351 if ( !$params ) {
1352 return [ 'before', $this->getLanguage()->$func( [] ) ];
1353 }
1354
1355 // First, determine what kinds of list items we have
1356 $types = [];
1357 $vars = [];
1358 $list = [];
1359 foreach ( $params as $n => $p ) {
1360 list( $type, $value ) = $this->extractParam( $p, $format );
1361 $types[$type] = true;
1362 $list[] = $value;
1363 $vars[] = '$' . ( $n + 1 );
1364 }
1365
1366 // Easy case: all are 'before' or 'after', so just join the
1367 // values and use the same type.
1368 if ( count( $types ) === 1 ) {
1369 return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1370 }
1371
1372 // Hard case: We need to process each value per its type, then
1373 // return the concatenated values as 'after'. We handle this by turning
1374 // the list into a RawMessage and processing that as a parameter.
1375 $vars = $this->getLanguage()->$func( $vars );
1376 return $this->extractParam( new RawMessage( $vars, $params ), $format );
1377 }
1378}
serialize()
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.
if( $line===false) $args
Definition cdb.php:64
Internationalisation code.
Definition Language.php:35
getCode()
Get the internal language code for this language object.
MediaWiki exception.
getTitle()
Get the Title object that we'll be acting on, as specified in the WebRequest.
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:
Definition Message.php:159
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition Message.php:1165
static listParam(array $list, $type='text')
Definition Message.php:1105
timeperiodParams()
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition Message.php:621
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
Definition Message.php:167
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition Message.php:1268
static rawParam( $raw)
Definition Message.php:1017
getParams()
Returns the message parameters.
Definition Message.php:354
durationParams()
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
Definition Message.php:577
static bitrateParam( $bitrate)
Definition Message.php:1083
static newFromKey( $key)
Factory function that is just wrapper for the real constructor.
Definition Message.php:395
numParams()
Add parameters that are numeric and will be passed through Language::formatNum before substitution.
Definition Message.php:555
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition Message.php:175
isMultiKey()
Definition Message.php:318
isBlank()
Check whether a message does not exist, or is an empty string.
Definition Message.php:993
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition Message.php:778
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
Definition Message.php:956
__construct( $key, $params=[], Language $language=null)
Definition Message.php:248
bool $useDatabase
Whether database can be used.
Definition Message.php:222
getKeysToTry()
Definition Message.php:328
parse()
Fully parse the text from wikitext to HTML.
Definition Message.php:920
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
Definition Message.php:165
__toString()
Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg: $foo = new Message( $k...
Definition Message.php:895
static newFallbackSequence()
Factory function accepting multiple message keys and returning a message instance for the first messa...
Definition Message.php:447
unserialize( $serialized)
Definition Message.php:300
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)
Definition Message.php:163
static sizeParam( $size)
Definition Message.php:1072
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition Message.php:1338
static timeperiodParam( $period)
Definition Message.php:1061
array $parameters
List of parameters which will be substituted into the message.
Definition Message.php:211
static plaintextParam( $plaintext)
Definition Message.php:1094
const FORMAT_PLAIN
Use message text as-is.
Definition Message.php:161
static durationParam( $duration)
Definition Message.php:1039
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
Definition Message.php:169
inLanguage( $lang)
Request the message in any language that is supported.
Definition Message.php:728
string $key
The message key.
Definition Message.php:201
sizeParams()
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
Definition Message.php:643
static numParam( $num)
Definition Message.php:1028
expiryParams()
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition Message.php:599
replaceParameters( $message, $type='before', $format)
Substitutes any parameters into the message text.
Definition Message.php:1125
inContentLanguage()
Request the message in the wiki's content language, unless it is disabled for this message.
Definition Message.php:757
plain()
Returns the message text as-is, only parameters are substituted.
Definition Message.php:944
exists()
Check whether a message key has been defined currently.
Definition Message.php:981
Content $content
Content object representing the message.
Definition Message.php:232
plaintextParams()
Add parameters that are plaintext and will be passed through without the content being evaluated.
Definition Message.php:689
rawParams()
Add parameters that are substituted after parsing or escaping.
Definition Message.php:533
title( $title)
Set the Title object to use as context when transforming the message.
Definition Message.php:807
Language bool $language
In which language to get this message.
Definition Message.php:195
getFormat()
Returns the message format.
Definition Message.php:366
useDatabase( $useDatabase)
Enable or disable database use.
Definition Message.php:792
fetchMessage()
Wrapper for what ever method we use to get message contents.
Definition Message.php:1285
content()
Returns the message as a Content object.
Definition Message.php:817
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with 'plaintext'.
Definition Message.php:1316
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
Definition Message.php:471
bitrateParams()
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition Message.php:665
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
Definition Message.php:1238
getKey()
Returns the message key.
Definition Message.php:343
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
Definition Message.php:1005
escaped()
Returns the message text.
Definition Message.php:969
params()
Adds parameters to the parameter list of this message.
Definition Message.php:496
getLanguage()
Returns the Language of the Message.
Definition Message.php:378
string $format
Definition Message.php:217
string $message
Definition Message.php:237
string[] $keysToTry
List of keys to try when fetching the message.
Definition Message.php:206
serialize()
Definition Message.php:282
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition Message.php:709
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Definition Message.php:835
Title $title
Title object to use as context.
Definition Message.php:227
text()
Returns the message text.
Definition Message.php:932
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:414
bool $interface
In which language to get this message.
Definition Message.php:188
static expiryParam( $expiry)
Definition Message.php:1050
getText( $options=[])
Get the output HTML.
Variant of the Message class.
static getMain()
Get the RequestContext object associated with the main request.
Stub object for the user language.
Represents a title within MediaWiki.
Definition Title.php:39
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
Definition deferred.txt:11
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
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
Definition design.txt:26
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
const NS_MEDIAWIKI
Definition Defines.php:82
the array() calling protocol came about after MediaWiki 1.4rc1.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2228
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
Definition hooks.txt:2163
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
Definition hooks.txt:865
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
Definition hooks.txt:2811
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
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
Definition hooks.txt:2006
if the prop value should be in the metadata multi language array format
Definition hooks.txt:1656
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
Definition hooks.txt:864
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
returning false will NOT prevent logging $e
Definition hooks.txt:2176
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
Definition injection.txt:37
Base interface for content objects.
Definition Content.php:34
Interface for objects which can provide a MediaWiki context on request.
$cache
Definition mcc.php:33
$params
foreach( $res as $row) $serialized
if(!isset( $args[0])) $lang