27 public function __construct() {
28 parent::__construct();
29 $this->addDescription(
'A script to populate fuzzy tags to revtag table.' );
32 '(optional) Namepace name or id',
36 $this->setBatchSize( 5000 );
37 $this->requireExtension(
'Translate' );
40 public function execute() {
41 global $wgTranslateMessageNamespaces;
43 $namespace = $this->getOption(
'namespace', $wgTranslateMessageNamespaces );
44 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
45 if ( is_string( $namespace ) && !$nsInfo->exists( $namespace ) ) {
46 $namespace = $nsInfo->getCanonicalIndex( $namespace );
47 if ( $namespace ===
null ) {
48 $this->fatalError(
'Bad namespace' );
52 $dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()
53 ->getMaintenanceConnectionRef( DB_PRIMARY );
54 $revStore = MediaWikiServices::getInstance()->getRevisionStore();
55 $queryInfo = $revStore->getQueryInfo( [
'page' ] );
57 $limit = $this->getBatchSize();
61 $this->output(
'.', 0 );
62 $options = [
'LIMIT' => $limit,
'OFFSET' => $offset ];
67 'page_latest = rev_id',
68 'page_namespace' => $namespace,
75 if ( !$res->numRows() ) {
79 $slots = $revStore->getContentBlobsForBatch( $res, [ SlotRecord::MAIN ] )->getValue();
80 foreach ( $res as $r ) {
81 if ( isset( $slots[$r->rev_id] ) ) {
82 $text = $slots[$r->rev_id][SlotRecord::MAIN]->blob_data;
84 $content = $revStore->newRevisionFromRow( $r )
85 ->getContent( SlotRecord::MAIN );
86 $text = TranslateUtils::getTextFromTextContent( $content );
88 if ( strpos( $text, TRANSLATE_FUZZY ) !==
false ) {
90 'rt_page' => $r->page_id,
91 'rt_revision' => $r->rev_id,
92 'rt_type' => RevTagStore::FUZZY_TAG
100 $dbw->replace(
'revtag', [ [
'rt_type',
'rt_page',
'rt_revision' ] ], $inserts, __METHOD__ );