Mediawiki php:如何获取上传文件的用户名?
发布时间:2020-12-13 22:27:30 所属栏目:PHP教程 来源:网络整理
导读:我正在更新MediaWiki扩展,显示类别中的所有图像( CategoryGallery). 我想显示上传图像的用户的名字,然后可能按用户过滤. 代码的一部分是这样的: // Capitalize the first letter in the category argument,convert spaces to _$params['cat'] = str_replace
我正在更新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的使用方式. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |