MediaWiki REL1_34
ConfirmEditHooks.php
Go to the documentation of this file.
1<?php
2
4
6 protected static $instanceCreated = false;
7
13 public static function getInstance() {
14 global $wgCaptcha, $wgCaptchaClass;
15
16 $class = $wgCaptchaClass;
17 if ( $class == null ) {
18 $class = 'SimpleCaptcha';
19 }
20 if ( !static::$instanceCreated ) {
21 static::$instanceCreated = true;
22 $wgCaptcha = new $class;
23 }
24
25 return $wgCaptcha;
26 }
27
37 public static function confirmEditMerged( $context, $content, $status, $summary, $user,
38 $minorEdit
39 ) {
40 return self::getInstance()->confirmEditMerged( $context, $content, $status, $summary,
41 $user, $minorEdit );
42 }
43
62 public static function onPageContentSaveComplete( WikiPage $wikiPage, User $user, Content $content,
63 $summary, $isMinor, $isWatch, $section, $flags, $revision, Status $status, $baseRevId
64 ) {
65 $title = $wikiPage->getTitle();
66 if ( $title->getText() === 'Captcha-ip-whitelist' && $title->getNamespace() === NS_MEDIAWIKI ) {
67 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
68 $cache->delete( $cache->makeKey( 'confirmedit', 'ipwhitelist' ) );
69 }
70
71 return true;
72 }
73
77 public static function confirmEditPage( EditPage $editpage ) {
78 self::getInstance()->editShowCaptcha( $editpage );
79 }
80
85 public static function showEditFormFields( $editPage, &$out ) {
86 self::getInstance()->showEditFormFields( $editPage, $out );
87 }
88
93 public static function injectEmailUser( &$form ) {
94 return self::getInstance()->injectEmailUser( $form );
95 }
96
105 public static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
106 return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
107 }
108
117 public static function onAPIGetAllowedParams( &$module, &$params, $flags = 1 ) {
118 return self::getInstance()->apiGetAllowedParams( $module, $params, $flags );
119 }
120
127 public static function onAuthChangeFormFields(
128 array $requests, array $fieldInfo, array &$formDescriptor, $action
129 ) {
130 self::getInstance()->onAuthChangeFormFields( $requests, $fieldInfo, $formDescriptor, $action );
131 }
132
133 public static function confirmEditSetup() {
134 // @codingStandardsIgnoreStart MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
135 global $wgCaptchaTriggers, $wgAllowConfirmedEmail,
136 $wgWikimediaJenkinsCI, $ceAllowConfirmedEmail;
137 // @codingStandardsIgnoreEnd
138
139 // There is no need to run (core) tests with enabled ConfirmEdit - bug T44145
140 if ( isset( $wgWikimediaJenkinsCI ) && $wgWikimediaJenkinsCI === true ) {
141 $wgCaptchaTriggers = array_fill_keys( array_keys( $wgCaptchaTriggers ), false );
142 }
143
144 // $ceAllowConfirmedEmail is deprecated and should be replaced by $wgAllowConfirmedEmail.
145 // For backward-compatibility, keep the value for some time. T162641
146 if ( isset( $ceAllowConfirmedEmail ) ) {
148 'Using $ceAllowConfirmedEmail is deprecated, ' .
149 'please migrate to $wgAllowConfirmedEmail as a replacement.' );
150 $wgAllowConfirmedEmail = $ceAllowConfirmedEmail;
151 }
152 }
153
161 public static function onTitleReadWhitelist( Title $title, User $user, &$whitelisted ) {
162 $image = SpecialPage::getTitleFor( 'Captcha', 'image' );
163 $help = SpecialPage::getTitleFor( 'Captcha', 'help' );
164 if ( $title->equals( $image ) || $title->equals( $help ) ) {
165 $whitelisted = true;
166 }
167 }
168
174 public static function onFancyCaptchaSetup() {
175 global $wgCaptchaDirectory, $wgUploadDirectory;
176 if ( !$wgCaptchaDirectory ) {
177 $wgCaptchaDirectory = "$wgUploadDirectory/captcha";
178 }
179 }
180
193 public static function onAlternateEditPreview( EditPage $editor, &$content, &$html, &$po ) {
194 $title = $editor->getTitle();
195 $exceptionTitle = Title::makeTitle( NS_MEDIAWIKI, 'Captcha-ip-whitelist' );
196
197 if ( !$title->equals( $exceptionTitle ) ) {
198 return true;
199 }
200
201 $ctx = $editor->getArticle()->getContext();
202 $out = $ctx->getOutput();
203 $lang = $ctx->getLanguage();
204
205 $lines = explode( "\n", $content->getNativeData() );
206 $html .= Html::rawElement(
207 'div',
208 [ 'class' => 'warningbox' ],
209 $ctx->msg( 'confirmedit-preview-description' )->parse()
210 ) .
211 Html::openElement(
212 'table',
213 [ 'class' => 'wikitable sortable' ]
214 ) .
215 Html::openElement( 'thead' ) .
216 Html::element( 'th', [], $ctx->msg( 'confirmedit-preview-line' )->text() ) .
217 Html::element( 'th', [], $ctx->msg( 'confirmedit-preview-content' )->text() ) .
218 Html::element( 'th', [], $ctx->msg( 'confirmedit-preview-validity' )->text() ) .
219 Html::closeElement( 'thead' );
220
221 foreach ( $lines as $count => $line ) {
222 $ip = trim( $line );
223 if ( $ip === '' || strpos( $ip, '#' ) !== false ) {
224 continue;
225 }
226 if ( IP::isIPAddress( $ip ) ) {
227 $validity = $ctx->msg( 'confirmedit-preview-valid' )->escaped();
228 $css = 'valid';
229 } else {
230 $validity = $ctx->msg( 'confirmedit-preview-invalid' )->escaped();
231 $css = 'notvalid';
232 }
233 $html .= Html::openElement( 'tr' ) .
234 Html::element(
235 'td',
236 [],
237 $lang->formatNum( $count + 1 )
238 ) .
239 Html::element(
240 'td',
241 [],
242 // IPv6 max length: 8 groups * 4 digits + 7 delimiter = 39
243 // + 11 chars for safety
244 $lang->truncateForVisual( $ip, 50 )
245 ) .
246 Html::rawElement(
247 'td',
248 // possible values:
249 // mw-confirmedit-ip-valid
250 // mw-confirmedit-ip-notvalid
251 [ 'class' => 'mw-confirmedit-ip-' . $css ],
252 $validity
253 ) .
254 Html::closeElement( 'tr' );
255 }
256 $html .= Html::closeElement( 'table' );
257 $out->addModuleStyles( 'ext.confirmEdit.editPreview.ipwhitelist.styles' );
258
259 return false;
260 }
261}
$wgUploadDirectory
The filesystem path of the images directory.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$line
Definition cdb.php:59
static onFancyCaptchaSetup()
Callback for extension.json of FancyCaptcha to set a default captcha directory, which depends on wgUp...
static injectEmailUser(&$form)
static confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit)
static showEditFormFields( $editPage, &$out)
static confirmEditPage(EditPage $editpage)
static confirmEmailUser( $from, $to, $subject, $text, &$error)
static onTitleReadWhitelist(Title $title, User $user, &$whitelisted)
TitleReadWhitelist hook handler.
static onAlternateEditPreview(EditPage $editor, &$content, &$html, &$po)
AlternateEditPreview hook handler.
static onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
static onPageContentSaveComplete(WikiPage $wikiPage, User $user, Content $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, Status $status, $baseRevId)
PageContentSaveComplete hook handler.
static onAPIGetAllowedParams(&$module, &$params, $flags=1)
APIGetAllowedParams hook handler Default $flags to 1 for backwards-compatible behavior.
static getInstance()
Get the global Captcha instance.
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition EditPage.php:46
MediaWikiServices is the service locator for the application scope of MediaWiki.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
Class representing a MediaWiki article and history.
Definition WikiPage.php:47
getTitle()
Get the title object of the article.
Definition WikiPage.php:298
const NS_MEDIAWIKI
Definition Defines.php:77
Base interface for content objects.
Definition Content.php:34
$context
Definition load.php:45
$cache
Definition mcc.php:33
$help
Definition mcc.php:32
$lines
Definition router.php:61
$content
Definition router.php:78
if(!isset( $args[0])) $lang