r25220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25219‎ | r25220 | r25221 >
Date:00:10, 28 August 2007
Author:aaron
Status:old
Tags:
Comment:
*Add compression support on fr_text
*Fix silly typos
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.pg.sql (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.sql (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -103,6 +103,8 @@
104104
105105 # How long to cache stable versions? (seconds)
106106 $wgFlaggedRevsExpire = 7 * 24 * 3600;
 107+# Compress pre-processed flagged revision text?
 108+$wgFlaggedRevsCompression = false;
107109
108110 # When setting up new dimensions or levels, you will need to add some
109111 # MediaWiki messages for the UI to show properly; any sysop can do this.
@@ -195,7 +197,7 @@
196198 */
197199 public static function expandText( $text='', $title, $id=null ) {
198200 global $wgParser;
199 - # Causes our hooks to trigger
 201+ # Make our hooks to trigger
200202 $wgParser->isStable = true;
201203 $wgParser->includesMatched = true;
202204 # Parse with default options
@@ -221,8 +223,8 @@
222224 */
223225 public static function parseStableText( $title, $text, $id=NULL, $options ) {
224226 global $wgParser;
225 -
226 - $wgParser->isStable = true; // Causes our hooks to trigger
 227+ # Make our hooks to trigger
 228+ $wgParser->isStable = true;
227229 # Don't show section-edit links
228230 # They can be old and misleading
229231 $options->setEditSection(false);
@@ -234,6 +236,49 @@
235237 return $parserOut;
236238 }
237239
 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+
238283 /**
239284 * @param int $rev_id
240285 * @returns string
@@ -243,12 +288,12 @@
244289 $db = wfGetDB( DB_SLAVE );
245290 // Get the text from the flagged revisions table
246291 $result = $db->select( array('flaggedrevs','revision'),
247 - array('fr_text'),
 292+ array('fr_text', 'fr_flags'),
248293 array('fr_rev_id' => $rev_id, 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
249294 __METHOD__,
250295 array('LIMIT' => 1) );
251296 if( $row = $db->fetchObject($result) ) {
252 - return $row->fr_text;
 297+ return self::uncompressText( $row->fr_text, $row->fr_flags );
253298 }
254299
255300 return NULL;
@@ -323,8 +368,10 @@
324369 return null;
325370
326371 $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp');
327 - if( $getText )
 372+ if( $getText ) {
328373 $selectColumns[] = 'fr_text';
 374+ $selectColumns[] = 'fr_flags';
 375+ }
329376
330377 if( !$forUpdate ) {
331378 $dbr = wfGetDB( DB_SLAVE );
@@ -728,7 +775,8 @@
729776 return true;
730777 # Parse the revision
731778 $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 );
733781 # Might as well update the stable cache while we're at it
734782 $article = new Article( $linksUpdate->mTitle );
735783 FlaggedRevs::updatePageCache( $article, $parserOutput );
@@ -1013,8 +1061,8 @@
10141062 $imgset[] = array(
10151063 'fi_rev_id' => $rev->getId(),
10161064 'fi_name' => $dbkey,
1017 - 'fi_img_timestamp' => $timestamp,
1018 - 'fr_img_sha1' => $sha1
 1065+ 'fi_img_timestamp' => $time,
 1066+ 'fi_img_sha1' => $sha1
10191067 );
10201068 }
10211069 }
@@ -1036,6 +1084,8 @@
10371085 $dbw->rollback(); // All versions must be specified, 0 for none
10381086 return false;
10391087 }
 1088+ # Compress $fulltext, passed by reference
 1089+ $textFlags = self::compressText( $fulltext );
10401090 # Our review entry
10411091 $revset = array(
10421092 'fr_rev_id' => $rev->getId(),
@@ -1044,8 +1094,9 @@
10451095 'fr_user' => $user->getId(),
10461096 'fr_timestamp' => wfTimestampNow(),
10471097 'fr_comment' => '',
 1098+ 'fr_quality' => $quality,
10481099 'fr_text' => $fulltext, // Store expanded text for speed
1049 - 'fr_quality' => $quality
 1100+ 'fr_flags' => $textFlags
10501101 );
10511102 # Update flagged revisions table
10521103 $dbw->replace( 'flaggedrevs', array( array('fr_rev_id','fr_namespace','fr_title') ), $revset, __METHOD__ );
@@ -1710,8 +1761,10 @@
17111762 }
17121763
17131764 $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp');
1714 - if( $getText )
 1765+ if( $getText ) {
17151766 $selectColumns[] = 'fr_text';
 1767+ $selectColumns[] = 'fr_flags';
 1768+ }
17161769
17171770 $dbw = wfGetDB( DB_MASTER );
17181771 // Skip deleted revisions
@@ -1751,8 +1804,10 @@
17521805 }
17531806
17541807 $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp');
1755 - if( $getText )
 1808+ if( $getText ) {
17561809 $selectColumns[] = 'fr_text';
 1810+ $selectColumns[] = 'fr_flags';
 1811+ }
17571812
17581813 $dbr = wfGetDB( DB_SLAVE );
17591814 // Skip deleted revisions
@@ -1790,8 +1845,10 @@
17911846 }
17921847
17931848 $selectColumns = array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp');
1794 - if( $getText )
 1849+ if( $getText ) {
17951850 $selectColumns[] = 'fr_text';
 1851+ $selectColumns[] = 'fr_flags';
 1852+ }
17961853
17971854 $dbr = wfGetDB( DB_SLAVE );
17981855 // Skip deleted revisions
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.sql
@@ -12,11 +12,14 @@
1313 fr_user int(5) NOT NULL,
1414 fr_timestamp char(14) NOT NULL,
1515 fr_comment mediumblob NOT NULL default '',
 16+ -- Store the precedence level
 17+ fr_quality tinyint(1) default 0,
1618 -- Store the text with all transclusions resolved
1719 -- This will trade space for speed
1820 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,
2124
2225 PRIMARY KEY (fr_namespace,fr_title,fr_rev_id),
2326 UNIQUE KEY (fr_rev_id),
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php
@@ -367,6 +367,8 @@
368368 $dbw->rollback(); // All versions must be specified, 0 for none
369369 return false;
370370 }
 371+ # Compress $fulltext, passed by reference
 372+ $textFlags = FlaggedRevs::compressText( $fulltext );
371373 // Our review entry
372374 $revset = array(
373375 'fr_rev_id' => $rev->getId(),
@@ -375,8 +377,9 @@
376378 'fr_user' => $wgUser->getId(),
377379 'fr_timestamp' => wfTimestampNow(),
378380 'fr_comment' => $notes,
 381+ 'fr_quality' => $quality,
379382 'fr_text' => $fulltext, // Store expanded text for speed
380 - 'fr_quality' => $quality
 383+ 'fr_flags' => $textFlags
381384 );
382385 // Update flagged revisions table
383386 $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 @@
1111 fr_user int(5) INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
1212 fr_timestamp TIMESTAMPTZ,
1313 fr_comment TEXT NOT NULL DEFAULT '',
 14+ fr_quality SMALLINT NOT NULL DEFAULT 0,
1415 fr_text TEXT NOT NULL DEFAULT '',
15 - fr_quality SMALLINT NOT NULL DEFAULT 0
 16+ fr_flags TEXT NOT NULL
1617 );
1718 CREATE INDEX fr_namespace_title ON flaggedrevs (fr_namespace,fr_title,fr_quality,fr_rev_id);
1819

Status & tagging log