23use InvalidArgumentException;
38 private $joinCache = [];
51 private bool $allowUnknown;
53 private bool $forImport =
false;
86 $this->fieldInfos = $fieldInfos;
87 $this->allowUnknown = $options[
'allowUnknown'] ??
true;
91 if ( $writeStage === 0 ) {
92 throw new InvalidArgumentException(
'$stage must include a write mode' );
94 if ( $readStage === 0 ) {
95 throw new InvalidArgumentException(
'$stage must include a read mode' );
98 throw new InvalidArgumentException(
'Cannot read multiple schemas' );
101 throw new InvalidArgumentException(
'Cannot read the old schema without also writing it' );
104 throw new InvalidArgumentException(
'Cannot read the new schema without also writing it' );
106 $this->readStage = $readStage;
107 $this->writeStage = $writeStage;
117 throw new LogicException( __METHOD__ .
" must be overridden" );
129 if ( isset( $this->fieldInfos[$key] ) ) {
130 return $this->fieldInfos[$key];
131 } elseif ( $this->allowUnknown ) {
134 throw new InvalidArgumentException( $this->
getInstanceName() .
": unknown key $key" );
147 if ( (
new ReflectionClass( $this ) )->isAnonymous() ) {
151 return static::class;
164 if ( isset( $fieldInfo[
'removedVersion'] ) ) {
165 $removedVersion = $fieldInfo[
'removedVersion'];
166 $component = $fieldInfo[
'component'] ??
'MediaWiki';
167 throw new InvalidArgumentException(
168 "Use of {$this->getInstanceName()} for '$key' was removed in $component $removedVersion"
171 if ( isset( $fieldInfo[
'deprecatedVersion'] ) ) {
172 $deprecatedVersion = $fieldInfo[
'deprecatedVersion'];
173 $component = $fieldInfo[
'component'] ??
'MediaWiki';
174 wfDeprecated(
"{$this->getInstanceName()} for '$key'", $deprecatedVersion, $component, 3 );
201 private function getFieldNames( $key ) {
203 $textField = $fieldInfo[
'textField'] ?? $key .
'_text';
204 $actorField = $fieldInfo[
'actorField'] ?? substr( $key, 0, -5 ) .
'_actor';
205 return [ $textField, $actorField ];
223 if ( !isset( $this->joinCache[$key] ) ) {
228 [ $text, $actor ] = $this->getFieldNames( $key );
231 $fields[$key] = $key;
232 $fields[$text] = $text;
233 $fields[$actor] =
'NULL';
235 $alias =
"actor_$key";
236 $tables[$alias] =
'actor';
237 $joins[$alias] = [
'JOIN',
"{$alias}.actor_id = {$actor}" ];
239 $fields[$key] =
"{$alias}.actor_user";
240 $fields[$text] =
"{$alias}.actor_name";
241 $fields[$actor] = $actor;
244 $this->joinCache[$key] = [
251 return $this->joinCache[$key];
266 [ $text, $actor ] = $this->getFieldNames( $key );
269 $ret[$key] = $user->
getId();
270 $ret[$text] = $user->
getName();
274 ->acquireActorId( $user, $dbw );
312 } elseif ( $users ===
null || $users ===
false ) {
315 } elseif ( !is_array( $users ) ) {
316 $what = get_debug_type( $users );
317 throw new InvalidArgumentException(
318 __METHOD__ .
": Value for \$users must be a UserIdentity or array, got $what"
326 foreach ( $users as $user ) {
327 if ( $useId && $user->isRegistered() ) {
328 $ids[] = $user->getId();
331 $names[] = IPUtils::sanitizeIP( $user->getName() );
334 ->findActorId( $user, $db );
337 $actors[] = $actorId;
341 [ $text, $actor ] = $this->getFieldNames( $key );
346 $conds[
'newactor'] = $db->
makeList( [ $actor => $actors ], IDatabase::LIST_AND );
350 $conds[
'userid'] = $db->
makeList( [ $key => $ids ], IDatabase::LIST_AND );
353 $conds[
'username'] = $db->
makeList( [ $text => $names ], IDatabase::LIST_AND );
359 'conds' => $conds ? $db->
makeList( array_values( $conds ), IDatabase::LIST_OR ) :
'1=0',
370 $this->forImport = $forImport;
378 if ( $this->forImport ) {
379 return $this->actorStoreFactory->getActorNormalizationForImport( $domainId );
381 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'))