User:AnomieBOT/source/tasks/WikiProjectWorker.pm

This is an old revision of this page, as edited by AnomieBOT (talk | contribs) at 17:52, 23 July 2009 (Updating published sources: d::WikiProjectTagging: * Add change reporting to WPBfixshell(). * Have WPBfixshell() change shell to WPB if >=6 banners, WPBS if <=3. WikiProjectTagger: * End WP:LONDON run. Seems to have been finished anyway before Domas). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
package tasks::WikiProjectWorker;

=pod

=begin metadata

Task:     WikiProjectWorker
BRFA:     Wikipedia:Bots/Requests for approval/AnomieBOT 28
Status:   Approved 2009-04-08
Rate:     Max 6 edits/minute
Created:  2009-03-27
OnDemand: true

Perform various tasks at the request of the affected WikiProjects:
* Add or remove banners on a specific set of pages (e.g. pages in a category, pages transcluding a template).
* Adjust banner parameters, particularly assessments and task forces.
* Fix banner shells on pages edited for the above reasons.

=end metadata

=cut

use utf8;
use strict;

use Data::Dumper;
use Digest::SHA qw/sha256_base64/;
use AnomieBOT::Task;
use vars qw/@ISA/;
@ISA=qw/AnomieBOT::Task/;

### Request link, for edit summary.
my $req="[[User:AnomieBOT/req/WikiProject NRHP 1|request]]";

### Increment this number every time a new run is started, so we don't have to
### mess around with deleting previous runs' database entries.
my $seq=7;

### How to find the pages?
my @cats=(
    'Category:National Register of Historic Places in Alabama',
    'Category:National Register of Historic Places in Alabama by county',
    'Category:Bridges on the National Register of Historic Places in Alabama',
    'Category:Houses on the National Register of Historic Places in Alabama',
    'Category:National Register of Historic Places Multiple Property Submissions in Alabama',
    'Category:National Historic Landmarks in Alabama',
    'Category:National Historic Sites in Alabama',
    'Category: Buildings of religious function on the National Register of Historic Places in Alabama',
    'Category:Alabama Registered Historic Place stubs',
    'Category:National Register of Historic Places in Alaska',
    'Category:National Historic Landmarks in Alaska',
    'Category:National Historic Sites in Alaska',
    'Category:National Register of Historic Places in Alaska by borough and census area',
    'Category:Houses on the National Register of Historic Places in Alaska',
    'Category:Buildings of religious function on the National Register of Historic Places in Alaska',
    'Category:Alaska Registered Historic Place stubs',
    'Category:National Register of Historic Places in Alaska',
    'Category:National Historic Landmarks in Arizona',
    'Category:National Historic Sites in Arizona',
    'Category:National Register of Historic Places in Arizona by county',
    'Category:Arizona Registered Historic Place stubs',
    'Category:National Register of Historic Places in Arkansas',
    'Category:National Historic Landmarks in Arkansas',
    'Category:National Historic Sites in Arkansas',
    'Category:Houses on the National Register of Historic Places in Arkansas',
    'Category:Arkansas Registered Historic Place stubs',
    'Category:National Register of Historic Places in California',
    'Category:National Historic Landmarks in California',
    'Category:National Historic Sites in California',
    'Category:National Register of Historic Places in the San Fernando Valley',
    'Category:Registered Historic Places of religious function in California',
    'Category:National Register of Historic Places in the San Francisco Bay Area',
    'Category:National Register of Historic Places in Sonoma County, California',
    'Category:California Registered Historic Place stubs',
    'Category:National Register of Historic Places in Colorado',
    'Category:National Historic Landmarks in Colorado',
    'Category:National Historic Sites in Colorado',
    'Category:National Register of Historic Places in Colorado by county',
    'Category:Buildings of religious function on the National Register of Historic Places in Colorado',
    'Category:National Register of Historic Places in Connecticut',
    'Category:National Historic Landmarks in Connecticut',
    'Category:National Historic Sites in Connecticut',
    'Category:National Register of Historic Places in Fairfield County, Connecticut',
    'Category:National Register of Historic Places in Delaware',
    'Category:National Historic Landmarks in Delaware',
    'Category:Houses on the National Register of Historic Places in Delaware',
    'Category:Buildings of religious function on the National Register of Historic Places in Delaware',
    'Category:National Register of Historic Places in Florida',
    'Category:National Register of Historic Places in Florida by county',
    'Category:Houses on the National Register of Historic Places in Florida',
    'Category:National Register of Historic Places Multiple Property Submissions in Florida',
    'Category:National Historic Landmarks in Florida',
    'Category:National Register of Historic Places in Alachua County, Florida',
    'Category:National Register of Historic Places in Brevard County, Florida',
    'Category:National Register of Historic Places in Broward County, Florida',
    'Category:National Register of Historic Places in Charlotte County, Florida',
    'Category:National Register of Historic Places in Clay County, Florida',
    'Category:National Register of Historic Places in Collier County, Florida',
    'Category:National Register of Historic Places in Duval County, Florida',
    'Category:National Register of Historic Places in Escambia County, Florida',
    'Category:National Register of Historic Places in Hillsborough County, Florida',
    'Category:National Register of Historic Places in Indian River County, Florida',
    'Category:National Register of Historic Places in Jefferson County, Florida',
    'Category:National Register of Historic Places in Lake County, Florida',
    'Category:National Register of Historic Places in Lee County, Florida',
    'Category:National Register of Historic Places in Leon County, Florida',
    'Category:National Register of Historic Places in Manatee County, Florida',
    'Category:National Register of Historic Places in Marion County, Florida',
    'Category:National Register of Historic Places in Miami-Dade County, Florida',
    'Category:National Register of Historic Places in Monroe County, Florida',
    'Category:National Register of Historic Places in Orange County, Florida',
    'Category:National Register of Historic Places in Palm Beach County, Florida',
    'Category:National Register of Historic Places in Pinellas County, Florida',
    'Category:National Register of Historic Places in Polk County, Florida',
    'Category:National Register of Historic Places in Putnam County, Florida',
    'Category:Buildings of religious function on the National Register of Historic Places in Florida',
    'Category:National Register of Historic Places in St. Johns County, Florida',
    'Category:National Register of Historic Places in St. Lucie County, Florida',
    'Category:National Register of Historic Places in Santa Rosa County, Florida',
    'Category:National Register of Historic Places in Sarasota County, Florida',
    'Category:National Register of Historic Places in Seminole County, Florida',
    'Category:National Register of Historic Places in Volusia County, Florida',
    'Category:Duval County Registered Historic Places building and structure stubs',
    'Category:Florida Registered Historic Places building and structure stubs',
    'Category:Florida Registered Historic Places district stubs',
    'Category:Hillsborough County Registered Historic Places building and structure stubs',
    'Category:Miami-Dade County Registered Historic Places building and structure stubs',
    'Category:Sarasota County Registered Historic Places building and structure stubs',
    'Category:National Register of Historic Places in Miami, Florida',
    'Category:National Register of Historic Places in Key West, Florida',
    'Category:Duval County Registered Historic Places building and structure stubs',
    'Category:Hillsborough County Registered Historic Places building and structure stubs',
    'Category:Miami-Dade County Registered Historic Places building and structure stubs',
    'Category:Sarasota County Registered Historic Places building and structure stubs',
    'Category:Houses on the National Register of Historic Places in Hillsborough County, Florida',
    'Category:Houses on the National Register of Historic Places in Sarasota County, Florida',
    'Category:Houses on the National Register of Historic Places in Hillsborough County, Florida',
    'Category:Houses on the National Register of Historic Places in Sarasota County, Florida',
    'Category:Houses on the National Register of Historic Places in Volusia County, Florida',
    'Category:National Register of Historic Places in Georgia (U.S. state)',
    'Category:National Historic Landmarks in Georgia (U.S. state)',
    'Category:National Historic Sites in Georgia (U.S. state)',
    'Category:National Register of Historic Places in Hawaii',
    'Category:National Historic Landmarks in Hawaii',
    'Category:National Historic Sites in Hawaii',
    'Category:Houses on the National Register of Historic Places in Hawaii',
    'Category:Buildings of religious function on the National Register of Historic Places in Hawaii',
    'Category:National Register of Historic Places in Idaho',
    'Category:National Historic Landmarks in Idaho',
    'Category:National Register of Historic Places in Idaho by county',
    'Category:Houses on the National Register of Historic Places in Idaho',
    'Category:National Historic Sites in Idaho',
    'Category:Buildings of religious function on the National Register of Historic Places in Idaho',
    'Category:National Register of Historic Places in Illinois',
    'Category:National Historic Landmarks in Illinois',
    'Category:National Historic Sites in Illinois',
    'Category:National Register of Historic Places in Boone County, Illinois',
    'Category:National Register of Historic Places in Cook County, Illinois',
    'Category:National Register of Historic Places in DeKalb County, Illinois',
    'Category:National Register of Historic Places in DuPage County, Illinois',
    'Category:National Register of Historic Places Multiple Property Submissions in Illinois',
    'Category:National Register of Historic Places in Jo Daviess County, Illinois',
    'Category:National Register of Historic Places in Kendall County, Illinois',
    'Category:National Register of Historic Places in Lake County, Illinois',
    'Category:National Register of Historic Places in Lee County, Illinois',
    'Category:National Register of Historic Places in McHenry County, Illinois',
    'Category:National Register of Historic Places in McLean County, Illinois',
    'Category:National Register of Historic Places in LaSalle County, Illinois',
    'Category:National Register of Historic Places in Montgomery County, Illinois',
    'Category:National Register of Historic Places in Sangamon County, Illinois',
    'Category:National Register of Historic Places in Chicago, Illinois',
    'Category:National Register of Historic Places in Ogle County, Illinois',
    'Category:National Register of Historic Places in Peoria County, Illinois',
    'Category:National Register of Historic Places in Stephenson County, Illinois',
    'Category:National Register of Historic Places in Whiteside County, Illinois',
    'Category:National Register of Historic Places in Will County, Illinois',
    'Category:Illinois Registered Historic Place stubs',
    'Category:National Register of Historic Places in Indiana',
    'Category:National Historic Landmarks in Indiana',
    'Category:National Register of Historic Places in Adams County, Indiana',
    'Category:National Register of Historic Places in Allen County, Indiana',
    'Category:National Register of Historic Places in Bartholomew County, Indiana',
    'Category:National Register of Historic Places in Benton County, Indiana',
    'Category:National Register of Historic Places in Clark County, Indiana',
    'Category:National Register of Historic Places in Clinton County, Indiana',
    'Category:National Register of Historic Places in Crawford County, Indiana',
    'Category:National Register of Historic Places in Daviess County, Indiana',
    'Category:National Register of Historic Places in Dearborn County, Indiana',
    'Category:National Register of Historic Places in Delaware County, Indiana',
    'Category:National Register of Historic Places in Elkhart County, Indiana',
    'Category:National Register of Historic Places in Fayette County, Indiana',
    'Category:National Register of Historic Places in Floyd County, Indiana',
    'Category:National Register of Historic Places in Franklin County, Indiana',
    'Category:National Register of Historic Places in Fulton County, Indiana',
    'Category:National Register of Historic Places in Grant County, Indiana',
    'Category:National Register of Historic Places in Hancock County, Indiana',
    'Category:National Register of Historic Places in Harrison County, Indiana',
    'Category:National Register of Historic Places in Henry County, Indiana',
    'Category:National Register of Historic Places in Howard County, Indiana',
    'Category:National Register of Historic Places in Huntington County, Indiana',
    'Category:National Register of Historic Places in Indianapolis, Indiana',
    'Category:National Register of Historic Places in Jackson County, Indiana',
    'Category:National Register of Historic Places in Jefferson County, Indiana',
    'Category:National Register of Historic Places in Knox County, Indiana',
    'Category:National Register of Historic Places in LaGrange County, Indiana',
    'Category:National Register of Historic Places in Lake County, Indiana',
    'Category:National Register of Historic Places in Lawrence County, Indiana',
    'Category:National Register of Historic Places in Madison County, Indiana',
    'Category:National Register of Historic Places in Marshall County, Indiana',
    'Category:National Register of Historic Places in Miami County, Indiana',
    'Category:National Register of Historic Places in Monroe County, Indiana',
    'Category:National Register of Historic Places in Montgomery County, Indiana',
    'Category:National Register of Historic Places in Morgan County, Indiana',
    'Category:National Register of Historic Places in Noble County, Indiana',
    'Category:National Register of Historic Places in Ohio County, Indiana',
    'Category:National Register of Historic Places in Orange County, Indiana',
    'Category:National Register of Historic Places in Owen County, Indiana',
    'Category:National Register of Historic Places in Parke County, Indiana',
    'Category:National Register of Historic Places in Porter County, Indiana',
    'Category:National Register of Historic Places in Pulaski County, Indiana',
    'Category:National Register of Historic Places in Putnam County, Indiana',
    'Category:National Register of Historic Places in Rush County, Indiana',
    'Category:National Register of Historic Places in Scott County, Indiana',
    'Category:National Register of Historic Places in St. Joseph County, Indiana',
    'Category:National Register of Historic Places in Sullivan County, Indiana',
    'Category:National Register of Historic Places in Switzerland County, Indiana',
    'Category:National Register of Historic Places in Tippecanoe County, Indiana',
    'Category:National Register of Historic Places in Vanderburgh County, Indiana',
    'Category:National Register of Historic Places in Vigo County, Indiana',
    'Category:National Register of Historic Places in Warren County, Indiana',
    'Category:National Register of Historic Places in Washington County, Indiana',
    'Category:National Register of Historic Places in Wayne County, Indiana',
    'Category:National Register of Historic Places in Whitley County, Indiana',
    'Category:Indiana Registered Historic Place stubs',
    'Category:National Historic Landmarks in Indianapolis, Indiana',
    'Category:National Historic Landmarks in Indianapolis, Indiana',
    'Category:National Register of Historic Places in Evansville',
    'Category:National Register of Historic Places in Terre Haute',
    'Category:National Register of Historic Places in Iowa',
    'Category:National Historic Landmarks in Iowa',
    'Category:National Historic Sites in Iowa',
    'Category:National Register of Historic Places in Iowa by county',
    'Category:Houses on the National Register of Historic Places in Iowa',
    'Category:Buildings of religious function on the National Register of Historic Places in Iowa',
    'Category:National Register of Historic Places in Kansas',
    'Category:National Historic Landmarks in Kansas',
    'Category:National Historic Sites in Kansas',
    'Category:National Register of Historic Places in Kansas by county',
    'Category:Houses on the National Register of Historic Places in Kansas',
    'Category:Buildings of religious function on the National Register of Historic Places in Kansas ',
    'Category:Kansas Registered Historic Place stubs',
    'Category:National Register of Historic Places in Kentucky',
    'Category:National Historic Landmarks in Kentucky',
    'Category:National Register of Historic Places in Kentucky by county',
    'Category:National Register of Historic Places in Bath County, Kentucky',
    'Category:National Register of Historic Places in Bell County, Kentucky',
    'Category:National Register of Historic Places in Bracken County, Kentucky',
    'Category:National Register of Historic Places in Bullitt County, Kentucky',
    'Category:National Register of Historic Places in Clay County, Kentucky',
    'Category:National Register of Historic Places in Harlan County, Kentucky',
    'Category:National Register of Historic Places in Knox County, Kentucky',
    'Category:National Register of Historic Places in LaRue County, Kentucky',
    'Category:National Register of Historic Places in Lewis County, Kentucky',
    'Category:National Register of Historic Places in Madison County, Kentucky',
    'Category:National Register of Historic Places in Montgomery County, Kentucky',
    'Category:National Register of Historic Places in Pendleton County, Kentucky',
    'Category:National Register of Historic Places in Powell County, Kentucky',
    'Category:National Register of Historic Places in Pulaski County, Kentucky',
    'Category:National Register of Historic Places in Shelby County, Kentucky',
    'Category:National Register of Historic Places in Trigg County, Kentucky',
    'Category:Kentucky Registered Historic Place stubs',
    'Category:National Register of Historic Places in Anderson County, Kentucky',
    'Category:National Register of Historic Places in Barren County, Kentucky',
    'Category:National Register of Historic Places in Boone County, Kentucky',
    'Category:National Register of Historic Places in Bourbon County, Kentucky',
    'Category:National Register of Historic Places in Boyle County, Kentucky',
    'Category:National Register of Historic Places in Butler County, Kentucky',
    'Category:National Register of Historic Places in Caldwell County, Kentucky',
    'Category:National Register of Historic Places in Calloway County, Kentucky',
    'Category:National Register of Historic Places in Campbell County, Kentucky',
    'Category:National Register of Historic Places in Christian County, Kentucky',
    'Category:National Register of Historic Places in Clark County, Kentucky',
    'Category:National Register of Historic Places in Daviess County, Kentucky',
    'Category:National Register of Historic Places in Fayette County, Kentucky',
    'Category:National Register of Historic Places in Franklin County, Kentucky',
    'Category:National Register of Historic Places in Fulton County, Kentucky',
    'Category:National Register of Historic Places in Garrard County, Kentucky',
    'Category:National Register of Historic Places in Graves County, Kentucky',
    'Category:National Register of Historic Places in Grayson County, Kentucky',
    'Category:National Register of Historic Places in Green County, Kentucky',
    'Category:National Register of Historic Places in Hardin County, Kentucky',
    'Category:National Register of Historic Places in Harrison County, Kentucky',
    'Category:National Register of Historic Places in Hart County, Kentucky',
    'Category:National Register of Historic Places in Henderson County, Kentucky',
    'Category:National Register of Historic Places in Henry County, Kentucky',
    'Category:National Register of Historic Places in Hickman County, Kentucky',
    'Category:National Register of Historic Places in Jefferson County, Kentucky',
    'Category:National Register of Historic Places in Jessamine County, Kentucky',
    'Category:National Register of Historic Places in Kenton County, Kentucky',
    'Category:National Register of Historic Places in Lincoln County, Kentucky',
    'Category:National Register of Historic Places in Logan County, Kentucky',
    'Category:National Register of Historic Places in Magoffin County, Kentucky',
    'Category:National Register of Historic Places in Marion County, Kentucky',
    'Category:National Register of Historic Places in McCracken County, Kentucky',
    'Category:National Register of Historic Places in Meade County, Kentucky',
    'Category:National Register of Historic Places in Mercer County, Kentucky',
    'Category:National Register of Historic Places in Nelson County, Kentucky',
    'Category:National Register of Historic Places in Oldham County, Kentucky',
    'Category:National Register of Historic Places in Scott County, Kentucky',
    'Category:National Register of Historic Places in Taylor County, Kentucky',
    'Category:National Register of Historic Places in Todd County, Kentucky',
    'Category:National Register of Historic Places in Union County, Kentucky',
    'Category:National Register of Historic Places in Warren County, Kentucky',
    'Category:National Register of Historic Places in Washington County, Kentucky',
    'Category:National Register of Historic Places in Woodford County, Kentucky',
    'Category:National Register of Historic Places in Danville, Kentucky',
    'Category:National Register of Historic Places in Lexington, Kentucky',
    'Category:National Register of Historic Places in Louisville, Kentucky',
    'Category:National Register of Historic Places in Louisiana',
    'Category:National Historic Landmarks in Louisiana',
    'Category:Louisiana Registered Historic Place stubs',
    'Category:National Register of Historic Places in Maine',
    'Category:National Historic Landmarks in Maine',
    'Category:National Register of Historic Places in Maine by county',
    'Category:Maine Registered Historic Place stubs',
    'Category:National Register of Historic Places in Maryland',
    'Category:National Historic Landmarks in Maryland',
    'Category:National Historic Sites in Maryland',
    'Category:National Register of Historic Places in Maryland by county',
    'Category:Buildings of religious function on the National Register of Historic Places in Maryland',
    'Category:National Register of Historic Places in Massachusetts',
    'Category:National Historic Landmarks in Massachusetts',
    'Category:National Historic Sites in Massachusetts',
    'Category:National Register of Historic Places in Michigan',
    'Category:Registered Historic Places in Michigan by county',
    'Category:National Historic Landmarks in Michigan',
    'Category:Michigan Registered Historic Place stubs',
    'Category:National Register of Historic Places in Minnesota',
    'Category:National Historic Landmarks in Minnesota',
    'Category:National Register of Historic Places in Minnesota by county',
    'Category:Houses on the National Register of Historic Places in Minnesota',
    'Category:National Register of Historic Places in Minneapolis, Minnesota',
    'Category:National Register of Historic Places in Mississippi',
    'Category:National Historic Landmarks in Mississippi',
    'Category:Mississippi Registered Historic Place stubs',
    'Category:National Register of Historic Places in Missouri',
    'Category:National Historic Landmarks in Missouri',
    'Category:National Historic Sites in Missouri',
    'Category:Missouri Registered Historic Place stubs',
    'Category:National Register of Historic Places in Montana',
    'Category:National Historic Landmarks in Montana',
    'Category:National Historic Sites in Montana',
    'Category:National Register of Historic Places in Montana by county',
    'Category:Houses on the National Register of Historic Places in Montana',
    'Category:Buildings of religious function on the National Register of Historic Places in Montana',
    'Category:Montana Registered Historic Place stubs',
    'Category:National Register of Historic Places in Nebraska',
    'Category:National Historic Landmarks in Nebraska',
    'Category:National Historic Sites in Nebraska',
    'Category:National Register of Historic Places in Nebraska by county',
    'Category:National Register of Historic Places Multiple Property Submissions in Nebraska',
    'Category:National Register of Historic Places in Omaha, Nebraska',
    'Category:Buildings of religious function on the National Register of Historic Places in Nebraska',
    'Category:Nebraska Registered Historic Place stubs',
    'Category:National Register of Historic Places in Nevada',
    'Category:National Historic Landmarks in Nevada',
    'Category:Houses on the National Register of Historic Places in Nevada',
    'Category:National Register of Historic Places in Clark County, Nevada',
    'Category:National Register of Historic Places in Las Vegas',
    'Category:National Register of Historic Places in New Hampshire',
    'Category:National Historic Landmarks in New Hampshire',
    'Category:National Historic Sites in New Hampshire',
    'Category:National Register of Historic Places in New Hampshire by county',
    'Category:Bridges on the National Register of Historic Places in New Hampshire',
    'Category:Houses on the National Register of Historic Places in New Hampshire',
    'Category:Buildings of religious function on the National Register of Historic Places in New Hampshire',
    'Category:National Register of Historic Places in New Jersey',
    'Category:National Historic Landmarks in New Jersey',
    'Category:New Jersey Registered Historic Place stubs',
    'Category:Houses on the National Register of Historic Places in New Jersey',
    'Category:National Register of Historic Places in New Mexico',
    'Category:National Historic Landmarks in New Mexico',
    'Category:National Register of Historic Places in New Mexico by county',
    'Category:Houses on the National Register of Historic Places in New Mexico',
    'Category:New Mexico Registered Historic Place stubs',
    'Category:National Register of Historic Places in New York',
    'Category:New York Registered Historic Place stubs',
    'Category:National Register of Historic Places in New York by county',
    'Category:National Historic Landmarks in New York',
    'Category:National Historic Sites in New York',
    'Category:National Register of Historic Places in New York City',
    'Category:National Register of Historic Places in Orange County, New York',
    'Category:National Register of Historic Places in Rensselaer County, New York',
    'Category:National Register of Historic Places listings in Suffolk County, New York',
    'Category:National Register of Historic Places in Sullivan County, New York',
    'Category:National Register of Historic Places in Ulster County, New York',
    'Category:National Register of Historic Places listings in Babylon (town), New York',
    'Category:National Register of Historic Places listings in Brookhaven (town), New York',
    'Category:National Register of Historic Places listings in East Hampton (town), New York',
    'Category:National Register of Historic Places listings in Huntington (town), New York',
    'Category:National Register of Historic Places listings in Islip (town), New York',
    'Category:National Register of Historic Places listings in Riverhead (town), New York',
    'Category:National Register of Historic Places listings in Shelter Island, New York',
    'Category:National Register of Historic Places listings in Smithtown (town), New York',
    'Category:National Register of Historic Places listings in Southampton (town), New York',
    'Category:National Register of Historic Places listings in Southold (town), New York',
    'Category:National Historic Landmarks in New York City',
    'Category:National Register of Historic Places in Manhattan',
    'Category:National Register of Historic Places in North Carolina',
    'Category:National Historic Landmarks in North Carolina',
    'Category:National Historic Sites in North Carolina',
    'Category:Houses on the National Register of Historic Places in North Carolina',
    'Category:National Register of Historic Places in Wake County, North Carolina',
    'Category:North Carolina Registered Historic Place stubs',
    'Category:National Register of Historic Places in Raleigh, North Carolina',
    'Category:National Register of Historic Places in North Dakota',
    'Category:National Historic Landmarks in North Dakota',
    'Category:National Register of Historic Places in North Dakota by county',
    'Category:National Historic Sites in North Dakota',
    'Category:Houses on the National Register of Historic Places in North Dakota',
    'Category:Buildings of religious function on the National Register of Historic Places in North Dakota',
    'Category:National Register of Historic Places in Ohio',
    'Category:National Historic Landmarks in Ohio',
    'Category:National Historic Sites in Ohio',
    'Category:National Register of Historic Places in Ohio by county',
    'Category:National Register of Historic Places in Cincinnati, Ohio',
    'Category:National Register of Historic Places in Oklahoma',
    'Category:National Historic Landmarks in Oklahoma',
    'Category:National Historic Sites in Oklahoma',
    'Category:Houses on the National Register of Historic Places in Oklahoma',
    'Category:National Register of Historic Places in Oklahoma by county',
    'Category:Buildings of religious function on the National Register of Historic Places in Oklahoma',
    'Category:Oklahoma Registered Historic Place stubs',
    'Category:National Register of Historic Places in Oregon',
    'Category:National Historic Landmarks in Oregon',
    'Category:National Historic Sites in Oregon',
    'Category:National Register of Historic Places in Clackamas County, Oregon',
    'Category:National Register of Historic Places in Jackson County, Oregon',
    'Category:National Register of Historic Places in Lane County, Oregon',
    'Category:National Register of Historic Places in Marion County, Oregon',
    'Category:National Register of Historic Places in Multnomah County, Oregon',
    'Category:National Register of Historic Places in Yamhill County, Oregon',
    'Category:Registered Historic Places of religious function in Oregon',
    'Category:National Register of Historic Places in Washington County, Oregon',
    'Category:Oregon Registered Historic Place stubs',
    'Category:National Register of Historic Places in Pennsylvania',
    'Category:National Historic Landmarks in Pennsylvania',
    'Category:Pennsylvania Registered Historic Place stubs',
    'Category:National Register of Historic Places in Pennsylvania by county',
    'Category:National Register of Historic Places in Philadelphia, Pennsylvania',
    'Category:National Register of Historic Places in Rhode Island',
    'Category:National Historic Landmarks in Rhode Island',
    'Category:National Historic Sites in Rhode Island',
    'Category:National Register of Historic Places in Rhode Island by county',
    'Category:Bridges on the National Register of Historic Places in Rhode Island',
    'Category:Houses on the National Register of Historic Places in Rhode Island',
    'Category:National Register of Historic Places in South Carolina',
    'Category:National Historic Sites in South Carolina',
    'Category:National Historic Landmarks in South Carolina',
    'Category:National Register of Historic Places in South Carolina by county',
    'Category:Buildings of religious function on the National Register of Historic Places in South Carolina',
    'Category:National Register of Historic Places in South Dakota',
    'Category:National Historic Landmarks in South Dakota',
    'Category:National Historic Sites in South Dakota',
    'Category:National Register of Historic Places in South Dakota by county',
    'Category:National Register of Historic Places in Tennessee',
    'Category:National Historic Landmarks in Tennessee',
    'Category:National Historic Sites in Tennessee',
    'Category:National Register of Historic Places in Tennessee by county',
    'Category:Buildings of religious function on the National Register of Historic Places in Tennessee',
    'Category:National Register of Historic Places in Texas',
    'Category:National Historic Landmarks in Texas',
    'Category:National Historic Sites in Texas',
    'Category:National Register of Historic Places in Austin, Texas',
    'Category:Houses on the National Register of Historic Places in Texas',
    'Category:National Register of Historic Places in Houston, Texas',
    'Category:National Register of Historic Places in Utah',
    'Category:National Historic Landmarks in Utah',
    'Category:National Historic Sites in Utah',
    'Category:National Register of Historic Places in Utah by county',
    'Category:Houses on the National Register of Historic Places in Utah',
    'Category:Buildings of religious function on the National Register of Historic Places in Utah',
    'Category:National Register of Historic Places in Vermont',
    'Category:National Historic Landmarks in Vermont',
    'Category:National Register of Historic Places in Vermont by county',
    'Category:Bridges on the National Register of Historic Places in Vermont',
    'Category:Houses on the National Register of Historic Places in Vermont',
    'Category:Buildings of religious function on the National Register of Historic Places in Vermont',
    'Category:Vermont Registered Historic Places building and structure stubs',
    'Category:National Register of Historic Places in Virginia',
    'Category:National Historic Landmarks in Virginia',
    'Category:National Historic Sites in Virginia',
    'Category:National Register of Historic Places in Roanoke, Virginia',
    'Category:National Register of Historic Places in Washington (U.S. state)',
    'Category:National Historic Landmarks in Washington (U.S. state)',
    'Category:National Historic Sites in Washington (U.S. state)',
    'Category:Buildings of religious function on the National Register of Historic Places in Washington (U.S. state)',
    'Category:National Register of Historic Places in Seattle, Washington',
    'Category:National Register of Historic Places in Washington, D.C.',
    'Category:National Historic Landmarks in Washington, D.C.',
    'Category:National Historic Sites in Washington, D.C.',
    'Category:Houses on the National Register of Historic Places in Washington, D.C.',
    'Category:Washington, D.C. Registered Historic Place stubs',
    'Category:National Register of Historic Places in Wisconsin',
    'Category:National Historic Landmarks in Wisconsin',
    'Category:Houses on the National Register of Historic Places in Wisconsin',
    'Category:Buildings of religious function on the National Register of Historic Places in Wisconsin',
    'Category:National Register of Historic Places in West Virginia',
    'Category:National Historic Landmarks in West Virginia',
    'Category:National Register of Historic Places in West Virginia by county',
    'Category:Buildings of religious function on the National Register of Historic Places in West Virginia',
    'Category:National Register of Historic Places in Wyoming',
    'Category:National Historic Landmarks in Wyoming',
    'Category:National Historic Sites in Wyoming',
    'Category:National Register of Historic Places in Wyoming by county',
    'Category:Houses on the National Register of Historic Places in Wyoming',
    'Category:Buildings of religious function on the National Register of Historic Places in Wyoming',
    'Category:Wyoming Registered Historic Place stubs',
    'Category:National Register of Historic Places by United States insular area',
    'Category:National Register of Historic Places in American Samoa',
    'Category:National Register of Historic Places in the Federated States of Micronesia',
    'Category:National Register of Historic Places in Guam',
    'Category:National Register of Historic Places in the Marshall Islands',
    'Category:National Register of Historic Places in the Northern Mariana Islands',
    'Category:National Register of Historic Places in Palau',
    'Category:National Register of Historic Places in Puerto Rico',
    'Category:National Register of Historic Places in the United States Virgin Islands',
    'Category:National Historic Landmarks in Puerto Rico',
);
my @iterators=(
    {
        list          => 'allpages',
        apprefix      => 'National Register of Historic Places listings in',
        apnamespace   => 0,
        apfilterredir => 'nonredirects',
        aplimit       => 'max',
    },
    {
        list        => 'categorymembers',
        cmtitle     => \@cats,
        cmnamespace => 0,
        cmlimit     => 'max',
    },
);

### Filter function: manipulate the found data as necessary, returning the talk
### page to tag (or undef to skip).
sub filter {
    return undef if $_[0]->{'redirect'};
    return 'Talk:'.$_[0]->{'title'};
}

### How to copy other projects' assessments
sub copy_class {
    return 'list' if $_[1]=~/^Talk:National Register of Historic Places listings in/;
    return '';
}

sub copy_importance {
    return '';
}

# Banner configurations.
my $main_banner='WikiProject National Register of Historic Places';
my @preprocess_templates=();
my %banner_cfgs=(
    'WikiProject National Register of Historic Places' => {
        meta => 0,
        stubauto => undef,
        importance => '',
    },
);

sub new {
    my $class=shift;
    my $self=$class->SUPER::new();
    $self->{'config loaded'}=0;
    bless $self, $class;
    return $self;
}

=pod

=for info
Approved 2009-04-08<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 28]]

=cut

sub approved {
    return -1;
}

sub run {
    my ($self, $api)=@_;
    my $res;

    $api->task('WikiProjectWorker', 0, 10, qw/d::WikiProjectTagging/);
    my $errto = 'Errors? [[User:'.$api->user.'/shutoff/WikiProjectWorker]]';

    # Load configs, if necessary
    if(!$self->{'config loaded'}){
        my %cfg=();
        while(my ($banner,$cfg)=each %banner_cfgs){
            $cfg=$api->WPBMetaConfig($cfg->{'meta'}, %$cfg) if exists($cfg->{'meta'});
            $cfg{$banner}=$cfg;
        }
        $api->WPBconfig(%cfg);
        $self->{'config loaded'}=1;
    }
    if(($api->store->{'configured'} // 0) < $seq){
        ### Initialize configuration here
    }

    # Spend a max of 5 minutes on this task before restarting
    my $endtime=time()+300;

    foreach my $itercfg (@iterators) {
        my $iter=$api->iterator(%$itercfg);
        while(my $page=$iter->next()){
            if(!$page->{'_ok_'}){
                $api->warn("Could not retrieve page from iterator: ".$page->{'error'}."\n");
                return 60;
            }

            my $pageid=$page->{'pageid'};
            next if ($api->store->{$pageid} // 0) >= $seq;

            my $title=filter($page);
            if(!defined($title)){
                $api->log("Skipping ".$page->{'title'}.", filter returned undef");
                $api->store->{$pageid}=$seq;
                next;
            }

            my $tok=$api->edittoken($title, EditRedir => 1);
            if($tok->{'code'} eq 'shutoff'){
                $api->warn("Task disabled: ".$tok->{'content'}."\n");
                return 300;
            }
            if($tok->{'code'} ne 'success'){
                $api->warn("Failed to get edit token for $title: ".$tok->{'error'}."\n");
                next;
            }
            if(($tok->{'ns'}&1)==0){
                $api->log("Cannot edit $title: namespace ".$tok->{'ns'}." is non-talk");
                $api->store->{$pageid}=$seq;
                next;
            }
            if(exists($tok->{'redirect'})){
                $api->log("$title is a redirect, skipping.");
                $api->store->{$pageid}=$seq;
                next;
            }

            $api->log("Checking $title...");

            my $intxt=exists($tok->{'revisions'}[0]{'*'})?$tok->{'revisions'}[0]{'*'}:'';
            my ($outtxt,$nowiki)=$api->strip_nowiki($intxt);

            my @params=();

            my $assess = undef;
            my $class = copy_class($api, $title, $intxt);
            if(ref($class) eq 'HASH'){
                $api->warn("Processing $title failed: ".$class->{'error'}."\n");
                next;
            }
            if($class eq ''){
                $assess=$api->WPBassess($title);
                if(ref($assess) eq 'HASH'){
                    if($assess->{'code'} eq 'pagemissing'){
                        # No subject page, doesn't matter
                        $assess=undef;
                    } else {
                        $api->warn("Processing $title failed: ".$assess->{'error'}."\n");
                        next;
                    }
                }
                #push @params, 'auto=yes' if ($assess // '') eq 'stub';
            } else {
                push @params, "class=$class";
                my $imp = copy_importance($api, $title, $intxt);
                if(ref($imp) eq 'HASH'){
                    $api->warn("Processing $title failed: ".$imp->{'error'}."\n");
                    next;
                }
                #push @params, "importance=$imp" if $imp eq '';
            }

            my $need_main_banner = ($api->WPBcheck($outtxt, $main_banner) == 0);

            ### PROCESSING ###

            my @merge=();
            my @summary=();

            if(@preprocess_templates){
                (undef,$outtxt)=$api->WPBcheck($outtxt, sub {
                    my $banner=shift;
                    my $name=shift;
                    my $oname=shift;
                    my $params=shift;
                    my $wikitext=shift;

                    return '' unless $need_main_banner;
                    $need_main_banner=0;
                    return "{{$main_banner}}";
                }, @preprocess_templates);
                if(ref($outtxt) eq 'HASH'){
                    $api->warn("Preprocessing $title failed: ".$outtxt->{'error'}."\n");
                    next;
                }
                if(!@merge){
                    $api->warn("$title contains ".$iter->iterval.", but not in section 0\n");
                    next;
                }
                $merge[-1]='and '.$merge[-1] if @merge>1;
                push @summary, "merging ".join((@merge>2)?', ':' ', @merge)." into $main_banner" if @merge;
            }

            $outtxt=$api->WPBadd($outtxt, $assess, sub {
                shift; # banner
                shift; # name
                my $oname=shift;
                my $params=shift;
                my $wikitext=shift;
                my $new=shift;
                return undef if $new;

                foreach my $p (@params){
                    next unless $p=~/^(.+?)=(.*)$/;
                    my ($k,$v)=($1,$2);
                    my $re=($k eq 'class')?qr/(?i:\Q$v\E)\s*$/:qr/\S/;
                    unless(grep(/^\s*\Q$k\E\s*=\s*$re/, @$params)){
                        push @$params, "$k=$v" unless(grep(s/^(\s*\Q$k\E\s*=\s*?)(?:\S.*?)?(\s*)$/$1$v$2/s, @$params));
                    }
                }

                my $out="{{$oname";
                $out.="|".join("|", @$params) if @$params;
                $out.="}}";
                return $wikitext if $out eq $wikitext;
                push @summary, "updating {{$main_banner}}" unless @summary;
                return $out;
            }, $main_banner, @params);
            if(ref($outtxt) eq 'HASH'){
                $api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
                next;
            }
            push @summary, "Tagging with {{$main_banner}}" unless @summary;

            $outtxt=$api->replace_nowiki($outtxt, $nowiki);

            # Need to edit?
            if($outtxt ne $intxt){
                if(!@summary){
                    $api->warn("$title changed, but nothing in \@summary\n");
                    next;
                }
                my $cat=$iter->iterval;
                $summary[-1]='and '.$summary[-1] if @summary>1;
                my $summary = ucfirst(join((@summary>2)?', ':' ', @summary))." per $req $errto";

                my @cleanup=();
                $outtxt=$api->WPBfixshell($outtxt, \@cleanup);
                if(ref($outtxt) eq 'HASH'){
                    $api->warn("Processing $title failed: ".$outtxt->{'error'}."\n");
                    next;
                }
                $summary.="; general banner cleanup (".join(', ', @cleanup).")" if @cleanup;

                $api->log("$summary in $title");
                my $r=$api->edit($tok, $outtxt, $summary, 1, 1);
                if($r->{'code'} ne 'success'){
                    $api->warn("Write failed on $title: ".$r->{'error'}."\n");
                    next;
                }
            } else {
                $api->log("Nothing to do in $title");
            }

            # Remember that we processed this page already
            $api->store->{$pageid}=$seq;

            # If we've been at it long enough, let another task have a go.
            return 0 if time()>=$endtime;
        }
    }

    # No more pages to check, try again in 10 minutes or so in case of errors.
    return 600;
}