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