MediaWiki  master
EditConstraintFactory.php
Go to the documentation of this file.
1 <?php
22 
23 use Content;
24 use IContextSource;
32 use ReadOnlyMode;
33 use Title;
34 use User;
35 
44 
46  public const CONSTRUCTOR_OPTIONS = [
47  // PageSizeConstraint
48  'MaxArticleSize',
49  ];
50 
52  private $options;
53 
55  private $loggerFactory;
56 
59 
61  private $hookContainer;
62 
64  private $readOnlyMode;
65 
68 
88  public function __construct(
95  ) {
96  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
97 
98  // Multiple
99  $this->options = $options;
100  $this->loggerFactory = $loggerFactory;
101 
102  // UserBlockConstraint
103  $this->permissionManager = $permissionManager;
104 
105  // EditFilterMergedContentHookConstraint
106  $this->hookContainer = $hookContainer;
107 
108  // ReadOnlyConstraint
109  $this->readOnlyMode = $readOnlyMode;
110 
111  // SpamRegexConstraint
112  $this->spamRegexChecker = $spamRegexChecker;
113  }
114 
125  string $summary,
126  bool $minorEdit
129  $this->hookContainer,
130  $content,
131  $context,
132  $summary,
133  $minorEdit
134  );
135  }
136 
142  public function newPageSizeConstraint(
143  int $contentSize,
144  string $type
145  ): PageSizeConstraint {
146  return new PageSizeConstraint(
147  $this->options->get( 'MaxArticleSize' ),
148  $contentSize,
149  $type
150  );
151  }
152 
157  return new ReadOnlyConstraint(
158  $this->readOnlyMode
159  );
160  }
161 
169  string $input,
170  UserIdentity $user,
171  Title $title
173  return new SimpleAntiSpamConstraint(
174  $this->loggerFactory->getLogger( 'SimpleAntiSpam' ),
175  $input,
176  $user,
177  $title
178  );
179  }
180 
190  public function newSpamRegexConstraint(
191  string $summary,
192  string $section,
193  string $sectionHeading,
194  string $text,
195  string $reqIP,
196  Title $title
198  return new SpamRegexConstraint(
199  $this->loggerFactory->getLogger( 'SpamRegex' ),
200  $this->spamRegexChecker,
201  $summary,
202  $section,
203  $sectionHeading,
204  $text,
205  $reqIP,
206  $title
207  );
208  }
209 
215  public function newUserBlockConstraint(
217  User $user
219  return new UserBlockConstraint(
220  $this->permissionManager,
221  $title,
222  $user
223  );
224  }
225 
226 }
MediaWiki\EditPage\Constraint\EditConstraintFactory\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition: EditConstraintFactory.php:46
MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint
Verify simple anti spam measure of an extra hidden text field.
Definition: SimpleAntiSpamConstraint.php:34
MediaWiki\EditPage\Constraint\PageSizeConstraint
Verify the page isn't larger than the maximum.
Definition: PageSizeConstraint.php:36
MediaWiki\EditPage\Constraint\ReadOnlyConstraint
Verify site is not in read only mode.
Definition: ReadOnlyConstraint.php:33
MediaWiki\EditPage\Constraint\UserBlockConstraint
Verify user permissions: Must not be blocked from the page.
Definition: UserBlockConstraint.php:36
ReadOnlyMode
A service class for fetching the wiki's current read-only mode.
Definition: ReadOnlyMode.php:11
MediaWiki\EditPage\Constraint\EditConstraintFactory\$permissionManager
PermissionManager $permissionManager
Definition: EditConstraintFactory.php:58
MediaWiki\EditPage\Constraint\SpamRegexConstraint
Verify summary and text do not match spam regexes.
Definition: SpamRegexConstraint.php:35
MediaWiki\EditPage\Constraint\EditFilterMergedContentHookConstraint
Verify EditFilterMergedContent hook.
Definition: EditFilterMergedContentHookConstraint.php:37
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\EditPage\Constraint\EditConstraintFactory
Constraints reflect possible errors that need to be checked.
Definition: EditConstraintFactory.php:43
MediaWiki\EditPage\Constraint\EditConstraintFactory\$hookContainer
HookContainer $hookContainer
Definition: EditConstraintFactory.php:61
MediaWiki\EditPage\Constraint\EditConstraintFactory\newReadOnlyConstraint
newReadOnlyConstraint()
Definition: EditConstraintFactory.php:156
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:27
MediaWiki\EditPage\Constraint\EditConstraintFactory\$spamRegexChecker
SpamChecker $spamRegexChecker
Definition: EditConstraintFactory.php:67
MediaWiki\EditPage\Constraint\EditConstraintFactory\newPageSizeConstraint
newPageSizeConstraint(int $contentSize, string $type)
Definition: EditConstraintFactory.php:142
MediaWiki\EditPage\Constraint\EditConstraintFactory\newUserBlockConstraint
newUserBlockConstraint(LinkTarget $title, User $user)
Definition: EditConstraintFactory.php:215
MediaWiki\EditPage\Constraint\EditConstraintFactory\$loggerFactory
Spi $loggerFactory
Definition: EditConstraintFactory.php:55
$title
$title
Definition: testCompression.php:38
MediaWiki\EditPage\Constraint\EditConstraintFactory\newSpamRegexConstraint
newSpamRegexConstraint(string $summary, string $section, string $sectionHeading, string $text, string $reqIP, Title $title)
Definition: EditConstraintFactory.php:190
MediaWiki\EditPage\Constraint\EditConstraintFactory\$options
ServiceOptions $options
Definition: EditConstraintFactory.php:52
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:53
$content
$content
Definition: router.php:76
MediaWiki\EditPage\SpamChecker
Service to check if text (either content or a summary) qualifies as spam.
Definition: SpamChecker.php:14
MediaWiki\EditPage\Constraint\EditConstraintFactory\newSimpleAntiSpamConstraint
newSimpleAntiSpamConstraint(string $input, UserIdentity $user, Title $title)
Definition: EditConstraintFactory.php:168
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
MediaWiki\EditPage\Constraint\EditConstraintFactory\newEditFilterMergedContentHookConstraint
newEditFilterMergedContentHookConstraint(Content $content, IContextSource $context, string $summary, bool $minorEdit)
Definition: EditConstraintFactory.php:122
Content
Base interface for content objects.
Definition: Content.php:35
Title
Represents a title within MediaWiki.
Definition: Title.php:48
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
MediaWiki\EditPage\Constraint\EditConstraintFactory\__construct
__construct(ServiceOptions $options, Spi $loggerFactory, PermissionManager $permissionManager, HookContainer $hookContainer, ReadOnlyMode $readOnlyMode, SpamChecker $spamRegexChecker)
Some constraints have dependencies that need to be injected, this class serves as a factory for all o...
Definition: EditConstraintFactory.php:88
MediaWiki\EditPage\Constraint\EditConstraintFactory\$readOnlyMode
ReadOnlyMode $readOnlyMode
Definition: EditConstraintFactory.php:64
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
MediaWiki\Logger\Spi
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:38
MediaWiki\$context
IContextSource $context
Definition: MediaWiki.php:40
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:68
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition: ServiceOptions.php:71
$type
$type
Definition: testCompression.php:52