MediaWiki
REL1_19
|
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; 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 // Include shared-repo files in the used check 00054 $this->mShared = true; 00055 } else { 00056 // Grab all local *plus* used shared 00057 $this->mSharedSupplement = true; 00058 } 00059 } 00060 $this-> { $this->mAction } ( $this->mShared ); 00061 if ( $this->mSharedSupplement ) { 00062 $this->fetchUsed( true ); 00063 } 00064 } 00065 00071 function fetchUsed( $shared ) { 00072 $dbr = wfGetDB( DB_SLAVE ); 00073 $image = $dbr->tableName( 'image' ); 00074 $imagelinks = $dbr->tableName( 'imagelinks' ); 00075 00076 $sql = "SELECT DISTINCT il_to, img_name 00077 FROM $imagelinks 00078 LEFT OUTER JOIN $image 00079 ON il_to=img_name"; 00080 $result = $dbr->query( $sql ); 00081 00082 foreach ( $result as $row ) { 00083 $this->outputItem( $row->il_to, $shared ); 00084 } 00085 } 00086 00092 function fetchLocal( $shared ) { 00093 $dbr = wfGetDB( DB_SLAVE ); 00094 $result = $dbr->select( 'image', 00095 array( 'img_name' ), 00096 '', 00097 __METHOD__ ); 00098 00099 foreach ( $result as $row ) { 00100 $this->outputItem( $row->img_name, $shared ); 00101 } 00102 } 00103 00104 function outputItem( $name, $shared ) { 00105 $file = wfFindFile( $name ); 00106 if ( $file && $this->filterItem( $file, $shared ) ) { 00107 $filename = $file->getPath(); 00108 $rel = wfRelativePath( $filename, $this->mBasePath ); 00109 $this->output( "$rel\n" ); 00110 } else { 00111 wfDebug( __METHOD__ . ": base file? $name\n" ); 00112 } 00113 } 00114 00115 function filterItem( $file, $shared ) { 00116 return $shared || $file->isLocal(); 00117 } 00118 } 00119 00120 $maintClass = "UploadDumper"; 00121 require_once( RUN_MAINTENANCE_IF_MAIN );