r106808 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106807‎ | r106808 | r106809 >
Date:16:17, 20 December 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Do some refactoring to allow easy subclassing stuffs
Modified paths:
  • /trunk/extensions/AntiSpoof/AntiSpoofHooks.php (modified) (history)
  • /trunk/extensions/AntiSpoof/SpoofUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AntiSpoof/SpoofUser.php
@@ -48,7 +48,7 @@
4949 * @return array empty if no conflict, or array containing conflicting usernames
5050 */
5151 public function getConflicts() {
52 - $dbr = wfGetDB( DB_SLAVE );
 52+ $dbr = self::getDBSlave();
5353
5454 // Join against the user table to ensure that we skip stray
5555 // entries left after an account is renamed or otherwise munged.
@@ -108,7 +108,7 @@
109109 foreach ( $items as $item ) {
110110 $fields[] = $item->insertFields();
111111 }
112 - $dbw = wfGetDB( DB_MASTER );
 112+ $dbw = self::getDBMaster();
113113 $dbw->replace(
114114 'spoofuser',
115115 array( 'su_name' ),
@@ -121,7 +121,7 @@
122122 * @param $oldName
123123 */
124124 public function update( $oldName ) {
125 - $dbw = wfGetDB( DB_MASTER );
 125+ $dbw = self::getDBMaster();
126126
127127 if( $this->record() ) {
128128 $dbw->delete(
@@ -131,4 +131,18 @@
132132 );
133133 }
134134 }
 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+ }
135149 }
Index: trunk/extensions/AntiSpoof/AntiSpoofHooks.php
@@ -22,6 +22,14 @@
2323 }
2424
2525 /**
 26+ * @param $name string Username
 27+ * @return SpoofUser
 28+ */
 29+ protected static function makeSpoofUser( $name ) {
 30+ return new SpoofUser( $name );
 31+ }
 32+
 33+ /**
2634 * Can be used to cancel user account creation
2735 *
2836 * @param $user User
@@ -44,7 +52,7 @@
4553 }
4654
4755 $name = $user->getName();
48 - $spoof = new SpoofUser( $name );
 56+ $spoof = self::makeSpoofUser( $name );
4957 if ( $spoof->isLegal() ) {
5058 $normalized = $spoof->getNormalized();
5159 $conflicts = $spoof->getConflicts();
@@ -100,7 +108,7 @@
101109 * @return bool
102110 */
103111 public static function asAddNewAccountHook( $user ) {
104 - $spoof = new SpoofUser( $user->getName() );
 112+ $spoof = self::makeSpoofUser( $user->getName() );
105113 $spoof->record();
106114 return true;
107115 }
@@ -115,7 +123,7 @@
116124 * @return bool
117125 */
118126 public static function asAddRenameUserHook( $uid, $oldName, $newName ) {
119 - $spoof = new SpoofUser( $newName );
 127+ $spoof = self::makeSpoofUser( $newName );
120128 $spoof->update( $oldName );
121129 return true;
122130 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r106809Followup r106808...reedy16:29, 20 December 2011

Comments

#Comment by Reedy (talk | contribs)   16:27, 20 December 2011

Prerequisite for (bug 28747) AntiSpoof should also check global accounts from CentralAuth

#Comment by Catrope (talk | contribs)   19:34, 21 December 2011

How does this help subclassing? It sounds to me like you'll need late static binding (PHP 5.3) to get this to do what you seem to want.

Status & tagging log