Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
refresh-translatable-pages.php
Go to the documentation of this file.
1<?php
10// Standard boilerplate to define $IP
11
15use MediaWiki\MediaWikiServices;
16
17if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
18 $IP = getenv( 'MW_INSTALL_PATH' );
19} else {
20 $dir = __DIR__;
21 $IP = "$dir/../../..";
22}
23require_once "$IP/maintenance/Maintenance.php";
24
29class RefreshTranslatablePages extends Maintenance {
30 private const USE_NON_PRIORITIZED_JOBS = true;
31
32 public function __construct() {
33 parent::__construct();
34 $this->addDescription( 'Ensure all translation pages are up to date.' );
35 $this->setBatchSize( 300 );
36 $this->addOption( 'jobqueue', 'Use JobQueue (asynchronous)' );
37 $this->requireExtension( 'Translate' );
38 }
39
40 public function execute() {
41 $groups = MessageGroups::singleton()->getGroups();
42 $mwInstance = MediaWikiServices::getInstance();
43 $lbFactory = $mwInstance->getDBLoadBalancerFactory();
44 $jobQueueGroup = $mwInstance->getJobQueueGroup();
45
46 $counter = 0;
47 $jobCounter = 0;
48 $useJobQueue = $this->hasOption( 'jobqueue' );
49
50 foreach ( $groups as $group ) {
51 if ( !$group instanceof WikiPageMessageGroup ) {
52 continue;
53 }
54
55 $counter++;
56 if ( ( $counter % $this->mBatchSize ) === 0 ) {
57 $lbFactory->waitForReplication();
58 }
59
60 $page = TranslatablePage::newFromTitle( $group->getTitle() );
61 $jobs = UpdateTranslatablePageJob::getRenderJobs( $page, self::USE_NON_PRIORITIZED_JOBS );
62 if ( $useJobQueue ) {
63 $jobCounter += count( $jobs );
64 $jobQueueGroup->push( $jobs );
65 } else {
66 foreach ( $jobs as $job ) {
67 $job->run();
68 }
69 }
70 }
71
72 if ( $useJobQueue ) {
73 $this->output( "Queued $jobCounter refresh job(s) for $counter translatable pages.\n" );
74 } else {
75 $this->output( "Refreshed $counter translatable pages.\n" );
76 }
77 }
78}
79
80$maintClass = RefreshTranslatablePages::class;
81require_once RUN_MAINTENANCE_IF_MAIN;
Factory class for accessing message groups individually by id or all of them as a list.
Mixed bag of methods related to translatable pages.
Job for updating translation units and translation pages when a translatable page is marked for trans...
Script to ensure all translation pages are up to date.
Wraps the translatable page sections into a message group.