Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/395064 )

Change subject: API: Account for PHP 7.2 change
......................................................................

API: Account for PHP 7.2 change

PHP 7.2 broke existing functionality in making count( null ) raise a
warning. So add tests for null all over the place, or change tests where
we know the value is null or an array (but not false, empty-string, or
0) to just cast to boolean.

Bug: T182004
Change-Id: Idfe23a07daa9f60eee72f2daf04304be87057a29
---
M includes/api/ApiDelete.php
M includes/api/ApiEditPage.php
M includes/api/ApiImageRotate.php
M includes/api/ApiOptions.php
M includes/api/ApiQueryAllPages.php
M includes/api/ApiQueryBacklinks.php
M includes/api/ApiQueryBacklinksprop.php
M includes/api/ApiQueryBase.php
M includes/api/ApiQueryCategoryMembers.php
M includes/api/ApiQueryExtLinksUsage.php
M includes/api/ApiQueryLinks.php
M includes/api/ApiRevisionDelete.php
M includes/api/ApiRollback.php
M includes/api/ApiSetPageLanguage.php
M includes/api/ApiTag.php
M includes/api/ApiUserrights.php
16 files changed, 27 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/64/395064/1

diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php
index 7766acd..96c291c 100644
--- a/includes/api/ApiDelete.php
+++ b/includes/api/ApiDelete.php
@@ -59,7 +59,7 @@
 
                // If change tagging was requested, check that the user is 
allowed to tag,
                // and the tags are valid
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $tagStatus = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
                        if ( !$tagStatus->isOK() ) {
                                $this->dieStatus( $tagStatus );
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index 94d6e97..26d4fd1 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -334,7 +334,7 @@
                }
 
                // Apply change tags
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $tagStatus = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
                        if ( $tagStatus->isOK() ) {
                                $requestArray['wpChangeTags'] = implode( ',', 
$params['tags'] );
diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php
index 71bda6d..0568403 100644
--- a/includes/api/ApiImageRotate.php
+++ b/includes/api/ApiImageRotate.php
@@ -43,7 +43,7 @@
                ] );
 
                // Check if user can add tags
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $ableToTag = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $this->getUser() );
                        if ( !$ableToTag->isOK() ) {
                                $this->dieStatus( $ableToTag );
diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php
index 5b0d86a..14bd089 100644
--- a/includes/api/ApiOptions.php
+++ b/includes/api/ApiOptions.php
@@ -64,7 +64,7 @@
                }
 
                $changes = [];
-               if ( count( $params['change'] ) ) {
+               if ( $params['change'] ) {
                        foreach ( $params['change'] as $entry ) {
                                $array = explode( '=', $entry, 2 );
                                $changes[$array[0]] = isset( $array[1] ) ? 
$array[1] : null;
diff --git a/includes/api/ApiQueryAllPages.php 
b/includes/api/ApiQueryAllPages.php
index 315def0..a084279 100644
--- a/includes/api/ApiQueryAllPages.php
+++ b/includes/api/ApiQueryAllPages.php
@@ -136,12 +136,12 @@
                }
 
                // Page protection filtering
-               if ( count( $params['prtype'] ) || $params['prexpiry'] != 'all' 
) {
+               if ( $params['prtype'] || $params['prexpiry'] != 'all' ) {
                        $this->addTables( 'page_restrictions' );
                        $this->addWhere( 'page_id=pr_page' );
                        $this->addWhere( "pr_expiry > {$db->addQuotes( 
$db->timestamp() )} OR pr_expiry IS NULL" );
 
-                       if ( count( $params['prtype'] ) ) {
+                       if ( $params['prtype'] ) {
                                $this->addWhereFld( 'pr_type', 
$params['prtype'] );
 
                                if ( isset( $params['prlevel'] ) ) {
diff --git a/includes/api/ApiQueryBacklinks.php 
b/includes/api/ApiQueryBacklinks.php
index 54be254..830cc48 100644
--- a/includes/api/ApiQueryBacklinks.php
+++ b/includes/api/ApiQueryBacklinks.php
@@ -138,7 +138,7 @@
 
                if ( count( $this->cont ) >= 2 ) {
                        $op = $this->params['dir'] == 'descending' ? '<' : '>';
-                       if ( count( $this->params['namespace'] ) > 1 ) {
+                       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 " .
@@ -160,7 +160,7 @@
                $this->addOption( 'LIMIT', $this->params['limit'] + 1 );
                $sort = ( $this->params['dir'] == 'descending' ? ' DESC' : '' );
                $orderBy = [];
-               if ( count( $this->params['namespace'] ) > 1 ) {
+               if ( $this->params['namespace'] !== null && count( 
$this->params['namespace'] ) > 1 ) {
                        $orderBy[] = $this->bl_from_ns . $sort;
                }
                $orderBy[] = $this->bl_from . $sort;
@@ -246,7 +246,7 @@
                        $where = "{$this->bl_from} $op= {$this->cont[5]}";
                        // Don't bother with namespace, title, or 
from_namespace if it's
                        // otherwise constant in the where clause.
-                       if ( count( $this->params['namespace'] ) > 1 ) {
+                       if ( $this->params['namespace'] !== null && count( 
$this->params['namespace'] ) > 1 ) {
                                $where = "{$this->bl_from_ns} $op 
{$this->cont[4]} OR " .
                                        "({$this->bl_from_ns} = 
{$this->cont[4]} AND ($where))";
                        }
@@ -278,7 +278,7 @@
                if ( count( $allRedirDBkey ) > 1 ) {
                        $orderBy[] = $this->bl_title . $sort;
                }
-               if ( count( $this->params['namespace'] ) > 1 ) {
+               if ( $this->params['namespace'] !== null && count( 
$this->params['namespace'] ) > 1 ) {
                        $orderBy[] = $this->bl_from_ns . $sort;
                }
                $orderBy[] = $this->bl_from . $sort;
diff --git a/includes/api/ApiQueryBacklinksprop.php 
b/includes/api/ApiQueryBacklinksprop.php
index 1db15f8..ef02d09 100644
--- a/includes/api/ApiQueryBacklinksprop.php
+++ b/includes/api/ApiQueryBacklinksprop.php
@@ -161,7 +161,9 @@
                                }
                        } else {
                                $this->addWhereFld( "{$p}_from_namespace", 
$params['namespace'] );
-                               if ( !empty( $settings['from_namespace'] ) && 
count( $params['namespace'] ) > 1 ) {
+                               if ( !empty( $settings['from_namespace'] )
+                                       && $params['namespace'] !== null && 
count( $params['namespace'] ) > 1
+                               ) {
                                        $sortby["{$p}_from_namespace"] = 'int';
                                }
                        }
diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php
index 6987dfb..8e9b1b4 100644
--- a/includes/api/ApiQueryBase.php
+++ b/includes/api/ApiQueryBase.php
@@ -262,9 +262,7 @@
         * @param string|string[] $value Value; ignored if null or empty array;
         */
        protected function addWhereFld( $field, $value ) {
-               // Use count() to its full documented capabilities to 
simultaneously
-               // test for null, empty array or empty countable object
-               if ( count( $value ) ) {
+               if ( $value !== null && count( $value ) ) {
                        $this->where[$field] = $value;
                }
        }
diff --git a/includes/api/ApiQueryCategoryMembers.php 
b/includes/api/ApiQueryCategoryMembers.php
index c570ec9..e3265d1 100644
--- a/includes/api/ApiQueryCategoryMembers.php
+++ b/includes/api/ApiQueryCategoryMembers.php
@@ -97,7 +97,7 @@
                // how to have efficient subcategory access :-) ~~~~ (oh well, 
domas)
                $miser_ns = [];
                if ( $this->getConfig()->get( 'MiserMode' ) ) {
-                       $miser_ns = $params['namespace'];
+                       $miser_ns = $params['namespace'] ?: [];
                } else {
                        $this->addWhereFld( 'page_namespace', 
$params['namespace'] );
                }
diff --git a/includes/api/ApiQueryExtLinksUsage.php 
b/includes/api/ApiQueryExtLinksUsage.php
index 6c29b60..43f4131 100644
--- a/includes/api/ApiQueryExtLinksUsage.php
+++ b/includes/api/ApiQueryExtLinksUsage.php
@@ -61,7 +61,7 @@
 
                $miser_ns = [];
                if ( $this->getConfig()->get( 'MiserMode' ) ) {
-                       $miser_ns = $params['namespace'];
+                       $miser_ns = $params['namespace'] ?: [];
                } else {
                        $this->addWhereFld( 'page_namespace', 
$params['namespace'] );
                }
diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php
index 508bdf3..119db3e 100644
--- a/includes/api/ApiQueryLinks.php
+++ b/includes/api/ApiQueryLinks.php
@@ -114,7 +114,7 @@
                        }
                } elseif ( $params['namespace'] ) {
                        $this->addWhereFld( $this->prefix . '_namespace', 
$params['namespace'] );
-                       $multiNS = count( $params['namespace'] ) !== 1;
+                       $multiNS = $params['namespace'] === null || count( 
$params['namespace'] ) !== 1;
                }
 
                if ( !is_null( $params['continue'] ) ) {
diff --git a/includes/api/ApiRevisionDelete.php 
b/includes/api/ApiRevisionDelete.php
index 9d71a7d..5a51b28 100644
--- a/includes/api/ApiRevisionDelete.php
+++ b/includes/api/ApiRevisionDelete.php
@@ -47,7 +47,7 @@
                }
 
                // Check if user can add tags
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $ableToTag = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
                        if ( !$ableToTag->isOK() ) {
                                $this->dieStatus( $ableToTag );
diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php
index 76b6cc6..4ca2955 100644
--- a/includes/api/ApiRollback.php
+++ b/includes/api/ApiRollback.php
@@ -52,7 +52,7 @@
 
                // If change tagging was requested, check that the user is 
allowed to tag,
                // and the tags are valid
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $tagStatus = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
                        if ( !$tagStatus->isOK() ) {
                                $this->dieStatus( $tagStatus );
diff --git a/includes/api/ApiSetPageLanguage.php 
b/includes/api/ApiSetPageLanguage.php
index 7e3f1ac..54394a5 100644
--- a/includes/api/ApiSetPageLanguage.php
+++ b/includes/api/ApiSetPageLanguage.php
@@ -73,7 +73,7 @@
 
                // If change tagging was requested, check that the user is 
allowed to tag,
                // and the tags are valid
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $tagStatus = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
                        if ( !$tagStatus->isOK() ) {
                                $this->dieStatus( $tagStatus );
diff --git a/includes/api/ApiTag.php b/includes/api/ApiTag.php
index 76c6762..9304c2b 100644
--- a/includes/api/ApiTag.php
+++ b/includes/api/ApiTag.php
@@ -37,7 +37,7 @@
                }
 
                // Check if user can add tags
-               if ( count( $params['tags'] ) ) {
+               if ( $params['tags'] ) {
                        $ableToTag = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
                        if ( !$ableToTag->isOk() ) {
                                $this->dieStatus( $ableToTag );
diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php
index 2a364d9..3813aba 100644
--- a/includes/api/ApiUserrights.php
+++ b/includes/api/ApiUserrights.php
@@ -64,14 +64,15 @@
                } else {
                        $expiry = [ 'infinity' ];
                }
-               if ( count( $expiry ) !== count( $params['add'] ) ) {
+               $add = (array)$params['add'];
+               if ( count( $expiry ) !== count( $add ) ) {
                        if ( count( $expiry ) === 1 ) {
-                               $expiry = array_fill( 0, count( $params['add'] 
), $expiry[0] );
+                               $expiry = array_fill( 0, count( $add ), 
$expiry[0] );
                        } else {
                                $this->dieWithError( [
                                        'apierror-toofewexpiries',
                                        count( $expiry ),
-                                       count( $params['add'] )
+                                       count( $add )
                                ] );
                        }
                }
@@ -79,7 +80,7 @@
                // Validate the expiries
                $groupExpiries = [];
                foreach ( $expiry as $index => $expiryValue ) {
-                       $group = $params['add'][$index];
+                       $group = $add[$index];
                        $groupExpiries[$group] = 
UserrightsPage::expiryToTimestamp( $expiryValue );
 
                        if ( $groupExpiries[$group] === false ) {
@@ -109,7 +110,7 @@
                $r['user'] = $user->getName();
                $r['userid'] = $user->getId();
                list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups(
-                       $user, (array)$params['add'], (array)$params['remove'],
+                       $user, (array)$add, (array)$params['remove'],
                        $params['reason'], $tags, $groupExpiries
                );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/395064
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idfe23a07daa9f60eee72f2daf04304be87057a29
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to