}
$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 ) {
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;
}
}
}
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
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
// 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;
+ }
+
}
}
}
+ /**
+ * 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