MediaWiki REL1_33
ImageHistoryPseudoPager.php
Go to the documentation of this file.
1<?php
21use Wikimedia\Timestamp\TimestampException;
22
24 protected $preventClickjacking = false;
25
29 protected $mImg;
30
34 protected $mTitle;
35
41
46 public $mHist;
47
52 public $mRange;
53
57 public function __construct( $imagePage ) {
58 parent::__construct( $imagePage->getContext() );
59 $this->mImagePage = $imagePage;
60 $this->mTitle = $imagePage->getTitle()->createFragmentTarget( 'filehistory' );
61 $this->mImg = null;
62 $this->mHist = [];
63 $this->mRange = [ 0, 0 ]; // display range
64
65 // Only display 10 revisions at once by default, otherwise the list is overwhelming
66 $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
67 $this->mDefaultLimit = 10;
68 list( $this->mLimit, /* $offset */ ) =
69 $this->mRequest->getLimitOffset( $this->mDefaultLimit, '' );
70 }
71
75 public function getTitle() {
76 return $this->mTitle;
77 }
78
79 public function getQueryInfo() {
80 return false;
81 }
82
86 public function getIndexField() {
87 return '';
88 }
89
94 public function formatRow( $row ) {
95 return '';
96 }
97
101 public function getBody() {
102 $s = '';
103 $this->doQuery();
104 if ( count( $this->mHist ) ) {
105 if ( $this->mImg->isLocal() ) {
106 // Do a batch existence check for user pages and talkpages
107 $linkBatch = new LinkBatch();
108 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
109 $file = $this->mHist[$i];
110 $user = $file->getUser( 'text' );
111 $linkBatch->add( NS_USER, $user );
112 $linkBatch->add( NS_USER_TALK, $user );
113 }
114 $linkBatch->execute();
115 }
116
117 $list = new ImageHistoryList( $this->mImagePage );
118 # Generate prev/next links
119 $navLink = $this->getNavigationBar();
120 $s = $list->beginImageHistoryList( $navLink );
121 // Skip rows there just for paging links
122 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
123 $file = $this->mHist[$i];
124 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
125 }
126 $s .= $list->endImageHistoryList( $navLink );
127
128 if ( $list->getPreventClickjacking() ) {
129 $this->preventClickjacking();
130 }
131 }
132 return $s;
133 }
134
135 public function doQuery() {
136 if ( $this->mQueryDone ) {
137 return;
138 }
139 $this->mImg = $this->mImagePage->getPage()->getFile(); // ensure loading
140 if ( !$this->mImg->exists() ) {
141 return;
142 }
143 // Make sure the date (probably from user input) is valid; if not, drop it.
144 if ( $this->mOffset !== null ) {
145 try {
146 $sadlyWeCannotPassThisTimestampDownTheStack = $this->mDb->timestamp( $this->mOffset );
147 } catch ( TimestampException $e ) {
148 $this->mOffset = null;
149 }
150 }
151 $queryLimit = $this->mLimit + 1; // limit plus extra row
152 if ( $this->mIsBackwards ) {
153 // Fetch the file history
154 $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
155 // The current rev may not meet the offset/limit
156 $numRows = count( $this->mHist );
157 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
158 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
159 }
160 } else {
161 // The current rev may not meet the offset
162 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
163 $this->mHist[] = $this->mImg;
164 }
165 // Old image versions (fetch extra row for nav links)
166 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
167 // Fetch the file history
168 $this->mHist = array_merge( $this->mHist,
169 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
170 }
171 $numRows = count( $this->mHist ); // Total number of query results
172 if ( $numRows ) {
173 # Index value of top item in the list
174 $firstIndex = $this->mIsBackwards ?
175 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
176 # Discard the extra result row if there is one
177 if ( $numRows > $this->mLimit && $numRows > 1 ) {
178 if ( $this->mIsBackwards ) {
179 # Index value of item past the index
180 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
181 # Index value of bottom item in the list
182 $lastIndex = $this->mHist[1]->getTimestamp();
183 # Display range
184 $this->mRange = [ 1, $numRows - 1 ];
185 } else {
186 # Index value of item past the index
187 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
188 # Index value of bottom item in the list
189 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
190 # Display range
191 $this->mRange = [ 0, $numRows - 2 ];
192 }
193 } else {
194 # Setting indexes to an empty string means that they will be
195 # omitted if they would otherwise appear in URLs. It just so
196 # happens that this is the right thing to do in the standard
197 # UI, in all the relevant cases.
198 $this->mPastTheEndIndex = '';
199 # Index value of bottom item in the list
200 $lastIndex = $this->mIsBackwards ?
201 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
202 # Display range
203 $this->mRange = [ 0, $numRows - 1 ];
204 }
205 } else {
206 $firstIndex = '';
207 $lastIndex = '';
208 $this->mPastTheEndIndex = '';
209 }
210 if ( $this->mIsBackwards ) {
211 $this->mIsFirst = ( $numRows < $queryLimit );
212 $this->mIsLast = ( $this->mOffset == '' );
213 $this->mLastShown = $firstIndex;
214 $this->mFirstShown = $lastIndex;
215 } else {
216 $this->mIsFirst = ( $this->mOffset == '' );
217 $this->mIsLast = ( $numRows < $queryLimit );
218 $this->mLastShown = $lastIndex;
219 $this->mFirstShown = $firstIndex;
220 }
221 $this->mQueryDone = true;
222 }
223
227 protected function preventClickjacking( $enable = true ) {
228 $this->preventClickjacking = $enable;
229 }
230
234 public function getPreventClickjacking() {
236 }
237
238}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:52
Builds the image revision log shown on image pages.
doQuery()
Do the query, using information from the object context.
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Class for viewing MediaWiki file description pages.
Definition ImagePage.php:31
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
Efficient paging for SQL queries.
Represents a title within MediaWiki.
Definition Title.php:40
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
const NS_USER
Definition Defines.php:75
const NS_USER_TALK
Definition Defines.php:76
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
returning false will NOT prevent logging $e
Definition hooks.txt:2175
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition router.php:42