Fixup some rc_* fields if empty for STRICT mode in RecentChange
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 2 Sep 2016 20:09:19 +0000 (13:09 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Sep 2016 22:31:34 +0000 (15:31 -0700)
Change-Id: Ie3849f5df8bc4f98d668ed024a052523357d3514

includes/changes/RecentChange.php

index df75ae3..a5d1fc5 100644 (file)
@@ -285,6 +285,17 @@ class RecentChange {
                        $this->mAttribs['rc_ip'] = '';
                }
 
+               # Strict mode fixups (not-NULL fields)
+               foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
+                       $this->mAttribs["rc_$field"] = (int)$this->mAttribs["rc_$field"];
+               }
+               # ...more fixups (NULL fields)
+               foreach ( [ 'old_len', 'new_len' ] as $field ) {
+                       $this->mAttribs["rc_$field"] = isset( $this->mAttribs["rc_$field"] )
+                               ? (int)$this->mAttribs["rc_$field"]
+                               : null;
+               }
+
                # If our database is strict about IP addresses, use NULL instead of an empty string
                if ( $dbw->strictIPs() && $this->mAttribs['rc_ip'] == '' ) {
                        unset( $this->mAttribs['rc_ip'] );
@@ -776,7 +787,7 @@ class RecentChange {
                        'rc_comment' => $logComment,
                        'rc_this_oldid' => $revId,
                        'rc_last_oldid' => 0,
-                       'rc_bot' => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
+                       'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0,
                        'rc_ip' => self::checkIPAddress( $ip ),
                        'rc_patrolled' => $markPatrolled ? 1 : 0,
                        'rc_new' => 0, # obsolete