Skip to content

Commit

Permalink
Use Int64 as MediaWiki page ID, revision ID, and user ID.
Browse files Browse the repository at this point in the history
Wikidata revision ID has exceeded Int32.MaxValue.
  • Loading branch information
CXuesong committed May 12, 2024
1 parent 6655faa commit df21c73
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 79 deletions.
2 changes: 1 addition & 1 deletion UnitTestProject1/Tests/PageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public async Task WpLzhPageLanguageLinksTest()
public async Task WpLzhFetchRevisionsTest()
{
var site = await WpLzhSiteAsync;
var revIds = new[] { 248199, 248197, 255289 };
var revIds = new[] { 248199L, 248197, 255289 };
var pageTitles = new[] { "", "", "香草" };
var rev = await Revision.FetchRevisionsAsync(site, revIds).ToListAsync();
ShallowTrace(rev);
Expand Down
2 changes: 1 addition & 1 deletion WikiClientLibrary.Wikia/Discussions/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Board(WikiaSite site, string title, int defaultNamespaceId)
/// <param name="site">The Wikia site.</param>
/// <param name="pageId">Page ID of the board.</param>
/// <exception cref="ArgumentNullException"><paramref name="site"/> is <c>null</c>.</exception>
public Board(WikiaSite site, int pageId)
public Board(WikiaSite site, long pageId)
{
Site = site ?? throw new ArgumentNullException(nameof(site));
Page = new WikiPageStub(pageId);
Expand Down
4 changes: 2 additions & 2 deletions WikiClientLibrary.Wikia/Discussions/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Post
/// For now, it is not possible to get the replies by using the constructor provided here.
/// To achieve this, you need to invoke <see cref="Board.EnumPostsAsync()"/> on a <see cref="Board"/> instance.
/// </remarks>
public Post(WikiaSite site, WikiPageStub ownerPage, int id)
public Post(WikiaSite site, WikiPageStub ownerPage, long id)
{
if (ownerPage.IsEmpty) throw new ArgumentException("ownerPage is empty.", nameof(ownerPage));
Site = site ?? throw new ArgumentNullException(nameof(site));
Expand All @@ -47,7 +47,7 @@ public Post(WikiaSite site, WikiPageStub ownerPage, int id)
public WikiaSite Site { get; }

/// <summary>Gets the ID of the post.</summary>
public int Id { get; private set; }
public long Id { get; private set; }

/// <summary>Gets the stub of the page that owns the comment.</summary>
public WikiPageStub OwnerPage { get; private set; }
Expand Down
10 changes: 5 additions & 5 deletions WikiClientLibrary.Wikia/RequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ IEnumerable<Post> PostsAndDescendants(IEnumerable<Post> posts)
var pages = partition.Select(p => new WikiPage(site, p.Id)).ToList();
var lastRevisionTask = pages.RefreshAsync(postLastRevisionQueryProvider, cancellationToken);
// Fetch the first revisions, when needed, to determine author.
Dictionary<int, Revision> firstRevisionDict = null;
Dictionary<long, Revision> firstRevisionDict = null;
if (partition.Count == 1
|| (options & PostQueryOptions.ExactAuthoringInformation) == PostQueryOptions.ExactAuthoringInformation)
{
// We can only fetch for 1 page at a time, with rvdir = "newer"
firstRevisionDict = new Dictionary<int, Revision>();
firstRevisionDict = new Dictionary<long, Revision>();
foreach (var post in partition)
{
var generator = new RevisionsGenerator(site, post.Id)
{
TimeAscending = true,
PaginationSize = 1,
PropertyProvider = postRevisionWithContentProvider
PropertyProvider = postRevisionWithContentProvider,
};
var rev = await generator.EnumItemsAsync().FirstAsync(cancellationToken);
firstRevisionDict[post.Id] = rev;
Expand All @@ -163,7 +163,7 @@ IEnumerable<Post> PostsAndDescendants(IEnumerable<Post> posts)
}
}

public static async Task<Post> PostCommentAsync(WikiaSite site, object scopeInst, WikiPageStub owner, int? parentId, string content, CancellationToken cancellationToken)
public static async Task<Post> PostCommentAsync(WikiaSite site, object scopeInst, WikiPageStub owner, long? parentId, string content, CancellationToken cancellationToken)
{
Debug.Assert(site != null);
Debug.Assert(owner.HasTitle);
Expand Down Expand Up @@ -267,7 +267,7 @@ public static async Task<Post> PostCommentAsync(WikiaSite site, object scopeInst
}

public static async Task<Post> ReplyWallMessageAsync(WikiaSite site, object scopeInst, WikiPageStub owner,
int parentId, string messageBody, CancellationToken cancellationToken)
long parentId, string messageBody, CancellationToken cancellationToken)
{
Debug.Assert(site != null);
using (site.BeginActionScope(scopeInst, owner, parentId))
Expand Down
10 changes: 5 additions & 5 deletions WikiClientLibrary.Wikia/WikiaApi/WikiaSiteWikiaApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public static Task<UserInfo> FetchUserAsync(this WikiaSite site, string userName
}
}

/// <inheritdoc cref="FetchRelatedPagesAsync(WikiaSite,int,int,CancellationToken)"/>
/// <inheritdoc cref="FetchRelatedPagesAsync(WikiaSite,long,int,CancellationToken)"/>
/// <remarks>This overload fetches 10 items at most.</remarks>
public static Task<IList<RelatedPageItem>> FetchRelatedPagesAsync(this WikiaSite site, int pageId)
public static Task<IList<RelatedPageItem>> FetchRelatedPagesAsync(this WikiaSite site, long pageId)
{
return FetchRelatedPagesAsync(site, pageId, 10, CancellationToken.None);
}

/// <inheritdoc cref="FetchRelatedPagesAsync(WikiaSite,int,int,CancellationToken)"/>
public static Task<IList<RelatedPageItem>> FetchRelatedPagesAsync(this WikiaSite site, int pageId, int maxCount)
/// <inheritdoc cref="FetchRelatedPagesAsync(WikiaSite,long,int,CancellationToken)"/>
public static Task<IList<RelatedPageItem>> FetchRelatedPagesAsync(this WikiaSite site, long pageId, int maxCount)
{
return FetchRelatedPagesAsync(site, pageId, maxCount, CancellationToken.None);
}
Expand All @@ -131,7 +131,7 @@ public static Task<IList<RelatedPageItem>> FetchRelatedPagesAsync(this WikiaSite
/// <exception cref="NotFoundApiException"><c>Related Pages</c> extension is not available.</exception>
/// <returns></returns>
public static async Task<IList<RelatedPageItem>> FetchRelatedPagesAsync(this WikiaSite site,
int pageId, int maxCount, CancellationToken cancellationToken)
long pageId, int maxCount, CancellationToken cancellationToken)
{
if (site == null) throw new ArgumentNullException(nameof(site));
if (maxCount <= 0) throw new ArgumentOutOfRangeException(nameof(maxCount));
Expand Down
8 changes: 4 additions & 4 deletions WikiClientLibrary.Wikibase/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Entity(WikiSite site, string id)
/// The property value is invalidated after you have performed edits on this instance.
/// To fetch the latest value, use <see cref="RefreshAsync(EntityQueryOptions)"/>.
/// </remarks>
public int PageId { get; private set; }
public long PageId { get; private set; }

/// <summary>
/// Namespace ID of the entity page.
Expand Down Expand Up @@ -164,7 +164,7 @@ public Entity(WikiSite site, string id)
/// <summary>
/// The revid of the last revision.
/// </summary>
public int LastRevisionId { get; private set; }
public long LastRevisionId { get; private set; }

/// <inheritdoc />
public WbMonolingualTextCollection Labels { get; private set; } = emptyStringDict;
Expand Down Expand Up @@ -268,12 +268,12 @@ internal void LoadFromContract(Contracts.Entity entity, EntityQueryOptions optio
if (!isPostEditing)
{
// wbeditentity response does not have these properties.
PageId = (int)extensionData["pageid"];
PageId = (long)extensionData["pageid"];
NamespaceId = (int)extensionData["ns"];
Title = (string)extensionData["title"];
LastModified = (DateTime)extensionData["modified"];
}
LastRevisionId = (int)extensionData["lastrevid"];
LastRevisionId = (long)extensionData["lastrevid"];
}

Labels = (options & EntityQueryOptions.FetchLabels) == EntityQueryOptions.FetchLabels && serializable.Labels.Count > 0
Expand Down
12 changes: 6 additions & 6 deletions WikiClientLibrary/Generators/LogEventsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ internal static LogEventItem FromRecentChangeItem(RecentChangeItem rc)

/// <summary>the page id at the time the log was stored.</summary>
[JsonProperty("logpage")]
public int PageId { get; private set; }
public long PageId { get; private set; }

/// <summary>Name of the user making this recent change.</summary>
[JsonProperty("user")]
Expand All @@ -229,13 +229,13 @@ internal static LogEventItem FromRecentChangeItem(RecentChangeItem rc)
/// for account creation events, this is user ID of the creating user is returned.
/// When absent, this is the user ID returned is that of the created account
/// (see <a href="https://phabricator.wikimedia.org/T73020">phab:T73020</a>).
/// In most cases (such as in <see cref="LogEventsList"/> or <see cref="RecentChangesGenerator"/>,
/// In most cases (such as in <see cref="LogEventsList"/> or <see cref="RecentChangesGenerator"/>),
/// <c>userid</c> property is specified implicitly.</para>
/// <para>To get the user ID for the created user, especially in <see cref="LogActions.Create2"/> log action,
/// use <see cref="Params"/>.<see cref="LogParameterCollection.UserId"/> .</para>
/// </remarks>
[JsonProperty]
public int UserId { get; private set; }
public long UserId { get; private set; }

/// <summary>The time and date of the change.</summary>
[JsonProperty]
Expand Down Expand Up @@ -404,12 +404,12 @@ static LogParameterCollection()
/// <summary>
/// (<see cref="LogActions.Patrol"/>)
/// </summary>
public int CurrentRevisionId => GetInt32Value("curid", 0);
public long CurrentRevisionId => GetInt64Value("curid", 0);

/// <summary>
/// (<see cref="LogActions.Patrol"/>)
/// </summary>
public int PreviousRevisionId => GetInt32Value("previd", 0);
public long PreviousRevisionId => GetInt64Value("previd", 0);

/// <summary>
/// (<see cref="LogActions.Patrol"/>)
Expand All @@ -420,7 +420,7 @@ static LogParameterCollection()
/// (<see cref="LogTypes.NewUsers"/>) The user ID of the created user.
/// </summary>
/// <see cref="LogEventItem.UserId"/>
public int UserId => GetInt32Value("userid", 0);
public long UserId => GetInt64Value("userid", 0);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected WikiPagePropertyList(WikiSite site, WikiPageStub pageStub)
/// Gets/sets the page ID from which to get the <c>list</c>-like property value.
/// </summary>
/// <remarks>If <see cref="PageTitle"/> is <c>null</c>, the value of this property will be used.
/// Otherwise the other one will be effective.</remarks>
public int PageId { get; set; }
/// Otherwise, the other one will be effective.</remarks>
public long PageId { get; set; }

/// <summary>
/// Gets/sets maximum items returned per MediaWiki API invocation.
Expand Down
10 changes: 5 additions & 5 deletions WikiClientLibrary/Generators/RecentChangeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ private string TypeName

/// <summary>ID of the page affected by this item.</summary>
[JsonProperty]
public int PageId { get; private set; }
public long PageId { get; private set; }

/// <summary>ID of the new revision affected by this item.</summary>
[JsonProperty("revid")]
public int RevisionId { get; private set; }
public long RevisionId { get; private set; }

/// <summary>ID of the old revision affected by this item.</summary>
[JsonProperty("old_revid")]
public int OldRevisionId { get; private set; }
public long OldRevisionId { get; private set; }

/// <summary>ID of recent change entry.</summary>
[JsonProperty("rcid")]
public int Id { get; private set; }
public long Id { get; private set; }

/// <summary>Name of the user making this recent change.</summary>
[JsonProperty("user")]
Expand All @@ -100,7 +100,7 @@ private string TypeName
/// <remarks>When using this property with log events, there are some caveats.
/// See <see cref="LogEventItem.UserId"/> for more information.</remarks>
[JsonProperty]
public int UserId { get; private set; }
public long UserId { get; private set; }

/// <summary>Content length of the old revision affected by this item.</summary>
[JsonProperty("oldlen")]
Expand Down
4 changes: 2 additions & 2 deletions WikiClientLibrary/Generators/RevisionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ protected override Revision ItemFromJson(JToken json, JObject jpage)
/// <summary>
/// Revision ID to start listing from.
/// </summary>
public int? StartRevisionId { get; set; }
public long? StartRevisionId { get; set; }

/// <summary>
/// Revision ID to stop listing at.
/// </summary>
public int? EndRevisionId { get; set; }
public long? EndRevisionId { get; set; }

/// <summary>
/// Only list revisions made by this user.
Expand Down
32 changes: 27 additions & 5 deletions WikiClientLibrary/Infrastructures/WikiReadOnlyDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,51 @@ protected void MakeReadonly()
return null;
}

/// <inheritdoc cref="GetInt64Value(string)"/>
/// <summary>
/// Gets the <see cref="int"/> value by property name.
/// This overload raises exception for missing key.
/// </summary>
/// <see cref="GetInt64Value(string,long)"/>
public int GetInt32Value(string key)
{
return (int)myDict[key];
}

/// <inheritdoc cref="GetInt64Value(string,long)"/>
/// <summary>
/// Gets the <see cref="int"/> value by property name.
/// A default value can be provided in case the specified key does not exist.
/// </summary>
public int GetInt32Value(string key, int defaultValue)
{
if (myDict.TryGetValue(key, out var value)) return (int)value;
return defaultValue;
}

/// <summary>
/// Gets the <see cref="long"/> value by property name.
/// This overload raises exception for missing key.
/// </summary>
/// <param name="key">The property name.</param>
/// <returns>The converted value.</returns>
/// <exception cref="KeyNotFoundException">The property is not found.</exception>
/// <see cref="GetInt32Value(string,int)"/>
public int GetInt32Value(string key)
public long GetInt64Value(string key)
{
return (int)myDict[key];
return (long)myDict[key];
}

/// <summary>
/// Gets the <see cref="int"/> value by property name.
/// Gets the <see cref="long"/> value by property name.
/// A default value can be provided in case the specified key does not exist.
/// </summary>
/// <param name="key">The property name.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>The converted value - or - <paramref name="defaultValue"/>.</returns>
public int GetInt32Value(string key, int defaultValue)
public long GetInt64Value(string key, long defaultValue)
{
if (myDict.TryGetValue(key, out var value)) return (int)value;
if (myDict.TryGetValue(key, out var value)) return (long)value;
return defaultValue;
}

Expand Down
4 changes: 2 additions & 2 deletions WikiClientLibrary/Pages/Parsing/ParsedContentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public ParsedContentInfo()
public string DisplayTitle { get; private set; }

[JsonProperty]
public int PageId { get; private set; }
public long PageId { get; private set; }

[JsonProperty("revid")]
public int RevisionId { get; private set; }
public long RevisionId { get; private set; }

/// <summary>
/// Parsed content, in HTML form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected internal PageInfoPropertyGroup(JObject jPage)

public DateTime LastTouched { get; }

public int LastRevisionId { get; }
public long LastRevisionId { get; }

public int ContentLength { get; }

Expand Down

0 comments on commit df21c73

Please sign in to comment.