-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from User123698745/feature/FileusageGenerator
FileusageGenerator _TranscludedInGenerator_ can not be used for files. This PR adds _FileusageGenerator_ ([API docs](https://www.mediawiki.org/wiki/API:Imageusage)) which is basically the same as the _TranscludedInGenerator_ ([API docs](https://www.mediawiki.org/wiki/API:Embeddedin)) just for files. Note: The API endpoint is called "Imageusage", but it works with any file (see test case).
- Loading branch information
Showing
3 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using WikiClientLibrary.Generators.Primitive; | ||
using WikiClientLibrary.Infrastructures; | ||
using WikiClientLibrary.Sites; | ||
|
||
namespace WikiClientLibrary.Generators | ||
{ | ||
/// <summary> | ||
/// Generates all the pages that transclude the specified file. | ||
/// </summary> | ||
/// <seealso cref="BacklinksGenerator"/> | ||
/// <seealso cref="TranscludedInGenerator"/> | ||
/// <seealso cref="TransclusionsGenerator"/> | ||
public class FileUsageGenerator : WikiPageGenerator | ||
{ | ||
|
||
/// <inheritdoc /> | ||
public FileUsageGenerator(WikiSite site) : base(site) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
/// <param name="targetTitle">List pages transclude this file. The file does not need to exist.</param> | ||
public FileUsageGenerator(WikiSite site, string targetTitle) : base(site) | ||
{ | ||
TargetTitle = targetTitle; | ||
} | ||
|
||
/// <summary> | ||
/// List pages transcluding this file. The file does not need to exist. | ||
/// </summary> | ||
public string TargetTitle { get; set; } = ""; | ||
|
||
/// <summary> | ||
/// Only list pages in these namespaces. | ||
/// </summary> | ||
/// <value>Selected ids of namespace, or <c>null</c> if all the namespaces are selected.</value> | ||
public IEnumerable<int>? NamespaceIds { get; set; } | ||
|
||
/// <summary> | ||
/// How to filter redirects in the results. | ||
/// </summary> | ||
public PropertyFilterOption RedirectsFilter { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public override string ListName => "imageusage"; | ||
|
||
/// <inheritdoc /> | ||
public override IEnumerable<KeyValuePair<string, object?>> EnumListParameters() | ||
{ | ||
return new Dictionary<string, object?> | ||
{ | ||
{"iutitle", TargetTitle}, | ||
{"iunamespace", NamespaceIds == null ? null : MediaWikiHelper.JoinValues(NamespaceIds)}, | ||
{"iufilterredir", RedirectsFilter.ToString("redirects", "nonredirects")}, | ||
{"iulimit", PaginationSize} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters