MediaWiki:Gadget-ImageAnnotator.js: Difference between revisions

Content deleted Content added
eliminate wgGlobals
Line 27:
 
// Global: importScript, importScriptURI (wiki.js)
// Global: wgPageName, wgCurRevisionId, wgUserGroups, wgRestrictionEdit (inline script on the page)
// Global: wgAction, wgNamespaceNumber, wgUserLanguage, wgContentLanguage, stylepath (inline script)
// Global: wgNamespaceIds (inline script)
/*jshint eqnull:true, laxbreak:true, laxcomma:true */
 
Line 297 ⟶ 294:
if (this.tooltip) this.tooltip.size_change();
LAPI.Ajax.editPage(
mw.config.get('wgPageName')
, function (doc, editForm, failureFunc, revision_id)
{
try {
if (revision_id && revision_id != mw.config.get('wgCurRevisionId'))
throw new Error ('#Page version (revision ID) mismatch: edit conflict.');
 
Line 354 ⟶ 351:
return;
}
mw.config.set('wgCurRevisionId =', revision_id); // Bump revision id!!
LAPI.Ajax.removeSpinner(spinnerId);
if (self.tooltip) self.tooltip.size_change();
Line 525 ⟶ 522:
'query'
, { prop : 'revisions'
,titles : mw.config.get('wgPageName')
,rvlimit : 1
,rvstartid : mw.config.get('wgCurRevisionId')
,rvprop : 'ids|content'
}
Line 537 ⟶ 534:
if (p && p.revisions && p.revisions.length) {
var rev = p.revisions[0];
if (rev.revid == mw.config.get('wgCurRevisionId') && rev["*"] && rev["*"].length)
IA.setWikitext(rev["*"]);
}
Line 702 ⟶ 699:
this.saving = true;
LAPI.Ajax.editPage(
mw.config.get('wgPageName')
, function (doc, editForm, failureFunc, revision_id)
{
try {
if (revision_id && revision_id != mw.config.get('wgCurRevisionId'))
// Page was edited since the user loaded it.
throw new Error('#Page version (revision ID) mismatch: edit conflict.');
Line 796 ⟶ 793:
return;
}
mw.config.set('wgCurRevisionId =', revision_id); // Bump revision id!!
self.note.model.html = LAPI.DOM.importNode(document, html, true);
if (doc.isFake && (typeof doc.dispose === 'function')) doc.dispose();
Line 845 ⟶ 842:
if (lk && lk.length && lk[0].firstChild.nodeName.toLowerCase() === 'a') {
lk = lk[0].firstChild;
lk.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', encodeURIComponent(mw.config.get('wgPageName'))) + '?action=edit';
}
if (ex) {
Line 1,370 ⟶ 1,367:
lk.parentNode.replaceChild(
LAPI.DOM.makeLink(
mw.config.get('wgArticlePath').replace('$1', encodeURIComponent(this.realName))
, this.realName
, this.realName
Line 1,485 ⟶ 1,482:
 
// We'll include self.haveAjax later on once more, to catch the !ajaxQueried case.
self.may_edit = mw.config.get('wgNamespaceNumber') >= 0 && mw.config.get('wgArticleId') > 0 && self.haveAjax && config.editingEnabled();
 
function namespaceCheck (list)
{
if (!list || Object.prototype.toString.call(list) !== '[object Array]') return false;
var namespaceIds = mw.config.get('wgNamespaceIds');
if(!namespaceIds) return false;
var namespaceNumber = mw.config.get('wgNamespaceNumber');
for (var i = 0; i < list.length; i++) {
if (wgNamespaceIdstypeof list[i] === 'string'
&& typeof list[i] === 'string'
&& (list[i] === '*'
|| wgNamespaceIdsnamespaceIds[list[i].toLowerCase().replace(/ /g, '_')] === wgNamespaceNumbernamespaceNumber
)
)
Line 1,523 ⟶ 1,522:
self.rules.thumbs.show = false;
}
if (mw.config.get('wgNamespaceNumber') == 6)
self.rules.shared.show = true;
else if ( !config.sharedImagesEnabled()
Line 1,641 ⟶ 1,640:
self.thumbs = getElementsByClassName (document, 'div', 'thumbinner'); // No galleries!
}
if ( mw.config.get('wgNamespaceNumber') == 6
|| (self.imgs_with_notes.length)
|| (self.thumbs.length)
Line 1,762 ⟶ 1,761:
var img = null;
if (scope == document) {
img = LAPI.WP.getPreviewImage(mw.config.get('wgTitle'));
// TIFFs may be multi-paged: allow only for single-page TIFFs
if ( document.pageselector ) img = null;
Line 1,783 ⟶ 1,782:
var name = null;
if (scope == document) {
name = mw.config.get('wgPageName');
} else {
name = LAPI.WP.pageFromLink(img.parentNode);
Line 1,838 ⟶ 1,837:
}
 
if (mw.config.get('wgNamespaceNumber') == 6) {
setup_images ([document]);
self.may_edit = self.may_edit && (self.imgs.length == 1);
Line 1,941 ⟶ 1,940:
self.imgs[i].has_page = (typeof info.missing === 'undefined');
self.imgs[i].isLocal = !info.imagerepository || info.imagerepository == 'local';
if (i != 0 || !self.may_edit || !info.protection || mw.config.get('wgNamespaceNumber') != 6) return;
// Care about the protection settings
var protection = Array.any(info.protection, function (e) {
Line 1,948 ⟶ 1,947:
self.may_edit =
!protection
|| (mw.config.get('wgUserGroups') && mw.config.get('wgUserGroups').join(' ').contains(protection.level))
;
}
Line 1,965 ⟶ 1,964:
// prompt by using getScript instead of parseWikitext in this case.
ImageAnnotator.info_callbacks = [];
var template = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json'
+ '&prop=info|imageinfo&inprop=protection&iiprop=size'
+ '&titles=&callback=ImageAnnotator.info_callbacks[].callback';
Line 2,089 ⟶ 2,088:
result = self.repo[id];
} else {
result = UIElements.getEntry(id, self.repo, mw.config.get('wgUserLanguage'), null);
add_plea = !result;
if (!result) result = UIElements.getEntry(id, self.repo);
Line 2,097 ⟶ 2,096:
if (basic) return LAPI.DOM.getInnerText(result).trim();
result = result.cloneNode(true);
if (mw.config.get('wgServer').contains('/commons') && add_plea && !no_plea) {
// Add a translation plea.
if (result.nodeName.toLowerCase() == 'div') {
Line 2,119 ⟶ 2,118:
span.appendChild(
LAPI.DOM.makeLink(
mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=MediaWiki_talk:ImageAnnotatorTexts'
+ '&action=edit&section=new&withJS=MediaWiki:ImageAnnotatorTranslator.js'
+ '&language=' + mw.config.get('wgUserLanguage')
, translate
, (typeof translate === 'string' ? translate : LAPI.DOM.getInnerText(translate).trim())
Line 2,163 ⟶ 2,162:
 
var ui_page = '{{MediaWiki:ImageAnnotatorTexts'
+ (mw.config.get('wgUserLanguage') != mw.config.get('wgContentLanguage') ? '|lang=' + mw.config.get('wgUserLanguage') : '')
+ '|live=1}}';
 
Line 2,169 ⟶ 2,168:
{
var url =
mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=parse&pst&text='
+ encodeURIComponent(ui_page) + '&title=API&prop=text&format=json'
+ '&callback=ImageAnnotator.UI.init&maxage=14400&smaxage=14400'
Line 2,244 ⟶ 2,243:
 
// Check edit permissions
if (self.may_edit && typeof wgRestrictionEdit !== mw.config.get('undefinedwgRestrictionEdit' )) {
self.may_edit =
( (mw.config.get('wgRestrictionEdit').length === 0 || mw.config.get('wgUserGroups') && mw.config.get('wgUserGroups').join(' ').contains('sysop'))
|| ( mw.config.get('wgRestrictionEdit').length === 1 && mw.config.get('wgRestrictionEdit')[0] === 'autoconfirmed'
&& mw.config.get('wgUserGroups') && mw.config.get('wgUserGroups').join(' ').contains('confirmed') // confirmed & autoconfirmed
)
);
Line 2,258 ⟶ 2,257:
self.may_edit = (!sharedUpload || sharedUpload.length === 0);
}
if (self.may_edit && mw.config.get('wgNamespaceNumber') != 6) {
// Only allow edits if the stored page name matches the current one.
var img_page_name =
Line 2,266 ⟶ 2,265:
else
img_page_name = '';
self.may_edit = (img_page_name.replace(/ /g, '_') == mw.config.get('wgTitle').replace(/ /g, '_'));
}
 
Line 2,496 ⟶ 2,495:
self.button_div.appendChild(self.help_link);
}
if (add_plea && mw.config.get('wgServer').contains('/commons'))
self.button_div.appendChild(ImageAnnotator.UI.get_plea());
 
Line 2,714 ⟶ 2,713:
{
var template = api + '?action=parse&pst&text=&prop=text&format=json'
+ '&maxage=1800&smaxage=1800&uselang=' + mw.config.get('wgUserLanguage') //see bugzilla 22764
+ '&callback=ImageAnnotator.script_callbacks[].callback';
if (template.startsWith('//')) template = document.___location.protocol + template; // Avoid protocol-relative URIs (IE7 bug)
Line 2,752 ⟶ 2,751:
 
if ((!window.XMLHttpRequest && !!window.ActiveXObject) || !self.haveAjax) {
make_script_calls(get_local, mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php');
} else {
make_calls(
Line 2,947 ⟶ 2,946:
tgt = msg.lastChild;
if (tgt.nodeName.toLowerCase() != 'a')
tgt = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', 'Help:Gadget-ImageAnnotator');
else
tgt = tgt.href;
Line 3,193 ⟶ 3,192:
// Backwards compatibility
function getElementsByClassName (scope, tag, className) {
if (window.jQuery) {
return jQuery(scope).find(((!tag || tag === '*') ? '' : tag) + '.' + className);
} else {
Line 3,207 ⟶ 3,206:
// Start it. Bypass caches; but allow for 4 hours client-side caching. Small file.
IA.getScript(
mw.config.get('wgScript') + '?title=MediaWiki:ImageAnnotatorConfig.js&action=raw&ctype=text/javascript'
+ '&dummy=' + Math.floor((new Date()).getTime() / (14400 * 1000)) // 4 hours
, true // No local caching!