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