Completed
Push — master ( 8d9042...565f83 )
by
unknown
01:56
created
src/WikibaseQualityConstraintsHooks.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@  discard block
 block discarded – undo
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
 
@@ -57,48 +57,48 @@  discard block
 block discarded – undo
57 57
 
58 58
 		// If jobs are enabled and the results would be stored in some way run a job.
59 59
 		if (
60
-			$config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) &&
61
-			$config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) &&
60
+			$config->get('WBQualityConstraintsEnableConstraintsCheckJobs') &&
61
+			$config->get('WBQualityConstraintsCacheCheckConstraintsResults') &&
62 62
 			self::isSelectedForJobRunBasedOnPercentage()
63 63
 		) {
64
-			$params = [ 'entityId' => $change->getEntityId()->getSerialization() ];
64
+			$params = ['entityId' => $change->getEntityId()->getSerialization()];
65 65
 			JobQueueGroup::singleton()->lazyPush(
66
-				new JobSpecification( CheckConstraintsJob::COMMAND, $params )
66
+				new JobSpecification(CheckConstraintsJob::COMMAND, $params)
67 67
 			);
68 68
 		}
69 69
 
70
-		if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) &&
71
-			self::isConstraintStatementsChange( $config, $change )
70
+		if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') &&
71
+			self::isConstraintStatementsChange($config, $change)
72 72
 		) {
73
-			$params = [ 'propertyId' => $change->getEntityId()->getSerialization() ];
73
+			$params = ['propertyId' => $change->getEntityId()->getSerialization()];
74 74
 			$metadata = $change->getMetadata();
75
-			if ( array_key_exists( 'rev_id', $metadata ) ) {
75
+			if (array_key_exists('rev_id', $metadata)) {
76 76
 				$params['revisionId'] = $metadata['rev_id'];
77 77
 			}
78 78
 			JobQueueGroup::singleton()->push(
79
-				new JobSpecification( 'constraintsTableUpdate', $params )
79
+				new JobSpecification('constraintsTableUpdate', $params)
80 80
 			);
81 81
 		}
82 82
 	}
83 83
 
84 84
 	private static function isSelectedForJobRunBasedOnPercentage() {
85 85
 		$config = MediaWikiServices::getInstance()->getMainConfig();
86
-		$percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' );
86
+		$percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio');
87 87
 
88
-		return mt_rand( 1, 100 ) <= $percentage;
88
+		return mt_rand(1, 100) <= $percentage;
89 89
 	}
90 90
 
91
-	public static function isConstraintStatementsChange( Config $config, Change $change ) {
92
-		if ( !( $change instanceof EntityChange ) ||
91
+	public static function isConstraintStatementsChange(Config $config, Change $change) {
92
+		if (!($change instanceof EntityChange) ||
93 93
 			 $change->getAction() !== EntityChange::UPDATE ||
94
-			 !( $change->getEntityId() instanceof PropertyId )
94
+			 !($change->getEntityId() instanceof PropertyId)
95 95
 		) {
96 96
 			return false;
97 97
 		}
98 98
 
99 99
 		$info = $change->getInfo();
100 100
 
101
-		if ( !array_key_exists( 'compactDiff', $info ) ) {
101
+		if (!array_key_exists('compactDiff', $info)) {
102 102
 			// the non-compact diff ($info['diff']) does not contain statement diffs (T110996),
103 103
 			// so we only know that the change *might* affect the constraint statements
104 104
 			return true;
@@ -107,47 +107,47 @@  discard block
 block discarded – undo
107 107
 		/** @var EntityDiffChangedAspects $aspects */
108 108
 		$aspects = $info['compactDiff'];
109 109
 
110
-		$propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' );
111
-		return in_array( $propertyConstraintId, $aspects->getStatementChanges() );
110
+		$propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId');
111
+		return in_array($propertyConstraintId, $aspects->getStatementChanges());
112 112
 	}
113 113
 
114
-	public static function onArticlePurge( WikiPage $wikiPage ) {
114
+	public static function onArticlePurge(WikiPage $wikiPage) {
115 115
 		$repo = WikibaseRepo::getDefaultInstance();
116 116
 
117 117
 		$entityContentFactory = $repo->getEntityContentFactory();
118
-		if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) {
118
+		if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) {
119 119
 			$entityIdLookup = $repo->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
 		$repo = WikibaseRepo::getDefaultInstance();
130 130
 
131 131
 		$lookup = $repo->getEntityNamespaceLookup();
132 132
 		$title = $out->getTitle();
133
-		if ( $title === null ) {
133
+		if ($title === null) {
134 134
 			return;
135 135
 		}
136 136
 
137
-		if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) {
137
+		if (!$lookup->isNamespaceWithEntities($title->getNamespace())) {
138 138
 			return;
139 139
 		}
140
-		if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) {
140
+		if (empty($out->getJsConfigVars()['wbIsEditView'])) {
141 141
 			return;
142 142
 		}
143 143
 
144
-		$out->addModules( 'wikibase.quality.constraints.suggestions' );
144
+		$out->addModules('wikibase.quality.constraints.suggestions');
145 145
 
146
-		if ( !$out->getUser()->isRegistered() ) {
146
+		if (!$out->getUser()->isRegistered()) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		$out->addModules( 'wikibase.quality.constraints.gadget' );
150
+		$out->addModules('wikibase.quality.constraints.gadget');
151 151
 	}
152 152
 
153 153
 }
Please login to merge, or discard this patch.