MediaWiki REL1_33
refreshExternallinksIndex.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription(
37 'Refresh the externallinks table el_index and el_index_60 from el_to' );
38 $this->setBatchSize( 10000 );
39 }
40
41 protected function getUpdateKey() {
42 return static::class
43 . ' v' . LinkFilter::VERSION
44 . ( LinkFilter::supportsIDN() ? '+' : '-' ) . 'IDN';
45 }
46
47 protected function updateSkippedMessage() {
48 return 'externallinks table indexes up to date';
49 }
50
51 protected function doDBUpdates() {
52 $dbw = $this->getDB( DB_MASTER );
53 if ( !$dbw->tableExists( 'externallinks' ) ) {
54 $this->error( "externallinks table does not exist" );
55 return false;
56 }
57 $this->output( "Updating externallinks table index fields\n" );
58
59 $minmax = $dbw->selectRow(
60 'externallinks',
61 [ 'min' => 'MIN(el_id)', 'max' => 'MAX(el_id)' ],
62 '',
63 __METHOD__
64 );
65
66 $updated = 0;
67 $deleted = 0;
68 $start = $minmax->min - 1;
69 $last = $minmax->max;
70 while ( $start < $last ) {
71 $end = min( $start + $this->mBatchSize, $last );
72 $this->output( "el_id $start - $end of $last\n" );
73 $res = $dbw->select( 'externallinks', [ 'el_id', 'el_to', 'el_index' ],
74 [
75 "el_id > $start",
76 "el_id <= $end",
77 ],
78 __METHOD__,
79 [ 'ORDER BY' => 'el_id' ]
80 );
81 foreach ( $res as $row ) {
82 $newIndexes = LinkFilter::makeIndexes( $row->el_to );
83 if ( !$newIndexes ) {
84 $dbw->delete( 'externallinks', [ 'el_id' => $row->el_id ], __METHOD__ );
85 $deleted++;
86 continue;
87 }
88 if ( in_array( $row->el_index, $newIndexes, true ) ) {
89 continue;
90 }
91
92 if ( count( $newIndexes ) === 1 ) {
93 $newIndex = $newIndexes[0];
94 } else {
95 // Assume the scheme is the only difference between the different $newIndexes.
96 // Keep this row's scheme, assuming there's another row with the other scheme.
97 $newIndex = substr( $row->el_index, 0, strpos( $row->el_index, ':' ) ) .
98 substr( $newIndexes[0], strpos( $newIndexes[0], ':' ) );
99 }
100 $dbw->update( 'externallinks',
101 [
102 'el_index' => $newIndex,
103 'el_index_60' => substr( $newIndex, 0, 60 ),
104 ],
105 [ 'el_id' => $row->el_id ],
106 __METHOD__
107 );
108 $updated++;
109 }
111 $start = $end;
112 }
113 $this->output( "Done, $updated rows updated, $deleted deleted.\n" );
114
115 return true;
116 }
117}
118
119$maintClass = "RefreshExternallinksIndex";
120require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
static makeIndexes( $url)
Converts a URL into a format for el_index.
static supportsIDN()
Indicate whether LinkFilter IDN support is available.
const VERSION
Increment this when makeIndexes output changes.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
Maintenance script that refreshes the externallinks table el_index and el_index_60 from el_to.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
getUpdateKey()
Get the update key name to go in the update log table.
$res
Definition database.txt:21
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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:37
require_once RUN_MAINTENANCE_IF_MAIN
$last
const DB_MASTER
Definition defines.php:26