diff options
Diffstat (limited to 'MLEB/Translate/utils/MessageWebImporter.php')
-rw-r--r-- | MLEB/Translate/utils/MessageWebImporter.php | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/MLEB/Translate/utils/MessageWebImporter.php b/MLEB/Translate/utils/MessageWebImporter.php index fb874dc5..308eba62 100644 --- a/MLEB/Translate/utils/MessageWebImporter.php +++ b/MLEB/Translate/utils/MessageWebImporter.php @@ -10,6 +10,10 @@ * @license GPL-2.0-or-later */ +use MediaWiki\Extensions\Translate\SystemUsers\FuzzyBot; +use MediaWiki\MediaWikiServices; +use MediaWiki\Revision\SlotRecord; + /** * Class which encapsulates message importing. It scans for changes (new, changed, deleted), * displays them in pretty way with diffs and finally executes the actions the user choices. @@ -321,7 +325,7 @@ class MessageWebImporter { foreach ( $actions as $action ) { $label = $context->msg( "translate-manage-action-$action" )->text(); $name = self::escapeNameForPHP( "action-$type-$key" ); - $id = Sanitizer::escapeId( "action-$key-$action" ); + $id = Sanitizer::escapeIdForAttribute( "action-$key-$action" ); $act[] = Xml::radioLabel( $label, $name, $action, $id, $action === $defaction ); } @@ -398,7 +402,7 @@ class MessageWebImporter { * See Article::doEdit. * @param int $editFlags Integer bitfield: see Article::doEdit * @throws MWException - * @return string Action result + * @return array Action result */ public static function doAction( $action, $group, $key, $code, $message, $comment = '', $user = null, $editFlags = 0 @@ -467,42 +471,47 @@ class MessageWebImporter { * @param string $comment * @param User $user * @param int $editFlags - * @return array|String + * @return array */ public static function doFuzzy( $title, $message, $comment, $user, $editFlags = 0 ) { $context = RequestContext::getMain(); + $services = MediaWikiServices::getInstance(); if ( !$context->getUser()->isAllowed( 'translate-manage' ) ) { - return $context->msg( 'badaccess-group0' )->text(); + return [ 'badaccess-group0' ]; } - $dbw = wfGetDB( DB_MASTER ); + // Edit with fuzzybot if there is no user. + if ( !$user ) { + $user = FuzzyBot::getUser(); + } // Work on all subpages of base title. $handle = new MessageHandle( $title ); $titleText = $handle->getKey(); - $conds = [ - 'page_namespace' => $title->getNamespace(), - 'page_latest=rev_id', - 'rev_text_id=old_id', - 'page_title' . $dbw->buildLike( "$titleText/", $dbw->anyString() ), - ]; - + $revStore = $services->getRevisionStore(); + $queryInfo = $revStore->getQueryInfo( [ 'page' ] ); + $dbw = $services->getDBLoadBalancer()->getConnectionRef( DB_MASTER ); $rows = $dbw->select( - [ 'page', 'revision', 'text' ], - [ 'page_title', 'page_namespace', 'old_text', 'old_flags' ], - $conds, - __METHOD__ + $queryInfo['tables'], + $queryInfo['fields'], + [ + 'page_namespace' => $title->getNamespace(), + 'page_latest=rev_id', + 'page_title' . $dbw->buildLike( "$titleText/", $dbw->anyString() ), + ], + __METHOD__, + [], + $queryInfo['joins'] ); - // Edit with fuzzybot if there is no user. - if ( !$user ) { - $user = FuzzyBot::getUser(); + $changed = []; + $slots = []; + if ( is_callable( [ $revStore, 'getContentBlobsForBatch' ] ) ) { + $slots = $revStore->getContentBlobsForBatch( $rows, [ SlotRecord::MAIN ] )->getValue(); } - // Process all rows. - $changed = []; foreach ( $rows as $row ) { global $wgTranslateDocumentationLanguageCode; @@ -514,9 +523,14 @@ class MessageWebImporter { ) { // Use imported text, not database text. $text = $message; + } elseif ( isset( $slots[$row->rev_id] ) ) { + $slot = $slots[$row->rev_id][SlotRecord::MAIN]; + $text = self::makeTextFuzzy( $slot->blob_data ); } else { - $text = Revision::getRevisionText( $row ); - $text = self::makeTextFuzzy( $text ); + $text = self::makeTextFuzzy( $revStore->newRevisionFromRow( $row ) + ->getContent( SlotRecord::MAIN ) + ->getNativeData() + ); } // Do actual import |