dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Avoid the use of IDatabase::insert() return value
[lhc/web/wiklou.git]
/
includes
/
block
/
BlockRestriction.php
diff --git
a/includes/block/BlockRestriction.php
b/includes/block/BlockRestriction.php
index
3baa063
..
ca36cda
100644
(file)
--- a/
includes/block/BlockRestriction.php
+++ b/
includes/block/BlockRestriction.php
@@
-22,6
+22,7
@@
namespace MediaWiki\Block;
namespace MediaWiki\Block;
+use MediaWiki\Block\Restriction\NamespaceRestriction;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\Restriction;
use Wikimedia\Rdbms\IResultWrapper;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\Restriction;
use Wikimedia\Rdbms\IResultWrapper;
@@
-29,6
+30,14
@@
use Wikimedia\Rdbms\IDatabase;
class BlockRestriction {
class BlockRestriction {
+ /**
+ * Map of all of the restriction types.
+ */
+ private static $types = [
+ PageRestriction::TYPE_ID => PageRestriction::class,
+ NamespaceRestriction::TYPE_ID => NamespaceRestriction::class,
+ ];
+
/**
* Retrieves the restrictions from the database by block id.
*
/**
* Retrieves the restrictions from the database by block id.
*
@@
-82,12
+91,14
@@
class BlockRestriction {
$dbw = wfGetDB( DB_MASTER );
$dbw = wfGetDB( DB_MASTER );
-
return
$dbw->insert(
+ $dbw->insert(
'ipblocks_restrictions',
$rows,
__METHOD__,
[ 'IGNORE' ]
);
'ipblocks_restrictions',
$rows,
__METHOD__,
[ 'IGNORE' ]
);
+
+ return true;
}
/**
}
/**
@@
-140,7
+151,6
@@
class BlockRestriction {
$restrictions
);
$restrictions
);
- // Nothing to remove.
if ( empty( $restrictionsToRemove ) ) {
continue;
}
if ( empty( $restrictionsToRemove ) ) {
continue;
}
@@
-415,11
+425,11
@@
class BlockRestriction {
* @return Restriction|null
*/
private static function rowToRestriction( \stdClass $row ) {
* @return Restriction|null
*/
private static function rowToRestriction( \stdClass $row ) {
- switch ( $row->ir_type ) {
- case PageRestriction::TYPE_ID:
- return PageRestriction::newFromRow( $row );
- default:
- return null;
+ if ( array_key_exists( (int)$row->ir_type, self::$types ) ) {
+ $class = self::$types[ (int)$row->ir_type ];
+ return call_user_func( [ $class, 'newFromRow' ], $row );
}
}
+
+ return null;
}
}
}
}