r42165 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42164‎ | r42165 | r42166 >
Date:04:33, 17 October 2008
Author:aaron
Status:old
Tags:
Comment:
Move authorwikiuser to better place
Modified paths:
  • /trunk/extensions/CodeReview/CodeRepository.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRepository.php
@@ -2,6 +2,8 @@
33 if (!defined('MEDIAWIKI')) die();
44
55 class CodeRepository {
 6+ static $userLinks = array();
 7+
68 public static function newFromName( $name ) {
79 $dbw = wfGetDB( DB_MASTER );
810 $row = $dbw->selectRow(
@@ -42,26 +44,26 @@
4345 return $repos;
4446 }
4547
46 - function getId() {
 48+ public function getId() {
4749 return intval( $this->mId );
4850 }
4951
50 - function getName() {
 52+ public function getName() {
5153 return $this->mName;
5254 }
5355
54 - function getPath(){
 56+ public function getPath(){
5557 return $this->mPath;
5658 }
5759
58 - function getViewVcBase(){
 60+ public function getViewVcBase(){
5961 return $this->mViewVc;
6062 }
6163
6264 /**
6365 * Return a bug URL or false.
6466 */
65 - function getBugPath( $bugId ) {
 67+ public function getBugPath( $bugId ) {
6668 if( $this->mBugzilla ) {
6769 return str_replace( '$1',
6870 urlencode( $bugId ), $this->mBugzilla );
@@ -69,7 +71,7 @@
7072 return false;
7173 }
7274
73 - function getLastStoredRev() {
 75+ public function getLastStoredRev() {
7476 $dbr = wfGetDB( DB_SLAVE );
7577 $row = $dbr->selectField(
7678 'code_rev',
@@ -80,7 +82,7 @@
8183 return intval( $row );
8284 }
8385
84 - function getAuthorList() {
 86+ public function getAuthorList() {
8587 global $wgMemc;
8688 $key = wfMemcKey( 'codereview', 'authors', $this->getId() );
8789 $authors = $wgMemc->get( $key );
@@ -104,7 +106,7 @@
105107 return $authors;
106108 }
107109
108 - function getTagList() {
 110+ public function getTagList() {
109111 global $wgMemc;
110112 $key = wfMemcKey( 'codereview', 'tags', $this->getId() );
111113 $tags = $wgMemc->get( $key );
@@ -131,7 +133,7 @@
132134 /**
133135 * Load a particular revision out of the DB
134136 */
135 - function getRevision( $id ) {
 137+ public function getRevision( $id ) {
136138 if ( !$this->isValidRev( $id ) ) {
137139 return null;
138140 }
@@ -155,7 +157,7 @@
156158 * @param $useCache 'skipcache' to avoid caching
157159 * 'cached' to *only* fetch if cached
158160 */
159 - function getDiff( $rev, $useCache = '' ) {
 161+ public function getDiff( $rev, $useCache = '' ) {
160162 global $wgMemc;
161163
162164 $rev1 = $rev - 1;
@@ -187,7 +189,7 @@
188190 * @return bool
189191 * @param $rev int Rev id to check
190192 */
191 - function isValidRev( $rev ) {
 193+ public function isValidRev( $rev ) {
192194 $rev = intval( $rev );
193195 if ( $rev > 0 && $rev <= $this->getLastStoredRev() ) {
194196 return true;
@@ -201,7 +203,7 @@
202204 * @param User $user
203205 * @return bool success
204206 */
205 - function linkTo( $author, User $user ) {
 207+ public function linkTo( $author, User $user ) {
206208 // We must link to an existing user
207209 if( !$user->getId() ) {
208210 return false;
@@ -238,7 +240,7 @@
239241 * @param string $author
240242 * @return bool success
241243 */
242 - function unlink( $author ) {
 244+ public function unlink( $author ) {
243245 $dbw = wfGetDB( DB_MASTER );
244246 $dbw->delete(
245247 'code_authors',
@@ -250,4 +252,32 @@
251253 );
252254 return ( $dbw->affectedRows() > 0 );
253255 }
 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+ }
254284 }
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -89,7 +89,6 @@
9090 */
9191 abstract class CodeView {
9292 var $mRepo;
93 - static $userLinks = array();
9493
9594 function __construct() {
9695 global $wgUser;
@@ -110,27 +109,7 @@
111110 * of false
112111 */
113112 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 );
135114 }
136115
137116 function authorLink( $author ) {

Status & tagging log