MediaWiki  master
Message.php
Go to the documentation of this file.
1 <?php
24 
161 class Message implements MessageSpecifier, Serializable {
163  public const FORMAT_PLAIN = 'plain';
165  public const FORMAT_BLOCK_PARSE = 'block-parse';
167  public const FORMAT_PARSE = 'parse';
169  public const FORMAT_TEXT = 'text';
171  public const FORMAT_ESCAPED = 'escaped';
172 
177  protected static $listTypeMap = [
178  'comma' => 'commaList',
179  'semicolon' => 'semicolonList',
180  'pipe' => 'pipeList',
181  'text' => 'listToText',
182  ];
183 
190  protected $interface = true;
191 
197  protected $language = false;
198 
203  protected $key;
204 
208  protected $keysToTry;
209 
213  protected $parameters = [];
214 
219  protected $format = 'parse';
220 
224  protected $useDatabase = true;
225 
229  protected $title = null;
230 
234  protected $content = null;
235 
239  protected $message;
240 
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  // Optimisation: Avoid cost of TitleFormatter on serialize,
295  // and especially cost of TitleParser (via Title::newFromText)
296  // on retrieval.
297  'titlevalue' => ( $this->title
298  ? [ 0 => $this->title->getNamespace(), 1 => $this->title->getDBkey() ]
299  : null
300  ),
301  ] );
302  }
303 
309  public function unserialize( $serialized ) {
310  $data = unserialize( $serialized );
311  if ( !is_array( $data ) ) {
312  throw new InvalidArgumentException( __METHOD__ . ': Invalid serialized data' );
313  }
314 
315  $this->interface = $data['interface'];
316  $this->key = $data['key'];
317  $this->keysToTry = $data['keysToTry'];
318  $this->parameters = $data['parameters'];
319  $this->format = $data['format'];
320  $this->useDatabase = $data['useDatabase'];
321  $this->language = $data['language']
322  ? MediaWikiServices::getInstance()->getLanguageFactory()
323  ->getLanguage( $data['language'] )
324  : false;
325 
326  // Since 1.35, the key 'titlevalue' is set, instead of 'titlestr'.
327  if ( isset( $data['titlevalue'] ) ) {
328  $this->title = Title::makeTitle( $data['titlevalue'][0], $data['titlevalue'][1] );
329  } elseif ( isset( $data['titlestr'] ) ) {
330  $this->title = Title::newFromText( $data['titlestr'] );
331  } else {
332  $this->title = null; // Explicit for sanity
333  }
334  }
335 
342  public function isMultiKey() {
343  return count( $this->keysToTry ) > 1;
344  }
345 
352  public function getKeysToTry() {
353  return $this->keysToTry;
354  }
355 
367  public function getKey() {
368  return $this->key;
369  }
370 
378  public function getParams() {
379  return $this->parameters;
380  }
381 
389  public function getLanguage() {
390  // Defaults to false which means current user language
391  return $this->language ?: RequestContext::getMain()->getLanguage();
392  }
393 
406  public static function newFromKey( $key, ...$params ) {
407  return new self( $key, $params );
408  }
409 
424  public static function newFromSpecifier( $value ) {
425  $params = [];
426  if ( is_array( $value ) ) {
427  $params = $value;
428  $value = array_shift( $params );
429  }
430 
431  if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
432  $message = clone $value;
433  } elseif ( $value instanceof MessageSpecifier ) {
434  $message = new Message( $value );
435  } elseif ( is_string( $value ) ) {
436  $message = new Message( $value, $params );
437  } else {
438  throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
439  . gettype( $value ) );
440  }
441 
442  return $message;
443  }
444 
458  public static function newFallbackSequence( ...$keys ) {
459  if ( func_num_args() == 1 ) {
460  if ( is_array( $keys[0] ) ) {
461  // Allow an array to be passed as the first argument instead
462  $keys = array_values( $keys[0] );
463  } else {
464  // Optimize a single string to not need special fallback handling
465  $keys = $keys[0];
466  }
467  }
468  return new self( $keys );
469  }
470 
481  public function getTitle() {
483 
484  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
485  $lang = $this->getLanguage();
486  $title = $this->key;
487  if (
488  !$lang->equals( $contLang )
489  && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
490  ) {
491  $title .= '/' . $lang->getCode();
492  }
493 
494  return Title::makeTitle(
495  NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
496  }
497 
508  public function params( ...$args ) {
509  // If $args has only one entry and it's an array, then it's either a
510  // non-varargs call or it happens to be a call with just a single
511  // "special" parameter. Since the "special" parameters don't have any
512  // numeric keys, we'll test that to differentiate the cases.
513  if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
514  if ( $args[0] === [] ) {
515  $args = [];
516  } else {
517  foreach ( $args[0] as $key => $value ) {
518  if ( is_int( $key ) ) {
519  $args = $args[0];
520  break;
521  }
522  }
523  }
524  }
525 
526  $this->parameters = array_merge( $this->parameters, array_values( $args ) );
527  return $this;
528  }
529 
543  public function rawParams( ...$params ) {
544  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
545  $params = $params[0];
546  }
547  foreach ( $params as $param ) {
548  $this->parameters[] = self::rawParam( $param );
549  }
550  return $this;
551  }
552 
564  public function numParams( ...$params ) {
565  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
566  $params = $params[0];
567  }
568  foreach ( $params as $param ) {
569  $this->parameters[] = self::numParam( $param );
570  }
571  return $this;
572  }
573 
585  public function durationParams( ...$params ) {
586  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
587  $params = $params[0];
588  }
589  foreach ( $params as $param ) {
590  $this->parameters[] = self::durationParam( $param );
591  }
592  return $this;
593  }
594 
606  public function expiryParams( ...$params ) {
607  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
608  $params = $params[0];
609  }
610  foreach ( $params as $param ) {
611  $this->parameters[] = self::expiryParam( $param );
612  }
613  return $this;
614  }
615 
627  public function timeperiodParams( ...$params ) {
628  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
629  $params = $params[0];
630  }
631  foreach ( $params as $param ) {
632  $this->parameters[] = self::timeperiodParam( $param );
633  }
634  return $this;
635  }
636 
648  public function sizeParams( ...$params ) {
649  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
650  $params = $params[0];
651  }
652  foreach ( $params as $param ) {
653  $this->parameters[] = self::sizeParam( $param );
654  }
655  return $this;
656  }
657 
669  public function bitrateParams( ...$params ) {
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( ...$params ) {
693  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
694  $params = $params[0];
695  }
696  foreach ( $params as $param ) {
697  $this->parameters[] = self::plaintextParam( $param );
698  }
699  return $this;
700  }
701 
711  public function setContext( IContextSource $context ) {
712  $this->inLanguage( $context->getLanguage() );
713  $this->title( $context->getTitle() );
714  $this->interface = true;
715 
716  return $this;
717  }
718 
730  public function inLanguage( $lang ) {
731  $previousLanguage = $this->language;
732 
733  if ( $lang instanceof Language ) {
734  $this->language = $lang;
735  } elseif ( is_string( $lang ) ) {
736  if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
737  $this->language = MediaWikiServices::getInstance()->getLanguageFactory()
738  ->getLanguage( $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  LoggerFactory::getInstance( 'message-format' )->warning(
848  $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
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 
1027  public static function rawParam( $raw ) {
1028  return [ 'raw' => $raw ];
1029  }
1030 
1038  public static function numParam( $num ) {
1039  return [ 'num' => $num ];
1040  }
1041 
1049  public static function durationParam( $duration ) {
1050  return [ 'duration' => $duration ];
1051  }
1052 
1060  public static function expiryParam( $expiry ) {
1061  return [ 'expiry' => $expiry ];
1062  }
1063 
1071  public static function timeperiodParam( $period ) {
1072  return [ 'period' => $period ];
1073  }
1074 
1082  public static function sizeParam( $size ) {
1083  return [ 'size' => $size ];
1084  }
1085 
1093  public static function bitrateParam( $bitrate ) {
1094  return [ 'bitrate' => $bitrate ];
1095  }
1096 
1104  public static function plaintextParam( $plaintext ) {
1105  return [ 'plaintext' => $plaintext ];
1106  }
1107 
1115  public static function listParam( array $list, $type = 'text' ) {
1116  if ( !isset( self::$listTypeMap[$type] ) ) {
1117  throw new InvalidArgumentException(
1118  "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1119  );
1120  }
1121  return [ 'list' => $list, 'type' => $type ];
1122  }
1123 
1135  protected function replaceParameters( $message, $type, $format ) {
1136  // A temporary marker for $1 parameters that is only valid
1137  // in non-attribute contexts. However if the entire message is escaped
1138  // then we don't want to use it because it will be mangled in all contexts
1139  // and its unnessary as ->escaped() messages aren't html.
1140  $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1141  $replacementKeys = [];
1142  foreach ( $this->parameters as $n => $param ) {
1143  list( $paramType, $value ) = $this->extractParam( $param, $format );
1144  if ( $type === 'before' ) {
1145  if ( $paramType === 'before' ) {
1146  $replacementKeys['$' . ( $n + 1 )] = $value;
1147  } else /* $paramType === 'after' */ {
1148  // To protect against XSS from replacing parameters
1149  // inside html attributes, we convert $1 to $'"1.
1150  // In the event that one of the parameters ends up
1151  // in an attribute, either the ' or the " will be
1152  // escaped, breaking the replacement and avoiding XSS.
1153  $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1154  }
1155  } elseif ( $paramType === 'after' ) {
1156  $replacementKeys[$marker . ( $n + 1 )] = $value;
1157  }
1158  }
1159  return strtr( $message, $replacementKeys );
1160  }
1161 
1172  protected function extractParam( $param, $format ) {
1173  if ( is_array( $param ) ) {
1174  if ( isset( $param['raw'] ) ) {
1175  return [ 'after', $param['raw'] ];
1176  } elseif ( isset( $param['num'] ) ) {
1177  // Replace number params always in before step for now.
1178  // No support for combined raw and num params
1179  return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1180  } elseif ( isset( $param['duration'] ) ) {
1181  return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1182  } elseif ( isset( $param['expiry'] ) ) {
1183  return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1184  } elseif ( isset( $param['period'] ) ) {
1185  return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1186  } elseif ( isset( $param['size'] ) ) {
1187  return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1188  } elseif ( isset( $param['bitrate'] ) ) {
1189  return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1190  } elseif ( isset( $param['plaintext'] ) ) {
1191  return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1192  } elseif ( isset( $param['list'] ) ) {
1193  return $this->formatListParam( $param['list'], $param['type'], $format );
1194  } else {
1195  LoggerFactory::getInstance( 'Bug58676' )->warning(
1196  'Invalid parameter for message "{msgkey}": {param}',
1197  [
1198  'exception' => new Exception,
1199  'msgkey' => $this->getKey(),
1200  'param' => htmlspecialchars( serialize( $param ) ),
1201  ]
1202  );
1203 
1204  return [ 'before', '[INVALID]' ];
1205  }
1206  } elseif ( $param instanceof Message ) {
1207  // Match language, flags, etc. to the current message.
1208  $msg = clone $param;
1209  if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1210  // Cache depends on these parameters
1211  $msg->message = null;
1212  }
1213  $msg->interface = $this->interface;
1214  $msg->language = $this->language;
1215  $msg->useDatabase = $this->useDatabase;
1216  $msg->title = $this->title;
1217 
1218  // DWIM
1219  if ( $format === 'block-parse' ) {
1220  $format = 'parse';
1221  }
1222  $msg->format = $format;
1223 
1224  // Message objects should not be before parameters because
1225  // then they'll get double escaped. If the message needs to be
1226  // escaped, it'll happen right here when we call toString().
1227  return [ 'after', $msg->toString( $format ) ];
1228  } else {
1229  return [ 'before', $param ];
1230  }
1231  }
1232 
1242  protected function parseText( $string ) {
1243  $out = MediaWikiServices::getInstance()->getMessageCache()->parse(
1244  $string,
1245  $this->title,
1246  /*linestart*/true,
1247  $this->interface,
1248  $this->getLanguage()
1249  );
1250 
1251  return $out instanceof ParserOutput
1252  ? $out->getText( [
1253  'enableSectionEditLinks' => false,
1254  // Wrapping messages in an extra <div> is probably not expected. If
1255  // they're outside the content area they probably shouldn't be
1256  // targeted by CSS that's targeting the parser output, and if
1257  // they're inside they already are from the outer div.
1258  'unwrap' => true,
1259  ] )
1260  : $out;
1261  }
1262 
1272  protected function transformText( $string ) {
1273  return MediaWikiServices::getInstance()->getMessageCache()->transform(
1274  $string,
1275  $this->interface,
1276  $this->getLanguage(),
1277  $this->title
1278  );
1279  }
1280 
1289  protected function fetchMessage() {
1290  if ( $this->message === null ) {
1291  $cache = MediaWikiServices::getInstance()->getMessageCache();
1292 
1293  foreach ( $this->keysToTry as $key ) {
1294  $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1295  if ( $message !== false && $message !== '' ) {
1296  break;
1297  }
1298  }
1299 
1300  // NOTE: The constructor makes sure keysToTry isn't empty,
1301  // so we know that $key and $message are initialized.
1302  $this->key = $key;
1303  $this->message = $message;
1304  }
1305  return $this->message;
1306  }
1307 
1320  protected function formatPlaintext( $plaintext, $format ) {
1321  switch ( $format ) {
1322  case self::FORMAT_TEXT:
1323  case self::FORMAT_PLAIN:
1324  return $plaintext;
1325 
1326  case self::FORMAT_PARSE:
1328  case self::FORMAT_ESCAPED:
1329  default:
1330  return htmlspecialchars( $plaintext, ENT_QUOTES );
1331  }
1332  }
1333 
1342  protected function formatListParam( array $params, $listType, $format ) {
1343  if ( !isset( self::$listTypeMap[$listType] ) ) {
1344  $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1345  . htmlspecialchars( $listType )
1346  . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1347  trigger_error( $warning, E_USER_WARNING );
1348  $e = new Exception;
1349  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1350  return [ 'before', '[INVALID]' ];
1351  }
1352  $func = self::$listTypeMap[$listType];
1353 
1354  // Handle an empty list sensibly
1355  if ( !$params ) {
1356  return [ 'before', $this->getLanguage()->$func( [] ) ];
1357  }
1358 
1359  // First, determine what kinds of list items we have
1360  $types = [];
1361  $vars = [];
1362  $list = [];
1363  foreach ( $params as $n => $p ) {
1364  list( $type, $value ) = $this->extractParam( $p, $format );
1365  $types[$type] = true;
1366  $list[] = $value;
1367  $vars[] = '$' . ( $n + 1 );
1368  }
1369 
1370  // Easy case: all are 'before' or 'after', so just join the
1371  // values and use the same type.
1372  if ( count( $types ) === 1 ) {
1373  return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1374  }
1375 
1376  // Hard case: We need to process each value per its type, then
1377  // return the concatenated values as 'after'. We handle this by turning
1378  // the list into a RawMessage and processing that as a parameter.
1379  $vars = $this->getLanguage()->$func( $vars );
1380  // @phan-suppress-next-line SecurityCheck-DoubleEscaped RawMessage is safe here
1381  return $this->extractParam( new RawMessage( $vars, $params ), $format );
1382  }
1383 }
Message\numParam
static numParam( $num)
Definition: Message.php:1038
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:424
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:363
Message\getParams
getParams()
Returns the message parameters.
Definition: Message.php:378
Message\exists
exists()
Check whether a message key has been defined currently.
Definition: Message.php:990
ParserOutput
Definition: ParserOutput.php:31
Message\$listTypeMap
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition: Message.php:177
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
Message\$message
string $message
Definition: Message.php:239
Message\toString
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Definition: Message.php:844
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:172
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
true
return true
Definition: router.php:90
MessageSpecifier
Stable for implementing.
Definition: MessageSpecifier.php:24
Message\parseText
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
Definition: Message.php:1242
Message\$keysToTry
string[] $keysToTry
List of keys to try when fetching the message.
Definition: Message.php:208
Message\timeperiodParam
static timeperiodParam( $period)
Definition: Message.php:1071
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:88
Message\fetchMessage
fetchMessage()
Wrapper for what ever method we use to get message contents.
Definition: Message.php:1289
Message\plain
plain()
Returns the message text as-is, only parameters are substituted.
Definition: Message.php:953
Message\$title
Title $title
Title object to use as context.
Definition: Message.php:229
Message\inContentLanguage
inContentLanguage()
Request the message in the wiki's content language, unless it is disabled for this message.
Definition: Message.php:766
Message\$content
Content $content
Content object representing the message.
Definition: Message.php:234
Message\isDisabled
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
Definition: Message.php:1014
Message\text
text()
Returns the message text.
Definition: Message.php:941
Message\setInterfaceMessageFlag
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition: Message.php:786
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:996
Message\listParam
static listParam(array $list, $type='text')
Definition: Message.php:1115
Message\__toString
__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
Message\$language
Language bool $language
In which language to get this message.
Definition: Message.php:197
Message\getKey
getKey()
Returns the message key.
Definition: Message.php:367
Message\getLanguage
getLanguage()
Returns the Language of the Message.
Definition: Message.php:389
Message\numParams
numParams(... $params)
Add parameters that are numeric and will be passed through Language::formatNum before substitution.
Definition: Message.php:564
Message\isBlank
isBlank()
Check whether a message does not exist, or is an empty string.
Definition: Message.php:1002
Message\FORMAT_BLOCK_PARSE
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)
Definition: Message.php:165
MWException
MediaWiki exception.
Definition: MWException.php:29
Message\isMultiKey
isMultiKey()
Definition: Message.php:342
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
Message\useDatabase
useDatabase( $useDatabase)
Enable or disable database use.
Definition: Message.php:800
Message\FORMAT_TEXT
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
Definition: Message.php:169
Message\durationParams
durationParams(... $params)
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
Definition: Message.php:585
Message\serialize
serialize()
Definition: Message.php:285
Message\$interface
bool $interface
In which language to get this message.
Definition: Message.php:190
$args
if( $line===false) $args
Definition: mcc.php:124
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:626
Message\rawParams
rawParams(... $params)
Add parameters that are substituted after parsing or escaping.
Definition: Message.php:543
Message\FORMAT_PARSE
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
Definition: Message.php:167
Message\getKeysToTry
getKeysToTry()
Definition: Message.php:352
Message\parseAsBlock
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
Definition: Message.php:965
Message\sizeParam
static sizeParam( $size)
Definition: Message.php:1082
Language\getCode
getCode()
Get the internal language code for this language object.
Definition: Language.php:4471
Message\formatPlaintext
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with 'plaintext'.
Definition: Message.php:1320
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1104
Message\rawParam
static rawParam( $raw)
Definition: Message.php:1027
StubUserLang
Stub object for the user language.
Definition: StubUserLang.php:26
Message\expiryParam
static expiryParam( $expiry)
Definition: Message.php:1060
Message\parse
parse()
Fully parse the text from wikitext to HTML.
Definition: Message.php:929
Message\setContext
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition: Message.php:711
Message\transformText
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition: Message.php:1272
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:476
IContextSource\getTitle
getTitle()
Message\plaintextParams
plaintextParams(... $params)
Add parameters that are plaintext and will be passed through without the content being evaluated.
Definition: Message.php:692
$wgForceUIMsgAsContentMsg
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
Definition: DefaultSettings.php:3417
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:57
Message\extractParam
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition: Message.php:1172
Message\escaped
escaped()
Returns the message text.
Definition: Message.php:978
Content
Base interface for content objects.
Definition: Content.php:35
Message\params
params(... $args)
Adds parameters to the parameter list of this message.
Definition: Message.php:508
Title
Represents a title within MediaWiki.
Definition: Title.php:46
Message\$key
string $key
The message key.
Definition: Message.php:203
Parser\stripOuterParagraph
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6288
Message\newFromKey
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:406
Message\formatListParam
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition: Message.php:1342
$cache
$cache
Definition: mcc.php:33
MessageContent
Wrapper allowing us to handle a system message as a Content object.
Definition: MessageContent.php:36
Message\getTitle
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
Definition: Message.php:481
Message\title
title( $title)
Set the Title object to use as context when transforming the message.
Definition: Message.php:815
Message\bitrateParam
static bitrateParam( $bitrate)
Definition: Message.php:1093
Message\replaceParameters
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition: Message.php:1135
Message\bitrateParams
bitrateParams(... $params)
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition: Message.php:669
Message\unserialize
unserialize( $serialized)
Definition: Message.php:309
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:161
$keys
$keys
Definition: testCompression.php:72
Message\$parameters
array $parameters
List of parameters which will be substituted into the message.
Definition: Message.php:213
Message\content
content()
Returns the message as a Content object.
Definition: Message.php:825
Message\expiryParams
expiryParams(... $params)
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition: Message.php:606
ParserOutput\getText
getText( $options=[])
Get the output HTML.
Definition: ParserOutput.php:350
Message\$useDatabase
bool $useDatabase
Whether database can be used.
Definition: Message.php:224
Message\timeperiodParams
timeperiodParams(... $params)
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition: Message.php:627
Message\FORMAT_ESCAPED
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
Definition: Message.php:171
RawMessage
Variant of the Message class.
Definition: RawMessage.php:35
Message\__construct
__construct( $key, $params=[], Language $language=null)
Stable to call.
Definition: Message.php:251
Message\sizeParams
sizeParams(... $params)
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
Definition: Message.php:648
Message\inLanguage
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:730
Message\FORMAT_PLAIN
const FORMAT_PLAIN
Use message text as-is.
Definition: Message.php:163
Message\newFallbackSequence
static newFallbackSequence(... $keys)
Factory function accepting multiple message keys and returning a message instance for the first messa...
Definition: Message.php:458
Message\durationParam
static durationParam( $duration)
Definition: Message.php:1049
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42
Message\$format
string $format
Definition: Message.php:219
IContextSource\getLanguage
getLanguage()
$type
$type
Definition: testCompression.php:52