Mediawiki php: how to get the name of the user who uploaded the file?

I am updating the MediaWiki extension, which displays all the images in a category ( CategoryGallery ).

I would like to show the name of the user who uploaded the image, and then possibly to filter by user.

Part of the code looks like this:

// 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 )

How can I get the name of the user who uploaded the photo to display it in the image gallery (where I posted the Username )?

+4
source share
1 answer

$title Title object. , :

$currentRevID = $title->getLatestRevID();
$revAuthors = $title->getAuthorsBetween($currentRevID, $currentRevID, 1, 'include_both'); //1=limit
$authorName = $revAuthors[0];

, , .

, , , . , , , , .

0

Source: https://habr.com/ru/post/1666668/


All Articles