MediaWiki:PrettyLinkWidget.js: Difference between revisions
Content deleted Content added
No edit summary |
mNo edit summary |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1:
/**
* @fileoverview File containing and invoking widget object▼
* ▼
* @author <a href="mailto:magnusmanske@googlemail.com">Magnus Manske</a>▼
▲ @fileoverview File containing and invoking widget object
▲ @author <a href="mailto:magnusmanske@googlemail.com">Magnus Manske</a>
* Pretty Link Widget
* (c) 2011 by Magnus Manske
* Released under GPL v2 or higher
* USAGE : Add the following line to Special:MyPage/common.js
* mw.loader.load('https://en.wikipedia.org/w/index.php?title=MediaWiki:PrettyLinkWidget.js&action=raw&ctype=text/javascript')
*
*/
jQuery.fn.exists = function(){return jQuery(this).length>0;}
Line 28 ⟶ 27:
ignore_images : [ 'Commons-logo.svg','Disambig-dark.svg','Wikisource-logo.svg','Wiktfavicon en.svg','Loudspeaker.svg','Portal.svg','Qsicon Lücke.svg','Wikinews-logo.svg','Wikiquote-logo.svg','Reddot.svg',
'Qsicon lesenswert.svg','Wiktionary-logo-en.svg','Wikiversity-logo-Snorky.svg','Wikibooks-logo.svg','North.svg','South.svg','East.svg','West.svg','Red pog.svg','Compass rose pale-50x50.png',
'Speaker Icon.svg','Cscr-featured.svg','Wikispecies-logo.svg','Padlock-silver.svg' ] ,
createDialog : function () {
if (
var h = "\
<div id='prettylinkwidget_dialog' style='display:none;font-size:10pt;overflow:none' title='Pretty link widget'>\
<div id='loading' style='float:right;color:white;background:#888888;padding:2px;display:none'><span id='loading-text'>Loading…</span> <img src='
<p>This widget can help you to generate pretty references to Wikipedia.</p>\
\
Line 61 ⟶ 60:
<tr>\
<td id='render' align='center' style='width:100%;padding:10px;vertical-align:center'></td>\
<td align='center'><textarea id='source' style='width:500px;font-size:7pt' rows='
</tr>\
</table>\
</div>\
</div>" ;
} ,
run : function () {
prettylinkwidget.createDialog();
width :
height : 650 ,
modal : true
Line 78 ⟶ 77:
prettylinkwidget.title = mw.config.get ( 'wgTitle' ) ;
prettylinkwidget.lang = mediaWiki.user.options.get ( 'language' ) ;
prettylinkwidget.thumbsize =
prettylinkwidget.images = {} ;
prettylinkwidget.use_desc =
prettylinkwidget.hide_flags =
prettylinkwidget.loaded = 0 ;
prettylinkwidget.desc = '' ;
prettylinkwidget.load_max = prettylinkwidget.use_desc + 1 ;
// Images
if ( 1 ) {
var url = "
url += escape(prettylinkwidget.title) ;
url += "&prop=imageinfo&gimlimit=500&format=json&iiprop=url|mime&iiurlwidth="+prettylinkwidget.thumbsize+"&iiurlheight="+prettylinkwidget.thumbsize+"&callback=?" ;
function ( data ) {
prettylinkwidget.images = data.query ? data.query.pages : [];
prettylinkwidget.check_loaded ( 1 ) ;
} ) ;
Line 104 ⟶ 103:
// First paragraph
if ( prettylinkwidget.use_desc ) {
var url = "
function ( data ) {
prettylinkwidget.desc = String ( data ) ;
Line 119 ⟶ 118:
var h2 = "<td style='text-align:center'><input type='radio' name='irb' value='noimage' checked /></td>" ;
var t = v.title.split(':');
t.shift();
t = t.join(':');
var ignore = false ;
if ( b == t ) ignore = true ;
} ) ;
Line 132 ⟶ 131:
if ( undefined === v.imageinfo ) return ;
v.thumb_url = v2.thumburl ;
v.desc_url = v2.descriptionurl ;
Line 149 ⟶ 148:
h += '<tr>' + h2 + '</tr>' ;
h += '</table>' ;
prettylinkwidget.load_image_license() ;
} ) ;
Line 157 ⟶ 156:
load_image_license : function () {
var i =
if ( i == 'noimage' ) {
prettylinkwidget.show_results() ;
Line 163 ⟶ 162:
}
if ( k != i ) return ;
var url = '
if ( v.imagerepository == 'local' ) url = '
var t = v.title.split(':') ;
t.shift() ;
t = "File:" + t.join(':');
url += '/w/api.php?action=query&prop=categories&format=json&cllimit=500&titles=' + escape ( t ) + '&callback=?' ;
function ( data ) {
var cat = v3.title ;
cat = cat.split(':') ;
Line 200 ⟶ 199:
var nl = "\n" ;
var rev = ''
if (
rev = mediaWiki.config.get('wgCurRevisionId');
}
var w =
var h = '<div style="border:2px solid #DDDDDD;width:' + w + 'px">' + nl ;
h += '<table border="0"><tr>' + nl ;
var i =
var image_license ;
if ( i != 'noimage' ) {
Line 215 ⟶ 214:
var du ;
var imagelink ;
if ( k != i ) return ;
url = v.thumb_url ;
Line 237 ⟶ 236:
var url_title = escape ( prettylinkwidget.title.replace(' ','_') ) ;
var wp_url ;
if ( rev === undefined || rev == '' ) wp_url = '
else wp_url = "
h += '<div style="margin-bottom:3px"><a href="' + wp_url + '"><b>' + prettylinkwidget.title.replace('_',' ') + '</b></a> on Wikipedia</div>' + nl ;
if (
var d = prettylinkwidget.desc.split('.') ;
var nos =
while ( d.length > nos ) d.pop();
d = d.join('.') ;
Line 251 ⟶ 250:
}
h += '<div style="font-size:60%">Wikipedia article <a href="
if ( image_license !== undefined && image_license != '' ) h += ' ' + image_license ;
h += '</div>' + nl ;
Line 262 ⟶ 261:
h += '</div>' ;
} ,
Line 273 ⟶ 272:
this.loaded += add ;
if ( this.loaded < this.load_max ) return ;
this.show_images() ;
this.show_results () ;
Line 301 ⟶ 300:
if ( mw.config.get ( 'wgAction' ) != 'view' ) return ;
// prettylinkwidget.createDialog();
mw.util.addPortletLink('p-tb', 'javascript:prettylinkwidget.run()', 'Pretty link widget', 't-prettylinkwidget', 'Pretty link widget', '', '#t-print');
} ) ;
// mw.loader.load('//toolserver.org/~magnus/lib/jquery-ui-1.7.2.custom/css/ui-lightness/jquery-ui-1.7.2.custom.css', 'text/css');
// mw.loader.load('//toolserver.org/~magnus/lib/jquery-ui-1.7.2.custom/js/jquery-ui-1.7.2.custom.min.js');
|