Jeroen De Dauw has submitted this change and it was merged. Change subject: Factor string normalization functions out of Utils. ......................................................................
Factor string normalization functions out of Utils. This introduces a StringNormalizer service and replaces any use of the static normalization functions in Utils. Change-Id: Ieeba2470dccf797b37243355ddcb2ccf5e5b18c0 --- M client/includes/WikibaseClient.php M lib/WikibaseLib.classes.php A lib/includes/StringNormalizer.php M lib/includes/Term.php M lib/includes/Utils.php M lib/includes/specials/SpecialWikibasePage.php A lib/tests/phpunit/StringNormalizerTest.php M lib/tests/phpunit/UtilsTest.php M repo/includes/Summary.php M repo/includes/WikibaseRepo.php M repo/includes/api/EditEntity.php M repo/includes/api/GetEntities.php M repo/includes/api/ModifyEntity.php M repo/includes/api/SetAliases.php M repo/includes/api/SetDescription.php M repo/includes/api/SetLabel.php M repo/includes/api/SetSiteLink.php M repo/includes/specials/SpecialItemByTitle.php M repo/includes/specials/SpecialNewEntity.php 19 files changed, 327 insertions(+), 131 deletions(-) Approvals: Jeroen De Dauw: Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index 18adf6f..0d43bc4 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -21,6 +21,7 @@ use Wikibase\RepoLinker; use Wikibase\Settings; use Wikibase\SettingsArray; +use Wikibase\StringNormalizer; use Wikibase\Test\MockRepository; /** @@ -76,6 +77,11 @@ protected $isInTestMode; private $storeInstances = array(); + + /** + * @var StringNormalizer + */ + private $stringNormalizer; /** * @since 0.4 @@ -203,6 +209,19 @@ /** * @since 0.4 * + * @return StringNormalizer + */ + public function getStringNormalizer() { + if ( $this->stringNormalizer === null ) { + $this->stringNormalizer = new StringNormalizer(); + } + + return $this->stringNormalizer; + } + + /** + * @since 0.4 + * * @return RepoLinker */ public function newRepoLinker() { diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php index 5bad03e..abdffc9 100644 --- a/lib/WikibaseLib.classes.php +++ b/lib/WikibaseLib.classes.php @@ -64,6 +64,7 @@ 'Wikibase\Term' => 'includes/Term.php', 'Wikibase\Lib\TermsToClaimsTranslator' => 'includes/TermsToClaimsTranslator.php', 'Wikibase\Lib\TypedValueFormatter' => 'includes/TypedValueFormatter.php', + 'Wikibase\StringNormalizer' => 'includes/StringNormalizer.php', 'Wikibase\Utils' => 'includes/Utils.php', 'Wikibase\WikibaseDiffOpFactory' => 'includes/WikibaseDiffOpFactory.php', 'Wikibase\Lib\WikibaseDataTypeBuilders' => 'includes/WikibaseDataTypeBuilders.php', diff --git a/lib/includes/StringNormalizer.php b/lib/includes/StringNormalizer.php new file mode 100644 index 0000000..269d7ea --- /dev/null +++ b/lib/includes/StringNormalizer.php @@ -0,0 +1,82 @@ +<?php + /** + * + * Copyright © 03.07.13 by the authors listed below. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @license GPL 2+ + * @file + * + * @author Daniel Kinzler + * @author John Erling Blad < jeb...@gmail.com > + */ + + +namespace Wikibase; + + +use UtfNormal; + +/** + * StringNormalizer provides several methods for normalizing strings. + * + * @since 0.4 + * + * @package Wikibase + */ +class StringNormalizer { + + + /** + * Trim initial and trailing whitespace and control chars, and optionally compress internal ones. + * + * @param string $inputString The actual string to process. + * + * @return string where whitespace possibly are removed. + */ + public function trimWhitespace( $inputString ) { + // \p{Z} - whitespace + // \p{Cc} - control chars + $trimmed = preg_replace( '/^[\p{Z}\p{Cc}]+|[\p{Z}\p{Cc}]+$/u', '', $inputString ); + $trimmed = preg_replace( '/[\p{Cc}]+/u', ' ', $trimmed ); + return $trimmed; + } + + /** + * Normalize string into NFC by using the cleanup metod from UtfNormal. + * + * @param string $inputString The actual string to process. + * + * @return string where whitespace possibly are removed. + */ + public function cleanupToNFC( $inputString ) { + return UtfNormal::cleanUp( $inputString ); + } + + /** + * Do a cleanupToNFC after the string is trimmed + * + * @param string $inputString + * + * @return string on NFC form + */ + public function trimToNFC( $inputString ) { + return $this->cleanupToNFC( $this->trimWhitespace( $inputString ) ); + } + + +} \ No newline at end of file diff --git a/lib/includes/Term.php b/lib/includes/Term.php index 6b25347..6fba0e7 100644 --- a/lib/includes/Term.php +++ b/lib/includes/Term.php @@ -2,6 +2,8 @@ namespace Wikibase; use MWException; +use Wikibase\Client\WikibaseClient; +use Wikibase\Repo\WikibaseRepo; /** * Object representing a term. @@ -227,21 +229,55 @@ * for specialized normalization. * * @return string + * + * @todo: Move this to TermSqlIndex */ public static function normalizeText( $text, $lang = 'en' ) { - // \p{Z} - whitespace - // \p{C} - control chars - $text = preg_replace( '/^[\p{Z}\p{C}]+|[\p{Z}\p{C}]+$/u', '', $text ); - $text = preg_replace( '/[\p{C}]+/u', ' ', $text ); + if ( $text === '' ) { + return ''; + } + + //FIXME: move normalizeText to TermSqlIndex to avoid this mess! + if ( class_exists( 'Wikibase\Repo\WikibaseRepo' ) ) { + $normalizer = WikibaseRepo::getDefaultInstance()->getStringNormalizer(); + } elseif ( class_exists( 'Wikibase\Client\WikibaseClient' ) ) { + $normalizer = WikibaseClient::getDefaultInstance()->getStringNormalizer(); + } else { + throw new \RuntimeException( "Found nither WikibaseRepo not WikibaseClient" ); + } // composed normal form - $text = Utils::cleanupToNFC( $text ); + $nfcText = $normalizer->cleanupToNFC( $text ); + + if ( !is_string( $nfcText ) || $nfcText === '' ) { + wfWarn( "Unicode normalization failed for `$text`" ); + } + + // \p{Z} - whitespace + // \p{C} - control chars + // WARNING: *any* invalid UTF8 sequence causes preg_replace to return an empty string. + $strippedText = $nfcText; + $strippedText = preg_replace( '/[\p{Cc}\p{Cf}\p{Cn}\p{Cs}]+/u', ' ', $strippedText ); + $strippedText = preg_replace( '/^[\p{Z}]+|[\p{Z}]+$/u', '', $strippedText ); + + if ( $strippedText === '' ) { + // NOTE: This happens when there is only whitespace in the string. + // However, preg_replace will also return an empty string if it + // encounters any invalid utf-8 sequence. + return ''; + } //TODO: Use Language::lc to convert to lower case. // But that requires us to load ALL the language objects, // which loads ALL the messages, which makes us run out // of RAM (see bug 41103). - return mb_strtolower( $text, 'UTF-8' ); + $normalized = mb_strtolower( $strippedText, 'UTF-8' ); + + if ( !is_string( $normalized ) || $normalized === '' ) { + wfWarn( "mb_strtolower normalization failed for `$strippedText`" ); + } + + return $normalized; } /** diff --git a/lib/includes/Utils.php b/lib/includes/Utils.php index e12dc70..540a560 100644 --- a/lib/includes/Utils.php +++ b/lib/includes/Utils.php @@ -189,49 +189,6 @@ } /** - * Trim initial and trailing whitespace and control chars, and optionally compress internal ones. - * - * @since 0.1 - * - * @param string $inputString The actual string to process. - * - * @return string where whitespace possibly are removed. - */ - static public function trimWhitespace( $inputString ) { - // \p{Z} - whitespace - // \p{Cc} - control chars - $trimmed = preg_replace( '/^[\p{Z}\p{Cc}]+|[\p{Z}\p{Cc}]+$/u', '', $inputString ); - $trimmed = preg_replace( '/[\p{Cc}]+/u', ' ', $trimmed ); - return $trimmed; - } - - /** - * Normalize string into NFC by using the cleanup metod from UtfNormal. - * - * @since 0.1 - * - * @param string $inputString The actual string to process. - * - * @return string where whitespace possibly are removed. - */ - static public function cleanupToNFC( $inputString ) { - return UtfNormal::cleanUp( $inputString ); - } - - /** - * Do a toNFC after the string is squashed - * - * @since 0.1 - * - * @param string $inputString - * - * @return string on NFC form - */ - static public function trimToNFC( $inputString ) { - return self::cleanupToNFC( self::trimWhitespace( $inputString ) ); - } - - /** * Check the given PID to see if it is alive * * @since 0.3 diff --git a/lib/includes/specials/SpecialWikibasePage.php b/lib/includes/specials/SpecialWikibasePage.php index 9d29d46..9f9aa20 100644 --- a/lib/includes/specials/SpecialWikibasePage.php +++ b/lib/includes/specials/SpecialWikibasePage.php @@ -29,9 +29,34 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ +use Wikibase\Repo\WikibaseRepo; +use Wikibase\StringNormalizer; + abstract class SpecialWikibasePage extends SpecialPage { /** + * @var StringNormalizer + */ + protected $stringNormalizer; + + /** + * Constructor. + * + * @since 0.4 + * + * @param string $name + * @param string $restriction + * @param bool $listed + */ + public function __construct( $name = '', $restriction = '', $listed = true ) { + parent::__construct( $name, $restriction, $listed ); + + // XXX: Use StringNormalizer as a plain composite - since it + // doesn't have any dependencies, local instantiation isn't an issue. + $this->stringNormalizer = new StringNormalizer(); + } + + /** * The subpage, ie the part after Special:PageName/ * Empty string if none is provided. * diff --git a/lib/tests/phpunit/StringNormalizerTest.php b/lib/tests/phpunit/StringNormalizerTest.php new file mode 100644 index 0000000..6d2cd68 --- /dev/null +++ b/lib/tests/phpunit/StringNormalizerTest.php @@ -0,0 +1,86 @@ +<?php + +namespace Wikibase\Test; +use Wikibase\StringNormalizer; +use Wikibase\Utils; + +/** + * Tests for the Wikibase\StringNormalizer class. + * + * @file + * @since 0.4 + * + * @ingroup WikibaseLib + * @ingroup Test + * + * @group WikibaseLib + * @group Wikibase + * + * @licence GNU GPL v2+ + * @author John Erling Blad < jeb...@gmail.com > + * @author Daniel Kinzler + */ +class StringNormalizerTest extends \MediaWikiTestCase { + + /** + * @dataProvider providerTrimWhitespace + */ + public function testTrimWhitespace( $string, $expected ) { + $normalizer = new StringNormalizer(); + $this->assertEquals( $expected, $normalizer->trimWhitespace( $string ) ); + } + + public static function providerTrimWhitespace() { + return array( + array( 'foo bar', 'foo bar'), // #0 + array( ' foo bar ', 'foo bar'), // #1 + array( ' foo bar ', 'foo bar'), // #2 + array( "foo\tbar", 'foo bar'), // #3, both a space and control char + array( "foo\nbar", 'foo bar'), // #4, both a space and control char + array( "foo\rbar", 'foo bar'), // #5, both a space and control char + array( "\r \t\nfoo\r\t\t\tbar\n\n\n\r\r", 'foo bar'), // #6, both space and control chars + array( "\r \t\nfoo\r\t\t\t bar\n\n\n\r\r", 'foo bar'), // #7, both space and control chars + array( html_entity_decode( "foo‌bar", ENT_QUOTES, "utf-8"), html_entity_decode( "foo‌bar", ENT_QUOTES, "utf-8") ), // #8 + array( html_entity_decode( "foo‌‌bar", ENT_QUOTES, "utf-8"), html_entity_decode( "foo‌‌bar", ENT_QUOTES, "utf-8") ), // #9 + ); + } + + /** + * @dataProvider providerCleanupToNFC + */ + public function testCleanupToNFC( $src, $dst, $expected ) { + $normalizer = new StringNormalizer(); + + if ($expected) { + $this->assertEquals( $dst, $normalizer->cleanupToNFC( $src ), "String '$src' is not the same as the expected '$dst'" ); + } + else { + $this->assertFalse( $dst === $normalizer->cleanupToNFC( $src ), "String '$src' (" . urlencode( $src ) . ") is the same as the expected '$dst' (" . urlencode( $dst ) . "). This is unusual, but correct." ); + } + } + + public static function providerCleanupToNFC() { + return array( + array( "\xC3\x85land", 'Åland', true ), + array( "A\xCC\x8Aland", 'Åland', true ), + array( "\xE2\x84\xABngstrom (unit)", 'Ångstrom (unit)', false ), + ); + } + + /** + * @dataProvider providerTrimToNFC + */ + public function testTrimToNFC( $src, $dst ) { + $normalizer = new StringNormalizer(); + $this->assertEquals( $dst, $normalizer->trimToNFC( $src ), "String '$src' is not the same as the expected '$dst'" ); + } + + public static function providerTrimToNFC() { + return array( + array( " \xC3\x85land øyene ", 'Åland øyene' ), // #0 + array( " A\xCC\x8Aland øyene ", 'Åland øyene' ), // #1 + array( " \xC3\x85land øyene ", 'Åland øyene' ), // #2 + array( " A\xCC\x8Aland øyene ", 'Åland øyene' ), // #3 + ); + } +} diff --git a/lib/tests/phpunit/UtilsTest.php b/lib/tests/phpunit/UtilsTest.php index 6c0e61c..17b8288 100644 --- a/lib/tests/phpunit/UtilsTest.php +++ b/lib/tests/phpunit/UtilsTest.php @@ -45,67 +45,6 @@ ); } - /** - * @group WikibaseUtils - * @dataProvider providerTrimWhitespace - */ - public function testTrimWhitespace( $string, $expected ) { - $this->assertEquals( $expected, Utils::trimWhitespace( $string ) ); - } - - public static function providerTrimWhitespace() { - return array( - array( 'foo bar', 'foo bar'), // #0 - array( ' foo bar ', 'foo bar'), // #1 - array( ' foo bar ', 'foo bar'), // #2 - array( "foo\tbar", 'foo bar'), // #3, both a space and control char - array( "foo\nbar", 'foo bar'), // #4, both a space and control char - array( "foo\rbar", 'foo bar'), // #5, both a space and control char - array( "\r \t\nfoo\r\t\t\tbar\n\n\n\r\r", 'foo bar'), // #6, both space and control chars - array( "\r \t\nfoo\r\t\t\t bar\n\n\n\r\r", 'foo bar'), // #7, both space and control chars - array( html_entity_decode( "foo‌bar", ENT_QUOTES, "utf-8"), html_entity_decode( "foo‌bar", ENT_QUOTES, "utf-8") ), // #8 - array( html_entity_decode( "foo‌‌bar", ENT_QUOTES, "utf-8"), html_entity_decode( "foo‌‌bar", ENT_QUOTES, "utf-8") ), // #9 - ); - } - - /** - * @group WikibaseUtils - * @dataProvider providerCleanupToNFC - */ - public function testCleanupToNFC( $src, $dst, $expected ) { - if ($expected) { - $this->assertEquals( $dst, Utils::cleanupToNFC( $src ), "String '$src' is not the same as the expected '$dst'" ); - } - else { - $this->assertFalse( $dst === Utils::cleanupToNFC( $src ), "String '$src' (" . urlencode( $src ) . ") is the same as the expected '$dst' (" . urlencode( $dst ) . "). This is unusual, but correct." ); - } - } - - public static function providerCleanupToNFC() { - return array( - array( "\xC3\x85land", 'Åland', true ), - array( "A\xCC\x8Aland", 'Åland', true ), - array( "\xE2\x84\xABngstrom (unit)", 'Ångstrom (unit)', false ), - ); - } - - /** - * @group WikibaseUtils - * @dataProvider providerTrimToNFC - */ - public function testTrimToNFC( $src, $dst ) { - $this->assertEquals( $dst, Utils::trimToNFC( $src ), "String '$src' is not the same as the expected '$dst'" ); - } - - public static function providerTrimToNFC() { - return array( - array( " \xC3\x85land øyene ", 'Åland øyene' ), // #0 - array( " A\xCC\x8Aland øyene ", 'Åland øyene' ), // #1 - array( " \xC3\x85land øyene ", 'Åland øyene' ), // #2 - array( " A\xCC\x8Aland øyene ", 'Åland øyene' ), // #3 - ); - } - public static function provideFetchLanguageName() { return array( array( // #0 diff --git a/repo/includes/Summary.php b/repo/includes/Summary.php index 82cf4f3..989aefe 100644 --- a/repo/includes/Summary.php +++ b/repo/includes/Summary.php @@ -4,6 +4,7 @@ use Language; use DataValues\StringValue; +use Wikibase\Repo\WikibaseRepo; /** * File defining the handler for autocomments and additional utility functions @@ -374,9 +375,10 @@ */ public static function formatTotalSummary( $comment, $summary, $length = SUMMARY_MAX_LENGTH ) { global $wgContLang; + $normalizer = WikibaseRepo::getDefaultInstance()->getStringNormalizer(); - $comment = Utils::trimToNFC( $comment ); - $summary = Utils::trimToNFC( $summary ); + $comment = $normalizer->trimToNFC( $comment ); + $summary = $normalizer->trimToNFC( $summary ); $mergedString = ''; if ( $comment !== '' ) { $mergedString .= "/* $comment */"; @@ -411,8 +413,10 @@ ) ); - $comment = ( $format & self::USE_COMMENT) ? Utils::trimToNFC( $comment ) : ''; - $summary = ( $format & self::USE_SUMMARY) ? Utils::trimToNFC( $summary ) : ''; + $normalizer = WikibaseRepo::getDefaultInstance()->getStringNormalizer(); + + $comment = ( $format & self::USE_COMMENT) ? $normalizer->trimToNFC( $comment ) : ''; + $summary = ( $format & self::USE_SUMMARY) ? $normalizer->trimToNFC( $summary ) : ''; $totalSummary = self::formatTotalSummary( $comment, $summary, $length ); diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 1d4f1d4..a68149f 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -21,6 +21,7 @@ use Wikibase\Store; use Wikibase\StoreFactory; use Wikibase\SnakFactory; +use Wikibase\StringNormalizer; /** * Top level factory for the WikibaseRepo extension. @@ -83,6 +84,12 @@ * @var LanguageFallbackChainFactory */ private $languageFallbackChainFactory; + + /** + * @var StringNormalizer + */ + private $stringNormalizer; + /** * @since 0.4 @@ -171,6 +178,19 @@ /** * @since 0.4 * + * @return StringNormalizer + */ + public function getStringNormalizer() { + if ( $this->stringNormalizer === null ) { + $this->stringNormalizer = new StringNormalizer(); + } + + return $this->stringNormalizer; + } + + /** + * @since 0.4 + * * @return EntityLookup */ public function getEntityLookup() { diff --git a/repo/includes/api/EditEntity.php b/repo/includes/api/EditEntity.php index 2fbcd0a..8ae91a3 100644 --- a/repo/includes/api/EditEntity.php +++ b/repo/includes/api/EditEntity.php @@ -202,7 +202,7 @@ $status->merge( $this->checkMultilangArgs( $arg, $langCode ) ); $language = $arg['language']; - $newLabel = Utils::trimToNFC( $arg['value'] ); + $newLabel = $this->stringNormalizer->trimToNFC( $arg['value'] ); if ( array_key_exists( 'remove', $arg ) || $newLabel === "" ) { $labelChangeOps[] = new ChangeOpLabel( $language, null ); @@ -235,7 +235,7 @@ $status->merge( $this->checkMultilangArgs( $arg, $langCode ) ); $language = $arg['language']; - $newDescription = Utils::trimToNFC( $arg['value'] ); + $newDescription = $this->stringNormalizer->trimToNFC( $arg['value'] ); if ( array_key_exists( 'remove', $arg ) || $newDescription === "" ) { $descriptionChangeOps[] = new ChangeOpDescription( $language, null ); @@ -278,7 +278,7 @@ foreach ( $args as $arg ) { $status->merge( $this->checkMultilangArgs( $arg, $langCode ) ); - $alias = array( Utils::trimToNFC( $arg['value'] ) ); + $alias = array( $this->stringNormalizer->trimToNFC( $arg['value'] ) ); $language = $arg['language']; if ( array_key_exists( 'remove', $arg ) ) { @@ -333,7 +333,7 @@ if ( array_key_exists( 'remove', $arg ) || $arg['title'] === "" ) { $siteLinksChangeOps[] = new ChangeOpSiteLink( $globalSiteId, null ); } else { - $linkPage = $linkSite->normalizePageName( Utils::trimWhitespace( $arg['title'] ) ); + $linkPage = $linkSite->normalizePageName( $this->stringNormalizer->trimWhitespace( $arg['title'] ) ); if ( $linkPage === false ) { wfProfileOut( __METHOD__ ); diff --git a/repo/includes/api/GetEntities.php b/repo/includes/api/GetEntities.php index 6c57165..d542738 100644 --- a/repo/includes/api/GetEntities.php +++ b/repo/includes/api/GetEntities.php @@ -30,6 +30,17 @@ class GetEntities extends ApiWikibase { /** + * @var \Wikibase\StringNormalizer + */ + protected $stringNormalizer; + + public function __construct( \ApiMain $main, $name, $prefix = '' ) { + parent::__construct( $main, $name, $prefix ); + + $this->stringNormalizer = WikibaseRepo::getDefaultInstance()->getStringNormalizer(); + } + + /** * @see \ApiBase::execute() */ public function execute() { @@ -59,7 +70,7 @@ for ( $k = 0; $k < $max; $k++ ) { $siteId = $params['sites'][$idxSites++ % $numSites]; - $title = Utils::trimToNFC( $params['titles'][$idxTitles++ % $numTitles] ); + $title = $this->stringNormalizer->trimToNFC( $params['titles'][$idxTitles++ % $numTitles] ); $id = StoreFactory::getStore()->newSiteLinkCache()->getItemIdForLink( $siteId, $title ); diff --git a/repo/includes/api/ModifyEntity.php b/repo/includes/api/ModifyEntity.php index 2719811..3052e34 100644 --- a/repo/includes/api/ModifyEntity.php +++ b/repo/includes/api/ModifyEntity.php @@ -12,6 +12,8 @@ use Wikibase\EntityContent; use Wikibase\EntityContentFactory; use Wikibase\ItemHandler; +use Wikibase\Repo\WikibaseRepo; +use Wikibase\StringNormalizer; use Wikibase\Summary; use Wikibase\Utils; @@ -29,6 +31,17 @@ * @author Daniel Kinzler */ abstract class ModifyEntity extends ApiWikibase { + + /** + * @var StringNormalizer + */ + protected $stringNormalizer; + + public function __construct( \ApiMain $main, $name, $prefix = '' ) { + parent::__construct( $main, $name, $prefix ); + + $this->stringNormalizer = WikibaseRepo::getDefaultInstance()->getStringNormalizer(); + } /** * Flags to pass to EditEntity::attemptSave; use with the EDIT_XXX constants. @@ -83,7 +96,7 @@ $entityTitle = $itemHandler->getTitleFromSiteLink( $params['site'], - Utils::trimToNFC( $params['title'] ) + $this->stringNormalizer->trimToNFC( $params['title'] ) ); if ( is_null( $entityTitle ) ) { @@ -257,7 +270,7 @@ protected function addNormalizationInfoToOutput( $title ) { $normalized = array(); - $normTitle = Utils::trimToNFC( $title ); + $normTitle = $this->stringNormalizer->trimToNFC( $title ); if ( $normTitle !== $title ) { $normalized['from'] = $title; $normalized['to'] = $normTitle; diff --git a/repo/includes/api/SetAliases.php b/repo/includes/api/SetAliases.php index 1140183..a19c03d 100644 --- a/repo/includes/api/SetAliases.php +++ b/repo/includes/api/SetAliases.php @@ -64,6 +64,8 @@ * @see \Wikibase\Api\ModifyEntity::modifyEntity() */ protected function modifyEntity( EntityContent &$entityContent, array $params ) { + $stringNormalizer = $this->stringNormalizer; // hack for PHP fail. + wfProfileIn( __METHOD__ ); $summary = $this->createSummary( $params ); @@ -76,7 +78,7 @@ $entityContent->getEntity()->setAliases( $params['language'], array_map( - function( $str ) { return Utils::trimToNFC( $str ); }, + function( $str ) use ( $stringNormalizer ) { return $stringNormalizer->trimToNFC( $str ); }, $params['set'] ) ); @@ -87,7 +89,7 @@ $entityContent->getEntity()->addAliases( $params['language'], array_map( - function( $str ) { return Utils::trimToNFC( $str ); }, + function( $str ) use ( $stringNormalizer ) { return $stringNormalizer->trimToNFC( $str ); }, $params['add'] ) ); @@ -97,7 +99,7 @@ $entityContent->getEntity()->removeAliases( $params['language'], array_map( - function( $str ) { return Utils::trimToNFC( $str ); }, + function( $str ) use ( $stringNormalizer ) { return $stringNormalizer->trimToNFC( $str ); }, $params['remove'] ) ); diff --git a/repo/includes/api/SetDescription.php b/repo/includes/api/SetDescription.php index 6af7132..31b3b9f 100644 --- a/repo/includes/api/SetDescription.php +++ b/repo/includes/api/SetDescription.php @@ -45,7 +45,7 @@ if ( isset( $params['value'] ) ) { - $description = Utils::trimToNFC( $params['value'] ); + $description = $this->stringNormalizer->trimToNFC( $params['value'] ); $language = $params['language']; if ( 0 < strlen( $description ) ) { diff --git a/repo/includes/api/SetLabel.php b/repo/includes/api/SetLabel.php index a25e6e4..92e5324 100644 --- a/repo/includes/api/SetLabel.php +++ b/repo/includes/api/SetLabel.php @@ -45,7 +45,7 @@ if ( isset( $params['value'] ) ) { - $label = Utils::trimToNFC( $params['value'] ); + $label = $this->stringNormalizer->trimToNFC( $params['value'] ); $language = $params['language']; if ( 0 < strlen( $label ) ) { $summary->addAutoSummaryArgs( $label ); diff --git a/repo/includes/api/SetSiteLink.php b/repo/includes/api/SetSiteLink.php index 5ba931b..7f2e235 100644 --- a/repo/includes/api/SetSiteLink.php +++ b/repo/includes/api/SetSiteLink.php @@ -84,7 +84,7 @@ $item = $entityContent->getItem(); if ( isset( $params['linksite'] ) && ( $params['linktitle'] === '' ) ) { - $linksite = Utils::trimToNFC( $params['linksite'] ); + $linksite = $this->stringNormalizer->trimToNFC( $params['linksite'] ); try { $link = $item->getSimpleSiteLink( $linksite ); @@ -108,7 +108,7 @@ $this->dieUsage( $this->msg( 'wikibase-api-not-recognized-siteid' )->text(), 'not-recognized-siteid' ); } - $page = $site->normalizePageName( Utils::trimWhitespace( $params['linktitle'] ) ); + $page = $site->normalizePageName( $this->stringNormalizer->trimWhitespace( $params['linktitle'] ) ); if ( $page === false ) { wfProfileOut( __METHOD__ ); diff --git a/repo/includes/specials/SpecialItemByTitle.php b/repo/includes/specials/SpecialItemByTitle.php index 6a65840..ba3664a 100644 --- a/repo/includes/specials/SpecialItemByTitle.php +++ b/repo/includes/specials/SpecialItemByTitle.php @@ -64,8 +64,8 @@ // If ther are enough data, then try to lookup the item content if ( isset( $site ) && isset( $page ) ) { // Try to get a item content - $siteId = \Wikibase\Utils::trimToNFC( $site ); // no stripping of underscores here! - $pageName = \Wikibase\Utils::trimToNFC( $page ); + $siteId = $this->stringNormalizer->trimToNFC( $site ); // no stripping of underscores here! + $pageName = $this->stringNormalizer->trimToNFC( $page ); if ( !\Sites::singleton()->getSite( $siteId ) ) { // HACK: If the site ID isn't known, add "wiki" to it; this allows the wikipedia diff --git a/repo/includes/specials/SpecialNewEntity.php b/repo/includes/specials/SpecialNewEntity.php index 6269619..43bbdb1 100644 --- a/repo/includes/specials/SpecialNewEntity.php +++ b/repo/includes/specials/SpecialNewEntity.php @@ -156,7 +156,8 @@ * @return bool */ protected function hasSufficientArguments() { - return Utils::trimWhitespace( $this->label ) !== '' || Utils::trimWhitespace( $this->description ) !== ''; + return $this->stringNormalizer->trimWhitespace( $this->label ) !== '' + || $this->stringNormalizer->trimWhitespace( $this->description ) !== ''; } /** -- To view, visit https://gerrit.wikimedia.org/r/72078 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ieeba2470dccf797b37243355ddcb2ccf5e5b18c0 Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Daniel Werner <daniel.wer...@wikimedia.de> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits