public int GetPendingDraftCount(IMediaWikiApi mediaWikiApi) { var categoryName = this.categoryConfiguration.PendingCategories.First().Key; if (categoryName.StartsWith("Category:")) { categoryName = categoryName.Substring("Category:".Length); } var categorySize = mediaWikiApi.GetCategorySize(categoryName); return(categorySize); }
protected internal override string GetShortUrl(string longUrl) { // check for allowed domains var host = new Uri(longUrl).Host; var match = false; foreach (var regex in this.allowedDomains) { if (regex.IsMatch(host)) { match = true; break; } } if (!match) { this.logger.DebugFormat("Url shortening request for {0} did not match allowed domains; deferring to secondary"); return(this.secondaryShortener.GetShortUrl(longUrl)); } IMediaWikiApi mediaWikiApi = null; try { mediaWikiApi = this.apiTypedFactory.Create <IMediaWikiApi>(this.mediaWikiConfig); mediaWikiApi.Login(); return(mediaWikiApi.ShortenUrl(longUrl)); } catch (GeneralMediaWikiApiException ex) { this.logger.Debug(ex.ApiResponse); this.logger.ErrorFormat(ex, "Error shortening url {0} with WMF shortener", longUrl); return(this.secondaryShortener.GetShortUrl(longUrl)); } finally { if (mediaWikiApi != null) { this.apiTypedFactory.Release(mediaWikiApi); } } }
public DateTime?GetOldestDraft(IMediaWikiApi mediaWikiApi) { var pagesInCategory = mediaWikiApi.GetPagesInCategory( this.categoryConfiguration.PendingCategories.First().Key, "max", true); var pendingDated = pagesInCategory.Values .Where(x => x.StartsWith("P") && x.Length >= 9) .Select(x => x.Substring(1, 8)) .ToList(); var expectedDuration = pendingDated.Skip((int)Math.Floor(pendingDated.Count * 0.05)).FirstOrDefault(); if (expectedDuration == null) { return(null); } return(DateTime.ParseExact(expectedDuration, "yyyyMMdd", CultureInfo.InvariantCulture)); }
public DraftStatus GetDraftStatus(IMediaWikiApi mediaWikiApi, string page) { var status = new DraftStatus(page); // retrieve the categories of the page var categorySet = mediaWikiApi.GetCategoriesOfPage(page); var speedyCategories = this.GetSpeedyCategories(categorySet); if (speedyCategories.Any()) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.SpeedyDeletion : status.StatusCode; status.SpeedyDeletionCategories = speedyCategories; } if (this.IsBeingReviewedNow(categorySet)) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.InReviewNow : status.StatusCode; } if (this.IsInArticleSpace(categorySet)) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.Pending : status.StatusCode; status.SubmissionInArticleSpace = true; } if (this.IsPendingReview(categorySet)) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.Pending : status.StatusCode; if (this.DuplicatesExisting(categorySet)) { status.DuplicatesExistingArticle = true; } } if (this.IsDraft(categorySet)) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.Draft : status.StatusCode; } var rejectCategories = this.GetRejectionCategories(categorySet); if (rejectCategories.Any()) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.Rejected : status.StatusCode; status.RejectionCategories = rejectCategories; } var declineCategories = this.GetDeclineCategories(categorySet); if (declineCategories.Any()) { status.StatusCode = status.StatusCode == DraftStatusCode.Unknown ? DraftStatusCode.Declined : status.StatusCode; status.DeclineCategories = declineCategories; } if (status.StatusCode == DraftStatusCode.Unknown) { this.logger.WarnFormat("Draft [[{0}]] reported status unknown - categories: {0}", string.Join("|", categorySet)); } status.SubmissionDate = this.GetSubmissionDate(categorySet); return(status); }
public void Release(IMediaWikiApi api) { this.factory.Release(api); }
public (int upToDate, int created, int updated, int deleted) Import(IMediaWikiApi mediaWikiApi) { lock (this) { this.logger.Debug("Fetching existing prefixes"); var allPrefixes = this.database.QueryOver <InterwikiPrefix>() .List().ToDictionary(x => x.Prefix); this.logger.Debug("Marking existing as absent"); foreach (var prefix in allPrefixes) { prefix.Value.AbsentFromLastImport = true; prefix.Value.CreatedSinceLast = false; } this.logger.Debug("Downloading latest map"); var prefixesToImport = mediaWikiApi.GetInterwikiPrefixes().ToList(); int deletedIw = 0, createdIw = 0, updatedIw = 0, upToDateIw = 0; this.logger.Debug("Iterating import"); int i = 0; foreach (var prefix in prefixesToImport) { this.logger.DebugFormat( " processed {0} of {1} - {2}%", i, prefixesToImport.Count, i / prefixesToImport.Count * 100); i++; if (allPrefixes.ContainsKey(prefix.Prefix)) { allPrefixes[prefix.Prefix].AbsentFromLastImport = false; // present, are we up-to-date? if (allPrefixes[prefix.Prefix].Url == prefix.Url) { // yes upToDateIw++; continue; } var existingImport = this.database.QueryOver <InterwikiPrefix>() .Where(x => x.ImportedAs == prefix.Prefix) .SingleOrDefault(); if (existingImport == null) { existingImport = new InterwikiPrefix(); } existingImport.Prefix = prefix.Prefix + "-import"; existingImport.ImportedAs = prefix.Prefix; existingImport.Url = prefix.Url; existingImport.AbsentFromLastImport = false; this.database.SaveOrUpdate(existingImport); updatedIw++; } else { this.database.Save( new InterwikiPrefix { Prefix = prefix.Prefix, Url = prefix.Url, AbsentFromLastImport = false, CreatedSinceLast = true }); createdIw++; } } this.logger.Debug("Saving absent prefixes"); foreach (var prefix in allPrefixes.Where(x => x.Value.AbsentFromLastImport)) { deletedIw++; this.database.Update(prefix.Value); } this.logger.Debug("Flushing session"); this.database.Flush(); return(upToDateIw, createdIw, updatedIw, deletedIw); } }