Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php	(revision 19199)
+++ wp-includes/rewrite.php	(working copy)
@@ -200,11 +200,17 @@
 define('EP_ALL', 8191);
 
 /**
- * Add an endpoint, like /trackback/.
+ * Add an endpoint, like /foo/bar/
  *
- * The endpoints are added to the end of the request. So a request matching
- * "/2008/10/14/my_post/myep/", the endpoint will be "/myep/".
+ * The endpoint query variable ('foo' in this example) gets set to the value trailing the
+ * endpoint ('bar' in this example).
  *
+ * If the $allow_empty parameter is true then the endpoint query variable will be set to
+ * string 'true' when accessing the endpoint without a trailing value (eg. /foo/).
+ *
+ * The endpoints are added to the end of the request. So for a request matching
+ * "/2008/10/14/my_post/foo/", the endpoint will be "/foo/".
+ *
  * Be sure to flush the rewrite rules (wp_rewrite->flush_rules()) when your plugin gets
  * activated (register_activation_hook()) and deactivated (register_deactivation_hook())
  *
@@ -212,12 +218,13 @@
  * @see WP_Rewrite::add_endpoint() Parameters and more description.
  * @uses $wp_rewrite
  *
- * @param unknown_type $name
- * @param unknown_type $places
+ * @param string $name The endpoint name (which is also the query variable)
+ * @param int|array $places An endpoint mask or array of endpoint masks
+ * @param bool $allow_empty Whether to allow an endpoint with no trailing value
  */
-function add_rewrite_endpoint($name, $places) {
+function add_rewrite_endpoint($name, $places, $allow_empty = false) {
 	global $wp_rewrite;
-	$wp_rewrite->add_endpoint($name, $places);
+	$wp_rewrite->add_endpoint($name, $places, $allow_empty);
 }
 
 /**
@@ -1204,11 +1211,21 @@
 		if ( $endpoints ) {
 			$ep_query_append = array ();
 			foreach ( (array) $this->endpoints as $endpoint) {
+
+				if ( isset( $endpoint[2] ) and $endpoint[2] ) {
+					//allow endpoints with no trailing value
+					$epmatch = $endpoint[1] . '/?$';
+					//this will be appended on to the rest of the query for each dir
+					$epquery = '&' . $endpoint[1] . '=true';
+					$ep_query_append[$epmatch] = array ( $endpoint[0], $epquery, true );
+				}
+
 				//match everything after the endpoint name, but allow for nothing to appear there
 				$epmatch = $endpoint[1] . '(/(.*))?/?$';
 				//this will be appended on to the rest of the query for each dir
 				$epquery = '&' . $endpoint[1] . '=';
 				$ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
+
 			}
 		}
 
@@ -1326,8 +1343,12 @@
 			if ( $endpoints ) {
 				foreach ( (array) $ep_query_append as $regex => $ep) {
 					//add the endpoints on if the mask fits
-					if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific )
-						$rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
+					if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) {
+						if ( isset( $ep[2] ) and $ep[2] )
+							$rewrite[$match . $regex] = $index . '?' . $query . $ep[1];
+						else
+							$rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
+					}
 				}
 			}
 
@@ -1815,12 +1836,13 @@
 	 * @since 2.1.0
 	 * @access public
 	 *
-	 * @param string $name Name of endpoint.
-	 * @param array $places URL types that endpoint can be used.
+	 * @param string $name The endpoint name (which is also the query variable)
+	 * @param int|array $places An endpoint mask or array of endpoint masks
+	 * @param bool $allow_empty Whether to allow an endpoint with no trailing value
 	 */
-	function add_endpoint($name, $places) {
+	function add_endpoint($name, $places, $allow_empty = false) {
 		global $wp;
-		$this->endpoints[] = array ( $places, $name );
+		$this->endpoints[] = array ( $places, $name, $allow_empty );
 		$wp->add_query_var($name);
 	}
 
