00001 <?php
00023 require_once( dirname(__FILE__) . '/Maintenance.php' );
00024
00025 class UploadDumper extends Maintenance {
00026 public function __construct() {
00027 parent::__construct();
00028 $this->mDescription = "Generates list of uploaded files which can be fed to tar or similar.
00029 By default, outputs relative paths against the parent directory of \$wgUploadDirectory.";
00030 $this->addOption( 'base', 'Set base relative path instead of wiki include root', false, true );
00031 $this->addOption( 'local', 'List all local files, used or not. No shared files included' );
00032 $this->addOption( 'used', 'Skip local images that are not used' );
00033 $this->addOption( 'shared', 'Include images used from shared repository' );
00034 }
00035
00036 public function execute() {
00037 global $IP, $wgUseSharedUploads;
00038 $this->mAction = 'fetchLocal';
00039 $this->mBasePath = $this->getOption( 'base', $IP );
00040 $this->mShared = false;
00041 $this->mSharedSupplement = false;
00042
00043 if( $this->hasOption('local') ) {
00044 $this->mAction = 'fetchLocal';
00045 }
00046
00047 if( $this->hasOption('used') ) {
00048 $this->mAction = 'fetchUsed';
00049 }
00050
00051 if( $this->hasOption('shared') ) {
00052 if( $this->hasOption('used') ) {
00053
00054 $this->mShared = true;
00055 } else {
00056
00057 $this->mSharedSupplement = true;
00058 }
00059 }
00060 $this->{$this->mAction}( $this->mShared );
00061 if( $this->mSharedSupplement ) {
00062 $this->fetchUsed( true );
00063 }
00064 }
00065
00072 function fetchUsed( $shared ) {
00073 $dbr = wfGetDB( DB_SLAVE );
00074 $image = $dbr->tableName( 'image' );
00075 $imagelinks = $dbr->tableName( 'imagelinks' );
00076
00077 $sql = "SELECT DISTINCT il_to, img_name
00078 FROM $imagelinks
00079 LEFT OUTER JOIN $image
00080 ON il_to=img_name";
00081 $result = $dbr->query( $sql );
00082
00083 foreach( $result as $row ) {
00084 $this->outputItem( $row->il_to, $shared );
00085 }
00086 $dbr->freeResult( $result );
00087 }
00088
00089 function fetchLocal( $shared ) {
00090 $dbr = wfGetDB( DB_SLAVE );
00091 $result = $dbr->select( 'image',
00092 array( 'img_name' ),
00093 '',
00094 __METHOD__ );
00095
00096 foreach( $result as $row ) {
00097 $this->outputItem( $row->img_name, $shared );
00098 }
00099 $dbr->freeResult( $result );
00100 }
00101
00102 function outputItem( $name, $shared ) {
00103 $file = wfFindFile( $name );
00104 if( $file && $this->filterItem( $file, $shared ) ) {
00105 $filename = $file->getFullPath();
00106 $rel = wfRelativePath( $filename, $this->mBasePath );
00107 $this->output( "$rel\n" );
00108 } else {
00109 wfDebug( __METHOD__ . ": base file? $name\n" );
00110 }
00111 }
00112
00113 function filterItem( $file, $shared ) {
00114 return $shared || $file->isLocal();
00115 }
00116 }
00117
00118 $maintClass = "UploadDumper";
00119 require_once( DO_MAINTENANCE );