enwikipedia-acc /
waca
| 1 | <?php |
||
| 2 | /****************************************************************************** |
||
| 3 | * Wikipedia Account Creation Assistance tool * |
||
| 4 | * * |
||
| 5 | * All code in this file is released into the public domain by the ACC * |
||
| 6 | * Development Team. Please see team.json for a list of contributors. * |
||
| 7 | ******************************************************************************/ |
||
| 8 | |||
| 9 | namespace Waca\Helpers; |
||
| 10 | |||
| 11 | use Exception; |
||
| 12 | use PDO; |
||
| 13 | use Waca\DataObject; |
||
| 14 | use Waca\DataObjects\Ban; |
||
| 15 | use Waca\DataObjects\Comment; |
||
| 16 | use Waca\DataObjects\Domain; |
||
| 17 | use Waca\DataObjects\EmailTemplate; |
||
| 18 | use Waca\DataObjects\JobQueue; |
||
| 19 | use Waca\DataObjects\Log; |
||
| 20 | use Waca\DataObjects\Request; |
||
| 21 | use Waca\DataObjects\RequestForm; |
||
| 22 | use Waca\DataObjects\RequestQueue; |
||
| 23 | use Waca\DataObjects\User; |
||
| 24 | use Waca\DataObjects\WelcomeTemplate; |
||
| 25 | use Waca\Helpers\SearchHelpers\LogSearchHelper; |
||
| 26 | use Waca\Helpers\SearchHelpers\UserSearchHelper; |
||
| 27 | use Waca\PdoDatabase; |
||
| 28 | use Waca\Security\SecurityManager; |
||
| 29 | use Waca\SiteConfiguration; |
||
| 30 | |||
| 31 | class LogHelper |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * Summary of getRequestLogsWithComments |
||
| 35 | * |
||
| 36 | * @param int $requestId |
||
| 37 | * @param PdoDatabase $db |
||
| 38 | * @param SecurityManager $securityManager |
||
| 39 | * |
||
| 40 | * @return DataObject[] |
||
| 41 | */ |
||
| 42 | public static function getRequestLogsWithComments($requestId, PdoDatabase $db, SecurityManager $securityManager) |
||
| 43 | { |
||
| 44 | // FIXME: domains |
||
| 45 | $logs = LogSearchHelper::get($db, 1)->byObjectType('Request')->byObjectId($requestId)->fetch(); |
||
| 46 | |||
| 47 | $currentUser = User::getCurrent($db); |
||
| 48 | $showRestrictedComments = $securityManager->allows('RequestData', 'seeRestrictedComments', $currentUser) === SecurityManager::ALLOWED; |
||
| 49 | $showCheckuserComments = $securityManager->allows('RequestData', 'seeCheckuserComments', $currentUser) === SecurityManager::ALLOWED; |
||
| 50 | |||
| 51 | $comments = Comment::getForRequest($requestId, $db, $showRestrictedComments, $showCheckuserComments, $currentUser->getId()); |
||
| 52 | |||
| 53 | $items = array_merge($logs, $comments); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param DataObject $item |
||
| 57 | * |
||
| 58 | * @return int |
||
| 59 | */ |
||
| 60 | $sortKey = function(DataObject $item) { |
||
| 61 | if ($item instanceof Log) { |
||
| 62 | return $item->getTimestamp()->getTimestamp(); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($item instanceof Comment) { |
||
| 66 | return $item->getTime()->getTimestamp(); |
||
| 67 | } |
||
| 68 | |||
| 69 | return 0; |
||
| 70 | }; |
||
| 71 | |||
| 72 | do { |
||
| 73 | $flag = false; |
||
| 74 | |||
| 75 | $loopLimit = (count($items) - 1); |
||
| 76 | for ($i = 0; $i < $loopLimit; $i++) { |
||
| 77 | // are these two items out of order? |
||
| 78 | if ($sortKey($items[$i]) > $sortKey($items[$i + 1])) { |
||
| 79 | // swap them |
||
| 80 | $swap = $items[$i]; |
||
| 81 | $items[$i] = $items[$i + 1]; |
||
| 82 | $items[$i + 1] = $swap; |
||
| 83 | |||
| 84 | // set a flag to say we've modified the array this time around |
||
| 85 | $flag = true; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | while ($flag); |
||
| 90 | |||
| 91 | return $items; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Summary of getLogDescription |
||
| 96 | * |
||
| 97 | * @param Log $entry |
||
| 98 | * |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public static function getLogDescription(Log $entry) |
||
| 102 | { |
||
| 103 | $text = "Deferred to "; |
||
| 104 | if (substr($entry->getAction(), 0, strlen($text)) == $text) { |
||
| 105 | // Deferred to a different queue |
||
| 106 | // This is exactly what we want to display. |
||
| 107 | return $entry->getAction(); |
||
| 108 | } |
||
| 109 | |||
| 110 | $text = "Closed custom-n"; |
||
| 111 | if ($entry->getAction() == $text) { |
||
| 112 | // Custom-closed |
||
| 113 | return "closed (custom reason - account not created)"; |
||
| 114 | } |
||
| 115 | |||
| 116 | $text = "Closed custom-y"; |
||
| 117 | if ($entry->getAction() == $text) { |
||
| 118 | // Custom-closed |
||
| 119 | return "closed (custom reason - account created)"; |
||
| 120 | } |
||
| 121 | |||
| 122 | $text = "Closed 0"; |
||
| 123 | if ($entry->getAction() == $text) { |
||
| 124 | // Dropped the request - short-circuit the lookup |
||
| 125 | return "dropped request"; |
||
| 126 | } |
||
| 127 | |||
| 128 | $text = "Closed "; |
||
| 129 | if (substr($entry->getAction(), 0, strlen($text)) == $text) { |
||
| 130 | // Closed with a reason - do a lookup here. |
||
| 131 | $id = substr($entry->getAction(), strlen($text)); |
||
| 132 | /** @var EmailTemplate $template */ |
||
| 133 | $template = EmailTemplate::getById((int)$id, $entry->getDatabase()); |
||
| 134 | |||
| 135 | if ($template != false) { |
||
| 136 | return "closed (" . $template->getName() . ")"; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | // Fall back to the basic stuff |
||
| 141 | $lookup = array( |
||
| 142 | 'Reserved' => 'reserved', |
||
| 143 | 'Email Confirmed' => 'email-confirmed', |
||
| 144 | 'Manually Confirmed' => 'manually confirmed the request', |
||
| 145 | 'Unreserved' => 'unreserved', |
||
| 146 | 'Approved' => 'approved', |
||
| 147 | 'Suspended' => 'suspended', |
||
| 148 | 'RoleChange' => 'changed roles', |
||
| 149 | 'Banned' => 'banned', |
||
| 150 | 'Edited' => 'edited interface message', |
||
| 151 | 'Declined' => 'declined', |
||
| 152 | 'EditComment-c' => 'edited a comment', |
||
| 153 | 'EditComment-r' => 'edited a comment', |
||
| 154 | 'FlaggedComment' => 'flagged a comment', |
||
| 155 | 'UnflaggedComment' => 'unflagged a comment', |
||
| 156 | 'Unbanned' => 'unbanned', |
||
| 157 | 'Promoted' => 'promoted to tool admin', |
||
| 158 | 'BreakReserve' => 'forcibly broke the reservation', |
||
| 159 | 'Prefchange' => 'changed user preferences', |
||
| 160 | 'Renamed' => 'renamed', |
||
| 161 | 'Demoted' => 'demoted from tool admin', |
||
| 162 | 'ReceiveReserved' => 'received the reservation', |
||
| 163 | 'SendReserved' => 'sent the reservation', |
||
| 164 | 'EditedEmail' => 'edited email', |
||
| 165 | 'DeletedTemplate' => 'deleted template', |
||
| 166 | 'EditedTemplate' => 'edited template', |
||
| 167 | 'CreatedEmail' => 'created email', |
||
| 168 | 'CreatedTemplate' => 'created template', |
||
| 169 | 'SentMail' => 'sent an email to the requester', |
||
| 170 | 'Registered' => 'registered a tool account', |
||
| 171 | 'JobIssue' => 'ran a background job unsuccessfully', |
||
| 172 | 'JobCompleted' => 'completed a background job', |
||
| 173 | 'JobAcknowledged' => 'acknowledged a job failure', |
||
| 174 | 'JobRequeued' => 'requeued a job for re-execution', |
||
| 175 | 'JobCancelled' => 'cancelled execution of a job', |
||
| 176 | 'EnqueuedJobQueue' => 'scheduled for creation', |
||
| 177 | 'Hospitalised' => 'sent to the hospital', |
||
| 178 | 'QueueCreated' => 'created a request queue', |
||
| 179 | 'QueueEdited' => 'edited a request queue', |
||
| 180 | 'DomainCreated' => 'created a domain', |
||
| 181 | 'DomainEdited' => 'edited a domain', |
||
| 182 | 'RequestFormCreated' => 'created a request form', |
||
| 183 | 'RequestFormEdited' => 'edited a request form', |
||
| 184 | ); |
||
| 185 | |||
| 186 | if (array_key_exists($entry->getAction(), $lookup)) { |
||
| 187 | return $lookup[$entry->getAction()]; |
||
| 188 | } |
||
| 189 | |||
| 190 | // OK, I don't know what this is. Fall back to something sane. |
||
| 191 | return "performed an unknown action ({$entry->getAction()})"; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @param PdoDatabase $database |
||
| 196 | * |
||
| 197 | * @return array |
||
| 198 | */ |
||
| 199 | public static function getLogActions(PdoDatabase $database) |
||
| 200 | { |
||
| 201 | $lookup = array( |
||
| 202 | "Requests" => [ |
||
| 203 | 'Reserved' => 'reserved', |
||
| 204 | 'Email Confirmed' => 'email-confirmed', |
||
| 205 | 'Manually Confirmed' => 'manually confirmed', |
||
| 206 | 'Unreserved' => 'unreserved', |
||
| 207 | 'EditComment-c' => 'edited a comment (by comment ID)', |
||
| 208 | 'EditComment-r' => 'edited a comment (by request)', |
||
| 209 | 'FlaggedComment' => 'flagged a comment', |
||
| 210 | 'UnflaggedComment' => 'unflagged a comment', |
||
| 211 | 'BreakReserve' => 'forcibly broke the reservation', |
||
| 212 | 'ReceiveReserved' => 'received the reservation', |
||
| 213 | 'SendReserved' => 'sent the reservation', |
||
| 214 | 'SentMail' => 'sent an email to the requester', |
||
| 215 | 'Closed 0' => 'dropped request', |
||
| 216 | 'Closed custom-y' => 'closed (custom reason - account created)', |
||
| 217 | 'Closed custom-n' => 'closed (custom reason - account not created)', |
||
| 218 | ], |
||
| 219 | 'Users' => [ |
||
| 220 | 'Approved' => 'approved', |
||
| 221 | 'Suspended' => 'suspended', |
||
| 222 | 'RoleChange' => 'changed roles', |
||
| 223 | 'Declined' => 'declined', |
||
| 224 | 'Prefchange' => 'changed user preferences', |
||
| 225 | 'Renamed' => 'renamed', |
||
| 226 | 'Promoted' => 'promoted to tool admin', |
||
| 227 | 'Demoted' => 'demoted from tool admin', |
||
| 228 | 'Registered' => 'registered a tool account', |
||
| 229 | ], |
||
| 230 | "Bans" => [ |
||
| 231 | 'Banned' => 'banned', |
||
| 232 | 'Unbanned' => 'unbanned', |
||
| 233 | ], |
||
| 234 | "Site notice" => [ |
||
| 235 | 'Edited' => 'edited interface message', |
||
| 236 | ], |
||
| 237 | "Email close templates" => [ |
||
| 238 | 'EditedEmail' => 'edited email', |
||
| 239 | 'CreatedEmail' => 'created email', |
||
| 240 | ], |
||
| 241 | "Welcome templates" => [ |
||
| 242 | 'DeletedTemplate' => 'deleted template', |
||
| 243 | 'EditedTemplate' => 'edited template', |
||
| 244 | 'CreatedTemplate' => 'created template', |
||
| 245 | ], |
||
| 246 | "Job queue" => [ |
||
| 247 | 'JobIssue' => 'ran a background job unsuccessfully', |
||
| 248 | 'JobCompleted' => 'completed a background job', |
||
| 249 | 'JobAcknowledged' => 'acknowledged a job failure', |
||
| 250 | 'JobRequeued' => 'requeued a job for re-execution', |
||
| 251 | 'JobCancelled' => 'cancelled execution of a job', |
||
| 252 | 'EnqueuedJobQueue' => 'scheduled for creation', |
||
| 253 | 'Hospitalised' => 'sent to the hospital', |
||
| 254 | ], |
||
| 255 | "Request queues" => [ |
||
| 256 | 'QueueCreated' => 'created a request queue', |
||
| 257 | 'QueueEdited' => 'edited a request queue', |
||
| 258 | ], |
||
| 259 | "Domains" => [ |
||
| 260 | 'DomainCreated' => 'created a domain', |
||
| 261 | 'DomainEdited' => 'edited a domain', |
||
| 262 | ], |
||
| 263 | "Request forms" => [ |
||
| 264 | 'RequestFormCreated' => 'created a request form', |
||
| 265 | 'RequestFormEdited' => 'edited a request form', |
||
| 266 | ], |
||
| 267 | ); |
||
| 268 | |||
| 269 | $databaseDrivenLogKeys = $database->query(<<<SQL |
||
| 270 | SELECT CONCAT('Closed ', id) AS k, CONCAT('closed (',name,')') AS v FROM emailtemplate |
||
| 271 | UNION ALL |
||
| 272 | SELECT CONCAT('Deferred to ', logname) AS k, CONCAT('deferred to ', displayname) AS v FROM requestqueue; |
||
| 273 | SQL |
||
| 274 | ); |
||
| 275 | foreach ($databaseDrivenLogKeys->fetchAll(PDO::FETCH_ASSOC) as $row) { |
||
| 276 | $lookup["Requests"][$row['k']] = $row['v']; |
||
| 277 | } |
||
| 278 | |||
| 279 | return $lookup; |
||
| 280 | } |
||
| 281 | |||
| 282 | public static function getObjectTypes() |
||
| 283 | { |
||
| 284 | return array( |
||
| 285 | 'Ban' => 'Ban', |
||
| 286 | 'Comment' => 'Comment', |
||
| 287 | 'EmailTemplate' => 'Email template', |
||
| 288 | 'JobQueue' => 'Job queue item', |
||
| 289 | 'Request' => 'Request', |
||
| 290 | 'SiteNotice' => 'Site notice', |
||
| 291 | 'User' => 'User', |
||
| 292 | 'WelcomeTemplate' => 'Welcome template', |
||
| 293 | 'RequestQueue' => 'Request queue', |
||
| 294 | 'Domain' => 'Domain', |
||
| 295 | 'RequestForm' => 'Request form' |
||
| 296 | ); |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * This returns a HTML |
||
| 301 | * |
||
| 302 | * @param string $objectId |
||
| 303 | * @param string $objectType |
||
| 304 | * @param PdoDatabase $database |
||
| 305 | * @param SiteConfiguration $configuration |
||
| 306 | * |
||
| 307 | * @return null|string |
||
| 308 | * @category Security-Critical |
||
| 309 | */ |
||
| 310 | private static function getObjectDescription( |
||
| 311 | $objectId, |
||
| 312 | $objectType, |
||
| 313 | PdoDatabase $database, |
||
| 314 | SiteConfiguration $configuration |
||
| 315 | ) { |
||
| 316 | if ($objectType == '') { |
||
| 317 | return null; |
||
| 318 | } |
||
| 319 | |||
| 320 | $baseurl = $configuration->getBaseUrl(); |
||
| 321 | |||
| 322 | switch ($objectType) { |
||
| 323 | case 'Ban': |
||
| 324 | /** @var Ban $ban */ |
||
| 325 | $ban = Ban::getById($objectId, $database); |
||
| 326 | |||
| 327 | if ($ban === false) { |
||
| 328 | return 'Ban #' . $objectId; |
||
| 329 | } |
||
| 330 | |||
| 331 | return <<<HTML |
||
| 332 | <a href="{$baseurl}/internal.php/bans/show?id={$objectId}">Ban #{$objectId}</a> |
||
| 333 | HTML; |
||
| 334 | case 'EmailTemplate': |
||
| 335 | /** @var EmailTemplate $emailTemplate */ |
||
| 336 | $emailTemplate = EmailTemplate::getById($objectId, $database); |
||
| 337 | |||
| 338 | if ($emailTemplate === false) { |
||
| 339 | return 'Email Template #' . $objectId; |
||
| 340 | } |
||
| 341 | |||
| 342 | $name = htmlentities($emailTemplate->getName(), ENT_COMPAT, 'UTF-8'); |
||
| 343 | |||
| 344 | return <<<HTML |
||
| 345 | <a href="{$baseurl}/internal.php/emailManagement/view?id={$objectId}">Email Template #{$objectId} ({$name})</a> |
||
| 346 | HTML; |
||
| 347 | case 'SiteNotice': |
||
| 348 | return "<a href=\"{$baseurl}/internal.php/siteNotice\">the site notice</a>"; |
||
| 349 | case 'Request': |
||
| 350 | /** @var Request $request */ |
||
| 351 | $request = Request::getById($objectId, $database); |
||
| 352 | |||
| 353 | if ($request === false) { |
||
| 354 | return 'Request #' . $objectId; |
||
| 355 | } |
||
| 356 | |||
| 357 | $name = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
||
| 358 | |||
| 359 | return <<<HTML |
||
| 360 | <a href="{$baseurl}/internal.php/viewRequest?id={$objectId}">Request #{$objectId} ({$name})</a> |
||
| 361 | HTML; |
||
| 362 | case 'User': |
||
| 363 | /** @var User $user */ |
||
| 364 | $user = User::getById($objectId, $database); |
||
| 365 | |||
| 366 | // Some users were merged out of existence |
||
| 367 | if ($user === false) { |
||
| 368 | return 'User #' . $objectId; |
||
| 369 | } |
||
| 370 | |||
| 371 | $username = htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'); |
||
| 372 | |||
| 373 | return "<a href=\"{$baseurl}/internal.php/statistics/users/detail?user={$objectId}\">{$username}</a>"; |
||
| 374 | case 'WelcomeTemplate': |
||
| 375 | /** @var WelcomeTemplate $welcomeTemplate */ |
||
| 376 | $welcomeTemplate = WelcomeTemplate::getById($objectId, $database); |
||
| 377 | |||
| 378 | // some old templates have been completely deleted and lost to the depths of time. |
||
| 379 | if ($welcomeTemplate === false) { |
||
| 380 | return "Welcome template #{$objectId}"; |
||
| 381 | } |
||
| 382 | else { |
||
| 383 | $userCode = htmlentities($welcomeTemplate->getUserCode(), ENT_COMPAT, 'UTF-8'); |
||
| 384 | |||
| 385 | return "<a href=\"{$baseurl}/internal.php/welcomeTemplates/view?template={$objectId}\">{$userCode}</a>"; |
||
| 386 | } |
||
| 387 | case 'JobQueue': |
||
| 388 | /** @var JobQueue $job */ |
||
| 389 | $job = JobQueue::getById($objectId, $database); |
||
| 390 | |||
| 391 | $taskDescriptions = JobQueue::getTaskDescriptions(); |
||
| 392 | |||
| 393 | if ($job === false) { |
||
| 394 | return 'Job Queue Task #' . $objectId; |
||
| 395 | } |
||
| 396 | |||
| 397 | $task = $job->getTask(); |
||
| 398 | if (isset($taskDescriptions[$task])) { |
||
| 399 | $description = $taskDescriptions[$task]; |
||
| 400 | } |
||
| 401 | else { |
||
| 402 | $description = 'Unknown task'; |
||
| 403 | } |
||
| 404 | |||
| 405 | return "<a href=\"{$baseurl}/internal.php/jobQueue/view?id={$objectId}\">Job #{$job->getId()} ({$description})</a>"; |
||
| 406 | case 'RequestQueue': |
||
| 407 | /** @var RequestQueue $queue */ |
||
| 408 | $queue = RequestQueue::getById($objectId, $database); |
||
| 409 | |||
| 410 | if ($queue === false) { |
||
| 411 | return "Request Queue #{$objectId}"; |
||
| 412 | } |
||
| 413 | |||
| 414 | $queueHeader = htmlentities($queue->getHeader(), ENT_COMPAT, 'UTF-8'); |
||
| 415 | |||
| 416 | return "<a href=\"{$baseurl}/internal.php/queueManagement/edit?queue={$objectId}\">{$queueHeader}</a>"; |
||
| 417 | case 'Domain': |
||
| 418 | /** @var Domain $domain */ |
||
| 419 | $domain = Domain::getById($objectId, $database); |
||
| 420 | |||
| 421 | if ($domain === false) { |
||
| 422 | return "Domain #{$objectId}"; |
||
| 423 | } |
||
| 424 | |||
| 425 | $domainName = htmlentities($domain->getShortName(), ENT_COMPAT, 'UTF-8'); |
||
| 426 | return "<a href=\"{$baseurl}/internal.php/domainManagement/edit?domain={$objectId}\">{$domainName}</a>"; |
||
| 427 | case 'RequestForm': |
||
| 428 | /** @var RequestForm $queue */ |
||
| 429 | $queue = RequestForm::getById($objectId, $database); |
||
| 430 | |||
| 431 | if ($queue === false) { |
||
| 432 | return "Request Form #{$objectId}"; |
||
| 433 | } |
||
| 434 | |||
| 435 | $formName = htmlentities($queue->getName(), ENT_COMPAT, 'UTF-8'); |
||
| 436 | |||
| 437 | return "<a href=\"{$baseurl}/internal.php/requestFormManagement/edit?form={$objectId}\">{$formName}</a>"; |
||
| 438 | case 'Comment': |
||
| 439 | /** @var Comment $comment */ |
||
| 440 | $comment = Comment::getById($objectId, $database); |
||
| 441 | $requestName = htmlentities(Request::getById($comment->getRequest(), $database)->getName(), ENT_COMPAT, 'UTF-8'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 442 | |||
| 443 | return "<a href=\"{$baseurl}/internal.php/editComment?id={$objectId}\">Comment {$objectId}</a> on request <a href=\"{$baseurl}/internal.php/viewRequest?id={$comment->getRequest()}#comment-{$objectId}\">#{$comment->getRequest()} ({$requestName})</a>"; |
||
| 444 | default: |
||
| 445 | return '[' . $objectType . " " . $objectId . ']'; |
||
| 446 | } |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @param Log[] $logs |
||
| 451 | * @param PdoDatabase $database |
||
| 452 | * @param SiteConfiguration $configuration |
||
| 453 | * |
||
| 454 | * @return array |
||
| 455 | * @throws Exception |
||
| 456 | */ |
||
| 457 | public static function prepareLogsForTemplate($logs, PdoDatabase $database, SiteConfiguration $configuration) |
||
| 458 | { |
||
| 459 | $userIds = array(); |
||
| 460 | |||
| 461 | foreach ($logs as $logEntry) { |
||
| 462 | if (!$logEntry instanceof Log) { |
||
| 463 | // if this happens, we've done something wrong with passing back the log data. |
||
| 464 | throw new Exception('Log entry is not an instance of a Log, this should never happen.'); |
||
| 465 | } |
||
| 466 | |||
| 467 | $user = $logEntry->getUser(); |
||
| 468 | if ($user === -1) { |
||
| 469 | continue; |
||
| 470 | } |
||
| 471 | |||
| 472 | if (!array_search($user, $userIds)) { |
||
| 473 | $userIds[] = $user; |
||
| 474 | } |
||
| 475 | } |
||
| 476 | |||
| 477 | $users = UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'); |
||
| 478 | $users[-1] = User::getCommunity()->getUsername(); |
||
| 479 | |||
| 480 | $logData = array(); |
||
| 481 | |||
| 482 | foreach ($logs as $logEntry) { |
||
| 483 | $objectDescription = self::getObjectDescription($logEntry->getObjectId(), $logEntry->getObjectType(), |
||
| 484 | $database, $configuration); |
||
| 485 | |||
| 486 | // initialise to sane default |
||
| 487 | $comment = null; |
||
| 488 | |||
| 489 | switch ($logEntry->getAction()) { |
||
| 490 | case 'Renamed': |
||
| 491 | $renameData = unserialize($logEntry->getComment()); |
||
| 492 | $oldName = htmlentities($renameData['old'], ENT_COMPAT, 'UTF-8'); |
||
| 493 | $newName = htmlentities($renameData['new'], ENT_COMPAT, 'UTF-8'); |
||
| 494 | $comment = 'Renamed \'' . $oldName . '\' to \'' . $newName . '\'.'; |
||
| 495 | break; |
||
| 496 | case 'RoleChange': |
||
| 497 | $roleChangeData = unserialize($logEntry->getComment()); |
||
| 498 | |||
| 499 | $removed = array(); |
||
| 500 | foreach ($roleChangeData['removed'] as $r) { |
||
| 501 | $removed[] = htmlentities($r, ENT_COMPAT, 'UTF-8'); |
||
| 502 | } |
||
| 503 | |||
| 504 | $added = array(); |
||
| 505 | foreach ($roleChangeData['added'] as $r) { |
||
| 506 | $added[] = htmlentities($r, ENT_COMPAT, 'UTF-8'); |
||
| 507 | } |
||
| 508 | |||
| 509 | $reason = htmlentities($roleChangeData['reason'], ENT_COMPAT, 'UTF-8'); |
||
| 510 | |||
| 511 | $roleDelta = 'Removed [' . implode(', ', $removed) . '], Added [' . implode(', ', $added) . ']'; |
||
| 512 | $comment = $roleDelta . ' with comment: ' . $reason; |
||
| 513 | break; |
||
| 514 | case 'JobIssue': |
||
| 515 | $jobIssueData = unserialize($logEntry->getComment()); |
||
| 516 | $errorMessage = $jobIssueData['error']; |
||
| 517 | $status = $jobIssueData['status']; |
||
| 518 | |||
| 519 | $comment = 'Job ' . htmlentities($status, ENT_COMPAT, 'UTF-8') . ': '; |
||
| 520 | $comment .= htmlentities($errorMessage, ENT_COMPAT, 'UTF-8'); |
||
| 521 | break; |
||
| 522 | case 'JobIssueRequest': |
||
| 523 | case 'JobCompletedRequest': |
||
| 524 | $jobData = unserialize($logEntry->getComment()); |
||
| 525 | |||
| 526 | /** @var JobQueue $job */ |
||
| 527 | $job = JobQueue::getById($jobData['job'], $database); |
||
| 528 | $descs = JobQueue::getTaskDescriptions(); |
||
| 529 | $comment = htmlentities($descs[$job->getTask()], ENT_COMPAT, 'UTF-8'); |
||
| 530 | break; |
||
| 531 | |||
| 532 | case 'JobCompleted': |
||
| 533 | break; |
||
| 534 | default: |
||
| 535 | $comment = $logEntry->getComment(); |
||
| 536 | break; |
||
| 537 | } |
||
| 538 | |||
| 539 | $logData[] = array( |
||
| 540 | 'timestamp' => $logEntry->getTimestamp(), |
||
| 541 | 'userid' => $logEntry->getUser(), |
||
| 542 | 'username' => $users[$logEntry->getUser()], |
||
| 543 | 'description' => self::getLogDescription($logEntry), |
||
| 544 | 'objectdescription' => $objectDescription, |
||
| 545 | 'comment' => $comment, |
||
| 546 | ); |
||
| 547 | } |
||
| 548 | |||
| 549 | return array($users, $logData); |
||
| 550 | } |
||
| 551 | } |
||
| 552 |