7 require_once 'commandLine.inc';
10 function __construct( $args ) {
11 global $IP, $wgUseSharedUploads;
12 $this->mAction
= 'fetchLocal';
13 $this->mBasePath
= $IP;
14 $this->mShared
= false;
15 $this->mSharedSupplement
= false;
17 if( isset( $args['help'] ) ) {
18 $this->mAction
= 'help';
21 if( isset( $args['base'] ) ) {
22 $this->mBasePath
= $args['base'];
25 if( isset( $args['local'] ) ) {
26 $this->mAction
= 'fetchLocal';
29 if( isset( $args['used'] ) ) {
30 $this->mAction
= 'fetchUsed';
33 if( isset( $args['shared'] ) ) {
34 if( isset( $args['used'] ) ) {
35 // Include shared-repo files in the used check
36 $this->mShared
= true;
38 // Grab all local *plus* used shared
39 $this->mSharedSupplement
= true;
45 $this->{$this->mAction
}( $this->mShared
);
46 if( $this->mSharedSupplement
) {
47 $this->fetchUsed( true );
53 Generates list of uploaded files which can be fed to tar or similar.
54 By default, outputs relative paths against the parent directory of
58 php dumpUploads.php [options] > list-o-files.txt
61 --base=<path> Set base relative path instead of wiki include root
63 --local List all local files, used or not. No shared files included.
64 --used Skip local images that are not used
65 --shared Include images used from shared repository
71 * Fetch a list of all or used images from a particular image source.
72 * @param string $table
73 * @param string $directory Base directory where files are located
74 * @param bool $shared true to pass shared-dir settings to hash func
76 function fetchUsed( $shared ) {
77 $dbr = wfGetDB( DB_SLAVE
);
78 $image = $dbr->tableName( 'image' );
79 $imagelinks = $dbr->tableName( 'imagelinks' );
81 $sql = "SELECT DISTINCT il_to, img_name
83 LEFT OUTER JOIN $image
85 $result = $dbr->query( $sql );
87 foreach( $result as $row ) {
88 $this->outputItem( $row->il_to
, $shared );
90 $dbr->freeResult( $result );
93 function fetchLocal( $shared ) {
94 $dbr = wfGetDB( DB_SLAVE
);
95 $result = $dbr->select( 'image',
100 foreach( $result as $row ) {
101 $this->outputItem( $row->img_name
, $shared );
103 $dbr->freeResult( $result );
106 function outputItem( $name, $shared ) {
107 $file = wfFindFile( $name );
108 if( $file && $this->filterItem( $file, $shared ) ) {
109 $filename = $file->getFullPath();
110 $rel = wfRelativePath( $filename, $this->mBasePath
);
113 wfDebug( __METHOD__
. ": base file? $name\n" );
117 function filterItem( $file, $shared ) {
118 return $shared ||
$file->isLocal();
122 $dumper = new UploadDumper( $options );