Add reciprocal language fallback for nn and nb (Norwegian)
[mediawiki.git] / maintenance / updateDoubleWidthSearch.php
blobcb2f125eca3cb619ef1505b063de1de1abe6fcc4
1 <?php
2 /**
3 * Normalize double-byte latin UTF-8 characters
5 * Usage: php updateDoubleWidthSearch.php
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @ingroup Maintenance
26 require_once __DIR__ . '/Maintenance.php';
28 /**
29 * Maintenance script to normalize double-byte latin UTF-8 characters.
31 * @ingroup Maintenance
33 class UpdateDoubleWidthSearch extends Maintenance {
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription( 'Script to normalize double-byte latin UTF-8 characters' );
38 $this->addOption( 'q', 'quiet', false, true );
39 $this->addOption(
40 'l',
41 'How long the searchindex and revision tables will be locked for',
42 false,
43 true
47 public function getDbType() {
48 return Maintenance::DB_ADMIN;
51 public function execute() {
52 $maxLockTime = $this->getOption( 'l', 20 );
54 $dbw = $this->getDB( DB_MASTER );
55 if ( $dbw->getType() !== 'mysql' ) {
56 $this->error( "This change is only needed on MySQL, quitting.\n", true );
59 $res = $this->findRows( $dbw );
60 $this->updateSearchIndex( $maxLockTime, [ $this, 'searchIndexUpdateCallback' ], $dbw, $res );
62 $this->output( "Done\n" );
65 public function searchIndexUpdateCallback( $dbw, $row ) {
66 return $this->updateSearchIndexForPage( $dbw, $row->si_page );
69 private function findRows( $dbw ) {
70 $searchindex = $dbw->tableName( 'searchindex' );
71 $regexp = '[[:<:]]u8efbd([89][1-9a]|8[b-f]|90)[[:>:]]';
72 $sql = "SELECT si_page FROM $searchindex
73 WHERE ( si_text RLIKE '$regexp' )
74 OR ( si_title RLIKE '$regexp' )";
76 return $dbw->query( $sql, __METHOD__ );
80 $maintClass = "UpdateDoubleWidthSearch";
81 require_once RUN_MAINTENANCE_IF_MAIN;