up liste changements récents

This commit is contained in:
Tykayn 2025-08-31 23:12:38 +02:00 committed by tykayn
parent a59113400c
commit 58848a78ab
6 changed files with 1339 additions and 234 deletions

View file

@ -111,6 +111,7 @@ class WikiController extends AbstractController
// Initialize arrays
$recentChanges = [];
$lastUpdated = null;
$teamMembers = [];
// Check if the recent changes file exists and load it
if (file_exists($recentChangesFile)) {
@ -119,6 +120,9 @@ class WikiController extends AbstractController
if (isset($recentChangesData['recent_changes']) && is_array($recentChangesData['recent_changes'])) {
$recentChanges = $recentChangesData['recent_changes'];
$lastUpdated = isset($recentChangesData['last_updated']) ? $recentChangesData['last_updated'] : null;
// Process team members statistics
$teamMembers = $this->processTeamMembersStats($recentChanges);
}
// Check if the data is older than 1 hour
@ -147,9 +151,69 @@ class WikiController extends AbstractController
return $this->render('admin/wiki_recent_changes.html.twig', [
'recent_changes' => $recentChanges,
'last_updated' => $lastUpdated
'last_updated' => $lastUpdated,
'team_members' => $teamMembers
]);
}
/**
* Process team members statistics from recent changes data
*
* @param array $recentChanges Recent changes data
* @return array Team members statistics
*/
private function processTeamMembersStats(array $recentChanges): array
{
$teamMembers = [];
// Group changes by user and count modifications
foreach ($recentChanges as $change) {
$user = $change['user'];
$changeSize = $change['change_size'];
// Initialize user data if not exists
if (!isset($teamMembers[$user])) {
$teamMembers[$user] = [
'username' => $user,
'contributions' => 0,
'chars_added' => 0,
'chars_changed' => 0,
'chars_deleted' => 0,
'user_url' => "https://wiki.openstreetmap.org/wiki/User:" . urlencode($user)
];
}
// Increment contribution count
$teamMembers[$user]['contributions']++;
// Process change size
if (is_numeric($changeSize)) {
$changeSize = (int) $changeSize;
if ($changeSize > 0) {
$teamMembers[$user]['chars_added'] += $changeSize;
} elseif ($changeSize < 0) {
$teamMembers[$user]['chars_deleted'] += abs($changeSize);
} else {
// Change size is 0, might be a new page or other change
$teamMembers[$user]['chars_changed'] += 0;
}
} elseif (preg_match('/^\+(\d+)$/', $changeSize, $matches)) {
// Format like "+123"
$teamMembers[$user]['chars_added'] += (int) $matches[1];
} elseif (preg_match('/^(\d+)$/', $changeSize, $matches)) {
// Format like "123" (note: this is not a regular minus sign)
$teamMembers[$user]['chars_deleted'] += (int) $matches[1];
}
}
// Convert to indexed array and sort by contributions count (descending)
$teamMembers = array_values($teamMembers);
usort($teamMembers, function($a, $b) {
return $b['contributions'] - $a['contributions'];
});
return $teamMembers;
}
/**
* Refresh the recent changes data by running the fetch_recent_changes.py script