美国主机Lunarpages

Mediawiki中文技术论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5787|回复: 0

mediawiki扩展:使用本地资源批量上传图片

[复制链接]
发表于 2014-2-16 00:13:17 | 显示全部楼层 |阅读模式
HostEase主机优惠

这几天在弄公司的wiki系统,用的死Mediawiki,感觉还不错,公司把它当作内部资料库在用,每个人都往里面贴东西,mediawiki自带的那个图片上传系统实在是有点简单了,上传少量图片还好,要是图片太多那岂不是不让人活了...
于是想办法,看能不能批量上传,baidu哈,倒是有关于mediawiki的mass
upload的字样,英文的,没办法,谁让要用呢,仔细看了看操作也不是太复杂,遂试试,当然不是在正在用的那个wiki系统上,另外建了个测试。
大概就是如下几步:
1.新建个文件夹放需要批量上传的图片,这里c:\ftp,去除其只读属性
2.在mediawiki安装目录下的localsetting.php中增加如下代码:
require_once( "extensions/SpecialUploadLocal.php" );
$wgUploadLocalDirectory = 'c:\ftp';
#你设置的文件夹地址,绝对的相对的都行
patch -p0
if (!defined('MEDIAWIKI')) die();
//Special:Uploadlocal specific
config
$wgExtensionFunctions[] =
"wfExtensionSpecialUploadLocal";
function wfExtensionSpecialUploadLocal() {
global
$wgMessageCache;
// I'd like to try adding these messages on
demand, and only have the
// essentials here
$messages = array(
'uploadlocal' => 'Upload local files'
,'uploadlocal_directory_readonly' => 'The local upload directory
($1) is'.
' not writeable by the webserver.'
,'uploadlocaltext' => 'Use this form to mass upload files
already on the'.
' server in the upload local directory. You can find out
more'.
' general information at [[Special:Upload|the regular upload
file'.
' page]].'
,'uploadlocalbtn' => 'Upload local files'
,'nolocalfiles' => 'There are no files in the local upload
folder. Try'.
' placing some files in "$1."'
,'uploadednolocalfiles' => 'You did not upload any files.'
,'allfilessuccessful' => 'All files uploaded successfully'
,'uploadlocalerrors' => 'Some files had errors'
,'allfilessuccessfultext' => 'All files uploaded successfully.
Return to'.
' [[Main Page]].'
,'uploadlocal_descriptions_append' => 'Append to description:
'
,'uploadlocal_descriptions_prepend' => 'Prepend to description:
'
,'uploadlocal_dest_file_append' => 'Append to dest. filename:
'
,'uploadlocal_dest_file_prepend' => 'Prepend to dest. filename:
'
,'uploadlocal_file_list' => 'Files ready for upload'
,'uploadlocal_file_list_explanation' => '\'\'\'X\'\'\'
indicates'.
' whether or not you want the file to be uploaded (uncheck
to'.
' prevent a file from being processed). \'\'\'W\'\'\'
indicates'.
' whether you want the file added to your watchlist.'
,'uploadlocal_global_params' => 'Global parameters'
,'uploadlocal_global_params_explanation' => 'What is entered
here will'.
' automatically get added to the entries listed above. This
helps'.
' remove repetitive text such as categories and metadata. To
\'\'\''.
'append\'\'\' is to add to the end of text, while to
\'\'\'prepend'.
'\'\'\' means to add to the beginning of text. Especially
for'.
' descriptions, make sure you give a few linebreaks
before/after'.
' the text.'
);
$wgMessageCache->addMessages($messages);
SpecialPage::addPage( new SpecialPage( 'UploadLocal', 'uploadlocal'
) );
}
$wgUploadLocalDirectory = $IP .
'/extensions/uploadlocal';
$wgAvailableRights[] =
'uploadlocal';
$wgGroupPermissions['uploader']['uploadlocal']
= true;
$wgGroupPermissions['sysop']
['uploadlocal'] = true;
?>
4.新建PHP文件includes/SpecialUploadLocal.php
(新浪这个只允许2万字,汗..下篇中有...)
5.新建文件Magic_quotes_2.patch 放安装根目录
--- C:/Documents and Settings/Edward/My Documents/My Webs/jpsband/mediawiki/t/includes/WebRequest.php (revision 454)
+++ includes/WebRequest.php (revision 526)
@@ -48,9 +48,15 @@
/**
* Recursively strips slashes from the given array;
* used for undoing the evil that is magic_quotes_gpc.
+*
+* Abandoned in favor of more accurate fix_magic_quotes_4 and 5, which
+* were based largely on comments in
+* http://us3.php.net/manual/en/function.get-magic-quotes-gpc.php
+*
* @param array &$arr will be modified
* @return array the original array
* @private
+* @deprecated
*/
function &fix_magic_quotes( &$arr ) {
foreach( $arr as $key => $val ) {
@@ -63,6 +69,35 @@
return $arr;
}
+ function fix_magic_quotes_4($array, $is_top = true) {
+$return = array();
+foreach ($array as $key => $value) {
+$clean_key = !$is_top ? stripslashes($key) : $key;
+if (is_array($value)) {
+$clean_value = $this->fix_magic_quotes_4($value, false);
+} else {
+$clean_value = stripslashes($value);
+}
+$return[$clean_key] = $clean_value;
+}
+return $return;
+ }
+
+ function fix_magic_quotes_5($array, $is_top = true) {
+$return = array();
+foreach ($array as $key => $value) {
+if (is_array($value)) {
+$clean_key= !$is_top ? stripslashes($key) : $key;
+$clean_value = $this->fix_magic_quotes_5($value, false);
+} else {
+$clean_key= stripslashes($key);
+$clean_value = stripslashes($value);
+}
+$return[$clean_key] = $clean_value;
+}
+return $return;
+ }
+
/**
* If magic_quotes_gpc option is on, run the global arrays
* through fix_magic_quotes to strip out the stupid slashes.
@@ -72,12 +107,27 @@
*/
function checkMagicQuotes() {
if ( get_magic_quotes_gpc() ) {
-$this->fix_magic_quotes( $_COOKIE );
-$this->fix_magic_quotes( $_ENV );
-$this->fix_magic_quotes( $_GET );
-$this->fix_magic_quotes( $_POST );
-$this->fix_magic_quotes( $_REQUEST );
-$this->fix_magic_quotes( $_SERVER );
+//I would rather do it this way, but supposedly, version_compare
+//is more accurate:
+//$php_version = substr(PHP_VERSION,0,strpos(PHP_VERSION,'.'));
+if (version_compare(PHP_VERSION, '4', '>=') && version_compare(PHP_VERSION, '5', '//it is PHP4
+$_COOKIE= $this->fix_magic_quotes_4( $_COOKIE );
+$_ENV= $this->fix_magic_quotes_4( $_ENV );
+$_GET= $this->fix_magic_quotes_4( $_GET );
+$_POST= $this->fix_magic_quotes_4( $_POST );
+$_REQUEST = $this->fix_magic_quotes_4( $_REQUEST );
+$_SERVER= $this->fix_magic_quotes_4( $_SERVER );
+} elseif (version_compare(PHP_VERSION, '5', '>=') && version_compare(PHP_VERSION, '6', '//it is PHP5
+$_COOKIE= $this->fix_magic_quotes_5( $_COOKIE );
+$_ENV= $this->fix_magic_quotes_5( $_ENV );
+$_GET= $this->fix_magic_quotes_5( $_GET );
+$_POST= $this->fix_magic_quotes_5( $_POST );
+$_REQUEST = $this->fix_magic_quotes_5( $_REQUEST );
+$_SERVER= $this->fix_magic_quotes_5( $_SERVER );
+}
+//behavior for PHP3 and PHP6 is undefined, so don't do any fixing
}
}
6.然后就可以通过Special:UploadLocal来访问这个多文件上传的页面了
7.需要注意的是上传过程中如果图片与已有的图片重名会被覆盖
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

美国主机评测网站

Archiver|手机版|小黑屋|Mediawiki中文技术论坛

GMT+8, 2024-12-14 11:37 , Processed in 0.036935 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表