Skip to content

Commit

Permalink
Add Page.IsSpecialPage property.
Browse files Browse the repository at this point in the history
Now Page properly handles Special pages.
  • Loading branch information
CXuesong committed Jul 12, 2017
1 parent ae8068f commit 3f52a26
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions WikiClientLibrary/Pages/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public Page(Site site, string title, int defaultNamespaceId)
Site = site;
WikiClient = Site.WikiClient;
Debug.Assert(WikiClient != null);
Title = WikiLink.NormalizeWikiLink(site, title, defaultNamespaceId);
var parsedTitle = WikiLink.Parse(site, title, defaultNamespaceId);
Title = parsedTitle.FullTitle;
NamespaceId = parsedTitle.Namespace.Id;
}

internal Page(Site site)
Expand Down Expand Up @@ -99,6 +101,11 @@ internal Page(Site site)
/// </summary>
public bool Exists { get; private set; }

/// <summary>
/// Gets whether the page is a Special page.
/// </summary>
public bool IsSpecialPage { get; private set; }

/// <summary>
/// Content model. (MediaWiki 1.22)
/// </summary>
Expand Down Expand Up @@ -262,8 +269,9 @@ protected virtual void OnLoadPageInfo(JObject jpage)
Exists = jpage["missing"] == null;
ContentModel = (string) jpage["contentmodel"];
PageLanguage = (string) jpage["pagelanguage"];
IsSpecialPage = jpage["special"] != null;
IsRedirect = jpage["redirect"] != null;
if (Exists)
if (Exists && !IsSpecialPage)
{
ContentLength = (int) jpage["length"];
LastRevisionId = (int) jpage["lastrevid"];
Expand Down Expand Up @@ -440,6 +448,9 @@ public IAsyncEnumerable<string> EnumTransclusionsAsync(IEnumerable<int> namespac
/// You should call <see cref="RefreshAsync()"/> again
/// if you're interested in them.
/// </remarks>
/// <exception cref="InvalidOperationException">Cannot create actual page in the specified namespace.</exception>
/// <exception cref="OperationConflictException">Edit conflict detected.</exception>
/// <exception cref="UnauthorizedOperationException">You have no rights to edit the page.</exception>
public Task UpdateContentAsync(string summary)
{
return UpdateContentAsync(summary, false, true, AutoWatchBehavior.Default, CancellationToken.None);
Expand All @@ -455,6 +466,9 @@ public Task UpdateContentAsync(string summary)
/// <see cref="ContentLength"/>, <see cref="LastRevision"/>, and <see cref="LastTouched"/>.
/// You should call <see cref="RefreshAsync(WikiClientLibrary.Pages.PageQueryOptions,System.Threading.CancellationToken)" /> again if you're interested in them.
/// </remarks>
/// <exception cref="InvalidOperationException">Cannot create actual page in the specified namespace.</exception>
/// <exception cref="OperationConflictException">Edit conflict detected.</exception>
/// <exception cref="UnauthorizedOperationException">You have no rights to edit the page.</exception>
public Task UpdateContentAsync(string summary, bool minor)
{
return UpdateContentAsync(summary, minor, true, AutoWatchBehavior.Default, CancellationToken.None);
Expand All @@ -470,6 +484,9 @@ public Task UpdateContentAsync(string summary, bool minor)
/// <see cref="ContentLength"/>, <see cref="LastRevision"/>, and <see cref="LastTouched"/>.
/// You should call <see cref="RefreshAsync(WikiClientLibrary.Pages.PageQueryOptions,System.Threading.CancellationToken)" /> again if you're interested in them.
/// </remarks>
/// <exception cref="InvalidOperationException">Cannot create actual page in the specified namespace.</exception>
/// <exception cref="OperationConflictException">Edit conflict detected.</exception>
/// <exception cref="UnauthorizedOperationException">You have no rights to edit the page.</exception>
public Task UpdateContentAsync(string summary, bool minor, bool bot)
{
return UpdateContentAsync(summary, minor, bot, AutoWatchBehavior.Default, CancellationToken.None);
Expand All @@ -487,6 +504,7 @@ public Task UpdateContentAsync(string summary, bool minor, bool bot)
/// You should call <see cref="RefreshAsync()"/> again
/// if you're interested in them.
/// </remarks>
/// <exception cref="InvalidOperationException">Cannot create actual page in the specified namespace.</exception>
/// <exception cref="OperationConflictException">Edit conflict detected.</exception>
/// <exception cref="UnauthorizedOperationException">You have no rights to edit the page.</exception>
public Task<bool> UpdateContentAsync(string summary, bool minor, bool bot, AutoWatchBehavior watch)
Expand All @@ -506,6 +524,7 @@ public Task<bool> UpdateContentAsync(string summary, bool minor, bool bot, AutoW
/// You should call <see cref="RefreshAsync()"/> again
/// if you're interested in them.
/// </remarks>
/// <exception cref="InvalidOperationException">Cannot create actual page in the specified namespace.</exception>
/// <exception cref="OperationConflictException">Edit conflict detected.</exception>
/// <exception cref="UnauthorizedOperationException">You have no rights to edit the page.</exception>
public async Task<bool> UpdateContentAsync(string summary, bool minor, bool bot, AutoWatchBehavior watch,
Expand Down Expand Up @@ -541,6 +560,8 @@ public async Task<bool> UpdateContentAsync(string summary, bool minor, bool bot,
{
case "protectedpage":
throw new UnauthorizedOperationException(ex);
case "pagecannotexist":
throw new InvalidOperationException(ex.ErrorMessage, ex);
default:
throw;
}
Expand Down

0 comments on commit 3f52a26

Please sign in to comment.