Index: akismet.php
===================================================================
--- akismet.php	(revision 220471)
+++ akismet.php	(working copy)
@@ -11,10 +11,7 @@
 define('AKISMET_VERSION', '2.2.7');
 
 // If you hardcode a WP.com API key here, all key config screens will be hidden
-if ( defined('WPCOM_API_KEY') )
-	$wpcom_api_key = constant('WPCOM_API_KEY');
-else
-	$wpcom_api_key = '';
+$wpcom_api_key = defined('WPCOM_API_KEY') ? WPCOM_API_KEY : '';
 
 function akismet_init() {
 	global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
@@ -52,6 +49,16 @@
 	function number_format_i18n( $number, $decimals = null ) { return number_format( $number, $decimals ); }
 }
 
+if ( !function_exists('esc_url') ) {
+	function esc_url( $url ) { return clean_url( $url ); }
+}
+if ( !function_exists('esc_html') ) {
+	function esc_html( $html ) { return wp_specialchars( $html ); }
+}
+if ( !function_exists('esc_attr') ) {
+	function esc_attr( $attr ) { return attribute_escape( $attr ); }
+}
+
 function akismet_config_page() {
 	if ( function_exists('add_submenu_page') )
 		add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
@@ -61,6 +68,7 @@
 function akismet_conf() {
 	global $akismet_nonce, $wpcom_api_key;
 
+	$key_status = '';
 	if ( isset($_POST['submit']) ) {
 		if ( function_exists('current_user_can') && !current_user_can('manage_options') )
 			die(__('Cheatin&#8217; uh?'));
@@ -142,7 +150,9 @@
 	<p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?>; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
 <?php endforeach; ?>
 <p><input id="key" name="key" type="text" size="15" maxlength="12" value="<?php echo get_option('wordpress_api_key'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /> (<?php _e('<a href="http://faq.wordpress.com/2005/10/19/api-key/">What is this?</a>'); ?>)</p>
-<?php if ( $invalid_key ) { ?>
+<?php
+// This variable appears to be entirely unused. This block should be removed.
+if ( isset( $invalid_key ) && $invalid_key ) { ?>
 <h3><?php _e('Why might my key be invalid?'); ?></h3>
 <p><?php _e('This can mean one of two things, either you copied the key wrong or that the plugin is unable to reach the Akismet servers, which is most often caused by an issue with your web host around firewalls or similar.'); ?></p>
 <?php } ?>
@@ -707,7 +717,7 @@
 	echo '<p>'.__('You can delete all of the spam from your database with a single click. This operation cannot be undone, so you may wish to check to ensure that no legitimate comments got through first. Spam is automatically deleted after 15 days, so don&#8217;t sweat it.').'</p>';
 ?>
 <?php if ( !isset( $_POST['s'] ) ) { ?>
-<form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
+<form method="post" action="<?php echo esc_attr( add_query_arg( 'noheader', 'true' ) ); ?>">
 <?php akismet_nonce_field($akismet_nonce) ?>
 <input type="hidden" name="action" value="delete" />
 <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" class="button delete" name="Submit" value="<?php _e('Delete all'); ?>" />
@@ -771,16 +781,16 @@
 
 if ($comments) {
 ?>
-<form method="post" action="<?php echo attribute_escape("$link?page=akismet-admin"); ?>" id="akismetsearch">
-<p>  <input type="text" name="s" value="<?php if (isset($_POST['s'])) echo attribute_escape($_POST['s']); ?>" size="17" />
-  <input type="submit" class="button" name="submit" value="<?php echo attribute_escape(__('Search Spam &raquo;')) ?>"  />  </p>
+<form method="post" action="<?php echo esc_attr("$link?page=akismet-admin"); ?>" id="akismetsearch">
+<p>  <input type="text" name="s" value="<?php if (isset($_POST['s'])) echo esc_attr($_POST['s']); ?>" size="17" />
+  <input type="submit" class="button" name="submit" value="<?php echo esc_attr(__('Search Spam &raquo;')) ?>"  />  </p>
 </form>
 <?php if ( $total > 50 ) {
 $total_pages = ceil( $total / 50 );
 $r = '';
 if ( 1 < $page ) {
 	$args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1;
-	$r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
+	$r .=  '<a class="prev" href="' . esc_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
 }
 if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) {
 	for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
@@ -790,7 +800,7 @@
 			$p = false;
 			if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
 				$args['apage'] = ( 1 == $page_num ) ? '' : $page_num;
-				$r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
+				$r .= '<a class="page-numbers" href="' . esc_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
 				$in = true;
 			elseif ( $in == true ) :
 				$r .= "...\n";
@@ -801,13 +811,13 @@
 }
 if ( ( $page ) * 50 < $total || -1 == $total ) {
 	$args['apage'] = $page + 1;
-	$r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
+	$r .=  '<a class="next" href="' . esc_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
 }
 echo "<p>$r</p>";
 ?>
 
 <?php } ?>
-<form style="clear: both;" method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
+<form style="clear: both;" method="post" action="<?php echo esc_attr( add_query_arg( 'noheader', 'true' ) ); ?>">
 <?php akismet_nonce_field($akismet_nonce) ?>
 <input type="hidden" name="action" value="recover" />
 <ul id="spam-list" class="commentlist" style="list-style: none; margin: 0; padding: 0;">
@@ -832,7 +842,7 @@
 <?php _e('Not Spam') ?></label> &#8212; <?php comment_date('M j, g:i A');  ?> &#8212; [
 <?php
 $post = get_post($comment->comment_post_ID);
-$post_title = wp_specialchars( $post->post_title, 'double' );
+$post_title = esc_html( $post->post_title, 'double' );
 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
 ?>
  <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ] </p>
@@ -847,7 +857,7 @@
 $r = '';
 if ( 1 < $page ) {
 	$args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1;
-	$r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
+	$r .=  '<a class="prev" href="' . esc_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
 }
 if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) {
 	for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
@@ -857,7 +867,7 @@
 			$p = false;
 			if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
 				$args['apage'] = ( 1 == $page_num ) ? '' : $page_num;
-				$r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
+				$r .= '<a class="page-numbers" href="' . esc_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
 				$in = true;
 			elseif ( $in == true ) :
 				$r .= "...\n";
@@ -868,13 +878,13 @@
 }
 if ( ( $page ) * 50 < $total || -1 == $total ) {
 	$args['apage'] = $page + 1;
-	$r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
+	$r .=  '<a class="next" href="' . esc_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
 }
 echo "<p>$r</p>";
 }
 ?>
 <p class="submit">
-<input type="submit" name="submit" value="<?php echo attribute_escape(__('De-spam marked comments &raquo;')); ?>" />
+<input type="submit" name="submit" value="<?php echo esc_attr(__('De-spam marked comments &raquo;')); ?>" />
 </p>
 <p><?php _e('Comments you de-spam will be submitted to Akismet as mistakes so it can learn and get better.'); ?></p>
 </form>
@@ -885,10 +895,10 @@
 <?php } ?>
 
 <?php if ( !isset( $_POST['s'] ) ) { ?>
-<form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
+<form method="post" action="<?php echo esc_attr( add_query_arg( 'noheader', 'true' ) ); ?>">
 <?php akismet_nonce_field($akismet_nonce) ?>
 <p><input type="hidden" name="action" value="delete" />
-<?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" name="Submit" class="button" value="<?php echo attribute_escape(__('Delete all')); ?>" />
+<?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" name="Submit" class="button" value="<?php echo esc_attr(__('Delete all')); ?>" />
 <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" /></p>
 </form>
 <?php } ?>
@@ -912,7 +922,7 @@
 		$link = 'edit-comments.php';
 	else
 		$link = 'edit.php';
-	echo '<p>'.sprintf(__('<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.'), 'http://akismet.com/', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'</p>';
+	echo '<p>'.sprintf(__('<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.'), 'http://akismet.com/', esc_url("$link?page=akismet-admin"), number_format_i18n($count) ).'</p>';
 }
 
 add_action('activity_box_end', 'akismet_stats');
@@ -943,12 +953,12 @@
 			'and there\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
 			'and there are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
 			$queue_count
-		), number_format_i18n( $queue_count ), clean_url($link) );
+		), number_format_i18n( $queue_count ), esc_url($link) );
 	} else {
-		$queue_text = sprintf( __( "but there's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), clean_url($link) );
+		$queue_text = sprintf( __( "but there's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), esc_url($link) );
 	}
 
-	$text = sprintf( _c( '%1$s %2$s|akismet_rightnow' ), $intro, $queue_text );
+	$text = sprintf( function_exists( '_x' ) ? _x( '%1$s %2$s', 'akismet_rightnow' ) : _c( '%1$s %2$s|akismet_rightnow' ), $intro, $queue_text );
 
 	echo "<p class='akismet-right-now'>$text</p>\n";
 }
@@ -956,6 +966,7 @@
 add_action('rightnow_end', 'akismet_rightnow');
 
 // For WP <= 2.3.x
+global $pagenow;
 if ( 'moderation.php' == $pagenow ) {
 	function akismet_recheck_button( $page ) {
 		global $submenu;
@@ -1077,7 +1088,7 @@
 
 	function widget_akismet_control() {
 		$options = $newoptions = get_option('widget_akismet');
-		if ( $_POST["akismet-submit"] ) {
+		if ( !empty( $_POST['akismet-submit'] ) ) {
 			$newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"]));
 			if ( empty($newoptions['title']) ) $newoptions['title'] = 'Spam Blocked';
 		}
@@ -1087,13 +1098,18 @@
 		}
 		$title = htmlspecialchars($options['title'], ENT_QUOTES);
 	?>
-				<p><label for="akismet-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="akismet-title" name="akismet-title" type="text" value="<?php echo $title; ?>" /></label></p>
+				<p><label for="akismet-title"><?php _e('Title:'); ?> <input style="width: 100%" id="akismet-title" name="akismet-title" type="text" value="<?php echo $title; ?>" /></label></p>
 				<input type="hidden" id="akismet-submit" name="akismet-submit" value="1" />
 	<?php
 	}
 
-	register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
-	register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
+	if ( function_exists( 'wp_register_sidebar_widget' ) && function_exists('wp_register_widget_control') ) {
+		wp_register_sidebar_widget( 'akismet', 'Akismet', 'widget_akismet' );
+		wp_register_widget_control( 'akismet', 'Akismet', 'widget_akismet_control', array( 'height' => 75 ) );
+	} else {
+		register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
+		register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
+	}
 	if ( is_active_widget('widget_akismet') )
 		add_action('wp_head', 'widget_akismet_style');
 	endif;
