@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return CheckResult |
57 | 57 | */ |
58 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
59 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
60 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
58 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
59 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
60 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $propertyId = $context->getSnak()->getPropertyId(); |
@@ -69,18 +69,18 @@ discard block |
||
69 | 69 | $propertyId |
70 | 70 | ); |
71 | 71 | |
72 | - if ( $propertyCount > 1 ) { |
|
73 | - $message = new ViolationMessage( 'wbqc-violation-message-single-value' ); |
|
72 | + if ($propertyCount > 1) { |
|
73 | + $message = new ViolationMessage('wbqc-violation-message-single-value'); |
|
74 | 74 | $status = CheckResult::STATUS_VIOLATION; |
75 | 75 | } else { |
76 | 76 | $message = null; |
77 | 77 | $status = CheckResult::STATUS_COMPLIANCE; |
78 | 78 | } |
79 | 79 | |
80 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
80 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
81 | 81 | } |
82 | 82 | |
83 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
83 | + public function checkConstraintParameters(Constraint $constraint) { |
|
84 | 84 | // no parameters |
85 | 85 | return []; |
86 | 86 | } |
@@ -78,22 +78,22 @@ discard block |
||
78 | 78 | * @return array first element is the namespace number (default namespace for TitleParser), |
79 | 79 | * second element is a string to prepend to the title before giving it to the TitleParser |
80 | 80 | */ |
81 | - private function getCommonsNamespace( $namespace ) { |
|
81 | + private function getCommonsNamespace($namespace) { |
|
82 | 82 | // for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php, |
83 | 83 | // 'wgExtraNamespaces' key, 'commonswiki' subkey |
84 | - switch ( $namespace ) { |
|
84 | + switch ($namespace) { |
|
85 | 85 | case '': |
86 | - return [ NS_MAIN, '' ]; |
|
86 | + return [NS_MAIN, '']; |
|
87 | 87 | case 'Creator': |
88 | - return [ 100, '' ]; |
|
88 | + return [100, '']; |
|
89 | 89 | case 'TimedText': |
90 | - return [ 102, '' ]; |
|
90 | + return [102, '']; |
|
91 | 91 | case 'Sequence': |
92 | - return [ 104, '' ]; |
|
92 | + return [104, '']; |
|
93 | 93 | case 'Institution': |
94 | - return [ 106, '' ]; |
|
94 | + return [106, '']; |
|
95 | 95 | default: |
96 | - return [ NS_MAIN, $namespace . ':' ]; |
|
96 | + return [NS_MAIN, $namespace.':']; |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
@@ -106,17 +106,17 @@ discard block |
||
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | * @return CheckResult |
108 | 108 | */ |
109 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
109 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
110 | 110 | $parameters = []; |
111 | 111 | $constraintParameters = $constraint->getConstraintParameters(); |
112 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
113 | - $parameters['namespace'] = [ $namespace ]; |
|
112 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
113 | + $parameters['namespace'] = [$namespace]; |
|
114 | 114 | |
115 | 115 | $snak = $context->getSnak(); |
116 | 116 | |
117 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
117 | + if (!$snak instanceof PropertyValueSnak) { |
|
118 | 118 | // nothing to check |
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $dataValue = $snak->getDataValue(); |
@@ -126,49 +126,49 @@ discard block |
||
126 | 126 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
127 | 127 | * parameter $namespace can be null, works for commons galleries |
128 | 128 | */ |
129 | - if ( $dataValue->getType() !== 'string' ) { |
|
130 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
129 | + if ($dataValue->getType() !== 'string') { |
|
130 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
131 | 131 | ->rawParams( |
132 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
133 | - wfMessage( 'datatypes-type-string' )->escaped() |
|
132 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
133 | + wfMessage('datatypes-type-string')->escaped() |
|
134 | 134 | ) |
135 | 135 | ->escaped(); |
136 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
136 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $commonsLink = $dataValue->getValue(); |
140 | 140 | |
141 | 141 | try { |
142 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
143 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
142 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
143 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
144 | 144 | } |
145 | - list( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
146 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
147 | - if ( $this->pageExists( $title ) ) { |
|
145 | + list($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
146 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
147 | + if ($this->pageExists($title)) { |
|
148 | 148 | $message = null; |
149 | 149 | $status = CheckResult::STATUS_COMPLIANCE; |
150 | 150 | } else { |
151 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
152 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
151 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
152 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
153 | 153 | } else { |
154 | - $message = new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ); |
|
154 | + $message = new ViolationMessage('wbqc-violation-message-commons-link-no-existent'); |
|
155 | 155 | $status = CheckResult::STATUS_VIOLATION; |
156 | 156 | } |
157 | 157 | } |
158 | - } catch ( MalformedTitleException $e ) { |
|
159 | - $message = new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ); |
|
158 | + } catch (MalformedTitleException $e) { |
|
159 | + $message = new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed'); |
|
160 | 160 | $status = CheckResult::STATUS_VIOLATION; |
161 | 161 | } |
162 | 162 | |
163 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
163 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
164 | 164 | } |
165 | 165 | |
166 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
166 | + public function checkConstraintParameters(Constraint $constraint) { |
|
167 | 167 | $constraintParameters = $constraint->getConstraintParameters(); |
168 | 168 | $exceptions = []; |
169 | 169 | try { |
170 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
171 | - } catch ( ConstraintParameterException $e ) { |
|
170 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
171 | + } catch (ConstraintParameterException $e) { |
|
172 | 172 | $exceptions[] = $e; |
173 | 173 | } |
174 | 174 | return $exceptions; |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return bool |
181 | 181 | */ |
182 | - private function pageExists( TitleValue $title ) { |
|
182 | + private function pageExists(TitleValue $title) { |
|
183 | 183 | $commonsWikiId = 'commonswiki'; |
184 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
184 | + if (defined('MW_PHPUNIT_TEST')) { |
|
185 | 185 | $commonsWikiId = false; |
186 | 186 | } |
187 | 187 | |
188 | - $dbLoadBalancer = wfGetLB( $commonsWikiId ); |
|
188 | + $dbLoadBalancer = wfGetLB($commonsWikiId); |
|
189 | 189 | $dbConnection = $dbLoadBalancer->getConnection( |
190 | 190 | DB_REPLICA, false, $commonsWikiId ); |
191 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
191 | + $row = $dbConnection->selectRow('page', '*', [ |
|
192 | 192 | 'page_title' => $title->getDBkey(), |
193 | 193 | 'page_namespace' => $title->getNamespace() |
194 | - ] ); |
|
194 | + ]); |
|
195 | 195 | |
196 | 196 | return $row !== false; |
197 | 197 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return bool |
203 | 203 | */ |
204 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
205 | - $toReplace = [ "_", "%20" ]; |
|
206 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
204 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
205 | + $toReplace = ["_", "%20"]; |
|
206 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
207 | 207 | return $commonsLink === $compareString; |
208 | 208 | } |
209 | 209 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return bool |
218 | 218 | */ |
219 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
219 | + private function valueIncludesNamespace($value, $namespace) { |
|
220 | 220 | return $namespace !== '' && |
221 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
221 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | } |