27 public function __construct() {
28 parent::__construct();
29 $this->addDescription(
'Creates serialised database of messages that need ' .
30 'checking for problems.' );
33 'Comma separated list of group IDs to process (can use * as wildcard).',
40 '(optional) Enable verbose logging. Default: off',
44 $this->requireExtension(
'Translate' );
47 public function execute() {
48 $codes = MediaWikiServices::getInstance()
49 ->getLanguageNameUtils()
50 ->getLanguageNames(
null, LanguageNameUtils::ALL );
53 global $wgTranslateDocumentationLanguageCode;
54 if ( $wgTranslateDocumentationLanguageCode ) {
55 unset( $codes[$wgTranslateDocumentationLanguageCode] );
58 $reqGroupsPattern = $this->getOption(
'group' );
59 $reqGroups = explode(
',', $reqGroupsPattern );
60 $reqGroups = array_map(
'trim', $reqGroups );
61 $reqGroups = MessageGroups::expandWildcards( $reqGroups );
63 $verbose = $this->hasOption(
'verbose' );
66 $this->fatalError(
"Pattern '$reqGroupsPattern' did not match any groups" );
69 $groups = MessageGroups::singleton()->getGroups();
70 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
73 foreach ( $reqGroups as $id ) {
74 $g = MessageGroups::getGroup( $id );
77 $sourceLanguage = $g->getSourceLanguage();
79 $validator = $g->getValidator();
82 $this->output(
"Skipping group $id due to lack of validators" );
88 $collection = $g->initCollection( $sourceLanguage,
true );
89 if ( !count( $collection ) ) {
93 $this->output(
"Processing group $id: ", $id );
97 unset( $langCodes[$sourceLanguage] );
99 $langCodes = array_keys( $langCodes );
102 foreach ( $langCodes as $code ) {
103 $this->output(
"$code ", $id );
107 $collection->resetForNewLanguage( $code );
108 $collection->loadTranslations();
109 $collection->filter(
'ignored' );
110 $collection->filter(
'fuzzy' );
111 $collection->filter(
'translated',
false );
113 foreach ( $collection as $key => $message ) {
114 $result = $validator->quickValidate( $message, $code );
115 if ( $result->hasIssues() ) {
118 $nsText = $contLang->getNsText( $g->getNamespace() );
119 $this->output(
"# [[$nsText:$key/$code]]\n" );
123 $problematic[] = [ $g->getNamespace(),
"$key/$code" ];
127 self::tagFuzzy( $problematic );
132 public static function tagFuzzy( array $problematic ):
void {
133 if ( $problematic === [] ) {
137 $titleConditions = [];
138 $dbw = wfGetDB( DB_PRIMARY );
140 foreach ( $problematic as $p ) {
142 $title = Title::makeTitleSafe( $p[0], $p[1] );
143 $titleText = $title->getDBkey();
144 $titleConditions[] = $dbw->makeList(
146 'page_namespace' => $p[0],
147 'page_title' => $titleText
153 $conds = $dbw->makeList( $titleConditions, LIST_OR );
155 $res = $dbw->select(
'page', [
'page_id',
'page_latest' ], $conds, __METHOD__ );
157 foreach ( $res as $row ) {
159 'rt_page' => $row->page_id,
160 'rt_revision' => $row->page_latest,
161 'rt_type' => RevTagStore::FUZZY_TAG
164 $dbw->replace(
'revtag', [ [
'rt_type',
'rt_page',
'rt_revision' ] ], $inserts, __METHOD__ );