24 public const ACTION_DELETE =
'delete';
26 public static function newJob(
28 ?
string $triggerAction =
null,
29 ?
string $unitTitleText =
null
31 $job =
new self( $target, [
'triggerAction' => $triggerAction,
'unitTitle' => $unitTitleText ] );
32 $job->setUser( FuzzyBot::getUser() );
33 $job->setFlags( EDIT_FORCE_BOT );
34 $job->setSummary( wfMessage(
'tpt-render-summary' )->inContentLanguage()->text() );
39 public function __construct( Title $title, array $params = [] ) {
40 parent::__construct(
'RenderTranslationPageJob', $title, $params );
41 $this->removeDuplicates =
true;
44 public function run():
bool {
46 $mwServices = MediaWikiServices::getInstance();
48 $lb = $mwServices->getDBLoadBalancerFactory();
49 if ( !$lb->waitForReplication() ) {
50 $this->logWarning(
'Continuing despite replication lag' );
54 $title = $this->title;
56 $tpPage = TranslatablePage::getTranslationPageFromTitle( $title );
58 $this->logError(
'Cannot render translation page!' );
63 $user = $this->getUser();
64 $summary = $this->getSummary();
65 $flags = $this->getFlags();
70 if ( $this->isDeleteTrigger() ) {
71 $flags = ( $flags | EDIT_UPDATE ) & ~EDIT_NEW;
75 Hooks::$allowTargetEdit =
true;
76 $commentStoreComment = CommentStoreComment::newUnsavedComment( $summary );
77 $content = $tpPage->getPageContent();
79 $pageUpdater = $mwServices->getWikiPageFactory()
80 ->newFromTitle( $title )
81 ->newPageUpdater( $user );
82 $pageUpdater->setContent( SlotRecord::MAIN, $content );
84 if ( $user->authorizeWrite(
'autopatrol', $title ) ) {
85 $pageUpdater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
88 $pageUpdater->saveRevision( $commentStoreComment, $flags );
89 $status = $pageUpdater->getStatus();
91 if ( !$status->isGood() ) {
92 if ( $this->isDeleteTrigger() && $status->hasMessage(
'edit-gone-missing' ) ) {
93 $this->logInfo(
'Translation page missing with delete trigger' );
96 'Error while editing content in page.',
98 'content' => $content->getTextForSummary(),
99 'errors' => $status->getErrors()
105 $this->logInfo(
'Finished page edit operation' );
106 Hooks::$allowTargetEdit =
false;
108 $this->logInfo(
'Finished TranslateRenderJob' );
112 public function setFlags(
int $flags ):
void {
113 $this->params[
'flags'] = $flags;
116 private function getFlags():
int {
117 return $this->params[
'flags'];
120 public function setSummary(
string $summary ):
void {
121 $this->params[
'summary'] = $summary;
128 unset( $info[
'params'][
'unitTitle'] );
132 private function getSummary(): string {
133 return $this->params[
'summary'];
138 if ( $user instanceof UserIdentity ) {
139 $this->params[
'user'] = $user->getName();
141 $this->params[
'user'] = $user;
146 private function getUser(): User {
147 $userFactory = MediaWikiServices::getInstance()->getUserFactory();
148 return $userFactory->newFromName( $this->params[
'user'], UserRigorOptions::RIGOR_NONE );
151 private function isDeleteTrigger(): bool {
152 $triggerAction = $this->params[
'triggerAction'] ?? null;
153 return $triggerAction === self::ACTION_DELETE;
156 private function logJobStart(): void {
157 $unitTitleText = $this->params[
'unitTitle'] ?? null;
158 $logMessage =
'Starting TranslateRenderJob ';
159 if ( $unitTitleText ) {
160 $logMessage .=
"trigged by $unitTitleText ";
163 if ( $this->isDeleteTrigger() ) {
164 $logMessage .=
'- [deletion] ';
167 $this->logInfo( trim( $logMessage ) );
return[ 'Translate:ConfigHelper'=> static function():ConfigHelper { return new ConfigHelper();}, 'Translate:CsvTranslationImporter'=> static function(MediaWikiServices $services):CsvTranslationImporter { return new CsvTranslationImporter( $services->getWikiPageFactory());}, 'Translate:EntitySearch'=> static function(MediaWikiServices $services):EntitySearch { return new EntitySearch($services->getMainWANObjectCache(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), MessageGroups::singleton(), $services->getNamespaceInfo(), $services->get( 'Translate:MessageIndex'), $services->getTitleParser(), $services->getTitleFormatter());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->getMainConfig(), $services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance( 'Translate.GroupSynchronization'), MessageIndex::singleton());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore(new RevTagStore(), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'));}, 'Translate:MessageGroupReview'=> static function(MediaWikiServices $services):MessageGroupReview { return new MessageGroupReview($services->getDBLoadBalancer(), $services->getHookContainer());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=$services->getMainConfig() ->get( 'TranslateMessageIndex');if(is_string( $params)) { $params=(array) $params;} $class=array_shift( $params);return new $class( $params);}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getDBLoadBalancer(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'));}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleMover'=> static function(MediaWikiServices $services):TranslatableBundleMover { return new TranslatableBundleMover($services->getMovePageFactory(), $services->getJobQueueGroup(), $services->getLinkBatchFactory(), $services->get( 'Translate:TranslatableBundleFactory'), $services->get( 'Translate:SubpageListBuilder'), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), new RevTagStore(), $services->getDBLoadBalancer());}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { $db=$services->getDBLoadBalancer() ->getConnectionRef(DB_REPLICA);return new TranslationStashStorage( $db);}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory());}, 'Translate:TranslationUnitStoreFactory'=> static function(MediaWikiServices $services):TranslationUnitStoreFactory { return new TranslationUnitStoreFactory( $services->getDBLoadBalancer());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getDBLoadBalancer());return new TranslatorActivity($services->getMainObjectStash(), $query, $services->getJobQueueGroup());}, 'Translate:TtmServerFactory'=> static function(MediaWikiServices $services):TtmServerFactory { $config=$services->getMainConfig();$default=$config->get( 'TranslateTranslationDefaultService');if( $default===false) { $default=null;} return new TtmServerFactory( $config->get( 'TranslateTranslationServices'), $default);}]
@phpcs-require-sorted-array