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 
423  public static function newFromSpecifier( $value ) {
424  $params = [];
425  if ( is_array( $value ) ) {
426  $params = $value;
427  $value = array_shift( $params );
428  }
429 
430  if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
431  $message = clone $value;
432  } elseif ( $value instanceof MessageSpecifier ) {
433  $message = new Message( $value );
434  } elseif ( is_string( $value ) ) {
435  $message = new Message( $value, $params );
436  } else {
437  throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
438  . gettype( $value ) );
439  }
440 
441  return $message;
442  }
443 
456  public static function newFallbackSequence( ...$keys ) {
457  if ( func_num_args() == 1 ) {
458  if ( is_array( $keys[0] ) ) {
459  // Allow an array to be passed as the first argument instead
460  $keys = array_values( $keys[0] );
461  } else {
462  // Optimize a single string to not need special fallback handling
463  $keys = $keys[0];
464  }
465  }
466  return new self( $keys );
467  }
468 
479  public function getTitle() {
481 
482  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
483  $lang = $this->getLanguage();
484  $title = $this->key;
485  if (
486  !$lang->equals( $contLang )
487  && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
488  ) {
489  $title .= '/' . $lang->getCode();
490  }
491 
492  return Title::makeTitle(
493  NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
494  }
495 
506  public function params( ...$args ) {
507  // If $args has only one entry and it's an array, then it's either a
508  // non-varargs call or it happens to be a call with just a single
509  // "special" parameter. Since the "special" parameters don't have any
510  // numeric keys, we'll test that to differentiate the cases.
511  if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
512  if ( $args[0] === [] ) {
513  $args = [];
514  } else {
515  foreach ( $args[0] as $key => $value ) {
516  if ( is_int( $key ) ) {
517  $args = $args[0];
518  break;
519  }
520  }
521  }
522  }
523 
524  $this->parameters = array_merge( $this->parameters, array_values( $args ) );
525  return $this;
526  }
527 
541  public function rawParams( ...$params ) {
542  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
543  $params = $params[0];
544  }
545  foreach ( $params as $param ) {
546  $this->parameters[] = self::rawParam( $param );
547  }
548  return $this;
549  }
550 
562  public function numParams( ...$params ) {
563  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
564  $params = $params[0];
565  }
566  foreach ( $params as $param ) {
567  $this->parameters[] = self::numParam( $param );
568  }
569  return $this;
570  }
571 
583  public function durationParams( ...$params ) {
584  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
585  $params = $params[0];
586  }
587  foreach ( $params as $param ) {
588  $this->parameters[] = self::durationParam( $param );
589  }
590  return $this;
591  }
592 
604  public function expiryParams( ...$params ) {
605  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
606  $params = $params[0];
607  }
608  foreach ( $params as $param ) {
609  $this->parameters[] = self::expiryParam( $param );
610  }
611  return $this;
612  }
613 
625  public function timeperiodParams( ...$params ) {
626  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
627  $params = $params[0];
628  }
629  foreach ( $params as $param ) {
630  $this->parameters[] = self::timeperiodParam( $param );
631  }
632  return $this;
633  }
634 
646  public function sizeParams( ...$params ) {
647  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
648  $params = $params[0];
649  }
650  foreach ( $params as $param ) {
651  $this->parameters[] = self::sizeParam( $param );
652  }
653  return $this;
654  }
655 
667  public function bitrateParams( ...$params ) {
668  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
669  $params = $params[0];
670  }
671  foreach ( $params as $param ) {
672  $this->parameters[] = self::bitrateParam( $param );
673  }
674  return $this;
675  }
676 
690  public function plaintextParams( ...$params ) {
691  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
692  $params = $params[0];
693  }
694  foreach ( $params as $param ) {
695  $this->parameters[] = self::plaintextParam( $param );
696  }
697  return $this;
698  }
699 
709  public function setContext( IContextSource $context ) {
710  $this->inLanguage( $context->getLanguage() );
711  $this->title( $context->getTitle() );
712  $this->interface = true;
713 
714  return $this;
715  }
716 
728  public function inLanguage( $lang ) {
729  $previousLanguage = $this->language;
730 
731  if ( $lang instanceof Language ) {
732  $this->language = $lang;
733  } elseif ( is_string( $lang ) ) {
734  if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
735  $this->language = MediaWikiServices::getInstance()->getLanguageFactory()
736  ->getLanguage( $lang );
737  }
738  } elseif ( $lang instanceof StubUserLang ) {
739  $this->language = false;
740  } else {
741  $type = gettype( $lang );
742  throw new MWException( __METHOD__ . " must be "
743  . "passed a String or Language object; $type given"
744  );
745  }
746 
747  if ( $this->language !== $previousLanguage ) {
748  // The language has changed. Clear the message cache.
749  $this->message = null;
750  }
751  $this->interface = false;
752  return $this;
753  }
754 
764  public function inContentLanguage() {
766  if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
767  return $this;
768  }
769 
770  $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
771  return $this;
772  }
773 
784  public function setInterfaceMessageFlag( $interface ) {
785  $this->interface = (bool)$interface;
786  return $this;
787  }
788 
798  public function useDatabase( $useDatabase ) {
799  $this->useDatabase = (bool)$useDatabase;
800  $this->message = null;
801  return $this;
802  }
803 
813  public function title( $title ) {
814  $this->title = $title;
815  return $this;
816  }
817 
823  public function content() {
824  if ( !$this->content ) {
825  $this->content = new MessageContent( $this );
826  }
827 
828  return $this->content;
829  }
830 
842  public function toString( $format = null ) {
843  if ( $format === null ) {
844  $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
845  LoggerFactory::getInstance( 'message-format' )->warning(
846  $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
848  }
849  $string = $this->fetchMessage();
850 
851  if ( $string === false ) {
852  // Err on the side of safety, ensure that the output
853  // is always html safe in the event the message key is
854  // missing, since in that case its highly likely the
855  // message key is user-controlled.
856  // '⧼' is used instead of '<' to side-step any
857  // double-escaping issues.
858  // (Keep synchronised with mw.Message#toString in JS.)
859  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
860  }
861 
862  # Replace $* with a list of parameters for &uselang=qqx.
863  if ( strpos( $string, '$*' ) !== false ) {
864  $paramlist = '';
865  if ( $this->parameters !== [] ) {
866  $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
867  }
868  $string = str_replace( '$*', $paramlist, $string );
869  }
870 
871  # Replace parameters before text parsing
872  $string = $this->replaceParameters( $string, 'before', $format );
873 
874  # Maybe transform using the full parser
875  if ( $format === self::FORMAT_PARSE ) {
876  $string = $this->parseText( $string );
877  $string = Parser::stripOuterParagraph( $string );
878  } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
879  $string = $this->parseText( $string );
880  } elseif ( $format === self::FORMAT_TEXT ) {
881  $string = $this->transformText( $string );
882  } elseif ( $format === self::FORMAT_ESCAPED ) {
883  $string = $this->transformText( $string );
884  $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
885  }
886 
887  # Raw parameter replacement
888  $string = $this->replaceParameters( $string, 'after', $format );
889 
890  return $string;
891  }
892 
902  public function __toString() {
903  // PHP doesn't allow __toString to throw exceptions and will
904  // trigger a fatal error if it does. So, catch any exceptions.
905 
906  try {
907  return $this->toString( self::FORMAT_PARSE );
908  } catch ( Exception $ex ) {
909  try {
910  trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
911  . $ex, E_USER_WARNING );
912  } catch ( Exception $ex ) {
913  // Doh! Cause a fatal error after all?
914  }
915 
916  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
917  }
918  }
919 
927  public function parse() {
928  $this->format = self::FORMAT_PARSE;
929  return $this->toString( self::FORMAT_PARSE );
930  }
931 
939  public function text() {
940  $this->format = self::FORMAT_TEXT;
941  return $this->toString( self::FORMAT_TEXT );
942  }
943 
951  public function plain() {
952  $this->format = self::FORMAT_PLAIN;
953  return $this->toString( self::FORMAT_PLAIN );
954  }
955 
963  public function parseAsBlock() {
964  $this->format = self::FORMAT_BLOCK_PARSE;
965  return $this->toString( self::FORMAT_BLOCK_PARSE );
966  }
967 
976  public function escaped() {
977  $this->format = self::FORMAT_ESCAPED;
978  return $this->toString( self::FORMAT_ESCAPED );
979  }
980 
988  public function exists() {
989  return $this->fetchMessage() !== false;
990  }
991 
1000  public function isBlank() {
1001  $message = $this->fetchMessage();
1002  return $message === false || $message === '';
1003  }
1004 
1012  public function isDisabled() {
1013  $message = $this->fetchMessage();
1014  return $message === false || $message === '' || $message === '-';
1015  }
1016 
1024  public static function rawParam( $raw ) {
1025  return [ 'raw' => $raw ];
1026  }
1027 
1035  public static function numParam( $num ) {
1036  return [ 'num' => $num ];
1037  }
1038 
1046  public static function durationParam( $duration ) {
1047  return [ 'duration' => $duration ];
1048  }
1049 
1057  public static function expiryParam( $expiry ) {
1058  return [ 'expiry' => $expiry ];
1059  }
1060 
1068  public static function timeperiodParam( $period ) {
1069  return [ 'period' => $period ];
1070  }
1071 
1079  public static function sizeParam( $size ) {
1080  return [ 'size' => $size ];
1081  }
1082 
1090  public static function bitrateParam( $bitrate ) {
1091  return [ 'bitrate' => $bitrate ];
1092  }
1093 
1101  public static function plaintextParam( $plaintext ) {
1102  return [ 'plaintext' => $plaintext ];
1103  }
1104 
1112  public static function listParam( array $list, $type = 'text' ) {
1113  if ( !isset( self::$listTypeMap[$type] ) ) {
1114  throw new InvalidArgumentException(
1115  "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1116  );
1117  }
1118  return [ 'list' => $list, 'type' => $type ];
1119  }
1120 
1132  protected function replaceParameters( $message, $type, $format ) {
1133  // A temporary marker for $1 parameters that is only valid
1134  // in non-attribute contexts. However if the entire message is escaped
1135  // then we don't want to use it because it will be mangled in all contexts
1136  // and its unnessary as ->escaped() messages aren't html.
1137  $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1138  $replacementKeys = [];
1139  foreach ( $this->parameters as $n => $param ) {
1140  list( $paramType, $value ) = $this->extractParam( $param, $format );
1141  if ( $type === 'before' ) {
1142  if ( $paramType === 'before' ) {
1143  $replacementKeys['$' . ( $n + 1 )] = $value;
1144  } else /* $paramType === 'after' */ {
1145  // To protect against XSS from replacing parameters
1146  // inside html attributes, we convert $1 to $'"1.
1147  // In the event that one of the parameters ends up
1148  // in an attribute, either the ' or the " will be
1149  // escaped, breaking the replacement and avoiding XSS.
1150  $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1151  }
1152  } elseif ( $paramType === 'after' ) {
1153  $replacementKeys[$marker . ( $n + 1 )] = $value;
1154  }
1155  }
1156  return strtr( $message, $replacementKeys );
1157  }
1158 
1169  protected function extractParam( $param, $format ) {
1170  if ( is_array( $param ) ) {
1171  if ( isset( $param['raw'] ) ) {
1172  return [ 'after', $param['raw'] ];
1173  } elseif ( isset( $param['num'] ) ) {
1174  // Replace number params always in before step for now.
1175  // No support for combined raw and num params
1176  return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1177  } elseif ( isset( $param['duration'] ) ) {
1178  return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1179  } elseif ( isset( $param['expiry'] ) ) {
1180  return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1181  } elseif ( isset( $param['period'] ) ) {
1182  return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1183  } elseif ( isset( $param['size'] ) ) {
1184  return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1185  } elseif ( isset( $param['bitrate'] ) ) {
1186  return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1187  } elseif ( isset( $param['plaintext'] ) ) {
1188  return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1189  } elseif ( isset( $param['list'] ) ) {
1190  return $this->formatListParam( $param['list'], $param['type'], $format );
1191  } else {
1192  LoggerFactory::getInstance( 'Bug58676' )->warning(
1193  'Invalid parameter for message "{msgkey}": {param}',
1194  [
1195  'exception' => new Exception,
1196  'msgkey' => $this->getKey(),
1197  'param' => htmlspecialchars( serialize( $param ) ),
1198  ]
1199  );
1200 
1201  return [ 'before', '[INVALID]' ];
1202  }
1203  } elseif ( $param instanceof Message ) {
1204  // Match language, flags, etc. to the current message.
1205  $msg = clone $param;
1206  if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1207  // Cache depends on these parameters
1208  $msg->message = null;
1209  }
1210  $msg->interface = $this->interface;
1211  $msg->language = $this->language;
1212  $msg->useDatabase = $this->useDatabase;
1213  $msg->title = $this->title;
1214 
1215  // DWIM
1216  if ( $format === 'block-parse' ) {
1217  $format = 'parse';
1218  }
1219  $msg->format = $format;
1220 
1221  // Message objects should not be before parameters because
1222  // then they'll get double escaped. If the message needs to be
1223  // escaped, it'll happen right here when we call toString().
1224  return [ 'after', $msg->toString( $format ) ];
1225  } else {
1226  return [ 'before', $param ];
1227  }
1228  }
1229 
1239  protected function parseText( $string ) {
1240  $out = MediaWikiServices::getInstance()->getMessageCache()->parse(
1241  $string,
1242  $this->title,
1243  /*linestart*/true,
1244  $this->interface,
1245  $this->getLanguage()
1246  );
1247 
1248  return $out instanceof ParserOutput
1249  ? $out->getText( [
1250  'enableSectionEditLinks' => false,
1251  // Wrapping messages in an extra <div> is probably not expected. If
1252  // they're outside the content area they probably shouldn't be
1253  // targeted by CSS that's targeting the parser output, and if
1254  // they're inside they already are from the outer div.
1255  'unwrap' => true,
1256  ] )
1257  : $out;
1258  }
1259 
1269  protected function transformText( $string ) {
1270  return MediaWikiServices::getInstance()->getMessageCache()->transform(
1271  $string,
1272  $this->interface,
1273  $this->getLanguage(),
1274  $this->title
1275  );
1276  }
1277 
1286  protected function fetchMessage() {
1287  if ( $this->message === null ) {
1288  $cache = MediaWikiServices::getInstance()->getMessageCache();
1289 
1290  foreach ( $this->keysToTry as $key ) {
1291  $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1292  if ( $message !== false && $message !== '' ) {
1293  break;
1294  }
1295  }
1296 
1297  // NOTE: The constructor makes sure keysToTry isn't empty,
1298  // so we know that $key and $message are initialized.
1299  $this->key = $key;
1300  $this->message = $message;
1301  }
1302  return $this->message;
1303  }
1304 
1317  protected function formatPlaintext( $plaintext, $format ) {
1318  switch ( $format ) {
1319  case self::FORMAT_TEXT:
1320  case self::FORMAT_PLAIN:
1321  return $plaintext;
1322 
1323  case self::FORMAT_PARSE:
1325  case self::FORMAT_ESCAPED:
1326  default:
1327  return htmlspecialchars( $plaintext, ENT_QUOTES );
1328  }
1329  }
1330 
1339  protected function formatListParam( array $params, $listType, $format ) {
1340  if ( !isset( self::$listTypeMap[$listType] ) ) {
1341  $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1342  . htmlspecialchars( $listType )
1343  . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1344  trigger_error( $warning, E_USER_WARNING );
1345  $e = new Exception;
1346  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1347  return [ 'before', '[INVALID]' ];
1348  }
1349  $func = self::$listTypeMap[$listType];
1350 
1351  // Handle an empty list sensibly
1352  if ( !$params ) {
1353  return [ 'before', $this->getLanguage()->$func( [] ) ];
1354  }
1355 
1356  // First, determine what kinds of list items we have
1357  $types = [];
1358  $vars = [];
1359  $list = [];
1360  foreach ( $params as $n => $p ) {
1361  list( $type, $value ) = $this->extractParam( $p, $format );
1362  $types[$type] = true;
1363  $list[] = $value;
1364  $vars[] = '$' . ( $n + 1 );
1365  }
1366 
1367  // Easy case: all are 'before' or 'after', so just join the
1368  // values and use the same type.
1369  if ( count( $types ) === 1 ) {
1370  return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1371  }
1372 
1373  // Hard case: We need to process each value per its type, then
1374  // return the concatenated values as 'after'. We handle this by turning
1375  // the list into a RawMessage and processing that as a parameter.
1376  $vars = $this->getLanguage()->$func( $vars );
1377  return $this->extractParam( new RawMessage( $vars, $params ), $format );
1378  }
1379 }
Message\numParam
static numParam( $num)
Definition: Message.php:1035
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:423
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:328
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:988
ParserOutput
Definition: ParserOutput.php:31
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:842
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:165
$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:1239
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:1068
$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:1286
Message\plain
plain()
Returns the message text as-is, only parameters are substituted.
Definition: Message.php:951
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:764
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:1012
Message\text
text()
Returns the message text.
Definition: Message.php:939
Message\setInterfaceMessageFlag
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition: Message.php:784
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:989
Message\listParam
static listParam(array $list, $type='text')
Definition: Message.php:1112
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:902
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:562
Message\isBlank
isBlank()
Check whether a message does not exist, or is an empty string.
Definition: Message.php:1000
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:798
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:583
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:591
Message\rawParams
rawParams(... $params)
Add parameters that are substituted after parsing or escaping.
Definition: Message.php:541
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:963
Message\sizeParam
static sizeParam( $size)
Definition: Message.php:1079
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:1317
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1101
Message\rawParam
static rawParam( $raw)
Definition: Message.php:1024
StubUserLang
Stub object for the user language.
Definition: StubUserLang.php:26
Message\expiryParam
static expiryParam( $expiry)
Definition: Message.php:1057
Message\parse
parse()
Fully parse the text from wikitext to HTML.
Definition: Message.php:927
Message\setContext
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition: Message.php:709
Message\transformText
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition: Message.php:1269
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:454
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:690
$wgForceUIMsgAsContentMsg
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
Definition: DefaultSettings.php:3339
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:1169
Message\escaped
escaped()
Returns the message text.
Definition: Message.php:976
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:506
Title
Represents a title within MediaWiki.
Definition: Title.php:41
Message\$key
string $key
The message key.
Definition: Message.php:203
Parser\stripOuterParagraph
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6227
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:1339
$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:479
Message\title
title( $title)
Set the Title object to use as context when transforming the message.
Definition: Message.php:813
Message\bitrateParam
static bitrateParam( $bitrate)
Definition: Message.php:1090
Message\replaceParameters
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition: Message.php:1132
Message\bitrateParams
bitrateParams(... $params)
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition: Message.php:667
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:823
Message\expiryParams
expiryParams(... $params)
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition: Message.php:604
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
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:625
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:646
Message\inLanguage
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:728
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:456
Message\durationParam
static durationParam( $duration)
Definition: Message.php:1046
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