这个问题出现在侧边栏收起展开的小工具上,代码中会用到两个svg的图标(一个向左和一个向右的箭头),正常尺寸是512×512像素,能够正常显示,并且240个像素也能正常显示。而代码中所使用的尺寸为15个像素却无法显示。
原本以为是过度缩小引起的问题,结果在另外一个图标上,240个像素同样无法显示(该图尺寸较大,原始尺寸1,376 × 395像素)。
一度我对这问题已经抱放弃的态度了,毕竟其他方面的使用没有什么太大的问题,不值得为了它花费太多时间。
然而就在最近,因为安装Math扩展,一致在跟restbase死磕,能想到的问题基本上都想过了。最后落在了nginx配置上,很有可能跟short url有关,官方其实提醒过不要采用www.example.com/page_title方式,容易出现问题,姑且一试吧。
其实我现在使用的nginx配置文件存在很久了,基本上在1.30年代使用到现在(参见《Mediawiki短链设置》,也不知道从哪个站点找来的,反正能用就懒得改了。先备份原有的文件后,尝试修改。
官方给了一个很好的网站https://shorturls.redwerks.org/,只要把你希望的short url的形式输入进去,它就会自动生成一个配置文件,非常方便,没想到就是这一个举动,竟然解决了这个问题。
贴一下它给出的代码:

server {
    # [...]

    # Location for the wiki's root
    location / {
        try_files $uri $uri/ @mediawiki;
        
        # Do this inside of a location so it can be negated
        location ~ \.php$ {
            try_files $uri $uri/ =404; # Don't let php execute non-existent php files
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
        }
    }
    
    location /images {
        # Separate location for images/ so .php execution won't apply
        
        location ~ ^/images/thumb/(archive/)?[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ {
            # Thumbnail handler for MediaWiki
            # This location only matches on a thumbnail's url
            # If the file does not exist we use @thumb to run the thumb.php script
            try_files $uri $uri/ @thumb;
        }
    }
    location /images/deleted {
        # Deny access to deleted images folder
        deny    all;
    }
    
    # Deny access to folders MediaWiki has a .htaccess deny in
    location /cache       { deny all; }
    location /languages   { deny all; }
    location /maintenance { deny all; }
    location /serialized  { deny all; }
    
    # Just in case, hide .svn and .git too
    location ~ /.(svn|git)(/|$) { deny all; }
    
    # Hide any .htaccess files
    location ~ /.ht { deny all; }
    
    # Uncomment the following code if you wish to hide the installer/updater
    ## Deny access to the installer
    #location /mw-config { deny all; }
    
    # Handling for the article path
    location @mediawiki {
        include /etc/nginx/fastcgi_params;
        # article path should always be passed to index.php
        fastcgi_param SCRIPT_FILENAME    $document_root/index.php;
        fastcgi_pass  127.0.0.1:9000;
    }
    
    # Thumbnail 404 handler, only called by try_files when a thumbnail does not exist
    location @thumb {
        # Do a rewrite here so that thumb.php gets the correct arguments
        rewrite ^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /thumb.php?f=$1&width=$2;
        rewrite ^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /thumb.php?f=$1&width=$2&archived=1;
        
        # Run the thumb.php script
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME    $document_root/thumb.php;
        fastcgi_pass  127.0.0.1:9000;
    }
    
    # [...]
}

可以看出,其中有一项单独的重写设置就是针对缩略图的。
另外,网站也给出了LocalSettings.php中的相应代码,可谓是相当贴心了。

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = "/$1";
$wgUsePathInfo = true;

## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads  = true;
$wgGenerateThumbnailOnParse = false;

重新加载配置后,刷新一下浏览器,可爱的图片终于出现了。

最后修改:2021 年 06 月 11 日
如果觉得我的文章对你有用,请随意赞赏