Jump to content

Wikia code/includes/api/ApiQueryRecentChanges.php

From mediawiki.org
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\api\ApiQueryRecentChanges.php	2011-07-30 00:54:26.165039000 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\api\ApiQueryRecentChanges.php	2011-08-17 15:28:14.185546900 +0100
@@ -170,6 +171,12 @@
 			// * the != condition doesn't throw out too many rows anyway
 			$this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
 
+		//  *** Wikia change (@author ADi) *** /Begin
+		if(!is_null($params['user'])) {
+			$this->addWhereFld('rc_user_text', $this->prepareUsername( $params['user'] ));
+		}
+		// *** Wikia change (@author ADi) *** /End
+
 		/* Add the fields we're concerned with to our query. */
 		$this->addFields( array (
 			'rc_timestamp',
@@ -187,6 +194,7 @@
 
 			/* Set up internal members based upon params. */
 			$this->initProperties( $prop );
+			$this->fld_wikiamode = isset($prop['wikiamode']);
 
 			global $wgUser;
 			if ( $this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() )
@@ -269,6 +277,32 @@
 	}
 
 	/**
+	 * (Wikia) Validate the 'user' parameter
+	 * @param string $userName user name
+	 * @author ADi
+	 */
+	private function prepareUsername( $userName ) {
+		if( $userName ) {
+			$userName = User::getCanonicalName( $userName, 'valid' );
+			if( $userName === false ) {
+				$this->dieUsage( "User name {$userName} is not valid", 'param_user' );
+			}
+			else {
+				$userId = User::idFromName( $userName );
+				if( empty( $userId ) ) {
+					$this->dieUsage( "User name {$userName} not found", 'param_user' );
+				}
+				else {
+					return $userName;
+				}
+			}
+		}
+		else {
+			$this->dieUsage( 'User parameter may not be empty', 'param_user' );
+		}
+	}
+
+	/**
 	 * Extracts from a single sql row the data needed to describe one recent change.
 	 *
 	 * @param $row The row from which to extract the data.
@@ -402,6 +436,10 @@
 			}
 		}
 
+		if($this->fld_wikiamode) {
+			$vals['rc_params'] = $row->rc_params;
+		}
+
 		return $vals;
 	}
 
@@ -481,6 +519,7 @@
 					'redirect',
 					'patrolled',
 					'loginfo',
+					'wikiamode',
 					'tags'
 				)
 			),
@@ -517,7 +556,12 @@
 					'new',
 					'log'
 				)
+			),
+			//  *** Wikia change (@author ADi) *** /Begin
+			'user' => array (
+				ApiBase :: PARAM_ISMULTI => false,
 			)
+			//  *** Wikia change (@author ADi) *** /End
 		);
 	}
 
@@ -536,6 +580,7 @@
 				'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
 			),
 			'type' => 'Which types of changes to show.',
+			'user' => 'Filter results per user name',
 			'limit' => 'How many total changes to return.',
 			'tag' => 'Only list changes tagged with this tag.',
 		);
@@ -560,6 +605,6 @@
 	}
 
 	public function getVersion() {
-		return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 93049 2011-07-25 15:37:22Z maxsem $';
+		return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 69932 2010-07-26 08:03:21Z tstarling $';
 	}
 }