MediaWiki  1.23.2
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->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs";
38  }
39 
40  protected function getUpdateKey() {
41  return 'fix protocol-relative URLs in externallinks';
42  }
43 
44  protected function updateSkippedMessage() {
45  return 'protocol-relative URLs in externallinks table already fixed.';
46  }
47 
48  protected function doDBUpdates() {
49  $db = wfGetDB( DB_MASTER );
50  if ( !$db->tableExists( 'externallinks' ) ) {
51  $this->error( "externallinks table does not exist" );
52  return false;
53  }
54  $this->output( "Fixing protocol-relative entries in the externallinks table...\n" );
55  $res = $db->select( 'externallinks', array( 'el_from', 'el_to', 'el_index' ),
56  array( 'el_index' . $db->buildLike( '//', $db->anyString() ) ),
57  __METHOD__
58  );
59  $count = 0;
60  foreach ( $res as $row ) {
61  $count++;
62  if ( $count % 100 == 0 ) {
63  $this->output( $count . "\n" );
65  }
66  $db->insert( 'externallinks',
67  array(
68  array(
69  'el_id' => $db->nextSequenceValue( 'externallinks_el_id_seq' ),
70  'el_from' => $row->el_from,
71  'el_to' => $row->el_to,
72  'el_index' => "http:{$row->el_index}",
73  ),
74  array(
75  'el_id' => $db->nextSequenceValue( 'externallinks_el_id_seq' ),
76  'el_from' => $row->el_from,
77  'el_to' => $row->el_to,
78  'el_index' => "https:{$row->el_index}",
79  )
80  ), __METHOD__, array( 'IGNORE' )
81  );
82  $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
83  }
84  $this->output( "Done, $count rows updated.\n" );
85  return true;
86  }
87 }
88 
89 $maintClass = "FixExtLinksProtocolRelative";
90 require_once RUN_MAINTENANCE_IF_MAIN;
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
FixExtLinksProtocolRelative\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: fixExtLinksProtocolRelative.php:40
FixExtLinksProtocolRelative
Maintenance script that fixes any entriy for protocol-relative URLs in the externallinks table.
Definition: fixExtLinksProtocolRelative.php:34
$maintClass
$maintClass
Definition: fixExtLinksProtocolRelative.php:89
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1209
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3795
FixExtLinksProtocolRelative\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: fixExtLinksProtocolRelative.php:48
FixExtLinksProtocolRelative\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: fixExtLinksProtocolRelative.php:44
$count
$count
Definition: UtfNormalTest2.php:96
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\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
$res
$res
Definition: database.txt:21