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