-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
…erator Add PagesWithPropGenerator
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json.Linq; | ||
using WikiClientLibrary.Generators.Primitive; | ||
using WikiClientLibrary.Infrastructures; | ||
using WikiClientLibrary.Sites; | ||
|
||
namespace WikiClientLibrary.Generators | ||
{ | ||
/// <summary> | ||
/// List all pages using a given page property. The list of available properties can be found at action=query&list=pagepropnames. | ||
/// </summary> | ||
public class PagesWithPropGenerator : WikiPageGenerator<PagesWithPropResultItem> | ||
{ | ||
public PagesWithPropGenerator(WikiSite site, string propertyName) : base(site) | ||
{ | ||
PropertyName = propertyName; | ||
} | ||
|
||
/// <summary> | ||
/// Page property for which to enumerate pages (action=query&list=pagepropnames returns page property names in use). | ||
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Linux Build & Test
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Release)
Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs GitHub Actions / Windows Build & Test (Debug)
|
||
/// </summary> | ||
public string PropertyName { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Gets/sets a value that indicates whether the links should be listed in | ||
/// the descending order. (MediaWiki 1.19+) | ||
/// </summary> | ||
public bool OrderDescending { get; set; } | ||
|
||
public override string ListName => "pageswithprop"; | ||
|
||
public override IEnumerable<KeyValuePair<string, object?>> EnumListParameters() | ||
{ | ||
return new Dictionary<string, object?> | ||
{ | ||
{"pwpprop", "ids|title|value"}, | ||
{"pwppropname", PropertyName}, | ||
{"pwplimit", PaginationSize}, | ||
{"pwpdir", OrderDescending ? "descending" : "ascending"}, | ||
}; | ||
} | ||
|
||
protected override PagesWithPropResultItem ItemFromJson(JToken json) | ||
{ | ||
return new PagesWithPropResultItem(MediaWikiHelper.PageStubFromJson((JObject)json), (string)json["value"]); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using WikiClientLibrary.Pages; | ||
|
||
namespace WikiClientLibrary.Generators | ||
{ | ||
public class PagesWithPropResultItem | ||
{ | ||
public WikiPageStub Page { get; } | ||
public string Value { get; set; } | ||
|
||
public PagesWithPropResultItem(WikiPageStub wikiPageStub, string value) | ||
{ | ||
Page = wikiPageStub; | ||
Value = value; | ||
} | ||
} | ||
} |