@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
7 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
6 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
7 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
8 | 8 | /* wfWarn( |
9 | 9 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
10 | 10 | 'Please use wfLoadExtension instead, ' . |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ); */ |
13 | 13 | return; |
14 | 14 | } else { |
15 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
15 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
16 | 16 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | /** English (English) */ |
12 | 12 | $specialPageAliases['en'] = [ |
13 | - 'ConstraintReport' => [ 'ConstraintReport', 'Constraint Report' ], |
|
13 | + 'ConstraintReport' => ['ConstraintReport', 'Constraint Report'], |
|
14 | 14 | ]; |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | use WikibaseQuality\ConstraintReport\UpdateConstraintsTableJob; |
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
12 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
11 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
12 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
13 | 13 | |
14 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
14 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Runs {@link UpdateConstraintsTableJob} once for every property. |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | public function __construct() { |
24 | 24 | parent::__construct(); |
25 | 25 | |
26 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
26 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function execute() { |
30 | - if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
31 | - $this->error( 'Constraint statements are not enabled. Aborting.', 1 ); |
|
30 | + if (!MediaWikiServices::getInstance()->getMainConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
31 | + $this->error('Constraint statements are not enabled. Aborting.', 1); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $propertyInfoLookup = WikibaseRepo::getDefaultInstance()->getStore()->getPropertyInfoLookup(); |
35 | - foreach ( $propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
36 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
37 | - $startTime = microtime( true ); |
|
38 | - $job = UpdateConstraintsTableJob::newFromGlobalState( Title::newMainPage(), [ 'propertyId' => $propertyIdSerialization ] ); |
|
35 | + foreach ($propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
36 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
37 | + $startTime = microtime(true); |
|
38 | + $job = UpdateConstraintsTableJob::newFromGlobalState(Title::newMainPage(), ['propertyId' => $propertyIdSerialization]); |
|
39 | 39 | $job->run(); |
40 | - $endTime = microtime( true ); |
|
41 | - $millis = ( $endTime - $startTime ) * 1000; |
|
42 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
40 | + $endTime = microtime(true); |
|
41 | + $millis = ($endTime - $startTime) * 1000; |
|
42 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 |
@@ -14,6 +14,6 @@ |
||
14 | 14 | * |
15 | 15 | * @return Constraint[] |
16 | 16 | */ |
17 | - public function queryConstraintsForProperty( PropertyId $propertyId ); |
|
17 | + public function queryConstraintsForProperty(PropertyId $propertyId); |
|
18 | 18 | |
19 | 19 | } |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return Constraint[] |
22 | 22 | */ |
23 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
24 | - $db = wfGetDB( DB_REPLICA ); |
|
23 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
24 | + $db = wfGetDB(DB_REPLICA); |
|
25 | 25 | |
26 | 26 | $results = $db->select( |
27 | 27 | 'wbqc_constraints', |
28 | 28 | '*', |
29 | - [ 'pid' => $propertyId->getNumericId() ] |
|
29 | + ['pid' => $propertyId->getNumericId()] |
|
30 | 30 | ); |
31 | 31 | |
32 | - return $this->convertToConstraints( $results ); |
|
32 | + return $this->convertToConstraints($results); |
|
33 | 33 | } |
34 | 34 | |
35 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
36 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
35 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
36 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
37 | 37 | |
38 | - if ( strlen( $json ) > 50000 ) { |
|
39 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
38 | + if (strlen($json) > 50000) { |
|
39 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | return $json; |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | * @throws DBUnexpectedError |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function insertBatch( array $constraints ) { |
|
51 | + public function insertBatch(array $constraints) { |
|
52 | 52 | $accumulator = array_map( |
53 | - function ( Constraint $constraint ) { |
|
53 | + function(Constraint $constraint) { |
|
54 | 54 | return [ |
55 | 55 | 'constraint_guid' => $constraint->getConstraintId(), |
56 | 56 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
57 | 57 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
58 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
58 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
59 | 59 | ]; |
60 | 60 | }, |
61 | 61 | $constraints |
62 | 62 | ); |
63 | 63 | |
64 | - $db = wfGetDB( DB_MASTER ); |
|
65 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
64 | + $db = wfGetDB(DB_MASTER); |
|
65 | + return $db->insert('wbqc_constraints', $accumulator); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - private function uuidPattern( LikeMatch $any ) { |
|
73 | + private function uuidPattern(LikeMatch $any) { |
|
74 | 74 | return array_merge( |
75 | - array_fill( 0, 8, $any ), [ '-' ], |
|
76 | - array_fill( 0, 4, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 12, $any ) |
|
75 | + array_fill(0, 8, $any), ['-'], |
|
76 | + array_fill(0, 4, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 12, $any) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @throws DBUnexpectedError |
88 | 88 | */ |
89 | 89 | public function deleteWhereConstraintIdIsUuid() { |
90 | - $db = wfGetDB( DB_MASTER ); |
|
90 | + $db = wfGetDB(DB_MASTER); |
|
91 | 91 | $db->delete( |
92 | 92 | 'wbqc_constraints', |
93 | 93 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
94 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
94 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @throws DBUnexpectedError |
103 | 103 | */ |
104 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
105 | - $db = wfGetDB( DB_MASTER ); |
|
104 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
105 | + $db = wfGetDB(DB_MASTER); |
|
106 | 106 | $db->delete( |
107 | 107 | 'wbqc_constraints', |
108 | 108 | [ |
109 | 109 | 'pid' => $propertyId->getNumericId(), |
110 | 110 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
111 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
111 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
112 | 112 | ] |
113 | 113 | ); |
114 | 114 | } |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws DBUnexpectedError |
121 | 121 | */ |
122 | - public function deleteAll( $batchSize = 1000 ) { |
|
123 | - if ( !is_int( $batchSize ) ) { |
|
122 | + public function deleteAll($batchSize = 1000) { |
|
123 | + if (!is_int($batchSize)) { |
|
124 | 124 | throw new InvalidArgumentException(); |
125 | 125 | } |
126 | - $db = wfGetDB( DB_MASTER ); |
|
127 | - if ( $db->getType() === 'sqlite' ) { |
|
128 | - $db->delete( 'wbqc_constraints', '*' ); |
|
126 | + $db = wfGetDB(DB_MASTER); |
|
127 | + if ($db->getType() === 'sqlite') { |
|
128 | + $db->delete('wbqc_constraints', '*'); |
|
129 | 129 | } else { |
130 | 130 | do { |
131 | - $db->commit( __METHOD__, 'flush' ); |
|
131 | + $db->commit(__METHOD__, 'flush'); |
|
132 | 132 | wfGetLBFactory()->waitForReplication(); |
133 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
134 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
135 | - } while ( $db->affectedRows() > 0 ); |
|
133 | + $table = $db->tableName('wbqc_constraints'); |
|
134 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
135 | + } while ($db->affectedRows() > 0); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -141,26 +141,26 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return Constraint[] |
143 | 143 | */ |
144 | - private function convertToConstraints( ResultWrapper $results ) { |
|
144 | + private function convertToConstraints(ResultWrapper $results) { |
|
145 | 145 | $constraints = []; |
146 | - foreach ( $results as $result ) { |
|
146 | + foreach ($results as $result) { |
|
147 | 147 | $constraintTypeItemId = $result->constraint_type_qid; |
148 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
148 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
149 | 149 | |
150 | - if ( $constraintParameters === null ) { |
|
150 | + if ($constraintParameters === null) { |
|
151 | 151 | // T171295 |
152 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
153 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
152 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
153 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | 154 | 'method' => __METHOD__, |
155 | 155 | 'constraintId' => $result->constraint_guid, |
156 | 156 | 'constraintParameters' => $result->constraint_parameters, |
157 | - ] ); |
|
158 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
157 | + ]); |
|
158 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $constraints[] = new Constraint( |
162 | 162 | $result->constraint_guid, |
163 | - PropertyId::newFromNumber( $result->pid ), |
|
163 | + PropertyId::newFromNumber($result->pid), |
|
164 | 164 | $constraintTypeItemId, |
165 | 165 | $constraintParameters |
166 | 166 | ); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @var ConstraintLookup $lookup The lookup to which all queries are delegated. |
28 | 28 | */ |
29 | - public function __construct( ConstraintLookup $lookup ) { |
|
29 | + public function __construct(ConstraintLookup $lookup) { |
|
30 | 30 | $this->lookup = $lookup; |
31 | 31 | } |
32 | 32 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | 39 | $id = $propertyId->getSerialization(); |
40 | - if ( !array_key_exists( $id, $this->cache ) ) { |
|
41 | - $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
|
40 | + if (!array_key_exists($id, $this->cache)) { |
|
41 | + $this->cache[$id] = $this->lookup->queryConstraintsForProperty($propertyId); |
|
42 | 42 | } |
43 | 43 | return $this->cache[$id]; |
44 | 44 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | * @codeCoverageIgnore |
73 | 73 | */ |
74 | 74 | private function __construct() { |
75 | - throw new LogicException( 'This class should never be instantiated.' ); |
|
75 | + throw new LogicException('This class should never be instantiated.'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param ItemId $itemId |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public static function fromItemId( ItemId $itemId ) { |
|
47 | + public static function fromItemId(ItemId $itemId) { |
|
48 | 48 | $ret = new self; |
49 | 49 | $ret->itemId = $itemId; |
50 | 50 | return $ret; |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | * @throws InvalidArgumentException |
81 | 81 | * @return self |
82 | 82 | */ |
83 | - public static function fromSnak( Snak $snak ) { |
|
84 | - switch ( true ) { |
|
83 | + public static function fromSnak(Snak $snak) { |
|
84 | + switch (true) { |
|
85 | 85 | case $snak instanceof PropertyValueSnak: |
86 | 86 | if ( |
87 | 87 | $snak->getDataValue() instanceof EntityIdValue && |
88 | 88 | $snak->getDataValue()->getEntityId() instanceof ItemId |
89 | 89 | ) { |
90 | - return self::fromItemId( $snak->getDataValue()->getEntityId() ); |
|
90 | + return self::fromItemId($snak->getDataValue()->getEntityId()); |
|
91 | 91 | } else { |
92 | - throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' ); |
|
92 | + throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak'); |
|
93 | 93 | } |
94 | 94 | case $snak instanceof PropertySomeValueSnak: |
95 | 95 | return self::someValue(); |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @return ItemId |
133 | 133 | */ |
134 | 134 | public function getItemId() { |
135 | - if ( ! $this->isValue() ) { |
|
136 | - throw new DomainException( 'This value does not contain an item ID.' ); |
|
135 | + if (!$this->isValue()) { |
|
136 | + throw new DomainException('This value does not contain an item ID.'); |
|
137 | 137 | } |
138 | 138 | return $this->itemId; |
139 | 139 | } |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | * @param Snak $snak |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - public function matchesSnak( Snak $snak ) { |
|
149 | - switch ( true ) { |
|
148 | + public function matchesSnak(Snak $snak) { |
|
149 | + switch (true) { |
|
150 | 150 | case $snak instanceof PropertyValueSnak: |
151 | 151 | return $this->isValue() && |
152 | 152 | $snak->getDataValue() instanceof EntityIdValue && |
153 | 153 | $snak->getDataValue()->getEntityId() instanceof ItemId && |
154 | - $snak->getDataValue()->getEntityId()->equals( $this->getItemId() ); |
|
154 | + $snak->getDataValue()->getEntityId()->equals($this->getItemId()); |
|
155 | 155 | case $snak instanceof PropertySomeValueSnak: |
156 | 156 | return $this->isSomeValue(); |
157 | 157 | case $snak instanceof PropertyNoValueSnak: |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | EntityDocument $entity, |
24 | 24 | Statement $statement |
25 | 25 | ) { |
26 | - parent::__construct( $entity, $statement->getMainSnak() ); |
|
26 | + parent::__construct($entity, $statement->getMainSnak()); |
|
27 | 27 | $this->statement = $statement; |
28 | 28 | } |
29 | 29 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | return $this->statement; |
40 | 40 | } |
41 | 41 | |
42 | - protected function &getMainArray( array &$container ) { |
|
42 | + protected function &getMainArray(array &$container) { |
|
43 | 43 | $statementArray = &$this->getStatementArray( |
44 | 44 | $container, |
45 | 45 | $this->entity->getId()->getSerialization(), |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | $this->statement->getGuid() |
48 | 48 | ); |
49 | 49 | |
50 | - if ( !array_key_exists( 'mainsnak', $statementArray ) ) { |
|
51 | - $statementArray['mainsnak'] = [ 'hash' => $this->statement->getMainSnak()->getHash() ]; |
|
50 | + if (!array_key_exists('mainsnak', $statementArray)) { |
|
51 | + $statementArray['mainsnak'] = ['hash' => $this->statement->getMainSnak()->getHash()]; |
|
52 | 52 | } |
53 | 53 | $mainsnakArray = &$statementArray['mainsnak']; |
54 | 54 |