Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | // Optional settings |
32 | 32 | $this->initialCapital = true; // by default |
33 | 33 | foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', |
34 | | - 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection' ) as $var ) |
| 34 | + 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 'useTransCache' ) as $var ) |
35 | 35 | { |
36 | 36 | if ( isset( $info[$var] ) ) { |
37 | 37 | $this->$var = $info[$var]; |
Index: trunk/phase3/includes/filerepo/File.php |
— | — | @@ -1067,14 +1067,54 @@ |
1068 | 1068 | } |
1069 | 1069 | $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() ); |
1070 | 1070 | if ( $renderUrl ) { |
| 1071 | + if ( $this->repo->useTransCache ) { |
| 1072 | + wfDebug("Attempting to get the description from the transwiki cache..."); |
| 1073 | + $this->purgeTransCacheEntries(); |
| 1074 | + $dbr = wfGetDB(DB_SLAVE); |
| 1075 | + $obj = $dbr->selectRow('transcache', array('tc_contents'), |
| 1076 | + array('tc_url' => $renderUrl)); |
| 1077 | + if ($obj) { |
| 1078 | + wfDebug("success!\n"); |
| 1079 | + return $obj->tc_contents; |
| 1080 | + } |
| 1081 | + wfDebug("miss\n"); |
| 1082 | + } |
1071 | 1083 | wfDebug( "Fetching shared description from $renderUrl\n" ); |
1072 | | - return Http::get( $renderUrl ); |
| 1084 | + $res = Http::get( $renderUrl ); |
| 1085 | + if ( $res && $this->repo->useTransCache ) $this->addToTransCache( $res, $renderUrl ); |
| 1086 | + return $res; |
1073 | 1087 | } else { |
1074 | 1088 | return false; |
1075 | 1089 | } |
1076 | 1090 | } |
1077 | 1091 | |
1078 | 1092 | /** |
| 1093 | + * Purge expired transcache entries |
| 1094 | + */ |
| 1095 | + function purgeTranscacheEntries() { |
| 1096 | + global $wgTranscludeCacheExpiry; |
| 1097 | + $dbw = wfGetDB( DB_MASTER ); |
| 1098 | + $table = $dbw->tableName('transcache'); |
| 1099 | + $expiry = $dbw->addQuotes(time() - $wgTranscludeCacheExpiry); |
| 1100 | + $res = $dbw->delete( $table, array("tc_time < $expiry"), __METHOD__ ); |
| 1101 | + if ($res) wfDebug("purging old transcache entries..."); |
| 1102 | + } |
| 1103 | + |
| 1104 | + /** |
| 1105 | + * Add new transcache entry |
| 1106 | + * |
| 1107 | + * @param string $text Text to add to the cache |
| 1108 | + * @param string $url Url we're caching |
| 1109 | + */ |
| 1110 | + function addToTransCache( $text, $url ) { |
| 1111 | + $dbw = wfGetDB( DB_MASTER ); |
| 1112 | + $dbw->replace('transcache', array('tc_url'), array( |
| 1113 | + 'tc_url' => $url, |
| 1114 | + 'tc_time' => time(), |
| 1115 | + 'tc_contents' => $text)); |
| 1116 | + } |
| 1117 | + |
| 1118 | + /** |
1079 | 1119 | * Get discription of file revision |
1080 | 1120 | * STUB |
1081 | 1121 | */ |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -179,6 +179,8 @@ |
180 | 180 | * Added blank special page Special:BlankPage for benchmarking, etc. |
181 | 181 | * (bug 13862) Specialpages now has a horizontal TOC if there's three or more |
182 | 182 | groups. |
| 183 | +* Foreign repo file descriptions via fetchDescription are now cached in the |
| 184 | + transcache. |
183 | 185 | |
184 | 186 | === Bug fixes in 1.13 === |
185 | 187 | |