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 public function __construct() {
31 parent::__construct();
32 $this->addDescription( 'Ensure all translation pages are up to date.' );
33 $this->setBatchSize( 300 );
34 $this->addOption( 'jobqueue', 'Use JobQueue (asynchronous)' );
35 $this->requireExtension( 'Translate' );
36 }
37
38 public function execute() {
39 $groups = MessageGroups::singleton()->getGroups();
40 $mwInstance = MediaWikiServices::getInstance();
41 $lbFactory = $mwInstance->getDBLoadBalancerFactory();
42 $jobQueueGroup = $mwInstance->getJobQueueGroup();
43
44 $counter = 0;
45 $useJobQueue = $this->hasOption( 'jobqueue' );
46
48 foreach ( $groups as $group ) {
49 if ( !$group instanceof WikiPageMessageGroup ) {
50 continue;
51 }
52
53 $counter++;
54 if ( ( $counter % $this->mBatchSize ) === 0 ) {
55 $lbFactory->waitForReplication();
56 }
57
58 $page = TranslatablePage::newFromTitle( $group->getTitle() );
59 $jobs = UpdateTranslatablePageJob::getRenderJobs( $page );
60 if ( $useJobQueue ) {
61 $jobQueueGroup->push( $jobs );
62 } else {
63 foreach ( $jobs as $job ) {
64 $job->run();
65 }
66 }
67 }
68
69 if ( $useJobQueue ) {
70 $this->output( "Queued refresh for $counter translatable pages.\n" );
71 } else {
72 $this->output( "Refreshed $counter translatable pages.\n" );
73 }
74 }
75}
76
77$maintClass = RefreshTranslatablePages::class;
78require_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.