r76214 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76213‎ | r76214 | r76215 >
Date:20:11, 6 November 2010
Author:demon
Status:ok
Tags:
Comment:
General code cleanup to CR:
* Remove more silly 'm' prefixes from member vars
* Got rid of entry point detection stuff, not necessary in files that only have classes
* Get rid of dupe authorWikiUser() from CodeView and children
* Made getViewFrom() non-static. It was also using $mRepo
* Tried to privatize some variables that didn't need to be public and had accessors
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeComment.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodePropChange.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodeRepository.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/Subversion.php (modified) (history)
  • /trunk/extensions/CodeReview/svnImport.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRepoListView.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionListView.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/SpecialCode.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/SpecialRepoAdmin.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeRevision.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class CodeRevision {
65 public $mRepoId, $mRepo, $mId, $mAuthor, $mTimestamp, $mMessage, $mPaths, $mStatus, $mOldStatus, $mCommonPath;
Index: trunk/extensions/CodeReview/backend/CodeRepository.php
@@ -1,12 +1,43 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
 4+/**
 5+ * Core class for interacting with a repository of code.
 6+ */
57 class CodeRepository {
6 - static $userLinks = array();
7 - static $authorLinks = array();
88
9 - public $mId, $mName, $mPath, $mViewVc, $mBugzilla;
 9+ /**
 10+ * Local cache of Wiki user -> SVN user mappings
 11+ * @var Array
 12+ */
 13+ private static $userLinks = array();
1014
 15+ /**
 16+ * Sort of the same, but looking it up for the other direction
 17+ * @var Array
 18+ */
 19+ private static $authorLinks = array();
 20+
 21+ /**
 22+ * Various data about the repo
 23+ */
 24+ private $id, $name, $path, $viewVc, $bugzilla;
 25+
 26+ /**
 27+ * Constructor, can't use it. Call one of the static newFrom* methods
 28+ * @param $id Int Database id for the repo
 29+ * @param $name String User-defined name for the repository
 30+ * @param $path String Path to SVN
 31+ * @param $viewVc String Base path to ViewVC URLs
 32+ * @param $bugzilla String Base path to Bugzilla
 33+ */
 34+ public function __construct( $id, $name, $path, $viewvc, $bugzilla ) {
 35+ $this->id = $id;
 36+ $this->name = $name;
 37+ $this->path = $path;
 38+ $this->viewVc = $viewvc;
 39+ $this->bugzilla = $bugzilla;
 40+ }
 41+
1142 public static function newFromName( $name ) {
1243 $dbw = wfGetDB( DB_MASTER );
1344 $row = $dbw->selectRow(
@@ -48,13 +79,13 @@
4980 }
5081
5182 static function newFromRow( $row ) {
52 - $repo = new CodeRepository();
53 - $repo->mId = intval( $row->repo_id );
54 - $repo->mName = $row->repo_name;
55 - $repo->mPath = $row->repo_path;
56 - $repo->mViewVc = $row->repo_viewvc;
57 - $repo->mBugzilla = $row->repo_bugzilla;
58 - return $repo;
 83+ return new CodeRepository(
 84+ intval( $row->repo_id ),
 85+ $row->repo_name,
 86+ $row->repo_path,
 87+ $row->repo_viewvc,
 88+ $row->repo_bugzilla
 89+ );
5990 }
6091
6192 static function getRepoList() {
@@ -68,28 +99,28 @@
69100 }
70101
71102 public function getId() {
72 - return intval( $this->mId );
 103+ return intval( $this->id );
73104 }
74105
75106 public function getName() {
76 - return $this->mName;
 107+ return $this->name;
77108 }
78109
79110 public function getPath() {
80 - return $this->mPath;
 111+ return $this->path;
81112 }
82113
83114 public function getViewVcBase() {
84 - return $this->mViewVc;
 115+ return $this->viewVc;
85116 }
86117
87118 /**
88119 * Return a bug URL or false.
89120 */
90121 public function getBugPath( $bugId ) {
91 - if ( $this->mBugzilla ) {
 122+ if ( $this->bugzilla ) {
92123 return str_replace( '$1',
93 - urlencode( $bugId ), $this->mBugzilla );
 124+ urlencode( $bugId ), $this->bugzilla );
94125 }
95126 return false;
96127 }
@@ -229,7 +260,7 @@
230261 }
231262
232263 # Try memcached...
233 - $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1, $rev2 );
 264+ $key = wfMemcKey( 'svn', md5( $this->path ), 'diff', $rev1, $rev2 );
234265 if ( $useCache === 'skipcache' ) {
235266 $data = null;
236267 } else {
@@ -241,7 +272,7 @@
242273 $dbr = wfGetDB( DB_SLAVE );
243274 $row = $dbr->selectRow( 'code_rev',
244275 array( 'cr_diff', 'cr_flags' ),
245 - array( 'cr_repo_id' => $this->mId, 'cr_id' => $rev, 'cr_diff IS NOT NULL' ),
 276+ array( 'cr_repo_id' => $this->id, 'cr_id' => $rev, 'cr_diff IS NOT NULL' ),
246277 __METHOD__
247278 );
248279 if ( $row ) {
@@ -259,7 +290,7 @@
260291
261292 # Generate the diff as needed...
262293 if ( !$data && $useCache !== 'cached' ) {
263 - $svn = SubversionAdaptor::newFromRepo( $this->mPath );
 294+ $svn = SubversionAdaptor::newFromRepo( $this->path );
264295 $data = $svn->getDiff( '', $rev1, $rev2 );
265296 // Store to cache
266297 $wgMemc->set( $key, $data, 3600 * 24 * 3 );
@@ -269,7 +300,7 @@
270301 $dbw = wfGetDB( DB_MASTER );
271302 $dbw->update( 'code_rev',
272303 array( 'cr_diff' => $storedData, 'cr_flags' => $flags ),
273 - array( 'cr_repo_id' => $this->mId, 'cr_id' => $rev ),
 304+ array( 'cr_repo_id' => $this->id, 'cr_id' => $rev ),
274305 __METHOD__
275306 );
276307 }
@@ -288,10 +319,10 @@
289320 $rev1 = $codeRev->getId() - 1;
290321 $rev2 = $codeRev->getId();
291322
292 - $svn = SubversionAdaptor::newFromRepo( $this->mPath );
 323+ $svn = SubversionAdaptor::newFromRepo( $this->path );
293324 $data = $svn->getDiff( '', $rev1, $rev2 );
294325 // Store to cache
295 - $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1, $rev2 );
 326+ $key = wfMemcKey( 'svn', md5( $this->path ), 'diff', $rev1, $rev2 );
296327 $wgMemc->set( $key, $data, 3600 * 24 * 3 );
297328 // Permanent DB storage
298329 $storedData = $data;
@@ -299,7 +330,7 @@
300331 $dbw = wfGetDB( DB_MASTER );
301332 $dbw->update( 'code_rev',
302333 array( 'cr_diff' => $storedData, 'cr_flags' => $flags ),
303 - array( 'cr_repo_id' => $this->mId, 'cr_id' => $codeRev->getId() ),
 334+ array( 'cr_repo_id' => $this->id, 'cr_id' => $codeRev->getId() ),
304335 __METHOD__
305336 );
306337 wfProfileOut( __METHOD__ );
Index: trunk/extensions/CodeReview/backend/CodeComment.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class CodeComment {
65 public $id, $text, $user, $userText, $timestamp, $review, $sortkey, $attrib, $removed, $added;
Index: trunk/extensions/CodeReview/backend/Subversion.php
@@ -1,6 +1,6 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
 4+
55 abstract class SubversionAdaptor {
66 protected $mRepo;
77
Index: trunk/extensions/CodeReview/backend/CodePropChange.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class CodePropChange {
65 function __construct( $rev ) {
Index: trunk/extensions/CodeReview/svnImport.php
@@ -113,7 +113,7 @@
114114 $codeRev->save();
115115
116116 $this->output( sprintf( "%d %s %s (%0.1f revs/sec)\n",
117 - $codeRev->mId,
 117+ $codeRev->getId(),
118118 wfTimestamp( TS_DB, $codeRev->mTimestamp ),
119119 $codeRev->mAuthor,
120120 $revSpeed ) );
Index: trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php
@@ -4,7 +4,7 @@
55 function __construct( $repoName, $author ) {
66 parent::__construct( $repoName );
77 $this->mAuthor = $author;
8 - $this->mUser = $this->authorWikiUser( $author );
 8+ $this->mUser = $this->mRepo->authorWikiUser( $author );
99 $this->mAppliedFilter = wfMsg( 'code-revfilter-cr_author', $author );
1010 }
1111
Index: trunk/extensions/CodeReview/ui/SpecialCode.php
@@ -1,12 +1,14 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
 4+/**
 5+ * Main UI entry point. This calls the appropriate CodeView subclass and runs it
 6+ */
57 class SpecialCode extends SpecialPage {
6 - function __construct() {
 8+ public function __construct() {
79 parent::__construct( 'Code' , 'codereview-use' );
810 }
911
10 - function execute( $subpage ) {
 12+ public function execute( $subpage ) {
1113 global $wgOut, $wgUser, $wgExtensionAssetsPath, $wgCodeReviewStyleVersion;
1214
1315 if ( !$this->userCanExecute( $wgUser ) ) {
@@ -17,7 +19,7 @@
1820 $this->setHeaders();
1921 $wgOut->addStyle( "$wgExtensionAssetsPath/CodeReview/codereview.css?$wgCodeReviewStyleVersion" );
2022
21 - $view = self::getViewFrom( $subpage );
 23+ $view = $this->getViewFrom( $subpage );
2224 if( $view ) {
2325 $view->execute();
2426 } else {
@@ -38,7 +40,7 @@
3941 * Get a view object from a sub page path.
4042 * @return View object or null if no valid action could be found
4143 */
42 - private static function getViewFrom( $subpage ) {
 44+ private function getViewFrom( $subpage ) {
4345 global $wgRequest;
4446
4547 # Remove stray slashes
@@ -149,16 +151,6 @@
150152
151153 abstract function execute();
152154
153 - /*
154 - * returns a User object if $author has a wikiuser associated,
155 - * of false
156 - */
157 - function authorWikiUser( $author ) {
158 - if ( $this->mRepo )
159 - return $this->mRepo->authorWikiUser( $author );
160 - return false;
161 - }
162 -
163155 function authorLink( $author, $extraParams = array() ) {
164156 $repo = $this->mRepo->getName();
165157 $special = SpecialPage::getTitleFor( 'Code', "$repo/author/$author" );
@@ -234,7 +226,7 @@
235227 function formatRow( $row ) {
236228 global $wgWikiSVN;
237229 $css = "mw-codereview-status-{$row->cr_status}";
238 - if ( $this->mRepo->mName == $wgWikiSVN ) {
 230+ if ( $this->mRepo->getName() == $wgWikiSVN ) {
239231 $css .= " mw-codereview-" . ( $row-> { $this->getDefaultSort() } <= $this->mCurSVN ? 'live' : 'notlive' );
240232 }
241233 $s = "<tr class=\"$css\">\n";
Index: trunk/extensions/CodeReview/ui/SpecialRepoAdmin.php
@@ -1,12 +1,13 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
4 -
 3+/**
 4+ * Repository administration
 5+ */
56 class SpecialRepoAdmin extends SpecialPage {
6 - function __construct() {
 7+ public function __construct() {
78 parent::__construct( 'RepoAdmin', 'repoadmin' );
89 }
910
10 - function execute( $subpage ) {
 11+ public function execute( $subpage ) {
1112 global $wgRequest, $wgUser;
1213
1314 $this->setHeaders();
@@ -18,32 +19,47 @@
1920
2021 $repo = $wgRequest->getVal( 'repo', $subpage );
2122 if ( $repo == '' ) {
22 - $view = new RepoAdminListView( $this );
 23+ $view = new RepoAdminListView( $this->getTitle() );
2324 } else {
24 - $view = new RepoAdminRepoView( $this, $repo );
 25+ $view = new RepoAdminRepoView( $this->getTitle( $repo ), $repo );
2526 }
2627 $view->execute();
2728 }
2829 }
2930
 31+/**
 32+ * View for viewing all of the repositories
 33+ */
3034 class RepoAdminListView {
31 - var $mPage;
 35+ /**
 36+ * Reference to Special:RepoAdmin
 37+ * @var Title
 38+ */
 39+ private $title;
3240
33 - function __construct( $page ) {
34 - $this->mPage = $page;
 41+ /**
 42+ * Constructor
 43+ * @param $t Title object referring to Special:RepoAdmin
 44+ */
 45+ public function __construct( Title $t ) {
 46+ $this->title = $t;
3547 }
3648
37 - function getForm() {
 49+ /**
 50+ * Get "create new repo" form
 51+ * @return String
 52+ */
 53+ private function getForm() {
3854 global $wgScript;
3955 return Xml::fieldset( wfMsg( 'repoadmin-new-legend' ) ) .
4056 Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
41 - Html::hidden( 'title', $this->mPage->getTitle()->getPrefixedDBKey() ) .
 57+ Html::hidden( 'title', $this->title->getPrefixedDBKey() ) .
4258 Xml::inputLabel( wfMsg( 'repoadmin-new-label' ), 'repo', 'repo' ) .
4359 Xml::submitButton( wfMsg( 'repoadmin-new-button' ) ) .
4460 '</form></fieldset>';
4561 }
4662
47 - function execute() {
 63+ public function execute() {
4864 global $wgOut;
4965 $wgOut->addHTML( $this->getForm() );
5066 $repos = CodeRepository::getRepoList();
@@ -59,22 +75,45 @@
6076 }
6177 }
6278
 79+/**
 80+ * View for editing a single repository
 81+ */
6382 class RepoAdminRepoView {
64 - var $mPage;
 83+ /**
 84+ * Reference to Special:RepoAdmin
 85+ * @var Title
 86+ */
 87+ private $title;
6588
66 - function __construct( $page, $repo ) {
67 - $this->mPage = $page;
68 - $this->mRepoName = $repo;
69 - $this->mRepo = CodeRepository::newFromName( $repo );
 89+ /**
 90+ * Human-readable name of the repository
 91+ * @var String
 92+ */
 93+ private $repoName;
 94+
 95+ /**
 96+ * Actual repository object
 97+ */
 98+ private $repo;
 99+
 100+ /**
 101+ * @
 102+ * @param $page Title Special page title (with repo subpage)
 103+ * @param $repo
 104+ */
 105+ public function __construct( Title $t, $repo ) {
 106+ $this->title = $t;
 107+ $this->repoName = $repo;
 108+ $this->repo = CodeRepository::newFromName( $repo );
70109 }
71110
72111 function execute() {
73112 global $wgOut, $wgRequest, $wgUser;
74 - $repoExists = (bool)$this->mRepo;
75 - $repoPath = $wgRequest->getVal( 'wpRepoPath', $repoExists ? $this->mRepo->mPath : '' );
76 - $bugPath = $wgRequest->getVal( 'wpBugPath', $repoExists ? $this->mRepo->mBugzilla : '' );
77 - $viewPath = $wgRequest->getVal( 'wpViewPath', $repoExists ? $this->mRepo->mViewVc : '' );
78 - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $this->mRepoName ) ) {
 113+ $repoExists = (bool)$this->repo;
 114+ $repoPath = $wgRequest->getVal( 'wpRepoPath', $repoExists ? $this->repo->getPath() : '' );
 115+ $bugPath = $wgRequest->getVal( 'wpBugPath', $repoExists ? $this->repo->getBugzillaBase() : '' );
 116+ $viewPath = $wgRequest->getVal( 'wpViewPath', $repoExists ? $this->repo->getViewVcBase() : '' );
 117+ if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $this->repoName ) ) {
79118 // @todo log
80119 $dbw = wfGetDB( DB_MASTER );
81120 if ( $repoExists ) {
@@ -92,7 +131,7 @@
93132 $dbw->insert(
94133 'code_repo',
95134 array(
96 - 'repo_name' => $this->mRepoName,
 135+ 'repo_name' => $this->repoName,
97136 'repo_path' => $repoPath,
98137 'repo_viewvc' => $viewPath,
99138 'repo_bugzilla' => $bugPath
@@ -100,12 +139,12 @@
101140 __METHOD__
102141 );
103142 }
104 - $wgOut->wrapWikiMsg( '<div class="successbox">$1</div>', array( 'repoadmin-edit-sucess', $this->mRepoName ) );
 143+ $wgOut->wrapWikiMsg( '<div class="successbox">$1</div>', array( 'repoadmin-edit-sucess', $this->repoName ) );
105144 return;
106145 }
107146 $wgOut->addHTML(
108 - Xml::fieldset( wfMsg( 'repoadmin-edit-legend', $this->mRepoName ) ) .
109 - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mPage->getTitle( $this->mRepoName )->getLocalURL() ) ) .
 147+ Xml::fieldset( wfMsg( 'repoadmin-edit-legend', $this->repoName ) ) .
 148+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->title->getLocalURL() ) ) .
110149 Xml::buildForm(
111150 array(
112151 'repoadmin-edit-path' =>
@@ -114,7 +153,7 @@
115154 Xml::input( 'wpBugPath', 60, $bugPath ),
116155 'repoadmin-edit-view' =>
117156 Xml::input( 'wpViewPath', 60, $viewPath ) ) ) .
118 - Html::hidden( 'wpEditToken', $wgUser->editToken( $this->mRepoName ) ) .
 157+ Html::hidden( 'wpEditToken', $wgUser->editToken( $this->repoName ) ) .
119158 Xml::submitButton( wfMsg( 'repoadmin-edit-button' ) ) .
120159 '</form></fieldset>'
121160 );
Index: trunk/extensions/CodeReview/ui/CodeRevisionListView.php
@@ -348,7 +348,7 @@
349349 function formatRow( $row ) {
350350 global $wgWikiSVN;
351351 $css = "mw-codereview-status-{$row->cr_status}";
352 - if ( $this->mRepo->mName == $wgWikiSVN ) {
 352+ if ( $this->mRepo->getName() == $wgWikiSVN ) {
353353 $css .= " mw-codereview-" . ( $row-> { $this->getDefaultSort() } <= $this->mCurSVN ? 'live' : 'notlive' );
354354 }
355355 $s = "<tr class=\"$css\">\n";
Index: trunk/extensions/CodeReview/ui/CodeRepoListView.php
@@ -1,9 +1,10 @@
22 <?php
33
4 -// Special:Code
 4+/**
 5+ * Class for showing the list of repositories, if none was specified
 6+ */
57 class CodeRepoListView {
6 -
7 - function execute() {
 8+ public function execute() {
89 global $wgOut;
910 $repos = CodeRepository::getRepoList();
1011 if ( !count( $repos ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r76879Fix for r76214: added missing method CodeRepository::getBugzillaBase(); was t...ialex11:43, 17 November 2010
r80481(bug 26780) Fix fatal from refactoring in r76214demon01:00, 18 January 2011

Status & tagging log