3 require_once 'commandLine.inc';
7 function __construct( $args ) {
8 global $IP, $wgUseSharedUploads;
9 $this->mAction
= 'fetchUsed';
10 $this->mBasePath
= $IP;
11 $this->mShared
= $wgUseSharedUploads;
13 if( isset( $args['help'] ) ) {
14 $this->mAction
= 'help';
19 $this->{$this->mAction
}();
24 Generates list of uploaded files which can be fed to tar or similar.
25 By default, outputs relative paths against the parent directory of
29 php dumpUploads.php [options] > list-o-files.txt
32 --local List all local files, used or not. No shared files included.
33 --used Skip local images that are not used
34 --shared Include images used from shared repository
36 FIXME: options not implemented yet ;)
42 * Fetch a list of all or used images from a particular image source.
43 * @param string $table
44 * @param string $directory Base directory where files are located
45 * @param bool $shared true to pass shared-dir settings to hash func
47 function fetchUsed() {
48 $dbr = wfGetDB( DB_SLAVE
);
49 $image = $dbr->tableName( 'image' );
50 $imagelinks = $dbr->tableName( 'imagelinks' );
52 $sql = "SELECT DISTINCT il_to, img_name
54 LEFT OUTER JOIN $image
56 $result = $dbr->query( $sql );
58 while( $row = $dbr->fetchObject( $result ) ) {
59 if( is_null( $row->img_name
) ) {
60 if( $this->mShared
) {
61 $this->outputShared( $row->il_to
);
64 $this->outputLocal( $row->il_to
);
67 $dbr->freeResult( $result );
70 function outputLocal( $name ) {
71 global $wgUploadDirectory;
72 return $this->outputItem( $name, $wgUploadDirectory, false );
75 function outputShared( $name ) {
76 global $wgSharedUploadDirectory;
77 return $this->outputItem( $name, $wgSharedUploadDirectory, true );
80 function outputItem( $name, $directory, $shared ) {
81 $filename = $directory .
82 wfGetHashPath( $name, $shared ) .
84 $rel = $this->relativePath( $filename, $this->mBasePath
);
89 * Return a relative path to $path from the base directory $base
90 * For instance relativePath( '/foo/bar/baz', '/foo' ) should return
93 function relativePath( $path, $base) {
94 $path = explode( DIRECTORY_SEPARATOR
, $path );
95 $base = explode( DIRECTORY_SEPARATOR
, $base );
96 while( count( $base ) && $path[0] == $base[0] ) {
100 foreach( $base as $prefix ) {
101 array_unshift( $path, '..' );
103 return implode( DIRECTORY_SEPARATOR
, $path );
107 $dumper = new UploadDumper( $options );