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\Maintenance\Maintenance;
16use MediaWiki\MediaWikiServices;
17
18if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
19 $IP = getenv( 'MW_INSTALL_PATH' );
20} else {
21 $dir = __DIR__;
22 $IP = "$dir/../../..";
23}
24require_once "$IP/maintenance/Maintenance.php";
25
30class RefreshTranslatablePages extends Maintenance {
31 private const USE_NON_PRIORITIZED_JOBS = true;
32
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Ensure all translation pages are up to date.' );
36 $this->setBatchSize( 300 );
37 $this->addOption( 'jobqueue', 'Use JobQueue (asynchronous)' );
38 $this->requireExtension( 'Translate' );
39 }
40
41 public function execute() {
42 $groups = MessageGroups::singleton()->getGroups();
43 $mwInstance = MediaWikiServices::getInstance();
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 $this->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.