29 public function __construct() {
30 parent::__construct();
31 $this->addDescription(
'Creates serialised database of messages that need ' .
32 'checking for problems.' );
35 'Comma separated list of group IDs to process (can use * as wildcard).',
42 '(optional) Enable verbose logging. Default: off',
46 $this->requireExtension(
'Translate' );
49 public function execute() {
50 $codes = MediaWikiServices::getInstance()
51 ->getLanguageNameUtils()
52 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::ALL );
55 global $wgTranslateDocumentationLanguageCode;
56 if ( $wgTranslateDocumentationLanguageCode ) {
57 unset( $codes[$wgTranslateDocumentationLanguageCode] );
60 $reqGroupsPattern = $this->getOption(
'group' );
61 $reqGroups = explode(
',', $reqGroupsPattern );
62 $reqGroups = array_map(
'trim', $reqGroups );
63 $reqGroups = MessageGroups::expandWildcards( $reqGroups );
65 $verbose = $this->hasOption(
'verbose' );
68 $this->fatalError(
"Pattern '$reqGroupsPattern' did not match any groups" );
71 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
74 foreach ( $reqGroups as $id ) {
75 $g = MessageGroups::getGroup( $id );
78 $sourceLanguage = $g->getSourceLanguage();
80 $validator = $g->getValidator();
83 $this->output(
"Skipping group $id due to lack of validators" );
89 $collection = $g->initCollection( $sourceLanguage,
true );
90 if ( !count( $collection ) ) {
94 $this->output(
"Processing group $id: ", $id );
98 unset( $langCodes[$sourceLanguage] );
100 $langCodes = array_keys( $langCodes );
103 foreach ( $langCodes as $code ) {
104 $this->output(
"$code ", $id );
108 $collection->resetForNewLanguage( $code );
109 $collection->loadTranslations();
110 $collection->filter(
'ignored' );
111 $collection->filter(
'fuzzy' );
112 $collection->filter(
'translated',
false );
114 foreach ( $collection as $key => $message ) {
115 $result = $validator->quickValidate( $message, $code );
116 if ( $result->hasIssues() ) {
119 $nsText = $contLang->getNsText( $g->getNamespace() );
120 $this->output(
"# [[$nsText:$key/$code]]\n" );
124 $problematic[] = [ $g->getNamespace(),
"$key/$code" ];
128 $this->tagFuzzy( $problematic );
133 public function tagFuzzy( array $problematic ):
void {
134 if ( $problematic === [] ) {
138 $titleConditions = [];
139 $dbw = $this->getDB( DB_PRIMARY );
141 foreach ( $problematic as $p ) {
143 $title = Title::makeTitleSafe( $p[0], $p[1] );
144 $titleText = $title->getDBkey();
145 $titleConditions[] = $dbw->makeList(
147 'page_namespace' => $p[0],
148 'page_title' => $titleText
154 $conds = $dbw->makeList( $titleConditions, LIST_OR );
156 $res = $dbw->newSelectQueryBuilder()
157 ->select( [
'page_id',
'page_latest' ] )
160 ->caller( __METHOD__ )
163 foreach ( $res as $row ) {
165 'rt_page' => $row->page_id,
166 'rt_revision' => $row->page_latest,
167 'rt_type' => RevTagStore::FUZZY_TAG
170 $dbw->replace(
'revtag', [ [
'rt_type',
'rt_page',
'rt_revision' ] ], $inserts, __METHOD__ );