User:Jack Phoenix/patches/RandomUsersWithAvatars

Index: RandomUsersWithAvatars.i18n.php

=
====================================================== --- RandomUsersWithAvatars.i18n.php	(revision 115) +++ RandomUsersWithAvatars.i18n.php	(working copy) @@ -1,12 +1,22 @@  array( -		'random-users-avatars-title'=>'Meet the Community', -		), -	); -} +$messages = array; -?> +/** English + * @author Wikia, Inc. + */ +$messages['en'] = array( +	'random-users-avatars-title' => 'Meet the Community', +); + +/** Finnish (Suomi) + * @author Jack Phoenix + */ +$messages['fi'] = array( +	'random-users-avatars-title' => 'Tapaa yhteisö', +); \ No newline at end of file Index: RandomUsersWithAvatars.php

=
====================================================== --- RandomUsersWithAvatars.php	(revision 115) +++ RandomUsersWithAvatars.php	(working copy) @@ -1,63 +1,88 @@ <?php -$wgExtensionFunctions[] = "wfRandomUsersWithAvatars"; +/** + * Protect against register_globals vulnerabilities. + * This line must be present before any global variable is referenced. + */ +if ( ! defined( 'MEDIAWIKI' ) ) +	die; +//Avoid unstubbing $wgParser too early on modern (1.12+) MW versions, as per r35980 +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { +	$wgHooks['ParserFirstCallInit'][] = 'wfRandomUsersWithAvatars'; +} else { +	$wgExtensionFunctions[] = 'wfRandomUsersWithAvatars'; +} + +$wgExtensionCredits['parserhook'][] = array( +	'name' => 'RandomUsersWithAvatars', +	'version' => '1.0', +	'author' => 'Wikia New York Team', +	'description' => 'Adds &lt;randomuserswithavatars&gt; tag to display the avatars of randomly chosen users', +	'url' => 'http://www.mediawiki.org/wiki/Extension:RandomUsersWithAvatars' +); + +$dir = dirname(__FILE__). '/'; +$wgExtensionMessagesFiles['RandomUsersWithAvatars'] = $dir. 'RandomUsersWithAvatars.i18n.php'; + function wfRandomUsersWithAvatars { global $wgParser, $wgOut; -   $wgParser->setHook( "randomuserswithavatars", "GetRandomUsersWithAvatars" ); +   $wgParser->setHook( 'randomuserswithavatars', 'GetRandomUsersWithAvatars' ); +	return true; } function GetRandomUsersWithAvatars( $input, $args, &$parser ){ global $wgUser, $wgParser, $wgTitle, $wgOut, $wgUploadDirectory, $wgDBname, $wgMemc; +	wfLoadExtensionMessages('RandomUsersWithAvatars'); wfProfileIn(__METHOD__); -	+ 	$parser->disableCache; $count = $args["count"]; $per_row = $args["row"]; if(!is_numeric($count) ) $count = 10; if(!is_numeric($per_row) ) $per_row = 4; -	+ 	//try cache $key = wfMemcKey( 'users', 'random', 'avatars', $count, $per_row ); $data = $wgMemc->get( $key ); if( !$data ){ $files = glob($wgUploadDirectory . "/avatars/{$wgDBname}_*_ml.*"); $wgMemc->set( $key, $files, 60 * 60); -	}else{ +	} else { wfDebug("Got random users with avatars from cache\n"); $files = $data; } 	$user_array = array; $random_users = array; -	+ 	$output = " -		 ".wfMsg("random-users-avatars-title")." "; +		 ".wfMsg('random-users-avatars-title')." "; -	$x=1; -	+	$x = 1; + 	if( count( $files ) < $count)$count = count($files); 	if( $count > 0 ) { 		$random_keys = array_rand($files, $count); 	} else { 		$random_keys = array; 	} -	+ 	foreach ($random_keys as $random) { -		+ 		//extract userid out of avatar image name 		$avatar_name = basename( $files[$random] ); 		preg_match("/{$wgDBname}_(.*)_/i", $avatar_name, $matches); 		$user_id = $matches[1]; -		+ 		if( $user_id ){ 			//load user 			$user = User::newFromId( $user_id ); 			$user->loadFromDatabase; 			$user_name = $user->getName;	-			$avatar = new wAvatar($user_id,"ml"); +			$avatar = new wAvatar($user_id, "ml"); 			$user_link = Title::makeTitle(NS_USER, $user_name); 			$output .= "escapeFullURL."\" rel=\"nofollow\">{$avatar->getAvatarURL}"; @@ -74,6 +99,4 @@ 	wfProfileIn(__METHOD__); 	return $output; -} - -?> +} \ No newline at end of file