@@ -31,25 +31,25 @@ 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 ) { |
|
52 | - if ( !( $change instanceof EntityChange ) ) { |
|
51 | + public static function onWikibaseChange(Change $change) { |
|
52 | + if (!($change instanceof EntityChange)) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
@@ -58,44 +58,44 @@ discard block |
||
58 | 58 | |
59 | 59 | // If jobs are enabled and the results would be stored in some way run a job. |
60 | 60 | if ( |
61 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
62 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
61 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
62 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
63 | 63 | self::isSelectedForJobRunBasedOnPercentage() |
64 | 64 | ) { |
65 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
65 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
66 | 66 | JobQueueGroup::singleton()->push( |
67 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
67 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
72 | - self::isConstraintStatementsChange( $config, $change ) |
|
71 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
72 | + self::isConstraintStatementsChange($config, $change) |
|
73 | 73 | ) { |
74 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
74 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
75 | 75 | JobQueueGroup::singleton()->push( |
76 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
76 | + new JobSpecification('constraintsTableUpdate', $params) |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | private static function isSelectedForJobRunBasedOnPercentage() { |
82 | 82 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
83 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
83 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
84 | 84 | |
85 | - return mt_rand( 1, 100 ) <= $percentage; |
|
85 | + return mt_rand(1, 100) <= $percentage; |
|
86 | 86 | } |
87 | 87 | |
88 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
89 | - if ( !( $change instanceof EntityChange ) || |
|
88 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
89 | + if (!($change instanceof EntityChange) || |
|
90 | 90 | $change->getAction() !== EntityChange::UPDATE || |
91 | - !( $change->getEntityId() instanceof PropertyId ) |
|
91 | + !($change->getEntityId() instanceof PropertyId) |
|
92 | 92 | ) { |
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $info = $change->getInfo(); |
97 | 97 | |
98 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
98 | + if (!array_key_exists('compactDiff', $info)) { |
|
99 | 99 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
100 | 100 | // so we only know that the change *might* affect the constraint statements |
101 | 101 | return true; |
@@ -104,46 +104,46 @@ discard block |
||
104 | 104 | /** @var EntityDiffChangedAspects $aspects */ |
105 | 105 | $aspects = $info['compactDiff']; |
106 | 106 | |
107 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
108 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
107 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
108 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
109 | 109 | } |
110 | 110 | |
111 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
111 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
112 | 112 | $repo = WikibaseRepo::getDefaultInstance(); |
113 | 113 | |
114 | 114 | $entityContentFactory = $repo->getEntityContentFactory(); |
115 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
117 | - if ( $entityId !== null ) { |
|
115 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
116 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
117 | + if ($entityId !== null) { |
|
118 | 118 | $resultsCache = ResultsCache::getDefaultInstance(); |
119 | - $resultsCache->delete( $entityId ); |
|
119 | + $resultsCache->delete($entityId); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
124 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
125 | 125 | $repo = WikibaseRepo::getDefaultInstance(); |
126 | 126 | |
127 | 127 | $lookup = $repo->getEntityNamespaceLookup(); |
128 | 128 | $title = $out->getTitle(); |
129 | - if ( $title === null ) { |
|
129 | + if ($title === null) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
133 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
136 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
140 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
141 | 141 | |
142 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
142 | + if (!$out->getUser()->isLoggedIn()) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
146 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @param User $user |
153 | 153 | * @param array[] &$prefs |
154 | 154 | */ |
155 | - public static function onGetBetaFeaturePreferences( User $user, array &$prefs ) { |
|
155 | + public static function onGetBetaFeaturePreferences(User $user, array &$prefs) { |
|
156 | 156 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
157 | - $extensionAssetsPath = $config->get( 'ExtensionAssetsPath' ); |
|
158 | - if ( $config->get( 'WBQualityConstraintsSuggestionsBetaFeature' ) ) { |
|
157 | + $extensionAssetsPath = $config->get('ExtensionAssetsPath'); |
|
158 | + if ($config->get('WBQualityConstraintsSuggestionsBetaFeature')) { |
|
159 | 159 | $prefs['constraint-suggestions'] = [ |
160 | 160 | 'label-message' => 'wbqc-beta-feature-label-message', |
161 | 161 | 'desc-message' => 'wbqc-beta-feature-description-message', |
@@ -179,20 +179,20 @@ discard block |
||
179 | 179 | * @param array &$vars |
180 | 180 | * @param OutputPage $out |
181 | 181 | */ |
182 | - public static function addVariables( &$vars, OutputPage $out ) { |
|
182 | + public static function addVariables(&$vars, OutputPage $out) { |
|
183 | 183 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
184 | 184 | |
185 | - $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
186 | - $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get( 'WBQualityConstraintsOneOfConstraintId' ); |
|
187 | - $vars['wbQualityConstraintsAllowedQualifierConstraintId'] = $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ); |
|
188 | - $vars['wbQualityConstraintsPropertyId'] = $config->get( 'WBQualityConstraintsPropertyId' ); |
|
189 | - $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
185 | + $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
186 | + $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get('WBQualityConstraintsOneOfConstraintId'); |
|
187 | + $vars['wbQualityConstraintsAllowedQualifierConstraintId'] = $config->get('WBQualityConstraintsAllowedQualifiersConstraintId'); |
|
188 | + $vars['wbQualityConstraintsPropertyId'] = $config->get('WBQualityConstraintsPropertyId'); |
|
189 | + $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
190 | 190 | |
191 | 191 | $vars['wbQualityConstraintsSuggestionsGloballyEnabled'] = false; |
192 | 192 | |
193 | - if ( $config->get( 'WBQualityConstraintsSuggestionsBetaFeature' ) && |
|
194 | - ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && |
|
195 | - BetaFeatures::isFeatureEnabled( $out->getUser(), 'constraint-suggestions' ) |
|
193 | + if ($config->get('WBQualityConstraintsSuggestionsBetaFeature') && |
|
194 | + ExtensionRegistry::getInstance()->isLoaded('BetaFeatures') && |
|
195 | + BetaFeatures::isFeatureEnabled($out->getUser(), 'constraint-suggestions') |
|
196 | 196 | ) { |
197 | 197 | $vars['wbQualityConstraintsSuggestionsGloballyEnabled'] = true; |
198 | 198 | } |
@@ -42,25 +42,25 @@ discard block |
||
42 | 42 | * @param Title $title |
43 | 43 | * @param string[] $params should contain 'entityId' => 'Q1234' |
44 | 44 | */ |
45 | - public function __construct( Title $title, array $params ) { |
|
46 | - parent::__construct( self::COMMAND, $title, $params ); |
|
45 | + public function __construct(Title $title, array $params) { |
|
46 | + parent::__construct(self::COMMAND, $title, $params); |
|
47 | 47 | $this->removeDuplicates = true; |
48 | 48 | |
49 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
49 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
50 | 50 | $this->entityId = $params['entityId']; |
51 | 51 | |
52 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
52 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
53 | 53 | // This job should only ever be used when caching result sources are used. |
54 | - $this->setResultsSource( $resultSource ); |
|
54 | + $this->setResultsSource($resultSource); |
|
55 | 55 | |
56 | - $this->setEntityIdParser( WikibaseRepo::getDefaultInstance()->getEntityIdParser() ); |
|
56 | + $this->setEntityIdParser(WikibaseRepo::getDefaultInstance()->getEntityIdParser()); |
|
57 | 57 | } |
58 | 58 | |
59 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
59 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
60 | 60 | $this->resultsSource = $resultsSource; |
61 | 61 | } |
62 | 62 | |
63 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
63 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
64 | 64 | $this->entityIdParser = $parser; |
65 | 65 | } |
66 | 66 | |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function run() { |
73 | 73 | try { |
74 | - $entityId = $this->entityIdParser->parse( $this->entityId ); |
|
75 | - } catch ( EntityIdParsingException $e ) { |
|
74 | + $entityId = $this->entityIdParser->parse($this->entityId); |
|
75 | + } catch (EntityIdParsingException $e) { |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
79 | - $this->checkConstraints( $entityId ); |
|
79 | + $this->checkConstraints($entityId); |
|
80 | 80 | |
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | |
84 | - private function checkConstraints( EntityId $entityId ) { |
|
84 | + private function checkConstraints(EntityId $entityId) { |
|
85 | 85 | $this->resultsSource->getResults( |
86 | - [ $entityId ], |
|
86 | + [$entityId], |
|
87 | 87 | [], |
88 | 88 | null, |
89 | 89 | [] |