MediaWiki REL1_33
dumpUploads.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
32class DumpUploads extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Generates list of uploaded files which can be fed to tar or similar.
36By default, outputs relative paths against the parent directory of $wgUploadDirectory.' );
37 $this->addOption( 'base', 'Set base relative path instead of wiki include root', false, true );
38 $this->addOption( 'local', 'List all local files, used or not. No shared files included' );
39 $this->addOption( 'used', 'Skip local images that are not used' );
40 $this->addOption( 'shared', 'Include images used from shared repository' );
41 }
42
43 public function execute() {
44 global $IP;
45 $this->mAction = 'fetchLocal';
46 $this->mBasePath = $this->getOption( 'base', $IP );
47 $this->mShared = false;
48 $this->mSharedSupplement = false;
49
50 if ( $this->hasOption( 'local' ) ) {
51 $this->mAction = 'fetchLocal';
52 }
53
54 if ( $this->hasOption( 'used' ) ) {
55 $this->mAction = 'fetchUsed';
56 }
57
58 if ( $this->hasOption( 'shared' ) ) {
59 if ( $this->hasOption( 'used' ) ) {
60 // Include shared-repo files in the used check
61 $this->mShared = true;
62 } else {
63 // Grab all local *plus* used shared
64 $this->mSharedSupplement = true;
65 }
66 }
67 $this->{$this->mAction} ( $this->mShared );
68 if ( $this->mSharedSupplement ) {
69 $this->fetchUsed( true );
70 }
71 }
72
78 function fetchUsed( $shared ) {
79 $dbr = $this->getDB( DB_REPLICA );
80 $image = $dbr->tableName( 'image' );
81 $imagelinks = $dbr->tableName( 'imagelinks' );
82
83 $sql = "SELECT DISTINCT il_to, img_name
84 FROM $imagelinks
85 LEFT JOIN $image
86 ON il_to=img_name";
87 $result = $dbr->query( $sql );
88
89 foreach ( $result as $row ) {
90 $this->outputItem( $row->il_to, $shared );
91 }
92 }
93
99 function fetchLocal( $shared ) {
100 $dbr = $this->getDB( DB_REPLICA );
101 $result = $dbr->select( 'image',
102 [ 'img_name' ],
103 '',
104 __METHOD__ );
105
106 foreach ( $result as $row ) {
107 $this->outputItem( $row->img_name, $shared );
108 }
109 }
110
111 function outputItem( $name, $shared ) {
112 $file = wfFindFile( $name );
113 if ( $file && $this->filterItem( $file, $shared ) ) {
114 $filename = $file->getLocalRefPath();
115 $rel = wfRelativePath( $filename, $this->mBasePath );
116 $this->output( "$rel\n" );
117 } else {
118 wfDebug( __METHOD__ . ": base file? $name\n" );
119 }
120 }
121
122 function filterItem( $file, $shared ) {
123 return $shared || $file->isLocal();
124 }
125}
126
127$maintClass = DumpUploads::class;
128require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfFindFile( $title, $options=[])
Find a file.
wfRelativePath( $path, $from)
Generate a relative path name to the given file.
Maintenance script to dump a the list of files uploaded, for feeding to tar or similar.
filterItem( $file, $shared)
fetchUsed( $shared)
Fetch a list of used images from a particular image source.
execute()
Do the actual work.
__construct()
Default constructor.
fetchLocal( $shared)
Fetch a list of all images from a particular image source.
outputItem( $name, $shared)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
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.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
Definition hooks.txt:886
$maintClass
$IP
Definition update.php:3
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25