Tpt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/295716
Change subject: Makes VE -> Wikieditor switch work
..
Makes VE -> Wikieditor switch work
Adds a simple Wikitext serialization parser
We should probably move to an API call in the future (see
Id34b2c10bbf0cb23643b3b300e3182a4a12c9933 )
Change-Id: I315468a493ba1c770bd1d1fd89e883e9bb5ab53f
---
M modules/ve/pageTarget/ve.init.mw.ProofreadPagePageTarget.js
1 file changed, 69 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage
refs/changes/16/295716/1
diff --git a/modules/ve/pageTarget/ve.init.mw.ProofreadPagePageTarget.js
b/modules/ve/pageTarget/ve.init.mw.ProofreadPagePageTarget.js
index 40baa84..3741282 100644
--- a/modules/ve/pageTarget/ve.init.mw.ProofreadPagePageTarget.js
+++ b/modules/ve/pageTarget/ve.init.mw.ProofreadPagePageTarget.js
@@ -138,6 +138,75 @@
};
/**
+ * @inheritdoc
+ */
+ve.init.mw.ProofreadPagePageTarget.prototype.submit = function ( wikitext,
fields ) {
+ var key, $form, params, content;
+
+ // Prevent duplicate requests
+ if ( this.submitting ) {
+ return false;
+ }
+ // Save DOM
+ this.submitting = true;
+ content = this.parseWikitext( wikitext );
+ $form = $( '' );
+ params = ve.extendObject( {
+ format: 'text/x-wiki',
+ model: 'proofread-page',
+ oldid: this.requestedRevId,
+ wpStarttime: this.startTimeStamp,
+ wpEdittime: this.baseTimeStamp,
+ wpHeaderTextbox: content.header,
+ wpTextbox1: content.body,
+ wpFooterTextbox: content.footer,
+ wpQuality: content.level.level,
+ wpEditToken: this.editToken
+ }, fields );
+ // Add params as hidden fields
+ for ( key in params ) {
+ $form.append( $( '' ).attr( { type: 'hidden', name: key,
value: params[ key ] } ) );
+ }
+ // Submit the form, mimicking a traditional edit
+ // Firefox requires the form to be attached
+ $form.attr( 'action', this.submitUrl ).appendTo( 'body' ).submit();
+ return true;
+};
+
+/**
+ * Parse Wikitext into the JSON serialization
+ */
+ve.init.mw.ProofreadPagePageTarget.prototype.parseWikitext = function (
wikitext ) {
+ var structureMatchResult, headerMatchResult, result = {
+ header: '',
+ body: '',
+ footer: '',
+ level: {
+ level: 1,
+ user: null
+ }
+ };
+
+ structureMatchResult = wikitext.match(
/^([\s\S]*)\n*<\/noinclude>([\s\S]*)([\s\S]*)<\/noinclude>$/
);
+ if ( structureMatchResult === null ) {
+ result.body = wikitext;
+ return result;
+ }
+ result.body = structureMatchResult[ 2 ];
+ result.footer = structureMatchResult[ 3 ];
+
+ headerMatchResult = structureMatchResult[ 1 ].match( /^|> *<\/pagequality>)([\s\S]*)$/ );
+ if ( headerMatchResult === null ) {
+ result.header = structureMatchResult[ 1 ];
+ return result;
+ }
+ result.level.level = parseInt( headerMatchResult[ 1 ] );
+ result.level.user = headerMatchResult[ 2 ];
+ result.header = headerMatchResult[ 4 ];
+ return result;
+};
+
+/**
* Split a document into balanced header, body and footer sections
*
* @param {HTMLDocument} doc Document
--
To view, visit https://gerrit.wikimedia.org/r/295716
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I315468a493ba1c770bd1d1fd89e883e9bb5ab53f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Tpt
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits