RevDelLogItem.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @ingroup RevisionDelete
  20. */
  21. /**
  22. * Item class for a logging table row
  23. */
  24. class RevDelLogItem extends RevDelItem {
  25. public function getIdField() {
  26. return 'log_id';
  27. }
  28. public function getTimestampField() {
  29. return 'log_timestamp';
  30. }
  31. public function getAuthorIdField() {
  32. return 'log_user';
  33. }
  34. public function getAuthorNameField() {
  35. return 'log_user_text';
  36. }
  37. public function getAuthorActorField() {
  38. return 'log_actor';
  39. }
  40. public function canView() {
  41. return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
  42. }
  43. public function canViewContent() {
  44. return true; // none
  45. }
  46. public function getBits() {
  47. return (int)$this->row->log_deleted;
  48. }
  49. public function setBits( $bits ) {
  50. $dbw = wfGetDB( DB_MASTER );
  51. $dbw->update( 'logging',
  52. [ 'log_deleted' => $bits ],
  53. [
  54. 'log_id' => $this->row->log_id,
  55. 'log_deleted' => $this->getBits() // cas
  56. ],
  57. __METHOD__
  58. );
  59. if ( !$dbw->affectedRows() ) {
  60. // Concurrent fail!
  61. return false;
  62. }
  63. $dbw->update( 'recentchanges',
  64. [
  65. 'rc_deleted' => $bits,
  66. 'rc_patrolled' => RecentChange::PRC_PATROLLED
  67. ],
  68. [
  69. 'rc_logid' => $this->row->log_id,
  70. 'rc_timestamp' => $this->row->log_timestamp // index
  71. ],
  72. __METHOD__
  73. );
  74. return true;
  75. }
  76. public function getHTML() {
  77. $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate(
  78. $this->row->log_timestamp, $this->list->getUser() ) );
  79. $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title );
  80. $formatter = LogFormatter::newFromRow( $this->row );
  81. $formatter->setContext( $this->list->getContext() );
  82. $formatter->setAudience( LogFormatter::FOR_THIS_USER );
  83. // Log link for this page
  84. $loglink = $this->getLinkRenderer()->makeLink(
  85. SpecialPage::getTitleFor( 'Log' ),
  86. $this->list->msg( 'log' )->text(),
  87. [],
  88. [ 'page' => $title->getPrefixedText() ]
  89. );
  90. $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped();
  91. // User links and action text
  92. $action = $formatter->getActionText();
  93. // Comment
  94. $comment = CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
  95. $comment = $this->list->getLanguage()->getDirMark()
  96. . Linker::commentBlock( $comment );
  97. if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
  98. $comment = '<span class="history-deleted">' . $comment . '</span>';
  99. }
  100. return "<li>$loglink $date $action $comment</li>";
  101. }
  102. public function getApiData( ApiResult $result ) {
  103. $logEntry = DatabaseLogEntry::newFromRow( $this->row );
  104. $user = $this->list->getUser();
  105. $ret = [
  106. 'id' => $logEntry->getId(),
  107. 'type' => $logEntry->getType(),
  108. 'action' => $logEntry->getSubtype(),
  109. 'userhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_USER ),
  110. 'commenthidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_COMMENT ),
  111. 'actionhidden' => (bool)$logEntry->isDeleted( LogPage::DELETED_ACTION ),
  112. ];
  113. if ( LogEventsList::userCan( $this->row, LogPage::DELETED_ACTION, $user ) ) {
  114. $ret['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
  115. }
  116. if ( LogEventsList::userCan( $this->row, LogPage::DELETED_USER, $user ) ) {
  117. $ret += [
  118. 'userid' => $this->row->log_user,
  119. 'user' => $this->row->log_user_text,
  120. ];
  121. }
  122. if ( LogEventsList::userCan( $this->row, LogPage::DELETED_COMMENT, $user ) ) {
  123. $ret += [
  124. 'comment' => CommentStore::getStore()->getComment( 'log_comment', $this->row )
  125. ->text,
  126. ];
  127. }
  128. return $ret;
  129. }
  130. }