MediaWiki  master
Message.php
Go to the documentation of this file.
1 <?php
24 
162  const FORMAT_PLAIN = 'plain';
164  const FORMAT_BLOCK_PARSE = 'block-parse';
166  const FORMAT_PARSE = 'parse';
168  const FORMAT_TEXT = 'text';
170  const FORMAT_ESCAPED = 'escaped';
171 
176  protected static $listTypeMap = [
177  'comma' => 'commaList',
178  'semicolon' => 'semicolonList',
179  'pipe' => 'pipeList',
180  'text' => 'listToText',
181  ];
182 
189  protected $interface = true;
190 
196  protected $language = false;
197 
202  protected $key;
203 
207  protected $keysToTry;
208 
212  protected $parameters = [];
213 
218  protected $format = 'parse';
219 
223  protected $useDatabase = true;
224 
228  protected $title = null;
229 
233  protected $content = null;
234 
238  protected $message;
239 
249  public function __construct( $key, $params = [], Language $language = null ) {
250  if ( $key instanceof MessageSpecifier ) {
251  if ( $params ) {
252  throw new InvalidArgumentException(
253  '$params must be empty if $key is a MessageSpecifier'
254  );
255  }
256  $params = $key->getParams();
257  $key = $key->getKey();
258  }
259 
260  if ( !is_string( $key ) && !is_array( $key ) ) {
261  throw new InvalidArgumentException( '$key must be a string or an array' );
262  }
263 
264  $this->keysToTry = (array)$key;
265 
266  if ( empty( $this->keysToTry ) ) {
267  throw new InvalidArgumentException( '$key must not be an empty list' );
268  }
269 
270  $this->key = reset( $this->keysToTry );
271 
272  $this->parameters = array_values( $params );
273  // User language is only resolved in getLanguage(). This helps preserve the
274  // semantic intent of "user language" across serialize() and unserialize().
275  $this->language = $language ?: false;
276  }
277 
283  public function serialize() {
284  return serialize( [
285  'interface' => $this->interface,
286  'language' => $this->language ? $this->language->getCode() : false,
287  'key' => $this->key,
288  'keysToTry' => $this->keysToTry,
289  'parameters' => $this->parameters,
290  'format' => $this->format,
291  'useDatabase' => $this->useDatabase,
292  'titlestr' => $this->title ? $this->title->getFullText() : null,
293  ] );
294  }
295 
301  public function unserialize( $serialized ) {
302  $data = unserialize( $serialized );
303  if ( !is_array( $data ) ) {
304  throw new InvalidArgumentException( __METHOD__ . ': Invalid serialized data' );
305  }
306 
307  $this->interface = $data['interface'];
308  $this->key = $data['key'];
309  $this->keysToTry = $data['keysToTry'];
310  $this->parameters = $data['parameters'];
311  $this->format = $data['format'];
312  $this->useDatabase = $data['useDatabase'];
313  $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
314 
315  if ( isset( $data['titlestr'] ) ) {
316  $this->title = Title::newFromText( $data['titlestr'] );
317  } elseif ( isset( $data['title'] ) && $data['title'] instanceof Title ) {
318  // Old serializations from before December 2018
319  $this->title = $data['title'];
320  } else {
321  $this->title = null; // Explicit for sanity
322  }
323  }
324 
331  public function isMultiKey() {
332  return count( $this->keysToTry ) > 1;
333  }
334 
341  public function getKeysToTry() {
342  return $this->keysToTry;
343  }
344 
356  public function getKey() {
357  return $this->key;
358  }
359 
367  public function getParams() {
368  return $this->parameters;
369  }
370 
379  public function getFormat() {
380  wfDeprecated( __METHOD__, '1.29' );
381  return $this->format;
382  }
383 
391  public function getLanguage() {
392  // Defaults to false which means current user language
393  return $this->language ?: RequestContext::getMain()->getLanguage();
394  }
395 
408  public static function newFromKey( $key /*...*/ ) {
409  $params = func_get_args();
410  array_shift( $params );
411  return new self( $key, $params );
412  }
413 
427  public static function newFromSpecifier( $value ) {
428  $params = [];
429  if ( is_array( $value ) ) {
430  $params = $value;
431  $value = array_shift( $params );
432  }
433 
434  if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
435  $message = clone $value;
436  } elseif ( $value instanceof MessageSpecifier ) {
437  $message = new Message( $value );
438  } elseif ( is_string( $value ) ) {
439  $message = new Message( $value, $params );
440  } else {
441  throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
442  . gettype( $value ) );
443  }
444 
445  return $message;
446  }
447 
460  public static function newFallbackSequence( /*...*/ ) {
461  $keys = func_get_args();
462  if ( func_num_args() == 1 ) {
463  if ( is_array( $keys[0] ) ) {
464  // Allow an array to be passed as the first argument instead
465  $keys = array_values( $keys[0] );
466  } else {
467  // Optimize a single string to not need special fallback handling
468  $keys = $keys[0];
469  }
470  }
471  return new self( $keys );
472  }
473 
484  public function getTitle() {
486 
487  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
488  $lang = $this->getLanguage();
489  $title = $this->key;
490  if (
491  !$lang->equals( $contLang )
492  && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
493  ) {
494  $title .= '/' . $lang->getCode();
495  }
496 
497  return Title::makeTitle(
498  NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
499  }
500 
511  public function params( /*...*/ ) {
512  $args = func_get_args();
513 
514  // If $args has only one entry and it's an array, then it's either a
515  // non-varargs call or it happens to be a call with just a single
516  // "special" parameter. Since the "special" parameters don't have any
517  // numeric keys, we'll test that to differentiate the cases.
518  if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
519  if ( $args[0] === [] ) {
520  $args = [];
521  } else {
522  foreach ( $args[0] as $key => $value ) {
523  if ( is_int( $key ) ) {
524  $args = $args[0];
525  break;
526  }
527  }
528  }
529  }
530 
531  $this->parameters = array_merge( $this->parameters, array_values( $args ) );
532  return $this;
533  }
534 
548  public function rawParams( /*...*/ ) {
549  $params = func_get_args();
550  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
551  $params = $params[0];
552  }
553  foreach ( $params as $param ) {
554  $this->parameters[] = self::rawParam( $param );
555  }
556  return $this;
557  }
558 
570  public function numParams( /*...*/ ) {
571  $params = func_get_args();
572  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
573  $params = $params[0];
574  }
575  foreach ( $params as $param ) {
576  $this->parameters[] = self::numParam( $param );
577  }
578  return $this;
579  }
580 
592  public function durationParams( /*...*/ ) {
593  $params = func_get_args();
594  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
595  $params = $params[0];
596  }
597  foreach ( $params as $param ) {
598  $this->parameters[] = self::durationParam( $param );
599  }
600  return $this;
601  }
602 
614  public function expiryParams( /*...*/ ) {
615  $params = func_get_args();
616  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
617  $params = $params[0];
618  }
619  foreach ( $params as $param ) {
620  $this->parameters[] = self::expiryParam( $param );
621  }
622  return $this;
623  }
624 
636  public function timeperiodParams( /*...*/ ) {
637  $params = func_get_args();
638  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
639  $params = $params[0];
640  }
641  foreach ( $params as $param ) {
642  $this->parameters[] = self::timeperiodParam( $param );
643  }
644  return $this;
645  }
646 
658  public function sizeParams( /*...*/ ) {
659  $params = func_get_args();
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( /*...*/ ) {
681  $params = func_get_args();
682  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
683  $params = $params[0];
684  }
685  foreach ( $params as $param ) {
686  $this->parameters[] = self::bitrateParam( $param );
687  }
688  return $this;
689  }
690 
704  public function plaintextParams( /*...*/ ) {
705  $params = func_get_args();
706  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
707  $params = $params[0];
708  }
709  foreach ( $params as $param ) {
710  $this->parameters[] = self::plaintextParam( $param );
711  }
712  return $this;
713  }
714 
724  public function setContext( IContextSource $context ) {
725  $this->inLanguage( $context->getLanguage() );
726  $this->title( $context->getTitle() );
727  $this->interface = true;
728 
729  return $this;
730  }
731 
743  public function inLanguage( $lang ) {
744  $previousLanguage = $this->language;
745 
746  if ( $lang instanceof Language ) {
747  $this->language = $lang;
748  } elseif ( is_string( $lang ) ) {
749  if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
750  $this->language = Language::factory( $lang );
751  }
752  } elseif ( $lang instanceof StubUserLang ) {
753  $this->language = false;
754  } else {
755  $type = gettype( $lang );
756  throw new MWException( __METHOD__ . " must be "
757  . "passed a String or Language object; $type given"
758  );
759  }
760 
761  if ( $this->language !== $previousLanguage ) {
762  // The language has changed. Clear the message cache.
763  $this->message = null;
764  }
765  $this->interface = false;
766  return $this;
767  }
768 
778  public function inContentLanguage() {
780  if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
781  return $this;
782  }
783 
784  $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
785  return $this;
786  }
787 
798  public function setInterfaceMessageFlag( $interface ) {
799  $this->interface = (bool)$interface;
800  return $this;
801  }
802 
812  public function useDatabase( $useDatabase ) {
813  $this->useDatabase = (bool)$useDatabase;
814  $this->message = null;
815  return $this;
816  }
817 
827  public function title( $title ) {
828  $this->title = $title;
829  return $this;
830  }
831 
837  public function content() {
838  if ( !$this->content ) {
839  $this->content = new MessageContent( $this );
840  }
841 
842  return $this->content;
843  }
844 
856  public function toString( $format = null ) {
857  if ( $format === null ) {
858  $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
859  \MediaWiki\Logger\LoggerFactory::getInstance( 'message-format' )->warning(
860  $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
862  }
863  $string = $this->fetchMessage();
864 
865  if ( $string === false ) {
866  // Err on the side of safety, ensure that the output
867  // is always html safe in the event the message key is
868  // missing, since in that case its highly likely the
869  // message key is user-controlled.
870  // '⧼' is used instead of '<' to side-step any
871  // double-escaping issues.
872  // (Keep synchronised with mw.Message#toString in JS.)
873  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
874  }
875 
876  # Replace $* with a list of parameters for &uselang=qqx.
877  if ( strpos( $string, '$*' ) !== false ) {
878  $paramlist = '';
879  if ( $this->parameters !== [] ) {
880  $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
881  }
882  $string = str_replace( '$*', $paramlist, $string );
883  }
884 
885  # Replace parameters before text parsing
886  $string = $this->replaceParameters( $string, 'before', $format );
887 
888  # Maybe transform using the full parser
889  if ( $format === self::FORMAT_PARSE ) {
890  $string = $this->parseText( $string );
891  $string = Parser::stripOuterParagraph( $string );
892  } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
893  $string = $this->parseText( $string );
894  } elseif ( $format === self::FORMAT_TEXT ) {
895  $string = $this->transformText( $string );
896  } elseif ( $format === self::FORMAT_ESCAPED ) {
897  $string = $this->transformText( $string );
898  $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
899  }
900 
901  # Raw parameter replacement
902  $string = $this->replaceParameters( $string, 'after', $format );
903 
904  return $string;
905  }
906 
916  public function __toString() {
917  // PHP doesn't allow __toString to throw exceptions and will
918  // trigger a fatal error if it does. So, catch any exceptions.
919 
920  try {
921  return $this->toString( self::FORMAT_PARSE );
922  } catch ( Exception $ex ) {
923  try {
924  trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
925  . $ex, E_USER_WARNING );
926  } catch ( Exception $ex ) {
927  // Doh! Cause a fatal error after all?
928  }
929 
930  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
931  }
932  }
933 
941  public function parse() {
942  $this->format = self::FORMAT_PARSE;
943  return $this->toString( self::FORMAT_PARSE );
944  }
945 
953  public function text() {
954  $this->format = self::FORMAT_TEXT;
955  return $this->toString( self::FORMAT_TEXT );
956  }
957 
965  public function plain() {
966  $this->format = self::FORMAT_PLAIN;
967  return $this->toString( self::FORMAT_PLAIN );
968  }
969 
977  public function parseAsBlock() {
978  $this->format = self::FORMAT_BLOCK_PARSE;
979  return $this->toString( self::FORMAT_BLOCK_PARSE );
980  }
981 
990  public function escaped() {
991  $this->format = self::FORMAT_ESCAPED;
992  return $this->toString( self::FORMAT_ESCAPED );
993  }
994 
1002  public function exists() {
1003  return $this->fetchMessage() !== false;
1004  }
1005 
1014  public function isBlank() {
1015  $message = $this->fetchMessage();
1016  return $message === false || $message === '';
1017  }
1018 
1026  public function isDisabled() {
1027  $message = $this->fetchMessage();
1028  return $message === false || $message === '' || $message === '-';
1029  }
1030 
1038  public static function rawParam( $raw ) {
1039  return [ 'raw' => $raw ];
1040  }
1041 
1049  public static function numParam( $num ) {
1050  return [ 'num' => $num ];
1051  }
1052 
1060  public static function durationParam( $duration ) {
1061  return [ 'duration' => $duration ];
1062  }
1063 
1071  public static function expiryParam( $expiry ) {
1072  return [ 'expiry' => $expiry ];
1073  }
1074 
1082  public static function timeperiodParam( $period ) {
1083  return [ 'period' => $period ];
1084  }
1085 
1093  public static function sizeParam( $size ) {
1094  return [ 'size' => $size ];
1095  }
1096 
1104  public static function bitrateParam( $bitrate ) {
1105  return [ 'bitrate' => $bitrate ];
1106  }
1107 
1115  public static function plaintextParam( $plaintext ) {
1116  return [ 'plaintext' => $plaintext ];
1117  }
1118 
1126  public static function listParam( array $list, $type = 'text' ) {
1127  if ( !isset( self::$listTypeMap[$type] ) ) {
1128  throw new InvalidArgumentException(
1129  "Invalid type '$type'. Known types are: " . implode( ', ', array_keys( self::$listTypeMap ) )
1130  );
1131  }
1132  return [ 'list' => $list, 'type' => $type ];
1133  }
1134 
1146  protected function replaceParameters( $message, $type, $format ) {
1147  // A temporary marker for $1 parameters that is only valid
1148  // in non-attribute contexts. However if the entire message is escaped
1149  // then we don't want to use it because it will be mangled in all contexts
1150  // and its unnessary as ->escaped() messages aren't html.
1151  $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1152  $replacementKeys = [];
1153  foreach ( $this->parameters as $n => $param ) {
1154  list( $paramType, $value ) = $this->extractParam( $param, $format );
1155  if ( $type === 'before' ) {
1156  if ( $paramType === 'before' ) {
1157  $replacementKeys['$' . ( $n + 1 )] = $value;
1158  } else /* $paramType === 'after' */ {
1159  // To protect against XSS from replacing parameters
1160  // inside html attributes, we convert $1 to $'"1.
1161  // In the event that one of the parameters ends up
1162  // in an attribute, either the ' or the " will be
1163  // escaped, breaking the replacement and avoiding XSS.
1164  $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1165  }
1166  } elseif ( $paramType === 'after' ) {
1167  $replacementKeys[$marker . ( $n + 1 )] = $value;
1168  }
1169  }
1170  return strtr( $message, $replacementKeys );
1171  }
1172 
1183  protected function extractParam( $param, $format ) {
1184  if ( is_array( $param ) ) {
1185  if ( isset( $param['raw'] ) ) {
1186  return [ 'after', $param['raw'] ];
1187  } elseif ( isset( $param['num'] ) ) {
1188  // Replace number params always in before step for now.
1189  // No support for combined raw and num params
1190  return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1191  } elseif ( isset( $param['duration'] ) ) {
1192  return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1193  } elseif ( isset( $param['expiry'] ) ) {
1194  return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1195  } elseif ( isset( $param['period'] ) ) {
1196  return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1197  } elseif ( isset( $param['size'] ) ) {
1198  return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1199  } elseif ( isset( $param['bitrate'] ) ) {
1200  return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1201  } elseif ( isset( $param['plaintext'] ) ) {
1202  return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1203  } elseif ( isset( $param['list'] ) ) {
1204  return $this->formatListParam( $param['list'], $param['type'], $format );
1205  } else {
1206  if ( !is_scalar( $param ) ) {
1207  $param = serialize( $param );
1208  }
1209  \MediaWiki\Logger\LoggerFactory::getInstance( 'Bug58676' )->warning(
1210  'Invalid parameter for message "{msgkey}": {param}',
1211  [
1212  'exception' => new Exception,
1213  'msgkey' => $this->getKey(),
1214  'param' => htmlspecialchars( $param ),
1215  ]
1216  );
1217 
1218  return [ 'before', '[INVALID]' ];
1219  }
1220  } elseif ( $param instanceof Message ) {
1221  // Match language, flags, etc. to the current message.
1222  $msg = clone $param;
1223  if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1224  // Cache depends on these parameters
1225  $msg->message = null;
1226  }
1227  $msg->interface = $this->interface;
1228  $msg->language = $this->language;
1229  $msg->useDatabase = $this->useDatabase;
1230  $msg->title = $this->title;
1231 
1232  // DWIM
1233  if ( $format === 'block-parse' ) {
1234  $format = 'parse';
1235  }
1236  $msg->format = $format;
1237 
1238  // Message objects should not be before parameters because
1239  // then they'll get double escaped. If the message needs to be
1240  // escaped, it'll happen right here when we call toString().
1241  return [ 'after', $msg->toString( $format ) ];
1242  } else {
1243  return [ 'before', $param ];
1244  }
1245  }
1246 
1256  protected function parseText( $string ) {
1257  $out = MessageCache::singleton()->parse(
1258  $string,
1259  $this->title,
1260  /*linestart*/true,
1261  $this->interface,
1262  $this->getLanguage()
1263  );
1264 
1265  return $out instanceof ParserOutput
1266  ? $out->getText( [
1267  'enableSectionEditLinks' => false,
1268  // Wrapping messages in an extra <div> is probably not expected. If
1269  // they're outside the content area they probably shouldn't be
1270  // targeted by CSS that's targeting the parser output, and if
1271  // they're inside they already are from the outer div.
1272  'unwrap' => true,
1273  ] )
1274  : $out;
1275  }
1276 
1286  protected function transformText( $string ) {
1287  return MessageCache::singleton()->transform(
1288  $string,
1289  $this->interface,
1290  $this->getLanguage(),
1291  $this->title
1292  );
1293  }
1294 
1303  protected function fetchMessage() {
1304  if ( $this->message === null ) {
1306 
1307  foreach ( $this->keysToTry as $key ) {
1308  $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1309  if ( $message !== false && $message !== '' ) {
1310  break;
1311  }
1312  }
1313 
1314  // NOTE: The constructor makes sure keysToTry isn't empty,
1315  // so we know that $key and $message are initialized.
1316  $this->key = $key;
1317  $this->message = $message;
1318  }
1319  return $this->message;
1320  }
1321 
1334  protected function formatPlaintext( $plaintext, $format ) {
1335  switch ( $format ) {
1336  case self::FORMAT_TEXT:
1337  case self::FORMAT_PLAIN:
1338  return $plaintext;
1339 
1340  case self::FORMAT_PARSE:
1341  case self::FORMAT_BLOCK_PARSE:
1342  case self::FORMAT_ESCAPED:
1343  default:
1344  return htmlspecialchars( $plaintext, ENT_QUOTES );
1345  }
1346  }
1347 
1356  protected function formatListParam( array $params, $listType, $format ) {
1357  if ( !isset( self::$listTypeMap[$listType] ) ) {
1358  $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1359  . htmlspecialchars( $listType )
1360  . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1361  trigger_error( $warning, E_USER_WARNING );
1362  $e = new Exception;
1363  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1364  return [ 'before', '[INVALID]' ];
1365  }
1366  $func = self::$listTypeMap[$listType];
1367 
1368  // Handle an empty list sensibly
1369  if ( !$params ) {
1370  return [ 'before', $this->getLanguage()->$func( [] ) ];
1371  }
1372 
1373  // First, determine what kinds of list items we have
1374  $types = [];
1375  $vars = [];
1376  $list = [];
1377  foreach ( $params as $n => $p ) {
1378  list( $type, $value ) = $this->extractParam( $p, $format );
1379  $types[$type] = true;
1380  $list[] = $value;
1381  $vars[] = '$' . ( $n + 1 );
1382  }
1383 
1384  // Easy case: all are 'before' or 'after', so just join the
1385  // values and use the same type.
1386  if ( count( $types ) === 1 ) {
1387  return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1388  }
1389 
1390  // Hard case: We need to process each value per its type, then
1391  // return the concatenated values as 'after'. We handle this by turning
1392  // the list into a RawMessage and processing that as a parameter.
1393  $vars = $this->getLanguage()->$func( $vars );
1394  return $this->extractParam( new RawMessage( $vars, $params ), $format );
1395  }
1396 }
getKeysToTry()
Definition: Message.php:341
getKey()
Returns the message key.
Definition: Message.php:356
static rawParam( $raw)
Definition: Message.php:1038
string [] $keysToTry
List of keys to try when fetching the message.
Definition: Message.php:207
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
static array bool $interface
In which language to get this message.
Definition: Message.php:189
isBlank()
Check whether a message does not exist, or is an empty string.
Definition: Message.php:1014
durationParams()
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
Definition: Message.php:592
bool $useDatabase
Whether database can be used.
Definition: Message.php:223
Content $content
Content object representing the message.
Definition: Message.php:233
Title $title
Title object to use as context.
Definition: Message.php:228
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
rawParams()
Add parameters that are substituted after parsing or escaping.
Definition: Message.php:548
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
unserialize( $serialized)
Definition: Message.php:301
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2159
string $format
Definition: Message.php:218
Wrapper allowing us to handle a system message as a Content object.
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition: Message.php:1356
const FORMAT_PLAIN
Use message text as-is.
Definition: Message.php:162
if(!isset( $args[0])) $lang
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag) ...
Definition: Message.php:164
Language bool $language
In which language to get this message.
Definition: Message.php:196
$value
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
Definition: hooks.txt:2151
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
text()
Returns the message text.
Definition: Message.php:953
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
Definition: Message.php:166
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
Definition: Message.php:977
getFormat()
Returns the message format.
Definition: Message.php:379
static numParam( $num)
Definition: Message.php:1049
content()
Returns the message as a Content object.
Definition: Message.php:837
static bitrateParam( $bitrate)
Definition: Message.php:1104
if( $line===false) $args
Definition: cdb.php:64
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6408
useDatabase( $useDatabase)
Enable or disable database use.
Definition: Message.php:812
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1982
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition: Message.php:176
getParams()
Returns the message parameters.
Definition: Message.php:367
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition: Message.php:1286
static getMain()
Get the RequestContext object associated with the main request.
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition: Message.php:798
isMultiKey()
Definition: Message.php:331
const FORMAT_TEXT
Transform {{..}} constructs but don&#39;t transform to HTML.
Definition: Message.php:168
timeperiodParams()
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition: Message.php:636
expiryParams()
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition: Message.php:614
static newFallbackSequence()
Factory function accepting multiple message keys and returning a message instance for the first messa...
Definition: Message.php:460
serialize()
Definition: Message.php:283
$cache
Definition: mcc.php:33
$params
string $key
The message key.
Definition: Message.php:202
array $parameters
List of parameters which will be substituted into the message.
Definition: Message.php:212
static newFromKey( $key)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:408
params()
Adds parameters to the parameter list of this message.
Definition: Message.php:511
static durationParam( $duration)
Definition: Message.php:1060
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
setContext(IContextSource $context)
Set the language and the title from a context object.
Definition: Message.php:724
toString( $format=null)
Returns the message parsed from wikitext to HTML.
Definition: Message.php:856
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:216
getLanguage()
Returns the Language of the Message.
Definition: Message.php:391
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:743
parse()
Fully parse the text from wikitext to HTML.
Definition: Message.php:941
const NS_MEDIAWIKI
Definition: Defines.php:68
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
title( $title)
Set the Title object to use as context when transforming the message.
Definition: Message.php:827
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with &#39;plaintext&#39;.
Definition: Message.php:1334
exists()
Check whether a message key has been defined currently.
Definition: Message.php:1002
numParams()
Add parameters that are numeric and will be passed through Language::formatNum before substitution...
Definition: Message.php:570
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:427
sizeParams()
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
Definition: Message.php:658
Variant of the Message class.
Definition: RawMessage.php:34
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
__toString()
Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg: $foo = new Message( $k...
Definition: Message.php:916
Stub object for the user language.
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace...
Definition: Message.php:484
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition: Message.php:1146
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a message
Definition: hooks.txt:2151
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition: Message.php:1183
plaintextParams()
Add parameters that are plaintext and will be passed through without the content being evaluated...
Definition: Message.php:704
bitrateParams()
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition: Message.php:680
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2633
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
Definition: Message.php:1256
plain()
Returns the message text as-is, only parameters are substituted.
Definition: Message.php:965
inContentLanguage()
Request the message in the wiki&#39;s content language, unless it is disabled for this message...
Definition: Message.php:778
fetchMessage()
Wrapper for what ever method we use to get message contents.
Definition: Message.php:1303
escaped()
Returns the message text.
Definition: Message.php:990
string $message
Definition: Message.php:238
static timeperiodParam( $period)
Definition: Message.php:1082
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
Definition: Message.php:170
foreach( $res as $row) $serialized
static sizeParam( $size)
Definition: Message.php:1093
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2217
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
Definition: Message.php:1026
static plaintextParam( $plaintext)
Definition: Message.php:1115
static singleton()
Get the signleton instance of this class.
static listParam(array $list, $type='text')
Definition: Message.php:1126
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1641
__construct( $key, $params=[], Language $language=null)
Definition: Message.php:249
static expiryParam( $expiry)
Definition: Message.php:1071
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319