+ if ( $query !== null && $query !== '' ) {
+ if ( $protocol === null ) {
+ $protocol = 'http://';
+ }
+
+ // Normalize query to match the normalization applied for the externallinks table
+ $query = Parser::normalizeLinkUrl( $protocol . $query );
+
+ $conds = LinkFilter::getQueryConditions( $query, [
+ 'protocol' => '',
+ 'oneWildcard' => true,
+ 'db' => $db
+ ] );
+ if ( !$conds ) {
+ $this->dieWithError( 'apierror-badquery' );
+ }
+ $this->addWhere( $conds );
+ if ( !isset( $conds['el_index_60'] ) ) {
+ $orderBy[] = 'el_index_60';
+ }
+ } else {
+ $orderBy[] = 'el_index_60';