ExternalLinks: Drop migration code
Anything that writes or reads from now-dropped columns Bug: T312666 Change-Id: Ic1c69de717bfa03bba94e97dabad9e717ba13fd6
This commit is contained in:
parent
9f3c7996ee
commit
06fa7a9107
14 changed files with 43 additions and 378 deletions
|
|
@ -44,6 +44,8 @@ For notes on 1.40.x and older releases, see HISTORY.
|
|||
* $wgCommentTempTableSchemaMigrationStage – This temporary flag did let you
|
||||
control the migration stage for the temporary comment database table, from
|
||||
revision.
|
||||
* $wgExternalLinksSchemaMigrationStage – This temporary flag did let you
|
||||
control the migration stage for the externallinks database table.
|
||||
* …
|
||||
|
||||
=== New user-facing features in 1.41 ===
|
||||
|
|
|
|||
|
|
@ -1984,16 +1984,6 @@ config-schema:
|
|||
- 1.38: Added
|
||||
- 1.39: Default has changed to SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
|
||||
and support for SCHEMA_COMPAT_OLD is dropped.
|
||||
ExternalLinksSchemaMigrationStage:
|
||||
default: 768
|
||||
type: integer
|
||||
description: |-
|
||||
Externallinks table schema migration stage.
|
||||
Use the SCHEMA_COMPAT_XXX flags. Supported values:
|
||||
- SCHEMA_COMPAT_OLD
|
||||
- SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
|
||||
History:
|
||||
- 1.40: Added
|
||||
ContentHandlers:
|
||||
default:
|
||||
wikitext: { class: WikitextContentHandler, services: [TitleFactory, ParserFactory, GlobalIdGenerator, LanguageNameUtils, MagicWordFactory, ParsoidParserFactory] }
|
||||
|
|
|
|||
|
|
@ -1229,12 +1229,6 @@ $wgMaxExecutionTimeForExpensiveQueries = null;
|
|||
*/
|
||||
$wgTemplateLinksSchemaMigrationStage = null;
|
||||
|
||||
/**
|
||||
* Config variable stub for the ExternalLinksSchemaMigrationStage setting, for use by phpdoc and IDEs.
|
||||
* @see MediaWiki\MainConfigSchema::ExternalLinksSchemaMigrationStage
|
||||
*/
|
||||
$wgExternalLinksSchemaMigrationStage = null;
|
||||
|
||||
/**
|
||||
* Config variable stub for the ContentHandlers setting, for use by phpdoc and IDEs.
|
||||
* @see MediaWiki\MainConfigSchema::ContentHandlers
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
namespace MediaWiki\ExternalLinks;
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\IReadableDatabase;
|
||||
|
||||
/**
|
||||
|
|
@ -39,27 +37,15 @@ class ExternalLinksLookup {
|
|||
* @return string[] array of external links
|
||||
*/
|
||||
public static function getExternalLinksForPage( int $pagId, IReadableDatabase $dbr, $fname ) {
|
||||
$extlinkStage = MediaWikiServices::getInstance()->getMainConfig()->get(
|
||||
MainConfigNames::ExternalLinksSchemaMigrationStage
|
||||
);
|
||||
if ( $extlinkStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
return $dbr->newSelectQueryBuilder()
|
||||
->select( 'el_to' )
|
||||
->distinct()
|
||||
->from( 'externallinks' )
|
||||
->where( [ 'el_from' => $pagId ] )
|
||||
->caller( $fname )->fetchFieldValues();
|
||||
} else {
|
||||
$links = [];
|
||||
$res = $dbr->newSelectQueryBuilder()
|
||||
->select( [ 'el_to_domain_index', 'el_to_path' ] )
|
||||
->from( 'externallinks' )
|
||||
->where( [ 'el_from' => $pagId ] )
|
||||
->caller( $fname )->fetchResultSet();
|
||||
foreach ( $res as $row ) {
|
||||
$links[] = LinkFilter::reverseIndexe( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
}
|
||||
return $links;
|
||||
$links = [];
|
||||
$res = $dbr->newSelectQueryBuilder()
|
||||
->select( [ 'el_to_domain_index', 'el_to_path' ] )
|
||||
->from( 'externallinks' )
|
||||
->where( [ 'el_from' => $pagId ] )
|
||||
->caller( $fname )->fetchResultSet();
|
||||
foreach ( $res as $row ) {
|
||||
$links[] = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,12 +236,6 @@ class LinkFilter {
|
|||
* @return string[]
|
||||
*/
|
||||
public static function getIndexedUrlsNonReversed( $urls ) {
|
||||
$migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
|
||||
MainConfigNames::ExternalLinksSchemaMigrationStage
|
||||
);
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
return $urls;
|
||||
}
|
||||
$newLinks = [];
|
||||
foreach ( $urls as $url ) {
|
||||
$indexes = self::makeIndexes( $url, false );
|
||||
|
|
@ -255,7 +249,7 @@ class LinkFilter {
|
|||
return $newLinks;
|
||||
}
|
||||
|
||||
public static function reverseIndexe( $domainIndex ) {
|
||||
public static function reverseIndexes( $domainIndex ) {
|
||||
$bits = wfParseUrl( $domainIndex );
|
||||
if ( !$bits ) {
|
||||
return '';
|
||||
|
|
@ -326,12 +320,6 @@ class LinkFilter {
|
|||
* @return array|false Query conditions (to be ANDed) or false on error.
|
||||
*/
|
||||
public static function getQueryConditions( $filterEntry, array $options = [] ) {
|
||||
$migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
|
||||
MainConfigNames::ExternalLinksSchemaMigrationStage
|
||||
);
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
return self::getQueryConditionsOld( $filterEntry, $options );
|
||||
}
|
||||
$options += [
|
||||
'protocol' => [ 'http://', 'https://' ],
|
||||
'oneWildcard' => false,
|
||||
|
|
@ -380,65 +368,6 @@ class LinkFilter {
|
|||
];
|
||||
}
|
||||
|
||||
private static function getQueryConditionsOld( $filterEntry, array $options = [] ) {
|
||||
$options += [
|
||||
'protocol' => null,
|
||||
'oneWildcard' => false,
|
||||
'db' => null,
|
||||
];
|
||||
if ( $options['protocol'] === null ) {
|
||||
$options['protocol'] = 'http://';
|
||||
}
|
||||
|
||||
// First, get the like array
|
||||
$like = self::makeLikeArray( $filterEntry, $options['protocol'] );
|
||||
if ( $like === false ) {
|
||||
return $like;
|
||||
}
|
||||
|
||||
$like = array_merge( $like[0], $like[1] );
|
||||
// Fix very specific case of domain having a wild card and path being empty
|
||||
// leading to LIKE com.example.%/%
|
||||
if (
|
||||
$like[count( $like ) - 1] instanceof LikeMatch &&
|
||||
$like[count( $like ) - 3] instanceof LikeMatch &&
|
||||
$like[count( $like ) - 2] == '/'
|
||||
) {
|
||||
array_pop( $like );
|
||||
// @phan-suppress-next-line PhanPluginDuplicateAdjacentStatement This will be removed soon
|
||||
array_pop( $like );
|
||||
}
|
||||
|
||||
// Get the constant prefix (i.e. everything up to the first wildcard)
|
||||
$trimmedLike = self::keepOneWildcard( $like );
|
||||
if ( $options['oneWildcard'] ) {
|
||||
$like = $trimmedLike;
|
||||
}
|
||||
if ( $trimmedLike[count( $trimmedLike ) - 1] instanceof LikeMatch ) {
|
||||
array_pop( $trimmedLike );
|
||||
}
|
||||
$index = implode( '', $trimmedLike );
|
||||
$db = $options['db'] ?: MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase();
|
||||
|
||||
// Build the query
|
||||
$l = strlen( $index );
|
||||
if ( $l >= 60 ) {
|
||||
// The constant prefix is larger than el_index_60, so we can use a
|
||||
// constant comparison.
|
||||
return [
|
||||
"el_index_60" => substr( $index, 0, 60 ),
|
||||
"el_index" . $db->buildLike( $like ),
|
||||
];
|
||||
}
|
||||
|
||||
// The constant prefix is smaller than el_index_60, so we use a LIKE
|
||||
// for a prefix search.
|
||||
return [
|
||||
"el_index_60" . $db->buildLike( $index, $db->anyString() ),
|
||||
"el_index" . $db->buildLike( $like ),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getProtocolPrefix( $protocol ) {
|
||||
// Find the right prefix
|
||||
$urlProtocols = MediaWikiServices::getInstance()->getMainConfig()
|
||||
|
|
|
|||
|
|
@ -1244,12 +1244,6 @@ class MainConfigNames {
|
|||
*/
|
||||
public const TemplateLinksSchemaMigrationStage = 'TemplateLinksSchemaMigrationStage';
|
||||
|
||||
/**
|
||||
* Name constant for the ExternalLinksSchemaMigrationStage setting, for use with Config::get()
|
||||
* @see MainConfigSchema::ExternalLinksSchemaMigrationStage
|
||||
*/
|
||||
public const ExternalLinksSchemaMigrationStage = 'ExternalLinksSchemaMigrationStage';
|
||||
|
||||
/**
|
||||
* Name constant for the ContentHandlers setting, for use with Config::get()
|
||||
* @see MainConfigSchema::ContentHandlers
|
||||
|
|
|
|||
|
|
@ -3243,22 +3243,6 @@ class MainConfigSchema {
|
|||
'type' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Externallinks table schema migration stage.
|
||||
*
|
||||
* Use the SCHEMA_COMPAT_XXX flags. Supported values:
|
||||
*
|
||||
* - SCHEMA_COMPAT_OLD
|
||||
* - SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
|
||||
*
|
||||
* History:
|
||||
* - 1.40: Added
|
||||
*/
|
||||
public const ExternalLinksSchemaMigrationStage = [
|
||||
'default' => SCHEMA_COMPAT_READ_NEW | SCHEMA_COMPAT_WRITE_NEW,
|
||||
'type' => 'integer',
|
||||
];
|
||||
|
||||
// endregion -- End of DB settings
|
||||
|
||||
/***************************************************************************/
|
||||
|
|
|
|||
|
|
@ -71,14 +71,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
|
|||
|
||||
$this->addTables( [ 'externallinks', 'page' ] );
|
||||
$this->addJoinConds( [ 'page' => [ 'JOIN', 'page_id=el_from' ] ] );
|
||||
$migrationStage = $this->getConfig()->get( MainConfigNames::ExternalLinksSchemaMigrationStage );
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$fields = [ 'el_to' ];
|
||||
$continueField = 'el_index_60';
|
||||
} else {
|
||||
$continueField = 'el_to_domain_index';
|
||||
$fields = [ 'el_to_domain_index', 'el_to_path' ];
|
||||
}
|
||||
$continueField = 'el_to_domain_index';
|
||||
$fields = [ 'el_to_domain_index', 'el_to_path' ];
|
||||
|
||||
$miser_ns = [];
|
||||
if ( $this->getConfig()->get( MainConfigNames::MiserMode ) ) {
|
||||
|
|
@ -86,9 +80,6 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
|
|||
} else {
|
||||
$this->addWhereFld( 'page_namespace', $params['namespace'] );
|
||||
}
|
||||
|
||||
$orderBy = [];
|
||||
|
||||
if ( $query !== null && $query !== '' ) {
|
||||
// Normalize query to match the normalization applied for the externallinks table
|
||||
$query = Parser::normalizeLinkUrl( $query );
|
||||
|
|
@ -101,33 +92,12 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
|
|||
$this->dieWithError( 'apierror-badquery' );
|
||||
}
|
||||
$this->addWhere( $conds );
|
||||
if ( !isset( $conds[$continueField] ) ) {
|
||||
$orderBy[] = $continueField;
|
||||
}
|
||||
} else {
|
||||
$orderBy[] = $continueField;
|
||||
if ( $protocol !== null ) {
|
||||
$this->addWhere( $continueField . $db->buildLike( "$protocol", $db->anyString() ) );
|
||||
} else {
|
||||
// It is not possible to do so in the new schema
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
// We're querying all protocols, filter out duplicate protocol-relative links
|
||||
$this->addWhere(
|
||||
$db->makeList( [
|
||||
'el_to NOT' . $db->buildLike( '//', $db->anyString() ),
|
||||
'el_index_60 ' . $db->buildLike( 'http://', $db->anyString() ),
|
||||
], LIST_OR )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$orderBy[] = 'el_id';
|
||||
} else {
|
||||
// READ NEW doesn't need this complex continuation
|
||||
$orderBy = [ 'el_id' ];
|
||||
}
|
||||
$orderBy = [ 'el_id' ];
|
||||
|
||||
$this->addOption( 'ORDER BY', $orderBy );
|
||||
$this->addFields( $orderBy ); // Make sure
|
||||
|
|
@ -196,11 +166,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
|
|||
ApiQueryBase::addTitleInfo( $vals, $title );
|
||||
}
|
||||
if ( $fld_url ) {
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$to = $row->el_to;
|
||||
} else {
|
||||
$to = LinkFilter::reverseIndexe( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
}
|
||||
$to = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
// expand protocol-relative urls
|
||||
if ( $params['expandurl'] ) {
|
||||
$to = (string)$this->urlUtils->expand( $to, PROTO_CANONICAL );
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\ExternalLinks\LinkFilter;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\Utils\UrlUtils;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
|
||||
|
|
@ -57,29 +56,16 @@ class ApiQueryExternalLinks extends ApiQueryBase {
|
|||
|
||||
$query = $params['query'];
|
||||
$protocol = LinkFilter::getProtocolPrefix( $params['protocol'] );
|
||||
$migrationStage = $this->getConfig()->get( MainConfigNames::ExternalLinksSchemaMigrationStage );
|
||||
|
||||
$fields = [ 'el_from' ];
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$fields[] = 'el_to';
|
||||
$continueField = 'el_index_60';
|
||||
} else {
|
||||
$fields[] = 'el_to_domain_index';
|
||||
$fields[] = 'el_to_path';
|
||||
$continueField = 'el_to_domain_index';
|
||||
}
|
||||
$fields[] = 'el_to_domain_index';
|
||||
$fields[] = 'el_to_path';
|
||||
$continueField = 'el_to_domain_index';
|
||||
$this->addFields( $fields );
|
||||
|
||||
$this->addTables( 'externallinks' );
|
||||
$this->addWhereFld( 'el_from', array_keys( $pages ) );
|
||||
|
||||
$orderBy = [];
|
||||
|
||||
// Don't order by el_from if it's constant in the WHERE clause
|
||||
if ( count( $pages ) !== 1 ) {
|
||||
$orderBy[] = 'el_from';
|
||||
}
|
||||
|
||||
if ( $query !== null && $query !== '' ) {
|
||||
// Normalize query to match the normalization applied for the externallinks table
|
||||
$query = Parser::normalizeLinkUrl( $query );
|
||||
|
|
@ -93,32 +79,13 @@ class ApiQueryExternalLinks extends ApiQueryBase {
|
|||
$this->dieWithError( 'apierror-badquery' );
|
||||
}
|
||||
$this->addWhere( $conds );
|
||||
if ( !isset( $conds[$continueField] ) ) {
|
||||
$orderBy[] = $continueField;
|
||||
}
|
||||
} else {
|
||||
$orderBy[] = $continueField;
|
||||
|
||||
if ( $protocol !== null ) {
|
||||
$this->addWhere( $continueField . $db->buildLike( "$protocol", $db->anyString() ) );
|
||||
} else {
|
||||
// It is not possible to do so in the new schema
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
// We're querying all protocols, filter out duplicate protocol-relative links
|
||||
$this->addWhere( $db->makeList( [
|
||||
'el_to NOT' . $db->buildLike( '//', $db->anyString() ),
|
||||
'el_index_60 ' . $db->buildLike( 'http://', $db->anyString() ),
|
||||
], LIST_OR ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$orderBy[] = 'el_id';
|
||||
} else {
|
||||
// READ NEW doesn't need this complex continuation
|
||||
$orderBy = [ 'el_id' ];
|
||||
}
|
||||
$orderBy = [ 'el_id' ];
|
||||
|
||||
$this->addOption( 'ORDER BY', $orderBy );
|
||||
$this->addFields( $orderBy ); // Make sure
|
||||
|
|
@ -143,11 +110,7 @@ class ApiQueryExternalLinks extends ApiQueryBase {
|
|||
break;
|
||||
}
|
||||
$entry = [];
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$to = $row->el_to;
|
||||
} else {
|
||||
$to = LinkFilter::reverseIndexe( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
}
|
||||
$to = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
// expand protocol-relative urls
|
||||
if ( $params['expandurl'] ) {
|
||||
$to = (string)$this->urlUtils->expand( $to, PROTO_CANONICAL );
|
||||
|
|
|
|||
|
|
@ -385,7 +385,6 @@ return [
|
|||
'DatabaseReplicaLagCritical' => 30,
|
||||
'MaxExecutionTimeForExpensiveQueries' => 0,
|
||||
'TemplateLinksSchemaMigrationStage' => 768,
|
||||
'ExternalLinksSchemaMigrationStage' => 768,
|
||||
'ContentHandlers' => [
|
||||
'wikitext' => [
|
||||
'class' => 'WikitextContentHandler',
|
||||
|
|
@ -2609,7 +2608,6 @@ return [
|
|||
'LBFactoryConf' => 'object',
|
||||
'LocalDatabases' => 'array',
|
||||
'TemplateLinksSchemaMigrationStage' => 'integer',
|
||||
'ExternalLinksSchemaMigrationStage' => 'integer',
|
||||
'ContentHandlers' => 'object',
|
||||
'NamespaceContentModels' => 'object',
|
||||
'TextModelsToParse' => 'array',
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Deferred\LinksUpdate;
|
||||
|
||||
use Config;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\ExternalLinks\LinkFilter;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use ParserOutput;
|
||||
|
||||
/**
|
||||
|
|
@ -16,31 +13,14 @@ use ParserOutput;
|
|||
* @since 1.38
|
||||
*/
|
||||
class ExternalLinksTable extends LinksTable {
|
||||
private const CONSTRUCTOR_OPTIONS = [
|
||||
MainConfigNames::ExternalLinksSchemaMigrationStage,
|
||||
];
|
||||
|
||||
private $newLinks = [];
|
||||
private $existingLinks;
|
||||
/** @var int */
|
||||
private $migrationStage;
|
||||
|
||||
public function __construct( Config $config ) {
|
||||
$options = new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $config );
|
||||
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
||||
|
||||
$this->migrationStage = $options->get( MainConfigNames::ExternalLinksSchemaMigrationStage );
|
||||
}
|
||||
|
||||
public function setParserOutput( ParserOutput $parserOutput ) {
|
||||
if ( !( $this->migrationStage & SCHEMA_COMPAT_WRITE_OLD ) ) {
|
||||
$links = LinkFilter::getIndexedUrlsNonReversed( array_keys( $parserOutput->getExternalLinks() ) );
|
||||
foreach ( $links as $link ) {
|
||||
$this->newLinks[$link] = true;
|
||||
}
|
||||
return;
|
||||
$links = LinkFilter::getIndexedUrlsNonReversed( array_keys( $parserOutput->getExternalLinks() ) );
|
||||
foreach ( $links as $link ) {
|
||||
$this->newLinks[$link] = true;
|
||||
}
|
||||
$this->newLinks = $parserOutput->getExternalLinks();
|
||||
}
|
||||
|
||||
protected function getTableName() {
|
||||
|
|
@ -52,10 +32,7 @@ class ExternalLinksTable extends LinksTable {
|
|||
}
|
||||
|
||||
protected function getExistingFields() {
|
||||
if ( !( $this->migrationStage & SCHEMA_COMPAT_WRITE_OLD ) ) {
|
||||
return [ 'el_to_domain_index', 'el_to_path' ];
|
||||
}
|
||||
return [ 'el_to' ];
|
||||
return [ 'el_to_domain_index', 'el_to_path' ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,11 +45,7 @@ class ExternalLinksTable extends LinksTable {
|
|||
if ( $this->existingLinks === null ) {
|
||||
$this->existingLinks = [];
|
||||
foreach ( $this->fetchExistingRows() as $row ) {
|
||||
if ( !( $this->migrationStage & SCHEMA_COMPAT_WRITE_OLD ) ) {
|
||||
$link = LinkFilter::reverseIndexe( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
} else {
|
||||
$link = $row->el_to;
|
||||
}
|
||||
$link = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path;
|
||||
$this->existingLinks[$link] = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -101,30 +74,20 @@ class ExternalLinksTable extends LinksTable {
|
|||
|
||||
protected function insertLink( $linkId ) {
|
||||
foreach ( LinkFilter::makeIndexes( $linkId ) as $index ) {
|
||||
$params = [];
|
||||
if ( $this->migrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
|
||||
$params['el_to'] = $linkId;
|
||||
$params['el_index'] = implode( '', $index );
|
||||
$params['el_index_60'] = substr( implode( '', $index ), 0, 60 );
|
||||
}
|
||||
if ( $this->migrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
|
||||
$params['el_to_domain_index'] = substr( $index[0], 0, 255 );
|
||||
$params['el_to_path'] = $index[1];
|
||||
}
|
||||
$params = [
|
||||
'el_to_domain_index' => substr( $index[0], 0, 255 ),
|
||||
'el_to_path' => $index[1],
|
||||
];
|
||||
$this->insertRow( $params );
|
||||
}
|
||||
}
|
||||
|
||||
protected function deleteLink( $linkId ) {
|
||||
if ( !( $this->migrationStage & SCHEMA_COMPAT_WRITE_OLD ) ) {
|
||||
foreach ( LinkFilter::makeIndexes( $linkId ) as $index ) {
|
||||
$this->deleteRow( [
|
||||
'el_to_domain_index' => substr( $index[0], 0, 255 ),
|
||||
'el_to_path' => $index[1]
|
||||
] );
|
||||
}
|
||||
} else {
|
||||
$this->deleteRow( [ 'el_to' => $linkId ] );
|
||||
foreach ( LinkFilter::makeIndexes( $linkId ) as $index ) {
|
||||
$this->deleteRow( [
|
||||
'el_to_domain_index' => substr( $index[0], 0, 255 ),
|
||||
'el_to_path' => $index[1]
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,6 @@ class LinksTableGroup {
|
|||
],
|
||||
'externallinks' => [
|
||||
'class' => ExternalLinksTable::class,
|
||||
'services' => [
|
||||
'MainConfig'
|
||||
],
|
||||
],
|
||||
'imagelinks' => [
|
||||
'class' => ImageLinksTable::class
|
||||
|
|
|
|||
|
|
@ -183,22 +183,12 @@ class SpecialLinkSearch extends QueryPage {
|
|||
|
||||
public function getQueryInfo() {
|
||||
$dbr = $this->getDatabaseProvider()->getReplicaDatabase();
|
||||
$migrationStage = $this->getConfig()->get( MainConfigNames::ExternalLinksSchemaMigrationStage );
|
||||
|
||||
$orderBy = [];
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$field = 'el_index_60';
|
||||
$extraFields = [
|
||||
'value' => 'el_index',
|
||||
'url' => 'el_to'
|
||||
];
|
||||
} else {
|
||||
$field = 'el_to_domain_index';
|
||||
$extraFields = [
|
||||
'urldomain' => 'el_to_domain_index',
|
||||
'urlpath' => 'el_to_path'
|
||||
];
|
||||
}
|
||||
$field = 'el_to_domain_index';
|
||||
$extraFields = [
|
||||
'urldomain' => 'el_to_domain_index',
|
||||
'urlpath' => 'el_to_path'
|
||||
];
|
||||
if ( $this->mQuery === '*' && $this->mProt !== '' ) {
|
||||
$this->mungedQuery = [
|
||||
$field . $dbr->buildLike( $this->mProt, $dbr->anyString() ),
|
||||
|
|
@ -213,15 +203,8 @@ class SpecialLinkSearch extends QueryPage {
|
|||
// Invalid query; return no results
|
||||
return [ 'tables' => 'page', 'fields' => 'page_id', 'conds' => '0=1' ];
|
||||
}
|
||||
$orderBy[] = $field;
|
||||
}
|
||||
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$orderBy[] = 'el_id';
|
||||
} else {
|
||||
// READ NEW doesn't need this complex continuation
|
||||
$orderBy = [ 'el_id' ];
|
||||
}
|
||||
$orderBy = [ 'el_id' ];
|
||||
|
||||
$retval = [
|
||||
'tables' => [ 'page', 'externallinks' ],
|
||||
|
|
@ -263,12 +246,7 @@ class SpecialLinkSearch extends QueryPage {
|
|||
public function formatResult( $skin, $result ) {
|
||||
$title = new TitleValue( (int)$result->namespace, $result->title );
|
||||
$pageLink = $this->getLinkRenderer()->makeLink( $title );
|
||||
$migrationStage = $this->getConfig()->get( MainConfigNames::ExternalLinksSchemaMigrationStage );
|
||||
if ( $migrationStage & SCHEMA_COMPAT_READ_OLD ) {
|
||||
$url = $result->url;
|
||||
} else {
|
||||
$url = LinkFilter::reverseIndexe( $result->urldomain ) . $result->urlpath;
|
||||
}
|
||||
$url = LinkFilter::reverseIndexes( $result->urldomain ) . $result->urlpath;
|
||||
|
||||
$urlLink = Linker::makeExternalLink( $url, $url );
|
||||
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ class LinkFilterTest extends MediaWikiLangTestCase {
|
|||
'file://', # Non-default
|
||||
] );
|
||||
|
||||
$index = LinkFilter::reverseIndexe( $url );
|
||||
$index = LinkFilter::reverseIndexes( $url );
|
||||
$this->assertEquals( $expected, $index, "LinkFilter::reverseIndexe(\"$url\")" );
|
||||
}
|
||||
|
||||
|
|
@ -478,89 +478,11 @@ class LinkFilterTest extends MediaWikiLangTestCase {
|
|||
* @dataProvider provideGetQueryConditions
|
||||
*/
|
||||
public function testGetQueryConditions( $query, $options, $expected ) {
|
||||
$this->overrideConfigValue( MainConfigNames::ExternalLinksSchemaMigrationStage, SCHEMA_COMPAT_OLD );
|
||||
$conds = LinkFilter::getQueryConditions( $query, $options );
|
||||
$this->assertEquals( $expected, $conds );
|
||||
}
|
||||
|
||||
public static function provideGetQueryConditions() {
|
||||
return [
|
||||
'Basic example' => [
|
||||
'example.com',
|
||||
[],
|
||||
[
|
||||
'el_index_60 LIKE \'http://com.example./%\' ESCAPE \'`\' ',
|
||||
'el_index LIKE \'http://com.example./%\' ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
'Basic example with path' => [
|
||||
'example.com/foobar',
|
||||
[],
|
||||
[
|
||||
'el_index_60 LIKE \'http://com.example./foobar%\' ESCAPE \'`\' ',
|
||||
'el_index LIKE \'http://com.example./foobar%\' ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
'Wildcard domain' => [
|
||||
'*.example.com',
|
||||
[],
|
||||
[
|
||||
'el_index_60 LIKE \'http://com.example.%\' ESCAPE \'`\' ',
|
||||
'el_index LIKE \'http://com.example.%\' ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
'Wildcard domain with path' => [
|
||||
'*.example.com/foobar',
|
||||
[],
|
||||
[
|
||||
'el_index_60 LIKE \'http://com.example.%\' ESCAPE \'`\' ',
|
||||
'el_index LIKE \'http://com.example.%/foobar%\' ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
'Wildcard domain with path, oneWildcard=true' => [
|
||||
'*.example.com/foobar',
|
||||
[ 'oneWildcard' => true ],
|
||||
[
|
||||
'el_index_60 LIKE \'http://com.example.%\' ESCAPE \'`\' ',
|
||||
'el_index LIKE \'http://com.example.%\' ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
'Constant prefix' => [
|
||||
'example.com/blah/blah/blah/blah/blah/blah/blah/blah/blah/blah?foo=',
|
||||
[],
|
||||
[
|
||||
'el_index_60' => 'http://com.example./blah/blah/blah/blah/blah/blah/blah/blah/',
|
||||
'el_index LIKE ' .
|
||||
'\'http://com.example./blah/blah/blah/blah/blah/blah/blah/blah/blah/blah?foo=%\' ' .
|
||||
'ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
'Bad protocol' => [
|
||||
'test/',
|
||||
[ 'protocol' => 'invalid://' ],
|
||||
false
|
||||
],
|
||||
'Various options' => [
|
||||
'example.com',
|
||||
[ 'protocol' => 'https://' ],
|
||||
[
|
||||
'el_index_60 LIKE \'https://com.example./%\' ESCAPE \'`\' ',
|
||||
'el_index LIKE \'https://com.example./%\' ESCAPE \'`\' ',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGetQueryConditionsReadNew
|
||||
*/
|
||||
public function testGetQueryConditionsReadNew( $query, $options, $expected ) {
|
||||
$this->overrideConfigValue( MainConfigNames::ExternalLinksSchemaMigrationStage, SCHEMA_COMPAT_NEW );
|
||||
$conds = LinkFilter::getQueryConditions( $query, $options );
|
||||
$this->assertEquals( $expected, $conds );
|
||||
}
|
||||
|
||||
public static function provideGetQueryConditionsReadNew() {
|
||||
return [
|
||||
'Basic example' => [
|
||||
'example.com',
|
||||
|
|
@ -638,7 +560,6 @@ class LinkFilterTest extends MediaWikiLangTestCase {
|
|||
* @dataProvider provideGetIndexedUrlsNonReversed
|
||||
*/
|
||||
public function testGetIndexedUrlsNonReversed( $urls, $expected ) {
|
||||
$this->overrideConfigValue( MainConfigNames::ExternalLinksSchemaMigrationStage, SCHEMA_COMPAT_NEW );
|
||||
$list = LinkFilter::getIndexedUrlsNonReversed( $urls );
|
||||
$this->assertEquals( $expected, $list );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue