2006-08-15 05:42:37 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-07-10 16:50:19 +00:00
|
|
|
* Dump a the list of files uploaded, for feeding to tar or similar.
|
2009-08-02 19:35:17 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-07-10 16:50:19 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2006-08-15 05:42:37 +00:00
|
|
|
|
2019-05-14 17:00:34 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2006-08-15 05:42:37 +00:00
|
|
|
|
2012-07-10 16:50:19 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to dump a the list of files uploaded,
|
|
|
|
|
* for feeding to tar or similar.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2018-05-24 01:34:01 +00:00
|
|
|
class DumpUploads extends Maintenance {
|
2019-09-07 13:54:20 +00:00
|
|
|
/** @var string */
|
|
|
|
|
private $mBasePath;
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Generates list of uploaded files which can be fed to tar or similar.
|
|
|
|
|
By default, outputs relative paths against the parent directory of $wgUploadDirectory.' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'base', 'Set base relative path instead of wiki include root', false, true );
|
|
|
|
|
$this->addOption( 'local', 'List all local files, used or not. No shared files included' );
|
|
|
|
|
$this->addOption( 'used', 'Skip local images that are not used' );
|
|
|
|
|
$this->addOption( 'shared', 'Include images used from shared repository' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2010-07-24 20:01:14 +00:00
|
|
|
global $IP;
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->mBasePath = $this->getOption( 'base', $IP );
|
2019-09-07 13:54:20 +00:00
|
|
|
$shared = false;
|
|
|
|
|
$sharedSupplement = false;
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->hasOption( 'shared' ) ) {
|
|
|
|
|
if ( $this->hasOption( 'used' ) ) {
|
2008-03-06 01:07:00 +00:00
|
|
|
// Include shared-repo files in the used check
|
2019-09-07 13:54:20 +00:00
|
|
|
$shared = true;
|
2008-03-06 01:07:00 +00:00
|
|
|
} else {
|
|
|
|
|
// Grab all local *plus* used shared
|
2019-09-07 13:54:20 +00:00
|
|
|
$sharedSupplement = true;
|
2008-03-06 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-07 13:54:20 +00:00
|
|
|
|
|
|
|
|
if ( $this->hasOption( 'local' ) ) {
|
|
|
|
|
$this->fetchLocal( $shared );
|
|
|
|
|
} elseif ( $this->hasOption( 'used' ) ) {
|
|
|
|
|
$this->fetchUsed( $shared );
|
|
|
|
|
} else {
|
|
|
|
|
$this->fetchLocal( $shared );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $sharedSupplement ) {
|
2008-03-06 01:07:00 +00:00
|
|
|
$this->fetchUsed( true );
|
|
|
|
|
}
|
2006-08-15 05:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-03-21 14:55:32 +00:00
|
|
|
* Fetch a list of used images from a particular image source.
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param bool $shared True to pass shared-dir settings to hash func
|
2006-08-15 05:42:37 +00:00
|
|
|
*/
|
2008-03-06 01:07:00 +00:00
|
|
|
function fetchUsed( $shared ) {
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = $this->getDB( DB_REPLICA );
|
2006-08-15 05:42:37 +00:00
|
|
|
$image = $dbr->tableName( 'image' );
|
|
|
|
|
$imagelinks = $dbr->tableName( 'imagelinks' );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2006-08-15 05:42:37 +00:00
|
|
|
$sql = "SELECT DISTINCT il_to, img_name
|
|
|
|
|
FROM $imagelinks
|
2019-03-06 22:01:20 +00:00
|
|
|
LEFT JOIN $image
|
2006-08-15 05:42:37 +00:00
|
|
|
ON il_to=img_name";
|
|
|
|
|
$result = $dbr->query( $sql );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $result as $row ) {
|
2008-03-06 01:07:00 +00:00
|
|
|
$this->outputItem( $row->il_to, $shared );
|
2006-08-15 05:42:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2010-03-21 14:55:32 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch a list of all images from a particular image source.
|
|
|
|
|
*
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param bool $shared True to pass shared-dir settings to hash func
|
2010-03-21 14:55:32 +00:00
|
|
|
*/
|
2008-03-06 01:07:00 +00:00
|
|
|
function fetchLocal( $shared ) {
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = $this->getDB( DB_REPLICA );
|
2008-03-06 01:07:00 +00:00
|
|
|
$result = $dbr->select( 'image',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'img_name' ],
|
2008-03-06 01:07:00 +00:00
|
|
|
'',
|
|
|
|
|
__METHOD__ );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $result as $row ) {
|
2008-03-06 01:07:00 +00:00
|
|
|
$this->outputItem( $row->img_name, $shared );
|
|
|
|
|
}
|
2006-08-15 05:42:37 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2008-03-06 01:07:00 +00:00
|
|
|
function outputItem( $name, $shared ) {
|
2019-05-14 17:00:34 +00:00
|
|
|
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $file && $this->filterItem( $file, $shared ) ) {
|
2016-02-04 16:58:45 +00:00
|
|
|
$filename = $file->getLocalRefPath();
|
2008-03-06 01:07:00 +00:00
|
|
|
$rel = wfRelativePath( $filename, $this->mBasePath );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "$rel\n" );
|
2008-03-06 01:07:00 +00:00
|
|
|
} else {
|
|
|
|
|
wfDebug( __METHOD__ . ": base file? $name\n" );
|
|
|
|
|
}
|
2006-08-15 05:42:37 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2008-03-06 01:07:00 +00:00
|
|
|
function filterItem( $file, $shared ) {
|
|
|
|
|
return $shared || $file->isLocal();
|
2006-08-15 05:42:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 01:34:01 +00:00
|
|
|
$maintClass = DumpUploads::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|