updateDoubleWidthSearch.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Normalize double-byte latin UTF-8 characters
  4. *
  5. * Usage: php updateDoubleWidthSearch.php
  6. *
  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.
  11. *
  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.
  16. *
  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
  21. *
  22. * @file
  23. * @ingroup Maintenance
  24. */
  25. require_once __DIR__ . '/Maintenance.php';
  26. /**
  27. * Maintenance script to normalize double-byte latin UTF-8 characters.
  28. *
  29. * @ingroup Maintenance
  30. */
  31. class UpdateDoubleWidthSearch extends Maintenance {
  32. public function __construct() {
  33. parent::__construct();
  34. $this->addDescription( 'Script to normalize double-byte latin UTF-8 characters' );
  35. $this->addOption( 'q', 'quiet', false, true );
  36. $this->addOption(
  37. 'l',
  38. 'How long the searchindex and revision tables will be locked for',
  39. false,
  40. true
  41. );
  42. }
  43. public function getDbType() {
  44. return Maintenance::DB_ADMIN;
  45. }
  46. public function execute() {
  47. $maxLockTime = $this->getOption( 'l', 20 );
  48. $dbw = $this->getDB( DB_MASTER );
  49. if ( $dbw->getType() !== 'mysql' ) {
  50. $this->error( "This change is only needed on MySQL, quitting.\n", true );
  51. }
  52. $res = $this->findRows( $dbw );
  53. $this->updateSearchIndex( $maxLockTime, [ $this, 'searchIndexUpdateCallback' ], $dbw, $res );
  54. $this->output( "Done\n" );
  55. }
  56. public function searchIndexUpdateCallback( $dbw, $row ) {
  57. return $this->updateSearchIndexForPage( $dbw, $row->si_page );
  58. }
  59. private function findRows( $dbw ) {
  60. $searchindex = $dbw->tableName( 'searchindex' );
  61. $regexp = '[[:<:]]u8efbd([89][1-9a]|8[b-f]|90)[[:>:]]';
  62. $sql = "SELECT si_page FROM $searchindex
  63. WHERE ( si_text RLIKE '$regexp' )
  64. OR ( si_title RLIKE '$regexp' )";
  65. return $dbw->query( $sql, __METHOD__ );
  66. }
  67. }
  68. $maintClass = "UpdateDoubleWidthSearch";
  69. require_once RUN_MAINTENANCE_IF_MAIN;