28 public function __construct() {
29 parent::__construct();
30 $this->addDescription(
'A script to populate fuzzy tags to revtag table.' );
33 '(optional) Namepace name or id',
37 $this->setBatchSize( 5000 );
38 $this->requireExtension(
'Translate' );
41 public function execute() {
42 global $wgTranslateMessageNamespaces;
44 $namespace = $this->getOption(
'namespace', $wgTranslateMessageNamespaces );
45 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
46 if ( is_string( $namespace ) && !$nsInfo->exists( $namespace ) ) {
47 $namespace = $nsInfo->getCanonicalIndex( $namespace );
48 if ( $namespace ===
null ) {
49 $this->fatalError(
'Bad namespace' );
53 $dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()
54 ->getMaintenanceConnectionRef( DB_PRIMARY );
55 $revStore = MediaWikiServices::getInstance()->getRevisionStore();
56 $queryInfo = $revStore->getQueryInfo( [
'page' ] );
58 $limit = $this->getBatchSize();
62 $this->output(
'.', 0 );
63 $options = [
'LIMIT' => $limit,
'OFFSET' => $offset ];
68 'page_latest = rev_id',
69 'page_namespace' => $namespace,
76 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 ( strpos( $text, TRANSLATE_FUZZY ) !==
false ) {
91 'rt_page' => $r->page_id,
92 'rt_revision' => $r->rev_id,
93 'rt_type' => RevTagStore::FUZZY_TAG
101 $dbw->replace(
'revtag', [ [
'rt_type',
'rt_page',
'rt_revision' ] ], $inserts, __METHOD__ );