Skip to content

Commit

Permalink
Merge pull request #103 from ashotjanibekyan/feature/PagesWithPropGen…
Browse files Browse the repository at this point in the history
…erator

Add PagesWithPropGenerator
  • Loading branch information
CXuesong committed Feb 18, 2024
2 parents 7247f13 + d193983 commit 13b0a0e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions UnitTestProject1/Tests/GeneratorTests2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,5 +408,16 @@ public async Task WpLzhSearchTest()
new HashSet<string>(pages.Select(p => p.Title!)));
}

[Fact]
public async Task WpEnPageWithPropTest()
{
var site = await WpEnSiteAsync;
var generator = new PagesWithPropGenerator(site, "defaultsort");
var result = await generator.EnumItemsAsync().Take(10).ToListAsync();
var pages = await generator.EnumPagesAsync().Take(10).ToListAsync();
Utility.AssertTitlesDistinct(pages);
Assert.All(result, r => Assert.NotNull(r.Value));
}

}
}
48 changes: 48 additions & 0 deletions WikiClientLibrary/Generators/PagesWithPropGenerator.cs
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&amp;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

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux Build & Test

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Release)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'

Check warning on line 20 in WikiClientLibrary/Generators/PagesWithPropGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows Build & Test (Debug)

XML comment has badly formed XML -- 'Reference to undefined entity 'list'.'
/// </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"]);
}
}
}
16 changes: 16 additions & 0 deletions WikiClientLibrary/Generators/PagesWithPropResultItem.cs
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;
}
}
}

0 comments on commit 13b0a0e

Please sign in to comment.