MediaWiki  1.30.0
ImageHistoryPseudoPager.php
Go to the documentation of this file.
1 <?php
22  protected $preventClickjacking = false;
23 
27  protected $mImg;
28 
32  protected $mTitle;
33 
38  public $mImagePage;
39 
44  public $mHist;
45 
50  public $mRange;
51 
55  public function __construct( $imagePage ) {
56  parent::__construct( $imagePage->getContext() );
57  $this->mImagePage = $imagePage;
58  $this->mTitle = $imagePage->getTitle()->createFragmentTarget( 'filehistory' );
59  $this->mImg = null;
60  $this->mHist = [];
61  $this->mRange = [ 0, 0 ]; // display range
62 
63  // Only display 10 revisions at once by default, otherwise the list is overwhelming
64  $this->mLimitsShown = array_merge( [ 10 ], $this->mLimitsShown );
65  $this->mDefaultLimit = 10;
66  list( $this->mLimit, /* $offset */ ) =
67  $this->mRequest->getLimitOffset( $this->mDefaultLimit, '' );
68  }
69 
73  public function getTitle() {
74  return $this->mTitle;
75  }
76 
77  public function getQueryInfo() {
78  return false;
79  }
80 
84  public function getIndexField() {
85  return '';
86  }
87 
92  public function formatRow( $row ) {
93  return '';
94  }
95 
99  public function getBody() {
100  $s = '';
101  $this->doQuery();
102  if ( count( $this->mHist ) ) {
103  if ( $this->mImg->isLocal() ) {
104  // Do a batch existence check for user pages and talkpages
105  $linkBatch = new LinkBatch();
106  for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
107  $file = $this->mHist[$i];
108  $user = $file->getUser( 'text' );
109  $linkBatch->add( NS_USER, $user );
110  $linkBatch->add( NS_USER_TALK, $user );
111  }
112  $linkBatch->execute();
113  }
114 
115  $list = new ImageHistoryList( $this->mImagePage );
116  # Generate prev/next links
117  $navLink = $this->getNavigationBar();
118  $s = $list->beginImageHistoryList( $navLink );
119  // Skip rows there just for paging links
120  for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
121  $file = $this->mHist[$i];
122  $s .= $list->imageHistoryLine( !$file->isOld(), $file );
123  }
124  $s .= $list->endImageHistoryList( $navLink );
125 
126  if ( $list->getPreventClickjacking() ) {
127  $this->preventClickjacking();
128  }
129  }
130  return $s;
131  }
132 
133  public function doQuery() {
134  if ( $this->mQueryDone ) {
135  return;
136  }
137  $this->mImg = $this->mImagePage->getPage()->getFile(); // ensure loading
138  if ( !$this->mImg->exists() ) {
139  return;
140  }
141  $queryLimit = $this->mLimit + 1; // limit plus extra row
142  if ( $this->mIsBackwards ) {
143  // Fetch the file history
144  $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
145  // The current rev may not meet the offset/limit
146  $numRows = count( $this->mHist );
147  if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
148  $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
149  }
150  } else {
151  // The current rev may not meet the offset
152  if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
153  $this->mHist[] = $this->mImg;
154  }
155  // Old image versions (fetch extra row for nav links)
156  $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
157  // Fetch the file history
158  $this->mHist = array_merge( $this->mHist,
159  $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
160  }
161  $numRows = count( $this->mHist ); // Total number of query results
162  if ( $numRows ) {
163  # Index value of top item in the list
164  $firstIndex = $this->mIsBackwards ?
165  $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
166  # Discard the extra result row if there is one
167  if ( $numRows > $this->mLimit && $numRows > 1 ) {
168  if ( $this->mIsBackwards ) {
169  # Index value of item past the index
170  $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
171  # Index value of bottom item in the list
172  $lastIndex = $this->mHist[1]->getTimestamp();
173  # Display range
174  $this->mRange = [ 1, $numRows - 1 ];
175  } else {
176  # Index value of item past the index
177  $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
178  # Index value of bottom item in the list
179  $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
180  # Display range
181  $this->mRange = [ 0, $numRows - 2 ];
182  }
183  } else {
184  # Setting indexes to an empty string means that they will be
185  # omitted if they would otherwise appear in URLs. It just so
186  # happens that this is the right thing to do in the standard
187  # UI, in all the relevant cases.
188  $this->mPastTheEndIndex = '';
189  # Index value of bottom item in the list
190  $lastIndex = $this->mIsBackwards ?
191  $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
192  # Display range
193  $this->mRange = [ 0, $numRows - 1 ];
194  }
195  } else {
196  $firstIndex = '';
197  $lastIndex = '';
198  $this->mPastTheEndIndex = '';
199  }
200  if ( $this->mIsBackwards ) {
201  $this->mIsFirst = ( $numRows < $queryLimit );
202  $this->mIsLast = ( $this->mOffset == '' );
203  $this->mLastShown = $firstIndex;
204  $this->mFirstShown = $lastIndex;
205  } else {
206  $this->mIsFirst = ( $this->mOffset == '' );
207  $this->mIsLast = ( $numRows < $queryLimit );
208  $this->mLastShown = $lastIndex;
209  $this->mFirstShown = $firstIndex;
210  }
211  $this->mQueryDone = true;
212  }
213 
217  protected function preventClickjacking( $enable = true ) {
218  $this->preventClickjacking = $enable;
219  }
220 
224  public function getPreventClickjacking() {
226  }
227 
228 }
ImageHistoryPseudoPager\$mImg
File $mImg
Definition: ImageHistoryPseudoPager.php:27
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
ImageHistoryPseudoPager\$mRange
int[] $mRange
Definition: ImageHistoryPseudoPager.php:50
ImageHistoryPseudoPager\$mImagePage
ImagePage $mImagePage
Definition: ImageHistoryPseudoPager.php:38
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
ImageHistoryList
Builds the image revision log shown on image pages.
Definition: ImageHistoryList.php:26
ImageHistoryPseudoPager\__construct
__construct( $imagePage)
Definition: ImageHistoryPseudoPager.php:55
captcha-old.count
count
Definition: captcha-old.py:249
$s
$s
Definition: mergeMessageFileList.php:188
ImagePage
Class for viewing MediaWiki file description pages.
Definition: ImagePage.php:30
ImageHistoryPseudoPager\preventClickjacking
preventClickjacking( $enable=true)
Definition: ImageHistoryPseudoPager.php:217
ImageHistoryPseudoPager\formatRow
formatRow( $row)
Definition: ImageHistoryPseudoPager.php:92
php
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:35
ImageHistoryPseudoPager\getBody
getBody()
Definition: ImageHistoryPseudoPager.php:99
ImageHistoryPseudoPager\doQuery
doQuery()
Do the query, using information from the object context.
Definition: ImageHistoryPseudoPager.php:133
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:51
ImageHistoryPseudoPager\$preventClickjacking
$preventClickjacking
Definition: ImageHistoryPseudoPager.php:22
ImageHistoryPseudoPager\getIndexField
getIndexField()
Definition: ImageHistoryPseudoPager.php:84
ImageHistoryPseudoPager\getPreventClickjacking
getPreventClickjacking()
Definition: ImageHistoryPseudoPager.php:224
ImageHistoryPseudoPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: ImageHistoryPseudoPager.php:77
list
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
ImageHistoryPseudoPager\getTitle
getTitle()
Definition: ImageHistoryPseudoPager.php:73
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:68
IndexPager\$mOffset
$mOffset
Definition: IndexPager.php:81
ImageHistoryPseudoPager\$mTitle
Title $mTitle
Definition: ImageHistoryPseudoPager.php:32
Title
Represents a title within MediaWiki.
Definition: Title.php:39
ImageHistoryPseudoPager\$mHist
File[] $mHist
Definition: ImageHistoryPseudoPager.php:44
NS_USER
const NS_USER
Definition: Defines.php:67
ReverseChronologicalPager
Efficient paging for SQL queries.
Definition: ReverseChronologicalPager.php:28
ImageHistoryPseudoPager
Definition: ImageHistoryPseudoPager.php:21
ReverseChronologicalPager\getNavigationBar
getNavigationBar()
Definition: ReverseChronologicalPager.php:34