@@ -20,13 +20,13 @@ |
||
20 | 20 | * @param PropertyId $propertyId |
21 | 21 | * @return int |
22 | 22 | */ |
23 | - public function getPropertyCount( array $snaks, PropertyId $propertyId ) { |
|
24 | - return count( array_filter( |
|
23 | + public function getPropertyCount(array $snaks, PropertyId $propertyId) { |
|
24 | + return count(array_filter( |
|
25 | 25 | $snaks, |
26 | - function ( Snak $snak ) use ( $propertyId ) { |
|
27 | - return $snak->getPropertyId()->equals( $propertyId ); |
|
26 | + function(Snak $snak) use ($propertyId) { |
|
27 | + return $snak->getPropertyId()->equals($propertyId); |
|
28 | 28 | } |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return CheckResult |
56 | 56 | */ |
57 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
58 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
59 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
57 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
58 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
59 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $propertyId = $context->getSnak()->getPropertyId(); |
@@ -68,18 +68,18 @@ discard block |
||
68 | 68 | $propertyId |
69 | 69 | ); |
70 | 70 | |
71 | - if ( $propertyCount <= 1 ) { |
|
72 | - $message = wfMessage( "wbqc-violation-message-multi-value" )->escaped(); |
|
71 | + if ($propertyCount <= 1) { |
|
72 | + $message = wfMessage("wbqc-violation-message-multi-value")->escaped(); |
|
73 | 73 | $status = CheckResult::STATUS_VIOLATION; |
74 | 74 | } else { |
75 | 75 | $message = ''; |
76 | 76 | $status = CheckResult::STATUS_COMPLIANCE; |
77 | 77 | } |
78 | 78 | |
79 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
79 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
80 | 80 | } |
81 | 81 | |
82 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
82 | + public function checkConstraintParameters(Constraint $constraint) { |
|
83 | 83 | // no parameters |
84 | 84 | return []; |
85 | 85 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return CheckResult |
56 | 56 | */ |
57 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
58 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
59 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
57 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
58 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
59 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $propertyId = $context->getSnak()->getPropertyId(); |
@@ -68,18 +68,18 @@ discard block |
||
68 | 68 | $propertyId |
69 | 69 | ); |
70 | 70 | |
71 | - if ( $propertyCount > 1 ) { |
|
72 | - $message = wfMessage( "wbqc-violation-message-single-value" )->escaped(); |
|
71 | + if ($propertyCount > 1) { |
|
72 | + $message = wfMessage("wbqc-violation-message-single-value")->escaped(); |
|
73 | 73 | $status = CheckResult::STATUS_VIOLATION; |
74 | 74 | } else { |
75 | 75 | $message = ''; |
76 | 76 | $status = CheckResult::STATUS_COMPLIANCE; |
77 | 77 | } |
78 | 78 | |
79 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
79 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
80 | 80 | } |
81 | 81 | |
82 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
82 | + public function checkConstraintParameters(Constraint $constraint) { |
|
83 | 83 | // no parameters |
84 | 84 | return []; |
85 | 85 | } |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return bool |
32 | 32 | */ |
33 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
34 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
33 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
34 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
35 | 35 | return true; |
36 | 36 | } |
37 | 37 | |
38 | - public static function onWikibaseChange( Change $change ) { |
|
38 | + public static function onWikibaseChange(Change $change) { |
|
39 | 39 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
40 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
41 | - self::isConstraintStatementsChange( $config, $change ) |
|
40 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
41 | + self::isConstraintStatementsChange($config, $change) |
|
42 | 42 | ) { |
43 | 43 | /** @var EntityChange $change */ |
44 | 44 | $title = Title::newMainPage(); |
45 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
45 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
46 | 46 | JobQueueGroup::singleton()->push( |
47 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
47 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
53 | - if ( !( $change instanceof EntityChange ) || |
|
52 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
53 | + if (!($change instanceof EntityChange) || |
|
54 | 54 | $change->getAction() !== EntityChange::UPDATE || |
55 | - !( $change->getEntityId() instanceof PropertyId ) |
|
55 | + !($change->getEntityId() instanceof PropertyId) |
|
56 | 56 | ) { |
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $info = $change->getInfo(); |
61 | 61 | |
62 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
62 | + if (!array_key_exists('compactDiff', $info)) { |
|
63 | 63 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
64 | 64 | // so we only know that the change *might* affect the constraint statements |
65 | 65 | return true; |
@@ -68,18 +68,18 @@ discard block |
||
68 | 68 | /** @var EntityDiffChangedAspects $aspects */ |
69 | 69 | $aspects = $info['compactDiff']; |
70 | 70 | |
71 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
72 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
71 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
72 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
73 | 73 | } |
74 | 74 | |
75 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
75 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
76 | 76 | $repo = WikibaseRepo::getDefaultInstance(); |
77 | 77 | |
78 | 78 | $entityContentFactory = $repo->getEntityContentFactory(); |
79 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
80 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
79 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
80 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
81 | 81 | $resultsCache = ResultsCache::getDefaultInstance(); |
82 | - $resultsCache->delete( $entityId ); |
|
82 | + $resultsCache->delete($entityId); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | * @param int $timestamp UTC timestamp (seconds since the Epoch) |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public static function isGadgetEnabledForUserName( $userName, $timestamp ) { |
|
91 | + public static function isGadgetEnabledForUserName($userName, $timestamp) { |
|
92 | 92 | $initial = $userName[0]; |
93 | 93 | |
94 | - if ( $initial === 'Z' ) { |
|
94 | + if ($initial === 'Z') { |
|
95 | 95 | $firstWeek = 0; |
96 | - } elseif ( $initial >= 'W' && $initial < 'Z' ) { |
|
96 | + } elseif ($initial >= 'W' && $initial < 'Z') { |
|
97 | 97 | $firstWeek = 1; |
98 | - } elseif ( $initial >= 'T' && $initial < 'W' ) { |
|
98 | + } elseif ($initial >= 'T' && $initial < 'W') { |
|
99 | 99 | $firstWeek = 2; |
100 | - } elseif ( $initial >= 'N' && $initial < 'T' ) { |
|
100 | + } elseif ($initial >= 'N' && $initial < 'T') { |
|
101 | 101 | $firstWeek = 3; |
102 | - } elseif ( $initial >= 'E' && $initial < 'N' ) { |
|
102 | + } elseif ($initial >= 'E' && $initial < 'N') { |
|
103 | 103 | $firstWeek = 4; |
104 | 104 | } else { |
105 | 105 | $firstWeek = 5; |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | return $timestamp >= $threshold; |
118 | 118 | } |
119 | 119 | |
120 | - public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) { |
|
120 | + public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { |
|
121 | 121 | $repo = WikibaseRepo::getDefaultInstance(); |
122 | 122 | |
123 | 123 | $lookup = $repo->getEntityNamespaceLookup(); |
124 | 124 | $title = $out->getTitle(); |
125 | - if ( $title === null ) { |
|
125 | + if ($title === null) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
129 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
132 | + if (!$out->getUser()->isLoggedIn()) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | - if ( !$out->getJsConfigVars()['wbIsEditView'] ) { |
|
135 | + if (!$out->getJsConfigVars()['wbIsEditView']) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - if ( self::isGadgetEnabledForUserName( $out->getUser()->getName(), time() ) ) { |
|
140 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
139 | + if (self::isGadgetEnabledForUserName($out->getUser()->getName(), time())) { |
|
140 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | * @throws ConstraintParameterException |
84 | 84 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
85 | 85 | */ |
86 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
87 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
86 | + private function parseConstraintParameters(Constraint $constraint) { |
|
87 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
88 | 88 | $constraint->getConstraintParameters(), |
89 | 89 | $constraint->getConstraintTypeItemId(), |
90 | 90 | 'quantity' |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | $constraint->getConstraintTypeItemId() |
95 | 95 | ); |
96 | 96 | |
97 | - if ( $min !== null ) { |
|
98 | - $parameters['minimum_quantity'] = [ $min ]; |
|
97 | + if ($min !== null) { |
|
98 | + $parameters['minimum_quantity'] = [$min]; |
|
99 | 99 | } |
100 | - if ( $max !== null ) { |
|
101 | - $parameters['maximum_quantity'] = [ $max ]; |
|
100 | + if ($max !== null) { |
|
101 | + $parameters['maximum_quantity'] = [$max]; |
|
102 | 102 | } |
103 | - $parameters['property'] = [ $property ]; |
|
103 | + $parameters['property'] = [$property]; |
|
104 | 104 | |
105 | - return [ $min, $max, $property, $parameters ]; |
|
105 | + return [$min, $max, $property, $parameters]; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool |
114 | 114 | */ |
115 | - private function rangeInYears( $min, $max ) { |
|
116 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
115 | + private function rangeInYears($min, $max) { |
|
116 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
117 | 117 | |
118 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
118 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
119 | 119 | return true; |
120 | 120 | } |
121 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
121 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
122 | 122 | return true; |
123 | 123 | } |
124 | 124 | |
@@ -134,57 +134,56 @@ discard block |
||
134 | 134 | * @throws ConstraintParameterException |
135 | 135 | * @return CheckResult |
136 | 136 | */ |
137 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
138 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
139 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
137 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
138 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
139 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | $parameters = []; |
143 | 143 | |
144 | 144 | $snak = $context->getSnak(); |
145 | 145 | |
146 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
146 | + if (!$snak instanceof PropertyValueSnak) { |
|
147 | 147 | // nothing to check |
148 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
148 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $minuend = $snak->getDataValue(); |
152 | 152 | |
153 | 153 | /** @var PropertyId $property */ |
154 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
154 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
155 | 155 | |
156 | 156 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
157 | - foreach ( $context->getSnakGroup() as $otherSnak ) { |
|
157 | + foreach ($context->getSnakGroup() as $otherSnak) { |
|
158 | 158 | if ( |
159 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
159 | + !$property->equals($otherSnak->getPropertyId()) || |
|
160 | 160 | !$otherSnak instanceof PropertyValueSnak |
161 | 161 | ) { |
162 | 162 | continue; |
163 | 163 | } |
164 | 164 | |
165 | 165 | $subtrahend = $otherSnak->getDataValue(); |
166 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
167 | - $diff = $this->rangeInYears( $min, $max ) ? |
|
168 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
169 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
166 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
167 | + $diff = $this->rangeInYears($min, $max) ? |
|
168 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
170 | 169 | |
171 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
172 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
170 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
171 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
173 | 172 | ) { |
174 | 173 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
175 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
176 | - $message = wfMessage( "wbqc-violation-message-diff-within-range$openness" ); |
|
174 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
175 | + $message = wfMessage("wbqc-violation-message-diff-within-range$openness"); |
|
177 | 176 | $message->rawParams( |
178 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
179 | - $this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ), |
|
180 | - $this->constraintParameterRenderer->formatEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ), |
|
181 | - $this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT ) |
|
177 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
178 | + $this->constraintParameterRenderer->formatDataValue($minuend, Role::OBJECT), |
|
179 | + $this->constraintParameterRenderer->formatEntityId($otherSnak->getPropertyId(), Role::PREDICATE), |
|
180 | + $this->constraintParameterRenderer->formatDataValue($subtrahend, Role::OBJECT) |
|
182 | 181 | ); |
183 | - if ( $min !== null ) { |
|
184 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
182 | + if ($min !== null) { |
|
183 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
185 | 184 | } |
186 | - if ( $max !== null ) { |
|
187 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
185 | + if ($max !== null) { |
|
186 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
188 | 187 | } |
189 | 188 | $message = $message->escaped(); |
190 | 189 | $status = CheckResult::STATUS_VIOLATION; |
@@ -193,19 +192,19 @@ discard block |
||
193 | 192 | $status = CheckResult::STATUS_COMPLIANCE; |
194 | 193 | } |
195 | 194 | } else { |
196 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-must-have-equal-types" )->escaped(); |
|
195 | + $message = wfMessage("wbqc-violation-message-diff-within-range-must-have-equal-types")->escaped(); |
|
197 | 196 | $status = CheckResult::STATUS_VIOLATION; |
198 | 197 | } |
199 | 198 | |
200 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
199 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
201 | 200 | } |
202 | 201 | |
203 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-property-must-exist" )->escaped(); |
|
202 | + $message = wfMessage("wbqc-violation-message-diff-within-range-property-must-exist")->escaped(); |
|
204 | 203 | $status = CheckResult::STATUS_VIOLATION; |
205 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
204 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
206 | 205 | } |
207 | 206 | |
208 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
207 | + public function checkConstraintParameters(Constraint $constraint) { |
|
209 | 208 | $constraintParameters = $constraint->getConstraintParameters(); |
210 | 209 | $exceptions = []; |
211 | 210 | try { |
@@ -214,12 +213,12 @@ discard block |
||
214 | 213 | $constraint->getConstraintTypeItemId(), |
215 | 214 | 'quantity' |
216 | 215 | ); |
217 | - } catch ( ConstraintParameterException $e ) { |
|
216 | + } catch (ConstraintParameterException $e) { |
|
218 | 217 | $exceptions[] = $e; |
219 | 218 | } |
220 | 219 | try { |
221 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
222 | - } catch ( ConstraintParameterException $e ) { |
|
220 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
221 | + } catch (ConstraintParameterException $e) { |
|
223 | 222 | $exceptions[] = $e; |
224 | 223 | } |
225 | 224 | return $exceptions; |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | private $cache; |
20 | 20 | |
21 | 21 | public static function getDefaultInstance() { |
22 | - return new self( MediaWikiServices::getInstance()->getMainWANObjectCache() ); |
|
22 | + return new self(MediaWikiServices::getInstance()->getMainWANObjectCache()); |
|
23 | 23 | } |
24 | 24 | |
25 | - public function __construct( WANObjectCache $cache ) { |
|
25 | + public function __construct(WANObjectCache $cache) { |
|
26 | 26 | $this->cache = $cache; |
27 | 27 | } |
28 | 28 | |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | * @param string|null $languageCode defaults to user language |
32 | 32 | * @return string cache key |
33 | 33 | */ |
34 | - public function makeKey( EntityId $entityId, $languageCode = null ) { |
|
34 | + public function makeKey(EntityId $entityId, $languageCode = null) { |
|
35 | 35 | global $wgLang, $wgContLang; |
36 | - if ( $languageCode === null ) { |
|
36 | + if ($languageCode === null) { |
|
37 | 37 | $languageCode = $wgLang->getCode(); |
38 | 38 | } |
39 | - if ( !Language::isKnownLanguageTag( $languageCode ) && $languageCode !== 'qqx' ) { |
|
39 | + if (!Language::isKnownLanguageTag($languageCode) && $languageCode !== 'qqx') { |
|
40 | 40 | $languageCode = $wgContLang->getCode(); |
41 | 41 | } |
42 | 42 | return $this->cache->makeKey( |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | * @param float &$asOf |
56 | 56 | * @return mixed |
57 | 57 | */ |
58 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null ) { |
|
59 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $asOf ); |
|
58 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null) { |
|
59 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $asOf); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,20 +66,20 @@ discard block |
||
66 | 66 | * @param array $opts |
67 | 67 | * @return bool |
68 | 68 | */ |
69 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
70 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
69 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
70 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @param EntityId $key |
75 | 75 | * @return bool |
76 | 76 | */ |
77 | - public function delete( EntityId $key ) { |
|
77 | + public function delete(EntityId $key) { |
|
78 | 78 | $ok = true; |
79 | - $languageCodes = array_keys( Language::fetchLanguageNames( null, 'all' ) ); |
|
79 | + $languageCodes = array_keys(Language::fetchLanguageNames(null, 'all')); |
|
80 | 80 | $languageCodes[] = 'qqx'; |
81 | - foreach ( $languageCodes as $languageCode ) { |
|
82 | - $ok = $this->cache->delete( $this->makeKey( $key, $languageCode ) ) && $ok; |
|
81 | + foreach ($languageCodes as $languageCode) { |
|
82 | + $ok = $this->cache->delete($this->makeKey($key, $languageCode)) && $ok; |
|
83 | 83 | } |
84 | 84 | return $ok; |
85 | 85 | } |
@@ -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 | |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @throws DBUnexpectedError |
105 | 105 | */ |
106 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
107 | - $db = wfGetDB( DB_MASTER ); |
|
106 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
107 | + $db = wfGetDB(DB_MASTER); |
|
108 | 108 | $db->delete( |
109 | 109 | 'wbqc_constraints', |
110 | 110 | [ |
111 | 111 | 'pid' => $propertyId->getNumericId(), |
112 | 112 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
113 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
113 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
114 | 114 | ] |
115 | 115 | ); |
116 | 116 | } |
@@ -121,20 +121,20 @@ discard block |
||
121 | 121 | * @throws InvalidArgumentException |
122 | 122 | * @throws DBUnexpectedError |
123 | 123 | */ |
124 | - public function deleteAll( $batchSize = 1000 ) { |
|
125 | - if ( !is_int( $batchSize ) ) { |
|
124 | + public function deleteAll($batchSize = 1000) { |
|
125 | + if (!is_int($batchSize)) { |
|
126 | 126 | throw new InvalidArgumentException(); |
127 | 127 | } |
128 | - $db = wfGetDB( DB_MASTER ); |
|
129 | - if ( $db->getType() === 'sqlite' ) { |
|
130 | - $db->delete( 'wbqc_constraints', '*' ); |
|
128 | + $db = wfGetDB(DB_MASTER); |
|
129 | + if ($db->getType() === 'sqlite') { |
|
130 | + $db->delete('wbqc_constraints', '*'); |
|
131 | 131 | } else { |
132 | 132 | do { |
133 | - $db->commit( __METHOD__, 'flush' ); |
|
133 | + $db->commit(__METHOD__, 'flush'); |
|
134 | 134 | wfGetLBFactory()->waitForReplication(); |
135 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
136 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
137 | - } while ( $db->affectedRows() > 0 ); |
|
135 | + $table = $db->tableName('wbqc_constraints'); |
|
136 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
137 | + } while ($db->affectedRows() > 0); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -143,26 +143,26 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return Constraint[] |
145 | 145 | */ |
146 | - private function convertToConstraints( IResultWrapper $results ) { |
|
146 | + private function convertToConstraints(IResultWrapper $results) { |
|
147 | 147 | $constraints = []; |
148 | - foreach ( $results as $result ) { |
|
148 | + foreach ($results as $result) { |
|
149 | 149 | $constraintTypeItemId = $result->constraint_type_qid; |
150 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
150 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
151 | 151 | |
152 | - if ( $constraintParameters === null ) { |
|
152 | + if ($constraintParameters === null) { |
|
153 | 153 | // T171295 |
154 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
155 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
155 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
156 | 156 | 'method' => __METHOD__, |
157 | 157 | 'constraintId' => $result->constraint_guid, |
158 | 158 | 'constraintParameters' => $result->constraint_parameters, |
159 | - ] ); |
|
160 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
159 | + ]); |
|
160 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $constraints[] = new Constraint( |
164 | 164 | $result->constraint_guid, |
165 | - PropertyId::newFromNumber( $result->pid ), |
|
165 | + PropertyId::newFromNumber($result->pid), |
|
166 | 166 | $constraintTypeItemId, |
167 | 167 | $constraintParameters |
168 | 168 | ); |
@@ -9,10 +9,10 @@ discard block |
||
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | 11 | // @codeCoverageIgnoreStart |
12 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
13 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
12 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
13 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
14 | 14 | |
15 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
15 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
16 | 16 | // @codeCoverageIgnoreEnd |
17 | 17 | |
18 | 18 | /** |
@@ -38,31 +38,31 @@ discard block |
||
38 | 38 | parent::__construct(); |
39 | 39 | $repo = WikibaseRepo::getDefaultInstance(); |
40 | 40 | $this->propertyInfoLookup = $repo->getStore()->getPropertyInfoLookup(); |
41 | - $this->newUpdateConstraintsTableJob = function ( $propertyIdSerialization ) { |
|
41 | + $this->newUpdateConstraintsTableJob = function($propertyIdSerialization) { |
|
42 | 42 | return UpdateConstraintsTableJob::newFromGlobalState( |
43 | 43 | Title::newMainPage(), |
44 | - [ 'propertyId' => $propertyIdSerialization ] |
|
44 | + ['propertyId' => $propertyIdSerialization] |
|
45 | 45 | ); |
46 | 46 | }; |
47 | 47 | |
48 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
49 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
48 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
49 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function execute() { |
53 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
54 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
53 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
54 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - foreach ( $this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
59 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
60 | - $startTime = microtime( true ); |
|
61 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
58 | + foreach ($this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
59 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
60 | + $startTime = microtime(true); |
|
61 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
62 | 62 | $job->run(); |
63 | - $endTime = microtime( true ); |
|
64 | - $millis = ( $endTime - $startTime ) * 1000; |
|
65 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
63 | + $endTime = microtime(true); |
|
64 | + $millis = ($endTime - $startTime) * 1000; |
|
65 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 |
@@ -31,21 +31,21 @@ |
||
31 | 31 | public function __construct( |
32 | 32 | $messageKey |
33 | 33 | ) { |
34 | - if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) { |
|
34 | + if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) { |
|
35 | 35 | throw new InvalidArgumentException( |
36 | - 'ViolationMessage key ⧼' . |
|
37 | - $messageKey . |
|
38 | - '⧽ should start with "' . |
|
39 | - self::MESSAGE_KEY_PREFIX . |
|
36 | + 'ViolationMessage key ⧼'. |
|
37 | + $messageKey. |
|
38 | + '⧽ should start with "'. |
|
39 | + self::MESSAGE_KEY_PREFIX. |
|
40 | 40 | '".' |
41 | 41 | ); |
42 | 42 | } |
43 | 43 | |
44 | - $this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) ); |
|
44 | + $this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX)); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function getMessageKey() { |
48 | - return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix; |
|
48 | + return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | } |