MediaWiki REL1_32
Message.php
Go to the documentation of this file.
1<?php
24
160class Message implements MessageSpecifier, Serializable {
162 const FORMAT_PLAIN = 'plain';
164 const FORMAT_BLOCK_PARSE = 'block-parse';
166 const FORMAT_PARSE = 'parse';
168 const FORMAT_TEXT = 'text';
170 const FORMAT_ESCAPED = 'escaped';
171
176 protected static $listTypeMap = [
177 'comma' => 'commaList',
178 'semicolon' => 'semicolonList',
179 'pipe' => 'pipeList',
180 'text' => 'listToText',
181 ];
182
189 protected $interface = true;
190
196 protected $language = false;
197
202 protected $key;
203
207 protected $keysToTry;
208
212 protected $parameters = [];
213
218 protected $format = 'parse';
219
223 protected $useDatabase = true;
224
228 protected $title = null;
229
233 protected $content = null;
234
238 protected $message;
239
249 public function __construct( $key, $params = [], Language $language = null ) {
250 if ( $key instanceof MessageSpecifier ) {
251 if ( $params ) {
252 throw new InvalidArgumentException(
253 '$params must be empty if $key is a MessageSpecifier'
254 );
255 }
256 $params = $key->getParams();
257 $key = $key->getKey();
258 }
259
260 if ( !is_string( $key ) && !is_array( $key ) ) {
261 throw new InvalidArgumentException( '$key must be a string or an array' );
262 }
263
264 $this->keysToTry = (array)$key;
265
266 if ( empty( $this->keysToTry ) ) {
267 throw new InvalidArgumentException( '$key must not be an empty list' );
268 }
269
270 $this->key = reset( $this->keysToTry );
271
272 $this->parameters = array_values( $params );
273 // User language is only resolved in getLanguage(). This helps preserve the
274 // semantic intent of "user language" across serialize() and unserialize().
275 $this->language = $language ?: false;
276 }
277
283 public function serialize() {
284 return serialize( [
285 'interface' => $this->interface,
286 'language' => $this->language ? $this->language->getCode() : false,
287 'key' => $this->key,
288 'keysToTry' => $this->keysToTry,
289 'parameters' => $this->parameters,
290 'format' => $this->format,
291 'useDatabase' => $this->useDatabase,
292 'title' => $this->title,
293 ] );
294 }
295
301 public function unserialize( $serialized ) {
302 $data = unserialize( $serialized );
303 $this->interface = $data['interface'];
304 $this->key = $data['key'];
305 $this->keysToTry = $data['keysToTry'];
306 $this->parameters = $data['parameters'];
307 $this->format = $data['format'];
308 $this->useDatabase = $data['useDatabase'];
309 $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
310 $this->title = $data['title'];
311 }
312
319 public function isMultiKey() {
320 return count( $this->keysToTry ) > 1;
321 }
322
329 public function getKeysToTry() {
330 return $this->keysToTry;
331 }
332
344 public function getKey() {
345 return $this->key;
346 }
347
355 public function getParams() {
356 return $this->parameters;
357 }
358
367 public function getFormat() {
368 wfDeprecated( __METHOD__, '1.29' );
369 return $this->format;
370 }
371
379 public function getLanguage() {
380 // Defaults to false which means current user language
381 return $this->language ?: RequestContext::getMain()->getLanguage();
382 }
383
396 public static function newFromKey( $key /*...*/ ) {
397 $params = func_get_args();
398 array_shift( $params );
399 return new self( $key, $params );
400 }
401
415 public static function newFromSpecifier( $value ) {
416 $params = [];
417 if ( is_array( $value ) ) {
418 $params = $value;
419 $value = array_shift( $params );
420 }
421
422 if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
423 $message = clone $value;
424 } elseif ( $value instanceof MessageSpecifier ) {
425 $message = new Message( $value );
426 } elseif ( is_string( $value ) ) {
427 $message = new Message( $value, $params );
428 } else {
429 throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
430 . gettype( $value ) );
431 }
432
433 return $message;
434 }
435
448 public static function newFallbackSequence( /*...*/ ) {
449 $keys = func_get_args();
450 if ( func_num_args() == 1 ) {
451 if ( is_array( $keys[0] ) ) {
452 // Allow an array to be passed as the first argument instead
453 $keys = array_values( $keys[0] );
454 } else {
455 // Optimize a single string to not need special fallback handling
456 $keys = $keys[0];
457 }
458 }
459 return new self( $keys );
460 }
461
472 public function getTitle() {
474
475 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
476 $lang = $this->getLanguage();
477 $title = $this->key;
478 if (
479 !$lang->equals( $contLang )
480 && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
481 ) {
482 $title .= '/' . $lang->getCode();
483 }
484
485 return Title::makeTitle(
486 NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
487 }
488
499 public function params( /*...*/ ) {
500 $args = func_get_args();
501
502 // If $args has only one entry and it's an array, then it's either a
503 // non-varargs call or it happens to be a call with just a single
504 // "special" parameter. Since the "special" parameters don't have any
505 // numeric keys, we'll test that to differentiate the cases.
506 if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
507 if ( $args[0] === [] ) {
508 $args = [];
509 } else {
510 foreach ( $args[0] as $key => $value ) {
511 if ( is_int( $key ) ) {
512 $args = $args[0];
513 break;
514 }
515 }
516 }
517 }
518
519 $this->parameters = array_merge( $this->parameters, array_values( $args ) );
520 return $this;
521 }
522
536 public function rawParams( /*...*/ ) {
537 $params = func_get_args();
538 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
539 $params = $params[0];
540 }
541 foreach ( $params as $param ) {
542 $this->parameters[] = self::rawParam( $param );
543 }
544 return $this;
545 }
546
558 public function numParams( /*...*/ ) {
559 $params = func_get_args();
560 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
561 $params = $params[0];
562 }
563 foreach ( $params as $param ) {
564 $this->parameters[] = self::numParam( $param );
565 }
566 return $this;
567 }
568
580 public function durationParams( /*...*/ ) {
581 $params = func_get_args();
582 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
583 $params = $params[0];
584 }
585 foreach ( $params as $param ) {
586 $this->parameters[] = self::durationParam( $param );
587 }
588 return $this;
589 }
590
602 public function expiryParams( /*...*/ ) {
603 $params = func_get_args();
604 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
605 $params = $params[0];
606 }
607 foreach ( $params as $param ) {
608 $this->parameters[] = self::expiryParam( $param );
609 }
610 return $this;
611 }
612
624 public function timeperiodParams( /*...*/ ) {
625 $params = func_get_args();
626 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
627 $params = $params[0];
628 }
629 foreach ( $params as $param ) {
630 $this->parameters[] = self::timeperiodParam( $param );
631 }
632 return $this;
633 }
634
646 public function sizeParams( /*...*/ ) {
647 $params = func_get_args();
648 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
649 $params = $params[0];
650 }
651 foreach ( $params as $param ) {
652 $this->parameters[] = self::sizeParam( $param );
653 }
654 return $this;
655 }
656
668 public function bitrateParams( /*...*/ ) {
669 $params = func_get_args();
670 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
671 $params = $params[0];
672 }
673 foreach ( $params as $param ) {
674 $this->parameters[] = self::bitrateParam( $param );
675 }
676 return $this;
677 }
678
692 public function plaintextParams( /*...*/ ) {
693 $params = func_get_args();
694 if ( isset( $params[0] ) && is_array( $params[0] ) ) {
695 $params = $params[0];
696 }
697 foreach ( $params as $param ) {
698 $this->parameters[] = self::plaintextParam( $param );
699 }
700 return $this;
701 }
702
712 public function setContext( IContextSource $context ) {
713 $this->inLanguage( $context->getLanguage() );
714 $this->title( $context->getTitle() );
715 $this->interface = true;
716
717 return $this;
718 }
719
731 public function inLanguage( $lang ) {
732 $previousLanguage = $this->language;
733
734 if ( $lang instanceof Language ) {
735 $this->language = $lang;
736 } elseif ( is_string( $lang ) ) {
737 if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
738 $this->language = Language::factory( $lang );
739 }
740 } elseif ( $lang instanceof StubUserLang ) {
741 $this->language = false;
742 } else {
743 $type = gettype( $lang );
744 throw new MWException( __METHOD__ . " must be "
745 . "passed a String or Language object; $type given"
746 );
747 }
748
749 if ( $this->language !== $previousLanguage ) {
750 // The language has changed. Clear the message cache.
751 $this->message = null;
752 }
753 $this->interface = false;
754 return $this;
755 }
756
766 public function inContentLanguage() {
768 if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
769 return $this;
770 }
771
772 $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
773 return $this;
774 }
775
786 public function setInterfaceMessageFlag( $interface ) {
787 $this->interface = (bool)$interface;
788 return $this;
789 }
790
800 public function useDatabase( $useDatabase ) {
801 $this->useDatabase = (bool)$useDatabase;
802 $this->message = null;
803 return $this;
804 }
805
815 public function title( $title ) {
816 $this->title = $title;
817 return $this;
818 }
819
825 public function content() {
826 if ( !$this->content ) {
827 $this->content = new MessageContent( $this );
828 }
829
830 return $this->content;
831 }
832
844 public function toString( $format = null ) {
845 if ( $format === null ) {
846 $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
847 \MediaWiki\Logger\LoggerFactory::getInstance( 'message-format' )->warning(
848 $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
849 $format = $this->format;
850 }
851 $string = $this->fetchMessage();
852
853 if ( $string === false ) {
854 // Err on the side of safety, ensure that the output
855 // is always html safe in the event the message key is
856 // missing, since in that case its highly likely the
857 // message key is user-controlled.
858 // '⧼' is used instead of '<' to side-step any
859 // double-escaping issues.
860 // (Keep synchronised with mw.Message#toString in JS.)
861 return '⧼' . htmlspecialchars( $this->key ) . '⧽';
862 }
863
864 # Replace $* with a list of parameters for &uselang=qqx.
865 if ( strpos( $string, '$*' ) !== false ) {
866 $paramlist = '';
867 if ( $this->parameters !== [] ) {
868 $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
869 }
870 $string = str_replace( '$*', $paramlist, $string );
871 }
872
873 # Replace parameters before text parsing
874 $string = $this->replaceParameters( $string, 'before', $format );
875
876 # Maybe transform using the full parser
877 if ( $format === self::FORMAT_PARSE ) {
878 $string = $this->parseText( $string );
879 $string = Parser::stripOuterParagraph( $string );
880 } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
881 $string = $this->parseText( $string );
882 } elseif ( $format === self::FORMAT_TEXT ) {
883 $string = $this->transformText( $string );
884 } elseif ( $format === self::FORMAT_ESCAPED ) {
885 $string = $this->transformText( $string );
886 $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
887 }
888
889 # Raw parameter replacement
890 $string = $this->replaceParameters( $string, 'after', $format );
891
892 return $string;
893 }
894
904 public function __toString() {
905 // PHP doesn't allow __toString to throw exceptions and will
906 // trigger a fatal error if it does. So, catch any exceptions.
907
908 try {
909 return $this->toString( self::FORMAT_PARSE );
910 } catch ( Exception $ex ) {
911 try {
912 trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
913 . $ex, E_USER_WARNING );
914 } catch ( Exception $ex ) {
915 // Doh! Cause a fatal error after all?
916 }
917
918 return '⧼' . htmlspecialchars( $this->key ) . '⧽';
919 }
920 }
921
929 public function parse() {
930 $this->format = self::FORMAT_PARSE;
931 return $this->toString( self::FORMAT_PARSE );
932 }
933
941 public function text() {
942 $this->format = self::FORMAT_TEXT;
943 return $this->toString( self::FORMAT_TEXT );
944 }
945
953 public function plain() {
954 $this->format = self::FORMAT_PLAIN;
955 return $this->toString( self::FORMAT_PLAIN );
956 }
957
965 public function parseAsBlock() {
966 $this->format = self::FORMAT_BLOCK_PARSE;
967 return $this->toString( self::FORMAT_BLOCK_PARSE );
968 }
969
978 public function escaped() {
979 $this->format = self::FORMAT_ESCAPED;
980 return $this->toString( self::FORMAT_ESCAPED );
981 }
982
990 public function exists() {
991 return $this->fetchMessage() !== false;
992 }
993
1002 public function isBlank() {
1003 $message = $this->fetchMessage();
1004 return $message === false || $message === '';
1005 }
1006
1014 public function isDisabled() {
1015 $message = $this->fetchMessage();
1016 return $message === false || $message === '' || $message === '-';
1017 }
1018
1026 public static function rawParam( $raw ) {
1027 return [ 'raw' => $raw ];
1028 }
1029
1037 public static function numParam( $num ) {
1038 return [ 'num' => $num ];
1039 }
1040
1048 public static function durationParam( $duration ) {
1049 return [ 'duration' => $duration ];
1050 }
1051
1059 public static function expiryParam( $expiry ) {
1060 return [ 'expiry' => $expiry ];
1061 }
1062
1070 public static function timeperiodParam( $period ) {
1071 return [ 'period' => $period ];
1072 }
1073
1081 public static function sizeParam( $size ) {
1082 return [ 'size' => $size ];
1083 }
1084
1092 public static function bitrateParam( $bitrate ) {
1093 return [ 'bitrate' => $bitrate ];
1094 }
1095
1103 public static function plaintextParam( $plaintext ) {
1104 return [ 'plaintext' => $plaintext ];
1105 }
1106
1114 public static function listParam( array $list, $type = 'text' ) {
1115 if ( !isset( self::$listTypeMap[$type] ) ) {
1116 throw new InvalidArgumentException(
1117 "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1118 );
1119 }
1120 return [ 'list' => $list, 'type' => $type ];
1121 }
1122
1134 protected function replaceParameters( $message, $type, $format ) {
1135 // A temporary marker for $1 parameters that is only valid
1136 // in non-attribute contexts. However if the entire message is escaped
1137 // then we don't want to use it because it will be mangled in all contexts
1138 // and its unnessary as ->escaped() messages aren't html.
1139 $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1140 $replacementKeys = [];
1141 foreach ( $this->parameters as $n => $param ) {
1142 list( $paramType, $value ) = $this->extractParam( $param, $format );
1143 if ( $type === 'before' ) {
1144 if ( $paramType === 'before' ) {
1145 $replacementKeys['$' . ( $n + 1 )] = $value;
1146 } else /* $paramType === 'after' */ {
1147 // To protect against XSS from replacing parameters
1148 // inside html attributes, we convert $1 to $'"1.
1149 // In the event that one of the parameters ends up
1150 // in an attribute, either the ' or the " will be
1151 // escaped, breaking the replacement and avoiding XSS.
1152 $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1153 }
1154 } else {
1155 if ( $paramType === 'after' ) {
1156 $replacementKeys[$marker . ( $n + 1 )] = $value;
1157 }
1158 }
1159 }
1160 $message = strtr( $message, $replacementKeys );
1161 return $message;
1162 }
1163
1174 protected function extractParam( $param, $format ) {
1175 if ( is_array( $param ) ) {
1176 if ( isset( $param['raw'] ) ) {
1177 return [ 'after', $param['raw'] ];
1178 } elseif ( isset( $param['num'] ) ) {
1179 // Replace number params always in before step for now.
1180 // No support for combined raw and num params
1181 return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1182 } elseif ( isset( $param['duration'] ) ) {
1183 return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1184 } elseif ( isset( $param['expiry'] ) ) {
1185 return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1186 } elseif ( isset( $param['period'] ) ) {
1187 return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1188 } elseif ( isset( $param['size'] ) ) {
1189 return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1190 } elseif ( isset( $param['bitrate'] ) ) {
1191 return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1192 } elseif ( isset( $param['plaintext'] ) ) {
1193 return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1194 } elseif ( isset( $param['list'] ) ) {
1195 return $this->formatListParam( $param['list'], $param['type'], $format );
1196 } else {
1197 if ( !is_scalar( $param ) ) {
1198 $param = serialize( $param );
1199 }
1200 \MediaWiki\Logger\LoggerFactory::getInstance( 'Bug58676' )->warning(
1201 'Invalid parameter for message "{msgkey}": {param}',
1202 [
1203 'exception' => new Exception,
1204 'msgkey' => $this->getKey(),
1205 'param' => htmlspecialchars( $param ),
1206 ]
1207 );
1208
1209 return [ 'before', '[INVALID]' ];
1210 }
1211 } elseif ( $param instanceof Message ) {
1212 // Match language, flags, etc. to the current message.
1213 $msg = clone $param;
1214 if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1215 // Cache depends on these parameters
1216 $msg->message = null;
1217 }
1218 $msg->interface = $this->interface;
1219 $msg->language = $this->language;
1220 $msg->useDatabase = $this->useDatabase;
1221 $msg->title = $this->title;
1222
1223 // DWIM
1224 if ( $format === 'block-parse' ) {
1225 $format = 'parse';
1226 }
1227 $msg->format = $format;
1228
1229 // Message objects should not be before parameters because
1230 // then they'll get double escaped. If the message needs to be
1231 // escaped, it'll happen right here when we call toString().
1232 return [ 'after', $msg->toString( $format ) ];
1233 } else {
1234 return [ 'before', $param ];
1235 }
1236 }
1237
1247 protected function parseText( $string ) {
1248 $out = MessageCache::singleton()->parse(
1249 $string,
1250 $this->title,
1251 /*linestart*/true,
1252 $this->interface,
1253 $this->getLanguage()
1254 );
1255
1256 return $out instanceof ParserOutput
1257 ? $out->getText( [
1258 'enableSectionEditLinks' => false,
1259 // Wrapping messages in an extra <div> is probably not expected. If
1260 // they're outside the content area they probably shouldn't be
1261 // targeted by CSS that's targeting the parser output, and if
1262 // they're inside they already are from the outer div.
1263 'unwrap' => true,
1264 ] )
1265 : $out;
1266 }
1267
1277 protected function transformText( $string ) {
1278 return MessageCache::singleton()->transform(
1279 $string,
1280 $this->interface,
1281 $this->getLanguage(),
1282 $this->title
1283 );
1284 }
1285
1294 protected function fetchMessage() {
1295 if ( $this->message === null ) {
1296 $cache = MessageCache::singleton();
1297
1298 foreach ( $this->keysToTry as $key ) {
1299 $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1300 if ( $message !== false && $message !== '' ) {
1301 break;
1302 }
1303 }
1304
1305 // NOTE: The constructor makes sure keysToTry isn't empty,
1306 // so we know that $key and $message are initialized.
1307 $this->key = $key;
1308 $this->message = $message;
1309 }
1310 return $this->message;
1311 }
1312
1325 protected function formatPlaintext( $plaintext, $format ) {
1326 switch ( $format ) {
1327 case self::FORMAT_TEXT:
1328 case self::FORMAT_PLAIN:
1329 return $plaintext;
1330
1331 case self::FORMAT_PARSE:
1332 case self::FORMAT_BLOCK_PARSE:
1333 case self::FORMAT_ESCAPED:
1334 default:
1335 return htmlspecialchars( $plaintext, ENT_QUOTES );
1336 }
1337 }
1338
1347 protected function formatListParam( array $params, $listType, $format ) {
1348 if ( !isset( self::$listTypeMap[$listType] ) ) {
1349 $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1350 . htmlspecialchars( $listType )
1351 . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1352 trigger_error( $warning, E_USER_WARNING );
1353 $e = new Exception;
1354 wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1355 return [ 'before', '[INVALID]' ];
1356 }
1357 $func = self::$listTypeMap[$listType];
1358
1359 // Handle an empty list sensibly
1360 if ( !$params ) {
1361 return [ 'before', $this->getLanguage()->$func( [] ) ];
1362 }
1363
1364 // First, determine what kinds of list items we have
1365 $types = [];
1366 $vars = [];
1367 $list = [];
1368 foreach ( $params as $n => $p ) {
1369 list( $type, $value ) = $this->extractParam( $p, $format );
1370 $types[$type] = true;
1371 $list[] = $value;
1372 $vars[] = '$' . ( $n + 1 );
1373 }
1374
1375 // Easy case: all are 'before' or 'after', so just join the
1376 // values and use the same type.
1377 if ( count( $types ) === 1 ) {
1378 return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1379 }
1380
1381 // Hard case: We need to process each value per its type, then
1382 // return the concatenated values as 'after'. We handle this by turning
1383 // the list into a RawMessage and processing that as a parameter.
1384 $vars = $this->getLanguage()->$func( $vars );
1385 return $this->extractParam( new RawMessage( $vars, $params ), $format );
1386 }
1387}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
getTitle()
Get the Title object that we'll be acting on, as specified in the WebRequest.
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:160
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition Message.php:1174
static listParam(array $list, $type='text')
Definition Message.php:1114
timeperiodParams()
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition Message.php:624
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
Definition Message.php:168
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition Message.php:1277
static rawParam( $raw)
Definition Message.php:1026
getParams()
Returns the message parameters.
Definition Message.php:355
durationParams()
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
Definition Message.php:580
static bitrateParam( $bitrate)
Definition Message.php:1092
static newFromKey( $key)
Factory function that is just wrapper for the real constructor.
Definition Message.php:396
numParams()
Add parameters that are numeric and will be passed through Language::formatNum before substitution.
Definition Message.php:558
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition Message.php:176
isMultiKey()
Definition Message.php:319
isBlank()
Check whether a message does not exist, or is an empty string.
Definition Message.php:1002
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition Message.php:786
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
Definition Message.php:965
__construct( $key, $params=[], Language $language=null)
Definition Message.php:249
bool $useDatabase
Whether database can be used.
Definition Message.php:223
getKeysToTry()
Definition Message.php:329
parse()
Fully parse the text from wikitext to HTML.
Definition Message.php:929
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
Definition Message.php:166
__toString()
Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg: $foo = new Message( $k...
Definition Message.php:904
static newFallbackSequence()
Factory function accepting multiple message keys and returning a message instance for the first messa...
Definition Message.php:448
unserialize( $serialized)
Definition Message.php:301
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)
Definition Message.php:164
static sizeParam( $size)
Definition Message.php:1081
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition Message.php:1347
static timeperiodParam( $period)
Definition Message.php:1070
array $parameters
List of parameters which will be substituted into the message.
Definition Message.php:212
static plaintextParam( $plaintext)
Definition Message.php:1103
const FORMAT_PLAIN
Use message text as-is.
Definition Message.php:162
static durationParam( $duration)
Definition Message.php:1048
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
Definition Message.php:170
inLanguage( $lang)
Request the message in any language that is supported.
Definition Message.php:731
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition Message.php:1134
string $key
The message key.
Definition Message.php:202
sizeParams()
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
Definition Message.php:646
static numParam( $num)
Definition Message.php:1037
expiryParams()
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition Message.php:602
inContentLanguage()
Request the message in the wiki's content language, unless it is disabled for this message.
Definition Message.php:766
plain()
Returns the message text as-is, only parameters are substituted.
Definition Message.php:953
exists()
Check whether a message key has been defined currently.
Definition Message.php:990
plaintextParams()
Add parameters that are plaintext and will be passed through without the content being evaluated.
Definition Message.php:692
rawParams()
Add parameters that are substituted after parsing or escaping.
Definition Message.php:536
title( $title)
Set the Title object to use as context when transforming the message.
Definition Message.php:815
Language bool $language
In which language to get this message.
Definition Message.php:196
getFormat()
Returns the message format.
Definition Message.php:367
useDatabase( $useDatabase)
Enable or disable database use.
Definition Message.php:800
fetchMessage()
Wrapper for what ever method we use to get message contents.
Definition Message.php:1294
content()
Returns the message as a Content object.
Definition Message.php:825
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with 'plaintext'.
Definition Message.php:1325
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
Definition Message.php:472
bitrateParams()
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition Message.php:668
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
Definition Message.php:1247
getKey()
Returns the message key.
Definition Message.php:344
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
Definition Message.php:1014
escaped()
Returns the message text.
Definition Message.php:978
params()
Adds parameters to the parameter list of this message.
Definition Message.php:499
getLanguage()
Returns the Language of the Message.
Definition Message.php:379
string $format
Definition Message.php:218
string $message
Definition Message.php:238
string[] $keysToTry
List of keys to try when fetching the message.
Definition Message.php:207
serialize()
Definition Message.php:283
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition Message.php:712
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Definition Message.php:844
Title $title
Title object to use as context.
Definition Message.php:228
text()
Returns the message text.
Definition Message.php:941
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:415
bool $interface
In which language to get this message.
Definition Message.php:189
static expiryParam( $expiry)
Definition Message.php:1059
getText( $options=[])
Get the output HTML.
Variant of the Message class.
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 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:72
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2278
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 use $formDescriptor instead 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 set this to the key of the message First element is the message key
Definition hooks.txt:2214
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:2885
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
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:2055
if the prop value should be in the metadata multi language array format
Definition hooks.txt:1690
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:894
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 use $formDescriptor instead 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:2213
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:2226
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$content
$params
foreach( $res as $row) $serialized
if(!isset( $args[0])) $lang