10use WikimediaEvents\WikimediaEventsHooks;
30 global $wgWMESchemaEditAttemptStepSamplingRate;
31 $extensionRegistry = ExtensionRegistry::getInstance();
32 if ( !$extensionRegistry->isLoaded(
'EventLogging' ) ) {
36 $samplingRate = $wgWMESchemaEditAttemptStepSamplingRate ?? 0.0625;
37 $inSample = EventLogging::sessionInSample(
38 (
int)( 1 / $samplingRate ), $data[
'editing_session_id']
40 $shouldOversample = $extensionRegistry->isLoaded(
'WikimediaEvents' ) &&
41 WikimediaEventsHooks::shouldSchemaEditAttemptStepOversample( $article->getContext() );
42 if ( !$inSample && !$shouldOversample ) {
46 $user = $article->getContext()->getUser();
47 $page = $article->getPage();
48 $title = $article->getTitle();
49 $revisionRecord = $page->getRevisionRecord();
54 'is_oversample' => !$inSample,
55 'editor_interface' =>
'wikitext',
56 'platform' =>
'desktop',
57 'integration' =>
'page',
58 'page_id' => $page->getId(),
59 'page_title' =>
$title->getPrefixedText(),
60 'page_ns' =>
$title->getNamespace(),
61 'revision_id' => $revisionRecord ? $revisionRecord->getId() : 0,
62 'user_id' => $user->getId(),
63 'user_editcount' => $user->getEditCount() ?: 0,
67 if ( $user->isAnon() ) {
68 $data[
'user_class'] =
'IP';
71 return EventLogging::logEvent(
'EditAttemptStep', 18530416, $data );
88 $request = $article->getContext()->getRequest();
91 $user = $article->getContext()->getUser();
92 if ( $user->getOption(
'usebetatoolbar' ) ) {
100 if ( ExtensionRegistry::getInstance()->isLoaded(
'EventLogging' ) && !$request->wasPosted() ) {
103 if ( $request->getVal(
'section' ) ) {
104 $data[
'init_type'] =
'section';
106 $data[
'init_type'] =
'page';
108 if ( $request->getHeader(
'Referer' ) ) {
110 $request->getVal(
'section' ) ===
'new'
111 || !$article->getPage()->exists()
113 $data[
'init_mechanism'] =
'new';
115 $data[
'init_mechanism'] =
'click';
118 $data[
'init_mechanism'] =
'url';
141 $shouldOversample = ExtensionRegistry::getInstance()->isLoaded(
'WikimediaEvents' ) &&
142 WikimediaEventsHooks::shouldSchemaEditAttemptStepOversample( $outputPage->
getContext() );
149 'name' =>
'editingStatsId',
150 'id' =>
'editingStatsId',
151 'value' => $editingStatsId
156 if ( $shouldOversample ) {
162 'name' =>
'editingStatsOversample',
163 'id' =>
'editingStatsOversample',
181 $defaultPreferences[
'usebetatoolbar'] = [
183 'label-message' =>
'wikieditor-toolbar-preference',
184 'help-message' =>
'wikieditor-toolbar-preference-help',
185 'section' =>
'editing/editor',
215 $msg = $ml->
msg(
'sig-text' )->params(
'~~~~' )->inContentLanguage();
216 return $raw ? $msg->plain() : $msg->text();
224 $requiredMagicWords = [
235 $factory = MediaWikiServices::getInstance()->getMagicWordFactory();
236 foreach ( $requiredMagicWords as $name ) {
237 $magicWords[$name] = $factory->get( $name )->getSynonym( 0 );
248 $fromRequest = $request->
getVal(
'editingStatsId' );
249 if ( $fromRequest ) {
252 if ( !self::$statsId ) {
265 $request = $article->getContext()->getRequest();
266 if ( $request->getVal(
'editingStatsId' ) ) {
270 [
'editing_session_id' => $request->getVal(
'editingStatsId' ) ]
283 $request = $article->getContext()->getRequest();
284 if ( $request->getVal(
'editingStatsId' ) ) {
286 $data[
'editing_session_id'] = $request->getVal(
'editingStatsId' );
288 if ( $status->
isOK() ) {
289 $action =
'saveSuccess';
291 $action =
'saveFailure';
294 if ( isset( $errors[0][0] ) ) {
295 $data[
'save_failure_message'] = $errors[0][0];
298 $wikiPage = $editPage->
getArticle()->getPage();
300 $data[
'save_failure_type'] =
'editConflict';
302 $data[
'save_failure_type'] =
'editPageDeleted';
303 } elseif ( isset( $errors[0][0] ) && $errors[0][0] ===
'abusefilter-disallowed' ) {
304 $data[
'save_failure_type'] =
'extensionAbuseFilter';
305 } elseif ( isset( $wikiPage->ConfirmEdit_ActivateCaptcha ) ) {
307 $data[
'save_failure_type'] =
'extensionCaptcha';
308 } elseif ( isset( $errors[0][0] ) && $errors[0][0] ===
'spam-blacklisted-link' ) {
309 $data[
'save_failure_type'] =
'extensionSpamBlacklist';
313 $data[
'save_failure_type'] =
'responseUnknown';
const MW_VERSION
The running version of MediaWiki.
getContext()
Get the base IContextSource object.
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
This is one of the Core classes and should be read at least once by any new developers.
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.
addHTML( $text)
Append $text to the body HTML.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
Context object that contains information about the state of a specific ResourceLoader web request.
isOK()
Returns whether the operation completed.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrorsArray()
Get the list of errors (but not warnings)
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
getVal( $name, $default=null)
Fetch a scalar from the input or return $default if it's not set.
static editPageShowEditFormInitial(EditPage $editPage, OutputPage $outputPage)
EditPage::showEditForm:initial hook.
static editPageAttemptSave(EditPage $editPage)
This is attached to the MediaWiki 'EditPage::attemptSave' hook.
static getMagicWords()
Expose useful magic words which are used by the wikieditor toolbar.
static getModuleData(ResourceLoaderContext $context, Config $config)
static getEditingStatsId(WebRequest $request)
Gets a 32 character alphanumeric random string to be used for stats.
static getSignatureMessage(MessageLocalizer $ml, $raw=false)
static editPageAttemptSaveAfter(EditPage $editPage, Status $status)
This is attached to the MediaWiki 'EditPage::attemptSave:after' hook.
static getModuleDataSummary(ResourceLoaderContext $context, Config $config)
static getPreferences( $user, &$defaultPreferences)
GetPreferences hook.
static editPageShowEditFormFields(EditPage $editPage, OutputPage $outputPage)
EditPage::showEditForm:fields hook.
static doEventLogging( $action, $article, $data=[])
Log stuff to EventLogging's Schema:EditAttemptStep - see https://meta.wikimedia.org/wiki/Schema:EditA...
const CONTENT_MODEL_WIKITEXT
Interface for configuration instances.
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
const AS_ARTICLE_WAS_DELETED
Status: article was deleted while editing and wpRecreate == false or form was not posted.
Interface for localizing messages in MediaWiki.
msg( $key,... $params)
This is the method for getting translated interface messages.