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 
390  public function getFormat() {
391  wfDeprecated( __METHOD__, '1.29' );
392  return $this->format;
393  }
394 
402  public function getLanguage() {
403  // Defaults to false which means current user language
404  return $this->language ?: RequestContext::getMain()->getLanguage();
405  }
406 
419  public static function newFromKey( $key, ...$params ) {
420  return new self( $key, $params );
421  }
422 
436  public static function newFromSpecifier( $value ) {
437  $params = [];
438  if ( is_array( $value ) ) {
439  $params = $value;
440  $value = array_shift( $params );
441  }
442 
443  if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
444  $message = clone $value;
445  } elseif ( $value instanceof MessageSpecifier ) {
446  $message = new Message( $value );
447  } elseif ( is_string( $value ) ) {
448  $message = new Message( $value, $params );
449  } else {
450  throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
451  . gettype( $value ) );
452  }
453 
454  return $message;
455  }
456 
469  public static function newFallbackSequence( ...$keys ) {
470  if ( func_num_args() == 1 ) {
471  if ( is_array( $keys[0] ) ) {
472  // Allow an array to be passed as the first argument instead
473  $keys = array_values( $keys[0] );
474  } else {
475  // Optimize a single string to not need special fallback handling
476  $keys = $keys[0];
477  }
478  }
479  return new self( $keys );
480  }
481 
492  public function getTitle() {
494 
495  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
496  $lang = $this->getLanguage();
497  $title = $this->key;
498  if (
499  !$lang->equals( $contLang )
500  && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
501  ) {
502  $title .= '/' . $lang->getCode();
503  }
504 
505  return Title::makeTitle(
506  NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
507  }
508 
519  public function params( ...$args ) {
520  // If $args has only one entry and it's an array, then it's either a
521  // non-varargs call or it happens to be a call with just a single
522  // "special" parameter. Since the "special" parameters don't have any
523  // numeric keys, we'll test that to differentiate the cases.
524  if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
525  if ( $args[0] === [] ) {
526  $args = [];
527  } else {
528  foreach ( $args[0] as $key => $value ) {
529  if ( is_int( $key ) ) {
530  $args = $args[0];
531  break;
532  }
533  }
534  }
535  }
536 
537  $this->parameters = array_merge( $this->parameters, array_values( $args ) );
538  return $this;
539  }
540 
554  public function rawParams( ...$params ) {
555  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
556  $params = $params[0];
557  }
558  foreach ( $params as $param ) {
559  $this->parameters[] = self::rawParam( $param );
560  }
561  return $this;
562  }
563 
575  public function numParams( ...$params ) {
576  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
577  $params = $params[0];
578  }
579  foreach ( $params as $param ) {
580  $this->parameters[] = self::numParam( $param );
581  }
582  return $this;
583  }
584 
596  public function durationParams( ...$params ) {
597  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
598  $params = $params[0];
599  }
600  foreach ( $params as $param ) {
601  $this->parameters[] = self::durationParam( $param );
602  }
603  return $this;
604  }
605 
617  public function expiryParams( ...$params ) {
618  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
619  $params = $params[0];
620  }
621  foreach ( $params as $param ) {
622  $this->parameters[] = self::expiryParam( $param );
623  }
624  return $this;
625  }
626 
638  public function timeperiodParams( ...$params ) {
639  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
640  $params = $params[0];
641  }
642  foreach ( $params as $param ) {
643  $this->parameters[] = self::timeperiodParam( $param );
644  }
645  return $this;
646  }
647 
659  public function sizeParams( ...$params ) {
660  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
661  $params = $params[0];
662  }
663  foreach ( $params as $param ) {
664  $this->parameters[] = self::sizeParam( $param );
665  }
666  return $this;
667  }
668 
680  public function bitrateParams( ...$params ) {
681  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
682  $params = $params[0];
683  }
684  foreach ( $params as $param ) {
685  $this->parameters[] = self::bitrateParam( $param );
686  }
687  return $this;
688  }
689 
703  public function plaintextParams( ...$params ) {
704  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
705  $params = $params[0];
706  }
707  foreach ( $params as $param ) {
708  $this->parameters[] = self::plaintextParam( $param );
709  }
710  return $this;
711  }
712 
722  public function setContext( IContextSource $context ) {
723  $this->inLanguage( $context->getLanguage() );
724  $this->title( $context->getTitle() );
725  $this->interface = true;
726 
727  return $this;
728  }
729 
741  public function inLanguage( $lang ) {
742  $previousLanguage = $this->language;
743 
744  if ( $lang instanceof Language ) {
745  $this->language = $lang;
746  } elseif ( is_string( $lang ) ) {
747  if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
748  $this->language = MediaWikiServices::getInstance()->getLanguageFactory()
749  ->getLanguage( $lang );
750  }
751  } elseif ( $lang instanceof StubUserLang ) {
752  $this->language = false;
753  } else {
754  $type = gettype( $lang );
755  throw new MWException( __METHOD__ . " must be "
756  . "passed a String or Language object; $type given"
757  );
758  }
759 
760  if ( $this->language !== $previousLanguage ) {
761  // The language has changed. Clear the message cache.
762  $this->message = null;
763  }
764  $this->interface = false;
765  return $this;
766  }
767 
777  public function inContentLanguage() {
779  if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
780  return $this;
781  }
782 
783  $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
784  return $this;
785  }
786 
797  public function setInterfaceMessageFlag( $interface ) {
798  $this->interface = (bool)$interface;
799  return $this;
800  }
801 
811  public function useDatabase( $useDatabase ) {
812  $this->useDatabase = (bool)$useDatabase;
813  $this->message = null;
814  return $this;
815  }
816 
826  public function title( $title ) {
827  $this->title = $title;
828  return $this;
829  }
830 
836  public function content() {
837  if ( !$this->content ) {
838  $this->content = new MessageContent( $this );
839  }
840 
841  return $this->content;
842  }
843 
855  public function toString( $format = null ) {
856  if ( $format === null ) {
857  $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
858  LoggerFactory::getInstance( 'message-format' )->warning(
859  $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
861  }
862  $string = $this->fetchMessage();
863 
864  if ( $string === false ) {
865  // Err on the side of safety, ensure that the output
866  // is always html safe in the event the message key is
867  // missing, since in that case its highly likely the
868  // message key is user-controlled.
869  // '⧼' is used instead of '<' to side-step any
870  // double-escaping issues.
871  // (Keep synchronised with mw.Message#toString in JS.)
872  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
873  }
874 
875  # Replace $* with a list of parameters for &uselang=qqx.
876  if ( strpos( $string, '$*' ) !== false ) {
877  $paramlist = '';
878  if ( $this->parameters !== [] ) {
879  $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
880  }
881  $string = str_replace( '$*', $paramlist, $string );
882  }
883 
884  # Replace parameters before text parsing
885  $string = $this->replaceParameters( $string, 'before', $format );
886 
887  # Maybe transform using the full parser
888  if ( $format === self::FORMAT_PARSE ) {
889  $string = $this->parseText( $string );
890  $string = Parser::stripOuterParagraph( $string );
891  } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
892  $string = $this->parseText( $string );
893  } elseif ( $format === self::FORMAT_TEXT ) {
894  $string = $this->transformText( $string );
895  } elseif ( $format === self::FORMAT_ESCAPED ) {
896  $string = $this->transformText( $string );
897  $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
898  }
899 
900  # Raw parameter replacement
901  $string = $this->replaceParameters( $string, 'after', $format );
902 
903  return $string;
904  }
905 
915  public function __toString() {
916  // PHP doesn't allow __toString to throw exceptions and will
917  // trigger a fatal error if it does. So, catch any exceptions.
918 
919  try {
920  return $this->toString( self::FORMAT_PARSE );
921  } catch ( Exception $ex ) {
922  try {
923  trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
924  . $ex, E_USER_WARNING );
925  } catch ( Exception $ex ) {
926  // Doh! Cause a fatal error after all?
927  }
928 
929  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
930  }
931  }
932 
940  public function parse() {
941  $this->format = self::FORMAT_PARSE;
942  return $this->toString( self::FORMAT_PARSE );
943  }
944 
952  public function text() {
953  $this->format = self::FORMAT_TEXT;
954  return $this->toString( self::FORMAT_TEXT );
955  }
956 
964  public function plain() {
965  $this->format = self::FORMAT_PLAIN;
966  return $this->toString( self::FORMAT_PLAIN );
967  }
968 
976  public function parseAsBlock() {
977  $this->format = self::FORMAT_BLOCK_PARSE;
978  return $this->toString( self::FORMAT_BLOCK_PARSE );
979  }
980 
989  public function escaped() {
990  $this->format = self::FORMAT_ESCAPED;
991  return $this->toString( self::FORMAT_ESCAPED );
992  }
993 
1001  public function exists() {
1002  return $this->fetchMessage() !== false;
1003  }
1004 
1013  public function isBlank() {
1014  $message = $this->fetchMessage();
1015  return $message === false || $message === '';
1016  }
1017 
1025  public function isDisabled() {
1026  $message = $this->fetchMessage();
1027  return $message === false || $message === '' || $message === '-';
1028  }
1029 
1037  public static function rawParam( $raw ) {
1038  return [ 'raw' => $raw ];
1039  }
1040 
1048  public static function numParam( $num ) {
1049  return [ 'num' => $num ];
1050  }
1051 
1059  public static function durationParam( $duration ) {
1060  return [ 'duration' => $duration ];
1061  }
1062 
1070  public static function expiryParam( $expiry ) {
1071  return [ 'expiry' => $expiry ];
1072  }
1073 
1081  public static function timeperiodParam( $period ) {
1082  return [ 'period' => $period ];
1083  }
1084 
1092  public static function sizeParam( $size ) {
1093  return [ 'size' => $size ];
1094  }
1095 
1103  public static function bitrateParam( $bitrate ) {
1104  return [ 'bitrate' => $bitrate ];
1105  }
1106 
1114  public static function plaintextParam( $plaintext ) {
1115  return [ 'plaintext' => $plaintext ];
1116  }
1117 
1125  public static function listParam( array $list, $type = 'text' ) {
1126  if ( !isset( self::$listTypeMap[$type] ) ) {
1127  throw new InvalidArgumentException(
1128  "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1129  );
1130  }
1131  return [ 'list' => $list, 'type' => $type ];
1132  }
1133 
1145  protected function replaceParameters( $message, $type, $format ) {
1146  // A temporary marker for $1 parameters that is only valid
1147  // in non-attribute contexts. However if the entire message is escaped
1148  // then we don't want to use it because it will be mangled in all contexts
1149  // and its unnessary as ->escaped() messages aren't html.
1150  $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1151  $replacementKeys = [];
1152  foreach ( $this->parameters as $n => $param ) {
1153  list( $paramType, $value ) = $this->extractParam( $param, $format );
1154  if ( $type === 'before' ) {
1155  if ( $paramType === 'before' ) {
1156  $replacementKeys['$' . ( $n + 1 )] = $value;
1157  } else /* $paramType === 'after' */ {
1158  // To protect against XSS from replacing parameters
1159  // inside html attributes, we convert $1 to $'"1.
1160  // In the event that one of the parameters ends up
1161  // in an attribute, either the ' or the " will be
1162  // escaped, breaking the replacement and avoiding XSS.
1163  $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1164  }
1165  } elseif ( $paramType === 'after' ) {
1166  $replacementKeys[$marker . ( $n + 1 )] = $value;
1167  }
1168  }
1169  return strtr( $message, $replacementKeys );
1170  }
1171 
1182  protected function extractParam( $param, $format ) {
1183  if ( is_array( $param ) ) {
1184  if ( isset( $param['raw'] ) ) {
1185  return [ 'after', $param['raw'] ];
1186  } elseif ( isset( $param['num'] ) ) {
1187  // Replace number params always in before step for now.
1188  // No support for combined raw and num params
1189  return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1190  } elseif ( isset( $param['duration'] ) ) {
1191  return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1192  } elseif ( isset( $param['expiry'] ) ) {
1193  return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1194  } elseif ( isset( $param['period'] ) ) {
1195  return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1196  } elseif ( isset( $param['size'] ) ) {
1197  return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1198  } elseif ( isset( $param['bitrate'] ) ) {
1199  return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1200  } elseif ( isset( $param['plaintext'] ) ) {
1201  return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1202  } elseif ( isset( $param['list'] ) ) {
1203  return $this->formatListParam( $param['list'], $param['type'], $format );
1204  } else {
1205  LoggerFactory::getInstance( 'Bug58676' )->warning(
1206  'Invalid parameter for message "{msgkey}": {param}',
1207  [
1208  'exception' => new Exception,
1209  'msgkey' => $this->getKey(),
1210  'param' => htmlspecialchars( serialize( $param ) ),
1211  ]
1212  );
1213 
1214  return [ 'before', '[INVALID]' ];
1215  }
1216  } elseif ( $param instanceof Message ) {
1217  // Match language, flags, etc. to the current message.
1218  $msg = clone $param;
1219  if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1220  // Cache depends on these parameters
1221  $msg->message = null;
1222  }
1223  $msg->interface = $this->interface;
1224  $msg->language = $this->language;
1225  $msg->useDatabase = $this->useDatabase;
1226  $msg->title = $this->title;
1227 
1228  // DWIM
1229  if ( $format === 'block-parse' ) {
1230  $format = 'parse';
1231  }
1232  $msg->format = $format;
1233 
1234  // Message objects should not be before parameters because
1235  // then they'll get double escaped. If the message needs to be
1236  // escaped, it'll happen right here when we call toString().
1237  return [ 'after', $msg->toString( $format ) ];
1238  } else {
1239  return [ 'before', $param ];
1240  }
1241  }
1242 
1252  protected function parseText( $string ) {
1253  $out = MediaWikiServices::getInstance()->getMessageCache()->parse(
1254  $string,
1255  $this->title,
1256  /*linestart*/true,
1257  $this->interface,
1258  $this->getLanguage()
1259  );
1260 
1261  return $out instanceof ParserOutput
1262  ? $out->getText( [
1263  'enableSectionEditLinks' => false,
1264  // Wrapping messages in an extra <div> is probably not expected. If
1265  // they're outside the content area they probably shouldn't be
1266  // targeted by CSS that's targeting the parser output, and if
1267  // they're inside they already are from the outer div.
1268  'unwrap' => true,
1269  ] )
1270  : $out;
1271  }
1272 
1282  protected function transformText( $string ) {
1283  return MediaWikiServices::getInstance()->getMessageCache()->transform(
1284  $string,
1285  $this->interface,
1286  $this->getLanguage(),
1287  $this->title
1288  );
1289  }
1290 
1299  protected function fetchMessage() {
1300  if ( $this->message === null ) {
1301  $cache = MediaWikiServices::getInstance()->getMessageCache();
1302 
1303  foreach ( $this->keysToTry as $key ) {
1304  $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1305  if ( $message !== false && $message !== '' ) {
1306  break;
1307  }
1308  }
1309 
1310  // NOTE: The constructor makes sure keysToTry isn't empty,
1311  // so we know that $key and $message are initialized.
1312  $this->key = $key;
1313  $this->message = $message;
1314  }
1315  return $this->message;
1316  }
1317 
1330  protected function formatPlaintext( $plaintext, $format ) {
1331  switch ( $format ) {
1332  case self::FORMAT_TEXT:
1333  case self::FORMAT_PLAIN:
1334  return $plaintext;
1335 
1336  case self::FORMAT_PARSE:
1338  case self::FORMAT_ESCAPED:
1339  default:
1340  return htmlspecialchars( $plaintext, ENT_QUOTES );
1341  }
1342  }
1343 
1352  protected function formatListParam( array $params, $listType, $format ) {
1353  if ( !isset( self::$listTypeMap[$listType] ) ) {
1354  $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1355  . htmlspecialchars( $listType )
1356  . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1357  trigger_error( $warning, E_USER_WARNING );
1358  $e = new Exception;
1359  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1360  return [ 'before', '[INVALID]' ];
1361  }
1362  $func = self::$listTypeMap[$listType];
1363 
1364  // Handle an empty list sensibly
1365  if ( !$params ) {
1366  return [ 'before', $this->getLanguage()->$func( [] ) ];
1367  }
1368 
1369  // First, determine what kinds of list items we have
1370  $types = [];
1371  $vars = [];
1372  $list = [];
1373  foreach ( $params as $n => $p ) {
1374  list( $type, $value ) = $this->extractParam( $p, $format );
1375  $types[$type] = true;
1376  $list[] = $value;
1377  $vars[] = '$' . ( $n + 1 );
1378  }
1379 
1380  // Easy case: all are 'before' or 'after', so just join the
1381  // values and use the same type.
1382  if ( count( $types ) === 1 ) {
1383  return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1384  }
1385 
1386  // Hard case: We need to process each value per its type, then
1387  // return the concatenated values as 'after'. We handle this by turning
1388  // the list into a RawMessage and processing that as a parameter.
1389  $vars = $this->getLanguage()->$func( $vars );
1390  return $this->extractParam( new RawMessage( $vars, $params ), $format );
1391  }
1392 }
Message\numParam
static numParam( $num)
Definition: Message.php:1048
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:436
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:329
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:1001
ParserOutput
Definition: ParserOutput.php:25
Message\$listTypeMap
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition: Message.php:177
Message\$message
string $message
Definition: Message.php:239
Message\toString
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Definition: Message.php:855
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
$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:1252
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:1081
$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:1299
Message\plain
plain()
Returns the message text as-is, only parameters are substituted.
Definition: Message.php:964
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:777
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:1025
Message\text
text()
Returns the message text.
Definition: Message.php:952
Message\setInterfaceMessageFlag
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition: Message.php:797
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:988
Message\listParam
static listParam(array $list, $type='text')
Definition: Message.php:1125
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:915
Message\getFormat
getFormat()
Returns the message format.
Definition: Message.php:390
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:402
Message\numParams
numParams(... $params)
Add parameters that are numeric and will be passed through Language::formatNum before substitution.
Definition: Message.php:575
Message\isBlank
isBlank()
Check whether a message does not exist, or is an empty string.
Definition: Message.php:1013
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:28
Message\isMultiKey
isMultiKey()
Definition: Message.php:342
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
Message\useDatabase
useDatabase( $useDatabase)
Enable or disable database use.
Definition: Message.php:811
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:596
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:592
Message\rawParams
rawParams(... $params)
Add parameters that are substituted after parsing or escaping.
Definition: Message.php:554
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:976
Message\sizeParam
static sizeParam( $size)
Definition: Message.php:1092
Language\getCode
getCode()
Get the internal language code for this language object.
Definition: Language.php:4370
Message\formatPlaintext
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with 'plaintext'.
Definition: Message.php:1330
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1114
Message\rawParam
static rawParam( $raw)
Definition: Message.php:1037
StubUserLang
Stub object for the user language.
Definition: StubUserLang.php:24
Message\expiryParam
static expiryParam( $expiry)
Definition: Message.php:1070
Message\parse
parse()
Fully parse the text from wikitext to HTML.
Definition: Message.php:940
Message\setContext
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition: Message.php:722
Message\transformText
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition: Message.php:1282
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:455
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:703
$wgForceUIMsgAsContentMsg
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
Definition: DefaultSettings.php:3321
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
Message\extractParam
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition: Message.php:1182
Message\escaped
escaped()
Returns the message text.
Definition: Message.php:989
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:519
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Message\$key
string $key
The message key.
Definition: Message.php:203
Parser\stripOuterParagraph
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6263
Message\newFromKey
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:419
Message\formatListParam
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition: Message.php:1352
$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:492
Message\title
title( $title)
Set the Title object to use as context when transforming the message.
Definition: Message.php:826
Message\bitrateParam
static bitrateParam( $bitrate)
Definition: Message.php:1103
Message\replaceParameters
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition: Message.php:1145
Message\bitrateParams
bitrateParams(... $params)
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition: Message.php:680
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:836
Message\expiryParams
expiryParams(... $params)
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition: Message.php:617
ParserOutput\getText
getText( $options=[])
Get the output HTML.
Definition: ParserOutput.php:346
Message\$useDatabase
bool $useDatabase
Whether database can be used.
Definition: Message.php:224
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:77
Message\timeperiodParams
timeperiodParams(... $params)
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition: Message.php:638
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 for calling.
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:659
Message\inLanguage
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:741
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:469
Message\durationParam
static durationParam( $duration)
Definition: Message.php:1059
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
Message\$format
string $format
Definition: Message.php:219
IContextSource\getLanguage
getLanguage()
$type
$type
Definition: testCompression.php:52