r63758 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63757‎ | r63758 | r63759 >
Date:20:48, 14 March 2010
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
Partial follow up to r63722 - will test the API module later today
Modified paths:
  • /trunk/extensions/Storyboard/api/ApiStoryReview.php (modified) (history)
  • /trunk/extensions/Storyboard/specials/Story/Story_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/specials/Story/Story_body.php
@@ -19,28 +19,29 @@
2020 parent::__construct( 'Story' );
2121 }
2222
23 - public function execute( $identifier ) {
 23+ public function execute( $title ) {
2424 wfProfileIn( __METHOD__ );
2525
26 - if ( trim( $identifier ) == '' ) {
27 - global $wgOut;
28 - $wgOut->addHTML( wfMsg( 'storyboard-nostorytitle' ) );
29 - return;
30 - }
31 -
3226 $dbr = wfGetDB( DB_SLAVE );
3327
34 - if ( is_numeric( $identifier ) ) {
 28+ if ( trim( $identifier ) != '' ) {
3529 $conds = array(
36 - 'story_id' => $identifier
 30+ 'story_title' => str_replace( '_', ' ', $title )
3731 );
3832 } else {
39 - $conds = array(
40 - 'story_title' => str_replace( '_', ' ', $identifier ) // TODO: escaping required?
41 - );
 33+ $id = $wgRequest->getIntOrNull( 'id' );
 34+ if ( $id ) {
 35+ $conds = array(
 36+ 'story_id' => $id
 37+ );
 38+ } else {
 39+ global $wgOut;
 40+ $wgOut->addWikiMsg( 'storyboard-nostorytitle' );
 41+ return;
 42+ }
4243 }
4344
44 - $stories = $dbr->Select(
 45+ $stories = $dbr->selectRow(
4546 'storyboard',
4647 array(
4748 'story_id',
Index: trunk/extensions/Storyboard/api/ApiStoryReview.php
@@ -43,7 +43,7 @@
4444 global $wgUser;
4545
4646 if ( !$wgUser->isAllowed( 'storyreview' ) || $wgUser->isBlocked() ) {
47 - $this->dieUsageMsg( array( 'storyreview' ) );
 47+ $this->dieUsageMsg( array( 'badaccess-groups' ) );
4848 }
4949
5050 $params = $this->extractRequestParams();
@@ -60,8 +60,7 @@
6161 $dbw = wfGetDB( DB_MASTER );
6262
6363 if ( $params['storyaction'] == 'delete' ) {
64 - // TODO: does this need to be escaped, or is putting the type of the param to integer sufficient?
65 - $dbw->delete( 'storyboard', "story_id = '$params[storyid]'" );
 64+ $dbw->delete( 'storyboard', array( 'story_id' => $dbw->escape( $params['storyid'] ) ) );
6665 } else {
6766 $conds = array(
6867 'story_id' => $params['storyid']
@@ -114,14 +113,24 @@
115114 'storyid' => array(
116115 ApiBase :: PARAM_TYPE => 'integer',
117116 ),
118 - 'storyaction' => null,
 117+ 'storyaction' => array(
 118+ ApiBase::PARAM_TYPE => array(
 119+ 'hide',
 120+ 'unhide',
 121+ 'publish',
 122+ 'unpublish',
 123+ 'hideimage',
 124+ 'showimage',
 125+ 'deleteimage',
 126+ )
 127+ ),
119128 );
120129 }
121130
122131 public function getParamDescription() {
123132 return array(
124 - 'storyid' => '',
125 - 'storyaction' => '',
 133+ 'storyid' => 'The id of the story you want to modify or delete',
 134+ 'storyaction' => 'Indicates in what way you want to modify the story',
126135 );
127136 }
128137

Follow-up revisions

RevisionCommit summaryAuthorDate
r63775Follow up to r63758 and r63763.jeroendedauw16:35, 15 March 2010
r63779Follow up to r63758jeroendedauw19:36, 15 March 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r63722* Added (untested) stuff to ApiStoryReview to enable ajax actions on Storyrev...jeroendedauw01:36, 14 March 2010

Comments

#Comment by Catrope (talk | contribs)   15:31, 15 March 2010
-		$stories = $dbr->Select(
+		$stories = $dbr->selectRow(

.

This won't magically work. select() returns a database result you have to grab rows from (or can use foreach() on), while selectRow() returns a single row. The code using $stories below this line needs to be updated for this.

+			$dbw->delete( 'storyboard', array( 'story_id' => $dbw->escape( $params['storyid'] ) ) );

When using the key-value format to pass WHERE conditions, you don't need to escape the values; doing so will lead to double-escaping.

+			'storyaction' => array(
+				ApiBase::PARAM_TYPE => array(
...

You seem to have forgotten about 'delete', which the code does check for.

#Comment by Jeroen De Dauw (talk | contribs)   16:37, 15 March 2010

The select stuff seems to be working though - and I don't know what else it should be. The var name should have changed though.

#Comment by Catrope (talk | contribs)   17:38, 15 March 2010

You're calling $story = $dbr->fetchObject( $story ); while $story is already a row, not a result. Apparently fetchObject() doesn't mind and it works anyway, but this behavior is not documented and could break at any time, or on DBMSes other than yours.

#Comment by Jeroen De Dauw (talk | contribs)   19:03, 15 March 2010

So how do I get a story object in the correct way? I seem unable to figure out how to do this.

#Comment by Catrope (talk | contribs)   19:20, 15 March 2010

Just use the return value of selectRow(), no need to feed it through fetchObject() first.

#Comment by Jeroen De Dauw (talk | contribs)   19:33, 15 March 2010

So I can only get it as a row, and not as an object?

Status & tagging log