MediaWiki  1.30.0
fixExtLinksProtocolRelative.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/Maintenance.php';
27 
35  public function __construct() {
36  parent::__construct();
37  $this->addDescription(
38  'Fixes any entries in the externallinks table containing protocol-relative URLs' );
39  }
40 
41  protected function getUpdateKey() {
42  return 'fix protocol-relative URLs in externallinks';
43  }
44 
45  protected function updateSkippedMessage() {
46  return 'protocol-relative URLs in externallinks table already fixed.';
47  }
48 
49  protected function doDBUpdates() {
50  $db = $this->getDB( DB_MASTER );
51  if ( !$db->tableExists( 'externallinks' ) ) {
52  $this->error( "externallinks table does not exist" );
53 
54  return false;
55  }
56  $this->output( "Fixing protocol-relative entries in the externallinks table...\n" );
57  $res = $db->select( 'externallinks', [ 'el_from', 'el_to', 'el_index' ],
58  [ 'el_index' . $db->buildLike( '//', $db->anyString() ) ],
59  __METHOD__
60  );
61  $count = 0;
62  foreach ( $res as $row ) {
63  $count++;
64  if ( $count % 100 == 0 ) {
65  $this->output( $count . "\n" );
67  }
68  $db->insert( 'externallinks',
69  [
70  [
71  'el_from' => $row->el_from,
72  'el_to' => $row->el_to,
73  'el_index' => "http:{$row->el_index}",
74  ],
75  [
76  'el_from' => $row->el_from,
77  'el_to' => $row->el_to,
78  'el_index' => "https:{$row->el_index}",
79  ]
80  ], __METHOD__, [ 'IGNORE' ]
81  );
82  $db->delete(
83  'externallinks',
84  [
85  'el_index' => $row->el_index,
86  'el_from' => $row->el_from,
87  'el_to' => $row->el_to
88  ],
89  __METHOD__
90  );
91  }
92  $this->output( "Done, $count rows updated.\n" );
93 
94  return true;
95  }
96 }
97 
98 $maintClass = "FixExtLinksProtocolRelative";
99 require_once RUN_MAINTENANCE_IF_MAIN;
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
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:3010
FixExtLinksProtocolRelative\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: fixExtLinksProtocolRelative.php:41
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
FixExtLinksProtocolRelative
Maintenance script that fixes any entriy for protocol-relative URLs in the externallinks table.
Definition: fixExtLinksProtocolRelative.php:34
$maintClass
$maintClass
Definition: fixExtLinksProtocolRelative.php:98
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1562
DB_MASTER
const DB_MASTER
Definition: defines.php:26
FixExtLinksProtocolRelative\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: fixExtLinksProtocolRelative.php:49
FixExtLinksProtocolRelative\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: fixExtLinksProtocolRelative.php:45
as
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
Definition: distributors.txt:9
FixExtLinksProtocolRelative\__construct
__construct()
Default constructor.
Definition: fixExtLinksProtocolRelative.php:35
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