MediaWiki  1.23.13
OldLocalFile.php
Go to the documentation of this file.
1 <?php
29 class OldLocalFile extends LocalFile {
31  protected $requestedTime;
32 
34  protected $archive_name;
35 
36  const CACHE_VERSION = 1;
37  const MAX_CACHE_ROWS = 20;
38 
46  static function newFromTitle( $title, $repo, $time = null ) {
47  # The null default value is only here to avoid an E_STRICT
48  if ( $time === null ) {
49  throw new MWException( __METHOD__ . ' got null for $time parameter' );
50  }
51 
52  return new self( $title, $repo, $time, null );
53  }
54 
61  static function newFromArchiveName( $title, $repo, $archiveName ) {
62  return new self( $title, $repo, null, $archiveName );
63  }
64 
70  static function newFromRow( $row, $repo ) {
71  $title = Title::makeTitle( NS_FILE, $row->oi_name );
72  $file = new self( $title, $repo, null, $row->oi_archive_name );
73  $file->loadFromRow( $row, 'oi_' );
74 
75  return $file;
76  }
77 
88  static function newFromKey( $sha1, $repo, $timestamp = false ) {
89  $dbr = $repo->getSlaveDB();
90 
91  $conds = array( 'oi_sha1' => $sha1 );
92  if ( $timestamp ) {
93  $conds['oi_timestamp'] = $dbr->timestamp( $timestamp );
94  }
95 
96  $row = $dbr->selectRow( 'oldimage', self::selectFields(), $conds, __METHOD__ );
97  if ( $row ) {
98  return self::newFromRow( $row, $repo );
99  } else {
100  return false;
101  }
102  }
103 
108  static function selectFields() {
109  return array(
110  'oi_name',
111  'oi_archive_name',
112  'oi_size',
113  'oi_width',
114  'oi_height',
115  'oi_metadata',
116  'oi_bits',
117  'oi_media_type',
118  'oi_major_mime',
119  'oi_minor_mime',
120  'oi_description',
121  'oi_user',
122  'oi_user_text',
123  'oi_timestamp',
124  'oi_deleted',
125  'oi_sha1',
126  );
127  }
128 
136  function __construct( $title, $repo, $time, $archiveName ) {
137  parent::__construct( $title, $repo );
138  $this->requestedTime = $time;
139  $this->archive_name = $archiveName;
140  if ( is_null( $time ) && is_null( $archiveName ) ) {
141  throw new MWException( __METHOD__ . ': must specify at least one of $time or $archiveName' );
142  }
143  }
144 
148  function getCacheKey() {
149  return false;
150  }
151 
155  function getArchiveName() {
156  if ( !isset( $this->archive_name ) ) {
157  $this->load();
158  }
159 
160  return $this->archive_name;
161  }
162 
166  function isOld() {
167  return true;
168  }
169 
173  function isVisible() {
174  return $this->exists() && !$this->isDeleted( File::DELETED_FILE );
175  }
176 
177  function loadFromDB() {
178  wfProfileIn( __METHOD__ );
179 
180  $this->dataLoaded = true;
181  $dbr = $this->repo->getSlaveDB();
182  $conds = array( 'oi_name' => $this->getName() );
183  if ( is_null( $this->requestedTime ) ) {
184  $conds['oi_archive_name'] = $this->archive_name;
185  } else {
186  $conds['oi_timestamp'] = $dbr->timestamp( $this->requestedTime );
187  }
188  $row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ),
189  $conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
190  if ( $row ) {
191  $this->loadFromRow( $row, 'oi_' );
192  } else {
193  $this->fileExists = false;
194  }
195 
196  wfProfileOut( __METHOD__ );
197  }
198 
202  protected function loadExtraFromDB() {
203  wfProfileIn( __METHOD__ );
204 
205  $this->extraDataLoaded = true;
206  $dbr = $this->repo->getSlaveDB();
207  $conds = array( 'oi_name' => $this->getName() );
208  if ( is_null( $this->requestedTime ) ) {
209  $conds['oi_archive_name'] = $this->archive_name;
210  } else {
211  $conds['oi_timestamp'] = $dbr->timestamp( $this->requestedTime );
212  }
213  // In theory the file could have just been renamed/deleted...oh well
214  $row = $dbr->selectRow( 'oldimage', $this->getLazyCacheFields( 'oi_' ),
215  $conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
216 
217  if ( !$row ) { // fallback to master
218  $dbr = $this->repo->getMasterDB();
219  $row = $dbr->selectRow( 'oldimage', $this->getLazyCacheFields( 'oi_' ),
220  $conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
221  }
222 
223  if ( $row ) {
224  foreach ( $this->unprefixRow( $row, 'oi_' ) as $name => $value ) {
225  $this->$name = $value;
226  }
227  } else {
228  wfProfileOut( __METHOD__ );
229  throw new MWException( "Could not find data for image '{$this->archive_name}'." );
230  }
231 
232  wfProfileOut( __METHOD__ );
233  }
234 
239  function getCacheFields( $prefix = 'img_' ) {
240  $fields = parent::getCacheFields( $prefix );
241  $fields[] = $prefix . 'archive_name';
242  $fields[] = $prefix . 'deleted';
243 
244  return $fields;
245  }
246 
250  function getRel() {
251  return 'archive/' . $this->getHashPath() . $this->getArchiveName();
252  }
253 
257  function getUrlRel() {
258  return 'archive/' . $this->getHashPath() . rawurlencode( $this->getArchiveName() );
259  }
260 
261  function upgradeRow() {
262  wfProfileIn( __METHOD__ );
263  $this->loadFromFile();
264 
265  # Don't destroy file info of missing files
266  if ( !$this->fileExists ) {
267  wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
268  wfProfileOut( __METHOD__ );
269 
270  return;
271  }
272 
273  $dbw = $this->repo->getMasterDB();
274  list( $major, $minor ) = self::splitMime( $this->mime );
275 
276  wfDebug( __METHOD__ . ': upgrading ' . $this->archive_name . " to the current schema\n" );
277  $dbw->update( 'oldimage',
278  array(
279  'oi_size' => $this->size, // sanity
280  'oi_width' => $this->width,
281  'oi_height' => $this->height,
282  'oi_bits' => $this->bits,
283  'oi_media_type' => $this->media_type,
284  'oi_major_mime' => $major,
285  'oi_minor_mime' => $minor,
286  'oi_metadata' => $this->metadata,
287  'oi_sha1' => $this->sha1,
288  ), array(
289  'oi_name' => $this->getName(),
290  'oi_archive_name' => $this->archive_name ),
291  __METHOD__
292  );
293  wfProfileOut( __METHOD__ );
294  }
295 
301  function isDeleted( $field ) {
302  $this->load();
303 
304  return ( $this->deleted & $field ) == $field;
305  }
306 
311  function getVisibility() {
312  $this->load();
313 
314  return (int)$this->deleted;
315  }
316 
325  function userCan( $field, User $user = null ) {
326  $this->load();
327 
328  return Revision::userCanBitfield( $this->deleted, $field, $user );
329  }
330 
343  function uploadOld( $srcPath, $archiveName, $timestamp, $comment, $user, $flags = 0 ) {
344  $this->lock();
345 
346  $dstRel = 'archive/' . $this->getHashPath() . $archiveName;
347  $status = $this->publishTo( $srcPath, $dstRel,
349  );
350 
351  if ( $status->isGood() ) {
352  if ( !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) ) {
353  $status->fatal( 'filenotfound', $srcPath );
354  }
355  }
356 
357  $this->unlock();
358 
359  return $status;
360  }
361 
372  function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
373  $dbw = $this->repo->getMasterDB();
374  $dbw->begin( __METHOD__ );
375 
376  $dstPath = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel();
377  $props = $this->repo->getFileProps( $dstPath );
378  if ( !$props['fileExists'] ) {
379  return false;
380  }
381 
382  $dbw->insert( 'oldimage',
383  array(
384  'oi_name' => $this->getName(),
385  'oi_archive_name' => $archiveName,
386  'oi_size' => $props['size'],
387  'oi_width' => intval( $props['width'] ),
388  'oi_height' => intval( $props['height'] ),
389  'oi_bits' => $props['bits'],
390  'oi_timestamp' => $dbw->timestamp( $timestamp ),
391  'oi_description' => $comment,
392  'oi_user' => $user->getId(),
393  'oi_user_text' => $user->getName(),
394  'oi_metadata' => $props['metadata'],
395  'oi_media_type' => $props['media_type'],
396  'oi_major_mime' => $props['major_mime'],
397  'oi_minor_mime' => $props['minor_mime'],
398  'oi_sha1' => $props['sha1'],
399  ), __METHOD__
400  );
401 
402  $dbw->commit( __METHOD__ );
403 
404  return true;
405  }
406 }
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
LocalFile\unprefixRow
unprefixRow( $row, $prefix='img_')
Definition: LocalFile.php:413
OldLocalFile\isOld
isOld()
Definition: OldLocalFile.php:164
File\$repo
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:94
OldLocalFile\CACHE_VERSION
const CACHE_VERSION
Definition: OldLocalFile.php:34
OldLocalFile\newFromKey
static newFromKey( $sha1, $repo, $timestamp=false)
Create a OldLocalFile from a SHA-1 key Do not call this except from inside a repo class.
Definition: OldLocalFile.php:86
LocalFile\unlock
unlock()
Decrement the lock reference count.
Definition: LocalFile.php:1827
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
OldLocalFile\isDeleted
isDeleted( $field)
Definition: OldLocalFile.php:299
OldLocalFile\loadFromDB
loadFromDB()
Load file metadata from the DB.
Definition: OldLocalFile.php:175
OldLocalFile\getVisibility
getVisibility()
Returns bitfield value.
Definition: OldLocalFile.php:309
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
LocalFile\$user
int $user
User ID of uploader *.
Definition: LocalFile.php:85
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
NS_FILE
const NS_FILE
Definition: Defines.php:85
OldLocalFile\selectFields
static selectFields()
Fields in the oldimage table.
Definition: OldLocalFile.php:106
OldLocalFile\uploadOld
uploadOld( $srcPath, $archiveName, $timestamp, $comment, $user, $flags=0)
Upload a file directly into archive.
Definition: OldLocalFile.php:341
LocalFile\$sha1
string $sha1
SHA-1 base 36 content hash *.
Definition: LocalFile.php:65
File\splitMime
static splitMime( $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
Definition: File.php:249
Revision\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1641
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2118
OldLocalFile\recordOldUpload
recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user)
Record a file upload in the oldimage table, without adding log entries.
Definition: OldLocalFile.php:370
OldLocalFile\$requestedTime
string $requestedTime
Timestamp *.
Definition: OldLocalFile.php:30
$dbr
$dbr
Definition: testCompression.php:48
MWException
MediaWiki exception.
Definition: MWException.php:26
OldLocalFile\$archive_name
string $archive_name
Archive name *.
Definition: OldLocalFile.php:32
LocalFile\publishTo
publishTo( $srcPath, $dstRel, $flags=0, array $options=array())
Move or copy a file to a specified location.
Definition: LocalFile.php:1479
OldLocalFile\upgradeRow
upgradeRow()
Fix assorted version-related problems with the image row by reloading it from the file.
Definition: OldLocalFile.php:259
LocalFile\loadFromRow
loadFromRow( $row, $prefix='img_')
Load file metadata from a DB result row.
Definition: LocalFile.php:463
LocalFile\$deleted
int $deleted
Bitfield akin to rev_deleted *.
Definition: LocalFile.php:71
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
OldLocalFile\loadExtraFromDB
loadExtraFromDB()
Load lazy file metadata from the DB.
Definition: OldLocalFile.php:200
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$comment
$comment
Definition: importImages.php:107
OldLocalFile\__construct
__construct( $title, $repo, $time, $archiveName)
Definition: OldLocalFile.php:134
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
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:46
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
$value
$value
Definition: styleTest.css.php:45
LocalFile\lock
lock()
Start a transaction and lock the image for update Increments a reference counter if the lock is alrea...
Definition: LocalFile.php:1798
LocalFile\load
load( $flags=0)
Load file metadata from cache or DB, unless already loaded.
Definition: LocalFile.php:481
File\$title
Title string bool $title
Definition: File.php:96
File\getName
getName()
Return the name of this file.
Definition: File.php:273
LocalFile\$timestamp
string $timestamp
Upload timestamp *.
Definition: LocalFile.php:83
OldLocalFile\isVisible
isVisible()
Definition: OldLocalFile.php:171
File\DELETE_SOURCE
const DELETE_SOURCE
Definition: File.php:65
OldLocalFile\newFromRow
static newFromRow( $row, $repo)
Definition: OldLocalFile.php:68
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
OldLocalFile\getCacheFields
getCacheFields( $prefix='img_')
Definition: OldLocalFile.php:237
OldLocalFile\getRel
getRel()
Definition: OldLocalFile.php:248
OldLocalFile\getUrlRel
getUrlRel()
Definition: OldLocalFile.php:255
LocalFile\getLazyCacheFields
getLazyCacheFields( $prefix='img_')
Definition: LocalFile.php:328
OldLocalFile\newFromTitle
static newFromTitle( $title, $repo, $time=null)
Definition: OldLocalFile.php:44
LocalFile\loadFromFile
loadFromFile()
Load metadata from the file itself.
Definition: LocalFile.php:294
OldLocalFile\userCan
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this image file,...
Definition: OldLocalFile.php:323
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
FileRepo\DELETE_SOURCE
const DELETE_SOURCE
Definition: FileRepo.php:38
File\$name
string $name
The name of a file from its title object *.
Definition: File.php:112
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:52
OldLocalFile\getCacheKey
getCacheKey()
Definition: OldLocalFile.php:146
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
OldLocalFile\getArchiveName
getArchiveName()
Definition: OldLocalFile.php:153
OldLocalFile
Class to represent a file in the oldimage table.
Definition: OldLocalFile.php:29
OldLocalFile\newFromArchiveName
static newFromArchiveName( $title, $repo, $archiveName)
Definition: OldLocalFile.php:59
File\getHashPath
getHashPath()
Get the filename hash component of the directory including trailing slash, e.g.
Definition: File.php:1210
LocalFile\exists
exists()
canRender inherited
Definition: LocalFile.php:754
OldLocalFile\MAX_CACHE_ROWS
const MAX_CACHE_ROWS
Definition: OldLocalFile.php:35