3 require_once 'commandLine.inc';
6 function __construct( $args ) {
7 global $IP, $wgUseSharedUploads;
8 $this->mAction
= 'fetchLocal';
9 $this->mBasePath
= $IP;
10 $this->mShared
= false;
11 $this->mSharedSupplement
= false;
13 if( isset( $args['help'] ) ) {
14 $this->mAction
= 'help';
17 if( isset( $args['base'] ) ) {
18 $this->mBasePath
= $args['base'];
21 if( isset( $args['local'] ) ) {
22 $this->mAction
= 'fetchLocal';
25 if( isset( $args['used'] ) ) {
26 $this->mAction
= 'fetchUsed';
29 if( isset( $args['shared'] ) ) {
30 if( isset( $args['used'] ) ) {
31 // Include shared-repo files in the used check
32 $this->mShared
= true;
34 // Grab all local *plus* used shared
35 $this->mSharedSupplement
= true;
41 $this->{$this->mAction
}( $this->mShared
);
42 if( $this->mSharedSupplement
) {
43 $this->fetchUsed( true );
49 Generates list of uploaded files which can be fed to tar or similar.
50 By default, outputs relative paths against the parent directory of
54 php dumpUploads.php [options] > list-o-files.txt
57 --base=<path> Set base relative path instead of wiki include root
59 --local List all local files, used or not. No shared files included.
60 --used Skip local images that are not used
61 --shared Include images used from shared repository
67 * Fetch a list of all or used images from a particular image source.
68 * @param string $table
69 * @param string $directory Base directory where files are located
70 * @param bool $shared true to pass shared-dir settings to hash func
72 function fetchUsed( $shared ) {
73 $dbr = wfGetDB( DB_SLAVE
);
74 $image = $dbr->tableName( 'image' );
75 $imagelinks = $dbr->tableName( 'imagelinks' );
77 $sql = "SELECT DISTINCT il_to, img_name
79 LEFT OUTER JOIN $image
81 $result = $dbr->query( $sql );
83 foreach( $result as $row ) {
84 $this->outputItem( $row->il_to
, $shared );
86 $dbr->freeResult( $result );
89 function fetchLocal( $shared ) {
90 $dbr = wfGetDB( DB_SLAVE
);
91 $result = $dbr->select( 'image',
96 foreach( $result as $row ) {
97 $this->outputItem( $row->img_name
, $shared );
99 $dbr->freeResult( $result );
102 function outputItem( $name, $shared ) {
103 $file = wfFindFile( $name );
104 if( $file && $this->filterItem( $file, $shared ) ) {
105 $filename = $file->getFullPath();
106 $rel = wfRelativePath( $filename, $this->mBasePath
);
109 wfDebug( __METHOD__
. ": base file? $name\n" );
113 function filterItem( $file, $shared ) {
114 return $shared ||
$file->isLocal();
118 $dumper = new UploadDumper( $options );