This commit is contained in:
Zel
2025-02-23 18:47:21 +08:00
parent eaaffeeccb
commit e46a7ca31c
104 changed files with 2630 additions and 2516 deletions

View File

@@ -8,19 +8,21 @@ using Constants = ZelWiki.Engine.Library.Constants;
namespace ZelWiki.Engine.Implementation
{
/// <summary>
/// Handles links from one wiki page to another.
/// 内链处理.
/// </summary>
public class InternalLinkHandler : IInternalLinkHandler
{
/// <summary>
/// Handles an internal wiki link.
///
/// </summary>
/// <param name="state">Reference to the wiki state object</param>
/// <param name="pageNavigation">The navigation for the linked page.</param>
/// <param name="pageName">The name of the page being linked to.</param>
/// <param name="linkText">The text which should be show in the absence of an image.</param>
/// <param name="image">The image that should be shown.</param>
/// <param name="imageScale">The 0-100 image scale factor for the given image.</param>
/// <param name="state"></param>
/// <param name="pageNavigation"></param>
/// <param name="pageName"></param>
/// <param name="linkText"></param>
/// <param name="image"></param>
/// <param name="imageScale"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public HandlerResult Handle(IZelEngineState state, NamespaceNavigation pageNavigation,
string pageName, string linkText, string? image, int imageScale)
{
@@ -37,18 +39,21 @@ namespace ZelWiki.Engine.Implementation
if (image.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|| image.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
//The image is external.
href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}{image}?Scale={imageScale}\" /></a>";
//外部图片.
href =
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}{image}?Scale={imageScale}\" /></a>";
}
else if (image.Contains('/'))
{
//The image is located on another page.
href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
//图像位于另一页面.
href =
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
}
else
{
//The image is located on this page, but this page does not exist.
href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>";
//图像位于此页面上,但此页面不存在.
href =
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>";
}
return new HandlerResult(href)
@@ -58,7 +63,8 @@ namespace ZelWiki.Engine.Implementation
}
else if (linkText != null)
{
var href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>"
var href =
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>"
+ "<font color=\"#cc0000\" size=\"2\">?</font>";
return new HandlerResult(href)
@@ -73,7 +79,7 @@ namespace ZelWiki.Engine.Implementation
}
else
{
//The page does not exist and the user does not have permission to create it.
//该页面不存在,用户没有创建该页面的权限.
if (image != null)
{
@@ -82,17 +88,18 @@ namespace ZelWiki.Engine.Implementation
if (image.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|| image.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
//The image is external.
//外部图像.
mockHref = $"<img src=\"{GlobalConfiguration.BasePath}{image}?Scale={imageScale}\" />";
}
else if (image.Contains('/'))
{
//The image is located on another page.
mockHref = $"<img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" />";
//图像位于另一页.
mockHref =
$"<img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" />";
}
else
{
//The image is located on this page, but this page does not exist.
//图像位于此页面上,但此页面不存在.
mockHref = $"linkText";
}
@@ -110,7 +117,7 @@ namespace ZelWiki.Engine.Implementation
}
else
{
throw new Exception("No link or image was specified.");
throw new Exception("未指定链接或图像.");
}
}
}
@@ -123,23 +130,26 @@ namespace ZelWiki.Engine.Implementation
if (image.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|| image.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
//The image is external.
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}{image}\" /></a>";
//外部图像.
href =
$"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}{image}\" /></a>";
}
else if (image.Contains('/'))
{
//The image is located on another page.
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
//图像在另一页面.
href =
$"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
}
else
{
//The image is located on this page.
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{state.Page.Navigation}/{image}?Scale={imageScale}\" /></a>";
//图像在此页面
href =
$"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{state.Page.Navigation}/{image}?Scale={imageScale}\" /></a>";
}
}
else
{
//Just a plain ol' internal page link.
//内链
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\">{linkText}</a>";
}
@@ -150,4 +160,4 @@ namespace ZelWiki.Engine.Implementation
}
}
}
}
}