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';
17 if( isset( $args['base'] ) ) {
18 $this->mBasePath
= $args['base'];
23 $this->{$this->mAction
}();
28 Generates list of uploaded files which can be fed to tar or similar.
29 By default, outputs relative paths against the parent directory of
33 php dumpUploads.php [options] > list-o-files.txt
36 --base=<path> Set base relative path instead of wiki include root
38 FIXME: other options not implemented yet ;)
40 --local List all local files, used or not. No shared files included.
41 --used Skip local images that are not used
42 --shared Include images used from shared repository
48 * Fetch a list of all or used images from a particular image source.
49 * @param string $table
50 * @param string $directory Base directory where files are located
51 * @param bool $shared true to pass shared-dir settings to hash func
53 function fetchUsed() {
54 $dbr = wfGetDB( DB_SLAVE
);
55 $image = $dbr->tableName( 'image' );
56 $imagelinks = $dbr->tableName( 'imagelinks' );
58 $sql = "SELECT DISTINCT il_to, img_name
60 LEFT OUTER JOIN $image
62 $result = $dbr->query( $sql );
64 while( $row = $dbr->fetchObject( $result ) ) {
65 if( is_null( $row->img_name
) ) {
66 if( $this->mShared
) {
67 $this->outputShared( $row->il_to
);
70 $this->outputLocal( $row->il_to
);
73 $dbr->freeResult( $result );
76 function outputLocal( $name ) {
77 global $wgUploadDirectory;
78 return $this->outputItem( $name, $wgUploadDirectory, false );
81 function outputShared( $name ) {
82 global $wgSharedUploadDirectory;
83 return $this->outputItem( $name, $wgSharedUploadDirectory, true );
86 function outputItem( $name, $directory, $shared ) {
87 $filename = $directory .
88 wfGetHashPath( $name, $shared ) .
90 $rel = $this->relativePath( $filename, $this->mBasePath
);
95 * Return a relative path to $path from the base directory $base
96 * For instance relativePath( '/foo/bar/baz', '/foo' ) should return
99 function relativePath( $path, $base) {
100 $path = explode( DIRECTORY_SEPARATOR
, $path );
101 $base = explode( DIRECTORY_SEPARATOR
, $base );
102 while( count( $base ) && $path[0] == $base[0] ) {
103 array_shift( $path );
104 array_shift( $base );
106 foreach( $base as $prefix ) {
107 array_unshift( $path, '..' );
109 return implode( DIRECTORY_SEPARATOR
, $path );
113 $dumper = new UploadDumper( $options );