Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/96528


Change subject: Make sure local URLs in image description are always absolute
......................................................................

Make sure local URLs in image description are always absolute

Not for the faint of heart.

Bug: 57187
Change-Id: Ib7a6234bf79473fc333d2eef9f7d9ce6e6565141
---
M CommonsMetadata_body.php
1 file changed, 33 insertions(+), 6 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommonsMetadata 
refs/changes/28/96528/1

diff --git a/CommonsMetadata_body.php b/CommonsMetadata_body.php
index 843fb73..40aa98e 100755
--- a/CommonsMetadata_body.php
+++ b/CommonsMetadata_body.php
@@ -79,12 +79,7 @@
                        );
                }
 
-               # Note: If this is a local file, there is no caching here.
-               # However, the results of this module have longer caching for 
local
-               # files to help compensate. For foreign files, this method is 
cached
-               # via parser cache, and possibly a second cache depending on
-               # descriptionCacheExpiry (disabled on Wikimedia).
-               $descriptionText = $file->getDescriptionText( $lang );
+               $descriptionText = self::getDescriptionText( $file, $lang );
 
                if ( $singleLang ) {
                        $data = self::getMetadata( $descriptionText, 
$lang->getCode() );
@@ -170,6 +165,38 @@
        }
 
        /**
+        * Gets the text of the file's description page.
+        * @param File $file
+        * @param Language $lang
+        * @return string
+        */
+       protected static function getDescriptionText( File $file, Language 
$lang ) {
+               # Note: If this is a local file, there is no caching here.
+               # However, the results of this module have longer caching for 
local
+               # files to help compensate. For foreign files, this method is 
cached
+               # via parser cache, and possibly a second cache depending on
+               # descriptionCacheExpiry (disabled on Wikimedia).
+
+               if ( get_class( $file ) == 'LocalFile' ) {
+                       // LocalFile gets the text in a different why, and ends 
up with different output
+                       // (specifically, relative instead of absolute URLs). 
There is no sane way to
+                       // influence this process, so we will do it the insane 
way.
+                       // See the end of Linker::getLocalURL for the gory 
details.
+                       global $wgRequest;
+                       $oldAction = $wgRequest->setVal( 'action', 'render' );
+                       $text = $file->getDescriptionText( $lang );
+                       if ( $oldAction === null ) {
+                               $wgRequest->unsetVal( 'action ');
+                       } else {
+                               $wgRequest->setVal( 'action', $oldAction );
+                       }
+               } else {
+                       $text = $file->getDescriptionText( $lang );
+               }
+               return $text;
+       }
+
+       /**
         * @param LocalFile $file
         * @return array list of category names in human-readable format
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/96528
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7a6234bf79473fc333d2eef9f7d9ce6e6565141
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommonsMetadata
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to