@@ -64,22 +64,22 @@ discard block |
||
64 | 64 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
65 | 65 | * @return CheckResult |
66 | 66 | */ |
67 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
68 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
69 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
67 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
68 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
69 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $parameters = []; |
73 | 73 | |
74 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
75 | - if ( $context->getType() === 'statement' ) { |
|
74 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
75 | + if ($context->getType() === 'statement') { |
|
76 | 76 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
77 | 77 | $context->getSnakStatement(), |
78 | 78 | true // ignore deprecated statements |
79 | 79 | ); |
80 | 80 | } else { |
81 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
82 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
81 | + if ($context->getSnak()->getType() !== 'value') { |
|
82 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
83 | 83 | } |
84 | 84 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
85 | 85 | $context->getEntity()->getId(), |
@@ -92,27 +92,27 @@ discard block |
||
92 | 92 | $otherEntities = $result->getArray(); |
93 | 93 | $metadata = $result->getMetadata(); |
94 | 94 | |
95 | - if ( $otherEntities === [] ) { |
|
95 | + if ($otherEntities === []) { |
|
96 | 96 | $status = CheckResult::STATUS_COMPLIANCE; |
97 | 97 | $message = null; |
98 | 98 | } else { |
99 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
99 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
100 | 100 | $status = CheckResult::STATUS_VIOLATION; |
101 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
102 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
101 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
102 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | 105 | $status = CheckResult::STATUS_TODO; |
106 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
107 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
106 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
107 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
108 | 108 | $metadata = Metadata::blank(); |
109 | 109 | } |
110 | 110 | |
111 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
112 | - ->withMetadata( $metadata ); |
|
111 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
112 | + ->withMetadata($metadata); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
116 | 116 | // no parameters |
117 | 117 | return []; |
118 | 118 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * @throws ConstraintParameterException |
86 | 86 | * @return CheckResult |
87 | 87 | */ |
88 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
88 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
89 | 89 | $parameters = []; |
90 | 90 | $constraintParameters = $constraint->getConstraintParameters(); |
91 | 91 | |
92 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
93 | - $parameters['pattern'] = [ $format ]; |
|
92 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
93 | + $parameters['pattern'] = [$format]; |
|
94 | 94 | |
95 | 95 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
96 | 96 | $constraintParameters |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | |
99 | 99 | $snak = $context->getSnak(); |
100 | 100 | |
101 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
101 | + if (!$snak instanceof PropertyValueSnak) { |
|
102 | 102 | // nothing to check |
103 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
103 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $dataValue = $snak->getDataValue(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * error handling: |
110 | 110 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
111 | 111 | */ |
112 | - switch ( $dataValue->getType() ) { |
|
112 | + switch ($dataValue->getType()) { |
|
113 | 113 | case 'string': |
114 | 114 | $text = $dataValue->getValue(); |
115 | 115 | break; |
@@ -118,49 +118,49 @@ discard block |
||
118 | 118 | $text = $dataValue->getText(); |
119 | 119 | break; |
120 | 120 | default: |
121 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
122 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
123 | - ->withDataValueType( 'string' ) |
|
124 | - ->withDataValueType( 'monolingualtext' ); |
|
125 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
121 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
122 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
123 | + ->withDataValueType('string') |
|
124 | + ->withDataValueType('monolingualtext'); |
|
125 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | if ( |
129 | - !( $this->sparqlHelper instanceof DummySparqlHelper ) && |
|
130 | - $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) |
|
129 | + !($this->sparqlHelper instanceof DummySparqlHelper) && |
|
130 | + $this->config->get('WBQualityConstraintsCheckFormatConstraint') |
|
131 | 131 | ) { |
132 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
132 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
133 | 133 | $message = null; |
134 | 134 | $status = CheckResult::STATUS_COMPLIANCE; |
135 | 135 | } else { |
136 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
137 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
138 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
139 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
140 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
136 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
137 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
138 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
139 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
140 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | 142 | } |
143 | 143 | } else { |
144 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
145 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
144 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
145 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
146 | 146 | $status = CheckResult::STATUS_TODO; |
147 | 147 | } |
148 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
148 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
151 | + public function checkConstraintParameters(Constraint $constraint) { |
|
152 | 152 | $constraintParameters = $constraint->getConstraintParameters(); |
153 | 153 | $exceptions = []; |
154 | 154 | try { |
155 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
156 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
156 | + } catch (ConstraintParameterException $e) { |
|
157 | 157 | $exceptions[] = $e; |
158 | 158 | } |
159 | 159 | try { |
160 | 160 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
161 | 161 | $constraintParameters |
162 | 162 | ); |
163 | - } catch ( ConstraintParameterException $e ) { |
|
163 | + } catch (ConstraintParameterException $e) { |
|
164 | 164 | $exceptions[] = $e; |
165 | 165 | } |
166 | 166 | return $exceptions; |
@@ -31,48 +31,48 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @param DatabaseUpdater $updater |
33 | 33 | */ |
34 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
34 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
35 | 35 | $updater->addExtensionTable( |
36 | 36 | 'wbqc_constraints', |
37 | - __DIR__ . '/../sql/create_wbqc_constraints.sql' |
|
37 | + __DIR__.'/../sql/create_wbqc_constraints.sql' |
|
38 | 38 | ); |
39 | 39 | $updater->addExtensionField( |
40 | 40 | 'wbqc_constraints', |
41 | 41 | 'constraint_id', |
42 | - __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
42 | + __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
43 | 43 | ); |
44 | 44 | $updater->addExtensionIndex( |
45 | 45 | 'wbqc_constraints', |
46 | 46 | 'wbqc_constraints_guid_uniq', |
47 | - __DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | + __DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | |
51 | - public static function onWikibaseChange( Change $change ) { |
|
51 | + public static function onWikibaseChange(Change $change) { |
|
52 | 52 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
53 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
54 | - self::isConstraintStatementsChange( $config, $change ) |
|
53 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
54 | + self::isConstraintStatementsChange($config, $change) |
|
55 | 55 | ) { |
56 | 56 | /** @var EntityChange $change */ |
57 | 57 | $title = Title::newMainPage(); |
58 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
58 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
59 | 59 | JobQueueGroup::singleton()->push( |
60 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
60 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
61 | 61 | ); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
66 | - if ( !( $change instanceof EntityChange ) || |
|
65 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
66 | + if (!($change instanceof EntityChange) || |
|
67 | 67 | $change->getAction() !== EntityChange::UPDATE || |
68 | - !( $change->getEntityId() instanceof PropertyId ) |
|
68 | + !($change->getEntityId() instanceof PropertyId) |
|
69 | 69 | ) { |
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $info = $change->getInfo(); |
74 | 74 | |
75 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
75 | + if (!array_key_exists('compactDiff', $info)) { |
|
76 | 76 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
77 | 77 | // so we only know that the change *might* affect the constraint statements |
78 | 78 | return true; |
@@ -81,46 +81,46 @@ discard block |
||
81 | 81 | /** @var EntityDiffChangedAspects $aspects */ |
82 | 82 | $aspects = $info['compactDiff']; |
83 | 83 | |
84 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
85 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
84 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
85 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
86 | 86 | } |
87 | 87 | |
88 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
88 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
89 | 89 | $repo = WikibaseRepo::getDefaultInstance(); |
90 | 90 | |
91 | 91 | $entityContentFactory = $repo->getEntityContentFactory(); |
92 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
93 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
94 | - if ( $entityId !== null ) { |
|
92 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
93 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
94 | + if ($entityId !== null) { |
|
95 | 95 | $resultsCache = ResultsCache::getDefaultInstance(); |
96 | - $resultsCache->delete( $entityId ); |
|
96 | + $resultsCache->delete($entityId); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
101 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
102 | 102 | $repo = WikibaseRepo::getDefaultInstance(); |
103 | 103 | |
104 | 104 | $lookup = $repo->getEntityNamespaceLookup(); |
105 | 105 | $title = $out->getTitle(); |
106 | - if ( $title === null ) { |
|
106 | + if ($title === null) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
110 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
113 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
117 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
118 | 118 | |
119 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
119 | + if (!$out->getUser()->isLoggedIn()) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
123 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | * @param User $user |
130 | 130 | * @param array[] &$prefs |
131 | 131 | */ |
132 | - public static function onGetBetaFeaturePreferences( User $user, array &$prefs ) { |
|
132 | + public static function onGetBetaFeaturePreferences(User $user, array &$prefs) { |
|
133 | 133 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
134 | - $extensionAssetsPath = $config->get( 'ExtensionAssetsPath' ); |
|
135 | - if ( $config->get( 'WBQualityConstraintsSuggestionsBetaFeature' ) ) { |
|
134 | + $extensionAssetsPath = $config->get('ExtensionAssetsPath'); |
|
135 | + if ($config->get('WBQualityConstraintsSuggestionsBetaFeature')) { |
|
136 | 136 | $prefs['constraint-suggestions'] = [ |
137 | 137 | 'label-message' => 'wbqc-beta-feature-label-message', |
138 | 138 | 'desc-message' => 'wbqc-beta-feature-description-message', |
@@ -156,20 +156,20 @@ discard block |
||
156 | 156 | * @param array &$vars |
157 | 157 | * @param OutputPage $out |
158 | 158 | */ |
159 | - public static function addVariables( &$vars, OutputPage $out ) { |
|
159 | + public static function addVariables(&$vars, OutputPage $out) { |
|
160 | 160 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
161 | 161 | |
162 | - $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
163 | - $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get( 'WBQualityConstraintsOneOfConstraintId' ); |
|
164 | - $vars['wbQualityConstraintsAllowedQualifierConstraintId'] = $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ); |
|
165 | - $vars['wbQualityConstraintsPropertyId'] = $config->get( 'WBQualityConstraintsPropertyId' ); |
|
166 | - $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
162 | + $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
163 | + $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get('WBQualityConstraintsOneOfConstraintId'); |
|
164 | + $vars['wbQualityConstraintsAllowedQualifierConstraintId'] = $config->get('WBQualityConstraintsAllowedQualifiersConstraintId'); |
|
165 | + $vars['wbQualityConstraintsPropertyId'] = $config->get('WBQualityConstraintsPropertyId'); |
|
166 | + $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
167 | 167 | |
168 | 168 | $vars['wbQualityConstraintsSuggestionsGloballyEnabled'] = false; |
169 | 169 | |
170 | - if ( $config->get( 'WBQualityConstraintsSuggestionsBetaFeature' ) && |
|
171 | - ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && |
|
172 | - BetaFeatures::isFeatureEnabled( $out->getUser(), 'constraint-suggestions' ) |
|
170 | + if ($config->get('WBQualityConstraintsSuggestionsBetaFeature') && |
|
171 | + ExtensionRegistry::getInstance()->isLoaded('BetaFeatures') && |
|
172 | + BetaFeatures::isFeatureEnabled($out->getUser(), 'constraint-suggestions') |
|
173 | 173 | ) { |
174 | 174 | $vars['wbQualityConstraintsSuggestionsGloballyEnabled'] = true; |
175 | 175 | } |