Provide short URL to file description page in imageinfo API
Bug: T122439 Change-Id: I0f00b986e6095bdb9b8d6af6fbc5b01995227e02
This commit is contained in:
parent
5a93e6b00b
commit
df622c4195
6 changed files with 82 additions and 1 deletions
|
|
@ -515,6 +515,11 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
}
|
||||
$vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
|
||||
$vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
|
||||
|
||||
$shortDescriptionUrl = $file->getDescriptionShortUrl();
|
||||
if ( $shortDescriptionUrl !== null ) {
|
||||
$vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $sha1 ) {
|
||||
|
|
|
|||
|
|
@ -218,7 +218,11 @@ class ForeignAPIRepo extends FileRepo {
|
|||
if ( $data && isset( $data['query']['pages'] ) ) {
|
||||
foreach ( $data['query']['pages'] as $info ) {
|
||||
if ( isset( $info['imageinfo'][0] ) ) {
|
||||
return $info['imageinfo'][0];
|
||||
$return = $info['imageinfo'][0];
|
||||
if ( isset( $info['pageid'] ) ) {
|
||||
$return['pageid'] = $info['pageid'];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,6 +354,16 @@ abstract class File implements IDBAccessObject {
|
|||
return $this->url;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get short description URL for a files based on the page ID
|
||||
*
|
||||
* @return string|null
|
||||
* @since 1.27
|
||||
*/
|
||||
public function getDescriptionShortUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a fully-qualified URL to the file.
|
||||
* Upload URL paths _may or may not_ be fully qualified, so
|
||||
|
|
|
|||
|
|
@ -218,6 +218,25 @@ class ForeignAPIFile extends File {
|
|||
return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short description URL for a file based on the foreign API response,
|
||||
* or if unavailable, the short URL is constructed from the foreign page ID.
|
||||
*
|
||||
* @return null|string
|
||||
* @since 1.27
|
||||
*/
|
||||
public function getDescriptionShortUrl() {
|
||||
if ( isset( $this->mInfo['descriptionshorturl'] ) ) {
|
||||
return $this->mInfo['descriptionshorturl'];
|
||||
} elseif ( isset( $this->mInfo['pageid'] ) ) {
|
||||
$url = $this->repo->makeUrl( array( 'curid' => $this->mInfo['pageid'] ) );
|
||||
if ( $url !== false ) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return int|null|string
|
||||
|
|
|
|||
|
|
@ -127,4 +127,28 @@ class ForeignDBFile extends LocalFile {
|
|||
// Restore remote behavior
|
||||
return File::getDescriptionText( $lang );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short description URL for a file based on the page ID.
|
||||
*
|
||||
* @return string
|
||||
* @throws DBUnexpectedError
|
||||
* @since 1.27
|
||||
*/
|
||||
public function getDescriptionShortUrl() {
|
||||
$dbr = $this->repo->getSlaveDB();
|
||||
$pageId = $dbr->selectField( 'page', 'page_id', array(
|
||||
'page_namespace' => NS_FILE,
|
||||
'page_title' => $this->title->getDBkey()
|
||||
) );
|
||||
|
||||
if ( $pageId !== false ) {
|
||||
$url = $this->repo->makeUrl( array( 'curid' => $pageId ) );
|
||||
if ( $url !== false ) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -757,6 +757,25 @@ class LocalFile extends File {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short description URL for a file based on the page ID.
|
||||
*
|
||||
* @return string|null
|
||||
* @throws MWException
|
||||
* @since 1.27
|
||||
*/
|
||||
public function getDescriptionShortUrl() {
|
||||
$pageId = $this->title->getArticleID();
|
||||
|
||||
if ( $pageId !== null ) {
|
||||
$url = $this->repo->makeUrl( array( 'curid' => $pageId ) );
|
||||
if ( $url !== false ) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get handler-specific metadata
|
||||
* @return string
|
||||
|
|
|
|||
Loading…
Reference in a new issue