Index: trunk/extensions/AntiSpoof/SpoofUser.php |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | * @return array empty if no conflict, or array containing conflicting usernames |
50 | 50 | */ |
51 | 51 | public function getConflicts() { |
52 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 52 | + $dbr = self::getDBSlave(); |
53 | 53 | |
54 | 54 | // Join against the user table to ensure that we skip stray |
55 | 55 | // entries left after an account is renamed or otherwise munged. |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | foreach ( $items as $item ) { |
110 | 110 | $fields[] = $item->insertFields(); |
111 | 111 | } |
112 | | - $dbw = wfGetDB( DB_MASTER ); |
| 112 | + $dbw = self::getDBMaster(); |
113 | 113 | $dbw->replace( |
114 | 114 | 'spoofuser', |
115 | 115 | array( 'su_name' ), |
— | — | @@ -121,7 +121,7 @@ |
122 | 122 | * @param $oldName |
123 | 123 | */ |
124 | 124 | public function update( $oldName ) { |
125 | | - $dbw = wfGetDB( DB_MASTER ); |
| 125 | + $dbw = self::getDBMaster(); |
126 | 126 | |
127 | 127 | if( $this->record() ) { |
128 | 128 | $dbw->delete( |
— | — | @@ -131,4 +131,18 @@ |
132 | 132 | ); |
133 | 133 | } |
134 | 134 | } |
| 135 | + |
| 136 | + /** |
| 137 | + * @return DatabaseBase |
| 138 | + */ |
| 139 | + protected static function getDBSlave() { |
| 140 | + return wfGetDB( DB_SLAVE ); |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * @return DatabaseBase |
| 145 | + */ |
| 146 | + protected static function getDBMaster() { |
| 147 | + return wfGetDB( DB_MASTER ); |
| 148 | + } |
135 | 149 | } |
Index: trunk/extensions/AntiSpoof/AntiSpoofHooks.php |
— | — | @@ -22,6 +22,14 @@ |
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
| 26 | + * @param $name string Username |
| 27 | + * @return SpoofUser |
| 28 | + */ |
| 29 | + protected static function makeSpoofUser( $name ) { |
| 30 | + return new SpoofUser( $name ); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
26 | 34 | * Can be used to cancel user account creation |
27 | 35 | * |
28 | 36 | * @param $user User |
— | — | @@ -44,7 +52,7 @@ |
45 | 53 | } |
46 | 54 | |
47 | 55 | $name = $user->getName(); |
48 | | - $spoof = new SpoofUser( $name ); |
| 56 | + $spoof = self::makeSpoofUser( $name ); |
49 | 57 | if ( $spoof->isLegal() ) { |
50 | 58 | $normalized = $spoof->getNormalized(); |
51 | 59 | $conflicts = $spoof->getConflicts(); |
— | — | @@ -100,7 +108,7 @@ |
101 | 109 | * @return bool |
102 | 110 | */ |
103 | 111 | public static function asAddNewAccountHook( $user ) { |
104 | | - $spoof = new SpoofUser( $user->getName() ); |
| 112 | + $spoof = self::makeSpoofUser( $user->getName() ); |
105 | 113 | $spoof->record(); |
106 | 114 | return true; |
107 | 115 | } |
— | — | @@ -115,7 +123,7 @@ |
116 | 124 | * @return bool |
117 | 125 | */ |
118 | 126 | public static function asAddRenameUserHook( $uid, $oldName, $newName ) { |
119 | | - $spoof = new SpoofUser( $newName ); |
| 127 | + $spoof = self::makeSpoofUser( $newName ); |
120 | 128 | $spoof->update( $oldName ); |
121 | 129 | return true; |
122 | 130 | } |