Jarry1250 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/153047

Change subject: Abstract and hollow out most of addSVGGroup()
......................................................................

Abstract and hollow out most of addSVGGroup()

Change-Id: I7842792c092770463d63c323469e6c376a7f2502
---
M SVGMessageGroup.php
M SpecialTranslateNewSVG.php
2 files changed, 18 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg 
refs/changes/47/153047/1

diff --git a/SVGMessageGroup.php b/SVGMessageGroup.php
index a32a8bd..c73b5ec 100644
--- a/SVGMessageGroup.php
+++ b/SVGMessageGroup.php
@@ -196,4 +196,19 @@
                }
                return $languages;
        }
+
+       public function register( $useJobQueue = true ) {
+               $articleId = Title::newFromText( $this->getLabel(), NS_FILE 
)->getArticleId();
+
+               $dbw = wfGetDB( DB_MASTER );
+               $row = array( 'ts_page_id' => $articleId );
+
+               // If $dbw->affectedRows() == 0, it already exists,
+               // but no particular reason to error out
+               $dbw->insert( 'translate_svg', $row, __METHOD__, array( 
'IGNORE' ) );
+
+               MessageGroups::clearCache();
+               MessageIndexRebuildJob::newJob()->insert();
+               return true;
+       }
 }
diff --git a/SpecialTranslateNewSVG.php b/SpecialTranslateNewSVG.php
index 904c334..4b875b8 100644
--- a/SpecialTranslateNewSVG.php
+++ b/SpecialTranslateNewSVG.php
@@ -54,36 +54,12 @@
        }
 
        protected function addSVGGroup( $groupName, $srcLang ) {
-               // Does this represent a file that exists?
-               $title = Title::makeTitleSafe( NS_FILE, $groupName );
-               if ( !$title->exists() ) {
-                       return false;
-               }
-               $file = wfFindFile( $title );
-               if ( !$file->exists() ) {
-                       return false;
-               }
-
-               // Pick up normalisations from makeTitleSafe()
-               $groupName = $title->getText();
-
                $group = new SVGMessageGroup( $groupName );
-               $group->setSourceLanguage( $srcLang );
-               if ( $group->importTranslations() ) {
-                       TranslateMetadata::set( $groupName, 'sourcelang', 
$srcLang );
-                       $dbw = wfGetDB( DB_MASTER );
-                       $table = 'translate_svg';
-                       $row = array( 'ts_page_id' => $title->getArticleId() );
-                       $dbw->insert( $table, $row, __METHOD__, array( 'IGNORE' 
) );
-                       MessageGroups::clearCache();
-                       MessageIndexRebuildJob::newJob()->insert();
-
-                       // If $dbw->affectedRows() == 0, something's not quite 
right, but it
-                       // seems odd to actively error here.
-                       return true;
-               } else {
+               if( $group === false ) {
                        return false;
                }
+               $group->setSourceLanguage( $srcLang );
+               return $group->importTranslations() && $group->register();
        }
 
        protected function showForm( $groupName, $srcLang ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/153047
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7842792c092770463d63c323469e6c376a7f2502
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

Reply via email to