Revision: 43523
Author:   werdna
Date:     2008-11-15 01:29:52 +0000 (Sat, 15 Nov 2008)

Log Message:
-----------
Configure extension:
* Let users enter an image name for the logo, and then click a button to have 
it converted to a thumbnail URL.

Modified Paths:
--------------
    trunk/extensions/Configure/Configure.i18n.php
    trunk/extensions/Configure/Configure.js
    trunk/extensions/Configure/Configure.page.php
    trunk/extensions/Configure/Configure.settings-core.php
    trunk/phase3/includes/AjaxFunctions.php
    trunk/phase3/includes/DefaultSettings.php

Modified: trunk/extensions/Configure/Configure.i18n.php
===================================================================
--- trunk/extensions/Configure/Configure.i18n.php       2008-11-15 01:23:39 UTC 
(rev 43522)
+++ trunk/extensions/Configure/Configure.i18n.php       2008-11-15 01:29:52 UTC 
(rev 43523)
@@ -39,6 +39,7 @@
        'configure-js-prompt-group'           => 'Enter the name of the new 
group:',
        'configure-js-remove'                 => 'Delete',
        'configure-js-remove-row'             => 'Delete this entry',
+       'configure-js-get-image-url'          => 'Convert image name to URL',
        'configure-no-diff'                   => 'There is no changes between 
selected versions.',
        'configure-no-directory'              => 'The directory used to store 
the settings, <tt>$1</tt>, does not exist.
 Please create it or change it to use this extension.',

Modified: trunk/extensions/Configure/Configure.js
===================================================================
--- trunk/extensions/Configure/Configure.js     2008-11-15 01:23:39 UTC (rev 
43522)
+++ trunk/extensions/Configure/Configure.js     2008-11-15 01:29:52 UTC (rev 
43523)
@@ -3,6 +3,7 @@
  * create JavaScript buttons to allow to modify the form to have more
  * flexibility
  */
+
 function setupConfigure(){
 
        // For old versions
@@ -151,6 +152,19 @@
                table.parentNode.appendChild( button );
        }
        
+       var thumbs = getElementsByClassName( configform, 'input', 
'image-selector' );
+       for( var t = 0; t < thumbs.length; t++ ){
+               var textbox = thumbs[t];
+               
+               var button = document.createElement( 'input' );
+               button.type = 'button';
+               button.className = 'mw-button-get-image-url';
+               button.value = wgConfigureGetImageUrl;
+               button.onclick = createImageUrlCallback( textbox );
+               
+               textbox.parentNode.appendChild( button );
+       }
+       
        // $wgGroupPermissions stuff, only if ajax is enabled
        // --------------------------------------------------
 
@@ -476,6 +490,20 @@
 }
 
 /**
+ * Handle [Get thumbnail URL] button clicks
+ */
+function createImageUrlCallback( textbox ) {
+       return function() {
+               sajax_do_call( 'wfAjaxGetThumbnailUrl',
+                       [textbox.value, 130, 130], // FIXME hard-coded.
+                       function(response) {
+                               textbox.value = response.responseText;
+                       }
+               );
+       }
+}
+
+/**
  * Get an image object representing an arrow
  * @param dir String: arrow direction, one of the following strings:
  *            - u: up

Modified: trunk/extensions/Configure/Configure.page.php
===================================================================
--- trunk/extensions/Configure/Configure.page.php       2008-11-15 01:23:39 UTC 
(rev 43522)
+++ trunk/extensions/Configure/Configure.page.php       2008-11-15 01:29:52 UTC 
(rev 43523)
@@ -511,6 +511,7 @@
                                break;
                        case 'text':
                        case 'lang':
+                       case 'image-url':
                                $settings[$name] = $wgRequest->getVal( 'wp' . 
$name );
                                break;
                        case 'int':
@@ -679,6 +680,7 @@
                $removeRow = Xml::encodeJsVar( wfMsg( 'configure-js-remove-row' 
) );
                $promptGroup = Xml::encodeJsVar( wfMsg( 
'configure-js-prompt-group' ) );
                $groupExists = Xml::encodeJsVar( wfMsg( 
'configure-js-group-exists' ) );
+               $getimgurl = Xml::encodeJsVar( wfMsg( 
'configure-js-get-image-url' ) );
                $ajax = isset( $wgUseAjax ) && $wgUseAjax ? 'true' : 'false';
                $script = array(
                        "<script type=\"$wgJsMimeType\">/*<![CDATA[*/",
@@ -688,6 +690,7 @@
                        "var wgConfigurePromptGroup = {$promptGroup};",
                        "var wgConfigureGroupExists = {$groupExists};",
                        "var wgConfigureUseAjax = {$ajax};",
+                       "var wgConfigureGetImageUrl = {$getimgurl};",
                        "/*]]>*/</script>",
                        "<script type=\"{$wgJsMimeType}\" 
src=\"{$wgScriptPath}/extensions/Configure/Configure.js?{$wgConfigureStyleVersion}\"></script>",
                );
@@ -726,16 +729,17 @@
                if( $type == 'text' || $type == 'int' ){
                        if( !$allowed )
                                return '<code>' . htmlspecialchars( 
(string)$default ) . '</code>';
-                       return Xml::element( 'input', array( 'name' => 'wp' . 
$conf, 'type' => 'text', 'value' => (string)$default ) );
+                       return Xml::input( "wp$conf", 45, (string)$default );
                }
+               if ( $type == 'image-url' ) {
+                       if( !$allowed )
+                               return '<code>' . htmlspecialchars( 
(string)$default ) . '</code>';
+                       return Xml::input( "wp$conf", 45, (string)$default, 
array( 'class' => 'image-selector' ) );
+               }
                if( $type == 'bool' ){
                        if( !$allowed )
                                return '<code>' . ( $default ? 'true' : 'false' 
) . '</code>';
-                       if( $default )
-                               $checked = array( 'checked' => 'checked' );
-                       else
-                               $checked = array();
-                       return Xml::element( 'input', array( 'name' => 'wp' . 
$conf, 'type' => 'checkbox', 'value' => '1' ) + $checked );
+                       return Xml::check( "wp$conf", $default, array( 'value' 
=> '1' ) );
                }
                if( $type == 'array' ){
                        return $this->buildArrayInput( $conf, $default, 
$allowed );

Modified: trunk/extensions/Configure/Configure.settings-core.php
===================================================================
--- trunk/extensions/Configure/Configure.settings-core.php      2008-11-15 
01:23:39 UTC (rev 43522)
+++ trunk/extensions/Configure/Configure.settings-core.php      2008-11-15 
01:29:52 UTC (rev 43523)
@@ -25,7 +25,7 @@
                        'wgDiff' => 'text',
                        'wgDiff3' => 'text',
                        'wgFavicon' => 'text',
-                       'wgLogo' => 'text',
+                       'wgLogo' => 'image-url',
                        'wgMathDirectory' => 'text',
                        'wgMathPath' => 'text',
                        'wgRedirectScript' => 'text',
@@ -1005,7 +1005,7 @@
 # Emal
        'wgSMTP',
 # Proxy
-#      'wgProxyKey', ## Deprecated
+       'wgProxyKey', ## Deprecated
        'wgSecretKey',
 );
 

Modified: trunk/phase3/includes/AjaxFunctions.php
===================================================================
--- trunk/phase3/includes/AjaxFunctions.php     2008-11-15 01:23:39 UTC (rev 
43522)
+++ trunk/phase3/includes/AjaxFunctions.php     2008-11-15 01:29:52 UTC (rev 
43523)
@@ -126,3 +126,18 @@
                return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), 
$title->getPrefixedText() );
        }
 }
+
+/**
+ * Called in some places (currently just extensions)
+ * to get the thumnail URL for a given file at a given resolution.
+ */
+function wfAjaxGetThumbnailUrl( $file, $width, $height ) {
+       $file = wfFindFile( $file );
+       
+       if ( !$file || !$file->exists() )
+               return null;
+               
+       $url = $file->getThumbnail( $width, $height )->url;
+       
+       return $url;
+}
\ No newline at end of file

Modified: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php   2008-11-15 01:23:39 UTC (rev 
43522)
+++ trunk/phase3/includes/DefaultSettings.php   2008-11-15 01:29:52 UTC (rev 
43523)
@@ -3301,7 +3301,7 @@
  * List of Ajax-callable functions.
  * Extensions acting as Ajax callbacks must register here
  */
-$wgAjaxExportList = array( );
+$wgAjaxExportList = array( 'wfAjaxGetThumbnailUrl' );
 
 /**
  * Enable watching/unwatching pages using AJAX.



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to