Jump to content

手册:钩子/UploadComplete

From mediawiki.org
This page is a translated version of the page Manual:Hooks/UploadComplete and the translation is 100% complete.
UploadComplete
自version 1.6.4 版可用
当文件上传完成时调用。
定义函数:
public static function onUploadComplete( $image ) { ... }
附加钩子: extension.json中:
{
	"Hooks": {
		"UploadComplete": "MediaWiki\\Extension\\MyExtension\\Hooks::onUploadComplete"
	}
}
调用自: 文件: upload/UploadBase.php
介面: UploadCompleteHook.php

更多有关附加钩子的信息,请参见Manual:Hooks
有关使用此钩子的扩展示例,请参见Category:UploadComplete extensions/zh

详情

  • $image: 保存的文件(对象) UploadForm对象(从1.16.0版本开始?UploadBase)
  • 返回值: 如果其他钩子应被评估则为真。 如果评估应停止则为假。 如果没有提供返回值,会发生错误。

示例方法

如果您想知道,来自对象的上传使用哪个方法,参阅includes/special/SpecialUpload.php

一些例子:

// 旧版本(?直到1.16?)
$image->mLocalFile; // LocalFile Object
$image->mLocalFile->fileExists; // 1 or 0
$image->mLocalFile->media_type; // examples: "AUDIO", "VIDEO", ...
$image->mLocalFile->mime; // example: audio/mp3
$image->mLocalFile->major_mime; // e.g. audio
$image->mLocalFile->minor_mime; // e.g. mp3
$image->mLocalFile->size; //in bytes, e.g. 2412586
$image->mLocalFile->user; // int userId 
$image->mLocalFile->user_text; // the username
$image->mLocalFile->description;
$image->mLocalFile->url; // gives the relative url for direct access of the uploaded media
$image->mLocalFile->getTitle(); // gives a title object for the current media

// 新MW版本(从?开始)
$image->getLocalFile(); // LocalFile Object
$image->getLocalFile()->fileExists; // 1 or 0
$image->getLocalFile()->media_type; // examples: "AUDIO", "VIDEO", ...
$image->getLocalFile()->mime; // example: audio/mp3
$image->getLocalFile()->major_mime; // e.g. audio
$image->getLocalFile()->minor_mime; // e.g. mp3
$image->getLocalFile()->size; //in bytes, e.g. 2412586
$image->getLocalFile()->user; // int userId
$image->getLocalFile()->user_text; // the username
$image->getLocalFile()->description;
$image->getLocalFile()->url; // gives the relative url for direct access of the uploaded media
$image->getLocalFile()->getTitle(); // gives a title object for the current media


/**
  * Do existence checks on a file and produce a warning
  * This check is static and can be done pre-upload via AJAX
  * Returns an HTML fragment consisting of one or more LI elements if there is a warning
  * Returns an empty string if there is no warning
  */
static function getExistsWarning( $file );

 /**
  * Split a file into a base name and all dot-delimited 'extensions'
  * on the end. Some web server configurations will fall back to
  * earlier pseudo-'extensions' to determine type and execute
  * scripts, so the blacklist needs to check them all.
  *
  * @return array
  */
function splitExtensions( $filename );