@@ -28,27 +28,27 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * @param DatabaseUpdater $updater |
| 30 | 30 | */ |
| 31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
| 32 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
| 31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
| 32 | + $dir = dirname(__DIR__).'/sql/'; |
|
| 33 | 33 | |
| 34 | 34 | $updater->addExtensionTable( |
| 35 | 35 | 'wbqc_constraints', |
| 36 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
| 36 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
| 37 | 37 | ); |
| 38 | 38 | $updater->addExtensionField( |
| 39 | 39 | 'wbqc_constraints', |
| 40 | 40 | 'constraint_id', |
| 41 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
| 41 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
| 42 | 42 | ); |
| 43 | 43 | $updater->addExtensionIndex( |
| 44 | 44 | 'wbqc_constraints', |
| 45 | 45 | 'wbqc_constraints_guid_uniq', |
| 46 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
| 46 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
| 47 | 47 | ); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public static function onWikibaseChange( Change $change ) { |
|
| 51 | - if ( !( $change instanceof EntityChange ) ) { |
|
| 50 | + public static function onWikibaseChange(Change $change) { |
|
| 51 | + if (!($change instanceof EntityChange)) { |
|
| 52 | 52 | return; |
| 53 | 53 | } |
| 54 | 54 | /** @var EntityChange $change */ |
@@ -59,48 +59,48 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // If jobs are enabled and the results would be stored in some way run a job. |
| 61 | 61 | if ( |
| 62 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
| 63 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
| 62 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
| 63 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
| 64 | 64 | self::isSelectedForJobRunBasedOnPercentage() |
| 65 | 65 | ) { |
| 66 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
| 66 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
| 67 | 67 | $jobQueueGroup->lazyPush( |
| 68 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
| 68 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
| 69 | 69 | ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
| 73 | - self::isConstraintStatementsChange( $config, $change ) |
|
| 72 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
| 73 | + self::isConstraintStatementsChange($config, $change) |
|
| 74 | 74 | ) { |
| 75 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
| 75 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
| 76 | 76 | $metadata = $change->getMetadata(); |
| 77 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
| 77 | + if (array_key_exists('rev_id', $metadata)) { |
|
| 78 | 78 | $params['revisionId'] = $metadata['rev_id']; |
| 79 | 79 | } |
| 80 | 80 | $jobQueueGroup->push( |
| 81 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
| 81 | + new JobSpecification('constraintsTableUpdate', $params) |
|
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | private static function isSelectedForJobRunBasedOnPercentage() { |
| 87 | 87 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 88 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
| 88 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
| 89 | 89 | |
| 90 | - return mt_rand( 1, 100 ) <= $percentage; |
|
| 90 | + return mt_rand(1, 100) <= $percentage; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
| 94 | - if ( !( $change instanceof EntityChange ) || |
|
| 93 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
| 94 | + if (!($change instanceof EntityChange) || |
|
| 95 | 95 | $change->getAction() !== EntityChange::UPDATE || |
| 96 | - !( $change->getEntityId() instanceof NumericPropertyId ) |
|
| 96 | + !($change->getEntityId() instanceof NumericPropertyId) |
|
| 97 | 97 | ) { |
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $info = $change->getInfo(); |
| 102 | 102 | |
| 103 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
| 103 | + if (!array_key_exists('compactDiff', $info)) { |
|
| 104 | 104 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
| 105 | 105 | // so we only know that the change *might* affect the constraint statements |
| 106 | 106 | return true; |
@@ -109,50 +109,50 @@ discard block |
||
| 109 | 109 | /** @var EntityDiffChangedAspects $aspects */ |
| 110 | 110 | $aspects = $info['compactDiff']; |
| 111 | 111 | |
| 112 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
| 113 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
| 112 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
| 113 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
| 116 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
| 117 | 117 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
| 118 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
| 118 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
| 119 | 119 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
| 120 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
| 121 | - if ( $entityId !== null ) { |
|
| 120 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
| 121 | + if ($entityId !== null) { |
|
| 122 | 122 | $resultsCache = ResultsCache::getDefaultInstance(); |
| 123 | - $resultsCache->delete( $entityId ); |
|
| 123 | + $resultsCache->delete($entityId); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
| 128 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
| 129 | 129 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
| 130 | 130 | $title = $out->getTitle(); |
| 131 | - if ( $title === null ) { |
|
| 131 | + if ($title === null) { |
|
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
| 135 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
| 138 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
| 139 | 139 | return; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | $services = MediaWikiServices::getInstance(); |
| 143 | 143 | $config = $services->getMainConfig(); |
| 144 | 144 | |
| 145 | - $isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
|
| 146 | - $services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView(); |
|
| 147 | - if ( $isMobileView ) { |
|
| 145 | + $isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') && |
|
| 146 | + $services->getService('MobileFrontend.Context')->shouldDisplayMobileView(); |
|
| 147 | + if ($isMobileView) { |
|
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
| 151 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
| 152 | 152 | |
| 153 | - if ( $config->get( 'WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers' ) |
|
| 154 | - || $out->getUser()->isRegistered() ) { |
|
| 155 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
| 153 | + if ($config->get('WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers') |
|
| 154 | + || $out->getUser()->isRegistered()) { |
|
| 155 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |