Mediawiki Version: 1.34
PHP Version: 7.3
Database Type: 10.3.24-MariaDB – MariaDB Server
Is there a way to do a "mass delete" of unused pages and pictures. The deleteArchivedFiles.php is not working as expected.
Mediawiki Version: 1.34
PHP Version: 7.3
Database Type: 10.3.24-MariaDB – MariaDB Server
Is there a way to do a "mass delete" of unused pages and pictures. The deleteArchivedFiles.php is not working as expected.
2
Answers
To get the list of unused files, use MediaWiki API:
https://mediawiki.org/w/api.php?action=query&format=json&list=querypage&qppage=Unusedimages&qplimit=500&qpoffset=0.
This URL will fetch 500 records (
qplimit
) for unused files (qppage
) from mediawiki.org (replace with your project) starting from 0 (qpoffset
) in JSON format (format
). XML is also available.You can use
jq
(apt install jq
) to parse JSON and extract full titles of file pages:Or, you can simply
grep
:You may need to repeat this increasing
qpoffset
byqplimit
until there is nothing left in.query.querypage.results
.Assuming that you have collected the list of what you want to delete in the file
list.txt
, one entry per line, use the maintenance scriptphp maintenance/deleteBatch.php -u "deleting user" -r "reason for deletion" list.txt
.Further reading:
Thanks for @Alexander Mashin. I used the same script to get an unused image list but I couldn’t delete the image because I got the non-exist page error when I run the delete batch script. So, I installed https://www.mediawiki.org/wiki/Extension:DeleteBatch extension and open Special:DeleteBatch page and paste the file list. Your images/deleted folder should have correct file permission otherwise, it cannot delete the files.