skip to Main Content

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


  1. 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:

    wget -cq -O - 'https://mediawiki.org/w/api.php?action=query&format=json&list=querypage&qppage=Unusedimages&qplimit=500&qpoffset=0' | jq -r '.query.querypage.results[].title' >> list.txt
    

    Or, you can simply grep:

    wget -cq -O - 'https://mediawiki.org/w/api.php?action=query&format=json&list=querypage&qppage=Unusedimages&qplimit=500&qpoffset=0' | grep -oP '(?<="title":")[^"]+' >> list.txt
    

    You may need to repeat this increasing qpoffset by qplimit 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 script php maintenance/deleteBatch.php -u "deleting user" -r "reason for deletion" list.txt.

    Further reading:

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search