Skip to content

Commit

Permalink
Add ParsingOptions.DisableLimitReport . Update the members of ParserL…
Browse files Browse the repository at this point in the history
…imitReport. Update RenderingTests.WpTestPageParsingTest1 .
  • Loading branch information
CXuesong committed Dec 6, 2016
1 parent c56d778 commit 79d010a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
12 changes: 6 additions & 6 deletions UnitTestProject1/RenderingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public void WpTestPageParsingTest1()
var site = WpTestSite;
var result = AwaitSync(
site.ParseContentAsync("{{DISPLAYTITLE:''TITLE''}}\nText '''Text'''\n\n{{PAGENAME}}", "Summary.",
"TITLE", ParsingOptions.LimitReport));
"TITLE", ParsingOptions.DisableLimitReport));
ShallowTrace(result, 3);
Assert.AreEqual(result.Title, "TITLE");
Assert.AreEqual(result.DisplayTitle, "<i>TITLE</i>");
Assert.AreEqual(result.Content.Trim(), "<p>Text <b>Text</b></p>\n<p>TITLE</p>");
Assert.AreEqual("TITLE", result.Title);
Assert.AreEqual("<i>TITLE</i>", result.DisplayTitle);
Assert.AreEqual("<p>Text <b>Text</b></p>\n<p>TITLE</p>", result.Content.Trim());
/////////////////////
result = AwaitSync(site.ParseContentAsync("{{ambox}}", "Summary.", "TITLE",
ParsingOptions.LimitReport | ParsingOptions.TranscludedPages));
ShallowTrace(result, 4);
Assert.IsTrue(result.TranscludedPages.Any(p => p.Title == "Template:Ambox"));
Assert.IsTrue((int) result.ParserLimitReports.First(r => r.Name == "limitreport")
.Content["expansiondepth"]["value"] > 1);
Assert.IsTrue((int) result.ParserLimitReports.First(r => r.Name == "limitreport-expansiondepth").Value > 1);
}
}
}
21 changes: 18 additions & 3 deletions WikiClientLibrary/ParsedContentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,28 @@ public class ParserLimitReport
/// <summary>
/// Limit report name.
/// </summary>
/// <remarks>E.g. smw-limitreport-intext-parsertime, limitreport-templateargumentsize .</remarks>
[JsonProperty]
public string Name { get; private set; }

/// <summary>
/// Limit report content, as a collection of JSON.
/// Current value of the report.
/// </summary>
[JsonExtensionData]
public IDictionary<string, JToken> Content { get; private set; }
[JsonProperty("0")]
public double Value { get; private set; }

/// <summary>
/// Value limit of the report, if available.
/// </summary>
[JsonProperty("1")]
public double? Limit { get; private set; }

/// <inheritdoc />
public override string ToString()
{
var s = Name + ": " + Value;
if (Limit != null) s += "/" + Limit;
return s;
}
}
}
21 changes: 18 additions & 3 deletions WikiClientLibrary/Site.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,13 @@ public Task<IList<OpenSearchResultEntry>> OpenSearchAsync(string searchExpressio
p["prop"] += "|templates";
if ((options & ParsingOptions.LimitReport) == ParsingOptions.LimitReport)
p["prop"] += "|limitreportdata";
if ((options & ParsingOptions.DisableLimitReport) == ParsingOptions.DisableLimitReport)
{
if (SiteInfo.Version >= new Version("1.26"))
p["disablelimitreport"] = true;
else
p["disablepp"] = true;
}
return p;
}

Expand Down Expand Up @@ -1138,17 +1145,25 @@ public enum ParsingOptions
/// </summary>
NoImages = 0x20,
/// <summary>
/// Gives the limit report. (1.23+)
/// Gives the structured limit report. (1.23+)
/// This flag fills <see cref="ParsedContentInfo.ParserLimitReports"/>.
/// </summary>
LimitReport = 0x40,
/// <summary>
/// Omit the limit report ("NewPP limit report") from the parser output. (1.17+, disablepp; 1.23+, disablelimitreport)
/// <see cref="ParsedContentInfo.ParserLimitReports"/> will be empty if both this flag and <see cref="LimitReport"/> is set.
/// </summary>
/// <remarks>By default, the limit report will be included as comment in the parsed HTML content.
/// This flag can supress such output.</remarks>
DisableLimitReport = 0x80,
/// <summary>
/// Includes language links supplied by extensions. (1.22+)
/// </summary>
EffectiveLanguageLinks = 0x80,
EffectiveLanguageLinks = 0x100,
/// <summary>
/// Gives the templates and other transcluded pages/modules in the parsed wikitext.
/// </summary>
TranscludedPages = 0x100,
TranscludedPages = 0x200,
}

/// <summary>
Expand Down

0 comments on commit 79d010a

Please sign in to comment.