Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F31672291
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
awight
Mar 9 2020, 6:03 AM
2020-03-09 06:03:30 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
/**
* User script to replay conflicts.
*
* The conflicting edit text is stored under a special title like,
* Conflict:<title>/<base_revision_id>/<conflict_sequence>
* Where the placeholders are, the page title where the conflict occurred, the base revision ID that was being edited,
* and a 1-based sequence which is ignored for now, and lets multiple conflicts share the same base revision.
*
* TODO:
* - User input for the edit summary.
* - Controls to do advanced things like tweaking the branchpoint and choosing an "other" edit other than
* the target page's latest revision.
* - Proper namespace for these pages.
*/
mw.loader.using( [
'mediawiki.api',
'moment',
'oojs-ui-core'
] ).done( function () {
$( function () {
// TODO: The regex is missing the start anchor "^" so that it can be used as a subpage in various places,
// until the Conflict namespace exists.
var conflictTitleParams = /Conflict:(.*)\/(\d+)\/(\d+)$/.exec( mw.config.get('wgPageName' ) );
if ( conflictTitleParams !== null ) {
var baseTitle = conflictTitleParams[1],
baseRevisionId = conflictTitleParams[2] /*,
conflictSequence = conflictTitleParams[3] */;
var form = new OO.ui.FormLayout( {
// TODO: urlencode the title, or build the query using a helper.
action: mw.config.get('wgScript' ) + '?title=' + baseTitle + '&action=submit',
method: 'post'
} );
form.addItems( [
new OO.ui.FieldsetLayout( {
label: 'Conflict',
items: [
new OO.ui.ButtonWidget( {
label: 'Recreate conflict',
title: 'Submit',
} ).on( 'click', function () {
// TODO: clean up binding
form.$element.submit();
} )
]
} )
] );
var postFields = {
wpUnicodeCheck: 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ',
editRevId: baseRevisionId,
parentRevId: baseRevisionId,
// TODO: stored / input / automatic summary field.
//wpSummary: '',
wpSave: 'Save changes',
mode: 'text',
wpUltimateParam: '1',
};
var api = new mw.Api();
Promise.all( [
api.getEditToken().then(
function ( editToken ) {
postFields.wpEditToken = editToken;
}
),
// Pull content from the conflict page.
api.get( {
action: 'query',
prop: 'revisions',
revids: mw.config.get( 'wgCurRevisionId' ),
rvprop: 'content'
} ).then(
function ( data ) {
for ( var pageId in data.query.pages ) {
for ( var index in data.query.pages[pageId].revisions ) {
var revision = data.query.pages[pageId].revisions[index];
postFields.wpTextbox1 = revision['*'];
postFields.format = revision.contentformat;
postFields.model = revision.contentmodel;
return;
}
}
}
),
// Get timestamp of the original base revision, to convince EditPage we need to conflict.
// Edit time turns out to be important, conflict cannot be triggered without it!
api.get( {
action: 'query',
prop: 'revisions',
revids: baseRevisionId,
rvprop: 'timestamp'
} ).then(
function ( data ) {
for ( var pageId in data.query.pages ) {
for ( var index in data.query.pages[pageId].revisions ) {
var revision = data.query.pages[pageId].revisions[index];
// FIXME: date conversion from a library
postFields.wpEdittime = moment( revision.timestamp ).format( 'YYYYMMDDHHmmss' );
return;
}
}
}
)
] ).then(
function ( ) {
var keys = Object.keys( postFields );
for ( var i = 0; i < keys.length; i++ ) {
form.addItems( [
new OO.ui.HiddenInputWidget( {
name: keys[i],
value: postFields[keys[i]],
} )
] );
}
$( '#bodyContent' ).prepend( form.$element );
}
);
}
});
});
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8346186
Default Alt Text
raw.txt (3 KB)
Attached To
Mode
P10653 User script to replay conflicts
Attached
Detach File
Event Timeline
Log In to Comment