Index: trunk/extensions/CodeReview/CodeRepository.php |
— | — | @@ -2,6 +2,8 @@ |
3 | 3 | if (!defined('MEDIAWIKI')) die(); |
4 | 4 | |
5 | 5 | class CodeRepository { |
| 6 | + static $userLinks = array(); |
| 7 | + |
6 | 8 | public static function newFromName( $name ) { |
7 | 9 | $dbw = wfGetDB( DB_MASTER ); |
8 | 10 | $row = $dbw->selectRow( |
— | — | @@ -42,26 +44,26 @@ |
43 | 45 | return $repos; |
44 | 46 | } |
45 | 47 | |
46 | | - function getId() { |
| 48 | + public function getId() { |
47 | 49 | return intval( $this->mId ); |
48 | 50 | } |
49 | 51 | |
50 | | - function getName() { |
| 52 | + public function getName() { |
51 | 53 | return $this->mName; |
52 | 54 | } |
53 | 55 | |
54 | | - function getPath(){ |
| 56 | + public function getPath(){ |
55 | 57 | return $this->mPath; |
56 | 58 | } |
57 | 59 | |
58 | | - function getViewVcBase(){ |
| 60 | + public function getViewVcBase(){ |
59 | 61 | return $this->mViewVc; |
60 | 62 | } |
61 | 63 | |
62 | 64 | /** |
63 | 65 | * Return a bug URL or false. |
64 | 66 | */ |
65 | | - function getBugPath( $bugId ) { |
| 67 | + public function getBugPath( $bugId ) { |
66 | 68 | if( $this->mBugzilla ) { |
67 | 69 | return str_replace( '$1', |
68 | 70 | urlencode( $bugId ), $this->mBugzilla ); |
— | — | @@ -69,7 +71,7 @@ |
70 | 72 | return false; |
71 | 73 | } |
72 | 74 | |
73 | | - function getLastStoredRev() { |
| 75 | + public function getLastStoredRev() { |
74 | 76 | $dbr = wfGetDB( DB_SLAVE ); |
75 | 77 | $row = $dbr->selectField( |
76 | 78 | 'code_rev', |
— | — | @@ -80,7 +82,7 @@ |
81 | 83 | return intval( $row ); |
82 | 84 | } |
83 | 85 | |
84 | | - function getAuthorList() { |
| 86 | + public function getAuthorList() { |
85 | 87 | global $wgMemc; |
86 | 88 | $key = wfMemcKey( 'codereview', 'authors', $this->getId() ); |
87 | 89 | $authors = $wgMemc->get( $key ); |
— | — | @@ -104,7 +106,7 @@ |
105 | 107 | return $authors; |
106 | 108 | } |
107 | 109 | |
108 | | - function getTagList() { |
| 110 | + public function getTagList() { |
109 | 111 | global $wgMemc; |
110 | 112 | $key = wfMemcKey( 'codereview', 'tags', $this->getId() ); |
111 | 113 | $tags = $wgMemc->get( $key ); |
— | — | @@ -131,7 +133,7 @@ |
132 | 134 | /** |
133 | 135 | * Load a particular revision out of the DB |
134 | 136 | */ |
135 | | - function getRevision( $id ) { |
| 137 | + public function getRevision( $id ) { |
136 | 138 | if ( !$this->isValidRev( $id ) ) { |
137 | 139 | return null; |
138 | 140 | } |
— | — | @@ -155,7 +157,7 @@ |
156 | 158 | * @param $useCache 'skipcache' to avoid caching |
157 | 159 | * 'cached' to *only* fetch if cached |
158 | 160 | */ |
159 | | - function getDiff( $rev, $useCache = '' ) { |
| 161 | + public function getDiff( $rev, $useCache = '' ) { |
160 | 162 | global $wgMemc; |
161 | 163 | |
162 | 164 | $rev1 = $rev - 1; |
— | — | @@ -187,7 +189,7 @@ |
188 | 190 | * @return bool |
189 | 191 | * @param $rev int Rev id to check |
190 | 192 | */ |
191 | | - function isValidRev( $rev ) { |
| 193 | + public function isValidRev( $rev ) { |
192 | 194 | $rev = intval( $rev ); |
193 | 195 | if ( $rev > 0 && $rev <= $this->getLastStoredRev() ) { |
194 | 196 | return true; |
— | — | @@ -201,7 +203,7 @@ |
202 | 204 | * @param User $user |
203 | 205 | * @return bool success |
204 | 206 | */ |
205 | | - function linkTo( $author, User $user ) { |
| 207 | + public function linkTo( $author, User $user ) { |
206 | 208 | // We must link to an existing user |
207 | 209 | if( !$user->getId() ) { |
208 | 210 | return false; |
— | — | @@ -238,7 +240,7 @@ |
239 | 241 | * @param string $author |
240 | 242 | * @return bool success |
241 | 243 | */ |
242 | | - function unlink( $author ) { |
| 244 | + public function unlink( $author ) { |
243 | 245 | $dbw = wfGetDB( DB_MASTER ); |
244 | 246 | $dbw->delete( |
245 | 247 | 'code_authors', |
— | — | @@ -250,4 +252,32 @@ |
251 | 253 | ); |
252 | 254 | return ( $dbw->affectedRows() > 0 ); |
253 | 255 | } |
| 256 | + |
| 257 | + /* |
| 258 | + * returns a User object if $author has a wikiuser associated, |
| 259 | + * of false |
| 260 | + */ |
| 261 | + public function authorWikiUser( $author ) { |
| 262 | + if( isset( self::$userLinks[$author] ) ) |
| 263 | + return self::$userLinks[$author]; |
| 264 | + |
| 265 | + $dbr = wfGetDB( DB_SLAVE ); |
| 266 | + $wikiUser = $dbr->selectField( |
| 267 | + 'code_authors', |
| 268 | + 'ca_user_text', |
| 269 | + array( |
| 270 | + 'ca_repo_id' => $this->getId(), |
| 271 | + 'ca_author' => $author, |
| 272 | + ), |
| 273 | + __METHOD__ |
| 274 | + ); |
| 275 | + $user = null; |
| 276 | + if( $wikiUser ) |
| 277 | + $user = User::newFromName( $wikiUser ); |
| 278 | + if( $user instanceof User ) |
| 279 | + $res = $user; |
| 280 | + else |
| 281 | + $res = false; |
| 282 | + return self::$userLinks[$author] = $res; |
| 283 | + } |
254 | 284 | } |
Index: trunk/extensions/CodeReview/SpecialCode.php |
— | — | @@ -89,7 +89,6 @@ |
90 | 90 | */ |
91 | 91 | abstract class CodeView { |
92 | 92 | var $mRepo; |
93 | | - static $userLinks = array(); |
94 | 93 | |
95 | 94 | function __construct() { |
96 | 95 | global $wgUser; |
— | — | @@ -110,27 +109,7 @@ |
111 | 110 | * of false |
112 | 111 | */ |
113 | 112 | function authorWikiUser( $author ) { |
114 | | - if( isset( self::$userLinks[$author] ) ) |
115 | | - return self::$userLinks[$author]; |
116 | | - |
117 | | - $dbr = wfGetDB( DB_SLAVE ); |
118 | | - $wikiUser = $dbr->selectField( |
119 | | - 'code_authors', |
120 | | - 'ca_user_text', |
121 | | - array( |
122 | | - 'ca_repo_id' => $this->mRepo->getId(), |
123 | | - 'ca_author' => $author, |
124 | | - ), |
125 | | - __METHOD__ |
126 | | - ); |
127 | | - $user = null; |
128 | | - if( $wikiUser ) |
129 | | - $user = User::newFromName( $wikiUser ); |
130 | | - if( $user instanceof User ) |
131 | | - $res = $user; |
132 | | - else |
133 | | - $res = false; |
134 | | - return self::$userLinks[$author] = $res; |
| 113 | + return $this->mRepo->authorWikiUser( $author ); |
135 | 114 | } |
136 | 115 | |
137 | 116 | function authorLink( $author ) { |