Mediawiki 修改:修訂版本之間的差異

出自六年制學程
跳轉到: 導覽搜尋
(新頁面: <tr><td>分類:Mediawiki分類:丁丁私人 ==更新快取== *資料夾沒有更名:編輯再儲存 *當修改 mediawiki 所在資料夾名稱,須同步改 LocalSettings.ph...)
 
第 1 行: 第 1 行:
<tr><td>[[分類:Mediawiki]][[分類:丁丁私人]]
+
[[分類:Mediawiki]][[分類:丁丁私人]]
 
==更新快取==
 
==更新快取==
 
*資料夾沒有更名:編輯再儲存
 
*資料夾沒有更名:編輯再儲存
第 16 行: 第 16 行:
 
===includes/Title.php===
 
===includes/Title.php===
 
====1.17版====
 
====1.17版====
在 Title 類別 userCanRead 方法中增加&lt;pre&gt;
+
在 Title 類別 userCanRead 方法中增加<pre>
 
global $wgUser, $wgGroupPermissions, $canRead; // by jj
 
global $wgUser, $wgGroupPermissions, $canRead; // by jj
  
 
// 依 $canRead 判斷是否可讀本頁 by jj
 
// 依 $canRead 判斷是否可讀本頁 by jj
 
if(isset($canRead['group']) &amp;&amp; count($canRead['group'])){
 
if(isset($canRead['group']) &amp;&amp; count($canRead['group'])){
$name = $this-&gt;getPrefixedText(); // 取回本頁帶名字空間的頁名
+
$name = $this->getPrefixedText(); // 取回本頁帶名字空間的頁名
 
if(isset($canRead['group'][$name]) &amp;&amp; is_array($canRead['group'][$name])){
 
if(isset($canRead['group'][$name]) &amp;&amp; is_array($canRead['group'][$name])){
if(isset($wgUser-&gt;mGroups) &amp;&amp; is_array($wgUser-&gt;mGroups)){
+
if(isset($wgUser->mGroups) &amp;&amp; is_array($wgUser->mGroups)){
 
$revoke=0;
 
$revoke=0;
foreach($wgUser-&gt;mGroups as $v){if(in_array($v,$canRead['group'][$name])){$revoke+=1;}}
+
foreach($wgUser->mGroups as $v){if(in_array($v,$canRead['group'][$name])){$revoke+=1;}}
 
if($revoke==0){
 
if($revoke==0){
 
return false;
 
return false;
第 31 行: 第 31 行:
 
}
 
}
 
}
 
}
}&lt;/pre&gt;
+
}</pre>
 
====1.19版====
 
====1.19版====
 
userCanRead()交給了userCan('read');
 
userCanRead()交給了userCan('read');
第 37 行: 第 37 行:
  
 
但上述這些函式只能增加「錯誤訊息」陣列,並不能阻擋共筆頁內容的顯示。所有要進行共筆頁讀取權限控管,必須從 /includes/SkinTemplate.php 中 SkinTemplate 類別的 outputPage 方法,在  
 
但上述這些函式只能增加「錯誤訊息」陣列,並不能阻擋共筆頁內容的顯示。所有要進行共筆頁讀取權限控管,必須從 /includes/SkinTemplate.php 中 SkinTemplate 類別的 outputPage 方法,在  
  $tpl-&gt;data['bodytext'] .= $tpl-&gt;data['debughtml'];
+
  $tpl->data['bodytext'] .= $tpl->data['debughtml'];
之後加上:&lt;pre&gt;// 依 $canRead 判斷是否可讀本頁,by jj
+
之後加上:<pre>// 依 $canRead 判斷是否可讀本頁,by jj
 
global $wgUser, $canRead, $wgTitle, $wgServer, $wgScriptPath;
 
global $wgUser, $canRead, $wgTitle, $wgServer, $wgScriptPath;
 
if(isset($canRead['group']) &amp;&amp; count($canRead['group'])){
 
if(isset($canRead['group']) &amp;&amp; count($canRead['group'])){
$name = $wgTitle-&gt;getPrefixedText(); // 取回本頁帶名字空間的頁名
+
$name = $wgTitle->getPrefixedText(); // 取回本頁帶名字空間的頁名
 
if(isset($canRead['group'][$name]) &amp;&amp; is_array($canRead['group'][$name])){
 
if(isset($canRead['group'][$name]) &amp;&amp; is_array($canRead['group'][$name])){
if(isset($wgUser-&gt;mGroups) &amp;&amp; is_array($wgUser-&gt;mGroups)){
+
if(isset($wgUser->mGroups) &amp;&amp; is_array($wgUser->mGroups)){
 
$revoke=0;
 
$revoke=0;
foreach($wgUser-&gt;mGroups as $v){if(in_array($v,$canRead['group'][$name])){$revoke+=1;}}
+
foreach($wgUser->mGroups as $v){if(in_array($v,$canRead['group'][$name])){$revoke+=1;}}
if($revoke==0){$tpl-&gt;data['bodycontent']='您無權限讀此頁。[&lt;a href='.$wgServer.$wgScriptPath.'&gt;回首頁&lt;/a&gt;]';}
+
if($revoke==0){$tpl->data['bodycontent']='您無權限讀此頁。[<a href='.$wgServer.$wgScriptPath.'>回首頁</a>]';}
 
}
 
}
 
}
 
}
}&lt;/pre&gt;
+
}</pre>
  
 
==除錯==
 
==除錯==
第 57 行: 第 57 行:
 
在之下插入除錯資訊 全域變數 $jjj,然後在要除錯的程式段落中對 $jjj 派值。
 
在之下插入除錯資訊 全域變數 $jjj,然後在要除錯的程式段落中對 $jjj 派值。
  
===&lt;nowiki&gt;{ {&lt;/nowiki&gt;…} }內層嵌入===
+
===<nowiki>{ {</nowiki>…} }內層嵌入===
&lt;nowiki&gt;{ {&lt;/nowiki&gt;…} }嵌入之title,其運行中之變數傳不到上一層,所以無法在skin(最外層)查看變數(如上段的方法),除錯,請用:
+
<nowiki>{ {</nowiki>…} }嵌入之title,其運行中之變數傳不到上一層,所以無法在skin(最外層)查看變數(如上段的方法),除錯,請用:
  
 
$flog=fopen('./jjj',"a+");fwrite($flog,變數."\n");fclose($flog); // by jj
 
$flog=fopen('./jjj',"a+");fwrite($flog,變數."\n");fclose($flog); // by jj
第 68 行: 第 68 行:
 
$messages 陣列中以下元素  
 
$messages 陣列中以下元素  
  
'badaccess-groups' =&gt; '您剛才的請求只有&lt;nowiki&gt;{{&lt;/nowiki&gt;PLURAL:$2|這個|這些}}使用者群組的使用者才能使用: $1',
+
'badaccess-groups' => '您剛才的請求只有<nowiki>{{</nowiki>PLURAL:$2|這個|這些}}使用者群組的使用者才能使用: $1',
  
 
將「群」改成「群組」
 
將「群」改成「群組」
第 86 行: 第 86 行:
 
==支援 SVG==
 
==支援 SVG==
 
*[http://www.mediawiki.org/wiki/Manual:$wgSVGConverters $wgSVGConverters]
 
*[http://www.mediawiki.org/wiki/Manual:$wgSVGConverters $wgSVGConverters]
*[http://www.mediawiki.org/wiki/Manual:Image_administration Image_administration]
+
*[http://www.mediawiki.org/wiki/Manual:Image_administration Image_administration]</td></tr>

2014年8月11日 (一) 09:29的修訂版本

更新快取

  • 資料夾沒有更名:編輯再儲存
  • 當修改 mediawiki 所在資料夾名稱,須同步改 LocalSettings.php 中的 $wgScriptPath 。但此時 mediawiki 仍會從快取中取得包含舊資料夾名稱的許多快取頁,導致網站完全無法運作。請依畫面指示,在相關的檔案中加一行「echo __FILE__;」,使網頁內容發生變化,導致產生新的快取,問題即可逐步排除。例如在 includes/Defines.php 中加「echo __FILE__;」。

限制某些頁面只有某些群組可讀取

wiki_user_groups表

對目標帳號加群組,如 jj

LocalSettings.php

定義 $canRead['group']

  1. 為一陣列
  2. 各元素索引為頁名
  3. 各元素值為可讀此頁之群組陣列
  4. 中文頁名須以 URL 格式寫,再以 urldecode 函式解碼

includes/Title.php

1.17版

在 Title 類別 userCanRead 方法中增加
global $wgUser, $wgGroupPermissions, $canRead;	// by jj

// 依 $canRead 判斷是否可讀本頁 by jj
if(isset($canRead['group']) && count($canRead['group'])){
	$name = $this->getPrefixedText();	// 取回本頁帶名字空間的頁名
	if(isset($canRead['group'][$name]) && is_array($canRead['group'][$name])){
		if(isset($wgUser->mGroups) && is_array($wgUser->mGroups)){
			$revoke=0;
			foreach($wgUser->mGroups as $v){if(in_array($v,$canRead['group'][$name])){$revoke+=1;}}
			if($revoke==0){
				return false;
			}
		}
	}
}

1.19版

userCanRead()交給了userCan('read'); userCan(動作,帳號物件,是否全套檢查)又交給了getUserPermissionsErrorsInternal(動作,帳號,是否全套,遇錯就短路);再交給checkReadPermissions(動作,帳號,錯陣列,是否全套,遇錯就短路)。

但上述這些函式只能增加「錯誤訊息」陣列,並不能阻擋共筆頁內容的顯示。所有要進行共筆頁讀取權限控管,必須從 /includes/SkinTemplate.php 中 SkinTemplate 類別的 outputPage 方法,在

$tpl->data['bodytext'] .= $tpl->data['debughtml'];
之後加上:
// 依 $canRead 判斷是否可讀本頁,by jj
global $wgUser, $canRead, $wgTitle, $wgServer, $wgScriptPath;
if(isset($canRead['group']) && count($canRead['group'])){
	$name = $wgTitle->getPrefixedText();	// 取回本頁帶名字空間的頁名
	if(isset($canRead['group'][$name]) && is_array($canRead['group'][$name])){
		if(isset($wgUser->mGroups) && is_array($wgUser->mGroups)){
			$revoke=0;
			foreach($wgUser->mGroups as $v){if(in_array($v,$canRead['group'][$name])){$revoke+=1;}}
			if($revoke==0){$tpl->data['bodycontent']='您無權限讀此頁。[<a href='.$wgServer.$wgScriptPath.'>回首頁</a>]';}
		}
	}
}

除錯

skins/Vector.php

VectorTemplate 類別中的 execute 方法中,找到 &lt;!-- bodytext --&gt;(1.19版為&lt;!-- bodycontent --&gt;)

在之下插入除錯資訊 全域變數 $jjj,然後在要除錯的程式段落中對 $jjj 派值。

{ {…} }內層嵌入

用{ {…} }嵌入之title,其運行中之變數傳不到上一層,所以無法在skin(最外層)查看變數(如上段的方法),除錯,請用:

$flog=fopen('./jjj',"a+");fwrite($flog,變數."\n");fclose($flog); // by jj

然後查看 mediawiki/jjj 檔之新寫入內容。

調整中文化訊息

languages/messages/MessagesZh_tw.php

$messages 陣列中以下元素

'badaccess-groups' => '您剛才的請求只有{{PLURAL:$2|這個|這些}}使用者群組的使用者才能使用: $1',

將「群」改成「群組」

資料表

wiki_interwiki

跨 wiki 連結增加中文維基百科 zhwikipedia:http://zh.wikipedia.org/wiki/$1

嵌入本站及跨wiki段落

詳見 includes/parser/Parser.php 中 Parser類別中的braceSubstitution方法之修改。

擴充可以用HTML標籤

  • 參考 英文維基百科說明
  • 調整 include/Sanitizer.php 中 Sanitizer.php,$htmlsingle,$htmlsingleonly,$htmlnest,$tabletags,$htmllist,$listtags 諸陣列的內容。
    1. a 標籤是有效的。
    2. iframe不但無效,而且基於安全考量,wikimedia 連 Extension:Website in iFrame 都加以移除。

支援 SVG