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