r105252 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105251‎ | r105252 | r105253 >
Date:23:56, 5 December 2011
Author:rsterbin
Status:resolved (Comments)
Tags:
Comment:
Tweaks and bug fixes for API uils class, as per Roan's review:
- Fixed incorrect global of $wgArticleFeedbackNamespaces
- Removed getRevisionId(), removed pointless use in view ratings api call
(rev id is never used), and replaced use in submit api call with
$title->getLatestRevID()
- Fixed doc block for getFields()
- Removed if statement to create an array before appending in getOptions()
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -323,7 +323,8 @@
324324
325325 # Fetch this if it wasn't passed in
326326 if ( !$revId ) {
327 - $revId = ApiArticleFeedbackv5Utils::getRevisionId( $params['pageid'] );
 327+ $title = Title::newFromID( $params['pageid'] );
 328+ $revId = $title->getLatestRevID();
328329 }
329330
330331 $dbw->insert( 'aft_article_feedback', array(
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -51,7 +51,7 @@
5252 * @return bool
5353 */
5454 public static function isFeedbackEnabled( $params ) {
55 - global $wgArticleFeedbackNamespaces;
 55+ global $wgArticleFeedbackv5Namespaces;
5656 $title = Title::newFromID( $params['pageid'] );
5757 if (
5858 // not an existing page?
@@ -90,32 +90,11 @@
9191 }
9292
9393 /**
94 - * Gets the most recent revision id for a page id
95 - *
96 - * @param $pageId int the page id
97 - * @return int the revision id
98 - */
99 - public static function getRevisionId( $pageId ) {
100 - $dbr = wfGetDB( DB_SLAVE );
101 - $revId = $dbr->selectField(
102 - 'revision', 'rev_id',
103 - array( 'rev_page' => $pageId ),
104 - __METHOD__,
105 - array(
106 - 'ORDER BY' => 'rev_id DESC',
107 - 'LIMIT' => 1
108 - )
109 - );
110 -
111 - return $revId;
112 - }
113 -
114 - /**
11594 * Gets the known feedback fields
11695 *
11796 * TODO: use memcache
11897 *
119 - * @return array the rows in the aft_article_field table
 98+ * @return ResultWrapper the rows in the aft_article_field table
12099 */
121100 public static function getFields() {
122101 $dbr = wfGetDB( DB_SLAVE );
@@ -147,9 +126,6 @@
148127 );
149128 $rv = array();
150129 foreach ( $rows as $row ) {
151 - if ( !isset( $rv[$row->afo_field_id] ) ) {
152 - $rv[$row->afo_field_id] = array();
153 - }
154130 $rv[$row->afo_field_id][$row->afo_option_id] = $row->afo_name;
155131 }
156132 return $rv;
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewRatingsArticleFeedbackv5.php
@@ -34,7 +34,6 @@
3535 $params = $this->extractRequestParams();
3636 $result = $this->getResult();
3737 $result_path = array( 'query', $this->getModuleName() );
38 - $revisionId = ApiArticleFeedbackv5Utils::getRevisionId( $params['pageid'] );
3938 $pageId = $params['pageid'];
4039 $rollup = $this->fetchRollup( $pageId );
4140

Follow-up revisions

RevisionCommit summaryAuthorDate
r106018Fix for r105252: Not checking the result of Title::newFromID could cause a fa...rsterbin13:06, 13 December 2011

Comments

#Comment by Catrope (talk | contribs)   15:06, 12 December 2011
-			$revId = ApiArticleFeedbackv5Utils::getRevisionId( $params['pageid'] );
+			$title = Title::newFromID( $params['pageid'] );
+			$revId = $title->getLatestRevID();

This will cause a fatal error if the given page ID is invalid, because newFromID() returns null in that case. Should be easy to reproduce by passing pageid=0.

OK otherwise, marking fixme because of the fatal.

#Comment by Rsterbin (talk | contribs)   13:07, 13 December 2011

Fixed in r106018 -- thanks!

Status & tagging log