MediaWiki r44223 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r44222‎ | r44223 (on ViewVC)‎ | r44224 >
Date:11:56, 4 December 2008
Author:werdna
Status:ok (Comments)
Tags:
Comment:
Add a sexy new UI for $wgRateLimits.
Still has weird jumpy tables, which have their width set to 100% with CSS. Still need to investigate that, but it's not a blocker.
Modified paths:

Diff [purge]

Index: trunk/extensions/Configure/Configure.page.php
===================================================================
--- trunk/extensions/Configure/Configure.page.php	(revision 44222)
+++ trunk/extensions/Configure/Configure.page.php	(revision 44223)
@@ -563,6 +563,27 @@
 						}
 					}
 					break;
+				case 'rate-limits':
+					$all = array();
+					## TODO put this stuff in a central place.
+					$validActions = array( 'edit', 'move', 'mailpassword', 'emailuser', 'rollback' );
+					$validGroups = array( 'anon', 'user', 'newbie', 'ip', 'subnet' );
+					
+					foreach( $validActions as $action ) {
+						$all[$action] = array();
+						foreach( $validGroups as $group ) {
+							$count = $wgRequest->getIntOrNull( "wp$name-key-$action-$group-count" );
+							$period = $wgRequest->getIntOrNull( "wp$name-key-$action-$group-period" );
+							
+							if ($count && $period) {
+								$all[$action][$group] = array( $count, $period );
+							} else {
+								$all[$action][$group] = null;
+							}
+						}
+					}
+					
+					$settings[$name] = $all;
 				}
 				break;
 			case 'text':
@@ -766,6 +787,8 @@
 		$biglist_show = Xml::encodeJsVar( wfMsg( 'configure-js-biglist-show' ) );
 		$biglist_hide = Xml::encodeJsVar( wfMsg( 'configure-js-biglist-hide' ) );
 		$summary_none = Xml::encodeJsVar( wfMsg( 'configure-js-summary-none' ) );
+		$throttle_summary = Xml::encodeJsVar( wfMsg( 'configure-throttle-summary' ) );
+		
 		$ajax = isset( $wgUseAjax ) && $wgUseAjax ? 'true' : 'false';
 		$script = array(
 			"<script type=\"$wgJsMimeType\">/*<![CDATA[*/",
@@ -782,6 +805,7 @@
 			"var wgConfigureBiglistShow = {$biglist_show};",
 			"var wgConfigureBiglistHide = {$biglist_hide};",
 			"var wgConfigureSummaryNone = {$summary_none};",
+			"var wgConfigureThrottleSummary = {$throttle_summary};",
 		 	"/*]]>*/</script>",
 			"<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}/extensions/Configure/Configure.js?{$wgConfigureStyleVersion}\"></script>",
 		);
@@ -873,6 +897,7 @@
 
 	/**
 	 * Build an input for an array setting
+	 * TODO Consolidate some of the duplicated code here.
 	 *
 	 * @param $conf String: setting name
 	 * @param $default Mixed: current value (but should be array :)
@@ -906,15 +931,13 @@
 			if (wfEmptyMsg( "configure-setting-$conf-value", $valdesc ))
 				$valdesc = wfMsgHtml( 'configure-desc-val' );
 
-			$classes = array('configure-array-table');
+			$classes = array('configure-array-table', 'assoc');
 
-			$classes[] = ($allowed ? 'assoc' : 'assoc disabled');
+			if (!$allowed)
+				$classes[] = 'disabled';
 			if (count($default) > 5)
 				$classes[] = 'configure-biglist';
 
-			if ( !$allowed )
-				$classes[] = 'disabled';
-
 			$text = Xml::openElement( 'table', array( 'class' => ( implode( ' ', $classes ) ),
 				'id' => $conf ) ) . "\n";
 			$text .= "<tr><th>{$keydesc}</th><th>{$valdesc}</th></tr>\n";
@@ -961,6 +984,63 @@
 			$text .= '</table>';
 			return $text;
 		}
+		if ($type == 'rate-limits') { ## Some of this is stolen from assoc, since it's an assoc with an assoc.
+			$keydesc = wfMsgExt( "configure-setting-$conf-key", 'parseinline' );
+			$valdesc = wfMsgExt( "configure-setting-$conf-value", 'parseinline' );
+			
+			if (wfEmptyMsg( "configure-setting-$conf-key", $keydesc ))
+				$keydesc = wfMsgHtml( 'configure-desc-key' );
+			if (wfEmptyMsg( "configure-setting-$conf-value", $valdesc ))
+				$valdesc = wfMsgHtml( 'configure-desc-val' );
+				
+			$classes = array('configure-array-table', 'configure-rate-limits');
+
+			if (!$allowed)
+				$classes[] = 'disabled';
+			
+			$rows = Xml::tags( 'tr', null, Xml::tags( 'th', null, $keydesc ) . " " . Xml::tags( 'th', null, $valdesc ) )."\n";
+			
+			# TODO put this stuff in one place.
+			$validActions = array( 'edit', 'move', 'mailpassword', 'emailuser', 'rollback' );
+			$validGroups = array( 'anon', 'user', 'newbie', 'ip', 'subnet' );
+			
+			foreach( $validActions as $action ) {
+				$val = array();
+				if (@isset($default[$action]))
+					$val = $default[$action];
+				
+				$key = Xml::tags( 'td', null, wfMsgExt( "configure-throttle-action-$action", 'parseinline' ) );
+				
+				## Build YET ANOTHER ASSOC TABLE ARGH!
+				$innerRows = Xml::tags( 'tr', null, Xml::tags( 'th', null, wfMsgExt( 'configure-throttle-group', 'parseinline' ) ) . " " . Xml::tags( 'th', null, wfMsgExt( 'configure-throttle-limit', 'parseinline' ) ) )."\n";
+				foreach( $validGroups as $type ) {
+					$limits = null;
+					if (@isset($default[$action][$type]))
+						$limits = $default[$action][$type];
+					if (is_array($limits) && count($limits) == 2)
+						list($count, $period) = $limits;
+					else
+						$count = $period = 0;
+					
+					$id = 'wp'.$conf.'-key-'.$action.'-'.$type;
+					$left_col = Xml::tags( 'td', null, wfMsgExt( "configure-throttle-group-$type", 'parseinline' ) );
+					
+					$right_col = Xml::inputLabel( wfMsg( 'configure-throttle-count' ), "$id-count", "$id-count", 15, $count ) . ' ' .
+						Xml::inputLabel( wfMsg( 'configure-throttle-period' ), "$id-period", "$id-period", 15, $period );
+					$right_col = Xml::tags( 'td', null, $right_col );
+					
+					$innerRows .= Xml::tags( 'tr', array( 'id' => $id), $left_col . $right_col ) . "\n";
+				}
+				
+				$value = Xml::tags( 'td', null, Xml::tags( 'table', array( 'class' => 'configure-biglist configure-rate-limits-action' ), Xml::tags( 'tbody', null, $innerRows ) ) );
+				$rows .= Xml::tags( 'tr', null, $key.$value )."\n";
+			}
+			
+// 			header( 'Content-Type: text/plain' );
+// 			die( $rows );
+			
+			return Xml::tags( 'table', array( 'class' => implode( ' ', $classes ) ), Xml::tags( 'tbody', null, $rows ) );
+		}
 		if ( $type == 'simple-dual' ) {
 			$var = array();
 			if ( is_array( $default ) ) {
Index: trunk/extensions/Configure/Configure.i18n.php
===================================================================
--- trunk/extensions/Configure/Configure.i18n.php	(revision 44222)
+++ trunk/extensions/Configure/Configure.i18n.php	(revision 44223)
@@ -156,6 +156,24 @@
 	'right-viewconfig-all'                => 'View all wiki configuration',
 	'right-viewconfig-interwiki'          => 'View foreign wiki configuration',
 	'viewconfig'                          => 'View wiki configuration',
+	
+	'configure-throttle-action-edit'      => 'Edit',
+	'configure-throttle-action-move'      => 'Move',
+	'configure-throttle-action-rollback'  => 'Rollback',
+	'configure-throttle-action-mailpassword' => 'Send password reminder',
+	'configure-throttle-action-emailuser' => 'Send mail',
+	
+	'configure-throttle-group-anon'       => 'All anonymous users',
+	'configure-throttle-group-user'       => 'Per user account',
+	'configure-throttle-group-newbie'     => 'Per new user account',
+	'configure-throttle-group-ip'         => 'Per IP address',
+	'configure-throttle-group-subnet'     => 'Per Class C subnet',
+	
+	'configure-throttle-count'            => 'Allowed actions:',
+	'configure-throttle-period'           => 'Reset period (seconds):',
+	'configure-throttle-summary'          => '$1 actions in $2 seconds.',
+	'configure-throttle-group'            => 'Type',
+	'configure-throttle-limit'            => 'Limit',
 );
 
 /** Message documentation (Message documentation)
Index: trunk/extensions/Configure/Configure.js
===================================================================
--- trunk/extensions/Configure/Configure.js	(revision 44222)
+++ trunk/extensions/Configure/Configure.js	(revision 44223)
@@ -380,8 +380,8 @@
 		}
 		
 		summary.innerHTML = matches.join( ', ' ); // Be aware of velociraptors.
-	} else if ( isType( 'ns-array' ) || isType( 'ns-text' ) ) {
-		// Get the headers
+	} else if ( isType( 'ns-array' ) || isType( 'ns-text' ) || isType( 'configure-rate-limits-action' ) ) {
+		// Basic strategy: find all labels, and list the values of their corresponding inputs, if those inputs have a value
 		var header_key = undefined;
 		var header_value = undefined;
 		
@@ -390,7 +390,7 @@
 		header_value = getInnerText( headers[1] );
 		
 		var table = document.createElement( 'table' );
-		table.className = 'ns-array';
+		table.className = 'assoc';
 		table.appendChild( document.createElement( 'tbody' ) );
 		table = table.firstChild;
 		
@@ -406,25 +406,58 @@
 		
 		var rows = false;
 		
-		var labels = div.getElementsByTagName( 'label' );
-		for( var i=0; i<labels.length; ++i ) {
-			var label = labels[i];
-			var arrayfield = document.getElementById( label.htmlFor );
-			
-			if ( arrayfield && arrayfield.value ) {
-				rows = true;
+		if ( isType( 'configure-rate-limits-action' ) ) {
+			var allRows = div.getElementsByTagName( 'tr' );
+			for( var i=0; i<allRows.length; ++i ) {
+				var row = allRows[i];
+				var idparts = row.id.split( '-' );
+				var action = idparts[2];
+				var type = idparts[3];
+				var typeDesc = getInnerText( row.getElementsByTagName( 'td' )[0] );
+				var periodField = document.getElementById( row.id+'-period' );
+				var countField = document.getElementById( row.id+'-count' );
 				
-				tr = document.createElement( 'tr' );
-				var key_td = document.createElement( 'td' );
-				var value_td = document.createElement( 'td' );
+				if ( periodField && periodField.value>0 ) {
+					rows = true;
+					
+					tr = document.createElement( 'tr' );
+					var key_td = document.createElement( 'td' );
+					var value_td = document.createElement( 'td' );
+					
+					// Create a cute summary.
+					var summ = wgConfigureThrottleSummary;
+					summ = summ.replace( '$1', countField.value );
+					summ = summ.replace( '$2', periodField.value );
+					key_td.appendChild( document.createTextNode( typeDesc ) );
+					value_td.appendChild( document.createTextNode( summ ) );
+					
+					tr.appendChild( key_td );
+					tr.appendChild( value_td );
+					
+					table.appendChild( tr );
+				}
+			}
+		} else {
+			var labels = div.getElementsByTagName( 'label' );
+			for( var i=0; i<labels.length; ++i ) {
+				var label = labels[i];
+				var arrayfield = document.getElementById( label.htmlFor );
 				
-				key_td.appendChild( document.createTextNode( getInnerText( label ) ) );
-				value_td.appendChild( document.createTextNode( arrayfield.value ) );
-				
-				tr.appendChild( key_td );
-				tr.appendChild( value_td );
-				
-				table.appendChild( tr );
+				if ( arrayfield && arrayfield.value ) {
+					rows = true;
+					
+					tr = document.createElement( 'tr' );
+					var key_td = document.createElement( 'td' );
+					var value_td = document.createElement( 'td' );
+					
+					key_td.appendChild( document.createTextNode( getInnerText( label ) ) );
+					value_td.appendChild( document.createTextNode( arrayfield.value ) );
+					
+					tr.appendChild( key_td );
+					tr.appendChild( value_td );
+					
+					table.appendChild( tr );
+				}
 			}
 		}
 		
@@ -438,6 +471,7 @@
 		}
 		
 		summary.appendChild( table );
+	} else if ( isType( 'configure-rate-limits-action' ) ) {
 	} else {
 		summary.appendChild( document.createTextNode( 'Useless type:'+elementType ) );
 	}
Index: trunk/extensions/Configure/Configure.settings-core.php
===================================================================
--- trunk/extensions/Configure/Configure.settings-core.php	(revision 44222)
+++ trunk/extensions/Configure/Configure.settings-core.php	(revision 44223)
@@ -766,7 +766,7 @@
 	'wgWhitelistRead' => 'simple',
 	'wgSpamRegex' => 'simple',
 # Rate limits
-	'wgRateLimits' => 'array',
+	'wgRateLimits' => 'rate-limits',
 	'wgRateLimitsExcludedGroups' => 'simple',
 # Proxies
 	'wgProxyList' => 'simple',

Comments

#Comment by Aaron Schulz (Talk | contribs)   16:41, 4 December 2008

Seems to work

Status & tagging log

Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox