RevisionItem.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Holders of revision list for a single page
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. */
  22. use MediaWiki\Revision\RevisionRecord;
  23. /**
  24. * Item class for a live revision table row
  25. */
  26. class RevisionItem extends RevisionItemBase {
  27. /** @var Revision */
  28. protected $revision;
  29. /** @var RequestContext */
  30. protected $context;
  31. public function __construct( $list, $row ) {
  32. parent::__construct( $list, $row );
  33. $this->revision = new Revision( $row );
  34. $this->context = $list->getContext();
  35. }
  36. public function getIdField() {
  37. return 'rev_id';
  38. }
  39. public function getTimestampField() {
  40. return 'rev_timestamp';
  41. }
  42. public function getAuthorIdField() {
  43. return 'rev_user';
  44. }
  45. public function getAuthorNameField() {
  46. return 'rev_user_text';
  47. }
  48. public function canView() {
  49. return $this->revision->userCan(
  50. RevisionRecord::DELETED_RESTRICTED, $this->context->getUser()
  51. );
  52. }
  53. public function canViewContent() {
  54. return $this->revision->userCan(
  55. RevisionRecord::DELETED_TEXT, $this->context->getUser()
  56. );
  57. }
  58. public function isDeleted() {
  59. return $this->revision->isDeleted( RevisionRecord::DELETED_TEXT );
  60. }
  61. /**
  62. * Get the HTML link to the revision text.
  63. * @todo Essentially a copy of RevDelRevisionItem::getRevisionLink. That class
  64. * should inherit from this one, and implement an appropriate interface instead
  65. * of extending RevDelItem
  66. * @return string
  67. */
  68. protected function getRevisionLink() {
  69. $date = $this->list->getLanguage()->userTimeAndDate(
  70. $this->revision->getTimestamp(), $this->list->getUser() );
  71. if ( $this->isDeleted() && !$this->canViewContent() ) {
  72. return htmlspecialchars( $date );
  73. }
  74. $linkRenderer = $this->getLinkRenderer();
  75. return $linkRenderer->makeKnownLink(
  76. $this->list->title,
  77. $date,
  78. [],
  79. [
  80. 'oldid' => $this->revision->getId(),
  81. 'unhide' => 1
  82. ]
  83. );
  84. }
  85. /**
  86. * Get the HTML link to the diff.
  87. * @todo Essentially a copy of RevDelRevisionItem::getDiffLink. That class
  88. * should inherit from this one, and implement an appropriate interface instead
  89. * of extending RevDelItem
  90. * @return string
  91. */
  92. protected function getDiffLink() {
  93. if ( $this->isDeleted() && !$this->canViewContent() ) {
  94. return $this->context->msg( 'diff' )->escaped();
  95. } else {
  96. $linkRenderer = $this->getLinkRenderer();
  97. return $linkRenderer->makeKnownLink(
  98. $this->list->title,
  99. $this->list->msg( 'diff' )->text(),
  100. [],
  101. [
  102. 'diff' => $this->revision->getId(),
  103. 'oldid' => 'prev',
  104. 'unhide' => 1
  105. ]
  106. );
  107. }
  108. }
  109. /**
  110. * @todo Essentially a copy of RevDelRevisionItem::getHTML. That class
  111. * should inherit from this one, and implement an appropriate interface instead
  112. * of extending RevDelItem
  113. * @return string
  114. */
  115. public function getHTML() {
  116. $difflink = $this->context->msg( 'parentheses' )
  117. ->rawParams( $this->getDiffLink() )->escaped();
  118. $revlink = $this->getRevisionLink();
  119. $userlink = Linker::revUserLink( $this->revision );
  120. $comment = Linker::revComment( $this->revision );
  121. if ( $this->isDeleted() ) {
  122. $revlink = "<span class=\"history-deleted\">$revlink</span>";
  123. }
  124. return "<li>$difflink $revlink $userlink $comment</li>";
  125. }
  126. }