Mediawiki php: 如何获取上传文件的用户名?
Mediawiki php: how to get the name of user who uploaded a file?
我正在更新一个 MediaWiki 扩展,它显示一个类别 (CategoryGallery) 中的所有图像。
我想显示上传图片的用户名,然后可能按用户过滤。
部分代码是这样的:
// Capitalize the first letter in the category argument, convert spaces to _
$params['cat'] = str_replace ( ' ', '_', ucfirst( $params['cat'] ) );
// Retrieve category members from database
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'categorylinks', 'cl_from',
array ('cl_to' => $params['cat'],
'cl_type' => 'file'));
$ids = array();
foreach ( $res as $row ) {
$ids[] = $row->cl_from;
}
// Create the gallery
$titles = Title::newFromIDs ( $ids );
$text = '';
foreach ( $titles as $title ) {
$titlePrefixedDBKey = $title->getPrefixedDBKey();
$text .= $titlePrefixedDBKey;
$text .= "|**Username**:\n";
}
$output = $parser->renderImageGallery( $text, $params )
如何检索上传照片的用户的姓名以在图片库中显示它(我在其中放置 用户名)?
您的 $title
变量是 Title
object。您应该能够使用它来获取最新修订版的作者:
$currentRevID = $title->getLatestRevID();
$revAuthors = $title->getAuthorsBetween($currentRevID, $currentRevID, 1, 'include_both'); //1=limit
$authorName = $revAuthors[0];
这使用了 return 作者在两次修订之间的函数,但我们只是将当前修订作为最小和最大修订传递。
请注意,编辑图片标题算作修订,因此此代码可以 return 未上传文件的用户的姓名。发生这种情况的可能性可能取决于您的 wiki 的使用方式。
我正在更新一个 MediaWiki 扩展,它显示一个类别 (CategoryGallery) 中的所有图像。
我想显示上传图片的用户名,然后可能按用户过滤。
部分代码是这样的:
// Capitalize the first letter in the category argument, convert spaces to _
$params['cat'] = str_replace ( ' ', '_', ucfirst( $params['cat'] ) );
// Retrieve category members from database
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'categorylinks', 'cl_from',
array ('cl_to' => $params['cat'],
'cl_type' => 'file'));
$ids = array();
foreach ( $res as $row ) {
$ids[] = $row->cl_from;
}
// Create the gallery
$titles = Title::newFromIDs ( $ids );
$text = '';
foreach ( $titles as $title ) {
$titlePrefixedDBKey = $title->getPrefixedDBKey();
$text .= $titlePrefixedDBKey;
$text .= "|**Username**:\n";
}
$output = $parser->renderImageGallery( $text, $params )
如何检索上传照片的用户的姓名以在图片库中显示它(我在其中放置 用户名)?
您的 $title
变量是 Title
object。您应该能够使用它来获取最新修订版的作者:
$currentRevID = $title->getLatestRevID();
$revAuthors = $title->getAuthorsBetween($currentRevID, $currentRevID, 1, 'include_both'); //1=limit
$authorName = $revAuthors[0];
这使用了 return 作者在两次修订之间的函数,但我们只是将当前修订作为最小和最大修订传递。
请注意,编辑图片标题算作修订,因此此代码可以 return 未上传文件的用户的姓名。发生这种情况的可能性可能取决于您的 wiki 的使用方式。