r51815 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51814‎ | r51815 | r51816 >
Date:06:31, 13 June 2009
Author:freakolowsky
Status:ok (Comments)
Tags:
Comment:
Added bitwise operations to DatabaseBase and overloaded in DatabaseOracle.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDeletedContributions.php (modified) (history)
  • /trunk/phase3/maintenance/ora/tables.sql (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/ora/tables.sql
@@ -638,3 +638,11 @@
639639 RETURN (x + y - BITAND(x, y));
640640 END;
641641 /*$mw$*/
 642+
 643+/*$mw$*/
 644+CREATE OR REPLACE FUNCTION BITNOT (x IN NUMBER) RETURN NUMBER AS
 645+BEGIN
 646+ RETURN (4294967295 - x);
 647+END;
 648+/*$mw$*/
 649+
Index: trunk/phase3/includes/Article.php
@@ -697,13 +697,13 @@
698698 $user = $this->getUser();
699699 $pageId = $this->getId();
700700
701 - $hideBit = Revision::DELETED_USER; // username hidden?
 701+ $deletedBit = $dbr->bitAnd('rev_deleted', Revision::DELETED_USER); // username hidden?
702702
703703 $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp
704704 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
705705 WHERE rev_page = $pageId
706706 AND rev_user != $user
707 - AND rev_deleted & $hideBit = 0
 707+ AND $deletedBit = 0
708708 GROUP BY rev_user, rev_user_text, user_real_name
709709 ORDER BY timestamp DESC";
710710
@@ -2213,7 +2213,7 @@
22142214 // Find out if there was only one contributor
22152215 // Only scan the last 20 revisions
22162216 $res = $dbw->select( 'revision', 'rev_user_text',
2217 - array( 'rev_page' => $this->getID(), 'rev_deleted & '.Revision::DELETED_USER.'=0' ),
 2217+ array( 'rev_page' => $this->getID(), $dbw->bitAnd('rev_deleted', Revision::DELETED_USER) . ' = 0' ),
22182218 __METHOD__,
22192219 array( 'LIMIT' => 20 )
22202220 );
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -1001,6 +1001,7 @@
10021002 return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
10031003 }
10041004
 1005+ /* redundand ... will remove after confirming bitwise operations functionality
10051006 public function makeList( $a, $mode = LIST_COMMA ) {
10061007 if ( !is_array( $a ) ) {
10071008 throw new DBUnexpectedError( $this, 'DatabaseOracle::makeList called with incorrect parameters' );
@@ -1032,7 +1033,21 @@
10331034
10341035 return parent::makeList($a2, $mode);
10351036 }
 1037+ */
10361038
 1039+ function bitNot($field) {
 1040+ //expecting bit-fields smaller than 4bytes
 1041+ return 'BITNOT('.$bitField.')';
 1042+ }
 1043+
 1044+ function bitAnd($fieldLeft, $fieldRight) {
 1045+ return 'BITAND('$fieldLeft.', '.$fieldRight.')';
 1046+ }
 1047+
 1048+ function bitOr($fieldLeft, $fieldRight) {
 1049+ return 'BITOR('$fieldLeft.', '.$fieldRight.')';
 1050+ }
 1051+
10371052 public function setTimeout( $timeout ) {
10381053 // @todo fixme no-op
10391054 }
Index: trunk/phase3/includes/db/Database.php
@@ -1441,6 +1441,22 @@
14421442 }
14431443
14441444 /**
 1445+ * Bitwise operations
 1446+ */
 1447+
 1448+ function bitNot($field) {
 1449+ return '~'.$bitField;
 1450+ }
 1451+
 1452+ function bitAnd($fieldLeft, $fieldRight) {
 1453+ return $fieldLeft.'&'.$fieldRight;
 1454+ }
 1455+
 1456+ function bitOr($fieldLeft, $fieldRight) {
 1457+ return $fieldLeft.'|'.$fieldRight;
 1458+ }
 1459+
 1460+ /**
14451461 * Change the current database
14461462 */
14471463 function selectDB( $db ) {
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -1411,7 +1411,7 @@
14121412 array( 'oi_archive_name' ),
14131413 array( 'oi_name' => $this->file->getName(),
14141414 'oi_archive_name IN (' . $dbw->makeList( array_keys($oldRels) ) . ')',
1415 - 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE ),
 1415+ $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
14161416 __METHOD__ );
14171417 while( $row = $dbw->fetchObject( $res ) ) {
14181418 $privateFiles[$row->oi_archive_name] = 1;
Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -50,7 +50,7 @@
5151 $inuse = $dbw->selectField( 'oldimage', '1',
5252 array( 'oi_sha1' => $sha1,
5353 "oi_archive_name LIKE '%.{$ext}'",
54 - 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
 54+ $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
5555 __METHOD__, array( 'FOR UPDATE' ) );
5656 }
5757 if ( !$inuse ) {
Index: trunk/phase3/includes/Export.php
@@ -155,7 +155,7 @@
156156 wfProfileIn( $fname );
157157 $this->author_list = "<contributors>";
158158 //rev_deleted
159 - $nothidden = '(rev_deleted & '.Revision::DELETED_USER.') = 0';
 159+ $nothidden = '('.$this->db->bitAnd('rev_deleted', Revision::DELETED_USER) . ') = 0';
160160
161161 $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
162162 WHERE page_id=rev_page AND $nothidden AND " . $cond ;
Index: trunk/phase3/includes/LogEventsList.php
@@ -681,7 +681,7 @@
682682 $this->mConds['log_user'] = $userid;
683683 // Paranoia: avoid brute force searches (bug 17342)
684684 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
685 - $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
 685+ $this->mConds[] = $this->mDb->bitAnd('log_deleted', LogPage::DELETED_USER) . ' = 0';
686686 }
687687 $this->user = $usertitle->getText();
688688 }
@@ -725,7 +725,7 @@
726726 }
727727 // Paranoia: avoid brute force searches (bug 17342)
728728 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
729 - $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
 729+ $this->mConds[] = $this->mDb->bitAnd('log_deleted', LogPage::DELETED_ACTION) . ' = 0';
730730 }
731731 }
732732
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -120,10 +120,10 @@
121121
122122 // Paranoia: avoid brute force searches (bug 17342)
123123 if (!is_null($title)) {
124 - $this->addWhere('log_deleted & ' . LogPage::DELETED_ACTION . ' = 0');
 124+ $this->addWhere($db->bitAnd('log_deleted', LogPage::DELETED_ACTION) . ' = 0');
125125 }
126126 if (!is_null($user)) {
127 - $this->addWhere('log_deleted & ' . LogPage::DELETED_USER . ' = 0');
 127+ $this->addWhere($db->bitAnd('log_deleted', LogPage::DELETED_USER) . ' = 0');
128128 }
129129
130130 $count = 0;
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -120,6 +120,7 @@
121121 }
122122 }
123123
 124+ $db = $this->getDB();
124125 $this->addTables('revision');
125126 $this->addFields(Revision::selectFields());
126127 $this->addTables('page');
@@ -219,11 +220,11 @@
220221 $this->addWhereFld('rev_user_text', $params['user']);
221222 } elseif (!is_null($params['excludeuser'])) {
222223 $this->addWhere('rev_user_text != ' .
223 - $this->getDB()->addQuotes($params['excludeuser']));
 224+ $db->addQuotes($params['excludeuser']));
224225 }
225226 if(!is_null($params['user']) || !is_null($params['excludeuser'])) {
226227 // Paranoia: avoid brute force searches (bug 17342)
227 - $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
 228+ $this->addWhere($db->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0');
228229 }
229230 }
230231 elseif ($revCount > 0) {
@@ -283,7 +284,6 @@
284285 $count = 0;
285286 $res = $this->select(__METHOD__);
286287
287 - $db = $this->getDB();
288288 while ($row = $db->fetchObject($res)) {
289289
290290 if (++ $count > $limit) {
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -162,7 +162,7 @@
163163 }
164164
165165 if(!$wgUser->isAllowed('hideuser'))
166 - $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
 166+ $this->addWhere($this->getDB()->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0');
167167 // We only want pages by the specified users.
168168 if($this->prefixMode)
169169 $this->addWhere("rev_user_text LIKE '" . $this->getDB()->escapeLike($this->userprefix) . "%'");
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -411,7 +411,7 @@
412412 $conds = array_merge( $userCond, $this->getNamespaceCond() );
413413 // Paranoia: avoid brute force searches (bug 17342)
414414 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
415 - $conds[] = 'rev_deleted & ' . Revision::DELETED_USER . ' = 0';
 415+ $conds[] = $this->mDb->bitAnd('rev_deleted', Revision::DELETED_USER) . ' = 0';
416416 }
417417 $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
418418
Index: trunk/phase3/includes/specials/SpecialDeletedContributions.php
@@ -31,7 +31,7 @@
3232 $conds = array_merge( $userCond, $this->getNamespaceCond() );
3333 // Paranoia: avoid brute force searches (bug 17792)
3434 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
35 - $conds[] = 'ar_deleted & ' . Revision::DELETED_USER . ' = 0';
 35+ $conds[] = $this->mDb->bitAnd('ar_deleted', Revision::DELETED_USER) . ' = 0';
3636 }
3737 return array(
3838 'tables' => array( 'archive' ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r51856Use parentheses for bit* to be on the safe side...simetrical20:13, 14 June 2009

Comments

#Comment by OverlordQ (talk | contribs)   06:40, 13 June 2009

FIXME: Parse error: syntax error, unexpected T_VARIABLE in includes/db/DatabaseOracle.php on line 1044

Forgot a . in the concatenation: http://oq.pastebin.com/m7335c658


#Comment by OverlordQ (talk | contribs)   06:41, 13 June 2009

Status & tagging log