protected internal virtual void OnLoadPageInfo(JObject jpage, IWikiPageQueryProvider options) { // Initialize propertyGroups?.Clear(); // Update page stub PageStub = MediaWikiHelper.PageStubFromJson(jpage); // Load page info // Invalid page title (like File:) if (PageStub.IsInvalid) { return; } // Load property groups foreach (var group in options.ParsePropertyGroups(jpage)) { Debug.Assert(group != null, "The returned sequence from IWikiPageQueryParameters.ParsePropertyGroups contains null item."); if (propertyGroups == null) { propertyGroups = new List <IWikiPagePropertyGroup>(); } propertyGroups.Add(group); } // Check if the client has requested for revision content… LastRevision = GetPropertyGroup <RevisionsPropertyGroup>()?.LatestRevision; if (LastRevision?.Content != null) { Content = LastRevision.Content; } LastFileRevision = GetPropertyGroup <FileInfoPropertyGroup>()?.LatestRevision; pageInfo = GetPropertyGroup <PageInfoPropertyGroup>(); LastRevisionId = pageInfo?.LastRevisionId ?? 0; ContentModel = pageInfo?.ContentModel; }
internal static RevisionsPropertyGroup Create(JObject jpage) { var jrevisions = jpage["revisions"]; if (jrevisions == null) { return(null); } if (!jrevisions.HasValues) { return(Empty); } var stub = MediaWikiHelper.PageStubFromJson(jpage); return(new RevisionsPropertyGroup(stub, (JArray)jrevisions)); }
internal static FileInfoPropertyGroup Create(JObject jpage) { var info = jpage["imageinfo"]; // jpage["imageinfo"] == null indicates the page may not be a valid File. if (info == null) { return(null); } if (!info.HasValues) { return(Empty); } var stub = MediaWikiHelper.PageStubFromJson(jpage); return(new FileInfoPropertyGroup(stub, (JArray)info)); }
internal static WikiPageCategoryInfo CategoryInfoFromJson(JToken json) { return(new WikiPageCategoryInfo(MediaWikiHelper.PageStubFromJson((JObject)json), json["hidden"] != null, (string)json["sortkeyprefix"], (string)json["sortkey"], (DateTime?)json["timestamp"] ?? DateTime.MinValue)); }
internal static WikiPageLinksHereInfo LinkedPagesFromJson(JToken json) { return(new WikiPageLinksHereInfo(MediaWikiHelper.PageStubFromJson((JObject)json), json["redirect"] != null)); }
/// <summary> /// Asynchronously purges the pages. /// </summary> /// <returns>A collection of pages that haven't been successfully purged, because of either missing or invalid titles.</returns> public static async Task <IReadOnlyCollection <PurgeFailureInfo> > PurgePagesAsync(IEnumerable <WikiPage> pages, PagePurgeOptions options, CancellationToken cancellationToken) { if (pages == null) { throw new ArgumentNullException(nameof(pages)); } List <PurgeFailureInfo> failedPages = null; // You can even purge pages from different sites. foreach (var sitePages in pages.GroupBy(p => new WikiPageGroupKey(p))) { var site = sitePages.Key.Site; var titleLimit = site.AccountInfo.HasRight(UserRights.ApiHighLimits) ? 500 : 50; using (site.BeginActionScope(sitePages, options)) { foreach (var partition in sitePages.Partition(titleLimit).Select(partition => partition.ToList())) { string titles; string ids; if (sitePages.Key.HasTitle) { // If a page has both title and ID information, // we will use title anyway. site.Logger.LogDebug("Purging {Count} pages by title.", partition.Count); titles = MediaWikiHelper.JoinValues(partition.Select(p => p.Title)); ids = null; } else { site.Logger.LogDebug("Purging {Count} pages by ID.", partition.Count); Debug.Assert(sitePages.All(p => p.PageStub.HasId)); titles = null; ids = MediaWikiHelper.JoinValues(partition.Select(p => p.Id)); } try { var jresult = await site.InvokeMediaWikiApiAsync(new MediaWikiFormRequestMessage(new { action = "purge", titles = titles, pageids = ids, forcelinkupdate = (options & PagePurgeOptions.ForceLinkUpdate) == PagePurgeOptions.ForceLinkUpdate, forcerecursivelinkupdate = (options & PagePurgeOptions.ForceRecursiveLinkUpdate) == PagePurgeOptions.ForceRecursiveLinkUpdate, }), cancellationToken); // Now check whether the pages have been purged successfully. foreach (var jitem in jresult["purge"]) { if (jitem["missing"] != null || jitem["invalid"] != null) { if (failedPages == null) { failedPages = new List <PurgeFailureInfo>(); } failedPages.Add(new PurgeFailureInfo(MediaWikiHelper.PageStubFromJson((JObject)jitem), (string)jitem["invalidreason"])); } } } catch (OperationFailedException ex) { if (ex.ErrorCode == "cantpurge") { throw new UnauthorizedOperationException(ex); } throw; } } } } return(failedPages ?? emptyPurgeFailures); }
/// <inheritdoc /> protected override Revision ItemFromJson(JToken json, JObject jpage) { return(MediaWikiHelper.RevisionFromJson((JObject)json, MediaWikiHelper.PageStubFromJson(jpage))); }
/// <inheritdoc /> protected override GeoSearchResultItem ItemFromJson(JToken json) { return(new GeoSearchResultItem(MediaWikiHelper.PageStubFromJson((JObject)json), MediaWikiHelper.GeoCoordinateFromJson((JObject)json), json["primary"] != null, (double)json["dist"])); }