http://www.mediawiki.org/wiki/Special:Code/MediaWiki/76214
Revision: 76214
Author: demon
Date: 2010-11-06 20:11:30 +0000 (Sat, 06 Nov 2010)
Log Message:
-----------
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
trunk/extensions/CodeReview/backend/CodePropChange.php
trunk/extensions/CodeReview/backend/CodeRepository.php
trunk/extensions/CodeReview/backend/CodeRevision.php
trunk/extensions/CodeReview/backend/Subversion.php
trunk/extensions/CodeReview/svnImport.php
trunk/extensions/CodeReview/ui/CodeRepoListView.php
trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php
trunk/extensions/CodeReview/ui/CodeRevisionListView.php
trunk/extensions/CodeReview/ui/SpecialCode.php
trunk/extensions/CodeReview/ui/SpecialRepoAdmin.php
Modified: trunk/extensions/CodeReview/backend/CodeComment.php
===================================================================
--- trunk/extensions/CodeReview/backend/CodeComment.php 2010-11-06 20:10:55 UTC
(rev 76213)
+++ trunk/extensions/CodeReview/backend/CodeComment.php 2010-11-06 20:11:30 UTC
(rev 76214)
@@ -1,5 +1,4 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
class CodeComment {
public $id, $text, $user, $userText, $timestamp, $review, $sortkey,
$attrib, $removed, $added;
Modified: trunk/extensions/CodeReview/backend/CodePropChange.php
===================================================================
--- trunk/extensions/CodeReview/backend/CodePropChange.php 2010-11-06
20:10:55 UTC (rev 76213)
+++ trunk/extensions/CodeReview/backend/CodePropChange.php 2010-11-06
20:11:30 UTC (rev 76214)
@@ -1,5 +1,4 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
class CodePropChange {
function __construct( $rev ) {
Modified: trunk/extensions/CodeReview/backend/CodeRepository.php
===================================================================
--- trunk/extensions/CodeReview/backend/CodeRepository.php 2010-11-06
20:10:55 UTC (rev 76213)
+++ trunk/extensions/CodeReview/backend/CodeRepository.php 2010-11-06
20:11:30 UTC (rev 76214)
@@ -1,12 +1,43 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
+/**
+ * Core class for interacting with a repository of code.
+ */
class CodeRepository {
- static $userLinks = array();
- static $authorLinks = array();
- public $mId, $mName, $mPath, $mViewVc, $mBugzilla;
+ /**
+ * Local cache of Wiki user -> SVN user mappings
+ * @var Array
+ */
+ private static $userLinks = array();
+ /**
+ * Sort of the same, but looking it up for the other direction
+ * @var Array
+ */
+ private static $authorLinks = array();
+
+ /**
+ * Various data about the repo
+ */
+ private $id, $name, $path, $viewVc, $bugzilla;
+
+ /**
+ * Constructor, can't use it. Call one of the static newFrom* methods
+ * @param $id Int Database id for the repo
+ * @param $name String User-defined name for the repository
+ * @param $path String Path to SVN
+ * @param $viewVc String Base path to ViewVC URLs
+ * @param $bugzilla String Base path to Bugzilla
+ */
+ public function __construct( $id, $name, $path, $viewvc, $bugzilla ) {
+ $this->id = $id;
+ $this->name = $name;
+ $this->path = $path;
+ $this->viewVc = $viewvc;
+ $this->bugzilla = $bugzilla;
+ }
+
public static function newFromName( $name ) {
$dbw = wfGetDB( DB_MASTER );
$row = $dbw->selectRow(
@@ -48,13 +79,13 @@
}
static function newFromRow( $row ) {
- $repo = new CodeRepository();
- $repo->mId = intval( $row->repo_id );
- $repo->mName = $row->repo_name;
- $repo->mPath = $row->repo_path;
- $repo->mViewVc = $row->repo_viewvc;
- $repo->mBugzilla = $row->repo_bugzilla;
- return $repo;
+ return new CodeRepository(
+ intval( $row->repo_id ),
+ $row->repo_name,
+ $row->repo_path,
+ $row->repo_viewvc,
+ $row->repo_bugzilla
+ );
}
static function getRepoList() {
@@ -68,28 +99,28 @@
}
public function getId() {
- return intval( $this->mId );
+ return intval( $this->id );
}
public function getName() {
- return $this->mName;
+ return $this->name;
}
public function getPath() {
- return $this->mPath;
+ return $this->path;
}
public function getViewVcBase() {
- return $this->mViewVc;
+ return $this->viewVc;
}
/**
* Return a bug URL or false.
*/
public function getBugPath( $bugId ) {
- if ( $this->mBugzilla ) {
+ if ( $this->bugzilla ) {
return str_replace( '$1',
- urlencode( $bugId ), $this->mBugzilla );
+ urlencode( $bugId ), $this->bugzilla );
}
return false;
}
@@ -229,7 +260,7 @@
}
# Try memcached...
- $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1,
$rev2 );
+ $key = wfMemcKey( 'svn', md5( $this->path ), 'diff', $rev1,
$rev2 );
if ( $useCache === 'skipcache' ) {
$data = null;
} else {
@@ -241,7 +272,7 @@
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'code_rev',
array( 'cr_diff', 'cr_flags' ),
- array( 'cr_repo_id' => $this->mId, 'cr_id' =>
$rev, 'cr_diff IS NOT NULL' ),
+ array( 'cr_repo_id' => $this->id, 'cr_id' =>
$rev, 'cr_diff IS NOT NULL' ),
__METHOD__
);
if ( $row ) {
@@ -259,7 +290,7 @@
# Generate the diff as needed...
if ( !$data && $useCache !== 'cached' ) {
- $svn = SubversionAdaptor::newFromRepo( $this->mPath );
+ $svn = SubversionAdaptor::newFromRepo( $this->path );
$data = $svn->getDiff( '', $rev1, $rev2 );
// Store to cache
$wgMemc->set( $key, $data, 3600 * 24 * 3 );
@@ -269,7 +300,7 @@
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'code_rev',
array( 'cr_diff' => $storedData, 'cr_flags' =>
$flags ),
- array( 'cr_repo_id' => $this->mId, 'cr_id' =>
$rev ),
+ array( 'cr_repo_id' => $this->id, 'cr_id' =>
$rev ),
__METHOD__
);
}
@@ -288,10 +319,10 @@
$rev1 = $codeRev->getId() - 1;
$rev2 = $codeRev->getId();
- $svn = SubversionAdaptor::newFromRepo( $this->mPath );
+ $svn = SubversionAdaptor::newFromRepo( $this->path );
$data = $svn->getDiff( '', $rev1, $rev2 );
// Store to cache
- $key = wfMemcKey( 'svn', md5( $this->mPath ), 'diff', $rev1,
$rev2 );
+ $key = wfMemcKey( 'svn', md5( $this->path ), 'diff', $rev1,
$rev2 );
$wgMemc->set( $key, $data, 3600 * 24 * 3 );
// Permanent DB storage
$storedData = $data;
@@ -299,7 +330,7 @@
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'code_rev',
array( 'cr_diff' => $storedData, 'cr_flags' => $flags ),
- array( 'cr_repo_id' => $this->mId, 'cr_id' =>
$codeRev->getId() ),
+ array( 'cr_repo_id' => $this->id, 'cr_id' =>
$codeRev->getId() ),
__METHOD__
);
wfProfileOut( __METHOD__ );
Modified: trunk/extensions/CodeReview/backend/CodeRevision.php
===================================================================
--- trunk/extensions/CodeReview/backend/CodeRevision.php 2010-11-06
20:10:55 UTC (rev 76213)
+++ trunk/extensions/CodeReview/backend/CodeRevision.php 2010-11-06
20:11:30 UTC (rev 76214)
@@ -1,5 +1,4 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
class CodeRevision {
public $mRepoId, $mRepo, $mId, $mAuthor, $mTimestamp, $mMessage,
$mPaths, $mStatus, $mOldStatus, $mCommonPath;
Modified: trunk/extensions/CodeReview/backend/Subversion.php
===================================================================
--- trunk/extensions/CodeReview/backend/Subversion.php 2010-11-06 20:10:55 UTC
(rev 76213)
+++ trunk/extensions/CodeReview/backend/Subversion.php 2010-11-06 20:11:30 UTC
(rev 76214)
@@ -1,6 +1,6 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
+
abstract class SubversionAdaptor {
protected $mRepo;
Modified: trunk/extensions/CodeReview/svnImport.php
===================================================================
--- trunk/extensions/CodeReview/svnImport.php 2010-11-06 20:10:55 UTC (rev
76213)
+++ trunk/extensions/CodeReview/svnImport.php 2010-11-06 20:11:30 UTC (rev
76214)
@@ -113,7 +113,7 @@
$codeRev->save();
$this->output( sprintf( "%d %s %s (%0.1f
revs/sec)\n",
- $codeRev->mId,
+ $codeRev->getId(),
wfTimestamp( TS_DB,
$codeRev->mTimestamp ),
$codeRev->mAuthor,
$revSpeed ) );
Modified: trunk/extensions/CodeReview/ui/CodeRepoListView.php
===================================================================
--- trunk/extensions/CodeReview/ui/CodeRepoListView.php 2010-11-06 20:10:55 UTC
(rev 76213)
+++ trunk/extensions/CodeReview/ui/CodeRepoListView.php 2010-11-06 20:11:30 UTC
(rev 76214)
@@ -1,9 +1,10 @@
<?php
-// Special:Code
+/**
+ * Class for showing the list of repositories, if none was specified
+ */
class CodeRepoListView {
-
- function execute() {
+ public function execute() {
global $wgOut;
$repos = CodeRepository::getRepoList();
if ( !count( $repos ) ) {
Modified: trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php
===================================================================
--- trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php 2010-11-06
20:10:55 UTC (rev 76213)
+++ trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php 2010-11-06
20:11:30 UTC (rev 76214)
@@ -4,7 +4,7 @@
function __construct( $repoName, $author ) {
parent::__construct( $repoName );
$this->mAuthor = $author;
- $this->mUser = $this->authorWikiUser( $author );
+ $this->mUser = $this->mRepo->authorWikiUser( $author );
$this->mAppliedFilter = wfMsg( 'code-revfilter-cr_author',
$author );
}
Modified: trunk/extensions/CodeReview/ui/CodeRevisionListView.php
===================================================================
--- trunk/extensions/CodeReview/ui/CodeRevisionListView.php 2010-11-06
20:10:55 UTC (rev 76213)
+++ trunk/extensions/CodeReview/ui/CodeRevisionListView.php 2010-11-06
20:11:30 UTC (rev 76214)
@@ -348,7 +348,7 @@
function formatRow( $row ) {
global $wgWikiSVN;
$css = "mw-codereview-status-{$row->cr_status}";
- if ( $this->mRepo->mName == $wgWikiSVN ) {
+ if ( $this->mRepo->getName() == $wgWikiSVN ) {
$css .= " mw-codereview-" . ( $row-> {
$this->getDefaultSort() } <= $this->mCurSVN ? 'live' : 'notlive' );
}
$s = "<tr class=\"$css\">\n";
Modified: trunk/extensions/CodeReview/ui/SpecialCode.php
===================================================================
--- trunk/extensions/CodeReview/ui/SpecialCode.php 2010-11-06 20:10:55 UTC
(rev 76213)
+++ trunk/extensions/CodeReview/ui/SpecialCode.php 2010-11-06 20:11:30 UTC
(rev 76214)
@@ -1,12 +1,14 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
+/**
+ * Main UI entry point. This calls the appropriate CodeView subclass and runs
it
+ */
class SpecialCode extends SpecialPage {
- function __construct() {
+ public function __construct() {
parent::__construct( 'Code' , 'codereview-use' );
}
- function execute( $subpage ) {
+ public function execute( $subpage ) {
global $wgOut, $wgUser, $wgExtensionAssetsPath,
$wgCodeReviewStyleVersion;
if ( !$this->userCanExecute( $wgUser ) ) {
@@ -17,7 +19,7 @@
$this->setHeaders();
$wgOut->addStyle(
"$wgExtensionAssetsPath/CodeReview/codereview.css?$wgCodeReviewStyleVersion" );
- $view = self::getViewFrom( $subpage );
+ $view = $this->getViewFrom( $subpage );
if( $view ) {
$view->execute();
} else {
@@ -38,7 +40,7 @@
* Get a view object from a sub page path.
* @return View object or null if no valid action could be found
*/
- private static function getViewFrom( $subpage ) {
+ private function getViewFrom( $subpage ) {
global $wgRequest;
# Remove stray slashes
@@ -149,16 +151,6 @@
abstract function execute();
- /*
- * returns a User object if $author has a wikiuser associated,
- * of false
- */
- function authorWikiUser( $author ) {
- if ( $this->mRepo )
- return $this->mRepo->authorWikiUser( $author );
- return false;
- }
-
function authorLink( $author, $extraParams = array() ) {
$repo = $this->mRepo->getName();
$special = SpecialPage::getTitleFor( 'Code',
"$repo/author/$author" );
@@ -234,7 +226,7 @@
function formatRow( $row ) {
global $wgWikiSVN;
$css = "mw-codereview-status-{$row->cr_status}";
- if ( $this->mRepo->mName == $wgWikiSVN ) {
+ if ( $this->mRepo->getName() == $wgWikiSVN ) {
$css .= " mw-codereview-" . ( $row-> {
$this->getDefaultSort() } <= $this->mCurSVN ? 'live' : 'notlive' );
}
$s = "<tr class=\"$css\">\n";
Modified: trunk/extensions/CodeReview/ui/SpecialRepoAdmin.php
===================================================================
--- trunk/extensions/CodeReview/ui/SpecialRepoAdmin.php 2010-11-06 20:10:55 UTC
(rev 76213)
+++ trunk/extensions/CodeReview/ui/SpecialRepoAdmin.php 2010-11-06 20:11:30 UTC
(rev 76214)
@@ -1,12 +1,13 @@
<?php
-if ( !defined( 'MEDIAWIKI' ) ) die();
-
+/**
+ * Repository administration
+ */
class SpecialRepoAdmin extends SpecialPage {
- function __construct() {
+ public function __construct() {
parent::__construct( 'RepoAdmin', 'repoadmin' );
}
- function execute( $subpage ) {
+ public function execute( $subpage ) {
global $wgRequest, $wgUser;
$this->setHeaders();
@@ -18,32 +19,47 @@
$repo = $wgRequest->getVal( 'repo', $subpage );
if ( $repo == '' ) {
- $view = new RepoAdminListView( $this );
+ $view = new RepoAdminListView( $this->getTitle() );
} else {
- $view = new RepoAdminRepoView( $this, $repo );
+ $view = new RepoAdminRepoView( $this->getTitle( $repo
), $repo );
}
$view->execute();
}
}
+/**
+ * View for viewing all of the repositories
+ */
class RepoAdminListView {
- var $mPage;
+ /**
+ * Reference to Special:RepoAdmin
+ * @var Title
+ */
+ private $title;
- function __construct( $page ) {
- $this->mPage = $page;
+ /**
+ * Constructor
+ * @param $t Title object referring to Special:RepoAdmin
+ */
+ public function __construct( Title $t ) {
+ $this->title = $t;
}
- function getForm() {
+ /**
+ * Get "create new repo" form
+ * @return String
+ */
+ private function getForm() {
global $wgScript;
return Xml::fieldset( wfMsg( 'repoadmin-new-legend' ) ) .
Xml::openElement( 'form', array( 'method' => 'get',
'action' => $wgScript ) ) .
- Html::hidden( 'title',
$this->mPage->getTitle()->getPrefixedDBKey() ) .
+ Html::hidden( 'title', $this->title->getPrefixedDBKey()
) .
Xml::inputLabel( wfMsg( 'repoadmin-new-label' ),
'repo', 'repo' ) .
Xml::submitButton( wfMsg( 'repoadmin-new-button' ) ) .
'</form></fieldset>';
}
- function execute() {
+ public function execute() {
global $wgOut;
$wgOut->addHTML( $this->getForm() );
$repos = CodeRepository::getRepoList();
@@ -59,22 +75,45 @@
}
}
+/**
+ * View for editing a single repository
+ */
class RepoAdminRepoView {
- var $mPage;
+ /**
+ * Reference to Special:RepoAdmin
+ * @var Title
+ */
+ private $title;
- function __construct( $page, $repo ) {
- $this->mPage = $page;
- $this->mRepoName = $repo;
- $this->mRepo = CodeRepository::newFromName( $repo );
+ /**
+ * Human-readable name of the repository
+ * @var String
+ */
+ private $repoName;
+
+ /**
+ * Actual repository object
+ */
+ private $repo;
+
+ /**
+ * @
+ * @param $page Title Special page title (with repo subpage)
+ * @param $repo
+ */
+ public function __construct( Title $t, $repo ) {
+ $this->title = $t;
+ $this->repoName = $repo;
+ $this->repo = CodeRepository::newFromName( $repo );
}
function execute() {
global $wgOut, $wgRequest, $wgUser;
- $repoExists = (bool)$this->mRepo;
- $repoPath = $wgRequest->getVal( 'wpRepoPath', $repoExists ?
$this->mRepo->mPath : '' );
- $bugPath = $wgRequest->getVal( 'wpBugPath', $repoExists ?
$this->mRepo->mBugzilla : '' );
- $viewPath = $wgRequest->getVal( 'wpViewPath', $repoExists ?
$this->mRepo->mViewVc : '' );
- if ( $wgRequest->wasPosted() && $wgUser->matchEditToken(
$wgRequest->getVal( 'wpEditToken' ), $this->mRepoName ) ) {
+ $repoExists = (bool)$this->repo;
+ $repoPath = $wgRequest->getVal( 'wpRepoPath', $repoExists ?
$this->repo->getPath() : '' );
+ $bugPath = $wgRequest->getVal( 'wpBugPath', $repoExists ?
$this->repo->getBugzillaBase() : '' );
+ $viewPath = $wgRequest->getVal( 'wpViewPath', $repoExists ?
$this->repo->getViewVcBase() : '' );
+ if ( $wgRequest->wasPosted() && $wgUser->matchEditToken(
$wgRequest->getVal( 'wpEditToken' ), $this->repoName ) ) {
// @todo log
$dbw = wfGetDB( DB_MASTER );
if ( $repoExists ) {
@@ -92,7 +131,7 @@
$dbw->insert(
'code_repo',
array(
- 'repo_name' => $this->mRepoName,
+ 'repo_name' => $this->repoName,
'repo_path' => $repoPath,
'repo_viewvc' => $viewPath,
'repo_bugzilla' => $bugPath
@@ -100,12 +139,12 @@
__METHOD__
);
}
- $wgOut->wrapWikiMsg( '<div
class="successbox">$1</div>', array( 'repoadmin-edit-sucess', $this->mRepoName
) );
+ $wgOut->wrapWikiMsg( '<div
class="successbox">$1</div>', array( 'repoadmin-edit-sucess', $this->repoName )
);
return;
}
$wgOut->addHTML(
- Xml::fieldset( wfMsg( 'repoadmin-edit-legend',
$this->mRepoName ) ) .
- Xml::openElement( 'form', array( 'method' => 'post',
'action' => $this->mPage->getTitle( $this->mRepoName )->getLocalURL() ) ) .
+ Xml::fieldset( wfMsg( 'repoadmin-edit-legend',
$this->repoName ) ) .
+ Xml::openElement( 'form', array( 'method' => 'post',
'action' => $this->title->getLocalURL() ) ) .
Xml::buildForm(
array(
'repoadmin-edit-path' =>
@@ -114,7 +153,7 @@
Xml::input( 'wpBugPath', 60,
$bugPath ),
'repoadmin-edit-view' =>
Xml::input( 'wpViewPath', 60,
$viewPath ) ) ) .
- Html::hidden( 'wpEditToken', $wgUser->editToken(
$this->mRepoName ) ) .
+ Html::hidden( 'wpEditToken', $wgUser->editToken(
$this->repoName ) ) .
Xml::submitButton( wfMsg( 'repoadmin-edit-button' ) ) .
'</form></fieldset>'
);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs