39 parent::__construct();
40 $this->
addDescription(
'Generates list of uploaded files which can be fed to tar or similar.
41By default, outputs relative paths against the parent directory of $wgUploadDirectory.' );
42 $this->
addOption(
'base',
'Set base relative path instead of wiki include root',
false,
true );
43 $this->
addOption(
'local',
'List all local files, used or not. No shared files included' );
44 $this->
addOption(
'used',
'Skip local images that are not used' );
45 $this->
addOption(
'shared',
'Include images used from shared repository' );
50 $this->mBasePath = $this->
getOption(
'base', $IP );
52 $sharedSupplement =
false;
60 $sharedSupplement =
true;
65 $this->fetchLocal( $shared );
67 $this->fetchUsed( $shared );
69 $this->fetchLocal( $shared );
72 if ( $sharedSupplement ) {
73 $this->fetchUsed(
true );
82 private function fetchUsed( $shared ) {
85 $result =
$dbr->newSelectQueryBuilder()
86 ->select( [
'il_to',
'img_name' ] )
88 ->from(
'imagelinks' )
89 ->leftJoin(
'image',
null,
'il_to=img_name' )
90 ->caller( __METHOD__ )
93 foreach ( $result as $row ) {
94 $this->outputItem( $row->il_to, $shared );
103 private function fetchLocal( $shared ) {
105 $result =
$dbr->newSelectQueryBuilder()
106 ->select(
'img_name' )
108 ->caller( __METHOD__ )
111 foreach ( $result as $row ) {
112 $this->outputItem( $row->img_name, $shared );
116 private function outputItem( $name, $shared ) {
117 $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
118 if (
$file && $this->filterItem(
$file, $shared ) ) {
119 $filename =
$file->getLocalRefPath();
121 $this->
output(
"$rel\n" );
123 wfDebug( __METHOD__ .
": base file? $name" );
127 private function filterItem(
$file, $shared ) {
128 return $shared ||
$file->isLocal();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.