' + this.i18n.reuse + '');
$enable.click(function (){
$.cookie('StockPhotoDisabled', null, {
path: '/'
});
StockPhoto.init();
});
$("#filetoc").append($enable);
return;
}
if ($('#file').length < 1) return;
this.small_horizontal_layout = false;
if (wgUserName !== null) this.small_horizontal_layout = true;
if (getParamValue('stockphoto_show_social_bookmarks') !== null) this.show_social_bookmarks = true;
var has_information = false;
$.each(this.information_template_hints, function (k, v) {
if ($('#' + v).length !== 0) has_information = true;
});
// No {{Information}}
if (!has_information) return;
// Has one or more problemtags
// Changed to also include renames and normal deletes
if ($('.nuke').length) return;
$('#stockphoto_base').remove();
var img_width = $('#file img').width();
var img_height = $('#file img').height();
var xoff = img_width + 40;
var yoff = $('#file').position().top + 5;
if (!horizontal && img_height < 300) this.small_horizontal_layout = true;
var horizontal = this.small_horizontal_layout;
$.each(this.horizontal_ui, function (k, v) {
v = new RegExp('\.' + v + '$', 'i');
if (wgTitle.match(v)) horizontal = true;
});
if ($(window).width() < 1030) horizontal = true;
// Initialize values
this.share_this(-1);
var html = "
";
else if (!$("body.rtl").length) html += "class='vertical' style='left:" + xoff + "px;top:" + yoff + "px'>";
else html += "class='vertical' style='left: 0px;top:" + yoff + "px'>";
html += this.add_button_row(this.ui_icon_download, "call_download", this.i18n.download, this.i18n.all_sizes, horizontal);
html += this.add_button_row(this.ui_icon_web, "call_web", this.i18n.use_this_file_web_short, this.i18n.on_a_website, horizontal);
html += this.add_button_row(this.ui_icon_wiki, "call_wiki", this.i18n.use_this_file_wiki_short, this.i18n.on_a_wiki, horizontal);
html += this.add_button_row(this.ui_icon_email, "send_email", this.i18n.email_link_short, this.i18n.to_this_file, horizontal);
html += this.add_button_row(this.ui_icon_help, "call_help", this.i18n.information, this.i18n.about_reusing, horizontal);
html += '';
if (this.show_social_bookmarks) html += this.add_social_icons(horizontal);
html += "
";
if ( this.small_horizontal_layout && $("#file").length ) {
$(".mw-filetoc-links").hide();
$("#filetoc").append(html);
} else {
$("#filetoc").after(html);
}
$('#stockphoto_remove').click(function () {
$.cookie('StockPhotoDisabled', true, {
expires: 60,
path: '/'
});
$('#stockphoto_base').remove();
$(".mw-filetoc-links").show();
});
$('#stockphoto_base img').parent().fadeTo(0, 0.7);
$('#stockphoto_base>span').hover(function () {
$(this).find('span:first a').fadeTo('fast', 1);
}, function (evt) {
$(this).find('span:first a').fadeTo('fast', 0.7);
});
},
add_button_row: function (icon_url, fkt, txt, html, horizontal) {
if (this.small_horizontal_layout) {
icon_url = icon_url.replace('/50px-', '/20px-');
}
var imgid = "stockphoto_icon_" + fkt;
var a = "";
var ret = "";
ret += "" + a + "";
ret += "" + a;
if (this.small_horizontal_layout) ret += txt + "";
else ret += "" + txt + " " + html;
ret += "";
return ret;
},
stockphoto_get_thumbnail_url: function (width) {
if (this.isset(this.file_icon)) return this.file_icon;
var thumb_url;
var alt_title = wgCanonicalNamespace + ":" + wgTitle;
$('#file img').each(function () {
if ($(this).attr('alt') != alt_title) return;
thumb_url = $(this).attr('src').split('/');
});
// Special case of mwEmbed rewrite
if( !thumb_url && $('#mwe_ogg_player_1').length ){
return $('#mwe_ogg_player_1').find('img').attr('src');
}
if( !thumb_url || thumb_url.length < 1 ) return;
var last = thumb_url.pop().replace(/^\d+px-/, width + 'px-');
thumb_url.push(last);
thumb_url = thumb_url.join('/');
return thumb_url;
},
is_audio_video_asset: function(url){
var ext = url.substr(-3);
if( ext == 'ogv' || ext == 'ogg' || ext == 'oga' ){
return true;
}
return false;
},
make_html_textarea: function (e) {
if(e) e.preventDefault(); // if()-check in case it wasn't fired by an event
var width = $('#stockphoto_html_select').val();
var type = $("input[name='stockphoto_code_type']:checked").val();
// Iframe share for mwEmbed player
if( this.is_audio_video_asset( this.backlink_url ) && type == 'html' ){
// Get the ratio ( from html or from mwEmbed player )
var height = ( $('#mwe_ogg_player_1').width() )?
width * $('#mwe_ogg_player_1').height() / $('#mwe_ogg_player_1').width() :
width * $('#file img,#file video').height() / $('#file img,#file video').width() ;
// For audio that has zero height:
if( height == 0 ) height = 20;
$('#stockphoto_html').text( '' );
return ;
}
var thumb_url = this.stockphoto_get_thumbnail_url(width);
var t;
if (type == "html") t = "";
else if (type == "bbcode") t = "[url=" + this.backlink_url + "][img]" + thumb_url + "[/img][/url]\n[url=" + this.backlink_url + "]" + this.nicetitle + "[/url]" + this.stockphoto_license + ", " + this.i18n.by + " " + this.stockphoto_author + ", " + this.i18n.from_wikimedia_commons;
$('#stockphoto_html').text(t);
},
get_author_attribution: function (use_html) {
var author = $.trim($("#fileinfotpl_aut + td").text());
var source = $.trim($("#fileinfotpl_src + td").text());
// Remove boiler template; not elegant, but...
if (author.match(/This file is lacking author information/)) author = '';
if (author.match(/^[Uu]nknown$/)) author = '';
author = author.replace(/\s*\(talk\)$/i, "");
if (author.indexOf('Original uploader was') != -1) {
author = author.replace(/\s*Original uploader was\s*/g, "");
this.fromCommons = true;
}
// Remove boiler template; not elegant, but...
if (source.match(/This file is lacking source information/)) source = '';
if (author !== '' && $('#own-work').length) { // Remove "own work" notice
source = '';
this.fromCommons = true;
}
if (author !== '' && source.length > 50) source = ''; // Remove long source info
if (author.substr(0, 3) == "[▼]") {
author = author.substr(3);
author = $.trim(author.split("Description").shift());
}
this.attribution = '';
if (author !== '') this.attribution = author;
if (source != '') {
if (this.attribution != '') this.attribution += " (" + source + ")";
else this.attribution = source;
}
this.stockphoto_author = this.attribution;
if (author !== '') this.attribution = this.i18n.by_u + " " + this.attribution;
else this.attribution = this.i18n.see_page_for_author;
if ($('#creator').length) {
this.attribution = $('#creator').text();
}
if ($('.licensetpl_aut').length) {
if (use_html) this.attribution = $('.licensetpl_aut').eq(0).html();
else this.attribution = $('.licensetpl_aut').eq(0).text();
}
if ($('.licensetpl_attr').length) {
if (use_html) this.attribution = $('.licensetpl_attr').eq(0).html();
else this.attribution = $('.licensetpl_attr').eq(0).text();
}
if ($("#fileinfotpl_credit + td").length) {
if (use_html) this.attribution = $("#fileinfotpl_credit + td").html();
else this.attribution = $("#fileinfotpl_credit + td").text();
}
},
get_license: function (generate_html) {
var licenses = new Array();
$readable = $('.licensetpl');
if (!$readable.length) {
this.stockphoto_license = "[" + this.i18n.see_page_for_license + "]";
return;
}
$readable.each(function () {
var cL = {};
cL['link'] = $(this).find('.licensetpl_link').html();
cL['short'] = $(this).find('.licensetpl_short').html();
cL['long'] = $(this).find('.licensetpl_long').html();
cL['attr'] = $(this).find('.licensetpl_attr').html();
cL['aut'] = $(this).find('.licensetpl_aut').html();
cL['link_req'] = $(this).find('.licensetpl_link_req').html();
cL['attr_req'] = $(this).find('.licensetpl_attr_req').html();
if (cL['short'] !== null) licenses.push(cL);
});
if (licenses.length > 0) {
$.each(licenses, function (k, v) {
if (v['attr_req'] == "false") StockPhoto.attrRequired = false;
if (v['short'].indexOf('GFDL') != -1) StockPhoto.gfdl_note = true;
if (generate_html && v['link']) {
licenses[k] = '' + v['short'] + '';
} else {
if (v.link_req == "true") {
licenses[k] = v['short'] + ' (' + v['link'] + ')';
} else {
licenses[k] = v['short'];
}
}
});
if (licenses.length > 1) {
var l2 = licenses.pop();
var l1 = licenses.pop();
licenses.push(l1 + " " + this.i18n.or + " " + l2);
}
this.stockphoto_license = " [" + licenses.join(', ') + "]";
} else {
this.stockphoto_license = " [" + this.i18n.see_page_for_license + "]";
}
},
get_attribution_text: function () {
from = (this.fromCommons) ? this.i18n.from_wikimedia_commons : this.i18n.via_wikimedia_commons;
html = ($("#stockphoto_attribution_html:checked").length) ? true : false;
this.get_license(html);
this.get_author_attribution(html);
if ($("#fileinfotpl_credit + td").length) text = this.attribution;
else text = this.attribution + this.stockphoto_license;
if (html) text += ", " + from + "";
else text += ", " + from;
return text;
},
refresh_attribution: function () {
$("#stockphoto_attribution").val(StockPhoto.get_attribution_text());
},
createDialogRow: function (label, prefill, id) {
idtext = (id) ? "id='" + id + "'" : ""
return "
" + label + ":
";
},
share_this: function (ui_mode) {
this.complete_attribution_text = this.get_attribution_text();
this.file_url = $("#file > a").attr("href");
if (!this.file_url) this.file_url = $("#file > div > div > a").attr("href");
if (!this.file_url) this.file_url = $("div.fullMedia a").attr("href");
this.nicetitle = wgTitle.split('.');
this.nicetitle.pop();
this.nicetitle = this.nicetitle.join('.');
$.each(this.icons_only, function (i, v) {
var re = new RegExp('\.' + v + '$', 'i');
if (!wgPageName.match(re)) return;
StockPhoto.file_icon = StockPhoto.ogg_icon;
});
this.backlink_url = "http://commons.wikimedia.org/wiki/" + encodeURI(wgPageName);
//Grab width in pixel from DOM, and trim it down
//This does not yet work for SVGs or videos
try {
var pixelStr = $('.fullImageLink').contents().get(5).data;
var widthSearchMatch = /([0-9 ,.\u00a0]+)\s*×/.exec(pixelStr);
var imageWidth = parseInt(widthSearchMatch[1].replace(/[ ,.\u00a0]/g, ''));
if (isNaN(imageWidth)) throw 'Cannot parse';
//Calculate to which power of two we should go
var power = Math.floor(Math.log(imageWidth) / Math.log(2));
//Push 6 width to array
var widths = [];
for (var i=0; i < 5; i++) {
widths.push(Math.pow(2, power-i));
}
widths = widths.reverse();
} catch (e) {
var widths = [75, 100, 120, 240, 500, 640, 800, 1024];
}
if (ui_mode == -1) return;
var html = "";
html += this.createDialogRow(this.i18n.page_url, this.escapeAttribute(this.backlink_url));
html += this.createDialogRow(this.i18n.file_url, this.escapeAttribute(this.file_url));
html += this.createDialogRow(this.i18n.attribution, this.escapeAttribute(this.complete_attribution_text), 'stockphoto_attribution');
html += "";
if (this.gfdl_note) html += " " + this.i18n.gfdl_warning + "";
if (!this.attrRequired) html += " " + this.i18n.no_attr + "";
switch (ui_mode) {
case 1:
dtitle = this.i18n.download_this_file;
if (this.isset(this.file_url)) {
html += "
" + this.i18n.download_image_file + ": ";
var dl_links = new Array();
$.each(widths, function (i, v) {
if (StockPhoto.isset(StockPhoto.file_icon)) return;
dl_links.push("" + v + "px");
});
if (this.file_url) dl_links.push("" + this.i18n.full_resolution + "");
if (dl_links.length) html += dl_links.join(" | ");
else html += "" + this.i18n.not_available + "";
html += "
";
}
break;
case 2:
dtitle = this.i18n.use_this_file_web;
html += "