MediaWiki  1.29.1
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  if ( !static::$instanceCreated ) {
17  static::$instanceCreated = true;
18  $wgCaptcha = new $wgCaptchaClass;
19  }
20 
21  return $wgCaptcha;
22  }
23 
24  static function confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit ) {
25  return self::getInstance()->confirmEditMerged( $context, $content, $status, $summary,
26  $user, $minorEdit );
27  }
28 
48  $summary, $isMinor, $isWatch, $section, $flags, $revision, Status $status, $baseRevId
49  ) {
50  $title = $wikiPage->getTitle();
51  if ( $title->getText() === 'Captcha-ip-whitelist' && $title->getNamespace() === NS_MEDIAWIKI ) {
53  $cache->delete( $cache->makeKey( 'confirmedit', 'ipwhitelist' ) );
54  }
55 
56  return true;
57  }
58 
59  static function confirmEditPage( $editpage, $buttons, $tabindex ) {
60  self::getInstance()->editShowCaptcha( $editpage );
61  }
62 
63  static function showEditFormFields( &$editPage, &$out ) {
64  self::getInstance()->showEditFormFields( $editPage, $out );
65  }
66 
67  static function injectEmailUser( &$form ) {
68  return self::getInstance()->injectEmailUser( $form );
69  }
70 
71  static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
72  return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
73  }
74 
75  // Default $flags to 1 for backwards-compatible behavior
76  public static function APIGetAllowedParams( &$module, &$params, $flags = 1 ) {
77  return self::getInstance()->APIGetAllowedParams( $module, $params, $flags );
78  }
79 
80  public static function onAuthChangeFormFields(
81  array $requests, array $fieldInfo, array &$formDescriptor, $action
82  ) {
83  self::getInstance()->onAuthChangeFormFields( $requests, $fieldInfo, $formDescriptor, $action );
84  }
85 
89  public static function confirmEditSetup() {
90  // @codingStandardsIgnoreStart MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
91  global $wgCaptchaTriggers, $wgWikimediaJenkinsCI, $ceAllowConfirmedEmail,
92  $wgAllowConfirmedEmail;
93  // @codingStandardsIgnoreEnd
94 
95  // There is no need to run (core) tests with enabled ConfirmEdit - bug T44145
96  if ( isset( $wgWikimediaJenkinsCI ) && $wgWikimediaJenkinsCI === true ) {
97  $wgCaptchaTriggers = array_fill_keys( array_keys( $wgCaptchaTriggers ), false );
98  }
99 
100  // $ceAllowConfirmedEmail is deprecated and should be replaced by $wgAllowConfirmedEmail.
101  // For backward-compatibility, keep the value for some time. T162641
102  if ( isset( $ceAllowConfirmedEmail ) ) {
103  wfDeprecated(
104  'Using $ceAllowConfirmedEmail is deprecated, ' .
105  'please migrate to $wgAllowConfirmedEmail as a replacement.' );
106  $wgAllowConfirmedEmail = $ceAllowConfirmedEmail;
107  }
108  }
109 
117  public static function onTitleReadWhitelist( Title $title, User $user, &$whitelisted ) {
118  $image = SpecialPage::getTitleFor( 'Captcha', 'image' );
119  $help = SpecialPage::getTitleFor( 'Captcha', 'help' );
120  if ( $title->equals( $image ) || $title->equals( $help ) ) {
121  $whitelisted = true;
122  }
123  }
124 
130  public static function onFancyCaptchaSetup() {
131  global $wgCaptchaDirectory, $wgUploadDirectory;
132  if ( !$wgCaptchaDirectory ) {
133  $wgCaptchaDirectory = "$wgUploadDirectory/captcha";
134  }
135  }
136 
141  public static function onReCaptchaSetup() {
142  require_once ( __DIR__ . '/../ReCaptcha/recaptchalib.php' );
143  }
144 
149  public static function efReCaptcha() {
150  global $wgReCaptchaPublicKey, $wgReCaptchaPrivateKey;
151  // @codingStandardsIgnoreStart
152  global $recaptcha_public_key, $recaptcha_private_key;
153  // @codingStandardsIgnoreEnd
155 
156  // Backwards compatibility
157  if ( $wgReCaptchaPublicKey == '' ) {
158  $wgReCaptchaPublicKey = $recaptcha_public_key;
159  }
160  if ( $wgReCaptchaPrivateKey == '' ) {
161  $wgReCaptchaPrivateKey = $recaptcha_private_key;
162  }
163 
164  if ( $wgReCaptchaPublicKey == '' || $wgReCaptchaPrivateKey == '' ) {
165  die (
166  'You need to set $wgReCaptchaPrivateKey and $wgReCaptchaPublicKey in LocalSettings.php to ' .
167  "use the reCAPTCHA plugin. You can sign up for a key <a href='" .
168  htmlentities( recaptcha_get_signup_url( $wgServerName, "mediawiki" ) ) .
169  "'>here</a>."
170  );
171  }
172  }
173 
186  public static function onAlternateEditPreview( EditPage $editor, &$content, &$html, &$po ) {
187  $title = $editor->getTitle();
188  $exceptionTitle = Title::makeTitle( NS_MEDIAWIKI, 'Captcha-ip-whitelist' );
189 
190  if ( !$title->equals( $exceptionTitle ) ) {
191  return true;
192  }
193 
194  $ctx = $editor->getArticle()->getContext();
195  $out = $ctx->getOutput();
196  $lang = $ctx->getLanguage();
197 
198  $lines = explode( "\n", $content->getNativeData() );
200  'div',
201  [ 'class' => 'warningbox' ],
202  $ctx->msg( 'confirmedit-preview-description' )->parse()
203  ) .
205  'table',
206  [ 'class' => 'wikitable sortable' ]
207  ) .
208  Html::openElement( 'thead' ) .
209  Html::element( 'th', [], $ctx->msg( 'confirmedit-preview-line' )->text() ) .
210  Html::element( 'th', [], $ctx->msg( 'confirmedit-preview-content' )->text() ) .
211  Html::element( 'th', [], $ctx->msg( 'confirmedit-preview-validity' )->text() ) .
212  Html::closeElement( 'thead' );
213 
214  foreach ( $lines as $count => $line ) {
215  $ip = trim( $line );
216  if ( $ip === '' || strpos( $ip, '#' ) !== false ) {
217  continue;
218  }
219  if ( IP::isIPAddress( $ip ) ) {
220  $validity = $ctx->msg( 'confirmedit-preview-valid' )->escaped();
221  $css = 'valid';
222  } else {
223  $validity = $ctx->msg( 'confirmedit-preview-invalid' )->escaped();
224  $css = 'notvalid';
225  }
226  $html .= Html::openElement( 'tr' ) .
228  'td',
229  [],
230  $lang->formatNum( $count + 1 )
231  ) .
233  'td',
234  [],
235  // IPv6 max length: 8 groups * 4 digits + 7 delimiter = 39
236  // + 11 chars for safety
237  $lang->truncate( $ip, 50 )
238  ) .
240  'td',
241  // possible values:
242  // mw-confirmedit-ip-valid
243  // mw-confirmedit-ip-notvalid
244  [ 'class' => 'mw-confirmedit-ip-' . $css ],
245  $validity
246  ) .
247  Html::closeElement( 'tr' );
248  }
249  $html .= Html::closeElement( 'table' );
250  $out->addModuleStyles( 'ext.confirmEdit.editPreview.ipwhitelist.styles' );
251 
252  return false;
253  }
254 }
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
ConfirmEditHooks\onTitleReadWhitelist
static onTitleReadWhitelist(Title $title, User $user, &$whitelisted)
TitleReadWhitelist hook handler.
Definition: ConfirmEditHooks.php:117
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ConfirmEditHooks
Definition: ConfirmEditHooks.php:5
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1049
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:36
$params
$params
Definition: styleTest.css.php:40
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:82
ConfirmEditHooks\getInstance
static getInstance()
Get the global Captcha instance.
Definition: ConfirmEditHooks.php:13
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
ConfirmEditHooks\confirmEditPage
static confirmEditPage( $editpage, $buttons, $tabindex)
Definition: ConfirmEditHooks.php:59
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1956
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1128
$css
$css
Definition: styleTest.css.php:50
ConfirmEditHooks\confirmEmailUser
static confirmEmailUser( $from, $to, $subject, $text, &$error)
Definition: ConfirmEditHooks.php:71
$content
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1049
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:237
$tabindex
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff & $tabindex
Definition: hooks.txt:1398
$lines
$lines
Definition: router.php:67
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$editor
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error etc yourself modifying $error and returning true will cause the contents of $error to be echoed at the top of the edit form as wikitext Return true without altering $error to allow the edit to proceed & $editor
Definition: hooks.txt:1252
ConfirmEditHooks\confirmEditMerged
static confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit)
Definition: ConfirmEditHooks.php:24
$image
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
Definition: hooks.txt:783
ConfirmEditHooks\efReCaptcha
static efReCaptcha()
Extension function, moved from ReCaptcha.php when that was decimated.
Definition: ConfirmEditHooks.php:149
$line
$line
Definition: cdb.php:58
ConfirmEditHooks\onFancyCaptchaSetup
static onFancyCaptchaSetup()
Callback for extension.json of FancyCaptcha to set a default captcha directory, which depends on wgUp...
Definition: ConfirmEditHooks.php:130
$wgServerName
$wgServerName
Server name.
Definition: DefaultSettings.php:125
$wgUploadDirectory
$wgUploadDirectory
The filesystem path of the images directory.
Definition: DefaultSettings.php:266
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:47
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:42
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:82
Content
Base interface for content objects.
Definition: Content.php:34
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$cache
$cache
Definition: mcc.php:33
ConfirmEditHooks\showEditFormFields
static showEditFormFields(&$editPage, &$out)
Definition: ConfirmEditHooks.php:63
ObjectCache\getMainWANInstance
static getMainWANInstance()
Get the main WAN cache object.
Definition: ObjectCache.php:370
$section
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:2929
ConfirmEditHooks\APIGetAllowedParams
static APIGetAllowedParams(&$module, &$params, $flags=1)
Definition: ConfirmEditHooks.php:76
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ConfirmEditHooks\confirmEditSetup
static confirmEditSetup()
Set up $wgWhitelistRead.
Definition: ConfirmEditHooks.php:89
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
$requests
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead. & $feedLinks hooks can tweak the array to change how login etc forms should look $requests
Definition: hooks.txt:306
ConfirmEditHooks\onAlternateEditPreview
static onAlternateEditPreview(EditPage $editor, &$content, &$html, &$po)
AlternateEditPreview hook handler.
Definition: ConfirmEditHooks.php:186
$help
$help
Definition: mcc.php:32
ConfirmEditHooks\$instanceCreated
static $instanceCreated
Definition: ConfirmEditHooks.php:6
ConfirmEditHooks\injectEmailUser
static injectEmailUser(&$form)
Definition: ConfirmEditHooks.php:67
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:70
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
ConfirmEditHooks\onAuthChangeFormFields
static onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Definition: ConfirmEditHooks.php:80
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:50
ConfirmEditHooks\onReCaptchaSetup
static onReCaptchaSetup()
Callback for extension.json of ReCaptcha to require the recaptcha library php file.
Definition: ConfirmEditHooks.php:141
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2749
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:79
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:783