我正在更新一个 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];
这使用了一个返回两个修订之间的作者的函数,但我们只是将当前修订作为最小和最大修订传递。
请注意,编辑图像标题算作修订,因此此代码可能会返回未上传文件的用户的姓名。发生这种情况的可能性可能取决于您的 wiki 的使用方式。
关于php - Mediawiki php : how to get the name of user who uploaded a file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41624403/