MediaWiki  1.34.0
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 ) ) {
147  wfDeprecated(
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 }
ConfirmEditHooks\onTitleReadWhitelist
static onTitleReadWhitelist(Title $title, User $user, &$whitelisted)
TitleReadWhitelist hook handler.
Definition: ConfirmEditHooks.php:161
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ConfirmEditHooks
Definition: ConfirmEditHooks.php:5
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:47
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:83
ConfirmEditHooks\getInstance
static getInstance()
Get the global Captcha instance.
Definition: ConfirmEditHooks.php:13
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
ConfirmEditHooks\confirmEmailUser
static confirmEmailUser( $from, $to, $subject, $text, &$error)
Definition: ConfirmEditHooks.php:105
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:298
EditPage\getArticle
getArticle()
Definition: EditPage.php:501
$lines
$lines
Definition: router.php:61
$title
$title
Definition: testCompression.php:34
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
ConfirmEditHooks\confirmEditMerged
static confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit)
Definition: ConfirmEditHooks.php:37
$line
$line
Definition: cdb.php:59
$content
$content
Definition: router.php:78
ConfirmEditHooks\onFancyCaptchaSetup
static onFancyCaptchaSetup()
Callback for extension.json of FancyCaptcha to set a default captcha directory, which depends on wgUp...
Definition: ConfirmEditHooks.php:174
ConfirmEditHooks\showEditFormFields
static showEditFormFields( $editPage, &$out)
Definition: ConfirmEditHooks.php:85
$wgUploadDirectory
$wgUploadDirectory
The filesystem path of the images directory.
Definition: DefaultSettings.php:256
ConfirmEditHooks\onPageContentSaveComplete
static onPageContentSaveComplete(WikiPage $wikiPage, User $user, Content $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, Status $status, $baseRevId)
PageContentSaveComplete hook handler.
Definition: ConfirmEditHooks.php:62
ConfirmEditHooks\confirmEditPage
static confirmEditPage(EditPage $editpage)
Definition: ConfirmEditHooks.php:77
ConfirmEditHooks\onAPIGetAllowedParams
static onAPIGetAllowedParams(&$module, &$params, $flags=1)
APIGetAllowedParams hook handler Default $flags to 1 for backwards-compatible behavior.
Definition: ConfirmEditHooks.php:117
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:46
$context
$context
Definition: load.php:45
Content
Base interface for content objects.
Definition: Content.php:34
Title
Represents a title within MediaWiki.
Definition: Title.php:42
$status
return $status
Definition: SyntaxHighlight.php:347
$cache
$cache
Definition: mcc.php:33
ConfirmEditHooks\confirmEditSetup
static confirmEditSetup()
Definition: ConfirmEditHooks.php:133
ConfirmEditHooks\onAlternateEditPreview
static onAlternateEditPreview(EditPage $editor, &$content, &$html, &$po)
AlternateEditPreview hook handler.
Definition: ConfirmEditHooks.php:193
EditPage\getTitle
getTitle()
Definition: EditPage.php:517
$help
$help
Definition: mcc.php:32
ConfirmEditHooks\$instanceCreated
static $instanceCreated
Definition: ConfirmEditHooks.php:6
ConfirmEditHooks\injectEmailUser
static injectEmailUser(&$form)
Definition: ConfirmEditHooks.php:93
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:68
ConfirmEditHooks\onAuthChangeFormFields
static onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Definition: ConfirmEditHooks.php:127
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:77