*/
protected $priority;
+ const RESERVED_NAME_CHAR = '_';
+
/**
* Create a new filter with the specified configuration.
*
*
* @param array $filterDefinition ChangesListFilter definition
*
- * $filterDefinition['name'] string Name of filter
+ * $filterDefinition['name'] string Name of filter; use lowercase with no
+ * punctuation
* $filterDefinition['cssClassSuffix'] string CSS class suffix, used to mark
* that a particular row belongs to this filter (when a row is included by the
* filter) (optional)
'ChangesListFilterGroup this filter belongs to' );
}
+ if ( strpos( $filterDefinition['name'], self::RESERVED_NAME_CHAR ) !== false ) {
+ throw new MWException( 'Filter names may not contain \'' .
+ self::RESERVED_NAME_CHAR .
+ '\'. Use the naming convention: \'lowercase\''
+ );
+ }
+
$this->name = $filterDefinition['name'];
if ( isset( $filterDefinition['cssClassSuffix'] ) ) {
const DEFAULT_PRIORITY = -100;
+ const RESERVED_NAME_CHAR = '_';
+
/**
* Create a new filter group with the specified configuration
*
* @param array $groupDefinition Configuration of group
- * * $groupDefinition['name'] string Group name
+ * * $groupDefinition['name'] string Group name; use camelCase with no punctuation
* * $groupDefinition['title'] string i18n key for title (optional, can be omitted
* * only if none of the filters in the group display in the structured UI)
* * $groupDefinition['type'] string A type constant from a subclass of this one
* * changes list entries are filtered out.
*/
public function __construct( array $groupDefinition ) {
+ if ( strpos( $groupDefinition['name'], self::RESERVED_NAME_CHAR ) !== false ) {
+ throw new MWException( 'Group names may not contain \'' .
+ self::RESERVED_NAME_CHAR .
+ '\'. Use the naming convention: \'camelCase\''
+ );
+ }
+
$this->name = $groupDefinition['name'];
if ( isset( $groupDefinition['title'] ) ) {
* @covers ChangesListFilterGroup
*/
class ChangesListFilterGroupTest extends MediaWikiTestCase {
+ // @codingStandardsIgnoreStart
+ /**
+ * @expectedException MWException
+ * @expectedExceptionMessage Group names may not contain '_'. Use the naming convention: 'camelCase'
+ */
+ // @codingStandardsIgnoreEnd
+ public function testReservedCharacter() {
+ new MockChangesListFilterGroup(
+ [
+ 'type' => 'some_type',
+ 'name' => 'group_name',
+ 'priority' => 1,
+ 'filters' => [],
+ ]
+ );
+ }
+
public function testAutoPriorities() {
$group = new MockChangesListFilterGroup(
[
}
+ // @codingStandardsIgnoreStart
+ /**
+ * @expectedException MWException
+ * @expectedExceptionMessage Filter names may not contain '_'. Use the naming convention: 'lowercase'
+ */
+ // @codingStandardsIgnoreEnd
+ public function testReservedCharacter() {
+ $filter = new MockChangesListFilter(
+ [
+ 'group' => $this->group,
+ 'name' => 'some_name',
+ 'priority' => 1,
+ ]
+ );
+ }
+
/**
* @expectedException MWException
* @expectedExceptionMessage Supersets can only be defined for filters in the same group