From: Jure Kajzer Date: Sat, 13 Jun 2009 06:31:38 +0000 (+0000) Subject: Added bitwise operations to DatabaseBase and overloaded in DatabaseOracle. X-Git-Tag: 1.31.0-rc.0~41393 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=c3fafd96f7a30de0c00ed35e1495bd18ace9fed4;p=lhc%2Fweb%2Fwiklou.git Added bitwise operations to DatabaseBase and overloaded in DatabaseOracle. --- diff --git a/includes/Article.php b/includes/Article.php index a2be947f45..9b626b6bb5 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ) ); diff --git a/includes/Export.php b/includes/Export.php index a991bcb504..56d555e210 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -155,7 +155,7 @@ class WikiExporter { wfProfileIn( $fname ); $this->author_list = ""; //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 ; diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index bca5ef3fda..e89e427255 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -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'; } } diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 893e228858..04fc366b8a 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -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; diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 54af269c0b..7e4f71f7d6 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -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) { diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 469a1b3af0..9d932c465e 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -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) . "%'"); diff --git a/includes/db/Database.php b/includes/db/Database.php index 57e2f7a16d..7bb5223584 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 */ diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index fbfcbeeb8f..657d29d85b 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -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 diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index d87e7bb626..4fe2c71408 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -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; diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 2b9fcafda6..1150964d19 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -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 ) { diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 90c313e872..63ae3c8141 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -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' ); diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 15d355c94c..7f25681db7 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -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' ), diff --git a/maintenance/ora/tables.sql b/maintenance/ora/tables.sql index d7e6a1e374..55b007222f 100644 --- a/maintenance/ora/tables.sql +++ b/maintenance/ora/tables.sql @@ -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$*/ +