Jarry1250 has uploaded a new change for review. https://gerrit.wikimedia.org/r/156885
Change subject: Phase out use of MessageGroupStats in favour of more brutal methods ...................................................................... Phase out use of MessageGroupStats in favour of more brutal methods MessageGroupStats uses a powerful but slow approach, iterating over every possible language, and then compiling the results in the database. This means it performs well if message groups are reused and developed, but poor performance if there are lots of new message groups to crawl. At the moment, such power seems unneccessary: getOnWikiLanguages is called infrequently, and does not require the filtering options provided by MessageGroupStats. Thus the first-time performance hit is the more major concern. It may be in future that the power/performance balance shifts, in which case this change can be easily reverted. Change-Id: I46253980a236d9f0b22aa3eee44540ef89fe11a1 --- M SVGMessageGroup.php 1 file changed, 22 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg refs/changes/85/156885/1 diff --git a/SVGMessageGroup.php b/SVGMessageGroup.php index 2562baa..9c2e3a0 100644 --- a/SVGMessageGroup.php +++ b/SVGMessageGroup.php @@ -157,6 +157,10 @@ if ( $language === 'fallback' ) { $language = $this->getSourceLanguage(); } + if ( !Language::isValidBuiltInCode( $language ) ) { + // Some weird attack vector? + continue; + } $translation = TranslateSvgUtils::arrayToTranslation( $innerArray ); $fullKey = $this->source . '/' . $key . '/' . $language; $title = Title::makeTitleSafe( $this->getNamespace(), $fullKey ); @@ -210,19 +214,26 @@ /** * Returns a list of languages the file has been translated into *on wiki* - * i.e. some of those may not have been saved back to the file yet. + * i.e. some of those may not have been saved back to the file yet. Only the language code is + * (even minimally) verified. A pretty brutal method all things considered, but effective and quick -- + * the downsides being that we assume a certain file structure and there's minimal caching. */ public function getOnWikiLanguages() { - $stats = MessageGroupStats::forGroup( $this->getId() ); $languages = array(); - foreach ( $stats as $language => $data ) { - $translatedCount = $data[MessageGroupStats::TRANSLATED]; - $fuzzyCount = $data[MessageGroupStats::FUZZY]; - if ( $translatedCount > 0 || $fuzzyCount > 0 ) { - $languages[] = $language; + $subpages = Title::makeTitleSafe( $this->getNamespace(), $this->source )->getSubpages(); + + foreach ( $subpages as $subpage ) { + /** @var Title $subpage */ + + // These are subpages of the form File:Foo.svg/tspan2991/de, i.e. actually sub-subpages, + // but $subpage->getSubpageText() will nevertheless just get the last bit (i.e. the language code). + $langCode = $subpage->getSubpageText(); + if( Language::isSupportedLanguage( $langCode ) ) { + $languages[] = $langCode; } } - return $languages; + + return array_unique( $languages ); } /* @@ -236,10 +247,11 @@ return $this->onWikiTranslations; } - $onWikiTranslations = array(); + // SVGs are unlikely to be translated into more than a dozen, so let's check first to see which + // languages have any translations at all in order to narrow our search. $languages = $this->getOnWikiLanguages(); - // Translations generated onwiki + $onWikiTranslations = array(); foreach ( $languages as $language ) { $collection = $this->initCollection( $language ); $collection->loadTranslations(); -- To view, visit https://gerrit.wikimedia.org/r/156885 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I46253980a236d9f0b22aa3eee44540ef89fe11a1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/TranslateSvg Gerrit-Branch: master Gerrit-Owner: Jarry1250 <jarry1...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits