![Lu Liu](/assets/img/avatar_default.png)
Closes #1640. All Wikibase-dependent parameters, which were previously hard-coded for Wikidata, are now described in a JSON manifest. The manifest is currently constructed by hand, but, in the future, will hopefully be published by each Wikibase instance at a standard location. * setup the manifest framework * add dependency mechanism to scrutinizers & update tests * add json creators to constraint entities * adapt the backend (units tests are to be updated) * remove the call to prepareDependencies() in the constructor * update code according to review feedback * update scrutinizers tests * fix typo & update ConstraintsV1 * log if a scrutinizer is skipped * update versioning handling in the backend * correct the order of "actual" and "expected" for assertEquals method * use regex to check manifest versions * 1. add wikibase-manager.js, wikibase-dialog.js, etc. 2. move dialog/schema-alignment-dialog.js -> schema-alignment.js 3. remove unused schema-alignment-dialog.html 4. change most mentions of "Wikidata" to "Wikibase" * support saving cookies for different Wikibases & fix LoginCommandTest * fix schema related tests * removed unused WikibaseCredentials * include MediaWiki API endpoint in the schema * fetch language codes for different Wikibases * fix lgtm-bot alerts * keep a connection map (MediaWiki API endpoint => Connection) in ConnectionManager * simplify the constraint configurations of the manifest and remove lots of unnecessary code. * add slash to the end of mediawiki.root * add manifest schema and use ajv to validate the manifest * remove JSONP support (Wikibase manifest host should support CORS) * save manifests on manifest update * add unit tests for Manifest * include the exception in logger.error() method to make it easier to debug * include the message of ManifestException when calling respondError * test multiple connections * test no manifest & test invalid manifest * adapt manage-account-dialog.js to support multiple Wikibase connections * update instance/subclass of related translations * beautify import-schema-dialog.html * use "${lang}" variable in the reconciliation service endpoint of the manifest * adapt schema-alignment.js after introducing "${lang}" variable in the reconciliation service endpoint * use WikibaseManager.getSelectedWikibaseApi() in SchemaAlignment._getPropertyType * replace more mentions of "Wikidata" to "Wikibase" * use WikibaseManager.getSelectedWikibaseApi() in previewrenderer.js * support fetching language codes of different Wikibases in the frontend * skip EditInspector if missing 'property_constraint_pid' in the manifest * improve unit tests for fetching lang codes * skip scrutinizers depending on fetcher if 'property_constraint_pid' is missing in the manifest * make sure the schema alignment panel is set up before rendering * fix preview bug * add getters of "instance of" and "subclass of" to the Manifest interface and use them in NewItemScrutinizer * fix hardcode for Wikidata in WbItemVariable * rename 'entity_prefix' to 'site_iri' and move it from 'manifest.wikibase.properties' to 'manifest.wikibase' * include oauth configurations in the manifest & support logging in with owner-only consumer for Wikibases with the OAuth extension * correct schema fallback logic * select default wikibase according to the saved schema * include maxlag in the manifest * [backend] move maxlag setting from preferences to request parameter * support setting maxlag when uploading edits * rename "Manage Wikibase" to "Select Wikibase instance" and localize it * fix manifest updating bug * include EditGroups in the manifest * add the reconciliation service from the manifest to standard services if it's not present yet when adding a new manifest * update according to review feedback 1. use inherited color variable 2. rename 'gridwroks' to 'openrefine' 3. remove unnecessary 'async: true' 4. add 'format: url' validation to urls to the schema * rename 'wikibasePrefix' to 'siteIri'
142 lines
4.5 KiB
JavaScript
142 lines
4.5 KiB
JavaScript
var PerformEditsDialog = {};
|
|
|
|
PerformEditsDialog.launch = function(logged_in_username, max_severity) {
|
|
var self = this;
|
|
var elmts = this._elmts;
|
|
var frame = this.frame;
|
|
|
|
if (this.missingSchema) {
|
|
return;
|
|
}
|
|
|
|
this._level = DialogSystem.showDialog(frame);
|
|
this._elmts.dialogHeader.text($.i18n('perform-wikibase-edits/dialog-header', WikibaseManager.getSelectedWikibaseName()));
|
|
this._elmts.loggedInAs.text($.i18n('perform-wikibase-edits/logged-in-as'));
|
|
this._elmts.editSummaryLabel.text($.i18n('perform-wikibase-edits/edit-summary-label'));
|
|
this._elmts.editSummary.attr('placeholder', $.i18n('perform-wikibase-edits/edit-summary-placeholder'));
|
|
this._elmts.maxlagLabel.text($.i18n('perform-wikibase-edits/maxlag-label'));
|
|
this._elmts.maxlag.val(WikibaseManager.getSelectedWikibaseMaxlag());
|
|
this._elmts.maxlag.attr('placeholder', WikibaseManager.getSelectedWikibaseMaxlag());
|
|
this._elmts.explainMaxlag.html($.i18n('perform-wikibase-edits/explain-maxlag'));
|
|
this._elmts.performEditsButton.text($.i18n('perform-wikibase-edits/perform-edits'));
|
|
this._elmts.cancelButton.text($.i18n('perform-wikibase-edits/cancel'));
|
|
|
|
var hiddenIframe = $('#hiddenIframe').contents();
|
|
|
|
var dismiss = function() {
|
|
DialogSystem.dismissUntil(self._level - 1);
|
|
};
|
|
|
|
|
|
var doFormSubmit = function() {
|
|
hiddenIframe.find('body').append(elmts.performEditsForm.clone());
|
|
var formCopy = hiddenIframe.find("#wikibase-perform-edits-form");
|
|
formCopy.submit();
|
|
|
|
if (elmts.editSummary.val().length === 0) {
|
|
elmts.editSummary.focus();
|
|
return;
|
|
}
|
|
|
|
if (elmts.maxlag.val().length === 0) {
|
|
elmts.maxlag.val(WikibaseManager.getSelectedWikibaseMaxlag());
|
|
}
|
|
|
|
// validate maxlag
|
|
if (!/^\+?[1-9]\d*$/.test(elmts.maxlag.val())) {
|
|
elmts.maxlag.focus();
|
|
alert($.i18n('perform-wikibase-edits/maxlag-validation'));
|
|
return;
|
|
}
|
|
|
|
Refine.postProcess(
|
|
"wikidata",
|
|
"perform-wikibase-edits",
|
|
{},
|
|
{ summary: elmts.editSummary.val(), maxlag: elmts.maxlag.val() },
|
|
{ includeEngine: true, cellsChanged: true, columnStatsChanged: true },
|
|
{ onDone: function() { dismiss(); } }
|
|
);
|
|
};
|
|
|
|
elmts.loggedInUsername
|
|
.text(logged_in_username)
|
|
.attr('href', WikibaseManager.getSelectedWikibaseRoot() + 'User:' + logged_in_username);
|
|
|
|
frame.find('.cancel-button').click(function() {
|
|
dismiss();
|
|
});
|
|
|
|
this._elmts.editSummary.keypress(function (evt) {
|
|
if (evt.which === 13) {
|
|
doFormSubmit();
|
|
evt.preventDefault();
|
|
}
|
|
});
|
|
|
|
if (max_severity === 'CRITICAL') {
|
|
elmts.performEditsButton.prop("disabled",true).addClass("button-disabled");
|
|
} else {
|
|
elmts.performEditsButton.click(function() {
|
|
doFormSubmit();
|
|
});
|
|
}
|
|
};
|
|
|
|
PerformEditsDialog.updateEditCount = function(edit_count) {
|
|
this._elmts.reviewYourEdits.html($.i18n('perform-wikibase-edits/review-your-edits',
|
|
edit_count,
|
|
WikibaseManager.getSelectedWikibaseMainPage(),
|
|
WikibaseManager.getSelectedWikibaseName(),
|
|
));
|
|
};
|
|
|
|
PerformEditsDialog._updateWarnings = function(data) {
|
|
var warnings = data.warnings;
|
|
var mainDiv = this._elmts.warningsArea;
|
|
|
|
// clear everything
|
|
mainDiv.empty();
|
|
PerformEditsDialog.updateEditCount(data.edit_count);
|
|
|
|
var table = $('<table></table>').appendTo(mainDiv);
|
|
for (var i = 0; i < warnings.length; i++) {
|
|
var rendered = WarningsRenderer._renderWarning(warnings[i]);
|
|
rendered.appendTo(table);
|
|
}
|
|
};
|
|
|
|
PerformEditsDialog.checkAndLaunch = function () {
|
|
this.frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/perform-edits-dialog.html"));
|
|
this._elmts = DOM.bind(this.frame);
|
|
this.missingSchema = false;
|
|
|
|
var onSaved = function () {
|
|
ManageAccountDialog.ensureLoggedIn(function (logged_in_username) {
|
|
var discardWaiter = DialogSystem.showBusy($.i18n('perform-wikibase-edits/analyzing-edits'));
|
|
Refine.postCSRF(
|
|
"command/wikidata/preview-wikibase-schema?" + $.param({project: theProject.id}),
|
|
{manifest: JSON.stringify(WikibaseManager.getSelectedWikibase()), engine: JSON.stringify(ui.browsingEngine.getJSON())},
|
|
function (data) {
|
|
discardWaiter();
|
|
if (data['code'] !== 'error') {
|
|
PerformEditsDialog._updateWarnings(data);
|
|
PerformEditsDialog.launch(logged_in_username, data['max_severity']);
|
|
} else {
|
|
SchemaAlignment.launch();
|
|
}
|
|
},
|
|
"json"
|
|
);
|
|
});
|
|
};
|
|
|
|
|
|
if (SchemaAlignment.isSetUp() && SchemaAlignment._hasUnsavedChanges) {
|
|
SchemaAlignment._save(onSaved);
|
|
} else {
|
|
onSaved();
|
|
}
|
|
|
|
};
|