3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
22 protected $preventClickjacking = false;
35 * @param ImagePage $imagePage
37 function __construct( $imagePage ) {
38 parent
::__construct( $imagePage->getContext() );
39 $this->mImagePage
= $imagePage;
40 $this->mTitle
= clone $imagePage->getTitle();
41 $this->mTitle
->setFragment( '#filehistory' );
44 $this->mRange
= [ 0, 0 ]; // display range
46 // Only display 10 revisions at once by default, otherwise the list is overwhelming
47 $this->mLimitsShown
= array_merge( [ 10 ], $this->mLimitsShown
);
48 $this->setLimit( 10 );
58 function getQueryInfo() {
65 function getIndexField() {
73 function formatRow( $row ) {
83 if ( count( $this->mHist
) ) {
84 if ( $this->mImg
->isLocal() ) {
85 // Do a batch existence check for user pages and talkpages
86 $linkBatch = new LinkBatch();
87 for ( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
88 $file = $this->mHist
[$i];
89 $user = $file->getUser( 'text' );
90 $linkBatch->add( NS_USER
, $user );
91 $linkBatch->add( NS_USER_TALK
, $user );
93 $linkBatch->execute();
96 $list = new ImageHistoryList( $this->mImagePage
);
97 # Generate prev/next links
98 $navLink = $this->getNavigationBar();
99 $s = $list->beginImageHistoryList( $navLink );
100 // Skip rows there just for paging links
101 for ( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
102 $file = $this->mHist
[$i];
103 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
105 $s .= $list->endImageHistoryList( $navLink );
107 if ( $list->getPreventClickjacking() ) {
108 $this->preventClickjacking();
115 if ( $this->mQueryDone
) {
118 $this->mImg
= $this->mImagePage
->getPage()->getFile(); // ensure loading
119 if ( !$this->mImg
->exists() ) {
122 $queryLimit = $this->mLimit +
1; // limit plus extra row
123 if ( $this->mIsBackwards
) {
124 // Fetch the file history
125 $this->mHist
= $this->mImg
->getHistory( $queryLimit, null, $this->mOffset
, false );
126 // The current rev may not meet the offset/limit
127 $numRows = count( $this->mHist
);
128 if ( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
129 $this->mHist
= array_merge( [ $this->mImg
], $this->mHist
);
132 // The current rev may not meet the offset
133 if ( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
134 $this->mHist
[] = $this->mImg
;
136 // Old image versions (fetch extra row for nav links)
137 $oiLimit = count( $this->mHist
) ?
$this->mLimit
: $this->mLimit +
1;
138 // Fetch the file history
139 $this->mHist
= array_merge( $this->mHist
,
140 $this->mImg
->getHistory( $oiLimit, $this->mOffset
, null, false ) );
142 $numRows = count( $this->mHist
); // Total number of query results
144 # Index value of top item in the list
145 $firstIndex = $this->mIsBackwards ?
146 $this->mHist
[$numRows - 1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
147 # Discard the extra result row if there is one
148 if ( $numRows > $this->mLimit
&& $numRows > 1 ) {
149 if ( $this->mIsBackwards
) {
150 # Index value of item past the index
151 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
152 # Index value of bottom item in the list
153 $lastIndex = $this->mHist
[1]->getTimestamp();
155 $this->mRange
= [ 1, $numRows - 1 ];
157 # Index value of item past the index
158 $this->mPastTheEndIndex
= $this->mHist
[$numRows - 1]->getTimestamp();
159 # Index value of bottom item in the list
160 $lastIndex = $this->mHist
[$numRows - 2]->getTimestamp();
162 $this->mRange
= [ 0, $numRows - 2 ];
165 # Setting indexes to an empty string means that they will be
166 # omitted if they would otherwise appear in URLs. It just so
167 # happens that this is the right thing to do in the standard
168 # UI, in all the relevant cases.
169 $this->mPastTheEndIndex
= '';
170 # Index value of bottom item in the list
171 $lastIndex = $this->mIsBackwards ?
172 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows - 1]->getTimestamp();
174 $this->mRange
= [ 0, $numRows - 1 ];
179 $this->mPastTheEndIndex
= '';
181 if ( $this->mIsBackwards
) {
182 $this->mIsFirst
= ( $numRows < $queryLimit );
183 $this->mIsLast
= ( $this->mOffset
== '' );
184 $this->mLastShown
= $firstIndex;
185 $this->mFirstShown
= $lastIndex;
187 $this->mIsFirst
= ( $this->mOffset
== '' );
188 $this->mIsLast
= ( $numRows < $queryLimit );
189 $this->mLastShown
= $lastIndex;
190 $this->mFirstShown
= $firstIndex;
192 $this->mQueryDone
= true;
196 * @param bool $enable
198 protected function preventClickjacking( $enable = true ) {
199 $this->preventClickjacking
= $enable;
205 public function getPreventClickjacking() {
206 return $this->preventClickjacking
;