Difference between revisions of "User:TidB/Operation Cleanup/Filters"

From Team Fortress Wiki
Jump to: navigation, search
(I may be misunderstading you a bit, but this should be correct (?))
(The problem with a lot of what this program is doing is that it's not really practical to automate it -- too liable to break something.)
 
(9 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
 
As I haven't looked into both wikitools' and WindBOT's code too much, this is really just a concept.
 
As I haven't looked into both wikitools' and WindBOT's code too much, this is really just a concept.
 +
=== Removing {{code|<nowiki>{{DISPLAYTITLE}}</nowiki>}} from certain pages ===
 
<pre>
 
<pre>
 
def check_displaytitle(t, **kwargs):
 
def check_displaytitle(t, **kwargs):
 
     displaytitle_notrequired = ["Cosmetic items", "Weapons", "Patches", "Tools", "Action items"]
 
     displaytitle_notrequired = ["Cosmetic items", "Weapons", "Patches", "Tools", "Action items"]
     displaytitle_required = ["Major updates", "Content Packs"]  # Set because major updates are also in the "patches" category
+
     displaytitle_required = ["Major updates", "Content Packs"]  # Set because these are also in the "patches" category
 
     if t.getName().startswith("DISPLAYTITLE:"):  # why do we need a getter method btw?
 
     if t.getName().startswith("DISPLAYTITLE:"):  # why do we need a getter method btw?
         categories = kwargs["page"].getCategories()  # I'm just guessing the return type is a list, will check later
+
         categories = kwargs["article"].getCategories()  # I'm just guessing the return type is a list, will check later
         language = kwargs["page"].title.split()[1]  # I know it's ugly, but I dunno if there are easier sources to get the language code
+
        print kwargs["article"].title
         if c:
+
         language = kwargs["article"].title.split("/")[-1]  # I know it's ugly, but I dunno if there are easier sources to get the language code. It's cleaner to check it with a list, though
            for c in displaytitle_required:
+
 
                if "Category:{}/{}".format(c, language) in categories]:
+
         for c in displaytitle_required:
                    return t
+
            if "Category:{}/{}".format(c, language) in categories:
         for category in displaytitle_notrequired:
+
                return t
             if "Category:{}/{}".format(category, language) in categories:
+
         for c in displaytitle_notrequired:
 +
             if "Category:{}/{}".format(c, language) in categories:
 
                 return None
 
                 return None
 +
    return t
 
addTemplateFilter(check_displaytitle)
 
addTemplateFilter(check_displaytitle)
 
</pre>
 
</pre>
 +
 +
=== Removing the {{code|name}} parameter from item infoboxes ===
 +
def name_parameter(t, **kwargs):
 +
    if t.getName() == "Item infobox":  # 'getName()' seems to return the stripped name; no newlines
 +
        t.delParam("name")
 +
    return t
 +
addTemplateFilter(name_parameter)

Latest revision as of 16:18, 4 February 2015

Test page; will poot filter concepts for User:WindBOT here. Later (my favorite word).

As I haven't looked into both wikitools' and WindBOT's code too much, this is really just a concept.

Removing {{DISPLAYTITLE}} from certain pages

def check_displaytitle(t, **kwargs):
    displaytitle_notrequired = ["Cosmetic items", "Weapons", "Patches", "Tools", "Action items"]
    displaytitle_required = ["Major updates", "Content Packs"]  # Set because these are also in the "patches" category
    if t.getName().startswith("DISPLAYTITLE:"):  # why do we need a getter method btw?
        categories = kwargs["article"].getCategories()  # I'm just guessing the return type is a list, will check later
        print kwargs["article"].title
        language = kwargs["article"].title.split("/")[-1]  # I know it's ugly, but I dunno if there are easier sources to get the language code. It's cleaner to check it with a list, though

        for c in displaytitle_required:
            if "Category:{}/{}".format(c, language) in categories:
                return t
        for c in displaytitle_notrequired:
            if "Category:{}/{}".format(c, language) in categories:
                return None
    return t
addTemplateFilter(check_displaytitle)

Removing the name parameter from item infoboxes

def name_parameter(t, **kwargs):
    if t.getName() == "Item infobox":  # 'getName()' seems to return the stripped name; no newlines
        t.delParam("name")
    return t
addTemplateFilter(name_parameter)