RevisionItemBase.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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\MediaWikiServices;
  23. /**
  24. * Abstract base class for revision items
  25. */
  26. abstract class RevisionItemBase {
  27. /** @var RevisionListBase The parent */
  28. protected $list;
  29. /** The database result row */
  30. protected $row;
  31. /**
  32. * @param RevisionListBase $list
  33. * @param object $row DB result row
  34. */
  35. public function __construct( $list, $row ) {
  36. $this->list = $list;
  37. $this->row = $row;
  38. }
  39. /**
  40. * Get the DB field name associated with the ID list.
  41. * Override this function.
  42. * @return null
  43. */
  44. public function getIdField() {
  45. return null;
  46. }
  47. /**
  48. * Get the DB field name storing timestamps.
  49. * Override this function.
  50. * @return bool
  51. */
  52. public function getTimestampField() {
  53. return false;
  54. }
  55. /**
  56. * Get the DB field name storing user ids.
  57. * Override this function.
  58. * @return bool
  59. */
  60. public function getAuthorIdField() {
  61. return false;
  62. }
  63. /**
  64. * Get the DB field name storing user names.
  65. * Override this function.
  66. * @return bool
  67. */
  68. public function getAuthorNameField() {
  69. return false;
  70. }
  71. /**
  72. * Get the DB field name storing actor ids.
  73. * Override this function.
  74. * @since 1.31
  75. * @return bool
  76. */
  77. public function getAuthorActorField() {
  78. return false;
  79. }
  80. /**
  81. * Get the ID, as it would appear in the ids URL parameter
  82. * @return int
  83. */
  84. public function getId() {
  85. $field = $this->getIdField();
  86. return $this->row->$field;
  87. }
  88. /**
  89. * Get the date, formatted in user's language
  90. * @return string
  91. */
  92. public function formatDate() {
  93. return $this->list->getLanguage()->userDate( $this->getTimestamp(),
  94. $this->list->getUser() );
  95. }
  96. /**
  97. * Get the time, formatted in user's language
  98. * @return string
  99. */
  100. public function formatTime() {
  101. return $this->list->getLanguage()->userTime( $this->getTimestamp(),
  102. $this->list->getUser() );
  103. }
  104. /**
  105. * Get the timestamp in MW 14-char form
  106. * @return mixed
  107. */
  108. public function getTimestamp() {
  109. $field = $this->getTimestampField();
  110. return wfTimestamp( TS_MW, $this->row->$field );
  111. }
  112. /**
  113. * Get the author user ID
  114. * @return int
  115. */
  116. public function getAuthorId() {
  117. $field = $this->getAuthorIdField();
  118. return intval( $this->row->$field );
  119. }
  120. /**
  121. * Get the author user name
  122. * @return string
  123. */
  124. public function getAuthorName() {
  125. $field = $this->getAuthorNameField();
  126. return strval( $this->row->$field );
  127. }
  128. /**
  129. * Get the author actor ID
  130. * @since 1.31
  131. * @return string
  132. */
  133. public function getAuthorActor() {
  134. $field = $this->getAuthorActorField();
  135. return strval( $this->row->$field );
  136. }
  137. /**
  138. * Returns true if the current user can view the item
  139. */
  140. abstract public function canView();
  141. /**
  142. * Returns true if the current user can view the item text/file
  143. */
  144. abstract public function canViewContent();
  145. /**
  146. * Get the HTML of the list item. Should be include "<li></li>" tags.
  147. * This is used to show the list in HTML form, by the special page.
  148. */
  149. abstract public function getHTML();
  150. /**
  151. * Returns an instance of LinkRenderer
  152. * @return \MediaWiki\Linker\LinkRenderer
  153. */
  154. protected function getLinkRenderer() {
  155. return MediaWikiServices::getInstance()->getLinkRenderer();
  156. }
  157. }