MediaWiki REL1_33
Message.php
Go to the documentation of this file.
1<?php
24
160class Message implements MessageSpecifier, Serializable {
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 ) {
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 /*...*/ ) {
411 return new self( $key, $params );
412 }
413
427 public static function newFromSpecifier( $value ) {
428 $params = [];
429 if ( is_array( $value ) ) {
430 $params = $value;
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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( /*...*/ ) {
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 ] );
861 $format = $this->format;
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 ) {
1305 $cache = MessageCache::singleton();
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}
serialize()
unserialize( $serialized)
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 and(2) offer you this license which gives you legal permission to copy
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
$wgForceUIMsgAsContentMsg
When translating messages with wfMessage(), it is not always clear what should be considered UI messa...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
if( $line===false) $args
Definition cdb.php:64
Internationalisation code.
Definition Language.php:36
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Wrapper allowing us to handle a system message as a Content object.
The Message class provides methods which fulfil two basic services:
Definition Message.php:160
extractParam( $param, $format)
Extracts the parameter type and preprocessed the value if needed.
Definition Message.php:1183
static listParam(array $list, $type='text')
Definition Message.php:1126
timeperiodParams()
Add parameters that are time periods and will be passed through Language::formatTimePeriod before sub...
Definition Message.php:636
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
Definition Message.php:168
transformText( $string)
Wrapper for what ever method we use to {{-transform wikitext.
Definition Message.php:1286
static rawParam( $raw)
Definition Message.php:1038
getParams()
Returns the message parameters.
Definition Message.php:367
durationParams()
Add parameters that are durations of time and will be passed through Language::formatDuration before ...
Definition Message.php:592
static bitrateParam( $bitrate)
Definition Message.php:1104
static newFromKey( $key)
Factory function that is just wrapper for the real constructor.
Definition Message.php:408
numParams()
Add parameters that are numeric and will be passed through Language::formatNum before substitution.
Definition Message.php:570
static array $listTypeMap
Mapping from Message::listParam() types to Language methods.
Definition Message.php:176
isMultiKey()
Definition Message.php:331
isBlank()
Check whether a message does not exist, or is an empty string.
Definition Message.php:1014
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
Definition Message.php:798
parseAsBlock()
Returns the parsed message text which is always surrounded by a block element.
Definition Message.php:977
__construct( $key, $params=[], Language $language=null)
Definition Message.php:249
bool $useDatabase
Whether database can be used.
Definition Message.php:223
getKeysToTry()
Definition Message.php:341
parse()
Fully parse the text from wikitext to HTML.
Definition Message.php:941
const FORMAT_PARSE
Use normal wikitext -> HTML parsing but strip the block-level wrapper.
Definition Message.php:166
__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
static newFallbackSequence()
Factory function accepting multiple message keys and returning a message instance for the first messa...
Definition Message.php:460
unserialize( $serialized)
Definition Message.php:301
const FORMAT_BLOCK_PARSE
Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag)
Definition Message.php:164
static sizeParam( $size)
Definition Message.php:1093
formatListParam(array $params, $listType, $format)
Formats a list of parameters as a concatenated string.
Definition Message.php:1356
static timeperiodParam( $period)
Definition Message.php:1082
array $parameters
List of parameters which will be substituted into the message.
Definition Message.php:212
static plaintextParam( $plaintext)
Definition Message.php:1115
const FORMAT_PLAIN
Use message text as-is.
Definition Message.php:162
static durationParam( $duration)
Definition Message.php:1060
const FORMAT_ESCAPED
Transform {{..}} constructs, HTML-escape the result.
Definition Message.php:170
inLanguage( $lang)
Request the message in any language that is supported.
Definition Message.php:743
replaceParameters( $message, $type, $format)
Substitutes any parameters into the message text.
Definition Message.php:1146
string $key
The message key.
Definition Message.php:202
sizeParams()
Add parameters that are file sizes and will be passed through Language::formatSize before substitutio...
Definition Message.php:658
static numParam( $num)
Definition Message.php:1049
expiryParams()
Add parameters that are expiration times and will be passed through Language::formatExpiry before sub...
Definition Message.php:614
inContentLanguage()
Request the message in the wiki's content language, unless it is disabled for this message.
Definition Message.php:778
plain()
Returns the message text as-is, only parameters are substituted.
Definition Message.php:965
exists()
Check whether a message key has been defined currently.
Definition Message.php:1002
plaintextParams()
Add parameters that are plaintext and will be passed through without the content being evaluated.
Definition Message.php:704
rawParams()
Add parameters that are substituted after parsing or escaping.
Definition Message.php:548
title( $title)
Set the Title object to use as context when transforming the message.
Definition Message.php:827
Language bool $language
In which language to get this message.
Definition Message.php:196
getFormat()
Returns the message format.
Definition Message.php:379
useDatabase( $useDatabase)
Enable or disable database use.
Definition Message.php:812
fetchMessage()
Wrapper for what ever method we use to get message contents.
Definition Message.php:1303
content()
Returns the message as a Content object.
Definition Message.php:837
formatPlaintext( $plaintext, $format)
Formats a message parameter wrapped with 'plaintext'.
Definition Message.php:1334
getTitle()
Get a title object for a mediawiki message, where it can be found in the mediawiki namespace.
Definition Message.php:484
bitrateParams()
Add parameters that are bitrates and will be passed through Language::formatBitrate before substituti...
Definition Message.php:680
parseText( $string)
Wrapper for what ever method we use to parse wikitext.
Definition Message.php:1256
getKey()
Returns the message key.
Definition Message.php:356
isDisabled()
Check whether a message does not exist, is an empty string, or is "-".
Definition Message.php:1026
escaped()
Returns the message text.
Definition Message.php:990
params()
Adds parameters to the parameter list of this message.
Definition Message.php:511
getLanguage()
Returns the Language of the Message.
Definition Message.php:391
string $format
Definition Message.php:218
string $message
Definition Message.php:238
string[] $keysToTry
List of keys to try when fetching the message.
Definition Message.php:207
serialize()
Definition Message.php:283
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
text()
Returns the message text.
Definition Message.php:953
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:427
bool $interface
In which language to get this message.
Definition Message.php:189
static expiryParam( $expiry)
Definition Message.php:1071
Variant of the Message class.
Stub object for the user language.
Represents a title within MediaWiki.
Definition Title.php:40
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 configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2228
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:855
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:2163
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:2848
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
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:2004
returning false will NOT prevent logging $e
Definition hooks.txt:2175
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Base interface for content objects.
Definition Content.php:34
Interface for objects which can provide a MediaWiki context on request.
$cache
Definition mcc.php:33
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$content
$params
foreach( $res as $row) $serialized
if(!isset( $args[0])) $lang
title