MediaWiki:Gadget-ImageAnnotator.js: Difference between revisions
Content deleted Content added
more clean up and type coercion guards |
Scope wgNamespaceNumber |
||
Line 26:
/*global prompt */ // discouraged browser globals
/*global wgServer, wgContentLanguage */ // legacy config site globals
/*global wgUserGroups
/*global mw, $ */
/*global importScript, importScriptURI */ // wikibits.js
Line 46:
'skin',
'stylepath',
'
'wgCurRevisionId',
'
'wgNamespaceNumber',
'wgPageName',
'
'wgUserLanguage'
]);
Line 1,240 ⟶ 1,241:
hide: function (evt) {
function intersect_rectangles
if (b.x > a.r || b.r < a.x || b.y > a.b || b.b < a.y)
return { x:0, y:0, r:0, b:0 };
Line 1,282 ⟶ 1,283:
img_pos.r = img_pos.x + this.overflowParents[i].clientWidth;
img_pos.b = img_pos.y + this.overflowParents[i].clientHeight;
rect = intersect_rectangles
}
}
Line 1,463 ⟶ 1,464:
// We'll include self.haveAjax later on once more, to catch the !ajaxQueried case.
self.may_edit = conf.wgNamespaceNumber >= 0 && conf.wgArticleId > 0 && self.haveAjax && config.editingEnabled();
function namespaceCheck (list) {
Line 1,471 ⟶ 1,472:
&& typeof list[i] === 'string'
&& (list[i] === '*'
|| conf.wgNamespaceIds[list[i].toLowerCase().replace(/ /g, '_')] === conf.wgNamespaceNumber
)
)
Line 1,498 ⟶ 1,499:
self.rules.thumbs.show = false;
}
if (conf.wgNamespaceNumber === 6)
self.rules.shared.show = true;
else if ( !config.sharedImagesEnabled()
Line 1,613 ⟶ 1,614:
self.thumbs = document.getElementsByClassName('thumbinner');
}
if (
|| (self.imgs_with_notes.length)
|| (self.thumbs.length)
Line 1,661 ⟶ 1,662:
document.body.insertBefore(testImgDiv, document.body.firstChild);
function img_check
var srcW = parseInt (img.getAttribute('width', 2), 10);
var srcH = parseInt (img.getAttribute('height', 2), 10);
Line 1,708 ⟶ 1,709:
}
function setup_one
var file_div = scope;
var is_thumb =
Line 1,738 ⟶ 1,739:
}
if (!img) return null;
var dim = img_check
if (!dim) return null;
// Conditionally exclude shared images.
Line 1,793 ⟶ 1,794:
}
function setup_images
Array.forEach(list,
function (elem) {
var desc = setup_one
if (desc) self.imgs[self.imgs.length] = desc;
}
Line 1,802 ⟶ 1,803:
}
if (conf.wgNamespaceNumber === 6) {
setup_images
self.may_edit = self.may_edit && (self.imgs.length === 1);
setup_images
} else {
setup_images
self.may_edit = self.may_edit && (self.imgs.length === 1);
}
Line 1,814 ⟶ 1,815:
if (self.haveAjax) {
setup_images
setup_images
}
Line 1,853 ⟶ 1,854:
var done = 0;
function check_done
done += length;
if (done >= names.length) {
Line 1,861 ⟶ 1,862:
}
function make_calls
function build_titles
var done = 0;
var text = '';
Line 1,880 ⟶ 1,881:
var start = 0;
while (to_do > 0) {
params = build_titles
execute_call
to_do -= params.n;
start += params.n;
Line 1,887 ⟶ 1,888:
}
function set_info
function get_size
if (!info.imageinfo || info.imageinfo.length === 0) return;
var title = info.title.replace(/ /g, '_');
Line 1,900 ⟶ 1,901:
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 || conf.wgNamespaceNumber !== 6) return;
// Care about the protection settings
var protection = Array.any(info.protection, function (e) {
Line 1,915 ⟶ 1,916:
if (json && json.query && json.query.pages) {
for (var page in json.query.pages) {
get_size
}
} // end if
Line 1,935 ⟶ 1,936:
ImageAnnotator.info_callbacks[idx] = {
callback: function (json) {
set_info
ImageAnnotator.info_callbacks[idx].done = true;
if (ImageAnnotator.info_callbacks[idx].script) {
Line 1,941 ⟶ 1,942:
ImageAnnotator.info_callbacks[idx].script = null;
}
check_done
},
done: false
Line 1,977 ⟶ 1,978:
},
function (request, json_result) {
set_info
check_done
},
function () {
Line 2,142 ⟶ 2,143:
}
function get_ui
IA.haveAjax = (LAPI.Ajax.getRequest() != null);
IA.ajaxQueried = true;
Line 2,172 ⟶ 2,173:
get_ui_no_ajax ();
} else {
get_ui
}
},
Line 2,391 ⟶ 2,392:
self.may_edit = (!sharedUpload || sharedUpload.length === 0);
}
if (self.may_edit && conf.wgNamespaceNumber !== 6) {
// Only allow edits if the stored page name matches the current one.
var img_page_name = self.imgs[0].scope.getElementsByClassName('wpImageAnnotatorPageName');
Line 2,481 ⟶ 2,482:
// API limits and to keep the URL length below the limit for the foreign_repo calls.
function make_calls
function composer (list, from, length, url_limit) {
function compose (list, from, length, url_limit) {
Line 2,509 ⟶ 2,510:
var param = compose (list, from, length, url_limit);
execute_call
return param.n;
}
Line 2,531 ⟶ 2,532:
// additional images we'd rather not load when we add this (X)HTML to the DOM. Therefore, we
// strip out everything but the notes.
function strip_noise
var result = '';
var m;
Line 2,539 ⟶ 2,540:
// Now collect pages
while (idx < l && i >= idx) {
var j = html.indexOf(inlineNameEnd, i + blockStart.length);
if (j < i + blockStart.length) break;
result += html.substring(i, j + inlineNameEnd.length);
idx = j + inlineNameEnd.length;
// Now collect all image image notes for that page
var note_begin = 0, next_block = html.indexOf(blockStart, idx);
Line 2,586 ⟶ 2,587:
}
function setup_thumb_viewers
var node = LAPI.make('div', null, {display: 'none'});
document.body.appendChild(node);
try {
node.innerHTML = strip_noise
var pages = node.getElementsByClassName('wpImageAnnotatorInlineImageWrapper');
for (var i = 0; pages && i < pages.length; i++) {
Line 2,658 ⟶ 2,659:
ImageAnnotator.script_callbacks = [];
function make_script_calls
var template = api + '?action=parse&pst&text=&prop=text&format=json'
+ '&maxage=1800&smaxage=1800&uselang=' + conf.wgUserLanguage //see bugzilla 22764
+ '&callback=ImageAnnotator.script_callbacks[].callback';
if (template.startsWith('//')) template = document.___location.protocol + template; // Avoid protocol-relative URIs (IE7 bug)
make_calls
list
, function (text) {
Line 2,670 ⟶ 2,671:
callback: function (json) {
if (json && json.parse && json.parse.text && json.parse.text['*']) {
setup_thumb_viewers
}
ImageAnnotator.script_callbacks[idx].done = true;
Line 2,720 ⟶ 2,721:
// character (2048 in the path part), and servers also may impose limits (on the WMF servers,
// the limit appears to be 8kB).
make_script_calls
},
Line 2,891 ⟶ 2,892:
tgt = tgt.href;
function make_handler
var target = tgt;
return function (evt) {
|