aboutsummaryrefslogtreecommitdiffstats
path: root/includes/upload
diff options
context:
space:
mode:
authorGiuseppe Lavagetto <glavagetto@wikimedia.org>2023-12-13 08:25:49 +0100
committerGiuseppe Lavagetto <glavagetto@wikimedia.org>2024-02-28 16:15:39 +0100
commit8039e062c2428dfcf22325627a1ee9a9d48883cf (patch)
treeb5c3fcedf9565b30cf61ad74e9b616e07c6a4850 /includes/upload
parent61ed857f9ed622ec0bf3cda287d34e74734e4788 (diff)
downloadmediawikicore-8039e062c2428dfcf22325627a1ee9a9d48883cf.tar.gz
mediawikicore-8039e062c2428dfcf22325627a1ee9a9d48883cf.zip
Add getCacheKey static method to UploadFromUrl
This will be useful in making the upload async and allow us to retrieve the status of an upload remotely. Change-Id: I7279185b3c5ece5f4177c0550ca0852810c8f052
Diffstat (limited to 'includes/upload')
-rw-r--r--includes/upload/UploadFromUrl.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/includes/upload/UploadFromUrl.php b/includes/upload/UploadFromUrl.php
index c5eaf8f820f3..8753913e331e 100644
--- a/includes/upload/UploadFromUrl.php
+++ b/includes/upload/UploadFromUrl.php
@@ -117,6 +117,26 @@ class UploadFromUrl extends UploadBase {
}
/**
+ * Provides a caching key for an upload from url set of parameters
+ * Used to set the status of an async job in UploadFromUrlJob
+ * and retreive it in frontend clients like ApiUpload. Will return the
+ * empty string if not all parameters are present.
+ *
+ * @param array $params
+ * @return string
+ */
+ public static function getCacheKey( $params ) {
+ if ( !isset( $params['filename'] ) || !isset( $params['url'] ) ) {
+ return "";
+ } else {
+ // We use sha1 here to ensure we have a fixed-length string of printable
+ // characters. There is no cryptography involved, so we just need a
+ // relatively fast function.
+ return sha1( sprintf( "%s|||%s", $params['filename'], $params['url'] ) );
+ }
+ }
+
+ /**
* @return string[]
*/
private static function getAllowedHosts(): array {