MediaWiki  1.30.0
updateDoubleWidthSearch.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/Maintenance.php';
27 
34 
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
44  );
45  }
46 
47  public function getDbType() {
48  return Maintenance::DB_ADMIN;
49  }
50 
51  public function execute() {
52  $maxLockTime = $this->getOption( 'l', 20 );
53 
54  $dbw = $this->getDB( DB_MASTER );
55  if ( $dbw->getType() !== 'mysql' ) {
56  $this->error( "This change is only needed on MySQL, quitting.\n", true );
57  }
58 
59  $res = $this->findRows( $dbw );
60  $this->updateSearchIndex( $maxLockTime, [ $this, 'searchIndexUpdateCallback' ], $dbw, $res );
61 
62  $this->output( "Done\n" );
63  }
64 
65  public function searchIndexUpdateCallback( $dbw, $row ) {
66  return $this->updateSearchIndexForPage( $dbw, $row->si_page );
67  }
68 
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' )";
75 
76  return $dbw->query( $sql, __METHOD__ );
77  }
78 }
79 
80 $maintClass = "UpdateDoubleWidthSearch";
81 require_once RUN_MAINTENANCE_IF_MAIN;
UpdateDoubleWidthSearch
Maintenance script to normalize double-byte latin UTF-8 characters.
Definition: updateDoubleWidthSearch.php:33
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$res
$res
Definition: database.txt:21
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$maintClass
$maintClass
Definition: updateDoubleWidthSearch.php:80
Maintenance\updateSearchIndex
updateSearchIndex( $maxLockTime, $callback, $dbw, $results)
Perform a search index update with locking.
Definition: Maintenance.php:1365
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
DB_MASTER
const DB_MASTER
Definition: defines.php:26
UpdateDoubleWidthSearch\execute
execute()
Do the actual work.
Definition: updateDoubleWidthSearch.php:51
Maintenance\DB_ADMIN
const DB_ADMIN
Definition: Maintenance.php:64
Maintenance\updateSearchIndexForPage
updateSearchIndexForPage( $dbw, $pageId)
Update the searchindex table for a given pageid.
Definition: Maintenance.php:1402
UpdateDoubleWidthSearch\findRows
findRows( $dbw)
Definition: updateDoubleWidthSearch.php:69
UpdateDoubleWidthSearch\__construct
__construct()
Default constructor.
Definition: updateDoubleWidthSearch.php:35
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
UpdateDoubleWidthSearch\searchIndexUpdateCallback
searchIndexUpdateCallback( $dbw, $row)
Definition: updateDoubleWidthSearch.php:65
UpdateDoubleWidthSearch\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: updateDoubleWidthSearch.php:47