31 public function __construct() {
32 parent::__construct();
33 $this->addDescription(
'A script to populate fuzzy tags to revtag table.' );
36 '(optional) Namepace name or id',
40 $this->setBatchSize( 500 );
41 $this->requireExtension(
'Translate' );
44 public function execute() {
45 global $wgTranslateMessageNamespaces;
47 $namespace = $this->getOption(
'namespace', $wgTranslateMessageNamespaces );
48 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
49 if ( is_string( $namespace ) && ( !is_numeric( $namespace ) || !$nsInfo->exists( (
int)$namespace ) ) ) {
50 $namespace = $nsInfo->getCanonicalIndex( $namespace );
51 if ( $namespace ===
null ) {
52 $this->fatalError(
'Bad namespace' );
56 $dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()
57 ->getMaintenanceConnectionRef( DB_PRIMARY );
58 $revStore = MediaWikiServices::getInstance()->getRevisionStore();
60 $limit = $this->getBatchSize();
63 $this->output(
'.', 0 );
64 $res = $revStore->newSelectQueryBuilder( $dbw )
68 'page_latest = rev_id',
69 'page_namespace' => $namespace,
73 ->caller( __METHOD__ )
76 if ( !$res->numRows() ) {
81 $slots = $revStore->getContentBlobsForBatch( $res, [ SlotRecord::MAIN ] )->getValue();
82 foreach ( $res as $r ) {
83 if ( isset( $slots[$r->rev_id] ) ) {
84 $text = $slots[$r->rev_id][SlotRecord::MAIN]->blob_data;
86 $content = $revStore->newRevisionFromRow( $r )
87 ->getContent( SlotRecord::MAIN );
88 $text = Utilities::getTextFromTextContent( $content );
90 if ( str_contains( $text, TRANSLATE_FUZZY ) ) {
92 'rt_page' => $r->page_id,
93 'rt_revision' => $r->rev_id,
94 'rt_type' => RevTagStore::FUZZY_TAG,
102 $dbw->newInsertQueryBuilder()
103 ->insertInto(
'revtag' )
105 ->caller( __METHOD__ )