r44266 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44265‎ | r44266 | r44267 >
Date:00:32, 6 December 2008
Author:werdna
Status:ok
Tags:
Comment:
Fix up Configure extension logo setting handling:
* Replace annoying button with an onblur preview and server-side conversion of file names into URLs.
Modified paths:
  • /trunk/extensions/Configure/Configure.js (modified) (history)
  • /trunk/extensions/Configure/Configure.page.php (modified) (history)
  • /trunk/phase3/includes/AjaxFunctions.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AjaxFunctions.php
@@ -140,4 +140,19 @@
141141 $url = $file->getThumbnail( $width, $height )->url;
142142
143143 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;
144159 }
\ No newline at end of file
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3328,7 +3328,7 @@
33293329 * List of Ajax-callable functions.
33303330 * Extensions acting as Ajax callbacks must register here
33313331 */
3332 -$wgAjaxExportList = array( 'wfAjaxGetThumbnailUrl' );
 3332+$wgAjaxExportList = array( 'wfAjaxGetThumbnailUrl', 'wfAjaxGetFileUrl' );
33333333
33343334 /**
33353335 * Enable watching/unwatching pages using AJAX.
Index: trunk/extensions/Configure/Configure.page.php
@@ -590,7 +590,15 @@
591591 case 'text':
592592 case 'lang':
593593 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+
595603 break;
596604 case 'int':
597605 $settings[$name] = $wgRequest->getInt( 'wp' . $name );
Index: trunk/extensions/Configure/Configure.js
@@ -169,15 +169,7 @@
170170 var conf = textbox.id.substr( 18 );
171171 var img = document.getElementById( 'image-url-preview-'+conf );
172172
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 ) );
182174 }
183175
184176 // $wgGroupPermissions stuff, only if ajax is enabled
@@ -789,15 +781,14 @@
790782 */
791783 function createImageUrlCallback( textbox, img ) {
792784 return function() {
793 - sajax_do_call( 'wfAjaxGetThumbnailUrl',
794 - [textbox.value, 130, 130], // FIXME hard-coded.
 785+ sajax_do_call( 'wfAjaxGetFileUrl',
 786+ [textbox.value],
795787 function(response) {
796788 var text = response.responseText;
797789 // basic error handling
798790 if( text.substr( 0, 9 ) == "<!DOCTYPE" ) {
799 - alert( wgConfigureImageError );
 791+ img.src = textbox.value;
800792 } else {
801 - textbox.value = response.responseText;
802793 img.src = response.responseText;
803794 }
804795 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r68126Kill off another AjaxFunction. The only thing that ever used this was Configu...demon17:24, 16 June 2010

Status & tagging log