MediaWiki  1.30.0
Message.php
Go to the documentation of this file.
1 <?php
159 class Message implements MessageSpecifier, Serializable {
161  const FORMAT_PLAIN = 'plain';
163  const FORMAT_BLOCK_PARSE = 'block-parse';
165  const FORMAT_PARSE = 'parse';
167  const FORMAT_TEXT = 'text';
169  const FORMAT_ESCAPED = 'escaped';
170 
175  protected static $listTypeMap = [
176  'comma' => 'commaList',
177  'semicolon' => 'semicolonList',
178  'pipe' => 'pipeList',
179  'text' => 'listToText',
180  ];
181 
188  protected $interface = true;
189 
195  protected $language = false;
196 
201  protected $key;
202 
206  protected $keysToTry;
207 
211  protected $parameters = [];
212 
217  protected $format = 'parse';
218 
222  protected $useDatabase = true;
223 
227  protected $title = null;
228 
232  protected $content = null;
233 
237  protected $message;
238 
248  public function __construct( $key, $params = [], Language $language = null ) {
249  if ( $key instanceof MessageSpecifier ) {
250  if ( $params ) {
251  throw new InvalidArgumentException(
252  '$params must be empty if $key is a MessageSpecifier'
253  );
254  }
255  $params = $key->getParams();
256  $key = $key->getKey();
257  }
258 
259  if ( !is_string( $key ) && !is_array( $key ) ) {
260  throw new InvalidArgumentException( '$key must be a string or an array' );
261  }
262 
263  $this->keysToTry = (array)$key;
264 
265  if ( empty( $this->keysToTry ) ) {
266  throw new InvalidArgumentException( '$key must not be an empty list' );
267  }
268 
269  $this->key = reset( $this->keysToTry );
270 
271  $this->parameters = array_values( $params );
272  // User language is only resolved in getLanguage(). This helps preserve the
273  // semantic intent of "user language" across serialize() and unserialize().
274  $this->language = $language ?: false;
275  }
276 
282  public function serialize() {
283  return serialize( [
284  'interface' => $this->interface,
285  'language' => $this->language ? $this->language->getCode() : false,
286  'key' => $this->key,
287  'keysToTry' => $this->keysToTry,
288  'parameters' => $this->parameters,
289  'format' => $this->format,
290  'useDatabase' => $this->useDatabase,
291  'title' => $this->title,
292  ] );
293  }
294 
300  public function unserialize( $serialized ) {
301  $data = unserialize( $serialized );
302  $this->interface = $data['interface'];
303  $this->key = $data['key'];
304  $this->keysToTry = $data['keysToTry'];
305  $this->parameters = $data['parameters'];
306  $this->format = $data['format'];
307  $this->useDatabase = $data['useDatabase'];
308  $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
309  $this->title = $data['title'];
310  }
311 
318  public function isMultiKey() {
319  return count( $this->keysToTry ) > 1;
320  }
321 
328  public function getKeysToTry() {
329  return $this->keysToTry;
330  }
331 
343  public function getKey() {
344  return $this->key;
345  }
346 
354  public function getParams() {
355  return $this->parameters;
356  }
357 
366  public function getFormat() {
367  wfDeprecated( __METHOD__, '1.29' );
368  return $this->format;
369  }
370 
378  public function getLanguage() {
379  // Defaults to false which means current user language
380  return $this->language ?: RequestContext::getMain()->getLanguage();
381  }
382 
395  public static function newFromKey( $key /*...*/ ) {
396  $params = func_get_args();
397  array_shift( $params );
398  return new self( $key, $params );
399  }
400 
414  public static function newFromSpecifier( $value ) {
415  $params = [];
416  if ( is_array( $value ) ) {
417  $params = $value;
418  $value = array_shift( $params );
419  }
420 
421  if ( $value instanceof Message ) { // Message, RawMessage, ApiMessage, etc
422  $message = clone $value;
423  } elseif ( $value instanceof MessageSpecifier ) {
424  $message = new Message( $value );
425  } elseif ( is_string( $value ) ) {
426  $message = new Message( $value, $params );
427  } else {
428  throw new InvalidArgumentException( __METHOD__ . ': invalid argument type '
429  . gettype( $value ) );
430  }
431 
432  return $message;
433  }
434 
447  public static function newFallbackSequence( /*...*/ ) {
448  $keys = func_get_args();
449  if ( func_num_args() == 1 ) {
450  if ( is_array( $keys[0] ) ) {
451  // Allow an array to be passed as the first argument instead
452  $keys = array_values( $keys[0] );
453  } else {
454  // Optimize a single string to not need special fallback handling
455  $keys = $keys[0];
456  }
457  }
458  return new self( $keys );
459  }
460 
471  public function getTitle() {
473 
474  $title = $this->key;
475  if (
476  !$this->language->equals( $wgContLang )
477  && in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
478  ) {
479  $code = $this->language->getCode();
480  $title .= '/' . $code;
481  }
482 
483  return Title::makeTitle( NS_MEDIAWIKI, $wgContLang->ucfirst( strtr( $title, ' ', '_' ) ) );
484  }
485 
496  public function params( /*...*/ ) {
497  $args = func_get_args();
498 
499  // If $args has only one entry and it's an array, then it's either a
500  // non-varargs call or it happens to be a call with just a single
501  // "special" parameter. Since the "special" parameters don't have any
502  // numeric keys, we'll test that to differentiate the cases.
503  if ( count( $args ) === 1 && isset( $args[0] ) && is_array( $args[0] ) ) {
504  if ( $args[0] === [] ) {
505  $args = [];
506  } else {
507  foreach ( $args[0] as $key => $value ) {
508  if ( is_int( $key ) ) {
509  $args = $args[0];
510  break;
511  }
512  }
513  }
514  }
515 
516  $this->parameters = array_merge( $this->parameters, array_values( $args ) );
517  return $this;
518  }
519 
533  public function rawParams( /*...*/ ) {
534  $params = func_get_args();
535  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
536  $params = $params[0];
537  }
538  foreach ( $params as $param ) {
539  $this->parameters[] = self::rawParam( $param );
540  }
541  return $this;
542  }
543 
555  public function numParams( /*...*/ ) {
556  $params = func_get_args();
557  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
558  $params = $params[0];
559  }
560  foreach ( $params as $param ) {
561  $this->parameters[] = self::numParam( $param );
562  }
563  return $this;
564  }
565 
577  public function durationParams( /*...*/ ) {
578  $params = func_get_args();
579  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
580  $params = $params[0];
581  }
582  foreach ( $params as $param ) {
583  $this->parameters[] = self::durationParam( $param );
584  }
585  return $this;
586  }
587 
599  public function expiryParams( /*...*/ ) {
600  $params = func_get_args();
601  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
602  $params = $params[0];
603  }
604  foreach ( $params as $param ) {
605  $this->parameters[] = self::expiryParam( $param );
606  }
607  return $this;
608  }
609 
621  public function timeperiodParams( /*...*/ ) {
622  $params = func_get_args();
623  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
624  $params = $params[0];
625  }
626  foreach ( $params as $param ) {
627  $this->parameters[] = self::timeperiodParam( $param );
628  }
629  return $this;
630  }
631 
643  public function sizeParams( /*...*/ ) {
644  $params = func_get_args();
645  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
646  $params = $params[0];
647  }
648  foreach ( $params as $param ) {
649  $this->parameters[] = self::sizeParam( $param );
650  }
651  return $this;
652  }
653 
665  public function bitrateParams( /*...*/ ) {
666  $params = func_get_args();
667  if ( isset( $params[0] ) && is_array( $params[0] ) ) {
668  $params = $params[0];
669  }
670  foreach ( $params as $param ) {
671  $this->parameters[] = self::bitrateParam( $param );
672  }
673  return $this;
674  }
675 
689  public function plaintextParams( /*...*/ ) {
690  $params = func_get_args();
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  if ( $lang instanceof Language ) {
730  $this->language = $lang;
731  } elseif ( is_string( $lang ) ) {
732  if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
733  $this->language = Language::factory( $lang );
734  }
735  } elseif ( $lang instanceof StubUserLang ) {
736  $this->language = false;
737  } else {
738  $type = gettype( $lang );
739  throw new MWException( __METHOD__ . " must be "
740  . "passed a String or Language object; $type given"
741  );
742  }
743  $this->message = null;
744  $this->interface = false;
745  return $this;
746  }
747 
757  public function inContentLanguage() {
759  if ( in_array( $this->key, (array)$wgForceUIMsgAsContentMsg ) ) {
760  return $this;
761  }
762 
764  $this->inLanguage( $wgContLang );
765  return $this;
766  }
767 
778  public function setInterfaceMessageFlag( $interface ) {
779  $this->interface = (bool)$interface;
780  return $this;
781  }
782 
792  public function useDatabase( $useDatabase ) {
793  $this->useDatabase = (bool)$useDatabase;
794  $this->message = null;
795  return $this;
796  }
797 
807  public function title( $title ) {
808  $this->title = $title;
809  return $this;
810  }
811 
817  public function content() {
818  if ( !$this->content ) {
819  $this->content = new MessageContent( $this );
820  }
821 
822  return $this->content;
823  }
824 
835  public function toString( $format = null ) {
836  if ( $format === null ) {
837  $ex = new LogicException( __METHOD__ . ' using implicit format: ' . $this->format );
838  \MediaWiki\Logger\LoggerFactory::getInstance( 'message-format' )->warning(
839  $ex->getMessage(), [ 'exception' => $ex, 'format' => $this->format, 'key' => $this->key ] );
840  $format = $this->format;
841  }
842  $string = $this->fetchMessage();
843 
844  if ( $string === false ) {
845  // Err on the side of safety, ensure that the output
846  // is always html safe in the event the message key is
847  // missing, since in that case its highly likely the
848  // message key is user-controlled.
849  // '⧼' is used instead of '<' to side-step any
850  // double-escaping issues.
851  // (Keep synchronised with mw.Message#toString in JS.)
852  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
853  }
854 
855  # Replace $* with a list of parameters for &uselang=qqx.
856  if ( strpos( $string, '$*' ) !== false ) {
857  $paramlist = '';
858  if ( $this->parameters !== [] ) {
859  $paramlist = ': $' . implode( ', $', range( 1, count( $this->parameters ) ) );
860  }
861  $string = str_replace( '$*', $paramlist, $string );
862  }
863 
864  # Replace parameters before text parsing
865  $string = $this->replaceParameters( $string, 'before', $format );
866 
867  # Maybe transform using the full parser
868  if ( $format === self::FORMAT_PARSE ) {
869  $string = $this->parseText( $string );
870  $string = Parser::stripOuterParagraph( $string );
871  } elseif ( $format === self::FORMAT_BLOCK_PARSE ) {
872  $string = $this->parseText( $string );
873  } elseif ( $format === self::FORMAT_TEXT ) {
874  $string = $this->transformText( $string );
875  } elseif ( $format === self::FORMAT_ESCAPED ) {
876  $string = $this->transformText( $string );
877  $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
878  }
879 
880  # Raw parameter replacement
881  $string = $this->replaceParameters( $string, 'after', $format );
882 
883  return $string;
884  }
885 
895  public function __toString() {
896  // PHP doesn't allow __toString to throw exceptions and will
897  // trigger a fatal error if it does. So, catch any exceptions.
898 
899  try {
900  return $this->toString( self::FORMAT_PARSE );
901  } catch ( Exception $ex ) {
902  try {
903  trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
904  . $ex, E_USER_WARNING );
905  } catch ( Exception $ex ) {
906  // Doh! Cause a fatal error after all?
907  }
908 
909  return '⧼' . htmlspecialchars( $this->key ) . '⧽';
910  }
911  }
912 
920  public function parse() {
921  $this->format = self::FORMAT_PARSE;
922  return $this->toString( self::FORMAT_PARSE );
923  }
924 
932  public function text() {
933  $this->format = self::FORMAT_TEXT;
934  return $this->toString( self::FORMAT_TEXT );
935  }
936 
944  public function plain() {
945  $this->format = self::FORMAT_PLAIN;
946  return $this->toString( self::FORMAT_PLAIN );
947  }
948 
956  public function parseAsBlock() {
957  $this->format = self::FORMAT_BLOCK_PARSE;
958  return $this->toString( self::FORMAT_BLOCK_PARSE );
959  }
960 
969  public function escaped() {
970  $this->format = self::FORMAT_ESCAPED;
971  return $this->toString( self::FORMAT_ESCAPED );
972  }
973 
981  public function exists() {
982  return $this->fetchMessage() !== false;
983  }
984 
993  public function isBlank() {
994  $message = $this->fetchMessage();
995  return $message === false || $message === '';
996  }
997 
1005  public function isDisabled() {
1006  $message = $this->fetchMessage();
1007  return $message === false || $message === '' || $message === '-';
1008  }
1009 
1017  public static function rawParam( $raw ) {
1018  return [ 'raw' => $raw ];
1019  }
1020 
1028  public static function numParam( $num ) {
1029  return [ 'num' => $num ];
1030  }
1031 
1039  public static function durationParam( $duration ) {
1040  return [ 'duration' => $duration ];
1041  }
1042 
1050  public static function expiryParam( $expiry ) {
1051  return [ 'expiry' => $expiry ];
1052  }
1053 
1061  public static function timeperiodParam( $period ) {
1062  return [ 'period' => $period ];
1063  }
1064 
1072  public static function sizeParam( $size ) {
1073  return [ 'size' => $size ];
1074  }
1075 
1083  public static function bitrateParam( $bitrate ) {
1084  return [ 'bitrate' => $bitrate ];
1085  }
1086 
1094  public static function plaintextParam( $plaintext ) {
1095  return [ 'plaintext' => $plaintext ];
1096  }
1097 
1105  public static function listParam( array $list, $type = 'text' ) {
1106  if ( !isset( self::$listTypeMap[$type] ) ) {
1107  throw new InvalidArgumentException(
1108  "Invalid type '$type'. Known types are: " . join( ', ', array_keys( self::$listTypeMap ) )
1109  );
1110  }
1111  return [ 'list' => $list, 'type' => $type ];
1112  }
1113 
1125  protected function replaceParameters( $message, $type = 'before', $format ) {
1126  // A temporary marker for $1 parameters that is only valid
1127  // in non-attribute contexts. However if the entire message is escaped
1128  // then we don't want to use it because it will be mangled in all contexts
1129  // and its unnessary as ->escaped() messages aren't html.
1130  $marker = $format === self::FORMAT_ESCAPED ? '$' : '$\'"';
1131  $replacementKeys = [];
1132  foreach ( $this->parameters as $n => $param ) {
1133  list( $paramType, $value ) = $this->extractParam( $param, $format );
1134  if ( $type === 'before' ) {
1135  if ( $paramType === 'before' ) {
1136  $replacementKeys['$' . ( $n + 1 )] = $value;
1137  } else /* $paramType === 'after' */ {
1138  // To protect against XSS from replacing parameters
1139  // inside html attributes, we convert $1 to $'"1.
1140  // In the event that one of the parameters ends up
1141  // in an attribute, either the ' or the " will be
1142  // escaped, breaking the replacement and avoiding XSS.
1143  $replacementKeys['$' . ( $n + 1 )] = $marker . ( $n + 1 );
1144  }
1145  } else {
1146  if ( $paramType === 'after' ) {
1147  $replacementKeys[$marker . ( $n + 1 )] = $value;
1148  }
1149  }
1150  }
1151  $message = strtr( $message, $replacementKeys );
1152  return $message;
1153  }
1154 
1165  protected function extractParam( $param, $format ) {
1166  if ( is_array( $param ) ) {
1167  if ( isset( $param['raw'] ) ) {
1168  return [ 'after', $param['raw'] ];
1169  } elseif ( isset( $param['num'] ) ) {
1170  // Replace number params always in before step for now.
1171  // No support for combined raw and num params
1172  return [ 'before', $this->getLanguage()->formatNum( $param['num'] ) ];
1173  } elseif ( isset( $param['duration'] ) ) {
1174  return [ 'before', $this->getLanguage()->formatDuration( $param['duration'] ) ];
1175  } elseif ( isset( $param['expiry'] ) ) {
1176  return [ 'before', $this->getLanguage()->formatExpiry( $param['expiry'] ) ];
1177  } elseif ( isset( $param['period'] ) ) {
1178  return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
1179  } elseif ( isset( $param['size'] ) ) {
1180  return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
1181  } elseif ( isset( $param['bitrate'] ) ) {
1182  return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];
1183  } elseif ( isset( $param['plaintext'] ) ) {
1184  return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
1185  } elseif ( isset( $param['list'] ) ) {
1186  return $this->formatListParam( $param['list'], $param['type'], $format );
1187  } else {
1188  $warning = 'Invalid parameter for message "' . $this->getKey() . '": ' .
1189  htmlspecialchars( serialize( $param ) );
1190  trigger_error( $warning, E_USER_WARNING );
1191  $e = new Exception;
1192  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1193 
1194  return [ 'before', '[INVALID]' ];
1195  }
1196  } elseif ( $param instanceof Message ) {
1197  // Match language, flags, etc. to the current message.
1198  $msg = clone $param;
1199  if ( $msg->language !== $this->language || $msg->useDatabase !== $this->useDatabase ) {
1200  // Cache depends on these parameters
1201  $msg->message = null;
1202  }
1203  $msg->interface = $this->interface;
1204  $msg->language = $this->language;
1205  $msg->useDatabase = $this->useDatabase;
1206  $msg->title = $this->title;
1207 
1208  // DWIM
1209  if ( $format === 'block-parse' ) {
1210  $format = 'parse';
1211  }
1212  $msg->format = $format;
1213 
1214  // Message objects should not be before parameters because
1215  // then they'll get double escaped. If the message needs to be
1216  // escaped, it'll happen right here when we call toString().
1217  return [ 'after', $msg->toString( $format ) ];
1218  } else {
1219  return [ 'before', $param ];
1220  }
1221  }
1222 
1232  protected function parseText( $string ) {
1233  $out = MessageCache::singleton()->parse(
1234  $string,
1235  $this->title,
1236  /*linestart*/true,
1237  $this->interface,
1238  $this->getLanguage()
1239  );
1240 
1241  return $out instanceof ParserOutput ? $out->getText() : $out;
1242  }
1243 
1253  protected function transformText( $string ) {
1254  return MessageCache::singleton()->transform(
1255  $string,
1256  $this->interface,
1257  $this->getLanguage(),
1258  $this->title
1259  );
1260  }
1261 
1270  protected function fetchMessage() {
1271  if ( $this->message === null ) {
1273 
1274  foreach ( $this->keysToTry as $key ) {
1275  $message = $cache->get( $key, $this->useDatabase, $this->getLanguage() );
1276  if ( $message !== false && $message !== '' ) {
1277  break;
1278  }
1279  }
1280 
1281  // NOTE: The constructor makes sure keysToTry isn't empty,
1282  // so we know that $key and $message are initialized.
1283  $this->key = $key;
1284  $this->message = $message;
1285  }
1286  return $this->message;
1287  }
1288 
1301  protected function formatPlaintext( $plaintext, $format ) {
1302  switch ( $format ) {
1303  case self::FORMAT_TEXT:
1304  case self::FORMAT_PLAIN:
1305  return $plaintext;
1306 
1307  case self::FORMAT_PARSE:
1308  case self::FORMAT_BLOCK_PARSE:
1309  case self::FORMAT_ESCAPED:
1310  default:
1311  return htmlspecialchars( $plaintext, ENT_QUOTES );
1312 
1313  }
1314  }
1315 
1324  protected function formatListParam( array $params, $listType, $format ) {
1325  if ( !isset( self::$listTypeMap[$listType] ) ) {
1326  $warning = 'Invalid list type for message "' . $this->getKey() . '": '
1327  . htmlspecialchars( $listType )
1328  . ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
1329  trigger_error( $warning, E_USER_WARNING );
1330  $e = new Exception;
1331  wfDebugLog( 'Bug58676', $warning . "\n" . $e->getTraceAsString() );
1332  return [ 'before', '[INVALID]' ];
1333  }
1334  $func = self::$listTypeMap[$listType];
1335 
1336  // Handle an empty list sensibly
1337  if ( !$params ) {
1338  return [ 'before', $this->getLanguage()->$func( [] ) ];
1339  }
1340 
1341  // First, determine what kinds of list items we have
1342  $types = [];
1343  $vars = [];
1344  $list = [];
1345  foreach ( $params as $n => $p ) {
1346  list( $type, $value ) = $this->extractParam( $p, $format );
1347  $types[$type] = true;
1348  $list[] = $value;
1349  $vars[] = '$' . ( $n + 1 );
1350  }
1351 
1352  // Easy case: all are 'before' or 'after', so just join the
1353  // values and use the same type.
1354  if ( count( $types ) === 1 ) {
1355  return [ key( $types ), $this->getLanguage()->$func( $list ) ];
1356  }
1357 
1358  // Hard case: We need to process each value per its type, then
1359  // return the concatenated values as 'after'. We handle this by turning
1360  // the list into a RawMessage and processing that as a parameter.
1361  $vars = $this->getLanguage()->$func( $vars );
1362  return $this->extractParam( new RawMessage( $vars, $params ), $format );
1363  }
1364 }
ParserOutput
Definition: ParserOutput.php:24
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
$context
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:2581
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:249
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
MessageSpecifier\getKey
getKey()
Returns the message key.
MessageSpecifier
Definition: MessageSpecifier.php:21
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:79
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:185
$params
$params
Definition: styleTest.css.php:40
serialize
serialize()
Definition: ApiMessage.php:177
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:1140
php
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
MessageSpecifier\getParams
getParams()
Returns the message parameters.
key
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
MWException
MediaWiki exception.
Definition: MWException.php:26
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1176
message
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 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:2133
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:529
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2198
list
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
MessageCache\singleton
static singleton()
Get the signleton instance of this class.
Definition: MessageCache.php:113
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
$value
$value
Definition: styleTest.css.php:45
StubUserLang
Stub object for the user language.
Definition: StubObject.php:177
language
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of either verbatim or with modifications and or translated into another language(Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:470
IContextSource\getTitle
getTitle()
Get the Title object.
format
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1639
plain
either a plain
Definition: hooks.txt:2026
$wgForceUIMsgAsContentMsg
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
Definition: DefaultSettings.php:3106
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
Content
Base interface for content objects.
Definition: Content.php:34
$args
if( $line===false) $args
Definition: cdb.php:63
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$cache
$cache
Definition: mcc.php:33
MessageContent
Wrapper allowing us to handle a system message as a Content object.
Definition: MessageContent.php:36
$code
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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 modifiable & $code
Definition: hooks.txt:781
as
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
$keys
$keys
Definition: testCompression.php:65
true
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:1965
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:73
RawMessage
Variant of the Message class.
Definition: RawMessage.php:34
Language
Internationalisation code.
Definition: Language.php:35
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:781
$type
$type
Definition: testCompression.php:48