summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/scripts/refresh-translatable-pages.php
blob: c92d853b871525bcafa5bec6597e03213c6b137d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
 * Script to ensure all translation pages are up to date.
 *
 * @author Niklas Laxström
 * @license GPL-2.0+
 * @file
 */

// Standard boilerplate to define $IP
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
	$IP = getenv( 'MW_INSTALL_PATH' );
} else {
	$dir = __DIR__;
	$IP = "$dir/../../..";
}
require_once "$IP/maintenance/Maintenance.php";

/**
 * Script to ensure all translation pages are up to date
 * @since 2013-04
 */
class RefreshTranslatablePages extends Maintenance {
	public function __construct() {
		parent::__construct();
		$this->mDescription = 'Ensure all translation pages are up to date.';
		$this->setBatchSize( 300 );
	}

	public function execute() {
		$groups = MessageGroups::singleton()->getGroups();
		$counter = 0;

		/** @var MessageGroup $group */
		foreach ( $groups as $group ) {
			if ( !$group instanceof WikiPageMessageGroup ) {
				continue;
			}

			$counter++;
			if ( ( $counter % $this->mBatchSize ) === 0 ) {
				wfWaitForSlaves();
			}

			// Get all translation subpages and refresh each one of them
			$page = TranslatablePage::newFromTitle( $group->getTitle() );
			$translationPages = $page->getTranslationPages();

			foreach ( $translationPages as $subpage ) {
				$job = TranslateRenderJob::newJob( $subpage );
				$job->run();
			}
		}

		$this->output( "Refreshed $counter translatable pages.\n" );
	}
}

$maintClass = 'RefreshTranslatablePages';
require_once RUN_MAINTENANCE_IF_MAIN;