Last active
August 17, 2023 19:18
-
-
Save znnahiyan/4c017c8bd97fffa42138 to your computer and use it in GitHub Desktop.
Lists and downloads all the dependencies of a supplied module's name from Wikipedia's servers. Usage: ./antidependency.sh Module:NAME1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
## Maintainer: [[User:Nahiyan8]] @ Wikimedia (en, bn) | |
## Copyright: Public domain, but I don't think anyone will be able to modify this... | |
## Created in: 2014-11-22 | |
## Last modified: 2014-11-22 | |
## | |
## | |
## Usage: | |
## $ ./antidependench.sh Module:NAME1 [Module:NAME2] ... | |
## | |
## @NOTE: All downloaded module codes will be downloaded into the current directory. | |
## @NOTE: All spaces in NAMEs must be replaced by _ (underscores). Example: Module:Message_box | |
## | |
## | |
## Instructions: | |
## Copy-paste/Download the code into a file named antidependency.sh, keeping care of the first line. | |
## | |
## Run these in your terminal. (don't copy the $, they signify the shell prompt.) | |
## $ cd /path/where/script/exists/ | |
## $ chmod +x ./antidependency.sh | |
## $ ./antidependency.sh Module:YOURMODULENAMEHERE | |
## | |
## Watch the code go by, and when it ends, copy the final list of modules and go to the wiki's special pages | |
## and click the "Export pages" link. Paste the list of modules that the script outputted last into the big box, | |
## and then click the button to export them, a download should start for an .xml file. | |
## | |
## Lastly, go into your own wiki's special pages to import the .xml, which contains the modules. Congratulations! | |
## | |
## | |
## @NOTE: When using this script to copy modules for your own wiki, please note, that a lot of Wikipedia modules | |
## were written for the latest development versions of MediaWiki and their assorted extensions as well. | |
## In particular, as of the time of this writing, the latest stable MediaWiki 1.23.6 is unable to run | |
## Module:HtmlBuilder correctly and fails because of a bad type test. It was fixed but only released | |
## on the on 1.24, which isn't released as stable yet. | |
## | |
## | |
## @WARNING: This script may fail if a script has a string like: 'Module:SOMETHINGHERE' but isn't a script. | |
## To fix the error, specify the affected modules in the blacklist variable, with the spaces in their | |
## name replaced by _ (underscores). Example: blacklist="Module:Bananas Module:Some_other_bananas" | |
## | |
## Customise this to any wiki's url to api.php, it usually should be in the same place as the index.php | |
## (e.g. http://www.example.com/wiki/index.php -> means -> api_url = http://www.example.com/wiki/api.php | |
## @NOTE: You might have to remove "&rawcontinue=" from the url=... line in the code, if the script doesn't work. | |
api_url="http://en.wikipedia.org/w/api.php" | |
blacklist="" | |
## Don't customise these lines, of course. These make the first module (that you specified) download. | |
needed="$@" | |
next="$1" | |
while [ ! -z "$next" ]; do | |
url="$api_url?action=query&rawcontinue=&format=xml&prop=revisions&rvprop=content&titles=$next" | |
temp=$(curl -U"AntiDependency.sh: [[User:Nahiyan8]]" -s "$url" | sed -e"s/^.*xml:space=\"preserve\">//" -e"s|</rev>.*$||" | tee ./$(echo "$next" | tr '/' '-') | grep -Eo "'Module:[^']+'" | sed -e "s/^'//" -e "s/'$//") | |
needed="$needed $(echo "$temp" | tr ' ' '_' | sort -u | tr '\n' ' ')" | |
needed="$(echo "$needed" | tr ' ' '\n' | sort -u | tr '\n' ' ')" | |
echo "Needed:$needed" 1>&2 | |
done="$(echo "$done $next" | tr ' ' '\n' | sort -u | tr '\n' ' ')" | |
next="$(comm -23 <(echo "$needed" | tr ' ' '\n' | sort -u) <(echo "$done $blacklist" | tr ' ' '\n' | sort -u) | tr '\n' ' ' | sed -e's/^ *//' -e's/ .*//')" | |
echo "Done:$done" 1>&2 | |
echo "Next: $next" 1>&2 | |
echo 1>&2 | |
sleep 4 | |
done | |
echo "FINAL:" | |
echo "$(echo "$needed" | tr ' ' '\n')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment