Use buildComparison() instead of raw SQL in more API modules (easy cases)
See ec79aa3943 about the new method.
These changes all follow the same simple patterns. More complex cases
are handled in I6231b6beae13474d4986929367a9adc6bb76b0db.
This commit was created by running the following terrible Ruby script
I devised: https://phabricator.wikimedia.org/P34833, then manually
reviewing the results: checking that the output makes sense in general,
that the affected variables are not used elsewhere in the file, and
that no comparison conditions have been lost. A few incorrect changes
were undone or corrected.
Change-Id: I8ed363bd6b80a9481d44434a526f078cce20220f
This commit is contained in:
parent
872970a21c
commit
00b74a0e4b
22 changed files with 198 additions and 209 deletions
|
|
@ -64,9 +64,9 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 1 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$cont_from = $db->addQuotes( $cont[0] );
|
||||
$this->addWhere( "cat_title $op= $cont_from" );
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$cont_from = $cont[0];
|
||||
$this->addWhere( $db->buildComparison( $op, [ 'cat_title' => $cont_from ] ) );
|
||||
}
|
||||
|
||||
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
|
||||
|
|
|
|||
|
|
@ -299,37 +299,39 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
|
|||
|
||||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$op = ( $dir == 'newer' ? '>' : '<' );
|
||||
$op = ( $dir == 'newer' ? '>=' : '<=' );
|
||||
if ( $optimizeGenerateTitles ) {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$ns = (int)$cont[0];
|
||||
$this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
|
||||
$title = $db->addQuotes( $cont[1] );
|
||||
$this->addWhere( "ar_namespace $op $ns OR " .
|
||||
"(ar_namespace = $ns AND ar_title $op= $title)" );
|
||||
$title = $cont[1];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_namespace' => $ns,
|
||||
'ar_title' => $title,
|
||||
] ) );
|
||||
} elseif ( $mode == 'all' ) {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 4 );
|
||||
$ns = (int)$cont[0];
|
||||
$this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
|
||||
$title = $db->addQuotes( $cont[1] );
|
||||
$ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
|
||||
$title = $cont[1];
|
||||
$ts = $db->timestamp( $cont[2] );
|
||||
$ar_id = (int)$cont[3];
|
||||
$this->dieContinueUsageIf( strval( $ar_id ) !== $cont[3] );
|
||||
$this->addWhere( "ar_namespace $op $ns OR " .
|
||||
"(ar_namespace = $ns AND " .
|
||||
"(ar_title $op $title OR " .
|
||||
"(ar_title = $title AND " .
|
||||
"(ar_timestamp $op $ts OR " .
|
||||
"(ar_timestamp = $ts AND " .
|
||||
"ar_id $op= $ar_id)))))" );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_namespace' => $ns,
|
||||
'ar_title' => $title,
|
||||
'ar_timestamp' => $ts,
|
||||
'ar_id' => $ar_id,
|
||||
] ) );
|
||||
} else {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$ts = $db->timestamp( $cont[0] );
|
||||
$ar_id = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( strval( $ar_id ) !== $cont[1] );
|
||||
$this->addWhere( "ar_timestamp $op $ts OR " .
|
||||
"(ar_timestamp = $ts AND " .
|
||||
"ar_id $op= $ar_id)" );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_timestamp' => $ts,
|
||||
'ar_id' => $ar_id,
|
||||
] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,9 +153,9 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 1 );
|
||||
$op = $ascendingOrder ? '>' : '<';
|
||||
$continueFrom = $db->addQuotes( $cont[0] );
|
||||
$this->addWhere( "img_name $op= $continueFrom" );
|
||||
$op = $ascendingOrder ? '>=' : '<=';
|
||||
$continueFrom = $cont[0];
|
||||
$this->addWhere( $db->buildComparison( $op, [ 'img_name' => $continueFrom ] ) );
|
||||
}
|
||||
|
||||
// Image filters
|
||||
|
|
@ -204,13 +204,13 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$op = ( $ascendingOrder ? '>' : '<' );
|
||||
$continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$continueName = $db->addQuotes( $cont[1] );
|
||||
$this->addWhere( "img_timestamp $op $continueTimestamp OR " .
|
||||
"(img_timestamp = $continueTimestamp AND " .
|
||||
"img_name $op= $continueName)"
|
||||
);
|
||||
$op = ( $ascendingOrder ? '>=' : '<=' );
|
||||
$continueTimestamp = $db->timestamp( $cont[0] );
|
||||
$continueName = $cont[1];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'img_timestamp' => $continueTimestamp,
|
||||
'img_name' => $continueName,
|
||||
] ) );
|
||||
}
|
||||
|
||||
// Image filters
|
||||
|
|
|
|||
|
|
@ -175,20 +175,19 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
|
|||
$continue = $params['continue'] !== null;
|
||||
if ( $continue ) {
|
||||
$continueArr = explode( '|', $params['continue'] );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
if ( $params['unique'] ) {
|
||||
$this->dieContinueUsageIf( count( $continueArr ) != 1 );
|
||||
$continueTitle = $db->addQuotes( $continueArr[0] );
|
||||
$this->addWhere( "{$titleField} $op= $continueTitle" );
|
||||
$continueTitle = $continueArr[0];
|
||||
$this->addWhere( $db->buildComparison( $op, [ $titleField => $continueTitle ] ) );
|
||||
} else {
|
||||
$this->dieContinueUsageIf( count( $continueArr ) != 2 );
|
||||
$continueTitle = $db->addQuotes( $continueArr[0] );
|
||||
$continueTitle = $continueArr[0];
|
||||
$continueFrom = (int)$continueArr[1];
|
||||
$this->addWhere(
|
||||
"{$titleField} $op $continueTitle OR " .
|
||||
"({$titleField} = $continueTitle AND " .
|
||||
"{$pfx}from $op= $continueFrom)"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
$titleField => $continueTitle,
|
||||
"{$pfx}from" => $continueFrom,
|
||||
] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 1 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$cont_from = $db->addQuotes( $cont[0] );
|
||||
$this->addWhere( "page_title $op= $cont_from" );
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$cont_from = $cont[0];
|
||||
$this->addWhere( $db->buildComparison( $op, [ 'page_title' => $cont_from ] ) );
|
||||
}
|
||||
|
||||
$miserMode = $this->getConfig()->get( MainConfigNames::MiserMode );
|
||||
|
|
|
|||
|
|
@ -156,15 +156,15 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
|
|||
$this->addWhereFld( $this->bl_from_ns, $this->params['namespace'] );
|
||||
|
||||
if ( count( $this->cont ) >= 2 ) {
|
||||
$op = $this->params['dir'] == 'descending' ? '<' : '>';
|
||||
$db = $this->getDB();
|
||||
$op = $this->params['dir'] == 'descending' ? '<=' : '>=';
|
||||
if ( $this->params['namespace'] !== null && count( $this->params['namespace'] ) > 1 ) {
|
||||
$this->addWhere(
|
||||
"{$this->bl_from_ns} $op {$this->cont[0]} OR " .
|
||||
"({$this->bl_from_ns} = {$this->cont[0]} AND " .
|
||||
"{$this->bl_from} $op= {$this->cont[1]})"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
$this->bl_from_ns => $this->cont[0],
|
||||
$this->bl_from => $this->cont[1],
|
||||
] ) );
|
||||
} else {
|
||||
$this->addWhere( "{$this->bl_from} $op= {$this->cont[1]}" );
|
||||
$this->addWhere( $db->buildComparison( $op, [ $this->bl_from => $this->cont[1] ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,16 +91,16 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
|
|||
}
|
||||
|
||||
if ( $params['continue'] !== null ) {
|
||||
$db = $this->getDB();
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$clfrom = (int)$cont[0];
|
||||
$clto = $this->getDB()->addQuotes( $cont[1] );
|
||||
$this->addWhere(
|
||||
"cl_from $op $clfrom OR " .
|
||||
"(cl_from = $clfrom AND " .
|
||||
"cl_to $op= $clto)"
|
||||
);
|
||||
$clto = $cont[1];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'cl_from' => $clfrom,
|
||||
'cl_to' => $clto,
|
||||
] ) );
|
||||
}
|
||||
|
||||
if ( isset( $show['hidden'] ) && isset( $show['!hidden'] ) ) {
|
||||
|
|
|
|||
|
|
@ -223,11 +223,10 @@ class ApiQueryContributors extends ApiQueryBase {
|
|||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$cont_page = (int)$cont[0];
|
||||
$cont_id = (int)$cont[1];
|
||||
$this->addWhere(
|
||||
"$pageField > $cont_page OR " .
|
||||
"($pageField = $cont_page AND " .
|
||||
"$idField >= $cont_id)"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( '>=', [
|
||||
$pageField => $cont_page,
|
||||
$idField => $cont_id,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$res = $this->select( __METHOD__ );
|
||||
|
|
|
|||
|
|
@ -193,31 +193,31 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
|
|||
|
||||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$op = ( $dir == 'newer' ? '>' : '<' );
|
||||
$op = ( $dir == 'newer' ? '>=' : '<=' );
|
||||
if ( $revCount !== 0 ) {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$rev = (int)$cont[0];
|
||||
$this->dieContinueUsageIf( strval( $rev ) !== $cont[0] );
|
||||
$ar_id = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( strval( $ar_id ) !== $cont[1] );
|
||||
$this->addWhere( "ar_rev_id $op $rev OR " .
|
||||
"(ar_rev_id = $rev AND " .
|
||||
"ar_id $op= $ar_id)" );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_rev_id' => $rev,
|
||||
'ar_id' => $ar_id,
|
||||
] ) );
|
||||
} else {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 4 );
|
||||
$ns = (int)$cont[0];
|
||||
$this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
|
||||
$title = $db->addQuotes( $cont[1] );
|
||||
$ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
|
||||
$title = $cont[1];
|
||||
$ts = $db->timestamp( $cont[2] );
|
||||
$ar_id = (int)$cont[3];
|
||||
$this->dieContinueUsageIf( strval( $ar_id ) !== $cont[3] );
|
||||
$this->addWhere( "ar_namespace $op $ns OR " .
|
||||
"(ar_namespace = $ns AND " .
|
||||
"(ar_title $op $title OR " .
|
||||
"(ar_title = $title AND " .
|
||||
"(ar_timestamp $op $ts OR " .
|
||||
"(ar_timestamp = $ts AND " .
|
||||
"ar_id $op= $ar_id)))))" );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_namespace' => $ns,
|
||||
'ar_title' => $title,
|
||||
'ar_timestamp' => $ts,
|
||||
'ar_id' => $ar_id,
|
||||
] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -251,30 +251,30 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
|
|||
|
||||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$op = ( $dir == 'newer' ? '>' : '<' );
|
||||
$op = ( $dir == 'newer' ? '>=' : '<=' );
|
||||
if ( $mode == 'all' || $mode == 'revs' ) {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 4 );
|
||||
$ns = (int)$cont[0];
|
||||
$this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
|
||||
$title = $db->addQuotes( $cont[1] );
|
||||
$ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
|
||||
$title = $cont[1];
|
||||
$ts = $db->timestamp( $cont[2] );
|
||||
$ar_id = (int)$cont[3];
|
||||
$this->dieContinueUsageIf( strval( $ar_id ) !== $cont[3] );
|
||||
$this->addWhere( "ar_namespace $op $ns OR " .
|
||||
"(ar_namespace = $ns AND " .
|
||||
"(ar_title $op $title OR " .
|
||||
"(ar_title = $title AND " .
|
||||
"(ar_timestamp $op $ts OR " .
|
||||
"(ar_timestamp = $ts AND " .
|
||||
"ar_id $op= $ar_id)))))" );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_namespace' => $ns,
|
||||
'ar_title' => $title,
|
||||
'ar_timestamp' => $ts,
|
||||
'ar_id' => $ar_id,
|
||||
] ) );
|
||||
} else {
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$ts = $db->timestamp( $cont[0] );
|
||||
$ar_id = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( strval( $ar_id ) !== $cont[1] );
|
||||
$this->addWhere( "ar_timestamp $op $ts OR " .
|
||||
"(ar_timestamp = $ts AND " .
|
||||
"ar_id $op= $ar_id)" );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'ar_timestamp' => $ts,
|
||||
'ar_id' => $ar_id,
|
||||
] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,17 +95,16 @@ class ApiQueryFilearchive extends ApiQueryBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 3 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$cont_from = $db->addQuotes( $cont[0] );
|
||||
$cont_timestamp = $db->addQuotes( $db->timestamp( $cont[1] ) );
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$cont_from = $cont[0];
|
||||
$cont_timestamp = $db->timestamp( $cont[1] );
|
||||
$cont_id = (int)$cont[2];
|
||||
$this->dieContinueUsageIf( $cont[2] !== (string)$cont_id );
|
||||
$this->addWhere( "fa_name $op $cont_from OR " .
|
||||
"(fa_name = $cont_from AND " .
|
||||
"(fa_timestamp $op $cont_timestamp OR " .
|
||||
"(fa_timestamp = $cont_timestamp AND " .
|
||||
"fa_id $op= $cont_id )))"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'fa_name' => $cont_from,
|
||||
'fa_timestamp' => $cont_timestamp,
|
||||
'fa_id' => $cont_id,
|
||||
] ) );
|
||||
}
|
||||
|
||||
// Image filters
|
||||
|
|
|
|||
|
|
@ -71,17 +71,15 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
|
|||
$this->dieContinueUsageIf( count( $cont ) != 3 );
|
||||
|
||||
$db = $this->getDB();
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$prefix = $db->addQuotes( $cont[0] );
|
||||
$title = $db->addQuotes( $cont[1] );
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$prefix = $cont[0];
|
||||
$title = $cont[1];
|
||||
$from = (int)$cont[2];
|
||||
$this->addWhere(
|
||||
"iwl_prefix $op $prefix OR " .
|
||||
"(iwl_prefix = $prefix AND " .
|
||||
"(iwl_title $op $title OR " .
|
||||
"(iwl_title = $title AND " .
|
||||
"iwl_from $op= $from)))"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'iwl_prefix' => $prefix,
|
||||
'iwl_title' => $title,
|
||||
'iwl_from' => $from,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$prop = array_fill_keys( $params['prop'], true );
|
||||
|
|
|
|||
|
|
@ -75,18 +75,16 @@ class ApiQueryIWLinks extends ApiQueryBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 3 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$db = $this->getDB();
|
||||
$iwlfrom = (int)$cont[0];
|
||||
$iwlprefix = $db->addQuotes( $cont[1] );
|
||||
$iwltitle = $db->addQuotes( $cont[2] );
|
||||
$this->addWhere(
|
||||
"iwl_from $op $iwlfrom OR " .
|
||||
"(iwl_from = $iwlfrom AND " .
|
||||
"(iwl_prefix $op $iwlprefix OR " .
|
||||
"(iwl_prefix = $iwlprefix AND " .
|
||||
"iwl_title $op= $iwltitle)))"
|
||||
);
|
||||
$iwlprefix = $cont[1];
|
||||
$iwltitle = $cont[2];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'iwl_from' => $iwlfrom,
|
||||
'iwl_prefix' => $iwlprefix,
|
||||
'iwl_title' => $iwltitle,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
|
||||
|
|
|
|||
|
|
@ -65,16 +65,16 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
|
|||
$this->addTables( 'imagelinks' );
|
||||
$this->addWhereFld( 'il_from', array_keys( $pages ) );
|
||||
if ( $params['continue'] !== null ) {
|
||||
$db = $this->getDB();
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$ilfrom = (int)$cont[0];
|
||||
$ilto = $this->getDB()->addQuotes( $cont[1] );
|
||||
$this->addWhere(
|
||||
"il_from $op $ilfrom OR " .
|
||||
"(il_from = $ilfrom AND " .
|
||||
"il_to $op= $ilto)"
|
||||
);
|
||||
$ilto = $cont[1];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'il_from' => $ilfrom,
|
||||
'il_to' => $ilto,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
|
||||
|
|
|
|||
|
|
@ -71,17 +71,15 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
|
|||
$this->dieContinueUsageIf( count( $cont ) != 3 );
|
||||
|
||||
$db = $this->getDB();
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$prefix = $db->addQuotes( $cont[0] );
|
||||
$title = $db->addQuotes( $cont[1] );
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$prefix = $cont[0];
|
||||
$title = $cont[1];
|
||||
$from = (int)$cont[2];
|
||||
$this->addWhere(
|
||||
"ll_lang $op $prefix OR " .
|
||||
"(ll_lang = $prefix AND " .
|
||||
"(ll_title $op $title OR " .
|
||||
"(ll_title = $title AND " .
|
||||
"ll_from $op= $from)))"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'll_lang' => $prefix,
|
||||
'll_title' => $title,
|
||||
'll_from' => $from,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$prop = array_fill_keys( $params['prop'], true );
|
||||
|
|
|
|||
|
|
@ -84,16 +84,16 @@ class ApiQueryLangLinks extends ApiQueryBase {
|
|||
$this->addTables( 'langlinks' );
|
||||
$this->addWhereFld( 'll_from', array_keys( $pages ) );
|
||||
if ( $params['continue'] !== null ) {
|
||||
$db = $this->getDB();
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$llfrom = (int)$cont[0];
|
||||
$lllang = $this->getDB()->addQuotes( $cont[1] );
|
||||
$this->addWhere(
|
||||
"ll_from $op $llfrom OR " .
|
||||
"(ll_from = $llfrom AND " .
|
||||
"ll_lang $op= $lllang)"
|
||||
);
|
||||
$lllang = $cont[1];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'll_from' => $llfrom,
|
||||
'll_lang' => $lllang,
|
||||
] ) );
|
||||
}
|
||||
|
||||
// FIXME: (follow-up) To allow extensions to add to the language links, we need
|
||||
|
|
|
|||
|
|
@ -150,19 +150,18 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
|
|||
}
|
||||
|
||||
if ( $params['continue'] !== null ) {
|
||||
$db = $this->getDB();
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 3 );
|
||||
$op = $params['dir'] == 'descending' ? '<' : '>';
|
||||
$op = $params['dir'] == 'descending' ? '<=' : '>=';
|
||||
$plfrom = (int)$cont[0];
|
||||
$plns = (int)$cont[1];
|
||||
$pltitle = $this->getDB()->addQuotes( $cont[2] );
|
||||
$this->addWhere(
|
||||
"{$this->prefix}_from $op $plfrom OR " .
|
||||
"({$this->prefix}_from = $plfrom AND " .
|
||||
"($nsField $op $plns OR " .
|
||||
"($nsField = $plns AND " .
|
||||
"$titleField $op= $pltitle)))"
|
||||
);
|
||||
$pltitle = $cont[2];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
"{$this->prefix}_from" => $plfrom,
|
||||
$nsField => $plns,
|
||||
$titleField => $pltitle,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
|
||||
|
|
|
|||
|
|
@ -194,14 +194,14 @@ class ApiQueryLogEvents extends ApiQueryBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$op = ( $params['dir'] === 'newer' ? '>' : '<' );
|
||||
$continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$op = ( $params['dir'] === 'newer' ? '>=' : '<=' );
|
||||
$continueTimestamp = $db->timestamp( $cont[0] );
|
||||
$continueId = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( $continueId != $cont[1] );
|
||||
$this->addWhere( "log_timestamp $op $continueTimestamp OR " .
|
||||
"(log_timestamp = $continueTimestamp AND " .
|
||||
"log_id $op= $continueId)"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'log_timestamp' => $continueTimestamp,
|
||||
'log_id' => $continueId,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$limit = $params['limit'];
|
||||
|
|
|
|||
|
|
@ -96,18 +96,17 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 3 );
|
||||
$op = ( $params['dir'] === 'newer' ? '>' : '<' );
|
||||
$op = ( $params['dir'] === 'newer' ? '>=' : '<=' );
|
||||
$db = $this->getDB();
|
||||
$continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$continueTimestamp = $db->timestamp( $cont[0] );
|
||||
$continueNs = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( $continueNs != $cont[1] );
|
||||
$continueTitle = $db->addQuotes( $cont[2] );
|
||||
$this->addWhere( "pt_timestamp $op $continueTimestamp OR " .
|
||||
"(pt_timestamp = $continueTimestamp AND " .
|
||||
"(pt_namespace $op $continueNs OR " .
|
||||
"(pt_namespace = $continueNs AND " .
|
||||
"pt_title $op= $continueTitle)))"
|
||||
);
|
||||
$continueTitle = $cont[2];
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'pt_timestamp' => $continueTimestamp,
|
||||
'pt_namespace' => $continueNs,
|
||||
'pt_title' => $continueTitle,
|
||||
] ) );
|
||||
}
|
||||
|
||||
if ( isset( $prop['user'] ) ) {
|
||||
|
|
|
|||
|
|
@ -137,15 +137,14 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
|
|||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$db = $this->getDB();
|
||||
$timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$timestamp = $db->timestamp( $cont[0] );
|
||||
$id = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( $id != $cont[1] );
|
||||
$op = $params['dir'] === 'older' ? '<' : '>';
|
||||
$this->addWhere(
|
||||
"rc_timestamp $op $timestamp OR " .
|
||||
"(rc_timestamp = $timestamp AND " .
|
||||
"rc_id $op= $id)"
|
||||
);
|
||||
$op = $params['dir'] === 'older' ? '<=' : '>=';
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
'rc_timestamp' => $timestamp,
|
||||
'rc_id' => $id,
|
||||
] ) );
|
||||
}
|
||||
|
||||
$order = $params['dir'] === 'older' ? 'DESC' : 'ASC';
|
||||
|
|
|
|||
|
|
@ -220,14 +220,14 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
|
|||
if ( $params['continue'] !== null ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$op = ( $params['dir'] === 'newer' ? '>' : '<' );
|
||||
$continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
|
||||
$op = ( $params['dir'] === 'newer' ? '>=' : '<=' );
|
||||
$continueTimestamp = $db->timestamp( $cont[0] );
|
||||
$continueId = (int)$cont[1];
|
||||
$this->dieContinueUsageIf( $continueId != $cont[1] );
|
||||
$this->addWhere( "$tsField $op $continueTimestamp OR " .
|
||||
"($tsField = $continueTimestamp AND " .
|
||||
"$idField $op= $continueId)"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
$tsField => $continueTimestamp,
|
||||
$idField => $continueId,
|
||||
] ) );
|
||||
}
|
||||
|
||||
// Convert startid/endid to timestamps (T163532)
|
||||
|
|
@ -276,26 +276,30 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
|
|||
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
if ( $params['start'] !== null ) {
|
||||
$op = ( $params['dir'] === 'newer' ? '>' : '<' );
|
||||
$op = ( $params['dir'] === 'newer' ? '>=' : '<=' );
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
$ts = $db->addQuotes( $db->timestampOrNull( $params['start'] ) );
|
||||
$ts = $db->timestampOrNull( $params['start'] );
|
||||
if ( $params['startid'] !== null ) {
|
||||
$this->addWhere( "$tsField $op $ts OR "
|
||||
. "$tsField = $ts AND $idField $op= " . (int)$params['startid'] );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
$tsField => $ts,
|
||||
$idField => (int)$params['startid'],
|
||||
] ) );
|
||||
} else {
|
||||
$this->addWhere( "$tsField $op= $ts" );
|
||||
$this->addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
|
||||
}
|
||||
}
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
if ( $params['end'] !== null ) {
|
||||
$op = ( $params['dir'] === 'newer' ? '<' : '>' ); // Yes, opposite of the above
|
||||
$op = ( $params['dir'] === 'newer' ? '<=' : '>=' ); // Yes, opposite of the above
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
$ts = $db->addQuotes( $db->timestampOrNull( $params['end'] ) );
|
||||
$ts = $db->timestampOrNull( $params['end'] );
|
||||
if ( $params['endid'] !== null ) {
|
||||
$this->addWhere( "$tsField $op $ts OR "
|
||||
. "$tsField = $ts AND $idField $op= " . (int)$params['endid'] );
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
$tsField => $ts,
|
||||
$idField => (int)$params['endid'],
|
||||
] ) );
|
||||
} else {
|
||||
$this->addWhere( "$tsField $op= $ts" );
|
||||
$this->addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -373,11 +377,10 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
|
|||
$this->dieContinueUsageIf( count( $cont ) != 2 );
|
||||
$pageid = (int)$cont[0];
|
||||
$revid = (int)$cont[1];
|
||||
$this->addWhere(
|
||||
"rev_page > $pageid OR " .
|
||||
"(rev_page = $pageid AND " .
|
||||
"rev_id >= $revid)"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( '>=', [
|
||||
'rev_page' => $pageid,
|
||||
'rev_id' => $revid,
|
||||
] ) );
|
||||
}
|
||||
$this->addOption( 'ORDER BY', [
|
||||
'rev_page',
|
||||
|
|
|
|||
|
|
@ -412,30 +412,26 @@ class ApiQueryUserContribs extends ApiQueryBase {
|
|||
$this->dieContinueUsageIf( count( $continue ) != 4 );
|
||||
$modeFlag = array_shift( $continue );
|
||||
$this->dieContinueUsageIf( $modeFlag !== $this->orderBy );
|
||||
$encUser = $db->addQuotes( array_shift( $continue ) );
|
||||
$encUser = array_shift( $continue );
|
||||
} else {
|
||||
$this->dieContinueUsageIf( count( $continue ) != 2 );
|
||||
}
|
||||
$encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
|
||||
$encTS = $db->timestamp( $continue[0] );
|
||||
$encId = (int)$continue[1];
|
||||
$this->dieContinueUsageIf( $encId != $continue[1] );
|
||||
$op = ( $this->params['dir'] == 'older' ? '<' : '>' );
|
||||
$op = ( $this->params['dir'] == 'older' ? '<=' : '>=' );
|
||||
if ( $this->multiUserMode ) {
|
||||
$this->addWhere(
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable encUser is set when used
|
||||
"$userField $op $encUser OR " .
|
||||
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable encUser is set when used
|
||||
"($userField = $encUser AND " .
|
||||
"($tsField $op $encTS OR " .
|
||||
"($tsField = $encTS AND " .
|
||||
"$idField $op= $encId)))"
|
||||
);
|
||||
$userField => $encUser,
|
||||
$tsField => $encTS,
|
||||
$idField => $encId,
|
||||
] ) );
|
||||
} else {
|
||||
$this->addWhere(
|
||||
"$tsField $op $encTS OR " .
|
||||
"($tsField = $encTS AND " .
|
||||
"$idField $op= $encId)"
|
||||
);
|
||||
$this->addWhere( $db->buildComparison( $op, [
|
||||
$tsField => $encTS,
|
||||
$idField => $encId,
|
||||
] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue