1 Page Protection: Another Missing Dimension of Wikipedia Research
2 -------------------------------------------------------------------------
4 | Author: Benjamin Mako Hill <mako@atdot.cc> and Aaron Shaw <aaron.d.shaw@gmail.com>
5 | Homepage: http://communitydata.cc/wiki-protection/
6 | Archival copy: http://dx.doi.org/10.7910/DVN/P1VECE
7 | Code: http://projects.mako.cc/source/?p=protection-tools
8 | License: GNU GPLv3 or any later version
11 Tools to generate a protection spells dataset from "raw" MediaWiki
12 XML dumps like those published by the Wikimedia foundation.
15 ----------------------
17 page protection log data is very uneven and changed its format many
18 times. For several years before 2008-09, data on the specific rights
19 were recorded in comment fields but this was subject to incorrect
20 parsing because people sometimes added additional information (or
21 tried to reproduce the format "by hand" as well).
23 This code is limited to extracting and parsing only the most reliable
24 information which means only protection data from 2008-09 and the
25 point of data collection.
27 There are two sources of page protection data:
29 - A log file that contains log events including protections, moves,
30 deletions, blocks, etc.
32 - A snapshot from Wikipedia MySQL database of protected pages at the
33 point that the database (and log) was exported.
35 As mentioned above, our log data begins only in 2008-09 which means we
36 have data on protection spells that is both right censored (i.e.,
37 ongoing protection events) and left censored (i.e., protect spells
38 that were ongoing in 2008-09. Because protection data was not
39 recorded reliably over Wikipedia's history, we believe that avoiding
40 censoring (either left or right) is not technically possible given the
41 data sources the WMF has published.
44 |---------|----------------|----->
45 2004 <x> 2008 <y> 2015 <z>
48 Because we don't have a perfect data for the beginning of any window,
49 it means that events that happened are invisible to us unless they are
50 ongoing at the point of data collection. When our dataset starts in
51 2008 (as it does in the dataset we produce here where the log format
52 stabilizes, this means that there are two conditions where data will
53 be missing (refer to the timeline figure above):
55 a) If a page is protected in <x> and is deleted in <y> we wll have no
56 indication that the page was protected at all and no page
57 protection spells will be included in the database.
59 b) If a page is protected in <x> and its protection status is changed
60 at any time <t> during period <y> (i.e., either by adjusting the
61 rights, updating the expiration time, or unprotecting the page) we
62 will know that the page was protected during the period from the
63 beginning of <y> until <t> but will we not know the specific rights
64 associated with the protection. We will have complete data on the
65 protection status of that page from <t> onward.
69 -----------------------------
71 0. Install dependencies
72 ===========================
76 - `data.table` R package available on CRAN
79 ==========================
81 First, download a dump of MediWiki log actions. WMF distributes these
82 for English Wikipedia at http://dumps.wikimedia.org. For example, the
83 latest version when we wrote this document was this file:
85 https://dumps.wikimedia.org/enwiki/20150112/enwiki-20150112-pages-logging.xml.gz
87 You will also need a page that includes the status of protected pages
88 at the point that data was created in the database. WMF distributes
89 these from http://dumps.wikimedia.org as well. For example, the latest
92 https://dumps.wikimedia.org/enwiki/20150112/enwiki-20150112-page_restrictions.sql.gz
94 Finally, because the table above maps only page ID numbers to
95 restriction events, we'll need a mapping of page IDs to page titles
96 which is contained in a table like this one (the latest at the time of
99 https://dumps.wikimedia.org/enwiki/20150112/enwiki-20150112-page.sql.gz
102 ============================
104 An important first step is parsing the two wQL dumps file into CSV
105 format. We can use the `mysqldump_to_csv.py` to do this like:
107 $ zcat enwiki-20150112-page_restrictions.sql.gz | ./02-mysqldump_to_csv.py \
108 > enwiki-20150112-page_restrictions.csv
110 $ zcat enwiki-20150112-page.sql.gz | ./02-mysqldump_to_csv.py \
111 > enwiki-20150112-page.csv
113 The first file is small and should be very quick. The second file is
114 larger but still should still take only several minutes.
116 The number is adapated from: https://github.com/jamesmishra/mysqldump-to-csv
119 =================================
121 The log file that contains changes over time is much larger and will
122 take several hours to parse for English Wikipedia even on a very fast
123 machine. The page log can be parsed using the file like:
125 $ zcat enwiki-20150112-pages-logging.xml.gz | ./03-parse_mw_event_log.py
127 This will produce several TSV files of the log file in several different
131 output-protection.tsv
134 If you pass an XML filename to 03-parse_mw_event_log.py, these file
135 will not be called output but something based on the root of the
138 4. Import Data Into R
139 =============================
141 Import all of the data that we've created into a series of RData
142 files. You'll need to first edit the file `04-import_data.R` so that
143 the input files (all defined at teh very top of the script) match the
144 files that you've downloaded and created.
146 Once you've done that, you can run the R script which will load and
149 $ R --no-save < 04-import_data.R
151 This will output an RData file called `processed_log_and_sql_data.RData`.
154 =============================
156 Finally, we run the command that reads in all the prepared dataset and
157 generates the spells dataset:
159 $ R --no-save < 05-generate_spells.R
161 This will generate the final page protection dataset: `spells.RData`