Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -30,7 +30,8 @@ |
31 | 31 | // Optional settings |
32 | 32 | $this->initialCapital = true; // by default |
33 | 33 | foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', |
34 | | - 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 'descriptionCacheExpiry' ) as $var ) |
| 34 | + 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', |
| 35 | + 'descriptionCacheExpiry', 'apiThumbCacheExpiry', 'apiThumbCacheDir' ) as $var ) |
35 | 36 | { |
36 | 37 | if ( isset( $info[$var] ) ) { |
37 | 38 | $this->$var = $info[$var]; |
Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | 'prop' => 'imageinfo' ) ) ); |
75 | 75 | |
76 | 76 | if( !isset( $this->mQueryCache[$url] ) ) { |
77 | | - $key = wfMemcKey( 'ForeignAPIRepo', $url ); |
| 77 | + $key = wfMemcKey( 'ForeignAPIRepo', 'Metadata', $url ); |
78 | 78 | $data = $wgMemc->get( $key ); |
79 | 79 | if( !$data ) { |
80 | 80 | $data = Http::get( $url ); |
— | — | @@ -102,9 +102,36 @@ |
103 | 103 | 'iiurlwidth' => $width, |
104 | 104 | 'iiurlheight' => $height ) ); |
105 | 105 | if( $info ) { |
| 106 | + wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" ); |
106 | 107 | return $info['thumburl']; |
107 | 108 | } else { |
108 | 109 | return false; |
109 | 110 | } |
110 | 111 | } |
| 112 | + |
| 113 | + function getThumbUrlFromCache( $name, $width, $height ) { |
| 114 | + global $wgMemc, $wgUploadPath, $wgServer, $wgUploadDirectory; |
| 115 | +; |
| 116 | + |
| 117 | + $key = wfMemcKey( 'ForeignAPIRepo', 'ThumbUrl', $name ); |
| 118 | + if ( $thumbUrl = $wgMemc->get($key) ) { |
| 119 | + wfDebug("Got thumb from local cache. $thumbUrl \n"); |
| 120 | + return $thumbUrl; |
| 121 | + } |
| 122 | + else { |
| 123 | + $foreignUrl = $this->getThumbUrl( $name, $width, $height ); |
| 124 | + $path = $this->apiThumbCacheDir . '/' . $this->name . '/' . |
| 125 | + $name . '/'; |
| 126 | + if ( !is_dir($wgUploadDirectory . '/' . $path) ) { |
| 127 | + wfMkdirParents($wgUploadDirectory . '/' . $path); |
| 128 | + } |
| 129 | + $localUrl = $wgServer . $wgUploadPath . '/' . $path . $width . 'px-' . $name; |
| 130 | + $thumb = Http::get( $foreignUrl ); |
| 131 | + # FIXME: Delete old thumbs that aren't being used. Maintenance script? |
| 132 | + file_put_contents($wgUploadDirectory . '/' . $path . $width . 'px-' . $name, $thumb ); |
| 133 | + $wgMemc->set( $key, $localUrl, $this->apiThumbCacheExpiry ); |
| 134 | + wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" ); |
| 135 | + return $localUrl; |
| 136 | + } |
| 137 | + } |
111 | 138 | } |
Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php |
— | — | @@ -31,12 +31,18 @@ |
32 | 32 | } |
33 | 33 | |
34 | 34 | function transform( $params, $flags = 0 ) { |
35 | | - $thumbUrl = $this->repo->getThumbUrl( |
36 | | - $this->getName(), |
37 | | - isset( $params['width'] ) ? $params['width'] : -1, |
38 | | - isset( $params['height'] ) ? $params['height'] : -1 ); |
| 35 | + if ( $this->repo->apiThumbCacheExpiry > 0 ) { |
| 36 | + $thumbUrl = $this->repo->getThumbUrlFromCache( |
| 37 | + $this->getName(), |
| 38 | + isset( $params['width'] ) ? $params['width'] : -1, |
| 39 | + isset( $params['height'] ) ? $params['height'] : -1 ); |
| 40 | + } else { |
| 41 | + $thumbUrl = $this->repo->getThumbUrl( |
| 42 | + $this->getName(), |
| 43 | + isset( $params['width'] ) ? $params['width'] : -1, |
| 44 | + isset( $params['height'] ) ? $params['height'] : -1 ); |
| 45 | + } |
39 | 46 | if( $thumbUrl ) { |
40 | | - wfDebug( __METHOD__ . " got remote thumb $thumbUrl\n" ); |
41 | 47 | return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );; |
42 | 48 | } |
43 | 49 | return false; |