Surlycyborg has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/355612 )
Change subject: WIP: Warn users when trying to insert "bad" URLs in references.
......................................................................
WIP: Warn users when trying to insert "bad" URLs in references.
Bug: T166296
Change-Id: Idd373321696124da2f3d3ec4fb0b3d287d877e4f
---
M modules/ve.ui.CiteFromIdInspector.js
M modules/ve.ui.CiteFromIdReferenceWidget.js
2 files changed, 74 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Citoid
refs/changes/12/355612/1
diff --git a/modules/ve.ui.CiteFromIdInspector.js
b/modules/ve.ui.CiteFromIdInspector.js
index 78c8bf1..9ada43b 100644
--- a/modules/ve.ui.CiteFromIdInspector.js
+++ b/modules/ve.ui.CiteFromIdInspector.js
@@ -1,3 +1,25 @@
+var kFakeSearchResults = [
+ {
+ "itemType": "blogPost",
+ "notes": [],
+ "tags": [],
+ "title": "Wikipedia",
+ "rights": "Creative Commons Attribution-ShareAlike License",
+ "encyclopediaTitle": "Wikipedia",
+ "url":
"https://en.wikipedia.org/w/index.php?title=Wikipedia&oldid=781479175",
+ "extra": "Page Version ID: 781479175",
+ "language": "en",
+ "date": "2017-05-21",
+ "abstractNote": "Wikipedia (/ˌwɪkᵻˈpiːdiə/ or /ˌwɪkiˈpiːdiə/
WIK-i-PEE-dee-ə) is a free online encyclopedia with the aim to allow anyone to
edit articles. Wikipedia is the largest and most popular general reference work
on the Internet and is ranked among the ten most popular websites. Wikipedia is
owned by the nonprofit Wikimedia Foundation.\nWikipedia was launched on January
15, 2001, by Jimmy Wales and Larry Sanger. Sanger coined its name, a
portmanteau of wiki and encyclopedia. There was only the English language
version initially, but it quickly developed similar versions in other
languages, which differ in content and in editing practices. With 5,412,377
articles, the English Wikipedia is the largest of the more than 290 Wikipedia
encyclopedias. Overall, Wikipedia consists of more than 40 million articles in
more than 250 different languages and, as of February 2014, it had 18 billion
page views and nearly 500 million unique visitors each month.\nAs of March
2017, Wikipedia has about forty thousand high-quality articles known as
Featured Articles and Good Articles that cover vital topics. In 2005, Nature
published a peer review comparing 42 science articles from Encyclopædia
Britannica and Wikipedia, and found that Wikipedia's level of accuracy
approached Encyclopædia Britannica's. Criticism of Wikipedia includes claims
that it exhibits systemic bias, presents a mixture of \"truths, half truths,
and some falsehoods\", and that, in controversial topics, it is subject to
manipulation and spin.",
+ "libraryCatalog": "Wikipedia",
+ "accessDate": "2017-05-25",
+ "source": [
+ "Zotero",
+ "Zotero"
+ ]
+ }
+]
+
/**
* Inspector to insert filled references using citoid service
*
@@ -590,20 +612,23 @@
// a proper xhr object with "abort" method, so we can
// hand off this abort method to the jquery promise
- if ( this.fullRestbaseUrl ) {
- // Use restbase endpoint
- this.serviceConfig.ajax.url = this.serviceUrl + '/' +
encodeURIComponent( search );
- xhr = new mw.Api( this.serviceConfig ).get();
- } else {
- // Use standalone citoid service
- xhr = this.service
- .get( {
- search: search,
- format: ve.ui.CiteFromIdInspector.static.citoidFormat
- } );
+ if (false) {
+ if ( this.fullRestbaseUrl ) {
+ // Use restbase endpoint
+ this.serviceConfig.ajax.url = this.serviceUrl + '/' +
encodeURIComponent( search );
+ xhr = new mw.Api( this.serviceConfig ).get();
+ } else {
+ // Use standalone citoid service
+ xhr = this.service
+ .get( {
+ search: search,
+ format:
ve.ui.CiteFromIdInspector.static.citoidFormat
+ } );
+ }
}
- this.lookupPromise = xhr
+ var fakexhr = $.Deferred()
+ this.lookupPromise = fakexhr
.then(
// Success
function ( searchResults ) {
@@ -632,8 +657,10 @@
.focus()
.popPending();
inspector.lookupButton.setDisabled( false );
- } )
- .promise( { abort: xhr.abort } );
+ } );
+ setTimeout(function() {
+ fakexhr.resolve(kFakeSearchResults);
+ }, 100);
return this.lookupPromise;
};
@@ -678,7 +705,8 @@
templateName: templateName,
template: null,
source: citation.source, // May be undefined or Array
- transclusionModel: new ve.dm.MWTransclusionModel()
+ transclusionModel: new ve.dm.MWTransclusionModel(),
+ badSourceWarning: false,
} );
result = this.results[ this.results.length - 1 ];
@@ -688,6 +716,7 @@
result.transclusionModel.addPart( result.template )
// Fill in the details for the individual
template
.then(
ve.ui.CiteFromIdInspector.static.populateTemplate.bind( this, result.template,
citation ) )
+ .then( function(badSourceWarning) {
result.badSourceWarning = badSourceWarning; } )
);
}
@@ -703,6 +732,7 @@
inspector.results[ i
].transclusionModel,
{
data: i,
+ warning: true,
templateName:
inspector.results[ i ].templateName,
citeTools: inspector.citeTools
} );
@@ -740,8 +770,10 @@
/**
* Fills template object parameters with values from the citation object
*
- * @param {ve.dm.MNTemplateModel} template A template model to fill
+ * @param {ve.dm.MWTemplateModel} template A template model to fill
* @param {Object} citation An object that contains values to insert into
template
+ * @return {boolean} whether this template contains a potentially bad citation
+ * URL that we should warn about.
*/
ve.ui.CiteFromIdInspector.static.populateTemplate = function ( template,
citation ) {
var citoidField, templateField, i, j,
@@ -749,7 +781,8 @@
concat2dField, // for storing elements of a 2d array converted
to a 1d element
spec = template.getSpec(),
maps = spec.getMaps(),
- map = maps[ ve.ui.CiteFromIdInspector.static.templateDataName ];
+ map = maps[ ve.ui.CiteFromIdInspector.static.templateDataName ],
+ badSourceWarning = false;
for ( citoidField in map ) {
templateField = map[ citoidField ];
@@ -759,6 +792,15 @@
// Case: Citoid parameter directly equivalent to TemplateData
parameter
if ( typeof templateField === 'string' && citation[ citoidField
] && typeof citation[ citoidField ] === 'string' ) {
+ if ( spec.getParameterType(templateField) === 'url' ) {
+ // While permitted in some cases, it's usually
a bad idea to use
+ // Wikipedia as a reference within Wikipedia
itself, so warn if
+ // that's the case.
+ var urlParser = $('<a>', {'href': citation[
citoidField ]})[0];
+ if ( urlParser.hostname.match(
/\.wikipedia\.org$/ ) ) {
+ badSourceWarning = true;
+ }
+ }
template.addParameter(
new ve.dm.MWParameterModel(
template, templateField, citation[
citoidField ]
@@ -844,6 +886,7 @@
}
}
}
+ return badSourceWarning;
};
/* Registration */
diff --git a/modules/ve.ui.CiteFromIdReferenceWidget.js
b/modules/ve.ui.CiteFromIdReferenceWidget.js
index 5ea9280..71bb849 100644
--- a/modules/ve.ui.CiteFromIdReferenceWidget.js
+++ b/modules/ve.ui.CiteFromIdReferenceWidget.js
@@ -9,10 +9,11 @@
* @param {ve.dm.MWTransclusionModel} transclusionModel Transclusion model
used for this template
* @param {Object} config Configuration object
* @cfg {string} [templateName] Template name
+ * @cfg {boolean} [warning] Whether to display a warning for a possibly bad
source
* @cfg {Object[]} citeTools An array of available citation tool configuration
*/
ve.ui.CiteFromIdReferenceWidget = function VeUiCiteFromIdReferenceWidget(
documentModel, transclusionModel, config ) {
- var i, len, icon, item, title, doc, node;
+ var i, len, icon, item, title, doc, node, warning;
config = config || {};
@@ -74,6 +75,17 @@
label: this.title
} );
+ if ( config.warning ) {
+ warning = [
+ new OO.ui.IconWidget(
+ { icon: 'alert', flags: 'warning', title: 'Bad
source warning' } ).$element,
+ new OO.ui.LabelWidget(
+ { label: 'OMG your sources are bad!!!'
}).$element
+ ];
+ } else {
+ warning = [];
+ }
+
// Events
this.insertButton.connect( this, { click: 'onInsertButtonClick' } );
@@ -83,6 +95,7 @@
.append(
this.$icon,
title.$element,
+ $('<div>').append(warning), // make sure the warning is
a block element
this.insertButton.$element,
this.preview.$element
);
--
To view, visit https://gerrit.wikimedia.org/r/355612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd373321696124da2f3d3ec4fb0b3d287d877e4f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Citoid
Gerrit-Branch: master
Gerrit-Owner: Surlycyborg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits