帮助:CSS 清理

跳转到:导航搜索

此页面描述了如何将硬编码的 "style=..." 替换为正确的 CSS 类。

您可以在 邮件列表存档 中找到更多详细信息。

工作流程

  1. 使用以下部分中的脚本下载所有 Template:* 页面
  2. 查找使用 style= 的模板grep -i style= templates/*
  3. 从 "style=..." 中获取样式,找到合适的 CSS 类名,并将其作为 CSS 类写入 $page
    1. 如果模板用作页面模板,请将确切的 style="..." 代码和新的类名存储在 $otherpage 上 - 这使得以后使用搜索和替换来清理这些页面更容易
  4. 联系维基管理员将 CSS 类移动到 MediaWiki:Common.css
  5. 从所有添加了 class= 的模板中删除 style=

用作页面模板的模板

用作页面模板的模板列在

下载所有模板页面的脚本

此脚本从 en.opensuse.org 下载所有 Template:* 页面。请仅在您想进行 CSS 清理时使用它,以避免不必要的服务器负载。

#!/bin/bash                                                                                                                                              
 
# where to store the templates
output_dir="./templates"
 
 
### you shouldn't need to change anything below this line ###
 
test -d "$output_dir" || mkdir -p "$output_dir" || { echo "can't mkdir $output_dir"; exit 1; }
cd "$output_dir" || { echo "can't cd to $output_dir"; exit 1; }
 
set -o pipefail
 
# get template list
wget -q 'https://en.opensuse.net.cn/index.php?title=Special:Templates&limit=500&offset=0' -O - | \
    sed -n '/<!-- Begin Content Area -->/,/<!-- End Content Area -->/ s/^<li><a href="\/\([^"]*\)".*/\1/p' | \
    grep -v '/doc$' > template-list.txt || { echo "error downloading the tempate list"; exit 1; }
 
echo "List of templates (excluding */doc) stored in template-list.txt."
 
# download templates
while read template ; do
    echo -n "downloading $template...   "
    outfile=$(echo "$template" | sed 's§/§+§g')
    test "$template" = "$outfile" || echo -n "(saved as $outfile)   "
    wget -q "https://en.opensuse.net.cn/index.php?title=$template&action=raw" -O "$outfile" && echo OK || { failures="$failures $template" ; echo failed; }
    sleep 1 # don't overload the wiki
done < template-list.txt
 
echo
echo "Templates saved in $output_dir"
test -n "$failures" && echo "Download failures: $failures"