jenkins-bot has submitted this change and it was merged.
Change subject: Provide short URL to file description page in imageinfo API
......................................................................
Provide short URL to file description page in imageinfo API
Bug: T122439
Change-Id: I0f00b986e6095bdb9b8d6af6fbc5b01995227e02
---
M includes/api/ApiQueryImageInfo.php
M includes/filerepo/ForeignAPIRepo.php
M includes/filerepo/file/File.php
M includes/filerepo/file/ForeignAPIFile.php
M includes/filerepo/file/ForeignDBFile.php
M includes/filerepo/file/LocalFile.php
6 files changed, 82 insertions(+), 1 deletion(-)
Approvals:
Unicornisaurous: Looks good to me, but someone else must approve
Gergő Tisza: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/api/ApiQueryImageInfo.php
b/includes/api/ApiQueryImageInfo.php
index 8dbd812..267cc6d 100644
--- a/includes/api/ApiQueryImageInfo.php
+++ b/includes/api/ApiQueryImageInfo.php
@@ -515,6 +515,11 @@
}
$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 ) {
diff --git a/includes/filerepo/ForeignAPIRepo.php
b/includes/filerepo/ForeignAPIRepo.php
index debdeb5..a8d37a1 100644
--- a/includes/filerepo/ForeignAPIRepo.php
+++ b/includes/filerepo/ForeignAPIRepo.php
@@ -218,7 +218,11 @@
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;
}
}
}
diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php
index 72f12d1..8a3900e 100644
--- a/includes/filerepo/file/File.php
+++ b/includes/filerepo/file/File.php
@@ -354,6 +354,16 @@
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
diff --git a/includes/filerepo/file/ForeignAPIFile.php
b/includes/filerepo/file/ForeignAPIFile.php
index 26ea38b..43cb5a5 100644
--- a/includes/filerepo/file/ForeignAPIFile.php
+++ b/includes/filerepo/file/ForeignAPIFile.php
@@ -219,6 +219,25 @@
}
/**
+ * 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
*/
diff --git a/includes/filerepo/file/ForeignDBFile.php
b/includes/filerepo/file/ForeignDBFile.php
index 561ead7..611ae10 100644
--- a/includes/filerepo/file/ForeignDBFile.php
+++ b/includes/filerepo/file/ForeignDBFile.php
@@ -127,4 +127,28 @@
// 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;
+ }
+
}
diff --git a/includes/filerepo/file/LocalFile.php
b/includes/filerepo/file/LocalFile.php
index b7d6f98..9e214f6 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -758,6 +758,25 @@
}
/**
+ * 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
*/
--
To view, visit https://gerrit.wikimedia.org/r/262415
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0f00b986e6095bdb9b8d6af6fbc5b01995227e02
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Victorbarbu <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: Unicornisaurous <[email protected]>
Gerrit-Reviewer: Victorbarbu <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits