00001 <?php
00007 require_once 'commandLine.inc';
00008
00009 class UploadDumper {
00010 function __construct( $args ) {
00011 global $IP, $wgUseSharedUploads;
00012 $this->mAction = 'fetchLocal';
00013 $this->mBasePath = $IP;
00014 $this->mShared = false;
00015 $this->mSharedSupplement = false;
00016
00017 if( isset( $args['help'] ) ) {
00018 $this->mAction = 'help';
00019 }
00020
00021 if( isset( $args['base'] ) ) {
00022 $this->mBasePath = $args['base'];
00023 }
00024
00025 if( isset( $args['local'] ) ) {
00026 $this->mAction = 'fetchLocal';
00027 }
00028
00029 if( isset( $args['used'] ) ) {
00030 $this->mAction = 'fetchUsed';
00031 }
00032
00033 if( isset( $args['shared'] ) ) {
00034 if( isset( $args['used'] ) ) {
00035
00036 $this->mShared = true;
00037 } else {
00038
00039 $this->mSharedSupplement = true;
00040 }
00041 }
00042 }
00043
00044 function run() {
00045 $this->{$this->mAction}( $this->mShared );
00046 if( $this->mSharedSupplement ) {
00047 $this->fetchUsed( true );
00048 }
00049 }
00050
00051 function help() {
00052 echo <<<END
00053 Generates list of uploaded files which can be fed to tar or similar.
00054 By default, outputs relative paths against the parent directory of
00055 \$wgUploadDirectory.
00056
00057 Usage:
00058 php dumpUploads.php [options] > list-o-files.txt
00059
00060 Options:
00061 --base=<path> Set base relative path instead of wiki include root
00062
00063 --local List all local files, used or not. No shared files included.
00064 --used Skip local images that are not used
00065 --shared Include images used from shared repository
00066
00067 END;
00068 }
00069
00076 function fetchUsed( $shared ) {
00077 $dbr = wfGetDB( DB_SLAVE );
00078 $image = $dbr->tableName( 'image' );
00079 $imagelinks = $dbr->tableName( 'imagelinks' );
00080
00081 $sql = "SELECT DISTINCT il_to, img_name
00082 FROM $imagelinks
00083 LEFT OUTER JOIN $image
00084 ON il_to=img_name";
00085 $result = $dbr->query( $sql );
00086
00087 foreach( $result as $row ) {
00088 $this->outputItem( $row->il_to, $shared );
00089 }
00090 $dbr->freeResult( $result );
00091 }
00092
00093 function fetchLocal( $shared ) {
00094 $dbr = wfGetDB( DB_SLAVE );
00095 $result = $dbr->select( 'image',
00096 array( 'img_name' ),
00097 '',
00098 __METHOD__ );
00099
00100 foreach( $result as $row ) {
00101 $this->outputItem( $row->img_name, $shared );
00102 }
00103 $dbr->freeResult( $result );
00104 }
00105
00106 function outputItem( $name, $shared ) {
00107 $file = wfFindFile( $name );
00108 if( $file && $this->filterItem( $file, $shared ) ) {
00109 $filename = $file->getFullPath();
00110 $rel = wfRelativePath( $filename, $this->mBasePath );
00111 echo "$rel\n";
00112 } else {
00113 wfDebug( __METHOD__ . ": base file? $name\n" );
00114 }
00115 }
00116
00117 function filterItem( $file, $shared ) {
00118 return $shared || $file->isLocal();
00119 }
00120 }
00121
00122 $dumper = new UploadDumper( $options );
00123 $dumper->run();
00124