MediaWiki REL1_31
ChangesListFilter.php
Go to the documentation of this file.
1<?php
29abstract class ChangesListFilter {
35 protected $name;
36
45 protected $cssClassSuffix;
46
53
59 protected $group;
60
66 protected $label;
67
73 protected $description;
74
81 protected $conflictingGroups = [];
82
89 protected $conflictingFilters = [];
90
96 protected $subsetFilters = [];
97
103 protected $priority;
104
110
112
142 public function __construct( array $filterDefinition ) {
143 if ( isset( $filterDefinition['group'] ) ) {
144 $this->group = $filterDefinition['group'];
145 } else {
146 throw new MWException( 'You must use \'group\' to specify the ' .
147 'ChangesListFilterGroup this filter belongs to' );
148 }
149
150 if ( strpos( $filterDefinition['name'], self::RESERVED_NAME_CHAR ) !== false ) {
151 throw new MWException( 'Filter names may not contain \'' .
152 self::RESERVED_NAME_CHAR .
153 '\'. Use the naming convention: \'lowercase\''
154 );
155 }
156
157 if ( $this->group->getFilter( $filterDefinition['name'] ) ) {
158 throw new MWException( 'Two filters in a group cannot have the ' .
159 "same name: '{$filterDefinition['name']}'" );
160 }
161
162 $this->name = $filterDefinition['name'];
163
164 if ( isset( $filterDefinition['cssClassSuffix'] ) ) {
165 $this->cssClassSuffix = $filterDefinition['cssClassSuffix'];
166 $this->isRowApplicableCallable = $filterDefinition['isRowApplicableCallable'];
167 }
168
169 if ( isset( $filterDefinition['label'] ) ) {
170 $this->label = $filterDefinition['label'];
171 $this->description = $filterDefinition['description'];
172 }
173
174 $this->priority = $filterDefinition['priority'];
175
176 $this->group->registerFilter( $this );
177 }
178
193 public function conflictsWith( $other, $globalKey, $forwardKey, $backwardKey ) {
194 if ( $globalKey === null || $forwardKey === null || $backwardKey === null ) {
195 throw new MWException( 'All messages must be specified' );
196 }
197
199 $other,
200 $globalKey,
201 $forwardKey
202 );
203
204 $other->setUnidirectionalConflict(
205 $this,
206 $globalKey,
207 $backwardKey
208 );
209 }
210
222 public function setUnidirectionalConflict( $other, $globalDescription, $contextDescription ) {
223 if ( $other instanceof ChangesListFilterGroup ) {
224 $this->conflictingGroups[] = [
225 'group' => $other->getName(),
226 'groupObject' => $other,
227 'globalDescription' => $globalDescription,
228 'contextDescription' => $contextDescription,
229 ];
230 } elseif ( $other instanceof ChangesListFilter ) {
231 $this->conflictingFilters[] = [
232 'group' => $other->getGroup()->getName(),
233 'filter' => $other->getName(),
234 'filterObject' => $other,
235 'globalDescription' => $globalDescription,
236 'contextDescription' => $contextDescription,
237 ];
238 } else {
239 throw new MWException( 'You can only pass in a ChangesListFilterGroup or a ChangesListFilter' );
240 }
241 }
242
252 public function setAsSupersetOf( ChangesListFilter $other ) {
253 if ( $other->getGroup() !== $this->getGroup() ) {
254 throw new MWException( 'Supersets can only be defined for filters in the same group' );
255 }
256
257 $this->subsetFilters[] = [
258 // It's always the same group, but this makes the representation
259 // more consistent with conflicts.
260 'group' => $other->getGroup()->getName(),
261 'filter' => $other->getName(),
262 ];
263 }
264
268 public function getName() {
269 return $this->name;
270 }
271
275 public function getGroup() {
276 return $this->group;
277 }
278
282 public function getLabel() {
283 return $this->label;
284 }
285
289 public function getDescription() {
290 return $this->description;
291 }
292
298 abstract public function displaysOnUnstructuredUi();
299
306 public function displaysOnStructuredUi() {
307 return $this->label !== null;
308 }
309
318 return $this->displaysOnStructuredUi();
319 }
320
324 public function getPriority() {
325 return $this->priority;
326 }
327
333 protected function getCssClass() {
334 if ( $this->cssClassSuffix !== null ) {
336 } else {
337 return null;
338 }
339 }
340
348 public function applyCssClassIfNeeded( IContextSource $ctx, RecentChange $rc, array &$classes ) {
349 if ( $this->isRowApplicableCallable === null ) {
350 return;
351 }
352
353 if ( call_user_func( $this->isRowApplicableCallable, $ctx, $rc ) ) {
354 $classes[] = $this->getCssClass();
355 }
356 }
357
365 public function getJsData() {
366 $output = [
367 'name' => $this->getName(),
368 'label' => $this->getLabel(),
369 'description' => $this->getDescription(),
370 'cssClass' => $this->getCssClass(),
371 'priority' => $this->priority,
372 'subset' => $this->subsetFilters,
373 'conflicts' => [],
374 'defaultHighlightColor' => $this->defaultHighlightColor
375 ];
376
377 $output['messageKeys'] = [
378 $this->getLabel(),
379 $this->getDescription(),
380 ];
381
382 $conflicts = array_merge(
383 $this->conflictingGroups,
384 $this->conflictingFilters
385 );
386
387 foreach ( $conflicts as $conflictInfo ) {
388 unset( $conflictInfo['filterObject'] );
389 unset( $conflictInfo['groupObject'] );
390 $output['conflicts'][] = $conflictInfo;
391 array_push(
392 $output['messageKeys'],
393 $conflictInfo['globalDescription'],
394 $conflictInfo['contextDescription']
395 );
396 }
397
398 return $output;
399 }
400
407 abstract public function isSelected( FormOptions $opts );
408
414 public function getConflictingGroups() {
415 return array_map(
416 function ( $conflictDesc ) {
417 return $conflictDesc[ 'groupObject' ];
418 },
420 );
421 }
422
428 public function getConflictingFilters() {
429 return array_map(
430 function ( $conflictDesc ) {
431 return $conflictDesc[ 'filterObject' ];
432 },
434 );
435 }
436
445 if ( $group->anySelected( $opts ) && $this->isSelected( $opts ) ) {
447 foreach ( $this->getSiblings() as $siblingFilter ) {
448 if ( $siblingFilter->isSelected( $opts ) && !$siblingFilter->hasConflictWithGroup( $group ) ) {
449 return false;
450 }
451 }
452 return true;
453 }
454 return false;
455 }
456
458 return in_array( $group, $this->getConflictingGroups() );
459 }
460
469 if ( $this->isSelected( $opts ) && $filter->isSelected( $opts ) ) {
471 foreach ( $this->getSiblings() as $siblingFilter ) {
472 if (
473 $siblingFilter->isSelected( $opts ) &&
474 !$siblingFilter->hasConflictWithFilter( $filter )
475 ) {
476 return false;
477 }
478 }
479 return true;
480 }
481 return false;
482 }
483
484 private function hasConflictWithFilter( ChangesListFilter $filter ) {
485 return in_array( $filter, $this->getConflictingFilters() );
486 }
487
493 protected function getSiblings() {
494 return array_filter(
495 $this->getGroup()->getFilters(),
496 function ( $filter ) {
497 return $filter !== $this;
498 }
499 );
500 }
501
506 $this->defaultHighlightColor = $defaultHighlightColor;
507 }
508}
no text was provided for refs named< code > blankwithnoreference</code ></span ></li ></ol ></div > !end !test with< references/> in group !wikitext Wikipedia rocks< ref > Proceeds of vol XXI</ref > Wikipedia rocks< ref group=note > Proceeds of vol XXI</ref >< references/>< references group=note/> ! html< p > Wikipedia rocks< sup id="cite_ref-1" class="reference">< a href="#cite_note-1"> &Wikipedia rocks< sup id="cite_ref-2" class="reference">< a href="#cite_note-2"> &</p >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-1">< span class="mw-cite-backlink">< a href="#cite_ref-1"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-2">< span class="mw-cite-backlink">< a href="#cite_ref-2"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div > !end !test with< references/> in group
Represents a filter group (used on ChangesListSpecialPage and descendants)
Represents a filter (used on ChangesListSpecialPage and descendants)
displaysOnUnstructuredUi()
Checks whether the filter should display on the unstructured UI.
$cssClassSuffix
CSS class suffix used for attribution, e.g.
getConflictingFilters()
Get filters conflicting with this filter.
getJsData()
Gets the JS data required by the front-end of the structured UI.
activelyInConflictWithGroup(ChangesListFilterGroup $group, FormOptions $opts)
Check if the conflict with a group is currently "active".
$conflictingGroups
Array of associative arrays with conflict information.
$conflictingFilters
Array of associative arrays with conflict information.
displaysOnStructuredUi()
Checks whether the filter should display on the structured UI This refers to the exact filter.
$label
i18n key of label for structured UI
setUnidirectionalConflict( $other, $globalDescription, $contextDescription)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
isFeatureAvailableOnStructuredUi()
Checks whether an equivalent feature for this filter is available on the structured UI.
applyCssClassIfNeeded(IContextSource $ctx, RecentChange $rc, array &$classes)
Add CSS class if needed.
setAsSupersetOf(ChangesListFilter $other)
Marks that the current instance is (also) a superset of the filter passed in.
$priority
Priority integer.
__construct(array $filterDefinition)
Creates a new filter with the specified configuration, and registers it to the specified group.
hasConflictWithGroup(ChangesListFilterGroup $group)
$subsetFilters
Array of associative arrays with subset information.
isSelected(FormOptions $opts)
Checks whether this filter is selected in the provided options.
setDefaultHighlightColor( $defaultHighlightColor)
$description
i18n key of description for structured UI
getConflictingGroups()
Get groups conflicting with this filter.
hasConflictWithFilter(ChangesListFilter $filter)
getCssClass()
Gets the CSS class.
getSiblings()
Get filters in the same group.
activelyInConflictWithFilter(ChangesListFilter $filter, FormOptions $opts)
Check if the conflict with a filter is currently "active".
$isRowApplicableCallable
Callable that returns true if and only if a row is attributed to this filter.
conflictsWith( $other, $globalKey, $forwardKey, $backwardKey)
Marks that the given ChangesListFilterGroup or ChangesListFilter conflicts with this object.
const CSS_CLASS_PREFIX
Helper class to keep track of options when mixing links and form elements.
MediaWiki exception.
Utility class for creating new RC entries.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2255
> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) name
Definition hooks.txt:1840
Interface for objects which can provide a MediaWiki context on request.