Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apprtype and apprlevel to AllPagesGenerator #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions WikiClientLibrary/Generators/AllPagesGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using WikiClientLibrary.Generators.Primitive;
using WikiClientLibrary.Pages;
using WikiClientLibrary.Sites;

namespace WikiClientLibrary.Generators
Expand Down Expand Up @@ -68,9 +61,19 @@ public AllPagesGenerator(WikiSite site) : base(site)
/// </summary>
public int? MaxPageContentLength { get; set; }

/// <summary>
/// Limit to protected pages only.
/// </summary>
public List<ProtectionType>? ProtectionType { get; set; }

/// <summary>
/// Filter protections based on protection level (must be used with ProtectionType).
/// </summary>
public List<ProtectionLevel>? ProtectionLevel { get; set; }

/// <inheritdoc/>
public override string ListName => "allpages";

/// <inheritdoc/>
public override IEnumerable<KeyValuePair<string, object?>> EnumListParameters()
{
Expand All @@ -85,6 +88,8 @@ public AllPagesGenerator(WikiSite site) : base(site)
{"apfilterlanglinks", LanguageLinkFilter.ToString("withlanglinks", "withoutlanglinks")},
{"apminsize", MinPageContentLength},
{"apmaxsize", MaxPageContentLength},
{"apprtype", ProtectionType != null && ProtectionType.Count != 0 ? string.Join('|', ProtectionType.Select(x => x.ToString().ToLower())) : null},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use MediaWikiHelper.JoinValues instead of string.Join('|', ...).

{"apprlevel", ProtectionLevel != null && ProtectionLevel.Count != 0 ? string.Join('|', ProtectionLevel.Select(x => x.ToString().ToLower())) : null},
// TODO add other filters
};
}
Expand All @@ -110,4 +115,19 @@ public enum PropertyFilterOption
/// </summary>
WithoutProperty,
}

public enum ProtectionType
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as ProtectionLevel.

{
Edit,
Move,
Upload
}

public enum ProtectionLevel
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some wikis may have more level. I used the English Wikipedia as a reference, the enum can be extended later.

Copy link
Owner

@CXuesong CXuesong Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked DB table and pr_level is a column of free text. Then probably you can use string as protection level, and use a another static class like ProtectionLevels to define common protection levels, like what I've been doing in LogActions class.

In the future we might consider introducing some utility structures like HttpMethod class for better strong-typing support.

{
Autoconfirmed,
ExtendedConfirmed,
TemplateEditor,
Sysop,
}
}