28 public function __construct() {
29 parent::__construct();
30 $this->addDescription(
'Creates serialised database of messages that need ' .
31 'checking for problems.' );
34 'Comma separated list of group IDs to process (can use * as wildcard).',
41 '(optional) Enable verbose logging. Default: off',
45 $this->requireExtension(
'Translate' );
48 public function execute() {
49 $codes = MediaWikiServices::getInstance()
50 ->getLanguageNameUtils()
51 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::ALL );
54 global $wgTranslateDocumentationLanguageCode;
55 if ( $wgTranslateDocumentationLanguageCode ) {
56 unset( $codes[$wgTranslateDocumentationLanguageCode] );
59 $reqGroupsPattern = $this->getOption(
'group' );
60 $reqGroups = explode(
',', $reqGroupsPattern );
61 $reqGroups = array_map(
'trim', $reqGroups );
62 $reqGroups = MessageGroups::expandWildcards( $reqGroups );
64 $verbose = $this->hasOption(
'verbose' );
67 $this->fatalError(
"Pattern '$reqGroupsPattern' did not match any groups" );
70 $groups = MessageGroups::singleton()->getGroups();
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 self::tagFuzzy( $problematic );
133 public static function tagFuzzy( array $problematic ):
void {
134 if ( $problematic === [] ) {
138 $titleConditions = [];
139 $dbw = wfGetDB( 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->select(
'page', [
'page_id',
'page_latest' ], $conds, __METHOD__ );
158 foreach ( $res as $row ) {
160 'rt_page' => $row->page_id,
161 'rt_revision' => $row->page_latest,
162 'rt_type' => RevTagStore::FUZZY_TAG
165 $dbw->replace(
'revtag', [ [
'rt_type',
'rt_page',
'rt_revision' ] ], $inserts, __METHOD__ );