9use InvalidArgumentException;
24 private $joinCache = [];
37 private bool $allowUnknown;
39 private bool $forImport =
false;
72 $this->fieldInfos = $fieldInfos;
73 $this->allowUnknown = $options[
'allowUnknown'] ??
true;
77 if ( $writeStage === 0 ) {
78 throw new InvalidArgumentException(
'$stage must include a write mode' );
80 if ( $readStage === 0 ) {
81 throw new InvalidArgumentException(
'$stage must include a read mode' );
84 throw new InvalidArgumentException(
'Cannot read multiple schemas' );
87 throw new InvalidArgumentException(
'Cannot read the old schema without also writing it' );
90 throw new InvalidArgumentException(
'Cannot read the new schema without also writing it' );
92 $this->readStage = $readStage;
93 $this->writeStage = $writeStage;
103 throw new LogicException( __METHOD__ .
" must be overridden" );
115 if ( isset( $this->fieldInfos[$key] ) ) {
116 return $this->fieldInfos[$key];
117 } elseif ( $this->allowUnknown ) {
120 throw new InvalidArgumentException( $this->
getInstanceName() .
": unknown key $key" );
133 if ( (
new ReflectionClass( $this ) )->isAnonymous() ) {
137 return static::class;
150 if ( isset( $fieldInfo[
'removedVersion'] ) ) {
151 $removedVersion = $fieldInfo[
'removedVersion'];
152 $component = $fieldInfo[
'component'] ??
'MediaWiki';
153 throw new InvalidArgumentException(
154 "Use of {$this->getInstanceName()} for '$key' was removed in $component $removedVersion"
157 if ( isset( $fieldInfo[
'deprecatedVersion'] ) ) {
158 $deprecatedVersion = $fieldInfo[
'deprecatedVersion'];
159 $component = $fieldInfo[
'component'] ??
'MediaWiki';
160 wfDeprecated(
"{$this->getInstanceName()} for '$key'", $deprecatedVersion, $component, 3 );
187 private function getFieldNames( $key ) {
189 $textField = $fieldInfo[
'textField'] ?? $key .
'_text';
190 $actorField = $fieldInfo[
'actorField'] ?? substr( $key, 0, -5 ) .
'_actor';
191 return [ $textField, $actorField ];
209 if ( !isset( $this->joinCache[$key] ) ) {
214 [ $text, $actor ] = $this->getFieldNames( $key );
217 $fields[$key] = $key;
218 $fields[$text] = $text;
219 $fields[$actor] =
'NULL';
221 $alias =
"actor_$key";
222 $tables[$alias] =
'actor';
223 $joins[$alias] = [
'JOIN',
"{$alias}.actor_id = {$actor}" ];
225 $fields[$key] =
"{$alias}.actor_user";
226 $fields[$text] =
"{$alias}.actor_name";
227 $fields[$actor] = $actor;
230 $this->joinCache[$key] = [
237 return $this->joinCache[$key];
252 [ $text, $actor ] = $this->getFieldNames( $key );
255 $ret[$key] = $user->
getId();
256 $ret[$text] = $user->
getName();
260 ->acquireActorId( $user, $dbw );
298 } elseif ( $users ===
null || $users ===
false ) {
301 } elseif ( !is_array( $users ) ) {
302 $what = get_debug_type( $users );
303 throw new InvalidArgumentException(
304 __METHOD__ .
": Value for \$users must be a UserIdentity or array, got $what"
312 foreach ( $users as $user ) {
313 if ( $useId && $user->isRegistered() ) {
314 $ids[] = $user->getId();
317 $names[] = IPUtils::sanitizeIP( $user->getName() );
320 ->findActorId( $user, $db );
323 $actors[] = $actorId;
327 [ $text, $actor ] = $this->getFieldNames( $key );
332 $conds[
'newactor'] = $db->
makeList( [ $actor => $actors ], IDatabase::LIST_AND );
336 $conds[
'userid'] = $db->
makeList( [ $key => $ids ], IDatabase::LIST_AND );
339 $conds[
'username'] = $db->
makeList( [ $text => $names ], IDatabase::LIST_AND );
345 'conds' => $conds ? $db->
makeList( array_values( $conds ), IDatabase::LIST_OR ) :
'1=0',
356 $this->forImport = $forImport;
364 if ( $this->forImport ) {
365 return $this->actorStoreFactory->getActorNormalizationForImport( $domainId );
367 return $this->actorStoreFactory->getActorNormalization( $domainId );
const SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_READ_OLD
const SCHEMA_COMPAT_WRITE_NEW
const SCHEMA_COMPAT_WRITE_MASK
const SCHEMA_COMPAT_READ_MASK
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))