3 * Holders of revision list for a single page
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.
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.
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
23 use MediaWiki\MediaWikiServices
;
26 * Abstract base class for revision items
28 abstract class RevisionItemBase
{
29 /** @var RevisionListBase The parent */
32 /** The database result row */
36 * @param RevisionListBase $list
37 * @param object $row DB result row
39 public function __construct( $list, $row ) {
45 * Get the DB field name associated with the ID list.
46 * Override this function.
49 public function getIdField() {
54 * Get the DB field name storing timestamps.
55 * Override this function.
58 public function getTimestampField() {
63 * Get the DB field name storing user ids.
64 * Override this function.
67 public function getAuthorIdField() {
72 * Get the DB field name storing user names.
73 * Override this function.
76 public function getAuthorNameField() {
81 * Get the DB field name storing actor ids.
82 * Override this function.
86 public function getAuthorActorField() {
91 * Get the ID, as it would appear in the ids URL parameter
94 public function getId() {
95 $field = $this->getIdField();
96 return $this->row
->$field;
100 * Get the date, formatted in user's language
103 public function formatDate() {
104 return $this->list->getLanguage()->userDate( $this->getTimestamp(),
105 $this->list->getUser() );
109 * Get the time, formatted in user's language
112 public function formatTime() {
113 return $this->list->getLanguage()->userTime( $this->getTimestamp(),
114 $this->list->getUser() );
118 * Get the timestamp in MW 14-char form
121 public function getTimestamp() {
122 $field = $this->getTimestampField();
123 return wfTimestamp( TS_MW
, $this->row
->$field );
127 * Get the author user ID
130 public function getAuthorId() {
131 $field = $this->getAuthorIdField();
132 return intval( $this->row
->$field );
136 * Get the author user name
139 public function getAuthorName() {
140 $field = $this->getAuthorNameField();
141 return strval( $this->row
->$field );
145 * Get the author actor ID
149 public function getAuthorActor() {
150 $field = $this->getAuthorActorField();
151 return strval( $this->row
->$field );
155 * Returns true if the current user can view the item
157 abstract public function canView();
160 * Returns true if the current user can view the item text/file
162 abstract public function canViewContent();
165 * Get the HTML of the list item. Should be include "<li></li>" tags.
166 * This is used to show the list in HTML form, by the special page.
168 abstract public function getHTML();
171 * Returns an instance of LinkRenderer
172 * @return \MediaWiki\Linker\LinkRenderer
174 protected function getLinkRenderer() {
175 return MediaWikiServices
::getInstance()->getLinkRenderer();