Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 5012)
+++ wp-includes/query.php	(working copy)
@@ -377,15 +377,15 @@
 		if ( !empty($query) || !isset($this->query) ) {
 			$this->init();
 			if ( is_array($query) )
-				$qv = & $query;
+				$this->query_vars = $query;
 			else
-				parse_str($query, $qv);
+				parse_str($query, $this->query_vars);
 			$this->query = $query;
-			$this->query_vars = $qv;
-		}
+			}
+			
+			$this->query_vars = $this->fill_query_vars($this->query_vars); 
+			$qv = &$this->query_vars;
 		
-		$qv = $this->fill_query_vars($qv);
-		
 		if ( ! empty($qv['robots']) ) {
 			$this->is_robots = true;
 			return;
@@ -398,9 +398,17 @@
 			}
 			return;
 		}
-
+		
+		$qv['p'] =  (int) $qv['p']; 
+ 	  $qv['page_id'] =  (int) $qv['page_id']; 
+ 	  $qv['year'] = (int) $qv['year']; 
+ 	  $qv['monthnum'] = (int) $qv['monthnum']; 
+ 	  $qv['day'] = (int) $qv['day']; 
+ 	  $qv['w'] = (int) $qv['w'];
 		$qv['m'] =  (int) $qv['m'];
-		$qv['p'] =  (int) $qv['p'];
+		if ( '' != $qv['hour'] ) $qv['hour'] = (int) $qv['hour']; 
+ 	  if ( '' != $qv['minute'] ) $qv['minute'] = (int) $qv['minute']; 
+ 	  if ( '' != $qv['second'] ) $qv['second'] = (int) $qv['second'];
 
 		// Compat.  Map subpost to attachment.
 		if ( '' != $qv['subpost'] )
@@ -408,62 +416,65 @@
 		if ( '' != $qv['subpost_id'] )
 			$qv['attachment_id'] = $qv['subpost_id'];
 
-		if ( ('' != $qv['attachment']) || (int) $qv['attachment_id'] ) {
+		$qv['attachment_id'] = (int) $qv['attachment_id'];
+		        
+ 	  if ( ('' != $qv['attachment']) || !empty($qv['attachment_id']) ) {
 			$this->is_single = true;
 			$this->is_attachment = true;
-		} elseif ('' != $qv['name']) {
+		} elseif ( '' != $qv['name'] ) { 
 			$this->is_single = true;
 		} elseif ( $qv['p'] ) {
 			$this->is_single = true;
-		} elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) {
+		} elseif ( ('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day']) )
+		{
 			// If year, month, day, hour, minute, and second are set, a single
 			// post is being queried.
 			$this->is_single = true;
-		} elseif ('' != $qv['static'] || '' != $qv['pagename'] || (int) $qv['page_id']) {
+		} elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) { 
 			$this->is_page = true;
 			$this->is_single = false;
-		} elseif (!empty($qv['s'])) {
+		} elseif ( !empty($qv['s']) ) {
 			$this->is_search = true;
 		} else {
 		// Look for archive queries.  Dates, categories, authors.
 
-			if ( (int) $qv['second']) {
+			if ( '' != $qv['second'] ) { 
 				$this->is_time = true;
 				$this->is_date = true;
 			}
 
-			if ( (int) $qv['minute']) {
+			if ( '' != $qv['minute'] ) { 
 				$this->is_time = true;
 				$this->is_date = true;
 			}
 
-			if ( (int) $qv['hour']) {
+			if ( '' != $qv['hour'] ) { 
 				$this->is_time = true;
 				$this->is_date = true;
 			}
 
-			if ( (int) $qv['day']) {
+			if ( $qv['day'] ) { 
 				if (! $this->is_date) {
 					$this->is_day = true;
 					$this->is_date = true;
 				}
 			}
 
-			if ( (int)  $qv['monthnum']) {
+			if ( $qv['monthnum'] ) { 
 				if (! $this->is_date) {
 					$this->is_month = true;
 					$this->is_date = true;
 				}
 			}
 
-			if ( (int)  $qv['year']) {
+			if ( $qv['year'] ) { 
 				if (! $this->is_date) {
 					$this->is_year = true;
 					$this->is_date = true;
 				}
 			}
 
-			if ( (int)  $qv['m']) {
+			if ( $qv['m'] ) { 
 				$this->is_date = true;
 				if (strlen($qv['m']) > 9) {
 					$this->is_time = true;
@@ -480,7 +491,7 @@
 				$this->is_date = true;
 			}
 
-			if (empty($qv['cat']) || ($qv['cat'] == '0')) {
+			if ( empty($qv['cat']) || ($qv['cat'] == '0') ) { 
 				$this->is_category = false;
 			} else {
 				if (stristr($qv['cat'],'-')) {
@@ -490,60 +501,51 @@
 				}
 			}
 
-			if ('' != $qv['category_name']) {
+			if ( '' != $qv['category_name'] ) { 
 				$this->is_category = true;
 			}
 
-			if ((empty($qv['author'])) || ($qv['author'] == '0')) {
+			if ( empty($qv['author']) || ($qv['author'] == '0') ) {
 				$this->is_author = false;
 			} else {
 				$this->is_author = true;
 			}
 
-			if ('' != $qv['author_name']) {
+			if ( '' != $qv['author_name'] ) { 
 				$this->is_author = true;
 			}
 
-			if ( ($this->is_date || $this->is_author || $this->is_category)) {
+			if ( ($this->is_date || $this->is_author || $this->is_category) )
 				$this->is_archive = true;
 			}
-		}
-
-		if ('' != $qv['feed']) {
+			
+		if ( '' != $qv['feed'] )
 			$this->is_feed = true;
-		}
-
-		if ('' != $qv['tb']) {
+		
+		if ( '' != $qv['tb'] ) 
 			$this->is_trackback = true;
-		}
-
-		if ('' != $qv['paged']) {
+			
+		if ( '' != $qv['paged'] ) 
 			$this->is_paged = true;
-		}
 
-		if ('' != $qv['comments_popup']) {
+		if ( '' != $qv['comments_popup'] )
 			$this->is_comments_popup = true;
-		}
 
 		//if we're previewing inside the write screen
-		if ('' != $qv['preview']) {
+		if ('' != $qv['preview']) 
 			$this->is_preview = true;
-		}
 
-		if (strstr($_SERVER['PHP_SELF'], 'wp-admin/')) {
+		if ( strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) 
 			$this->is_admin = true;
-		}
 
 		if ( $this->is_single || $this->is_page || $this->is_attachment )
 			$this->is_singular = true;
 
-		if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
+		if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup))
 			$this->is_home = true;
-		}
 
-		if ( !empty($query) ) {
+		if ( !empty($query) )
 			do_action_ref_array('parse_query', array(&$this));
-		}
 	}
 
 	function set_404() {
@@ -634,7 +636,7 @@
 		$wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)";
 
 		// If a month is specified in the querystring, load that month
-		if ( (int) $q['m'] ) {
+		if ( $q['m'] ) { 
 			$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
 			$where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4);
 			if (strlen($q['m'])>5)
@@ -649,41 +651,24 @@
 				$where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2);
 		}
 
-		if ( (int) $q['hour'] ) {
-			$q['hour'] = '' . intval($q['hour']);
+		if ( '' != $q['hour'] )
 			$where .= " AND HOUR(post_date)='" . $q['hour'] . "'";
-		}
 
-		if ( (int) $q['minute'] ) {
-			$q['minute'] = '' . intval($q['minute']);
+		if ( '' != $q['minute'] )
 			$where .= " AND MINUTE(post_date)='" . $q['minute'] . "'";
-		}
 
-		if ( (int) $q['second'] ) {
-			$q['second'] = '' . intval($q['second']);
+		if ( '' != $q['second'] )
 			$where .= " AND SECOND(post_date)='" . $q['second'] . "'";
-		}
 
-		if ( (int) $q['year'] ) {
-			$q['year'] = '' . intval($q['year']);
+		if ( $q['year'] )
 			$where .= " AND YEAR(post_date)='" . $q['year'] . "'";
-		}
 
-		if ( (int) $q['monthnum'] ) {
-			$q['monthnum'] = '' . intval($q['monthnum']);
+		if ( $q['monthnum'] )
 			$where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'";
-		}
 
-		if ( (int) $q['day'] ) {
-			$q['day'] = '' . intval($q['day']);
+		if ( $q['day'] )
 			$where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'";
-		}
 
-		// Compat.  Map subpost to attachment.
-		if ( '' != $q['subpost'] )
-			$q['attachment'] = $q['subpost'];
-		if ( '' != $q['subpost_id'] )
-			$q['attachment_id'] = $q['subpost_id'];
 
 		if ('' != $q['name']) {
 			$q['name'] = sanitize_title($q['name']);
@@ -715,26 +700,21 @@
 			$where .= " AND post_name = '" . $q['attachment'] . "'";
 		}
 
-		if ( (int) $q['w'] ) {
-			$q['w'] = ''.intval($q['w']);
+		if ( $q['w'] )
 			$where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
-		}
 
 		if ( intval($q['comments_popup']) )
 			$q['p'] = intval($q['comments_popup']);
 
-		// If a attachment is requested by number, let it supercede any post number.
-		if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) )
-			$q['p'] = (int) $q['attachment_id'];
+		// If an attachment is requested by number, let it supercede any post number.
+		if ( $q['attachment_id'] ) 
+		  $q['p'] = $q['attachment_id'];
 
 		// If a post number is specified, load that post
-		if (($q['p'] != '') && intval($q['p']) != 0) {
-			$q['p'] =  (int) $q['p'];
+		if ( $q['p'] )
 			$where = ' AND ID = ' . $q['p'];
-		}
 
-		if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) {
-			$q['page_id'] = intval($q['page_id']);
+		if ( $q['page_id'] ) { 
 			if  ( ('page' == get_option('show_on_front') ) && ( $q['page_id'] == get_option('page_for_posts') ) ) {
 				$this->is_singular = false;
 				$this->is_page = false;
@@ -742,12 +722,12 @@
 				$this->is_posts_page = true;
 			} else {
 				$q['p'] = $q['page_id'];
-				$where = ' AND ID = '.$q['page_id'];
+				$where = ' AND ID = ' . $q['page_id'];
 			}
 		}
 
 		// If a search pattern is specified, load the posts that match
-		if (!empty($q['s'])) {
+		if ( !empty($q['s']) ) {
 			// added slashes screw with quote grouping when done early, so done later
 			$q['s'] = stripslashes($q['s']);
 			if ($q['sentence']) {
@@ -774,10 +754,10 @@
 
 		// Category stuff
 
-		if ((empty($q['cat'])) || ($q['cat'] == '0') ||
+		if ( empty($q['cat']) || ($q['cat'] == '0') ||
 				// Bypass cat checks if fetching specific posts
-				( $this->is_single || $this->is_page )) {
-			$whichcat='';
+				$this->is_singular ) {
+				$whichcat = '';
 		} else {
 			$q['cat'] = ''.urldecode($q['cat']).'';
 			$q['cat'] = addslashes_gpc($q['cat']);
@@ -814,7 +794,7 @@
 		}
 
 		// Category stuff for nice URLs
-		if ('' != $q['category_name']) {
+		if ( '' != $q['category_name'] ) { 
 			$reqcat = get_category_by_path($q['category_name']);
 			$q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name'])));
 			$cat_paths = '/' . trim($q['category_name'], '/');
@@ -849,7 +829,7 @@
 
 		// Author/user stuff
 
-		if ((empty($q['author'])) || ($q['author'] == '0')) {
+		if ( empty($q['author']) || ($q['author'] == '0') ) {
 			$whichauthor='';
 		} else {
 			$q['author'] = ''.urldecode($q['author']).'';
@@ -889,12 +869,11 @@
 
 		$where .= $search.$whichcat.$whichauthor;
 
-		if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) {
+		if ( empty($q['order']) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC')) )
 			$q['order']='DESC';
-		}
 
 		// Order by
-		if (empty($q['orderby'])) {
+		if ( empty($q['orderby']) ) {
 			$q['orderby'] = 'post_date '.$q['order'];
 		} else {
 			// Used to filter values
@@ -950,7 +929,7 @@
 		$join = apply_filters('posts_join', $join);
 
 		// Paging
-		if (empty($q['nopaging']) && !$this->is_singular) {
+		if ( empty($q['nopaging']) && !$this->is_singular ) {
 			$page = abs(intval($q['paged']));
 			if (empty($page)) {
 				$page = 1;

