MediaWiki REL1_34
fixExtLinksProtocolRelative.php
Go to the documentation of this file.
1<?php
26require_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 'el_index_60' => substr( "http:{$row->el_index}", 0, 60 ),
75 ],
76 [
77 'el_from' => $row->el_from,
78 'el_to' => $row->el_to,
79 'el_index' => "https:{$row->el_index}",
80 'el_index_60' => substr( "https:{$row->el_index}", 0, 60 ),
81 ]
82 ], __METHOD__, [ 'IGNORE' ]
83 );
84 $db->delete(
85 'externallinks',
86 [
87 'el_index' => $row->el_index,
88 'el_from' => $row->el_from,
89 'el_to' => $row->el_to
90 ],
91 __METHOD__
92 );
93 }
94 $this->output( "Done, $count rows updated.\n" );
95
96 return true;
97 }
98}
99
100$maintClass = FixExtLinksProtocolRelative::class;
101require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that fixes any entriy for protocol-relative URLs in the externallinks table.
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.
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.
addDescription( $text)
Set the description text.
const DB_MASTER
Definition defines.php:26