summaryrefslogtreecommitdiff
path: root/maintenance/updateDoubleWidthSearch.php
blob: 61545f8df27c21827e32d872ac2d8f6e5240c7b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
 * Script to normalize double-byte latin UTF-8 characters
 *
 * Usage: php updateDoubleWidthSearch.php
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @ingroup Maintenance
 */

require_once( dirname( __FILE__ ) . '/Maintenance.php' );

class UpdateDoubleWidthSearch extends Maintenance {

	public function __construct() {
		parent::__construct();
		$this->mDescription = "Script to normalize double-byte latin UTF-8 characters";
		$this->addOption( 'q', 'quiet', false, true );
		$this->addOption( 'l', 'How long the searchindex and revision tables will be locked for', false, true );
	}

	public function getDbType() {
		return Maintenance::DB_ADMIN;
	}

	public function execute() {
		$maxLockTime = $this->getOption( 'l', 20 );

		$dbw = wfGetDB( DB_MASTER );
		if ( $dbw->getType() !== 'mysql' ) {
			$this->error( "This change is only needed on MySQL, quitting.\n", true );
		}

		$res = $this->findRows( $dbw );
		$this->updateSearchIndex( $maxLockTime, array( $this, 'searchIndexUpdateCallback' ), $dbw, $res );

		$this->output( "Done\n" );
	}

	public function searchIndexUpdateCallback( $dbw, $row ) {
		return $this->updateSearchIndexForPage( $dbw, $row->si_page );
	}

	private function findRows( $dbw ) {
		$searchindex = $dbw->tableName( 'searchindex' );
		$regexp = '[[:<:]]u8efbd([89][1-9a]|8[b-f]|90)[[:>:]]';
		$sql = "SELECT si_page FROM $searchindex
				 WHERE ( si_text RLIKE '$regexp' )
					OR ( si_title RLIKE '$regexp' )";
		return $dbw->query( $sql, __METHOD__ );
	}
}

$maintClass = "UpdateDoubleWidthSearch";
require_once( RUN_MAINTENANCE_IF_MAIN );