Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -103,6 +103,8 @@ |
104 | 104 | |
105 | 105 | # How long to cache stable versions? (seconds) |
106 | 106 | $wgFlaggedRevsExpire = 7 * 24 * 3600; |
| 107 | +# Compress pre-processed flagged revision text? |
| 108 | +$wgFlaggedRevsCompression = false; |
107 | 109 | |
108 | 110 | # When setting up new dimensions or levels, you will need to add some |
109 | 111 | # MediaWiki messages for the UI to show properly; any sysop can do this. |
— | — | @@ -195,7 +197,7 @@ |
196 | 198 | */ |
197 | 199 | public static function expandText( $text='', $title, $id=null ) { |
198 | 200 | global $wgParser; |
199 | | - # Causes our hooks to trigger |
| 201 | + # Make our hooks to trigger |
200 | 202 | $wgParser->isStable = true; |
201 | 203 | $wgParser->includesMatched = true; |
202 | 204 | # Parse with default options |
— | — | @@ -221,8 +223,8 @@ |
222 | 224 | */ |
223 | 225 | public static function parseStableText( $title, $text, $id=NULL, $options ) { |
224 | 226 | global $wgParser; |
225 | | - |
226 | | - $wgParser->isStable = true; // Causes our hooks to trigger |
| 227 | + # Make our hooks to trigger |
| 228 | + $wgParser->isStable = true; |
227 | 229 | # Don't show section-edit links |
228 | 230 | # They can be old and misleading |
229 | 231 | $options->setEditSection(false); |
— | — | @@ -234,6 +236,49 @@ |
235 | 237 | return $parserOut; |
236 | 238 | } |
237 | 239 | |
| 240 | + /** |
| 241 | + * @param string $text |
| 242 | + * @returns string, flags |
| 243 | + * Compress pre-processed text, passed by reference |
| 244 | + */ |
| 245 | + public static function compressText( &$text ) { |
| 246 | + global $wgFlaggedRevsCompression; |
| 247 | + # Compress text if $wgFlaggedRevsCompression is set. |
| 248 | + $flags = array( 'utf-8' ); |
| 249 | + if( $wgFlaggedRevsCompression ) { |
| 250 | + if( function_exists( 'gzdeflate' ) ) { |
| 251 | + $text = gzdeflate( $text ); |
| 252 | + $flags[] = 'gzip'; |
| 253 | + } else { |
| 254 | + wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" ); |
| 255 | + } |
| 256 | + } |
| 257 | + return implode( ',', $flags ); |
| 258 | + } |
| 259 | + |
| 260 | + /** |
| 261 | + * @param string $text |
| 262 | + * @param mixed $flags, either in string or array form |
| 263 | + * @returns string |
| 264 | + * Uncompress pre-processed text, using flags |
| 265 | + */ |
| 266 | + public static function uncompressText( $text, $flags ) { |
| 267 | + global $wgFlaggedRevsCompression; |
| 268 | + |
| 269 | + if( !is_array($flags) ) { |
| 270 | + $flags = explode( ',', $flags ); |
| 271 | + } |
| 272 | + # Lets not mix up types here |
| 273 | + if( is_null($text) ) |
| 274 | + return null; |
| 275 | + |
| 276 | + if( in_array( 'gzip', $flags ) ) { |
| 277 | + # Deal with optional compression if $wgFlaggedRevsCompression is set. |
| 278 | + $text = gzinflate( $text ); |
| 279 | + } |
| 280 | + return $text; |
| 281 | + } |
| 282 | + |
238 | 283 | /** |
239 | 284 | * @param int $rev_id |
240 | 285 | * @returns string |
— | — | @@ -243,12 +288,12 @@ |
244 | 289 | $db = wfGetDB( DB_SLAVE ); |
245 | 290 | // Get the text from the flagged revisions table |
246 | 291 | $result = $db->select( array('flaggedrevs','revision'), |
247 | | - array('fr_text'), |
| 292 | + array('fr_text', 'fr_flags'), |
248 | 293 | array('fr_rev_id' => $rev_id, 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'), |
249 | 294 | __METHOD__, |
250 | 295 | array('LIMIT' => 1) ); |
251 | 296 | if( $row = $db->fetchObject($result) ) { |
252 | | - return $row->fr_text; |
| 297 | + return self::uncompressText( $row->fr_text, $row->fr_flags ); |
253 | 298 | } |
254 | 299 | |
255 | 300 | return NULL; |
— | — | @@ -323,8 +368,10 @@ |
324 | 369 | return null; |
325 | 370 | |
326 | 371 | $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'); |
327 | | - if( $getText ) |
| 372 | + if( $getText ) { |
328 | 373 | $selectColumns[] = 'fr_text'; |
| 374 | + $selectColumns[] = 'fr_flags'; |
| 375 | + } |
329 | 376 | |
330 | 377 | if( !$forUpdate ) { |
331 | 378 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -728,7 +775,8 @@ |
729 | 776 | return true; |
730 | 777 | # Parse the revision |
731 | 778 | $options = new ParserOptions; |
732 | | - $parserOutput = self::parseStableText( $linksUpdate->mTitle, $sv->fr_text, $sv->fr_rev_id, $options ); |
| 779 | + $text = self::uncompressText( $sv->fr_text, $sv->fr_flags ); |
| 780 | + $parserOutput = self::parseStableText( $linksUpdate->mTitle, $text, $sv->fr_rev_id, $options ); |
733 | 781 | # Might as well update the stable cache while we're at it |
734 | 782 | $article = new Article( $linksUpdate->mTitle ); |
735 | 783 | FlaggedRevs::updatePageCache( $article, $parserOutput ); |
— | — | @@ -1013,8 +1061,8 @@ |
1014 | 1062 | $imgset[] = array( |
1015 | 1063 | 'fi_rev_id' => $rev->getId(), |
1016 | 1064 | 'fi_name' => $dbkey, |
1017 | | - 'fi_img_timestamp' => $timestamp, |
1018 | | - 'fr_img_sha1' => $sha1 |
| 1065 | + 'fi_img_timestamp' => $time, |
| 1066 | + 'fi_img_sha1' => $sha1 |
1019 | 1067 | ); |
1020 | 1068 | } |
1021 | 1069 | } |
— | — | @@ -1036,6 +1084,8 @@ |
1037 | 1085 | $dbw->rollback(); // All versions must be specified, 0 for none |
1038 | 1086 | return false; |
1039 | 1087 | } |
| 1088 | + # Compress $fulltext, passed by reference |
| 1089 | + $textFlags = self::compressText( $fulltext ); |
1040 | 1090 | # Our review entry |
1041 | 1091 | $revset = array( |
1042 | 1092 | 'fr_rev_id' => $rev->getId(), |
— | — | @@ -1044,8 +1094,9 @@ |
1045 | 1095 | 'fr_user' => $user->getId(), |
1046 | 1096 | 'fr_timestamp' => wfTimestampNow(), |
1047 | 1097 | 'fr_comment' => '', |
| 1098 | + 'fr_quality' => $quality, |
1048 | 1099 | 'fr_text' => $fulltext, // Store expanded text for speed |
1049 | | - 'fr_quality' => $quality |
| 1100 | + 'fr_flags' => $textFlags |
1050 | 1101 | ); |
1051 | 1102 | # Update flagged revisions table |
1052 | 1103 | $dbw->replace( 'flaggedrevs', array( array('fr_rev_id','fr_namespace','fr_title') ), $revset, __METHOD__ ); |
— | — | @@ -1710,8 +1761,10 @@ |
1711 | 1762 | } |
1712 | 1763 | |
1713 | 1764 | $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'); |
1714 | | - if( $getText ) |
| 1765 | + if( $getText ) { |
1715 | 1766 | $selectColumns[] = 'fr_text'; |
| 1767 | + $selectColumns[] = 'fr_flags'; |
| 1768 | + } |
1716 | 1769 | |
1717 | 1770 | $dbw = wfGetDB( DB_MASTER ); |
1718 | 1771 | // Skip deleted revisions |
— | — | @@ -1751,8 +1804,10 @@ |
1752 | 1805 | } |
1753 | 1806 | |
1754 | 1807 | $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'); |
1755 | | - if( $getText ) |
| 1808 | + if( $getText ) { |
1756 | 1809 | $selectColumns[] = 'fr_text'; |
| 1810 | + $selectColumns[] = 'fr_flags'; |
| 1811 | + } |
1757 | 1812 | |
1758 | 1813 | $dbr = wfGetDB( DB_SLAVE ); |
1759 | 1814 | // Skip deleted revisions |
— | — | @@ -1790,8 +1845,10 @@ |
1791 | 1846 | } |
1792 | 1847 | |
1793 | 1848 | $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'); |
1794 | | - if( $getText ) |
| 1849 | + if( $getText ) { |
1795 | 1850 | $selectColumns[] = 'fr_text'; |
| 1851 | + $selectColumns[] = 'fr_flags'; |
| 1852 | + } |
1796 | 1853 | |
1797 | 1854 | $dbr = wfGetDB( DB_SLAVE ); |
1798 | 1855 | // Skip deleted revisions |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.sql |
— | — | @@ -12,11 +12,14 @@ |
13 | 13 | fr_user int(5) NOT NULL, |
14 | 14 | fr_timestamp char(14) NOT NULL, |
15 | 15 | fr_comment mediumblob NOT NULL default '', |
| 16 | + -- Store the precedence level |
| 17 | + fr_quality tinyint(1) default 0, |
16 | 18 | -- Store the text with all transclusions resolved |
17 | 19 | -- This will trade space for speed |
18 | 20 | fr_text mediumblob NOT NULL default '', |
19 | | - -- Store the precedence level |
20 | | - fr_quality tinyint(1) default 0, |
| 21 | + -- Comma-separated list of flags: |
| 22 | + -- gzip: text is compressed with PHP's gzdeflate() function. |
| 23 | + fr_flags tinyblob NOT NULL, |
21 | 24 | |
22 | 25 | PRIMARY KEY (fr_namespace,fr_title,fr_rev_id), |
23 | 26 | UNIQUE KEY (fr_rev_id), |
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php |
— | — | @@ -367,6 +367,8 @@ |
368 | 368 | $dbw->rollback(); // All versions must be specified, 0 for none |
369 | 369 | return false; |
370 | 370 | } |
| 371 | + # Compress $fulltext, passed by reference |
| 372 | + $textFlags = FlaggedRevs::compressText( $fulltext ); |
371 | 373 | // Our review entry |
372 | 374 | $revset = array( |
373 | 375 | 'fr_rev_id' => $rev->getId(), |
— | — | @@ -375,8 +377,9 @@ |
376 | 378 | 'fr_user' => $wgUser->getId(), |
377 | 379 | 'fr_timestamp' => wfTimestampNow(), |
378 | 380 | 'fr_comment' => $notes, |
| 381 | + 'fr_quality' => $quality, |
379 | 382 | 'fr_text' => $fulltext, // Store expanded text for speed |
380 | | - 'fr_quality' => $quality |
| 383 | + 'fr_flags' => $textFlags |
381 | 384 | ); |
382 | 385 | // Update flagged revisions table |
383 | 386 | $dbw->replace( 'flaggedrevs', array( array('fr_rev_id','fr_namespace','fr_title') ), $revset, __METHOD__ ); |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.pg.sql |
— | — | @@ -10,8 +10,9 @@ |
11 | 11 | fr_user int(5) INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL, |
12 | 12 | fr_timestamp TIMESTAMPTZ, |
13 | 13 | fr_comment TEXT NOT NULL DEFAULT '', |
| 14 | + fr_quality SMALLINT NOT NULL DEFAULT 0, |
14 | 15 | fr_text TEXT NOT NULL DEFAULT '', |
15 | | - fr_quality SMALLINT NOT NULL DEFAULT 0 |
| 16 | + fr_flags TEXT NOT NULL |
16 | 17 | ); |
17 | 18 | CREATE INDEX fr_namespace_title ON flaggedrevs (fr_namespace,fr_title,fr_quality,fr_rev_id); |
18 | 19 | |