30 public function __construct() {
31 parent::__construct();
32 $this->addDescription(
'A script to populate fuzzy tags to revtag table.' );
35 '(optional) Namepace name or id',
39 $this->setBatchSize( 500 );
40 $this->requireExtension(
'Translate' );
43 public function execute() {
44 global $wgTranslateMessageNamespaces;
46 $namespace = $this->getOption(
'namespace', $wgTranslateMessageNamespaces );
47 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
48 if ( is_string( $namespace ) && ( !is_numeric( $namespace ) || !$nsInfo->exists( (
int)$namespace ) ) ) {
49 $namespace = $nsInfo->getCanonicalIndex( $namespace );
50 if ( $namespace ===
null ) {
51 $this->fatalError(
'Bad namespace' );
55 $dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()
56 ->getMaintenanceConnectionRef( DB_PRIMARY );
57 $revStore = MediaWikiServices::getInstance()->getRevisionStore();
59 $limit = $this->getBatchSize();
62 $this->output(
'.', 0 );
63 $res = $revStore->newSelectQueryBuilder( $dbw )
67 'page_latest = rev_id',
68 'page_namespace' => $namespace,
72 ->caller( __METHOD__ )
75 if ( !$res->numRows() ) {
80 $slots = $revStore->getContentBlobsForBatch( $res, [ SlotRecord::MAIN ] )->getValue();
81 foreach ( $res as $r ) {
82 if ( isset( $slots[$r->rev_id] ) ) {
83 $text = $slots[$r->rev_id][SlotRecord::MAIN]->blob_data;
85 $content = $revStore->newRevisionFromRow( $r )
86 ->getContent( SlotRecord::MAIN );
87 $text = Utilities::getTextFromTextContent( $content );
89 if ( str_contains( $text, TRANSLATE_FUZZY ) ) {
91 'rt_page' => $r->page_id,
92 'rt_revision' => $r->rev_id,
93 'rt_type' => RevTagStore::FUZZY_TAG,
101 $dbw->insert(
'revtag', $inserts, __METHOD__ );