MediaWiki定制化改動


Linux下面安裝MediaWiki環境的方法,可以參照我上一篇文章linux使用xampp安裝MediaWiki環境

重置用戶密碼

使用維護腳本

可以使用maintenance/changePassword.php維護腳本來重置一名用戶的密碼。必須在命令行下運行該腳本,需要登錄到安裝wiki的服務器,然后進入命令行提示符。進入安裝目錄,然后進入maintenance子目錄。運行下列命令:

php changePassword.php --user=someuser --password=somepass

這里可見的“somepass”就是您將要設置的密碼,而“someuser”就是您將修改其密碼的用戶名,該用戶名應出現在數據庫的“user”表中

直接修改數據庫

同樣可以使用直接修改數據庫的老辦法。假設變量$wgPasswordSalt已被設為true值(默認),您可以在MySQL中運行下列SQL查詢:

UPDATE user SET user_password = MD5(CONCAT(user_id, '-',  MD5('你的密碼'))) WHERE user_name = '你的用戶名';

修改維基名稱

在wiki代碼根目錄,找到LocalSettings.php,修改相應代碼為:

$wgSitename = "你的百科名稱";

現將文件上傳到對應目錄,即/opt/lampp/htdocs/wiki/resources/assets/。圖片大小改動可以使用這個網站

在wiki代碼根目錄,找到LocalSettings.php,修改相應代碼為:

## The URL path to the logo.  Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
$wgLogo = "$wgResourceBasePath/resources/assets/wiki.gif";

即將原先的wiki.png改為wiki.gif

頁面底部顯示最后修訂人名稱

在wiki代碼根目錄,找到LocalSettings.php,增加代碼

$wgMaxCredits = 2;

這樣一來就可以顯示最后修改的2條記錄,比如說

本頁面被小芒果最后修改於2019年10月11日 (星期五) 08:10。 基於芒果百科用戶小番茄的工作。

所在機器默認跳轉到wiki

安裝xampp后,index默認跳轉到 本機xampp主頁,即http://IP地址/xampp/,需要修改

修改index.php,改為

<?php
        if (!empty($_SERVER['HTTPS']) &amp;&amp; ('on' == $_SERVER['HTTPS'])) {
                $uri = 'https://';
        } else {
                $uri = 'http://';
        }
        $uri .= $_SERVER['HTTP_HOST'];
        header('Location: '.$uri.'/wiki/');
        exit;
?>

關閉游客注冊/修改/查看權限

在wiki代碼根目錄,找到LocalSettings.php,,在最后面附加如下代碼:

$wgGroupPermissions['*']['createaccount'] = true;
$wgGroupPermissions['*']['read'] = true;
$wgGroupPermissions['*']['edit'] = false;

即打開游客 注冊 / 瀏覽 權限,關閉 修改 權限

文檔歸類

為了防止出現信息孤島,所有百科頁面都該有分類,方便層層跳轉。

為了將當前頁面自動歸類,增加如下代碼即可將當前頁面自動歸類,比如我們有個歸類,專門用來教導用戶更好的使用wiki,即Wiki使用教程

[[category:Wiki使用教程]]

定制側邊欄

進入URL: /index.php/MediaWiki:Sidebar

我們將上面使用的那個分類加入側邊欄,增加一行** 分類:Wiki定制化|更好地使用wiki,其中|后的文案,即你要顯示在側邊欄的文本。

* navigation
** mainpage|mainpage-description
** recentchanges-url|recentchanges
** helppage|help
** 分類:Wiki定制化|更好地使用wiki

* SEARCH
* TOOLBOX
* LANGUAGES

修改后的側邊欄

修改后的側邊欄

Markdown文本轉MediaWiki格式

有些人不熟悉mediawiki的語法,更習慣使用markdown進行文檔編寫;或者有大量的markdown格式的文檔需要轉到wiki中來,怎么辦呢?
我們可以這么做:

少量文字直接使用在線版

https://pandoc.org/try/?text=&from=markdown&to=mediawiki

大量文字使用下載版

官網下載相應系統版本,比如我們使用windows版本

下載后放到任意盤(我放在D盤),將所在目錄加入環境變量,輸入指令進行轉化

D:\>pandoc.exe -f markdown -t mediawiki test.md > test.txt

文件上傳

官方上傳文檔教程

在wiki代碼根目錄,找到LocalSettings.php,添加允許的格式即可,比如允許bmp

$wgFileExtensions[] = 'bmp';

有些文件比較特殊,就算加到運行上傳列表還不夠,還要從黑名單里刪除,比如exe

$wgFileExtensions[] = 'exe';
$wgFileBlacklist = array_diff( $wgFileBlacklist, array ('exe') );

自定義皮膚

下載皮膚

下載鏈接,選擇1.33版本

放置到/opt/lampp/htdocs/維基目錄/skins/下面,解壓

$ tar xvf apex-REL1_33-9f99205.tar.gz 

加載皮膚

在wiki代碼根目錄,找到LocalSettings.php,在最后加入代碼:

wfLoadSkin( 'apex' );

自定義CSS

進入MediaWiki:Vector.css特殊頁面,然后編輯你要覆蓋重寫的CSS內容

MediaWiki:Vector.css 頁面

提供個不錯的主題CSS: DarkVector主題CSS

給默認的vector加上本博客的樣式

#p-tb {
    margin-top: 10px;
}
.mw-body p {
    font-size: 16px;
    color: #444;
}
pre, .mw-code {
    display: block;
    overflow-x: auto;
    padding: 20px !important;
    background: #edf0f3 !important;
    border: none !important;
    font-family: 'Consolas','Courier New',Courier,monospace !important;
    font-size: 14px !important;
}

div#mw-panel #p-logo + div.portal div.body {
    margin: 0;
}
div#mw-panel div.portal {
    background-image: none;
}
div#mw-panel div.portal div.body {
    margin: 0;
}

div#mw-panel div.portal div.body ul {
    border-top: 10px solid #CAD2DE;
    background: #2B497B;    
}

div#mw-panel div.portal div.body ul li {
    border-bottom: 1px dotted #fff;
    padding: 0.2em 10px;
    line-height: 15px;
}

div#mw-panel div.portal div.body ul li:hover {
    background: #A3181E;
}

div#mw-panel div.portal div.body ul li a {
    font-size: 10px;
    display: block;
    color: #FFF;
    font-weight: normal;
    text-decoration: none;
    text-transform: uppercase;
}

div#mw-panel div.portal div.body ul li a:visited {
    color: #EEE;
}

div#mw-panel div.portal h3 {
    font-size: 15px; 
    background: #A3181E;
    color: white;
    display: block;
    padding: 5px 10px;
}


.mw-body h1 {
    font-size: 2.5em;
    font-family: "微軟雅黑";
    font-weight: normal;
}

.mw-body h2 {
    font-size: 2em;
    margin: 1em 0 0.25em;
    padding: 10px 0px;
    border-bottom: 5px solid #F1F4F9;
    font-family: "微軟雅黑";
    font-weight: bold;
}

.mw-body h3:before {
    content: "\25BA ";
}

.mw-body a.external {
    text-decoration: none;
    color: orange !important;
    border-bottom: 1px dashed;
    padding-bottom: 2px;
}

.mw-body a.external:before {
    content: "\27A5";
}

.mw-body code {
    font-family: "Courier New",sans-serif !important;
    font-size: 12px !important;
    background-color: #f5f5f5 !important;
    padding: 0 5px !important;
    border-radius: 3px !important;
    border:none;
    line-height: 1.8;
    margin: 1px 5px;
    vertical-align: middle;
    display: inline-block;
}

.mw-body blockquote {
    background-color: #f7f7f7;
    word-break: break-word;
    font-weight: 400;
    line-height: 30px;
    padding: 1.5em;
    background: #E1E8FB;
    border-left: 5px solid #D2D8FB;
    margin: 10px 10px 10px 0px;
}

#catlinks {
    background-color: #f1f4f9;
    color: #f1f4f9;
    padding: 10px 0px;
    border: none;
}

#catlinks li {
    border: none;
}

#catlinks li a:link {
    position: relative;
    display: inline-block;
    height: 30px;
    padding: 0 12px;
    line-height: 30px;
    vertical-align: top;
    text-decoration: none;
    background: #fff;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 11px;
}
  
#catlinks li a:hover{
    background: #237dac;
    color: white;
}

#mw-normal-catlinks > a {
    position: relative;
    display: inline-block;
    height: 30px;
    padding: 0px 0px 0px 20px;
    line-height: 30px;
    vertical-align: top;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 11px;
}

/* 編輯按鈕 */
.editButtons input  {
    color: #fff;
    background-color: #1890ff;
    border-color: #1890ff;
    text-shadow: 0 -1px 0 rgba(0,0,0,0.12);
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    line-height: 1.5;
    position: relative;
    display: inline-block;
    font-weight: 400;
    white-space: nowrap;
    text-align: center;
    background-image: none;
    border: 1px solid transparent;
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.015);
    box-shadow: 0 2px 0 rgba(0,0,0,0.015);
    cursor: pointer;
    -webkit-transition: all .3s cubic-bezier(.645, .045, .355, 1);
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    height: 32px;
    padding: 0 15px;
    font-size: 14px;
    border-radius: 4px;
    border-color: #d9d9d9;
}

.editButtons input  {
    color: #fff;
    background-color: #1890ff;
    border-color: #1890ff;
    text-shadow: 0 -1px 0 rgba(0,0,0,0.12);
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    line-height: 1.5;
    position: relative;
    display: inline-block;
    font-weight: 400;
    white-space: nowrap;
    text-align: center;
    background-image: none;
    border: 1px solid transparent;
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.015);
    box-shadow: 0 2px 0 rgba(0,0,0,0.015);
    cursor: pointer;
    -webkit-transition: all .3s cubic-bezier(.645, .045, .355, 1);
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    height: 32px;
    padding: 0 15px;
    font-size: 14px;
    border-radius: 4px;
    border-color: #d9d9d9;
}

.editButtons input:hover {
    background-color: #40a9ff;
}

.editButtons input  {
    color: #fff;
    background-color: #1890ff;
    border-color: #1890ff;
    text-shadow: 0 -1px 0 rgba(0,0,0,0.12);
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    line-height: 1.5;
    position: relative;
    display: inline-block;
    font-weight: 400;
    white-space: nowrap;
    text-align: center;
    background-image: none;
    border: 1px solid transparent;
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.015);
    box-shadow: 0 2px 0 rgba(0,0,0,0.015);
    cursor: pointer;
    -webkit-transition: all .3s cubic-bezier(.645, .045, .355, 1);
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    height: 32px;
    padding: 0 15px;
    font-size: 14px;
    border-radius: 4px;
    border-color: #d9d9d9;
}

.editButtons input:hover {
    background-color: #40a9ff;
}

#wpSave {
    background-color: #009100;
}

#wpSave:hover {
    background-color: #00A600;
}

.mango-alert {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    color: rgba(0,0,0,0.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    list-style: none;
    font-feature-settings: 'tnum';
    position: relative;
    padding: 8px 15px 8px 37px;
    word-wrap: break-word;
    border-radius: 4px;
    margin: 10px 0px 10px 0px;
}

.mango-alert-info {
    background-color: #e6f7ff;
    border: 1px solid #91d5ff;
}

.mango-alert-warn {
    background-color: #fffbe6;
    border: 1px solid #ffe58f
}

.mango-alert-error {
    background-color: #fff1f0;
    border: 1px solid #ffa39e;
}

/**
 * 左側導航欄拓寬
 */

div#mw-panel {
    width: 13em;
}

.mw-body {
    margin-left: 14em;
}

#left-navigation {
    margin-left: 14em;
}

#p-logo a {
    width: 13em;
}

div#footer {
    margin-left: 13em;
}


/** 
 * 表格樣式 
 */

table.wikitable {
	border: none !important;
}

table.wikitable td {
	border: none !important;
	padding: 0.2em 2em !important;
}

/*設置奇數行顏色*/
table.wikitable  tr:nth-child(odd) {
    background: #EEE;
}

/*設置偶數行顏色*/
table.wikitable  tr:nth-child(even) {
    background: #FFF;
}

table.wikitable th {
    background-color: #2894FF !important;
    color: white;
    text-align: center;
    font-weight: bold;
    letter-spacing: 1em;
    border: none !important;
	padding: 0.2em 2em !important;
}

table.wikitable tr:nth-child(1) {
    background-color: #2894FF;
    color: white;
    text-align: center;
    font-weight: bold;
    letter-spacing: 1em;
}

table.wikitable tbody:last-child {
    border-bottom: 1px solid;
}


模板功能

進入模板:提示路由,即可建立名字為提示的模板。

<div style="background-color: #e6f7ff;border: 1px solid #91d5ff; -webkit-box-sizing: border-box; box-sizing: border-box;margin: 0; color: rgba(0,0,0,0.65);font-size: 14px;font-variant: tabular-nums;line-height: 1.5;list-style: none; font-feature-settings: 'tnum';position: relative;padding: 8px 15px 8px 37px;word-wrap: break-word;border-radius: 4px;margin: 10px 0px 10px 0px;">
<span style="font-size: 1.5em;">🙋</span> {{{文本}}}
</div>

上面的代碼中,{{{文本}}}即你可以填寫變量的地方,變量名就叫做文本。保存后,在其他頁面這樣使用

{{提示 | 文本=這樣就可以使用模板啦!]]}}

樣式如下所示:

當然了,css寫在單獨文件是比較好的習慣,直接給div加上相應的類就好了!

嵌套模板

上面的模板,還可以設置一個母模板,以方便采用多種樣式的提示框

進入模板:提示框路由,即可建立名字為提示框的母模板。

<div class="mango-alert mango-alert-{{{類型}}}">
<span style="font-size: 1.5em;">{{{圖標}}}</span> {{{文本}}}
</div>

然后,重新編輯上面的模板提示

{{提示框
|類型=info
|圖標=🙋
|文本={{{文本}}}
}}

在自定義CSS中加入以下代碼

.mango-alert {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    color: rgba(0,0,0,0.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    list-style: none;
    font-feature-settings: 'tnum';
    position: relative;
    padding: 8px 15px 8px 37px;
    word-wrap: break-word;
    border-radius: 4px;
    margin: 10px 0px 10px 0px;
}

.mango-alert-info {
    background-color: #e6f7ff;
    border: 1px solid #91d5ff;
}

.mango-alert-warn {
    background-color: #fffbe6;
    border: 1px solid #ffe58f
}

.mango-alert-error {
    background-color: #fff1f0;
    border: 1px solid #ffa39e;
}

如此一來,便可以實現嵌套模板啦!

啟用更強的編輯功能

如圖,點擊右上角設置,按照下面的設置選中相關選項即可

自動給標題加編號

如圖,點擊右上角設置 > 顯示,按照下面的設置選中相關選項即可

升級時候全wiki只讀

在wiki代碼根目錄,找到LocalSettings.php,增加代碼

$wgReadOnly = '系統維護中,請2019年10月25日上午10點后操作....';

當用戶修改文件時,將會顯示下面的提示


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM