mDescription = 'A script to populate fuzzy tags to revtag table.'; $this->addOption( 'namespace', '(optional) Namepace name or id', /*required*/false, /*has arg*/true ); } public function execute() { global $wgTranslateMessageNamespaces; $namespace = $this->getOption( 'namespace', $wgTranslateMessageNamespaces ); if ( is_string( $namespace ) && !MWNamespace::exists( $namespace ) ) { $namespace = MWNamespace::getCanonicalIndex( $namespace ); if ( $namespace === null ) { $this->error( 'Bad namespace', true ); } } $dbw = wfGetDB( DB_MASTER ); $tables = [ 'page', 'text', 'revision' ]; $fields = [ 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' ]; $conds = [ 'page_latest = rev_id', 'old_id = rev_text_id', 'page_namespace' => $namespace, ]; $limit = 100; $offset = 0; while ( true ) { $inserts = []; $this->output( '.', 0 ); $options = [ 'LIMIT' => $limit, 'OFFSET' => $offset ]; $res = $dbw->select( $tables, $fields, $conds, __METHOD__, $options ); if ( !$res->numRows() ) { break; } foreach ( $res as $r ) { $text = Revision::getRevisionText( $r ); if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) { $inserts[] = [ 'rt_page' => $r->page_id, 'rt_revision' => $r->rev_id, 'rt_type' => RevTag::getType( 'fuzzy' ), ]; } } $offset += $limit; $dbw->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ ); } } } $maintClass = PopulateFuzzy::class; require_once RUN_MAINTENANCE_IF_MAIN;