RevDelRevisionItem.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 live revision table row
  23. */
  24. class RevDelRevisionItem extends RevDelItem {
  25. /** @var Revision */
  26. public $revision;
  27. public function __construct( $list, $row ) {
  28. parent::__construct( $list, $row );
  29. $this->revision = new Revision( $row );
  30. }
  31. public function getIdField() {
  32. return 'rev_id';
  33. }
  34. public function getTimestampField() {
  35. return 'rev_timestamp';
  36. }
  37. public function getAuthorIdField() {
  38. return 'rev_user';
  39. }
  40. public function getAuthorNameField() {
  41. return 'rev_user_text';
  42. }
  43. public function getAuthorActorField() {
  44. return 'rev_actor';
  45. }
  46. public function canView() {
  47. return $this->revision->userCan( Revision::DELETED_RESTRICTED, $this->list->getUser() );
  48. }
  49. public function canViewContent() {
  50. return $this->revision->userCan( Revision::DELETED_TEXT, $this->list->getUser() );
  51. }
  52. public function getBits() {
  53. return $this->revision->getVisibility();
  54. }
  55. public function setBits( $bits ) {
  56. $dbw = wfGetDB( DB_MASTER );
  57. // Update revision table
  58. $dbw->update( 'revision',
  59. [ 'rev_deleted' => $bits ],
  60. [
  61. 'rev_id' => $this->revision->getId(),
  62. 'rev_page' => $this->revision->getPage(),
  63. 'rev_deleted' => $this->getBits() // cas
  64. ],
  65. __METHOD__
  66. );
  67. if ( !$dbw->affectedRows() ) {
  68. // Concurrent fail!
  69. return false;
  70. }
  71. // Update recentchanges table
  72. $dbw->update( 'recentchanges',
  73. [
  74. 'rc_deleted' => $bits,
  75. 'rc_patrolled' => RecentChange::PRC_PATROLLED
  76. ],
  77. [
  78. 'rc_this_oldid' => $this->revision->getId(), // condition
  79. // non-unique timestamp index
  80. 'rc_timestamp' => $dbw->timestamp( $this->revision->getTimestamp() ),
  81. ],
  82. __METHOD__
  83. );
  84. return true;
  85. }
  86. public function isDeleted() {
  87. return $this->revision->isDeleted( Revision::DELETED_TEXT );
  88. }
  89. public function isHideCurrentOp( $newBits ) {
  90. return ( $newBits & Revision::DELETED_TEXT )
  91. && $this->list->getCurrent() == $this->getId();
  92. }
  93. /**
  94. * Get the HTML link to the revision text.
  95. * Overridden by RevDelArchiveItem.
  96. * @return string
  97. */
  98. protected function getRevisionLink() {
  99. $date = $this->list->getLanguage()->userTimeAndDate(
  100. $this->revision->getTimestamp(), $this->list->getUser() );
  101. if ( $this->isDeleted() && !$this->canViewContent() ) {
  102. return htmlspecialchars( $date );
  103. }
  104. return $this->getLinkRenderer()->makeKnownLink(
  105. $this->list->title,
  106. $date,
  107. [],
  108. [
  109. 'oldid' => $this->revision->getId(),
  110. 'unhide' => 1
  111. ]
  112. );
  113. }
  114. /**
  115. * Get the HTML link to the diff.
  116. * Overridden by RevDelArchiveItem
  117. * @return string
  118. */
  119. protected function getDiffLink() {
  120. if ( $this->isDeleted() && !$this->canViewContent() ) {
  121. return $this->list->msg( 'diff' )->escaped();
  122. } else {
  123. return $this->getLinkRenderer()->makeKnownLink(
  124. $this->list->title,
  125. $this->list->msg( 'diff' )->text(),
  126. [],
  127. [
  128. 'diff' => $this->revision->getId(),
  129. 'oldid' => 'prev',
  130. 'unhide' => 1
  131. ]
  132. );
  133. }
  134. }
  135. /**
  136. * @return string A HTML <li> element representing this revision, showing
  137. * change tags and everything
  138. */
  139. public function getHTML() {
  140. $difflink = $this->list->msg( 'parentheses' )
  141. ->rawParams( $this->getDiffLink() )->escaped();
  142. $revlink = $this->getRevisionLink();
  143. $userlink = Linker::revUserLink( $this->revision );
  144. $comment = Linker::revComment( $this->revision );
  145. if ( $this->isDeleted() ) {
  146. $revlink = "<span class=\"history-deleted\">$revlink</span>";
  147. }
  148. $content = "$difflink $revlink $userlink $comment";
  149. $attribs = [];
  150. $tags = $this->getTags();
  151. if ( $tags ) {
  152. list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow(
  153. $tags,
  154. 'revisiondelete',
  155. $this->list->getContext()
  156. );
  157. $content .= " $tagSummary";
  158. $attribs['class'] = implode( ' ', $classes );
  159. }
  160. return Xml::tags( 'li', $attribs, $content );
  161. }
  162. /**
  163. * @return string Comma-separated list of tags
  164. */
  165. public function getTags() {
  166. return $this->row->ts_tags;
  167. }
  168. public function getApiData( ApiResult $result ) {
  169. $rev = $this->revision;
  170. $user = $this->list->getUser();
  171. $ret = [
  172. 'id' => $rev->getId(),
  173. 'timestamp' => wfTimestamp( TS_ISO_8601, $rev->getTimestamp() ),
  174. 'userhidden' => (bool)$rev->isDeleted( Revision::DELETED_USER ),
  175. 'commenthidden' => (bool)$rev->isDeleted( Revision::DELETED_COMMENT ),
  176. 'texthidden' => (bool)$rev->isDeleted( Revision::DELETED_TEXT ),
  177. ];
  178. if ( $rev->userCan( Revision::DELETED_USER, $user ) ) {
  179. $ret += [
  180. 'userid' => $rev->getUser( Revision::FOR_THIS_USER ),
  181. 'user' => $rev->getUserText( Revision::FOR_THIS_USER ),
  182. ];
  183. }
  184. if ( $rev->userCan( Revision::DELETED_COMMENT, $user ) ) {
  185. $ret += [
  186. 'comment' => $rev->getComment( Revision::FOR_THIS_USER ),
  187. ];
  188. }
  189. return $ret;
  190. }
  191. }