Free Software Directory:Participate/Approval script

From Free Software Directory
< Free Software Directory:ParticipateThis is the approved revision of this page; it is not the most recent. View the most recent revision.
Jump to: navigation, search

This is a much faster workflow for approving "Pages whose approved revision is not their latest", if doing more than ~10 pages

1. Run this to get all the diffs and setup a shell environment for fast reviewing

Use the same bash shell throughout these steps.

mkdir -p /tmp/fsdapprovals
cd /tmp/fsdapprovals
# download all unapproved revs html:
wget -O unapproved 'https://directory.fsf.org/wiki?title=Special:ApprovedRevs&limit=5000&show=notlatest'
# strip to just list of diffs
sed -n '/^<li>.*href="\/wiki.*diff=/p' unapproved > tmp; mv tmp unapproved
# strip those to just the diff urls:
sed -ri 's/&/\&/g;s/^([^"]+"){5}([^"]+).*/\2/;s,^,http://directory.fsf.org,'  unapproved
uniq unapproved > tmp; mv tmp unapproved
# download the diffs
mkdir diffs; cd diffs; wget -i ../unapproved
# setup functions for reviewing in firefox
chunk=10; i=0; mkdir -p ../review-later
l() { m mv "${x[i-chunk+$1+1]}" ../review-later; }
n() {
    x=(*);
    for ((j=0;j<10;j++)); do
        k=$((i+j))
        (( k<=${#x[@]} )) || { echo done; break; }
        z="${x[k]}"
        echo "$((j+1)) $z"
        firefox -new-tab "$PWD/$z"
    done
    i=$((i+10))
}
firefox -new-tab "$PWD/$z"; done; i=$((i+10)); };
convert-approve() {
    f="$1";
    f=${f##*/}; f=${f%&oldid=*}; f=${f/diff=/oldid=}
    f="https://directory.fsf.org/${f}&action=approve"
    # example of $f: https://directory.fsf.org/wiki?title=123sqlengine&action=approve&oldid=39397
}

2. Review diffs quickly in firefox using functions created in the last step

Run the shell command n to load the next $chunk of pages (set to 10 above).

Run the shell command l NUM to not approve the NUM page. NUM matches with the number printed in console. All other pages will be approved in a later step. The diff is moved to ../review-later in case you want it later.

When done reviewing a chunk of pages, close all tabs but 1, and run n again. You must review all chunks, because every unapproved page is included by default to be approved in the later step. Useful firefox keybinds are "ctrl-w" for closing a tab, and "ctrl-tab" for cycling between tabs"


3. Save cookies

Log in to fsd, then save your cookies with cookie exporter extension: https://addons.mozilla.org/en-US/firefox/addon/cookie-exporter/

Go to tools -> export cookies. Save to /tmp/fsdapprovals/cookies.txt

This is needed so wget can act as your logged in user who has the permission to approve an edit.


4. Optionally, test one approval

Run the following code to do just the first approval to test that it's working:

x=(*)
convert-approve "$x"
wget -O ../test_result.html --load-cookies=../cookies.txt "$f"
firefox ../test_result.html


5. Approve all pages not set aside with l

Run the following code:

for x in *; do
    convert-approve "$x"
    echo "$f" >> ../approve
done
mkdir -p ../approval-results
# just having a separate dir for the wget output,
# in case we need it for debugging
cd ../approval-results
wget --load-cookies=../cookies.txt -i ../approve


6. Cleanup

If everything worked, deal with remaining pages, usually in the standard way of browsing the fsd, then remove the temporary directory we've been working in:

rm -r /tmp/fsdapprovals


Development notes (feel free to ignore this)

example of conditionining on username, can be adapted to approve all edits of a user

# finds this html:
# Latest revision as of 20:10, 26 December 2016</a> (<a href="/wiki?title=123sqlengine&action=edit" title="123sqlengine">view source</a>)</strong></div><div id="mw-diff-ntitle2"><a href="/wiki?title=User:Alejandroindependiente

if grep -Eq 'Latest revision as of[^>]*> \([^)]+\)</strong></div><div id="mw-diff-ntitle2"><a href="/wiki\?title=User:Alejandroindependiente' "$f"; then


background of cookie extensions

I checked all other cookie addons, there was only one that was multi-process compatible, but it has a little issue with the export format: https://github.com/vanowm/FirefoxCookiesManagerPlus/issues/124 Anyways, the one I recommended doesn't crash firefox or anything with multi-process forced to be on, so whatever.


background on methodology:

experimented with trying to load final urls in firefox with js but couldn't get it to wait until one is loaded to do the next one. window.open("https://google.com","_self") there were 2 stackoverflow pages suggesting how to hook onto window.load after a window.open, but neither worked for google.com, it may be because google.come overwrote it, but anyways, it's not needed, it just saves a few clicks to export the cookies, so abandoned.

s = document.createElement('script'); s.src = 'file:///a/x.js'; document.body.appendChild(s);


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.