Added bitwise operations to DatabaseBase and overloaded in DatabaseOracle.
authorJure Kajzer <freakolowsky@users.mediawiki.org>
Sat, 13 Jun 2009 06:31:38 +0000 (06:31 +0000)
committerJure Kajzer <freakolowsky@users.mediawiki.org>
Sat, 13 Jun 2009 06:31:38 +0000 (06:31 +0000)
13 files changed:
includes/Article.php
includes/Export.php
includes/LogEventsList.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQueryUserContributions.php
includes/db/Database.php
includes/db/DatabaseOracle.php
includes/filerepo/LocalFile.php
includes/filerepo/LocalRepo.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
maintenance/ora/tables.sql

index a2be947..9b626b6 100644 (file)
@@ -697,13 +697,13 @@ class Article {
                $user = $this->getUser();
                $pageId = $this->getId();
 
-               $hideBit = Revision::DELETED_USER; // username hidden?
+               $deletedBit = $dbr->bitAnd('rev_deleted', Revision::DELETED_USER); // username hidden?
 
                $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp
                        FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
                        WHERE rev_page = $pageId
                        AND rev_user != $user
-                       AND rev_deleted & $hideBit = 0
+                       AND $deletedBit = 0
                        GROUP BY rev_user, rev_user_text, user_real_name
                        ORDER BY timestamp DESC";
 
@@ -2213,7 +2213,7 @@ class Article {
                // Find out if there was only one contributor
                // Only scan the last 20 revisions
                $res = $dbw->select( 'revision', 'rev_user_text',
-                       array( 'rev_page' => $this->getID(), 'rev_deleted & '.Revision::DELETED_USER.'=0' ),
+                       array( 'rev_page' => $this->getID(), $dbw->bitAnd('rev_deleted', Revision::DELETED_USER) . ' = 0' ),
                        __METHOD__,
                        array( 'LIMIT' => 20 )
                );
index a991bcb..56d555e 100644 (file)
@@ -155,7 +155,7 @@ class WikiExporter {
                wfProfileIn( $fname );
                $this->author_list = "<contributors>";
                //rev_deleted
-               $nothidden = '(rev_deleted & '.Revision::DELETED_USER.') = 0';
+               $nothidden = '('.$this->db->bitAnd('rev_deleted', Revision::DELETED_USER) . ') = 0';
 
                $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision} 
                WHERE page_id=rev_page AND $nothidden AND " . $cond ;
index bca5ef3..e89e427 100644 (file)
@@ -681,7 +681,7 @@ class LogPager extends ReverseChronologicalPager {
                        $this->mConds['log_user'] = $userid;
                        // Paranoia: avoid brute force searches (bug 17342)
                        if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
-                               $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
+                               $this->mConds[] = $this->mDb->bitAnd('log_deleted', LogPage::DELETED_USER) . ' = 0';
                        }
                        $this->user = $usertitle->getText();
                }
@@ -725,7 +725,7 @@ class LogPager extends ReverseChronologicalPager {
                }
                // Paranoia: avoid brute force searches (bug 17342)
                if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
-                       $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
+                       $this->mConds[] = $this->mDb->bitAnd('log_deleted', LogPage::DELETED_ACTION) . ' = 0';
                }
        }
 
index 893e228..04fc366 100644 (file)
@@ -120,10 +120,10 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
                // Paranoia: avoid brute force searches (bug 17342)
                if (!is_null($title)) {
-                       $this->addWhere('log_deleted & ' . LogPage::DELETED_ACTION . ' = 0');
+                       $this->addWhere($db->bitAnd('log_deleted', LogPage::DELETED_ACTION) . ' = 0');
                }
                if (!is_null($user)) {
-                       $this->addWhere('log_deleted & ' . LogPage::DELETED_USER . ' = 0');
+                       $this->addWhere($db->bitAnd('log_deleted', LogPage::DELETED_USER) . ' = 0');
                }
 
                $count = 0;
index 54af269..7e4f71f 100644 (file)
@@ -120,6 +120,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                        }
                }
 
+               $db = $this->getDB();
                $this->addTables('revision');
                $this->addFields(Revision::selectFields());
                $this->addTables('page');
@@ -219,11 +220,11 @@ class ApiQueryRevisions extends ApiQueryBase {
                                $this->addWhereFld('rev_user_text', $params['user']);
                        } elseif (!is_null($params['excludeuser'])) {
                                $this->addWhere('rev_user_text != ' .
-                                       $this->getDB()->addQuotes($params['excludeuser']));
+                                       $db->addQuotes($params['excludeuser']));
                        }
                        if(!is_null($params['user']) || !is_null($params['excludeuser'])) {
                                // Paranoia: avoid brute force searches (bug 17342)
-                               $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
+                               $this->addWhere($db->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0');
                        }
                }
                elseif ($revCount > 0) {
@@ -283,7 +284,6 @@ class ApiQueryRevisions extends ApiQueryBase {
                $count = 0;
                $res = $this->select(__METHOD__);
 
-               $db = $this->getDB();
                while ($row = $db->fetchObject($res)) {
 
                        if (++ $count > $limit) {
index 469a1b3..9d932c4 100644 (file)
@@ -162,7 +162,7 @@ class ApiQueryContributions extends ApiQueryBase {
                }
 
                if(!$wgUser->isAllowed('hideuser'))
-                       $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
+                       $this->addWhere($this->getDB()->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0');
                // We only want pages by the specified users.
                if($this->prefixMode)
                        $this->addWhere("rev_user_text LIKE '" . $this->getDB()->escapeLike($this->userprefix) . "%'");
index 57e2f7a..7bb5223 100644 (file)
@@ -1440,6 +1440,22 @@ abstract class DatabaseBase {
                return $list;
        }
 
+       /**
+        * Bitwise operations
+        */
+
+       function bitNot($field) {
+               return '~'.$bitField;
+       }
+
+       function bitAnd($fieldLeft, $fieldRight) {
+               return $fieldLeft.'&'.$fieldRight;
+       }
+
+       function bitOr($fieldLeft, $fieldRight) {
+               return $fieldLeft.'|'.$fieldRight;
+       }
+
        /**
         * Change the current database
         */
index fbfcbee..657d29d 100644 (file)
@@ -1001,6 +1001,7 @@ class DatabaseOracle extends DatabaseBase {
                return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
        }
 
+       /* redundand ... will remove after confirming bitwise operations functionality
        public function makeList( $a, $mode = LIST_COMMA ) {
                if ( !is_array( $a ) ) {
                        throw new DBUnexpectedError( $this, 'DatabaseOracle::makeList called with incorrect parameters' );
@@ -1032,6 +1033,20 @@ class DatabaseOracle extends DatabaseBase {
 
                return parent::makeList($a2, $mode);
        }
+       */
+
+       function bitNot($field) {
+               //expecting bit-fields smaller than 4bytes
+               return 'BITNOT('.$bitField.')';
+       }
+
+       function bitAnd($fieldLeft, $fieldRight) {
+               return 'BITAND('$fieldLeft.', '.$fieldRight.')';
+       }
+
+       function bitOr($fieldLeft, $fieldRight) {
+               return 'BITOR('$fieldLeft.', '.$fieldRight.')';
+       }
 
        public function setTimeout( $timeout ) {
                // @todo fixme no-op
index d87e7bb..4fe2c71 100644 (file)
@@ -1411,7 +1411,7 @@ class LocalFileDeleteBatch {
                                array( 'oi_archive_name' ),
                                array( 'oi_name' => $this->file->getName(),
                                        'oi_archive_name IN (' . $dbw->makeList( array_keys($oldRels) ) . ')',
-                                       'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE ),
+                                       $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
                                __METHOD__ );
                        while( $row = $dbw->fetchObject( $res ) ) {
                                $privateFiles[$row->oi_archive_name] = 1;
index 2b9fcaf..1150964 100644 (file)
@@ -50,7 +50,7 @@ class LocalRepo extends FSRepo {
                                $inuse = $dbw->selectField( 'oldimage', '1',
                                        array( 'oi_sha1' => $sha1,
                                                "oi_archive_name LIKE '%.{$ext}'",
-                                               'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
+                                               $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
                                        __METHOD__, array( 'FOR UPDATE' ) );
                        }
                        if ( !$inuse ) {
index 90c313e..63ae3c8 100644 (file)
@@ -411,7 +411,7 @@ class ContribsPager extends ReverseChronologicalPager {
                $conds = array_merge( $userCond, $this->getNamespaceCond() );
                // Paranoia: avoid brute force searches (bug 17342)
                if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
-                       $conds[] = 'rev_deleted & ' . Revision::DELETED_USER . ' = 0';
+                       $conds[] = $this->mDb->bitAnd('rev_deleted', Revision::DELETED_USER) . ' = 0';
                }
                $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
                
index 15d355c..7f25681 100644 (file)
@@ -31,7 +31,7 @@ class DeletedContribsPager extends IndexPager {
                $conds = array_merge( $userCond, $this->getNamespaceCond() );
                // Paranoia: avoid brute force searches (bug 17792)
                if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
-                       $conds[] = 'ar_deleted & ' . Revision::DELETED_USER . ' = 0';
+                       $conds[] = $this->mDb->bitAnd('ar_deleted', Revision::DELETED_USER) . ' = 0';
                }
                return array(
                        'tables' => array( 'archive' ),
index d7e6a1e..55b0072 100644 (file)
@@ -638,3 +638,11 @@ BEGIN
   RETURN (x + y - BITAND(x, y));
 END;
 /*$mw$*/
+
+/*$mw$*/
+CREATE OR REPLACE FUNCTION BITNOT (x IN NUMBER) RETURN NUMBER AS
+BEGIN
+  RETURN (4294967295 - x);
+END;
+/*$mw$*/
+