Skip to content

Commit

Permalink
remove more template blacklisting/template exclusion handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
schmir committed Jul 2, 2013
1 parent dd01021 commit 1e98231
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 151 deletions.
20 changes: 0 additions & 20 deletions docs/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,6 @@ one command.
Maximum size (which can be either width or height, whichever is greater) of
images. If images exceed this maximum size, they're scaled down.

``--template-blacklist=ARTICLE``

A name of an article containing a list of "blacklisted templates", i.e.
MediaWiki templates that should be discarded during rendering.
Example for such a template blacklist page::

* [[Template:SkipMe]]
* [[Template:MeToo]]

``--template-exclusion-category=CATEGORY``

A name of a category: Templates in this cateogry are excluded during rendering.

``--print-template-prefix=PREFIX``

Prefix for "print templates", i.e. templates that are tried to fetch before
regular templates. The default value is 'Print' resultint in print template
names of the form 'Template:PrintNAME' (with NAME being the name of the original
template).

``-o, --output=OUTPUT``

Write output to given file.
Expand Down
6 changes: 1 addition & 5 deletions mwlib/apps/make_nuwiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def fetch_pages_from_metabook(self, api):
'script_extension': self.options.script_extension})


if self.options.print_template_pattern:
nfo["print_template_pattern"] = self.options.print_template_pattern


fsout.nfo = nfo

# fsout.dump_json(nfo=nfo)
Expand All @@ -53,8 +51,6 @@ def fetch_pages_from_metabook(self, api):
licenses=self.licenses,
status=self.status,
progress=self.progress,
print_template_pattern=self.options.print_template_pattern,
template_exclusion_category=self.options.template_exclusion_category,
imagesize=self.options.imagesize,
cover_image=metabook.cover_image,
fetch_images=not self.options.noimages)
Expand Down
33 changes: 1 addition & 32 deletions mwlib/net/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,12 @@ class fetcher(object):
def __init__(self, api, fsout, pages, licenses,
status=None,
progress=None,
print_template_pattern=None,
template_exclusion_category=None,
cover_image=None,
imagesize=800, fetch_images=True):

self.dispatch_event = gevent.event.Event()
self.api_semaphore = gevent.coros.Semaphore(20)

self.print_template_pattern = None
self.template_exclusion_category = None
self.template_blacklist = None
self.cover_image = cover_image

self.pages = pages
Expand Down Expand Up @@ -280,23 +275,11 @@ def __init__(self, api, fsout, pages, licenses,
siteinfo = self.get_siteinfo_for(self.api)
self.fsout.write_siteinfo(siteinfo)
self.nshandler = nshandling.nshandler(siteinfo)
if self.template_exclusion_category:
ns, partial, fqname = self.nshandler.splitname(self.template_exclusion_category, 14)
if ns != 14:
print "bad category name:", repr(self.template_exclusion_category)

params = mwapi.get_collection_params(api)
self.__dict__.update(params)
if template_exclusion_category:
self.template_exclusion_category = template_exclusion_category

if print_template_pattern:
self.print_template_pattern = print_template_pattern

if self.print_template_pattern:
self.make_print_template = utils.get_print_template_maker(self.print_template_pattern)
else:
self.make_print_template = None
self.make_print_template = None

titles, revids = self._split_titles_revids(pages)

Expand Down Expand Up @@ -458,11 +441,6 @@ def fetch_used_block(self, name, lst, expanded):
self.pages_todo.append(t)
self.scheduled.add(t)

if self.print_template_pattern is not None and ":" in t:
t = self.make_print_template(t)
if t not in self.scheduled:
self.pages_todo.append(t)
self.scheduled.add(t)

def get_siteinfo_for(self, m):
return m.get_siteinfo()
Expand Down Expand Up @@ -733,12 +711,6 @@ def doit(name, lst):

self.report()

def _compute_excluded(self):
if self.template_exclusion_category:
ns, partial, fqname = self.nshandler.splitname(self.template_exclusion_category, 14)
excluded = self.cat2members.get(fqname)
if excluded:
self.fsout.write_excluded(excluded)

def _sanity_check(self):
seen = self.fsout.seen
Expand All @@ -757,11 +729,8 @@ def _sanity_check(self):

def finish(self):
self._sanity_check()
self._compute_excluded()
self.fsout.write_redirects(self.redirects)
self.fsout.write_licenses(self.licenses)
if self.fsout.nfo and self.print_template_pattern:
self.fsout.nfo["print_template_pattern"] = self.print_template_pattern
self.fsout.close()

def _refcall(self, fun, *args, **kw):
Expand Down
25 changes: 1 addition & 24 deletions mwlib/net/sapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,7 @@ def guess_api_urls(url):


def get_collection_params(api):
r = api._post(action="expandtemplates",
format="json",
text="""
template_blacklist={{Mediawiki:coll-template_blacklist_title}}
template_exclusion_category={{Mediawiki:coll-exclusion_category_title}}
print_template_pattern={{Mediawiki:coll-print_template_pattern}}
""")

allowed = "template_blacklist template_exclusion_category print_template_pattern".split()
res = dict()
try:
txt = r["expandtemplates"]["*"]
except KeyError:
return res

for k, v in re.findall("([a-z_]+)=(.*)", txt):
v = v.strip()

if v.startswith("[[") or not v:
continue

if k in allowed:
res[str(k)] = v
return res
return dict()


def main():
Expand Down
8 changes: 0 additions & 8 deletions mwlib/nserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ def make_collection_id(data):
for key in (
'base_url',
'script_extension',
'template_blacklist',
'template_exclusion_category',
'print_template_prefix',
'print_template_pattern',
'login_credentials',
):
sio.write(repr(data.get(key)))
Expand Down Expand Up @@ -281,10 +277,6 @@ def _get_params(self, post_data, collection_id):
writer=g('writer', self.default_writer),
base_url=g('base_url'),
writer_options=g('writer_options', ''),
template_blacklist=g('template_blacklist', ''),
template_exclusion_category=g('template_exclusion_category', ''),
print_template_prefix=g('print_template_prefix', ''),
print_template_pattern=g('print_template_pattern', ''),
login_credentials=g('login_credentials', ''),
force_render=bool(g('force_render')),
script_extension=g('script_extension', ''),
Expand Down
4 changes: 0 additions & 4 deletions mwlib/nslave.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ def system(args, timeout=None):


def _get_args(writer_options=None,
template_blacklist=None,
template_exclusion_category=None,
print_template_prefix=None,
print_template_pattern=None,
language=None,
zip_only=False,
login_credentials=None,
Expand Down
14 changes: 1 addition & 13 deletions mwlib/nuwiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ def __setstate__(self, d):
self.set_make_print_template()

def set_make_print_template(self):
p = self.nfo.get("print_template_pattern")
if p and "$1" in p:
self.make_print_template = utils.get_print_template_maker(p)
else:
self.make_print_template = None
self.make_print_template = None

def _loadjson(self, path, default=None):
path = self._pathjoin(path)
Expand Down Expand Up @@ -189,14 +185,6 @@ def _get_page(self, name, revision=None):
oldname = name
name = self.redirects.get(name, name)

if self.make_print_template is not None:
pname = self.make_print_template(name)
r=self.revisions.get(pname)
# print "returning print template", repr(pname)
if r is not None:
# r.title = name # XXX not so sure about that one???
return r

return self.revisions.get(name) or self.revisions.get(oldname)

def get_page(self, name, revision=None):
Expand Down
23 changes: 0 additions & 23 deletions mwlib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ def __init__(self, usage='%prog [OPTIONS] [ARTICLETITLE...]'):
help="exclude images")

a("-l", "--logfile", help="log to logfile")

a("--template-exclusion-category", metavar="CATEGORY",
help="Name of category for templates to be excluded")

a("--print-template-prefix", metavar="PREFIX",
help="Prefix for print templates (deprecated: use --print-template-pattern)")

a("--print-template-pattern", metavar="SUBPAGE",
help="Prefix for print templates, '$1' is replaced by original template name")

a("--template-blacklist", metavar="ARTICLE",
help="Title of article containing blacklisted templates")

a("--username", help="username for login")
a("--password", help="password for login")
Expand Down Expand Up @@ -117,17 +105,6 @@ def parse_args(self):

self.metabook.append_article(title)

if self.options.print_template_pattern and "$1" not in self.options.print_template_pattern:
self.error("bad --print-template-pattern argument [must contain $1, but %r does not]" % (self.options.print_template_pattern,))


if self.options.print_template_prefix and self.options.print_template_pattern:
log.warn('Both --print-template-pattern and --print-template-prefix (deprecated) specified. Using --print-template-pattern only.')
elif self.options.print_template_prefix:
self.options.print_template_pattern = '%s$1' % self.options.print_template_prefix

del self.options.print_template_prefix

return self.options, self.args

def makewiki(self):
Expand Down
4 changes: 0 additions & 4 deletions mwlib/postman.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def get_collection_dir(collection_id):


def _get_args(writer_options=None,
template_blacklist=None,
template_exclusion_category=None,
print_template_prefix=None,
print_template_pattern=None,
language=None,
zip_only=False,
**kw):
Expand Down
4 changes: 0 additions & 4 deletions mwlib/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ def make_collection_id(data):
_version.version,
'base_url',
'script_extension',
'template_blacklist',
'template_exclusion_category',
'print_template_prefix',
'print_template_pattern',
'login_credentials',
):
sio.write(repr(data.get(key)))
Expand Down
14 changes: 0 additions & 14 deletions mwlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@
log = Log('mwlib.utils')


def get_print_template_maker(pattern):
assert "$1" in pattern, 'pattern %r does not contain "$1"' % pattern

def make_print_template(title):
if ':' in title:
p, s = title.split(":", 1)
s = pattern.replace("$1", s)
return '%s:%s' % (p, s)
else:
return pattern.replace("$1", title)

return make_print_template


def fsescape(s):
"""Escape string to be safely used in path names
Expand Down

0 comments on commit 1e98231

Please sign in to comment.