r47395 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47394‎ | r47395 | r47396 >
Date:23:33, 17 February 2009
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
Allow multiple revisions to be changed at the same time in list views.
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionListView.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -43,6 +43,7 @@
4444 'code-field-comments' => 'Notes',
4545 'code-field-path' => 'Path',
4646 'code-field-text' => 'Note',
 47+ 'code-field-select' => 'Select',
4748 'code-rev-author' => 'Author:',
4849 'code-rev-date' => 'Date:',
4950 'code-rev-message' => 'Comment:',
@@ -76,6 +77,11 @@
7778 'code-rev-submit' => 'Save changes',
7879 'code-rev-submit-next' => 'Save & next unresolved',
7980
 81+ 'code-batch-status' => 'Change status:',
 82+ 'code-batch-tags' => 'Change tags:',
 83+ 'codereview-batch-title' => 'Change all selected revisions',
 84+ 'codereview-batch-submit' => 'Submit',
 85+
8086 'code-releasenotes' => 'release notes',
8187 'code-release-legend' => 'Generate release notes',
8288 'code-release-startrev' => 'Start rev:',
Index: trunk/extensions/CodeReview/CodeRevisionListView.php
@@ -15,22 +15,117 @@
1616 }
1717
1818 function execute() {
19 - global $wgOut;
 19+ global $wgOut, $wgUser, $wgRequest;
2020 if( !$this->mRepo ) {
2121 $view = new CodeRepoListView();
2222 $view->execute();
2323 return;
2424 }
 25+
 26+ // Check for batch change requests.
 27+ $editToken = $wgRequest->getVal( 'wpBatchChangeEditToken' );
 28+ if ( $wgUser->matchEditToken( $editToken ) ) {
 29+ $this->doBatchChange();
 30+ return;
 31+ }
 32+
2533 $this->showForm();
2634 $pager = $this->getPager();
 35+
 36+ // Batch change interface.
 37+ $changeInterface = $this->buildBatchInterface( $pager );
 38+
2739 $wgOut->addHTML(
2840 $pager->getNavigationBar() .
2941 $pager->getLimitForm() .
 42+ Xml::openElement( 'form',
 43+ array(
 44+ 'action' => $pager->getTitle()->getLocalURL(),
 45+ 'method' => 'POST'
 46+ ) ) .
3047 $pager->getBody() .
31 - $pager->getNavigationBar()
 48+ $pager->getNavigationBar() .
 49+ $changeInterface .
 50+ Xml::closeElement( 'form' )
3251 );
3352 }
3453
 54+ function doBatchChange() {
 55+ global $wgRequest;
 56+
 57+ $revisions = $wgRequest->getArray( 'wpRevisionSelected' );
 58+ $removeTags = $wgRequest->getVal( 'wpRemoveTag' );
 59+ $addTags = $wgRequest->getVal( 'wpTag' );
 60+ $status = $wgRequest->getVal( 'wpStatus' );
 61+
 62+ // Grab data from the DB
 63+ $dbr = wfGetDB( DB_SLAVE );
 64+ $revObjects = array();
 65+ $res = $dbr->select( 'code_rev', '*', array( 'cr_id' => $revisions ), __METHOD__ );
 66+ while( $row = $dbr->fetchObject( $res ) ) {
 67+ $revObjects[] = CodeRevision::newFromRow( $this->mRepo, $row );
 68+ }
 69+
 70+ global $wgUser;
 71+ if ( $wgUser->isAllowed( 'codereview-add-tag' ) &&
 72+ $addTags || $removeTags ) {
 73+ $addTags = array_map( 'trim', explode( ",", $addTags ) );
 74+ $removeTags = array_map( 'trim', explode( ",", $removeTags ) );
 75+
 76+ foreach( $revObjects as $id => $rev ) {
 77+ $rev->changeTags( $addTags, $removeTags, $wgUser );
 78+ }
 79+ }
 80+
 81+ if( $wgUser->isAllowed( 'codereview-set-status' ) &&
 82+ $revObjects[0]->isValidStatus( $status ) ) {
 83+ foreach( $revObjects as $id => $rev ) {
 84+ $rev->setStatus( $status, $wgUser );
 85+ }
 86+ }
 87+
 88+ // Automatically refresh
 89+ // This way of getting GET parameters is horrible, but effective.
 90+ $fields = array_merge( $_GET, $_POST );
 91+ foreach( array_keys( $fields ) as $key ) {
 92+ if ( substr( $key, 0, 2 ) == 'wp' || $key == 'title' )
 93+ unset( $fields[$key] );
 94+ }
 95+
 96+ global $wgOut;
 97+ $wgOut->redirect( $this->getPager()->getTitle()->getFullURL( $fields ) );
 98+ }
 99+
 100+ function buildBatchInterface( $pager ) {
 101+ global $wgUser;
 102+
 103+ $changeInterface = '';
 104+ $changeFields = array();
 105+
 106+ if( $wgUser->isAllowed( 'codereview-set-status' ) ) {
 107+ $changeFields['code-batch-status'] =
 108+ Xml::tags( 'select', array( 'name' => 'wpStatus' ),
 109+ Xml::tags( 'option',
 110+ array( 'value' => '', 'selected' => 'selected' ), ' '
 111+ ) .
 112+ CodeRevisionView::buildStatusList( null, $this )
 113+ );
 114+ }
 115+
 116+ if ($wgUser->isAllowed( 'codereview-add-tag' ) ) {
 117+ $changeFields['code-batch-tags'] =
 118+ CodeRevisionView::addTagForm( '', '' );
 119+ }
 120+
 121+ $changeInterface = Xml::fieldset( wfMsg('codereview-batch-title'),
 122+ Xml::buildForm( $changeFields, 'codereview-batch-submit' ) );
 123+
 124+ $changeInterface .= $pager->getHiddenFields();
 125+ $changeInterface .= Xml::hidden( 'wpBatchChangeEditToken', $wgUser->editToken() );
 126+
 127+ return $changeInterface;
 128+ }
 129+
35130 function showForm( $path = '' ) {
36131 global $wgOut, $wgScript;
37132 if( $this->mAuthor ) {
@@ -117,6 +212,7 @@
118213
119214 function getFieldNames() {
120215 return array(
 216+ 'selectforchange' => wfMsg( 'code-field-select' ),
121217 $this->getDefaultSort() => wfMsg( 'code-field-id' ),
122218 'cr_status' => wfMsg( 'code-field-status' ),
123219 'comments' => wfMsg( 'code-field-comments' ),
@@ -132,6 +228,10 @@
133229 function formatRevValue( $name, $value, $row ) {
134230 global $wgUser, $wgLang;
135231 switch( $name ) {
 232+ case 'selectforchange':
 233+ $sort = $this->getDefaultSort();
 234+ return Xml::check( "wpRevisionSelected[]", false,
 235+ array( 'value' => $row->$sort ) );
136236 case 'cp_rev_id':
137237 case 'cr_id':
138238 return $this->mView->mSkin->link(
Index: trunk/extensions/CodeReview/CodeRevisionView.php
@@ -205,7 +205,7 @@
206206 ) . ' ';
207207 }
208208 if( $wgUser->isAllowed( 'codereview-add-tag' ) ) {
209 - $list .= $this->addTagForm();
 209+ $list .= $this->addTagForm( $this->mAddTags, $this->mRemoveTags );
210210 }
211211 return $list;
212212 }
@@ -223,7 +223,7 @@
224224 return $tags;
225225 }
226226
227 - protected function listTags( $tags ) {
 227+ static function listTags( $tags ) {
228228 if( empty($tags) )
229229 return "";
230230 return implode(",",$tags);
@@ -235,30 +235,31 @@
236236 $repo = $this->mRepo->getName();
237237 $rev = $this->mRev->getId();
238238 return Xml::openElement( 'select', array( 'name' => 'wpStatus' ) ) .
239 - $this->buildStatusList() . xml::closeElement('select');
 239+ self::buildStatusList( $this->mRev->getStatus(), $this ) .
 240+ xml::closeElement('select');
240241 } else {
241242 return htmlspecialchars( $this->statusDesc( $this->mRev->getStatus() ) );
242243 }
243244 }
244245
245 - protected function buildStatusList() {
 246+ static function buildStatusList( $status, $view ) {
246247 $states = CodeRevision::getPossibleStates();
247248 $out = '';
248249 foreach( $states as $state ) {
249 - $out .= Xml::option( $this->statusDesc( $state ), $state, $this->mStatus === $state );
 250+ $out .= Xml::option( $view->statusDesc( $state ), $state,
 251+ $status === $state );
250252 }
251253 return $out;
252254 }
253255
254 - protected function addTagForm() {
 256+ /** Parameters are the tags to be added/removed sent with the request */
 257+ static function addTagForm( $addTags, $removeTags ) {
255258 global $wgUser;
256 - $repo = $this->mRepo->getName();
257 - $rev = $this->mRev->getId();
258259 return '<div><table><tr><td>' .
259260 Xml::inputLabel( wfMsg('code-rev-tag-add'), 'wpTag', 'wpTag', 20,
260 - $this->listTags($this->mAddTags) ) . '</td><td>&nbsp;</td><td>' .
 261+ self::listTags( $addTags ) ) . '</td><td>&nbsp;</td><td>' .
261262 Xml::inputLabel( wfMsg('code-rev-tag-remove'), 'wpRemoveTag', 'wpRemoveTag', 20,
262 - $this->listTags($this->mRemoveTags) ) . '</td></tr></table></div>';
 263+ self::listTags( $removeTags ) ) . '</td></tr></table></div>';
263264 }
264265
265266 protected function formatTag( $tag ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r47415Fixed broken XHTML from r47395aaron03:13, 18 February 2009
r69704*(bug 24468) Invalid repo ID in CodeRevision::newFromRow...reedy19:57, 21 July 2010
r70811Cleanup r47395, at least use WebRequest::getValues() rather than merging $_GE...demon12:51, 10 August 2010

Comments

#Comment by Catrope (talk | contribs)   20:04, 21 July 2010
+		// Automatically refresh
+		// This way of getting GET parameters is horrible, but effective.
+		$fields = array_merge( $_GET, $_POST );
+		foreach( array_keys( $fields ) as $key ) {
+			if ( substr( $key, 0, 2 ) == 'wp' || $key == 'title' )
+				unset( $fields[$key] );
+		}
+		
+		global $wgOut;
+		$wgOut->redirect( $this->getPager()->getTitle()->getFullURL( $fields ) );

This is indeed horrible, as the comment says. The least you could do is use $wgRequest->getData() instead of array_merge( $_GET, $_POST );. There's a reason we built an entire class around $_REQUEST and your array_merge() only scratches the surface.

#Comment by 😂 (talk | contribs)   12:51, 10 August 2010

Resolved in r70811?

#Comment by Reedy (talk | contribs)   12:57, 10 August 2010

Putting back to deferred. You've done the "least" Roan asked for ;)

Status & tagging log