MediaWiki  REL1_24
updateDoubleWidthSearch.php
Go to the documentation of this file.
00001 <?php
00026 require_once __DIR__ . '/Maintenance.php';
00027 
00033 class UpdateDoubleWidthSearch extends Maintenance {
00034 
00035     public function __construct() {
00036         parent::__construct();
00037         $this->mDescription = "Script to normalize double-byte latin UTF-8 characters";
00038         $this->addOption( 'q', 'quiet', false, true );
00039         $this->addOption(
00040             'l',
00041             'How long the searchindex and revision tables will be locked for',
00042             false,
00043             true
00044         );
00045     }
00046 
00047     public function getDbType() {
00048         return Maintenance::DB_ADMIN;
00049     }
00050 
00051     public function execute() {
00052         $maxLockTime = $this->getOption( 'l', 20 );
00053 
00054         $dbw = wfGetDB( DB_MASTER );
00055         if ( $dbw->getType() !== 'mysql' ) {
00056             $this->error( "This change is only needed on MySQL, quitting.\n", true );
00057         }
00058 
00059         $res = $this->findRows( $dbw );
00060         $this->updateSearchIndex( $maxLockTime, array( $this, 'searchIndexUpdateCallback' ), $dbw, $res );
00061 
00062         $this->output( "Done\n" );
00063     }
00064 
00065     public function searchIndexUpdateCallback( $dbw, $row ) {
00066         return $this->updateSearchIndexForPage( $dbw, $row->si_page );
00067     }
00068 
00069     private function findRows( $dbw ) {
00070         $searchindex = $dbw->tableName( 'searchindex' );
00071         $regexp = '[[:<:]]u8efbd([89][1-9a]|8[b-f]|90)[[:>:]]';
00072         $sql = "SELECT si_page FROM $searchindex
00073                  WHERE ( si_text RLIKE '$regexp' )
00074                     OR ( si_title RLIKE '$regexp' )";
00075 
00076         return $dbw->query( $sql, __METHOD__ );
00077     }
00078 }
00079 
00080 $maintClass = "UpdateDoubleWidthSearch";
00081 require_once RUN_MAINTENANCE_IF_MAIN;