Remove phpcs exclude rules and update PHP code
Change-Id: Ie37deda368a4d163cf324988721033829ae8af77
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<ruleset>
|
<ruleset>
|
||||||
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
|
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
|
||||||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate" />
|
<rule ref="MediaWiki.Files.ClassMatchesFilename.NotMatch">
|
||||||
<exclude name="MediaWiki.Files.ClassMatchesFilename.NotMatch" />
|
<exclude-pattern>*/scripts/compile-font-repo\.php</exclude-pattern>
|
||||||
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
|
<exclude-pattern>*/scripts/generate-font-test-page\.php</exclude-pattern>
|
||||||
<exclude name="MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationProtected" />
|
|
||||||
</rule>
|
</rule>
|
||||||
<file>.</file>
|
<file>.</file>
|
||||||
<arg name="extensions" value="php" />
|
<arg name="extensions" value="php" />
|
||||||
|
|||||||
@@ -144,6 +144,9 @@ class LanguageNameIndexer extends Maintenance {
|
|||||||
$this->generateFile( $buckets );
|
$this->generateFile( $buckets );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function getLanguageData() {
|
private function getLanguageData() {
|
||||||
$file = __DIR__ . '/../lib/jquery.uls/src/jquery.uls.data.js';
|
$file = __DIR__ . '/../lib/jquery.uls/src/jquery.uls.data.js';
|
||||||
$contents = file_get_contents( $file );
|
$contents = file_get_contents( $file );
|
||||||
@@ -158,6 +161,9 @@ class LanguageNameIndexer extends Maintenance {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $buckets
|
||||||
|
*/
|
||||||
private function generateFile( array $buckets ) {
|
private function generateFile( array $buckets ) {
|
||||||
$template = <<<'PHP'
|
$template = <<<'PHP'
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
@@ -105,11 +105,21 @@ class LanguageNameSearch {
|
|||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string $searchKey
|
||||||
|
* @param int $typos
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function matchNames( $name, $searchKey, $typos ) {
|
public static function matchNames( $name, $searchKey, $typos ) {
|
||||||
return strrpos( $name, $searchKey, -strlen( $name ) ) !== false
|
return strrpos( $name, $searchKey, -strlen( $name ) ) !== false
|
||||||
|| ( $typos > 0 && self::levenshteinDistance( $name, $searchKey ) <= $typos );
|
|| ( $typos > 0 && self::levenshteinDistance( $name, $searchKey ) <= $typos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public static function getIndex( $name ) {
|
public static function getIndex( $name ) {
|
||||||
$codepoint = self::getCodepoint( $name );
|
$codepoint = self::getCodepoint( $name );
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ use Wikimedia\ParamValidator\ParamValidator;
|
|||||||
* @ingroup API
|
* @ingroup API
|
||||||
*/
|
*/
|
||||||
class ApiLanguageSearch extends ApiBase {
|
class ApiLanguageSearch extends ApiBase {
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$params = $this->extractRequestParams();
|
$params = $this->extractRequestParams();
|
||||||
$search = $params['search'];
|
$search = $params['search'];
|
||||||
@@ -37,6 +40,9 @@ class ApiLanguageSearch extends ApiBase {
|
|||||||
$result->addValue( null, $this->getModuleName(), $searches );
|
$result->addValue( null, $this->getModuleName(), $searches );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function getAllowedParams() {
|
public function getAllowedParams() {
|
||||||
return [
|
return [
|
||||||
'search' => [
|
'search' => [
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ class ApiULSLocalization extends ApiBase {
|
|||||||
$this->languageNameUtils = $languageNameUtils;
|
$this->languageNameUtils = $languageNameUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$this->getMain()->setCacheMode( 'public' );
|
$this->getMain()->setCacheMode( 'public' );
|
||||||
$this->getMain()->setCacheMaxAge( 2419200 );
|
$this->getMain()->setCacheMaxAge( 2419200 );
|
||||||
@@ -63,6 +66,9 @@ class ApiULSLocalization extends ApiBase {
|
|||||||
$this->getResult()->addValue( null, 'mime', 'application/json' );
|
$this->getResult()->addValue( null, 'mime', 'application/json' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function getCustomPrinter() {
|
public function getCustomPrinter() {
|
||||||
return new ApiFormatRaw(
|
return new ApiFormatRaw(
|
||||||
$this->getMain(),
|
$this->getMain(),
|
||||||
@@ -70,6 +76,9 @@ class ApiULSLocalization extends ApiBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function getAllowedParams() {
|
public function getAllowedParams() {
|
||||||
return [
|
return [
|
||||||
'language' => [
|
'language' => [
|
||||||
@@ -91,6 +100,9 @@ class ApiULSLocalization extends ApiBase {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function isInternal() {
|
public function isInternal() {
|
||||||
// Try to scare people away from using this externally
|
// Try to scare people away from using this externally
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ class ApiULSSetLanguage extends ApiBase {
|
|||||||
$this->languageNameUtils = $languageNameUtils;
|
$this->languageNameUtils = $languageNameUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
if ( !$request->wasPosted() ) {
|
if ( !$request->wasPosted() ) {
|
||||||
@@ -91,6 +94,9 @@ class ApiULSSetLanguage extends ApiBase {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function getAllowedParams() {
|
public function getAllowedParams() {
|
||||||
return [
|
return [
|
||||||
'languagecode' => [
|
'languagecode' => [
|
||||||
@@ -99,11 +105,17 @@ class ApiULSSetLanguage extends ApiBase {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function isInternal() {
|
public function isInternal() {
|
||||||
// Try to scare people away from using this externally
|
// Try to scare people away from using this externally
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
public function needsToken() {
|
public function needsToken() {
|
||||||
return 'csrf';
|
return 'csrf';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,23 @@ use OutputPage;
|
|||||||
* @since 2016.04
|
* @since 2016.04
|
||||||
*/
|
*/
|
||||||
class FontRepoCompiler {
|
class FontRepoCompiler {
|
||||||
|
/** @var string */
|
||||||
protected $fsPath;
|
protected $fsPath;
|
||||||
|
/** @var string */
|
||||||
protected $webPath;
|
protected $webPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fsPath
|
||||||
|
* @param string $webPath
|
||||||
|
*/
|
||||||
public function __construct( $fsPath, $webPath ) {
|
public function __construct( $fsPath, $webPath ) {
|
||||||
$this->fsPath = $fsPath;
|
$this->fsPath = $fsPath;
|
||||||
$this->webPath = $webPath;
|
$this->webPath = $webPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getRepository() {
|
public function getRepository() {
|
||||||
$files = $this->getFilesFromPath( $this->fsPath );
|
$files = $this->getFilesFromPath( $this->fsPath );
|
||||||
|
|
||||||
@@ -46,14 +55,26 @@ class FontRepoCompiler {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fspath
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
public function getFilesFromPath( $fspath ) {
|
public function getFilesFromPath( $fspath ) {
|
||||||
return glob( "$fspath/*/font.ini" );
|
return glob( "$fspath/*/font.ini" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filepath
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
public function parseFile( $filepath ) {
|
public function parseFile( $filepath ) {
|
||||||
return parse_ini_file( $filepath, true );
|
return parse_ini_file( $filepath, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $font
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getLanguages( array $font ) {
|
public function getLanguages( array $font ) {
|
||||||
if ( !isset( $font['languages'] ) ) {
|
if ( !isset( $font['languages'] ) ) {
|
||||||
return [];
|
return [];
|
||||||
@@ -65,6 +86,11 @@ class FontRepoCompiler {
|
|||||||
return $languages;
|
return $languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array &$languages
|
||||||
|
* @param array $fontLanguages
|
||||||
|
* @param string $fontname
|
||||||
|
*/
|
||||||
public function appendLanguages( &$languages, $fontLanguages, $fontname ) {
|
public function appendLanguages( &$languages, $fontLanguages, $fontname ) {
|
||||||
foreach ( $fontLanguages as $rcode ) {
|
foreach ( $fontLanguages as $rcode ) {
|
||||||
$code = str_replace( '*', '', $rcode );
|
$code = str_replace( '*', '', $rcode );
|
||||||
@@ -84,6 +110,11 @@ class FontRepoCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $font
|
||||||
|
* @param string $fontpath
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getFontInfo( $font, $fontpath ) {
|
public function getFontInfo( $font, $fontpath ) {
|
||||||
$info = [];
|
$info = [];
|
||||||
$fontdir = basename( $fontpath );
|
$fontdir = basename( $fontpath );
|
||||||
|
|||||||
@@ -421,6 +421,11 @@ class Hooks implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user User whose preferences are being modified
|
||||||
|
* @param array &$preferences Preferences description array, to be fed to an HTMLForm object
|
||||||
|
* @return bool|void True or no return value to continue or false to abort
|
||||||
|
*/
|
||||||
public function onGetPreferences( $user, &$preferences ) {
|
public function onGetPreferences( $user, &$preferences ) {
|
||||||
// T259037: Does not work well on Minerva
|
// T259037: Does not work well on Minerva
|
||||||
$skin = RequestContext::getMain()->getSkin();
|
$skin = RequestContext::getMain()->getSkin();
|
||||||
@@ -455,6 +460,10 @@ class Hooks implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param array[] &$prefs
|
||||||
|
*/
|
||||||
public function onGetBetaFeaturePreferences( $user, array &$prefs ) {
|
public function onGetBetaFeaturePreferences( $user, array &$prefs ) {
|
||||||
if ( $this->config->get( 'ULSCompactLanguageLinksBetaFeature' ) === true &&
|
if ( $this->config->get( 'ULSCompactLanguageLinksBetaFeature' ) === true &&
|
||||||
$this->config->get( 'InterwikiMagic' ) === true &&
|
$this->config->get( 'InterwikiMagic' ) === true &&
|
||||||
@@ -526,6 +535,10 @@ class Hooks implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param OutputPage $out
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
private function getSetLang( OutputPage $out ): ?string {
|
private function getSetLang( OutputPage $out ): ?string {
|
||||||
$setLangCode = $out->getRequest()->getRawVal( 'setlang' );
|
$setLangCode = $out->getRequest()->getRawVal( 'setlang' );
|
||||||
if ( $setLangCode && $this->languageNameUtils->isSupportedLanguage( $setLangCode ) ) {
|
if ( $setLangCode && $this->languageNameUtils->isSupportedLanguage( $setLangCode ) ) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use ResourceLoaderModule;
|
|||||||
* ResourceLoader module for UniversalLanguageSelector
|
* ResourceLoader module for UniversalLanguageSelector
|
||||||
*/
|
*/
|
||||||
class ResourceLoaderULSModule extends ResourceLoaderModule {
|
class ResourceLoaderULSModule extends ResourceLoaderModule {
|
||||||
|
/** @var string[] */
|
||||||
protected $targets = [ 'desktop', 'mobile' ];
|
protected $targets = [ 'desktop', 'mobile' ];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user