24use Psr\Log\LoggerInterface;
25use Psr\Log\LoggerAwareInterface;
26use Wikimedia\Timestamp\ConvertibleTimestamp;
73 if ( $val !==
'True' && $val !==
'False' ) {
74 $this->logger->info( __METHOD__ .
" Expected True or False but got $val" );
91 if ( !preg_match(
'/^(?:-?\d+)\/(?:\d+[1-9]|[1-9]\d*)$/D', $val ) ) {
92 $this->logger->info( __METHOD__ .
" Expected rational but got $val" );
108 if ( !$standalone ) {
112 if ( !preg_match(
'/^[-+]?\d*(?:\.?\d*)$/D', $val )
113 || !is_numeric( $val )
115 $this->logger->info( __METHOD__ .
" Expected rating but got $val" );
125 $this->logger->info( __METHOD__ .
" Rating too low, setting to -1 (Rejected)" );
131 $this->logger->info( __METHOD__ .
" Rating too high, setting to 5" );
147 if ( !$standalone ) {
151 if ( !preg_match(
'/^[-+]?\d+$/D', $val ) ) {
152 $this->logger->info( __METHOD__ .
" Expected integer but got $val" );
166 if ( !$standalone ) {
173 if ( isset( $info[
'rangeLow'] )
174 && isset( $info[
'rangeHigh'] )
175 && is_numeric( $val )
176 && ( intval( $val ) <= $info[
'rangeHigh'] )
177 && ( intval( $val ) >= $info[
'rangeLow'] )
182 if ( !isset( $info[
'choices'][$val] ) && !$inRange ) {
183 $this->logger->info( __METHOD__ .
" Expected closed choice, but got $val" );
200 if ( !( isset( $val[
'Fired'] )
201 && isset( $val[
'Function'] )
202 && isset( $val[
'Mode'] )
203 && isset( $val[
'RedEyeMode'] )
204 && isset( $val[
'Return'] )
206 $this->logger->info( __METHOD__ .
" Flash structure did not have all the required components" );
209 $val = (
"\0" | ( $val[
'Fired'] ===
'True' )
210 | ( intval( $val[
'Return'] ) << 1 )
211 | ( intval( $val[
'Mode'] ) << 3 )
212 | ( ( $val[
'Function'] ===
'True' ) << 5 )
213 | ( ( $val[
'RedEyeMode'] ===
'True' ) << 6 ) );
231 if ( !$standalone ) {
235 if ( !preg_match(
'/^[-A-Za-z0-9]{2,}$/D', $val ) ) {
237 $this->logger->info( __METHOD__ .
" Expected Lang code but got $val" );
260 if ( !$standalone ) {
268 '/^([0-3]\d{3})(?:-([01]\d)(?:-([0-3]\d)(?:T([0-2]\d):([0-6]\d)(?::([0-6]\d)(?:\.\d+)?)?([-+]\d{2}:\d{2}|Z)?)?)?)?$/D',
273 $this->logger->info( __METHOD__ .
" Expected date but got $val" );
290 if (
$res[1] ===
'0000' ) {
291 $this->logger->info( __METHOD__ .
" Invalid date (year 0): $val" );
297 if ( !isset(
$res[4] ) ) {
300 if ( isset(
$res[2] ) ) {
301 $val .=
':' .
$res[2];
303 if ( isset(
$res[3] ) ) {
304 $val .=
':' .
$res[3];
310 if ( !isset(
$res[7] ) ||
$res[7] ===
'Z' ) {
314 if ( isset(
$res[6] ) &&
$res[6] !==
'' ) {
315 $val .=
':' .
$res[6];
322 $stripSeconds =
false;
323 if ( !isset(
$res[6] ) ||
$res[6] ===
'' ) {
325 $stripSeconds =
true;
333 $unix = ConvertibleTimestamp::convert( TS_UNIX,
336 $offset = intval( substr(
$res[7], 1, 2 ) ) * 60 * 60;
337 $offset += intval( substr(
$res[7], 4, 2 ) ) * 60;
338 if ( substr(
$res[7], 0, 1 ) ===
'-' ) {
341 $val = ConvertibleTimestamp::convert( TS_EXIF, $unix + $offset );
343 if ( $stripSeconds ) {
345 $val = substr( $val, 0, -3 );
363 if ( !$standalone ) {
369 '/(\d{1,3}),(\d{1,2}),(\d{1,2})([NWSE])/D',
372 $coord = intval( $m[1] );
373 $coord += intval( $m[2] ) * ( 1 / 60 );
374 $coord += intval( $m[3] ) * ( 1 / 3600 );
375 if ( $m[4] ===
'S' || $m[4] ===
'W' ) {
381 } elseif ( preg_match(
382 '/(\d{1,3}),(\d{1,2}(?:.\d*)?)([NWSE])/D',
385 $coord = intval( $m[1] );
386 $coord += floatval( $m[2] ) * ( 1 / 60 );
387 if ( $m[3] ===
'S' || $m[3] ===
'W' ) {
394 $this->logger->info( __METHOD__
395 .
" Expected GPSCoordinate, but got $val." );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This contains some static methods for validating XMP properties.
validateRating( $info, &$val, $standalone)
function to validate rating properties -1, 0-5
validateInteger( $info, &$val, $standalone)
function to validate integers
validateClosed( $info, &$val, $standalone)
function to validate properties with a fixed number of allowed choices.
setLogger(LoggerInterface $logger)
validateBoolean( $info, &$val, $standalone)
Function to validate boolean properties ( True or False )
validateDate( $info, &$val, $standalone)
function to validate date properties, and convert to (partial) Exif format.
validateGPS( $info, &$val, $standalone)
function to validate, and more importantly translate the XMP DMS form of gps coords to the decimal fo...
__construct(LoggerInterface $logger)
validateRational( $info, &$val, $standalone)
function to validate rational properties ( 12/10 )
validateFlash( $info, &$val, $standalone)
function to validate and modify flash structure
validateLangCode( $info, &$val, $standalone)
function to validate LangCode properties ( en-GB, etc )
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