*/
protected $description;
- /**
- * Callable used to check whether this filter is allowed to take effect
- *
- * @var callable $isAllowedCallable
- */
- protected $isAllowedCallable;
-
/**
* List of conflicting groups
*
const RESERVED_NAME_CHAR = '_';
/**
- * Create a new filter with the specified configuration.
+ * Creates a new filter with the specified configuration, and registers it to the
+ * specified group.
*
* It infers which UI (it can be either or both) to display the filter on based on
* which messages are provided.
* $filterDefinition['label'] string i18n key of label for structured UI.
* $filterDefinition['description'] string i18n key of description for structured
* UI.
- * $filterDefinition['isAllowedCallable'] callable Callable taking two parameters,
- * the class name of the special page and an IContextSource, and returning true
- * if and only if the current user is permitted to use this filter on the current
- * wiki. If it returns false, it will both hide the UI (in all UIs) and prevent
- * the DB query modification from taking effect. (optional, defaults to allowed)
* $filterDefinition['priority'] int Priority integer. Higher value means higher
* up in the group's filter list.
*/
);
}
+ if ( $this->group->getFilter( $filterDefinition['name'] ) ) {
+ throw new MWException( 'Two filters in a group cannot have the ' .
+ "same name: '{$filterDefinition['name']}'" );
+ }
+
$this->name = $filterDefinition['name'];
if ( isset( $filterDefinition['cssClassSuffix'] ) ) {
$this->description = $filterDefinition['description'];
}
- if ( isset( $filterDefinition['isAllowedCallable'] ) ) {
- $this->isAllowedCallable = $filterDefinition['isAllowedCallable'];
- }
-
$this->priority = $filterDefinition['priority'];
$this->group->registerFilter( $this );
/**
* Checks whether the filter should display on the unstructured UI
*
- * @param ChangesListSpecialPage $specialPage Current special page
* @return bool Whether to display
*/
- abstract public function displaysOnUnstructuredUi( ChangesListSpecialPage $specialPage );
+ abstract public function displaysOnUnstructuredUi();
/**
* Checks whether the filter should display on the structured UI
* This refers to the exact filter. See also isFeatureAvailableOnStructuredUi.
*
- * @param ChangesListSpecialPage $specialPage Current special page
* @return bool Whether to display
*/
- public function displaysOnStructuredUi( ChangesListSpecialPage $specialPage ) {
- return $this->label !== null && $this->isAllowed( $specialPage );
+ public function displaysOnStructuredUi() {
+ return $this->label !== null;
}
/**
*
* This can either be the exact filter, or a new filter that replaces it.
*/
- public function isFeatureAvailableOnStructuredUi( ChangesListSpecialPage $specialPage ) {
- return $this->displaysOnStructuredUi( $specialPage );
+ public function isFeatureAvailableOnStructuredUi() {
+ return $this->displaysOnStructuredUi();
}
/**
return $this->priority;
}
- /**
- * Checks whether the filter is allowed for the current context
- *
- * @param ChangesListSpecialPage $specialPage Current special page
- * @return bool Whether it is allowed
- */
- public function isAllowed( ChangesListSpecialPage $specialPage ) {
- if ( $this->isAllowedCallable === null ) {
- return true;
- } else {
- return call_user_func(
- $this->isAllowedCallable,
- get_class( $specialPage ),
- $specialPage->getContext()
- );
- }
- }
-
/**
* Gets the CSS class
*