Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -349,9 +349,20 @@ |
350 | 350 | ), |
351 | 351 | 'dependencies' => array( |
352 | 352 | 'jquery.ui.button', |
| 353 | + 'ep.imageinput', |
353 | 354 | ), |
354 | 355 | ); |
355 | 356 | |
| 357 | +$wgResourceModules['ep.imageinput'] = $moduleTemplate + array( |
| 358 | + 'scripts' => array( |
| 359 | + 'jquery.imageinput.js', |
| 360 | + 'ep.imageinput.js', |
| 361 | + ), |
| 362 | + 'dependencies' => array( |
| 363 | + 'jquery.ui.autocomplete', |
| 364 | + ), |
| 365 | +); |
| 366 | + |
356 | 367 | $wgResourceModules['ep.addorg'] = $moduleTemplate + array( |
357 | 368 | 'scripts' => array( |
358 | 369 | 'ep.addorg.js', |
Index: trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php |
— | — | @@ -76,29 +76,30 @@ |
77 | 77 | $fields['photo'] = array( |
78 | 78 | 'type' => 'text', |
79 | 79 | 'label-message' => $this->getMsgPrefix() . 'profile-photo', |
80 | | - 'validation-callback' => function ( $value, array $alldata = null ) use ( $lang, $prefix ) { |
81 | | - if ( trim( $value ) === '' ) { |
82 | | - return true; |
83 | | - } |
84 | | - |
85 | | - $domains = EPSettings::get( 'ambassadorPictureDomains' ); |
86 | | - |
87 | | - foreach ( $domains as $domain ) { |
88 | | - $pattern = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i'; |
89 | | - |
90 | | - if ( preg_match( $pattern, $value ) ) { |
91 | | - return true; |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - return wfMsgExt( |
96 | | - $prefix . 'profile-invalid-photo', |
97 | | - 'parsemag', |
98 | | - $lang->listToText( $domains ), |
99 | | - count( $domains ) |
100 | | - ); |
101 | | - }, |
| 80 | +// 'validation-callback' => function ( $value, array $alldata = null ) use ( $lang, $prefix ) { |
| 81 | +// if ( trim( $value ) === '' ) { |
| 82 | +// return true; |
| 83 | +// } |
| 84 | +// |
| 85 | +// $domains = EPSettings::get( 'ambassadorPictureDomains' ); |
| 86 | +// |
| 87 | +// foreach ( $domains as $domain ) { |
| 88 | +// $pattern = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i'; |
| 89 | +// |
| 90 | +// if ( preg_match( $pattern, $value ) ) { |
| 91 | +// return true; |
| 92 | +// } |
| 93 | +// } |
| 94 | +// |
| 95 | +// return wfMsgExt( |
| 96 | +// $prefix . 'profile-invalid-photo', |
| 97 | +// 'parsemag', |
| 98 | +// $lang->listToText( $domains ), |
| 99 | +// count( $domains ) |
| 100 | +// ); |
| 101 | +// }, |
102 | 102 | 'default' => $ambassador->getField( 'photo' ), |
| 103 | + 'cssclass' => 'commons-input', |
103 | 104 | ); |
104 | 105 | |
105 | 106 | return $fields; |
Index: trunk/extensions/EducationProgram/resources/ep.imageinput.js |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Education Program MediaWiki extension. |
| 4 | + * @see https://www.mediawiki.org/wiki/Extension:Education_Program |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function( $, mw ) { |
| 11 | + |
| 12 | + $( 'input.commons-input' ).imageInput( { |
| 13 | + 'apipath': 'http://commons.wikimedia.org/w/api.php?callback=?' |
| 14 | + } ); |
| 15 | + |
| 16 | +})( window.jQuery, window.mediaWiki ); |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/resources/jquery.imageinput.js |
— | — | @@ -0,0 +1,120 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Education Program MediaWiki extension. |
| 4 | + * @see https://www.mediawiki.org/wiki/Extension:Education_Program |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function( $, mw ) { $.fn.imageInput = function( options ) { |
| 11 | + |
| 12 | + var settings = $.extend( { |
| 13 | + 'apipath': wgScriptPath + '/api.php' |
| 14 | + }, options ); |
| 15 | + |
| 16 | + return this.each( function() { |
| 17 | + |
| 18 | + var _this = this, |
| 19 | + $this = $( _this ), |
| 20 | + $img = undefined; |
| 21 | + |
| 22 | + this.setup = function() { |
| 23 | + $img = $( '<img>' ).attr( { |
| 24 | + 'src': '', |
| 25 | + 'width': '200px', |
| 26 | + 'style': 'display:none' |
| 27 | + } ); |
| 28 | + |
| 29 | + $this.after( $img ); |
| 30 | + |
| 31 | + if ( $.trim( $this.val() ) !== '' ) { |
| 32 | + this.getAndDisplayImage( $this.val() ); |
| 33 | + } |
| 34 | + |
| 35 | + $this.autocomplete( { |
| 36 | + source: this.findImages, |
| 37 | + select: this.onSelect |
| 38 | + } ); |
| 39 | + }; |
| 40 | + |
| 41 | + this.findImages = function( request, response ) { |
| 42 | + $.getJSON( |
| 43 | + settings.apipath, |
| 44 | + { |
| 45 | + 'action': 'query', |
| 46 | + 'format': 'json', |
| 47 | + 'list': 'allpages', |
| 48 | + 'apprefix': request.term, |
| 49 | + 'apnamespace': 6, |
| 50 | + 'aplimit': 5 |
| 51 | + }, |
| 52 | + function( data ) { |
| 53 | + response( $.map( data.query.allpages, function( item ) { |
| 54 | + return { |
| 55 | + 'label': item.title, |
| 56 | + 'value': item.title |
| 57 | + }; |
| 58 | + } ) ); |
| 59 | + } |
| 60 | + ); |
| 61 | + }; |
| 62 | + |
| 63 | + this.onSelect = function( event, ui ) { |
| 64 | + this.getAndDisplayImage( ui.item.label ); |
| 65 | + }; |
| 66 | + |
| 67 | + this.getAndDisplayImage = function( pageTitle ) { |
| 68 | + this.getPreviewImage( |
| 69 | + { |
| 70 | + 'title': pageTitle, |
| 71 | + 'width': 200 |
| 72 | + }, |
| 73 | + this.displayImage |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + this.displayImage = function( imageUrl ) { |
| 78 | + if ( imageUrl === false ) { |
| 79 | + $img.attr( 'style', 'display:none' ); |
| 80 | + } |
| 81 | + else { |
| 82 | + $img.attr( { |
| 83 | + 'src': imageUrl, |
| 84 | + 'style': 'display:block' |
| 85 | + } ); |
| 86 | + } |
| 87 | + }; |
| 88 | + |
| 89 | + this.getPreviewImage = function( args, callback ) { |
| 90 | + $.getJSON( |
| 91 | + settings.apipath, |
| 92 | + { |
| 93 | + 'action': 'query', |
| 94 | + 'format': 'json', |
| 95 | + 'prop': 'imageinfo', |
| 96 | + 'iiprop': 'url', |
| 97 | + 'titles': args.title, |
| 98 | + 'iiurlwidth': args.width |
| 99 | + }, |
| 100 | + function( data ) { |
| 101 | + if ( data.query && data.query.pages ) { |
| 102 | + var pages = data.query.pages; |
| 103 | + |
| 104 | + for ( p in pages ) { |
| 105 | + var info = pages[p].imageinfo; |
| 106 | + for ( i in info ) { |
| 107 | + callback( info[i].thumburl ); |
| 108 | + return; |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + callback( false ); |
| 113 | + } |
| 114 | + ); |
| 115 | + }; |
| 116 | + |
| 117 | + this.setup(); |
| 118 | + |
| 119 | + }); |
| 120 | + |
| 121 | +}; })( window.jQuery, window.mediaWiki ); |