MediaWiki REL1_28
ImageHistoryPseudoPager.php
Go to the documentation of this file.
1<?php
22 protected $preventClickjacking = false;
23
27 protected $mImg;
28
32 protected $mTitle;
33
37 function __construct( $imagePage ) {
38 parent::__construct( $imagePage->getContext() );
39 $this->mImagePage = $imagePage;
40 $this->mTitle = clone $imagePage->getTitle();
41 $this->mTitle->setFragment( '#filehistory' );
42 $this->mImg = null;
43 $this->mHist = [];
44 $this->mRange = [ 0, 0 ]; // display range
45 }
46
50 function getTitle() {
51 return $this->mTitle;
52 }
53
54 function getQueryInfo() {
55 return false;
56 }
57
61 function getIndexField() {
62 return '';
63 }
64
69 function formatRow( $row ) {
70 return '';
71 }
72
76 function getBody() {
77 $s = '';
78 $this->doQuery();
79 if ( count( $this->mHist ) ) {
80 if ( $this->mImg->isLocal() ) {
81 // Do a batch existence check for user pages and talkpages
82 $linkBatch = new LinkBatch();
83 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
84 $file = $this->mHist[$i];
85 $user = $file->getUser( 'text' );
86 $linkBatch->add( NS_USER, $user );
87 $linkBatch->add( NS_USER_TALK, $user );
88 }
89 $linkBatch->execute();
90 }
91
92 $list = new ImageHistoryList( $this->mImagePage );
93 # Generate prev/next links
94 $navLink = $this->getNavigationBar();
95 $s = $list->beginImageHistoryList( $navLink );
96 // Skip rows there just for paging links
97 for ( $i = $this->mRange[0]; $i <= $this->mRange[1]; $i++ ) {
98 $file = $this->mHist[$i];
99 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
100 }
101 $s .= $list->endImageHistoryList( $navLink );
102
103 if ( $list->getPreventClickjacking() ) {
104 $this->preventClickjacking();
105 }
106 }
107 return $s;
108 }
109
110 function doQuery() {
111 if ( $this->mQueryDone ) {
112 return;
113 }
114 $this->mImg = $this->mImagePage->getPage()->getFile(); // ensure loading
115 if ( !$this->mImg->exists() ) {
116 return;
117 }
118 $queryLimit = $this->mLimit + 1; // limit plus extra row
119 if ( $this->mIsBackwards ) {
120 // Fetch the file history
121 $this->mHist = $this->mImg->getHistory( $queryLimit, null, $this->mOffset, false );
122 // The current rev may not meet the offset/limit
123 $numRows = count( $this->mHist );
124 if ( $numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset ) {
125 $this->mHist = array_merge( [ $this->mImg ], $this->mHist );
126 }
127 } else {
128 // The current rev may not meet the offset
129 if ( !$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset ) {
130 $this->mHist[] = $this->mImg;
131 }
132 // Old image versions (fetch extra row for nav links)
133 $oiLimit = count( $this->mHist ) ? $this->mLimit : $this->mLimit + 1;
134 // Fetch the file history
135 $this->mHist = array_merge( $this->mHist,
136 $this->mImg->getHistory( $oiLimit, $this->mOffset, null, false ) );
137 }
138 $numRows = count( $this->mHist ); // Total number of query results
139 if ( $numRows ) {
140 # Index value of top item in the list
141 $firstIndex = $this->mIsBackwards ?
142 $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
143 # Discard the extra result row if there is one
144 if ( $numRows > $this->mLimit && $numRows > 1 ) {
145 if ( $this->mIsBackwards ) {
146 # Index value of item past the index
147 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
148 # Index value of bottom item in the list
149 $lastIndex = $this->mHist[1]->getTimestamp();
150 # Display range
151 $this->mRange = [ 1, $numRows - 1 ];
152 } else {
153 # Index value of item past the index
154 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
155 # Index value of bottom item in the list
156 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
157 # Display range
158 $this->mRange = [ 0, $numRows - 2 ];
159 }
160 } else {
161 # Setting indexes to an empty string means that they will be
162 # omitted if they would otherwise appear in URLs. It just so
163 # happens that this is the right thing to do in the standard
164 # UI, in all the relevant cases.
165 $this->mPastTheEndIndex = '';
166 # Index value of bottom item in the list
167 $lastIndex = $this->mIsBackwards ?
168 $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
169 # Display range
170 $this->mRange = [ 0, $numRows - 1 ];
171 }
172 } else {
173 $firstIndex = '';
174 $lastIndex = '';
175 $this->mPastTheEndIndex = '';
176 }
177 if ( $this->mIsBackwards ) {
178 $this->mIsFirst = ( $numRows < $queryLimit );
179 $this->mIsLast = ( $this->mOffset == '' );
180 $this->mLastShown = $firstIndex;
181 $this->mFirstShown = $lastIndex;
182 } else {
183 $this->mIsFirst = ( $this->mOffset == '' );
184 $this->mIsLast = ( $numRows < $queryLimit );
185 $this->mLastShown = $lastIndex;
186 $this->mFirstShown = $firstIndex;
187 }
188 $this->mQueryDone = true;
189 }
190
194 protected function preventClickjacking( $enable = true ) {
195 $this->preventClickjacking = $enable;
196 }
197
201 public function getPreventClickjacking() {
203 }
204
205}
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:50
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 representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:32
IndexPager with a formatted navigation bar.
Represents a title within MediaWiki.
Definition Title.php:36
const NS_USER
Definition Defines.php:58
const NS_USER_TALK
Definition Defines.php:59
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 local account $user
Definition hooks.txt:249
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