populateFuzzy.php
Go to the documentation of this file.00001 <?php
00011
00012 if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
00013 $IP = getenv( 'MW_INSTALL_PATH' );
00014 } else {
00015 $dir = __DIR__;
00016 $IP = "$dir/../../..";
00017 }
00018 require_once "$IP/maintenance/Maintenance.php";
00019
00021 class PopulateFuzzy extends Maintenance {
00022 public function __construct() {
00023 parent::__construct();
00024 $this->mDescription = 'A script to populate fuzzy tags to revtag table.';
00025 $this->addOption(
00026 'namespace',
00027 '(optional) Namepace name or id',
00028 false,
00029 true
00030 );
00031 }
00032
00033 public function execute() {
00034 global $wgTranslateMessageNamespaces;
00035
00036 $namespace = $this->getOption( 'namespace', $wgTranslateMessageNamespaces );
00037 if ( is_string( $namespace ) ) {
00038 if ( !MWNamespace::exists( $namespace ) ) {
00039 $namespace = MWNamespace::getCanonicalIndex( $namespace );
00040 if ( $namespace === null ) {
00041 $this->error( 'Bad namespace', true );
00042 }
00043 }
00044 }
00045
00046 $db = wfGetDB( DB_MASTER );
00047 $tables = array( 'page', 'text', 'revision' );
00048 $fields = array( 'page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags' );
00049 $conds = array(
00050 'page_latest = rev_id',
00051 'old_id = rev_text_id',
00052 'page_namespace' => $namespace,
00053 );
00054
00055 $limit = 100;
00056 $offset = 0;
00057 while ( true ) {
00058 $inserts = array();
00059 $this->output( '.', 0 );
00060 $options = array( 'LIMIT' => $limit, 'OFFSET' => $offset );
00061 $res = $db->select( $tables, $fields, $conds, __METHOD__, $options );
00062
00063 if ( !$res->numRows() ) {
00064 break;
00065 }
00066
00067 foreach ( $res as $r ) {
00068 $text = Revision::getRevisionText( $r );
00069 if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) {
00070 $inserts[] = array(
00071 'rt_page' => $r->page_id,
00072 'rt_revision' => $r->rev_id,
00073 'rt_type' => RevTag::getType( 'fuzzy' ),
00074 );
00075 }
00076 }
00077
00078 $offset += $limit;
00079
00080 $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
00081 }
00082 }
00083 }
00084
00085 $maintClass = 'PopulateFuzzy';
00086 require_once RUN_MAINTENANCE_IF_MAIN;