Index: trunk/phase3/includes/AjaxFunctions.php |
— | — | @@ -140,4 +140,19 @@ |
141 | 141 | $url = $file->getThumbnail( $width, $height )->url; |
142 | 142 | |
143 | 143 | return $url; |
| 144 | +} |
| 145 | + |
| 146 | +/** |
| 147 | + * Called in some places (currently just extensions) |
| 148 | + * to get the URL for a given file. |
| 149 | + */ |
| 150 | +function wfAjaxGetFileUrl( $file ) { |
| 151 | + $file = wfFindFile( $file ); |
| 152 | + |
| 153 | + if ( !$file || !$file->exists() ) |
| 154 | + return null; |
| 155 | + |
| 156 | + $url = $file->getUrl(); |
| 157 | + |
| 158 | + return $url; |
144 | 159 | } |
\ No newline at end of file |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -3328,7 +3328,7 @@ |
3329 | 3329 | * List of Ajax-callable functions. |
3330 | 3330 | * Extensions acting as Ajax callbacks must register here |
3331 | 3331 | */ |
3332 | | -$wgAjaxExportList = array( 'wfAjaxGetThumbnailUrl' ); |
| 3332 | +$wgAjaxExportList = array( 'wfAjaxGetThumbnailUrl', 'wfAjaxGetFileUrl' ); |
3333 | 3333 | |
3334 | 3334 | /** |
3335 | 3335 | * Enable watching/unwatching pages using AJAX. |
Index: trunk/extensions/Configure/Configure.page.php |
— | — | @@ -590,7 +590,15 @@ |
591 | 591 | case 'text': |
592 | 592 | case 'lang': |
593 | 593 | case 'image-url': |
594 | | - $settings[$name] = trim( $wgRequest->getVal( 'wp' . $name ) ); |
| 594 | + $setting = trim( $wgRequest->getVal( 'wp' . $name ) ); |
| 595 | + |
| 596 | + if ( $file = wfFindFile( $setting ) ) { |
| 597 | + ## It's actually a local file. |
| 598 | + $setting = $file->getUrl(); |
| 599 | + } |
| 600 | + |
| 601 | + $settings[$name] = $setting; |
| 602 | + |
595 | 603 | break; |
596 | 604 | case 'int': |
597 | 605 | $settings[$name] = $wgRequest->getInt( 'wp' . $name ); |
Index: trunk/extensions/Configure/Configure.js |
— | — | @@ -169,15 +169,7 @@ |
170 | 170 | var conf = textbox.id.substr( 18 ); |
171 | 171 | var img = document.getElementById( 'image-url-preview-'+conf ); |
172 | 172 | |
173 | | - var button = document.createElement( 'input' ); |
174 | | - button.type = 'button'; |
175 | | - button.className = 'mw-button-get-image-url'; |
176 | | - button.value = wgConfigureGetImageUrl; |
177 | | - button.onclick = createImageUrlCallback( textbox, img ); |
178 | | - |
179 | | - textbox.parentNode.insertBefore( button, img ); |
180 | | - textbox.parentNode.insertBefore( document.createTextNode( '\u00A0' ), button ); // nbsp |
181 | | - img.parentNode.insertBefore( document.createTextNode( '\u00A0' ), img ); // nbsp |
| 173 | + addHandler( textbox, 'blur', createImageUrlCallback( textbox, img ) ); |
182 | 174 | } |
183 | 175 | |
184 | 176 | // $wgGroupPermissions stuff, only if ajax is enabled |
— | — | @@ -789,15 +781,14 @@ |
790 | 782 | */ |
791 | 783 | function createImageUrlCallback( textbox, img ) { |
792 | 784 | return function() { |
793 | | - sajax_do_call( 'wfAjaxGetThumbnailUrl', |
794 | | - [textbox.value, 130, 130], // FIXME hard-coded. |
| 785 | + sajax_do_call( 'wfAjaxGetFileUrl', |
| 786 | + [textbox.value], |
795 | 787 | function(response) { |
796 | 788 | var text = response.responseText; |
797 | 789 | // basic error handling |
798 | 790 | if( text.substr( 0, 9 ) == "<!DOCTYPE" ) { |
799 | | - alert( wgConfigureImageError ); |
| 791 | + img.src = textbox.value; |
800 | 792 | } else { |
801 | | - textbox.value = response.responseText; |
802 | 793 | img.src = response.responseText; |
803 | 794 | } |
804 | 795 | } |