MediaWiki  master
Message.php
Go to the documentation of this file.
1 <?php
26 
164  const FORMAT_PLAIN = 'plain';
166  const FORMAT_BLOCK_PARSE = 'block-parse';
168  const FORMAT_PARSE = 'parse';
170  const FORMAT_TEXT = 'text';
172  const FORMAT_ESCAPED = 'escaped';
173 
178  protected static $listTypeMap = [
179  'comma' => 'commaList',
180  'semicolon' => 'semicolonList',
181  'pipe' => 'pipeList',
182  'text' => 'listToText',
183  ];
184 
191  protected $interface = true;
192 
198  protected $language = false;
199 
204  protected $key;
205 
209  protected $keysToTry;
210 
214  protected $parameters = [];
215 
220  protected $format = 'parse';
221 
225  protected $useDatabase = true;
226 
230  protected $title = null;
231 
235  protected $content = null;
236 
240  protected $message;
241 
251  public function __construct( $key, $params = [], Language $language = null ) {
252  if ( $key instanceof MessageSpecifier ) {
253  if ( $params ) {
254  throw new InvalidArgumentException(
255  '$params must be empty if $key is a MessageSpecifier'
256  );
257  }
258  $params = $key->getParams();
259  $key = $key->getKey();
260  }
261 
262  if ( !is_string( $key ) && !is_array( $key ) ) {
263  throw new InvalidArgumentException( '$key must be a string or an array' );
264  }
265 
266  $this->keysToTry = (array)$key;
267 
268  if ( empty( $this->keysToTry ) ) {
269  throw new InvalidArgumentException( '$key must not be an empty list' );
270  }
271 
272  $this->key = reset( $this->keysToTry );
273 
274  $this->parameters = array_values( $params );
275  // User language is only resolved in getLanguage(). This helps preserve the
276  // semantic intent of "user language" across serialize() and unserialize().
277  $this->language = $language ?: false;
278  }
279 
285  public function serialize() {
286  return serialize( [
287  'interface' => $this->interface,
288  'language' => $this->language ? $this->language->getCode() : false,
289  'key' => $this->key,
290  'keysToTry' => $this->keysToTry,
291  'parameters' => $this->parameters,
292  'format' => $this->format,
293  'useDatabase' => $this->useDatabase,
294  'titlestr' => $this->title ? $this->title->getFullText() : null,
295  ] );
296  }
297 
303  public function unserialize( $serialized ) {
304  $data = unserialize( $serialized );
305  if ( !is_array( $data ) ) {
306  throw new InvalidArgumentException( __METHOD__ . ': Invalid serialized data' );
307  }
308 
309  $this->interface = $data['interface'];
310  $this->key = $data['key'];
311  $this->keysToTry = $data['keysToTry'];
312  $this->parameters = $data['parameters'];
313  $this->format = $data['format'];
314  $this->useDatabase = $data['useDatabase'];
315  $this->language = $data['language']
316  ? MediaWikiServices::getInstance()->getLanguageFactory()
317  ->getLanguage( $data['language'] )
318  : false;
319 
320  if ( isset( $data['titlestr'] ) ) {
321  $this->title = Title::newFromText( $data['titlestr'] );
322  } elseif ( isset( $data['title'] ) && $data['title'] instanceof Title ) {
323  // Old serializations from before December 2018
324  $this->title = $data['title'];
325  } else {
326  $this->title = null; // Explicit for sanity
327  }
328  }
329 
336  public function isMultiKey() {
337  return count( $this->keysToTry ) > 1;
338  }
339 
346  public function getKeysToTry() {
347  return $this->keysToTry;
348  }
349 
361  public function getKey() {
362  return $this->key;
363  }
364 
372  public function getParams() {
373  return $this->parameters;
374  }
375 
384  public function getFormat() {
385  wfDeprecated( __METHOD__, '1.29' );
386  return $this->format;
387  }
388 
396  public function getLanguage() {
397  // Defaults to false which means current user language
398  return $this->language ?: RequestContext::getMain()->getLanguage();
399  }
400 
413  public static function newFromKey( $key, ...$params ) {
414  return new self( $key, $params );
415  }
416 
430  public static function newFromSpecifier( $value ) {
431  $params = [];
432  if ( is_array( $value ) ) {
433  $params = $value;
434  $value = array_shift( $params );
435  }
436 
437  if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
438  $message = clone $value;
439  } elseif ( $value instanceof MessageSpecifier ) {
440  $message = new Message( $value );
441  } elseif ( is_string( $value ) ) {
442  $message = new Message( $value, $params );
443  } else {
444  throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
445  . gettype( $value ) );
446  }
447 
448  return $message;
449  }
450 
463  public static function newFallbackSequence( ...$keys ) {
464  if ( func_num_args() == 1 ) {
465  if ( is_array( $keys[0] ) ) {
466  // Allow an array to be passed as the first argument instead
467  $keys = array_values( $keys[0] );
468  } else {
469  // Optimize a single string to not need special fallback handling
470  $keys = $keys[0];
471  }
472  }
473  return new self( $keys );
474  }
475 
486  public function getTitle() {
488 
489  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
490  $lang = $this->getLanguage();
491  $title = $this->key;
492  if (
493  !$lang->equals( $contLang )
494  && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
495  ) {
496  $title .= '/' . $lang->getCode();
497  }
498 
499  return Title::makeTitle(
500  NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
501  }
502 
513  public function params( ...$args ) {
514  // If $args has only one entry and it's an array, then it's either a
515  // non-varargs call or it happens to be a call with just a single
516  // "special" parameter. Since the "special" parameters don't have any
517  // numeric keys, we'll test that to differentiate the cases.
518  if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
519  if ( $args[0] === [] ) {
520  $args = [];
521  } else {
522  foreach ( $args[0] as $key => $value ) {
523  if ( is_int( $key ) ) {
524  $args = $args[0];
525  break;
526  }
527  }
528  }
529  }
530 
531  $this->parameters = array_merge( $this->parameters, array_values( $args ) );
532  return $this;
533  }
534 
548  public function rawParams( ...$params ) {
549  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
550  $params = $params[0];
551  }
552  foreach ( $params as $param ) {
553  $this->parameters[] = self::rawParam( $param );
554  }
555  return $this;
556  }
557 
569  public function numParams( ...$params ) {
570  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
571  $params = $params[0];
572  }
573  foreach ( $params as $param ) {
574  $this->parameters[] = self::numParam( $param );
575  }
576  return $this;
577  }
578 
590  public function durationParams( ...$params ) {
591  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
592  $params = $params[0];
593  }
594  foreach ( $params as $param ) {
595  $this->parameters[] = self::durationParam( $param );
596  }
597  return $this;
598  }
599 
611  public function expiryParams( ...$params ) {
612  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
613  $params = $params[0];
614  }
615  foreach ( $params as $param ) {
616  $this->parameters[] = self::expiryParam( $param );
617  }
618  return $this;
619  }
620 
632  public function timeperiodParams( ...$params ) {
633  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
634  $params = $params[0];
635  }
636  foreach ( $params as $param ) {
637  $this->parameters[] = self::timeperiodParam( $param );
638  }
639  return $this;
640  }
641 
653  public function sizeParams( ...$params ) {
654  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
655  $params = $params[0];
656  }
657  foreach ( $params as $param ) {
658  $this->parameters[] = self::sizeParam( $param );
659  }
660  return $this;
661  }
662 
674  public function bitrateParams( ...$params ) {
675  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
676  $params = $params[0];
677  }
678  foreach ( $params as $param ) {
679  $this->parameters[] = self::bitrateParam( $param );
680  }
681  return $this;
682  }
683 
697  public function plaintextParams( ...$params ) {
698  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
699  $params = $params[0];
700  }
701  foreach ( $params as $param ) {
702  $this->parameters[] = self::plaintextParam( $param );
703  }
704  return $this;
705  }
706 
716  public function setContext( IContextSource $context ) {
717  $this->inLanguage( $context->getLanguage() );
718  $this->title( $context->getTitle() );
719  $this->interface = true;
720 
721  return $this;
722  }
723 
735  public function inLanguage( $lang ) {
736  $previousLanguage = $this->language;
737 
738  if ( $lang instanceof Language ) {
739  $this->language = $lang;
740  } elseif ( is_string( $lang ) ) {
741  if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
742  $this->language = MediaWikiServices::getInstance()->getLanguageFactory()
743  ->getLanguage( $lang );
744  }
745  } elseif ( $lang instanceof StubUserLang ) {
746  $this->language = false;
747  } else {
748  $type = gettype( $lang );
749  throw new MWException( __METHOD__ . " must be "
750  . "passed a String or Language object; $type given"
751  );
752  }
753 
754  if ( $this->language !== $previousLanguage ) {
755  // The language has changed. Clear the message cache.
756  $this->message = null;
757  }
758  $this->interface = false;
759  return $this;
760  }
761 
771  public function inContentLanguage() {
773  if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
774  return $this;
775  }
776 
777  $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
778  return $this;
779  }
780 
791  public function setInterfaceMessageFlag( $interface ) {
792  $this->interface = (bool)$interface;
793  return $this;
794  }
795 
805  public function useDatabase( $useDatabase ) {
806  $this->useDatabase = (bool)$useDatabase;
807  $this->message = null;
808  return $this;
809  }
810 
820  public function title( $title ) {
821  $this->title = $title;
822  return $this;
823  }
824 
830  public function content() {
831  if ( !$this->content ) {
832  $this->content = new MessageContent( $this );
833  }
834 
835  return $this->content;
836  }
837 
849  public function toString( $format = null ) {
850  if ( $format === null ) {
851  $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
852  LoggerFactory::getInstance( 'message-format' )->warning(
853  $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
855  }
856  $string = $this->fetchMessage();
857 
858  if ( $string === false ) {
859  // Err on the side of safety, ensure that the output
860  // is always html safe in the event the message key is
861  // missing, since in that case its highly likely the
862  // message key is user-controlled.
863  // '⧼' is used instead of '<' to side-step any
864  // double-escaping issues.
865  // (Keep synchronised with mw.Message#toString in JS.)
866  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
867  }
868 
869  # Replace $* with a list of parameters for &uselang=qqx.
870  if ( strpos( $string, '$*' ) !== false ) {
871  $paramlist = '';
872  if ( $this->parameters !== [] ) {
873  $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
874  }
875  $string = str_replace( '$*', $paramlist, $string );
876  }
877 
878  # Replace parameters before text parsing
879  $string = $this->replaceParameters( $string, 'before', $format );
880 
881  # Maybe transform using the full parser
882  if ( $format === self::FORMAT_PARSE ) {
883  $string = $this->parseText( $string );
884  $string = Parser::stripOuterParagraph( $string );
885  } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
886  $string = $this->parseText( $string );
887  } elseif ( $format === self::FORMAT_TEXT ) {
888  $string = $this->transformText( $string );
889  } elseif ( $format === self::FORMAT_ESCAPED ) {
890  $string = $this->transformText( $string );
891  $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
892  }
893 
894  # Raw parameter replacement
895  $string = $this->replaceParameters( $string, 'after', $format );
896 
897  return $string;
898  }
899 
909  public function __toString() {
910  // PHP doesn't allow __toString to throw exceptions and will
911  // trigger a fatal error if it does. So, catch any exceptions.
912 
913  try {
914  return $this->toString( self::FORMAT_PARSE );
915  } catch ( Exception $ex ) {
916  try {
917  trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
918  . $ex, E_USER_WARNING );
919  } catch ( Exception $ex ) {
920  // Doh! Cause a fatal error after all?
921  }
922 
923  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
924  }
925  }
926 
934  public function parse() {
935  $this->format = self::FORMAT_PARSE;
936  return $this->toString( self::FORMAT_PARSE );
937  }
938 
946  public function text() {
947  $this->format = self::FORMAT_TEXT;
948  return $this->toString( self::FORMAT_TEXT );
949  }
950 
958  public function plain() {
959  $this->format = self::FORMAT_PLAIN;
960  return $this->toString( self::FORMAT_PLAIN );
961  }
962 
970  public function parseAsBlock() {
971  $this->format = self::FORMAT_BLOCK_PARSE;
972  return $this->toString( self::FORMAT_BLOCK_PARSE );
973  }
974 
983  public function escaped() {
984  $this->format = self::FORMAT_ESCAPED;
985  return $this->toString( self::FORMAT_ESCAPED );
986  }
987 
995  public function exists() {
996  return $this->fetchMessage() !== false;
997  }
998 
1007  public function isBlank() {
1008  $message = $this->fetchMessage();
1009  return $message === false || $message === '';
1010  }
1011 
1019  public function isDisabled() {
1020  $message = $this->fetchMessage();
1021  return $message === false || $message === '' || $message === '-';
1022  }
1023 
1031  public static function rawParam( $raw ) {
1032  return [ 'raw' => $raw ];
1033  }
1034 
1042  public static function numParam( $num ) {
1043  return [ 'num' => $num ];
1044  }
1045 
1053  public static function durationParam( $duration ) {
1054  return [ 'duration' => $duration ];
1055  }
1056 
1064  public static function expiryParam( $expiry ) {
1065  return [ 'expiry' => $expiry ];
1066  }
1067 
1075  public static function timeperiodParam( $period ) {
1076  return [ 'period' => $period ];
1077  }
1078 
1086  public static function sizeParam( $size ) {
1087  return [ 'size' => $size ];
1088  }
1089 
1097  public static function bitrateParam( $bitrate ) {
1098  return [ 'bitrate' => $bitrate ];
1099  }
1100 
1108  public static function plaintextParam( $plaintext ) {
1109  return [ 'plaintext' => $plaintext ];
1110  }
1111 
1119  public static function listParam( array $list, $type = 'text' ) {
1120  if ( !isset( self::$listTypeMap[$type] ) ) {
1121  throw new InvalidArgumentException(
1122  "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1123  );
1124  }
1125  return [ 'list' => $list, 'type' => $type ];
1126  }
1127 
1139  protected function replaceParameters( $message, $type, $format ) {
1140  // A temporary marker for $1 parameters that is only valid
1141  // in non-attribute contexts. However if the entire message is escaped
1142  // then we don't want to use it because it will be mangled in all contexts
1143  // and its unnessary as ->escaped() messages aren't html.
1144  $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1145  $replacementKeys = [];
1146  foreach ( $this->parameters as $n => $param ) {
1147  list( $paramType, $value ) = $this->extractParam( $param, $format );
1148  if ( $type === 'before' ) {
1149  if ( $paramType === 'before' ) {
1150  $replacementKeys['$' . ( $n + 1 )] = $value;
1151  } else /* $paramType === 'after' */ {
1152  // To protect against XSS from replacing parameters
1153  // inside html attributes, we convert $1 to $'"1.
1154  // In the event that one of the parameters ends up
1155  // in an attribute, either the ' or the " will be
1156  // escaped, breaking the replacement and avoiding XSS.
1157  $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1158  }
1159  } elseif ( $paramType === 'after' ) {
1160  $replacementKeys[$marker . ( $n + 1 )] = $value;
1161  }
1162  }
1163  return strtr( $message, $replacementKeys );
1164  }
1165 
1176  protected function extractParam( $param, $format ) {
1177  if ( is_array( $param ) ) {
1178  if ( isset( $param['raw'] ) ) {
1179  return [ 'after', $param['raw'] ];
1180  } elseif ( isset( $param['num'] ) ) {
1181  // Replace number params always in before step for now.
1182  // No support for combined raw and num params
1183  return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1184  } elseif ( isset( $param['duration'] ) ) {
1185  return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1186  } elseif ( isset( $param['expiry'] ) ) {
1187  return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1188  } elseif ( isset( $param['period'] ) ) {
1189  return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1190  } elseif ( isset( $param['size'] ) ) {
1191  return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1192  } elseif ( isset( $param['bitrate'] ) ) {
1193  return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1194  } elseif ( isset( $param['plaintext'] ) ) {
1195  return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1196  } elseif ( isset( $param['list'] ) ) {
1197  return $this->formatListParam( $param['list'], $param['type'], $format );
1198  } else {
1199  if ( !is_scalar( $param ) ) {
1200  $param = serialize( $param );
1201  }
1202  LoggerFactory::getInstance( 'Bug58676' )->warning(
1203  'Invalid parameter for message "{msgkey}": {param}',
1204  [
1205  'exception' => new Exception,
1206  'msgkey' => $this->getKey(),
1207  'param' => htmlspecialchars( $param ),
1208  ]
1209  );
1210 
1211  return [ 'before', '[INVALID]' ];
1212  }
1213  } elseif ( $param instanceof Message ) {
1214  // Match language, flags, etc. to the current message.
1215  $msg = clone $param;
1216  if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1217  // Cache depends on these parameters
1218  $msg->message = null;
1219  }
1220  $msg->interface = $this->interface;
1221  $msg->language = $this->language;
1222  $msg->useDatabase = $this->useDatabase;
1223  $msg->title = $this->title;
1224 
1225  // DWIM
1226  if ( $format === 'block-parse' ) {
1227  $format = 'parse';
1228  }
1229  $msg->format = $format;
1230 
1231  // Message objects should not be before parameters because
1232  // then they'll get double escaped. If the message needs to be
1233  // escaped, it'll happen right here when we call toString().
1234  return [ 'after', $msg->toString( $format ) ];
1235  } else {
1236  return [ 'before', $param ];
1237  }
1238  }
1239 
1249  protected function parseText( $string ) {
1250  $out = MessageCache::singleton()->parse(
1251  $string,
1252  $this->title,
1253  /*linestart*/true,
1254  $this->interface,
1255  $this->getLanguage()
1256  );
1257 
1258  return $out instanceof ParserOutput
1259  ? $out->getText( [
1260  'enableSectionEditLinks' => false,
1261  // Wrapping messages in an extra <div> is probably not expected. If
1262  // they're outside the content area they probably shouldn't be
1263  // targeted by CSS that's targeting the parser output, and if
1264  // they're inside they already are from the outer div.
1265  'unwrap' => true,
1266  ] )
1267  : $out;
1268  }
1269 
1279  protected function transformText( $string ) {
1280  return MessageCache::singleton()->transform(
1281  $string,
1282  $this->interface,
1283  $this->getLanguage(),
1284  $this->title
1285  );
1286  }
1287 
1296  protected function fetchMessage() {
1297  if ( $this->message === null ) {
1299 
1300  foreach ( $this->keysToTry as $key ) {
1301  $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1302  if ( $message !== false && $message !== '' ) {
1303  break;
1304  }
1305  }
1306 
1307  // NOTE: The constructor makes sure keysToTry isn't empty,
1308  // so we know that $key and $message are initialized.
1309  $this->key = $key;
1310  $this->message = $message;
1311  }
1312  return $this->message;
1313  }
1314 
1327  protected function formatPlaintext( $plaintext, $format ) {
1328  switch ( $format ) {
1329  case self::FORMAT_TEXT:
1330  case self::FORMAT_PLAIN:
1331  return $plaintext;
1332 
1333  case self::FORMAT_PARSE:
1334  case self::FORMAT_BLOCK_PARSE:
1335  case self::FORMAT_ESCAPED:
1336  default:
1337  return htmlspecialchars( $plaintext, ENT_QUOTES );
1338  }
1339  }
1340 
1349  protected function formatListParam( array $params, $listType, $format ) {
1350  if ( !isset( self::$listTypeMap[$listType] ) ) {
1351  $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1352  . htmlspecialchars( $listType )
1353  . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1354  trigger_error( $warning, E_USER_WARNING );
1355  $e = new Exception;
1356  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1357  return [ 'before', '[INVALID]' ];
1358  }
1359  $func = self::$listTypeMap[$listType];
1360 
1361  // Handle an empty list sensibly
1362  if ( !$params ) {
1363  return [ 'before', $this->getLanguage()->$func( [] ) ];
1364  }
1365 
1366  // First, determine what kinds of list items we have
1367  $types = [];
1368  $vars = [];
1369  $list = [];
1370  foreach ( $params as $n => $p ) {
1371  list( $type, $value ) = $this->extractParam( $p, $format );
1372  $types[$type] = true;
1373  $list[] = $value;
1374  $vars[] = '$' . ( $n + 1 );
1375  }
1376 
1377  // Easy case: all are 'before' or 'after', so just join the
1378  // values and use the same type.
1379  if ( count( $types ) === 1 ) {
1380  return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1381  }
1382 
1383  // Hard case: We need to process each value per its type, then
1384  // return the concatenated values as 'after'. We handle this by turning
1385  // the list into a RawMessage and processing that as a parameter.
1386  $vars = $this->getLanguage()->$func( $vars );
1387  return $this->extractParam( new RawMessage( $vars, $params ), $format );
1388  }
1389 }
getKeysToTry()
Definition: Message.php:346
getKey()
Returns the message key.
Definition: Message.php:361
static rawParam( $raw)
Definition: Message.php:1031
string [] $keysToTry
List of keys to try when fetching the message.
Definition: Message.php:209
timeperiodParams(... $params)
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition: Message.php:632
static array bool $interface
In which language to get this message.
Definition: Message.php:191
isBlank()
Check whether a message does not exist, or is an empty string.
Definition: Message.php:1007
$context
Definition: load.php:40
bool $useDatabase
Whether database can be used.
Definition: Message.php:225
Content $content
Content object representing the message.
Definition: Message.php:235
Title $title
Title object to use as context.
Definition: Message.php:230
bitrateParams(... $params)
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition: Message.php:674
rawParams(... $params)
Add parameters that are substituted after parsing or escaping.
Definition: Message.php:548
sizeParams(... $params)
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
Definition: Message.php:653
unserialize( $serialized)
Definition: Message.php:303
The Message class provides methods which fulfil two basic services:
Definition: Message.php:162
string $format
Definition: Message.php:220
Wrapper allowing us to handle a system message as a Content object.
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition: Message.php:1349
const FORMAT_PLAIN
Use message text as-is.
Definition: Message.php:164
if(!isset( $args[0])) $lang
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag) ...
Definition: Message.php:166
Language bool $language
In which language to get this message.
Definition: Message.php:198
text()
Returns the message text.
Definition: Message.php:946
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
Definition: Message.php:168
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
Definition: Message.php:970
expiryParams(... $params)
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition: Message.php:611
getFormat()
Returns the message format.
Definition: Message.php:384
static numParam( $num)
Definition: Message.php:1042
content()
Returns the message as a Content object.
Definition: Message.php:830
static bitrateParam( $bitrate)
Definition: Message.php:1097
durationParams(... $params)
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
Definition: Message.php:590
plaintextParams(... $params)
Add parameters that are plaintext and will be passed through without the content being evaluated...
Definition: Message.php:697
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6387
useDatabase( $useDatabase)
Enable or disable database use.
Definition: Message.php:805
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition: Message.php:178
getParams()
Returns the message parameters.
Definition: Message.php:372
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition: Message.php:1279
if( $line===false) $args
Definition: mcc.php:124
static getMain()
Get the RequestContext object associated with the main request.
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition: Message.php:791
isMultiKey()
Definition: Message.php:336
const FORMAT_TEXT
Transform {{..}} constructs but don&#39;t transform to HTML.
Definition: Message.php:170
serialize()
Definition: Message.php:285
$cache
Definition: mcc.php:33
string $key
The message key.
Definition: Message.php:204
array $parameters
List of parameters which will be substituted into the message.
Definition: Message.php:214
static durationParam( $duration)
Definition: Message.php:1053
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition: Message.php:716
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Definition: Message.php:849
getLanguage()
Returns the Language of the Message.
Definition: Message.php:396
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:735
parse()
Fully parse the text from wikitext to HTML.
Definition: Message.php:934
const NS_MEDIAWIKI
Definition: Defines.php:68
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
title( $title)
Set the Title object to use as context when transforming the message.
Definition: Message.php:820
numParams(... $params)
Add parameters that are numeric and will be passed through Language::formatNum before substitution...
Definition: Message.php:569
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with &#39;plaintext&#39;.
Definition: Message.php:1327
exists()
Check whether a message key has been defined currently.
Definition: Message.php:995
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:584
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:430
Variant of the Message class.
Definition: RawMessage.php:34
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
__toString()
Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg: $foo = new Message( $k...
Definition: Message.php:909
Stub object for the user language.
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace...
Definition: Message.php:486
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition: Message.php:1139
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition: Message.php:1176
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
Definition: Message.php:1249
plain()
Returns the message text as-is, only parameters are substituted.
Definition: Message.php:958
inContentLanguage()
Request the message in the wiki&#39;s content language, unless it is disabled for this message...
Definition: Message.php:771
fetchMessage()
Wrapper for what ever method we use to get message contents.
Definition: Message.php:1296
escaped()
Returns the message text.
Definition: Message.php:983
string $message
Definition: Message.php:240
static timeperiodParam( $period)
Definition: Message.php:1075
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
Definition: Message.php:172
static newFallbackSequence(... $keys)
Factory function accepting multiple message keys and returning a message instance for the first messa...
Definition: Message.php:463
foreach( $res as $row) $serialized
static sizeParam( $size)
Definition: Message.php:1086
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
Definition: Message.php:1019
static plaintextParam( $plaintext)
Definition: Message.php:1108
return true
Definition: router.php:92
static singleton()
Get the singleton instance of this class.
static listParam(array $list, $type='text')
Definition: Message.php:1119
__construct( $key, $params=[], Language $language=null)
Definition: Message.php:251
static expiryParam( $expiry)
Definition: Message.php:1064
params(... $args)
Adds parameters to the parameter list of this message.
Definition: Message.php:513
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:413
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:317