-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from ashotjanibekyan/feature/MyWatchlistGener…
…ator Add MyWatchlistGenerator
- Loading branch information
Showing
5 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json.Linq; | ||
using WikiClientLibrary.Generators.Primitive; | ||
using WikiClientLibrary.Infrastructures; | ||
using WikiClientLibrary.Sites; | ||
|
||
namespace WikiClientLibrary.Generators | ||
{ | ||
/// <summary> | ||
/// Get all pages on the current user's watchlist. | ||
/// </summary> | ||
public class MyWatchlistGenerator : WikiPageGenerator<MyWatchlistResultItem> | ||
{ | ||
public MyWatchlistGenerator(WikiSite site) : base(site) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Only list pages in the given namespaces. | ||
/// </summary> | ||
public IEnumerable<int>? NamespaceIds { get; set; } | ||
|
||
/// <summary> | ||
/// Only show pages that have not been changed. | ||
/// </summary> | ||
public PropertyFilterOption NotChangedPagesFilter { get; set; } | ||
|
||
/// <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; } | ||
|
||
/// <summary> | ||
/// Title (with namespace prefix) to begin enumerating from. | ||
/// </summary> | ||
public string? FromTitle { get; set; } | ||
|
||
/// <summary> | ||
/// Title (with namespace prefix) to stop enumerating at. | ||
/// </summary> | ||
public string? ToTitle { get; set; } | ||
|
||
public override IEnumerable<KeyValuePair<string, object?>> EnumListParameters() | ||
{ | ||
return new Dictionary<string, object?> | ||
{ | ||
{"wrnamespace", NamespaceIds == null ? null : MediaWikiHelper.JoinValues(NamespaceIds)}, | ||
{"wrlimit", PaginationSize}, | ||
{"wrprop", "changed"}, | ||
{"wrshow", NotChangedPagesFilter.ToString("!changed", "changed", null)}, | ||
{"wrdir", OrderDescending ? "descending" : "ascending"}, | ||
{"wrfromtitle", FromTitle}, | ||
{"wrtotitle", ToTitle}, | ||
}; | ||
} | ||
|
||
protected override MyWatchlistResultItem ItemFromJson(JToken json) | ||
{ | ||
DateTime? changedTime = null; | ||
if (json["changed"] != null) | ||
{ | ||
changedTime = DateTime.Parse((string)json["changed"]); | ||
} | ||
|
||
return new MyWatchlistResultItem(MediaWikiHelper.PageStubFromJson((JObject)json), json["changed"] != null, changedTime); | ||
} | ||
|
||
public override string ListName => "watchlistraw"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using WikiClientLibrary.Pages; | ||
|
||
namespace WikiClientLibrary.Generators | ||
{ | ||
public sealed class MyWatchlistResultItem | ||
{ | ||
public WikiPageStub Page { get; } | ||
public bool IsChanged { get; } | ||
public DateTime? ChangedTime { get; } | ||
|
||
public MyWatchlistResultItem(WikiPageStub page, bool isChanged, DateTime? changedTime = null) | ||
{ | ||
Page = page; | ||
IsChanged |