From 3f52a26b3192f347c1efb3be328e0bc03655807c Mon Sep 17 00:00:00 2001 From: forest93 Date: Wed, 12 Jul 2017 22:31:45 +0800 Subject: [PATCH] Add Page.IsSpecialPage property. Now Page properly handles Special pages. --- WikiClientLibrary/Pages/Page.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/WikiClientLibrary/Pages/Page.cs b/WikiClientLibrary/Pages/Page.cs index f358fddbc..df7e3018c 100644 --- a/WikiClientLibrary/Pages/Page.cs +++ b/WikiClientLibrary/Pages/Page.cs @@ -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) @@ -99,6 +101,11 @@ internal Page(Site site) /// public bool Exists { get; private set; } + /// + /// Gets whether the page is a Special page. + /// + public bool IsSpecialPage { get; private set; } + /// /// Content model. (MediaWiki 1.22) /// @@ -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"]; @@ -440,6 +448,9 @@ public IAsyncEnumerable EnumTransclusionsAsync(IEnumerable namespac /// You should call again /// if you're interested in them. /// + /// Cannot create actual page in the specified namespace. + /// Edit conflict detected. + /// You have no rights to edit the page. public Task UpdateContentAsync(string summary) { return UpdateContentAsync(summary, false, true, AutoWatchBehavior.Default, CancellationToken.None); @@ -455,6 +466,9 @@ public Task UpdateContentAsync(string summary) /// , , and . /// You should call again if you're interested in them. /// + /// Cannot create actual page in the specified namespace. + /// Edit conflict detected. + /// You have no rights to edit the page. public Task UpdateContentAsync(string summary, bool minor) { return UpdateContentAsync(summary, minor, true, AutoWatchBehavior.Default, CancellationToken.None); @@ -470,6 +484,9 @@ public Task UpdateContentAsync(string summary, bool minor) /// , , and . /// You should call again if you're interested in them. /// + /// Cannot create actual page in the specified namespace. + /// Edit conflict detected. + /// You have no rights to edit the page. public Task UpdateContentAsync(string summary, bool minor, bool bot) { return UpdateContentAsync(summary, minor, bot, AutoWatchBehavior.Default, CancellationToken.None); @@ -487,6 +504,7 @@ public Task UpdateContentAsync(string summary, bool minor, bool bot) /// You should call again /// if you're interested in them. /// + /// Cannot create actual page in the specified namespace. /// Edit conflict detected. /// You have no rights to edit the page. public Task UpdateContentAsync(string summary, bool minor, bool bot, AutoWatchBehavior watch) @@ -506,6 +524,7 @@ public Task UpdateContentAsync(string summary, bool minor, bool bot, AutoW /// You should call again /// if you're interested in them. /// + /// Cannot create actual page in the specified namespace. /// Edit conflict detected. /// You have no rights to edit the page. public async Task UpdateContentAsync(string summary, bool minor, bool bot, AutoWatchBehavior watch, @@ -541,6 +560,8 @@ public async Task UpdateContentAsync(string summary, bool minor, bool bot, { case "protectedpage": throw new UnauthorizedOperationException(ex); + case "pagecannotexist": + throw new InvalidOperationException(ex.ErrorMessage, ex); default: throw; }