r103056 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103055‎ | r103056 | r103057 >
Date:22:40, 14 November 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1 (modified) (history)
  • /branches/wmf/1.18wmf1/includes (modified) (history)
  • /branches/wmf/1.18wmf1/includes/AutoLoader.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/GlobalFunctions.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/LinksUpdate.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/api (modified) (history)
  • /branches/wmf/1.18wmf1/includes/api/ApiQueryExternalLinks.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/installer/DatabaseUpdater.php (modified) (history)
  • /branches/wmf/1.18wmf1/maintenance/fixExtLinksProtocolRelative.php (added) (history)
  • /branches/wmf/1.18wmf1/tests/phpunit/includes/GlobalFunctions/GlobalTest.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/maintenance/fixExtLinksProtocolRelative.php
@@ -0,0 +1,81 @@
 2+<?php
 3+/**
 4+ * Fixes any entries for protocol-relative URLs in the externallinks table,
 5+ * replacing each protocol-relative entry with two entries, one for http
 6+ * and one for https.
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License along
 19+ * with this program; if not, write to the Free Software Foundation, Inc.,
 20+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 21+ * http://www.gnu.org/copyleft/gpl.html
 22+ *
 23+ * @ingroup Maintenance
 24+ */
 25+
 26+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 27+
 28+class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
 29+ public function __construct() {
 30+ parent::__construct();
 31+ $this->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs";
 32+ }
 33+
 34+ protected function getUpdateKey() {
 35+ return 'fix protocol-relative URLs in externallinks';
 36+ }
 37+
 38+ protected function updateSkippedMessage() {
 39+ return 'protocol-relative URLs in externallinks table already fixed.';
 40+ }
 41+
 42+ protected function doDBUpdates() {
 43+ $db = wfGetDB( DB_MASTER );
 44+ if ( !$db->tableExists( 'externallinks' ) ) {
 45+ $this->error( "externallinks table does not exist" );
 46+ return false;
 47+ }
 48+ $this->output( "Fixing protocol-relative entries in the externallinks table...\n" );
 49+ $res = $db->select( 'externallinks', array( 'el_from', 'el_to', 'el_index' ),
 50+ array( 'el_index' . $db->buildLike( '//', $db->anyString() ) ),
 51+ __METHOD__
 52+ );
 53+ $count = 0;
 54+ foreach ( $res as $row ) {
 55+ $count++;
 56+ if ( $count % 100 == 0 ) {
 57+ $this->output( $count );
 58+ wfWaitForSlaves();
 59+ }
 60+ $db->insert( 'externallinks',
 61+ array(
 62+ array(
 63+ 'el_from' => $row->el_from,
 64+ 'el_to' => $row->el_to,
 65+ 'el_index' => "http:{$row->el_index}",
 66+ ),
 67+ array(
 68+ 'el_from' => $row->el_from,
 69+ 'el_to' => $row->el_to,
 70+ 'el_index' => "https:{$row->el_index}",
 71+ )
 72+ ), __METHOD__, array( 'IGNORE' )
 73+ );
 74+ $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
 75+ }
 76+ $this->output( "Done, $count rows updated.\n" );
 77+ return true;
 78+ }
 79+}
 80+
 81+$maintClass = "FixExtLinksProtocolRelative";
 82+require_once( RUN_MAINTENANCE_IF_MAIN );
Property changes on: branches/wmf/1.18wmf1/maintenance/fixExtLinksProtocolRelative.php
___________________________________________________________________
Added: svn:eol-style
183 + native
Index: branches/wmf/1.18wmf1/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -831,42 +831,42 @@
832832 }
833833
834834 /**
835 - * @dataProvider provideMakeUrlIndex()
 835+ * @dataProvider provideMakeUrlIndexes()
836836 */
837 - function testMakeUrlIndex( $url, $expected ) {
838 - $index = wfMakeUrlIndex( $url );
839 - $this->assertEquals( $expected, $index, "wfMakeUrlIndex(\"$url\")" );
 837+ function testMakeUrlIndexes( $url, $expected ) {
 838+ $index = wfMakeUrlIndexes( $url );
 839+ $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
840840 }
841841
842 - function provideMakeUrlIndex() {
 842+ function provideMakeUrlIndexes() {
843843 return array(
844844 array(
845845 // just a regular :)
846846 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
847 - 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
 847+ array( 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
848848 ),
849849 array(
850850 // mailtos are handled special
851851 // is this really right though? that final . probably belongs earlier?
852852 'mailto:wiki@wikimedia.org',
853 - 'mailto:org.wikimedia@wiki.',
 853+ array( 'mailto:org.wikimedia@wiki.' )
854854 ),
855855
856856 // file URL cases per bug 28627...
857857 array(
858858 // three slashes: local filesystem path Unix-style
859859 'file:///whatever/you/like.txt',
860 - 'file://./whatever/you/like.txt'
 860+ array( 'file://./whatever/you/like.txt' )
861861 ),
862862 array(
863863 // three slashes: local filesystem path Windows-style
864864 'file:///c:/whatever/you/like.txt',
865 - 'file://./c:/whatever/you/like.txt'
 865+ array( 'file://./c:/whatever/you/like.txt' )
866866 ),
867867 array(
868868 // two slashes: UNC filesystem path Windows-style
869869 'file://intranet/whatever/you/like.txt',
870 - 'file://intranet./whatever/you/like.txt'
 870+ array( 'file://intranet./whatever/you/like.txt' )
871871 ),
872872 // Multiple-slash cases that can sorta work on Mozilla
873873 // if you hack it just right are kinda pathological,
@@ -875,6 +875,15 @@
876876 //
877877 // Those will survive the algorithm but with results that
878878 // are less consistent.
 879+
 880+ // protocol-relative URL cases per bug 29854...
 881+ array(
 882+ '//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
 883+ array(
 884+ 'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
 885+ 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
 886+ )
 887+ ),
879888 );
880889 }
881890
Index: branches/wmf/1.18wmf1/includes/GlobalFunctions.php
@@ -597,12 +597,12 @@
598598 }
599599
600600 /**
601 - * Make a URL index, appropriate for the el_index field of externallinks.
 601+ * Make URL indexes, appropriate for the el_index field of externallinks.
602602 *
603603 * @param $url String
604 - * @return String
 604+ * @return array
605605 */
606 -function wfMakeUrlIndex( $url ) {
 606+function wfMakeUrlIndexes( $url ) {
607607 $bits = wfParseUrl( $url );
608608
609609 // Reverse the labels in the hostname, convert to lower case
@@ -642,7 +642,12 @@
643643 if ( isset( $bits['fragment'] ) ) {
644644 $index .= '#' . $bits['fragment'];
645645 }
646 - return $index;
 646+
 647+ if ( $prot == '' ) {
 648+ return array( "http:$index", "https:$index" );
 649+ } else {
 650+ return array( $index );
 651+ }
647652 }
648653
649654 /**
Property changes on: branches/wmf/1.18wmf1/includes/GlobalFunctions.php
___________________________________________________________________
Modified: svn:mergeinfo
650655 Merged /trunk/phase3/includes/GlobalFunctions.php:r102951,102954
Index: branches/wmf/1.18wmf1/includes/installer/DatabaseUpdater.php
@@ -40,7 +40,8 @@
4141 protected $shared = false;
4242
4343 protected $postDatabaseUpdateMaintenance = array(
44 - 'DeleteDefaultMessages'
 44+ 'DeleteDefaultMessages',
 45+ 'FixExtLinksProtocolRelative',
4546 );
4647
4748 /**
Index: branches/wmf/1.18wmf1/includes/LinksUpdate.php
@@ -438,11 +438,13 @@
439439 $arr = array();
440440 $diffs = array_diff_key( $this->mExternals, $existing );
441441 foreach( $diffs as $url => $dummy ) {
442 - $arr[] = array(
443 - 'el_from' => $this->mId,
444 - 'el_to' => $url,
445 - 'el_index' => wfMakeUrlIndex( $url ),
446 - );
 442+ foreach( wfMakeUrlIndexes( $url ) as $index ) {
 443+ $arr[] = array(
 444+ 'el_from' => $this->mId,
 445+ 'el_to' => $url,
 446+ 'el_index' => $index,
 447+ );
 448+ }
447449 }
448450 return $arr;
449451 }
Index: branches/wmf/1.18wmf1/includes/api/ApiQueryExternalLinks.php
@@ -69,6 +69,11 @@
7070 $this->addOption( 'ORDER BY', 'el_from' );
7171 }
7272
 73+ // If we're querying all protocols, use DISTINCT to avoid repeating protocol-relative links twice
 74+ if ( $protocol === null ) {
 75+ $this->addOption( 'DISTINCT' );
 76+ }
 77+
7378 $this->addOption( 'LIMIT', $params['limit'] + 1 );
7479 $offset = isset( $params['offset'] ) ? $params['offset'] : 0;
7580 if ( $offset ) {
Property changes on: branches/wmf/1.18wmf1/includes/api
___________________________________________________________________
Modified: svn:mergeinfo
7681 Merged /trunk/phase3/includes/api:r102951,102954
Index: branches/wmf/1.18wmf1/includes/AutoLoader.php
@@ -827,6 +827,7 @@
828828 'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php',
829829 'FakeMaintenance' => 'maintenance/Maintenance.php',
830830 'Maintenance' => 'maintenance/Maintenance.php',
 831+ 'FixExtLinksProtocolRelative' => 'maintenance/fixExtLinksProtocolRelative.php',
831832 'PopulateCategory' => 'maintenance/populateCategory.php',
832833 'PopulateLogSearch' => 'maintenance/populateLogSearch.php',
833834 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php',
Property changes on: branches/wmf/1.18wmf1/includes/AutoLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
834835 Merged /trunk/phase3/includes/AutoLoader.php:r102951,102954
Property changes on: branches/wmf/1.18wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
835836 Merged /trunk/phase3/includes:r102951,102954
Property changes on: branches/wmf/1.18wmf1
___________________________________________________________________
Modified: svn:mergeinfo
836837 Merged /trunk/phase3:r102951,102954

Follow-up revisions

RevisionCommit summaryAuthorDate
r104716Merge r103033 from REL1_18 to fix fatal on fixExtLinksProtocolRelative from r...reedy18:56, 30 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102951(bug 29854) Store protocol-relative links twice in the externallinks table, o...catrope09:13, 14 November 2011
r102954Fix for r102949: don't delete too muchcatrope09:16, 14 November 2011

Comments

#Comment by Krinkle (talk | contribs)   18:22, 30 November 2011
Fatal error: Class 'LoggedUpdateMaintenance' not found in /srv/org/wikimedia/prototype/wikis/rc/maintenance/fixExtLinksProtocolRelative.php on line 27

LoggedUpdateMaintenance does not exist in 1.18wmf1 Maintenance.php

Status & tagging log