Index: wp-includes/widgets.php
===================================================================
--- wp-includes/widgets.php	(revision 32551)
+++ wp-includes/widgets.php	(working copy)
@@ -21,7 +21,7 @@
  * @subpackage Widgets
  * @since 2.8.0
  */
-class WP_Widget {
+abstract class WP_Widget {
 
 	/**
 	 * Root ID for all widgets of this type.
@@ -104,10 +104,45 @@
 	 * @param array $instance The settings for the particular instance of the widget.
 	 */
 	public function widget( $args, $instance ) {
-		die('function WP_Widget::widget() must be over-ridden in a sub-class.');
+		$this->before_widget( $args, $instance );
+		$this->widget_markup();
+		$this->after_widget( $args, $instance );
 	}
 
+
 	/**
+	 * Default treatment of before widget markup
+	 *
+	 * @param $args
+	 * @param $instance
+	 */
+	public function before_widget( $args, $instance ) {
+
+		$title = apply_filters( 'widget_title', ! isset($instance['title']  ) || empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
+
+		echo $args['before_widget'];
+		if ( $title ) {
+			echo $args['before_title'] . $title . $args['after_title'];
+		}
+	}
+
+	/**
+	 * Output the custom markup content for the widget
+	 *
+	 * Subclasses will override this to create their output
+	 */
+	public function widget_markup() {}
+
+	/**
+	 * Default treatment of after widget markup
+	 * @param $args
+	 * @param $instance
+	 */
+	public function after_widget( $args, $instance ) {
+		echo $args['after_widget'];
+	}
+
+	/**
 	 * Update a particular instance.
 	 *
 	 * This function should check that $new_instance is set correctly. The newly-calculated
@@ -136,7 +171,7 @@
 	 * @return string Default return is 'noform'.
 	 */
 	public function form($instance) {
-		echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
+		echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this widget.' ) . '</p>';
 		return 'noform';
 	}
 
@@ -157,11 +192,11 @@
 	 *                                for information on accepted arguments. Default empty array.
 	 */
 	public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
-		$this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base);
+		$this->id_base = empty( $id_base ) ? preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ) : strtolower( $id_base );
 		$this->name = $name;
 		$this->option_name = 'widget_' . $this->id_base;
-		$this->widget_options = wp_parse_args( $widget_options, array('classname' => $this->option_name) );
-		$this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) );
+		$this->widget_options = wp_parse_args( $widget_options, array( 'classname' => $this->option_name ) );
+		$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
 	}
 
 	/**
@@ -204,6 +239,7 @@
 		return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
 	}
 
+
 	/**
 	 * Register all widget instances of this widget class.
 	 *
@@ -214,11 +250,11 @@
 		$settings = $this->get_settings();
 		$empty = true;
 
-		if ( is_array($settings) ) {
-			foreach ( array_keys($settings) as $number ) {
-				if ( is_numeric($number) ) {
-					$this->_set($number);
-					$this->_register_one($number);
+		if ( is_array( $settings ) ) {
+			foreach ( array_keys( $settings ) as $number ) {
+				if ( is_numeric( $number ) ) {
+					$this->_set( $number );
+					$this->_register_one( $number );
 					$empty = false;
 				}
 			}
@@ -227,7 +263,7 @@
 		if ( $empty ) {
 			// If there are none, we register the widget's existence with a
 			// generic template
-			$this->_set(1);
+			$this->_set( 1 );
 			$this->_register_one();
 		}
 	}
@@ -247,15 +283,15 @@
 	}
 
 	public function _get_display_callback() {
-		return array($this, 'display_callback');
+		return array( $this, 'display_callback' );
 	}
 
 	public function _get_update_callback() {
-		return array($this, 'update_callback');
+		return array( $this, 'update_callback' );
 	}
 
 	public function _get_form_callback() {
-		return array($this, 'form_callback');
+		return array( $this, 'form_callback' );
 	}
 
 	/**
@@ -293,9 +329,10 @@
 	 *     @type int $number Number increment used for multiples of the same widget.
 	 * }
 	 */
-	public function display_callback( $args, $widget_args = 1 ) {
-		if ( is_numeric($widget_args) )
+	final public function display_callback( $args, $widget_args = 1 ) {
+		if ( is_numeric( $widget_args ) ) {
 			$widget_args = array( 'number' => $widget_args );
+		}
 
 		$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
 		$this->_set( $widget_args['number'] );
@@ -302,7 +339,7 @@
 		$instance = $this->get_settings();
 
 		if ( array_key_exists( $this->number, $instance ) ) {
-			$instance = $instance[$this->number];
+			$instance = $instance[ $this->number ];
 
 			/**
 			 * Filter the settings for a particular widget instance.
@@ -342,32 +379,35 @@
 	 *
 	 * @param int $deprecated Not used.
 	 */
-	public function update_callback( $deprecated = 1 ) {
+	final public function update_callback( $deprecated = 1 ) {
 		global $wp_registered_widgets;
 
 		$all_instances = $this->get_settings();
 
 		// We need to update the data
-		if ( $this->updated )
+		if ( $this->updated ) {
 			return;
+		}
 
 		if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
 			// Delete the settings for this instance of the widget
-			if ( isset($_POST['the-widget-id']) )
+			if ( isset( $_POST['the-widget-id'] ) ) {
 				$del_id = $_POST['the-widget-id'];
-			else
+			} else {
 				return;
+			}
 
-			if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
-				$number = $wp_registered_widgets[$del_id]['params'][0]['number'];
+			if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number']) ) {
+				$number = $wp_registered_widgets[ $del_id ]['params'][0]['number'];
 
-				if ( $this->id_base . '-' . $number == $del_id )
-					unset($all_instances[$number]);
+				if ( $this->id_base . '-' . $number == $del_id ) {
+					unset( $all_instances[ $number ] );
+				}
 			}
 		} else {
-			if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
+			if ( isset( $_POST['widget-' . $this->id_base] ) && is_array( $_POST['widget-' . $this->id_base] ) ) {
 				$settings = $_POST['widget-' . $this->id_base];
-			} elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {
+			} elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] == $this->id_base ) {
 				$num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
 				$settings = array( $num => array() );
 			} else {
@@ -375,10 +415,10 @@
 			}
 
 			foreach ( $settings as $number => $new_instance ) {
-				$new_instance = stripslashes_deep($new_instance);
-				$this->_set($number);
+				$new_instance = stripslashes_deep( $new_instance );
+				$this->_set( $number );
 
-				$old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
+				$old_instance = isset( $all_instances[ $number ]) ? $all_instances[ $number ] : array();
 
 				$was_cache_addition_suspended = wp_suspend_cache_addition();
 				if ( $this->is_preview() && ! $was_cache_addition_suspended ) {
@@ -406,7 +446,7 @@
 				 */
 				$instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this );
 				if ( false !== $instance ) {
-					$all_instances[$number] = $instance;
+					$all_instances[ $number ] = $instance;
 				}
 
 				break; // run only once
@@ -413,7 +453,7 @@
 			}
 		}
 
-		$this->save_settings($all_instances);
+		$this->save_settings( $all_instances );
 		$this->updated = true;
 	}
 
@@ -425,9 +465,10 @@
 	 *
 	 * @param int|array $widget_args Widget instance number or array of widget arguments.
 	 */
-	public function form_callback( $widget_args = 1 ) {
-		if ( is_numeric($widget_args) )
+	final public function form_callback( $widget_args = 1 ) {
+		if ( is_numeric( $widget_args ) ) {
 			$widget_args = array( 'number' => $widget_args );
+		}
 
 		$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
 		$all_instances = $this->get_settings();
@@ -434,10 +475,10 @@
 
 		if ( -1 == $widget_args['number'] ) {
 			// We echo out a form where 'number' can be set later
-			$this->_set('__i__');
+			$this->_set( '__i__' );
 			$instance = array();
 		} else {
-			$this->_set($widget_args['number']);
+			$this->_set( $widget_args['number'] );
 			$instance = $all_instances[ $widget_args['number'] ];
 		}
 
@@ -455,7 +496,7 @@
 
 		$return = null;
 		if ( false !== $instance ) {
-			$return = $this->form($instance);
+			$return = $this->form( $instance );
 
 			/**
 			 * Fires at the end of the widget control form.
@@ -516,17 +557,20 @@
 	 */
 	public function get_settings() {
 
-		$settings = get_option($this->option_name);
+		$settings = get_option( $this->option_name );
 
-		if ( false === $settings && isset($this->alt_option_name) )
-			$settings = get_option($this->alt_option_name);
+		if ( false === $settings && isset( $this->alt_option_name ) ) {
+			$settings = get_option( $this->alt_option_name );
+		}
 
-		if ( !is_array($settings) )
+		if ( ! is_array( $settings ) ) {
 			$settings = array();
+		}
 
-		if ( !empty($settings) && !array_key_exists('_multiwidget', $settings) ) {
+
+		if ( ! empty( $settings ) && ! array_key_exists( '_multiwidget', $settings ) ) {
 			// old format, convert if single widget
-			$settings = wp_convert_widget_settings($this->id_base, $this->option_name, $settings);
+			$settings = wp_convert_widget_settings( $this->id_base, $this->option_name, $settings );
 		}
 
 		unset($settings['_multiwidget'], $settings['__i__']);
@@ -557,7 +601,7 @@
 	 * @param string $widget_class The name of a {@see WP_Widget} subclass.
 	 */
 	public function register( $widget_class ) {
-		$this->widgets[$widget_class] = new $widget_class();
+		$this->widgets[ $widget_class ] = new $widget_class();
 	}
 
 	/**
@@ -580,18 +624,18 @@
 	 */
 	public function _register_widgets() {
 		global $wp_registered_widgets;
-		$keys = array_keys($this->widgets);
-		$registered = array_keys($wp_registered_widgets);
-		$registered = array_map('_get_widget_id_base', $registered);
+		$keys = array_keys( $this->widgets );
+		$registered = array_keys( $wp_registered_widgets );
+		$registered = array_map( '_get_widget_id_base', $registered );
 
 		foreach ( $keys as $key ) {
 			// don't register new widget if old widget with the same id is already registered
-			if ( in_array($this->widgets[$key]->id_base, $registered, true) ) {
-				unset($this->widgets[$key]);
+			if ( in_array( $this->widgets[ $key ]->id_base, $registered, true ) ) {
+				unset( $this->widgets[ $key ] );
 				continue;
 			}
 
-			$this->widgets[$key]->_register();
+			$this->widgets[ $key ]->_register();
 		}
 	}
 }
@@ -677,7 +721,7 @@
 function register_widget($widget_class) {
 	global $wp_widget_factory;
 
-	$wp_widget_factory->register($widget_class);
+	$wp_widget_factory->register( $widget_class );
 }
 
 /**
@@ -697,7 +741,7 @@
 function unregister_widget($widget_class) {
 	global $wp_widget_factory;
 
-	$wp_widget_factory->unregister($widget_class);
+	$wp_widget_factory->unregister( $widget_class );
 }
 
 /**
