9use InvalidArgumentException;
24 private $joinCache = [];
27 private readonly
int $readStage;
30 private readonly
int $writeStage;
32 private readonly
bool $allowUnknown;
34 private bool $forImport =
false;
62 private readonly array $fieldInfos,
67 $this->allowUnknown = $options[
'allowUnknown'] ??
true;
71 if ( $writeStage === 0 ) {
72 throw new InvalidArgumentException(
'$stage must include a write mode' );
74 if ( $readStage === 0 ) {
75 throw new InvalidArgumentException(
'$stage must include a read mode' );
78 throw new InvalidArgumentException(
'Cannot read multiple schemas' );
81 throw new InvalidArgumentException(
'Cannot read the old schema without also writing it' );
84 throw new InvalidArgumentException(
'Cannot read the new schema without also writing it' );
86 $this->readStage = $readStage;
87 $this->writeStage = $writeStage;
95 throw new LogicException( __METHOD__ .
" must be overridden" );
107 if ( isset( $this->fieldInfos[$key] ) ) {
108 return $this->fieldInfos[$key];
109 } elseif ( $this->allowUnknown ) {
112 throw new InvalidArgumentException( $this->
getInstanceName() .
": unknown key $key" );
125 if ( (
new ReflectionClass( $this ) )->isAnonymous() ) {
129 return static::class;
142 if ( isset( $fieldInfo[
'removedVersion'] ) ) {
143 $removedVersion = $fieldInfo[
'removedVersion'];
144 $component = $fieldInfo[
'component'] ??
'MediaWiki';
145 throw new InvalidArgumentException(
146 "Use of {$this->getInstanceName()} for '$key' was removed in $component $removedVersion"
149 if ( isset( $fieldInfo[
'deprecatedVersion'] ) ) {
150 $deprecatedVersion = $fieldInfo[
'deprecatedVersion'];
151 $component = $fieldInfo[
'component'] ??
'MediaWiki';
152 wfDeprecated(
"{$this->getInstanceName()} for '$key'", $deprecatedVersion, $component, 3 );
179 private function getFieldNames( $key ) {
181 $textField = $fieldInfo[
'textField'] ?? $key .
'_text';
182 $actorField = $fieldInfo[
'actorField'] ?? substr( $key, 0, -5 ) .
'_actor';
183 return [ $textField, $actorField ];
201 if ( !isset( $this->joinCache[$key] ) ) {
206 [ $text, $actor ] = $this->getFieldNames( $key );
209 $fields[$key] = $key;
210 $fields[$text] = $text;
211 $fields[$actor] =
'NULL';
213 $alias =
"actor_$key";
214 $tables[$alias] =
'actor';
215 $joins[$alias] = [
'JOIN',
"{$alias}.actor_id = {$actor}" ];
217 $fields[$key] =
"{$alias}.actor_user";
218 $fields[$text] =
"{$alias}.actor_name";
219 $fields[$actor] = $actor;
222 $this->joinCache[$key] = [
229 return $this->joinCache[$key];
244 [ $text, $actor ] = $this->getFieldNames( $key );
247 $ret[$key] = $user->
getId();
248 $ret[$text] = $user->
getName();
252 ->acquireActorId( $user, $dbw );
290 } elseif ( $users ===
null || $users ===
false ) {
293 } elseif ( !is_array( $users ) ) {
294 $what = get_debug_type( $users );
295 throw new InvalidArgumentException(
296 __METHOD__ .
": Value for \$users must be a UserIdentity or array, got $what"
304 foreach ( $users as $user ) {
305 if ( $useId && $user->isRegistered() ) {
306 $ids[] = $user->getId();
309 $names[] = IPUtils::sanitizeIP( $user->getName() );
312 ->findActorId( $user, $db );
315 $actors[] = $actorId;
319 [ $text, $actor ] = $this->getFieldNames( $key );
324 $conds[
'newactor'] = $db->
makeList( [ $actor => $actors ], IDatabase::LIST_AND );
328 $conds[
'userid'] = $db->
makeList( [ $key => $ids ], IDatabase::LIST_AND );
331 $conds[
'username'] = $db->
makeList( [ $text => $names ], IDatabase::LIST_AND );
337 'conds' => $conds ? $db->
makeList( array_values( $conds ), IDatabase::LIST_OR ) :
'1=0',
348 $this->forImport = $forImport;
356 if ( $this->forImport ) {
357 return $this->actorStoreFactory->getActorNormalizationForImport( $domainId );
359 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'))