r107804 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107803‎ | r107804 | r107805 >
Date:08:00, 2 January 2012
Author:johnduhart
Status:ok
Tags:
Comment:
Code formatting
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -51,15 +51,15 @@
5252 */
5353 public static function getRevisionLimit( $pageId ) {
5454 global $wgArticleFeedbackv5RatingLifetime;
55 - $dbr = wfGetDB( DB_SLAVE );
 55+ $dbr = wfGetDB( DB_SLAVE );
5656 $revision = $dbr->selectField(
5757 'revision', 'rev_id',
5858 array( 'rev_page' => $pageId ),
5959 __METHOD__,
6060 array(
6161 'ORDER BY' => 'rev_id DESC',
62 - 'LIMIT' => 1,
63 - 'OFFSET' => $wgArticleFeedbackv5RatingLifetime - 1
 62+ 'LIMIT' => 1,
 63+ 'OFFSET' => $wgArticleFeedbackv5RatingLifetime - 1
6464 )
6565 );
6666 return $revision ? intval( $revision ) : 0;
@@ -73,32 +73,32 @@
7474 public static function getFields() {
7575 global $wgMemc;
7676
77 - $key = wfMemcKey( 'articlefeedbackv5', 'getFields' );
 77+ $key = wfMemcKey( 'articlefeedbackv5', 'getFields' );
7878 $cached = $wgMemc->get( $key );
7979
80 - if( $cached != '' ) {
 80+ if ( $cached != '' ) {
8181 return $cached;
8282 } else {
83 - $rv = array();
84 - $dbr = wfGetDB( DB_SLAVE );
 83+ $rv = array();
 84+ $dbr = wfGetDB( DB_SLAVE );
8585 $rows = $dbr->select(
8686 'aft_article_field',
87 - array(
88 - 'afi_name',
89 - 'afi_id',
90 - 'afi_data_type',
91 - 'afi_bucket_id'
 87+ array(
 88+ 'afi_name',
 89+ 'afi_id',
 90+ 'afi_data_type',
 91+ 'afi_bucket_id'
9292 ),
93 - null,
 93+ null,
9494 __METHOD__
9595 );
9696
97 - foreach( $rows as $row ) {
 97+ foreach ( $rows as $row ) {
9898 $rv[] = array(
99 - 'afi_name' => $row->afi_name,
100 - 'afi_id' => $row->afi_id,
101 - 'afi_data_type' => $row->afi_data_type,
102 - 'afi_bucket_id' => $row->afi_bucket_id
 99+ 'afi_name' => $row->afi_name,
 100+ 'afi_id' => $row->afi_id,
 101+ 'afi_data_type' => $row->afi_data_type,
 102+ 'afi_bucket_id' => $row->afi_bucket_id
103103 );
104104 }
105105
@@ -112,7 +112,7 @@
113113 /**
114114 * Gets the known feedback options
115115 *
116 - * Pulls all the rows in the aft_article_field_option table, then
 116+ * Pulls all the rows in the aft_article_field_option table, then
117117 * arranges them like so:
118118 * {field id} => array(
119119 * {option id} => {option name},
@@ -121,32 +121,32 @@
122122 * @return array the rows in the aft_article_field_option table
123123 */
124124 public static function getOptions() {
125 - global $wgMemc;
 125+ global $wgMemc;
126126
127 - $key = wfMemcKey( 'articlefeedbackv5', 'getOptions' );
128 - $cached = $wgMemc->get( $key );
 127+ $key = wfMemcKey( 'articlefeedbackv5', 'getOptions' );
 128+ $cached = $wgMemc->get( $key );
129129
130 - if( $cached != '' ) {
131 - return $cached;
132 - } else {
133 - $rv = array();
134 - $dbr = wfGetDB( DB_SLAVE );
 130+ if ( $cached != '' ) {
 131+ return $cached;
 132+ } else {
 133+ $rv = array();
 134+ $dbr = wfGetDB( DB_SLAVE );
135135 $rows = $dbr->select(
136136 'aft_article_field_option',
137 - array(
138 - 'afo_option_id',
139 - 'afo_field_id',
140 - 'afo_name'
 137+ array(
 138+ 'afo_option_id',
 139+ 'afo_field_id',
 140+ 'afo_name'
141141 ),
142 - null,
 142+ null,
143143 __METHOD__
144144 );
145145 foreach ( $rows as $row ) {
146146 $rv[$row->afo_field_id][$row->afo_option_id] = $row->afo_name;
147147 }
148 - // An hour? That might be reasonable for a cache time.
149 - $wgMemc->set( $key, $rv, 60 * 60 );
150 - }
 148+ // An hour? That might be reasonable for a cache time.
 149+ $wgMemc->set( $key, $rv, 60 * 60 );
 150+ }
151151 return $rv;
152152 }
153153 }
Index: trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php
@@ -15,12 +15,12 @@
1616 }
1717
1818 $ratings = $this->fetchOverallRating( $pageId );
19 - $found = isset( $ratings['found'] ) ? $ratings['found'] : null;
20 - $rating = isset( $ratings['rating'] ) ? $ratings['rating'] : null;
 19+ $found = isset( $ratings['found'] ) ? $ratings['found'] : null;
 20+ $rating = isset( $ratings['rating'] ) ? $ratings['rating'] : null;
2121
2222 $out->setPagetitle( "Feedback for $title" );
2323
24 - if( !$pageId ) {
 24+ if ( !$pageId ) {
2525 $out->addWikiMsg( 'articlefeedbackv5-invalid-page-id' );
2626 } else {
2727 $out->addHTML(
@@ -28,33 +28,33 @@
2929 Title::newFromText( $param ),
3030 $this->msg( 'articlefeedbackv5-go-to-article' )->escaped()
3131 )
32 - .' | '.
33 - Linker::link(
34 - Title::newFromText( $param ),
35 - $this->msg( 'articlefeedbackv5-discussion-page' )->escaped()
36 - )
37 - .' | '.
38 - Linker::link(
39 - Title::newFromText( $param ),
40 - $this->msg( 'articlefeedbackv5-whats-this' )->escaped()
41 - )
 32+ . ' | ' .
 33+ Linker::link(
 34+ Title::newFromText( $param ),
 35+ $this->msg( 'articlefeedbackv5-discussion-page' )->escaped()
 36+ )
 37+ . ' | ' .
 38+ Linker::link(
 39+ Title::newFromText( $param ),
 40+ $this->msg( 'articlefeedbackv5-whats-this' )->escaped()
 41+ )
4242 );
4343 }
4444
45 - if( $found ) {
 45+ if ( $found ) {
4646 $out->addWikiMsg( 'articlefeedbackv5-percent-found', $found );
4747 }
4848
49 - if( $rating ) {
50 - $out->addWikiMsg( 'articlefeedbackv5-overall-rating', $rating);
 49+ if ( $rating ) {
 50+ $out->addWikiMsg( 'articlefeedbackv5-overall-rating', $rating );
5151 }
5252
5353 $out->addWikiMsg( 'articlefeedbackv5-special-title' );
5454
5555 $showing = $this->msg(
5656 'articlefeedbackv5-special-showing',
57 - Html::element( 'span', array( 'id' => 'aft-feedback-count-shown' ), '0'),
58 - Html::element( 'span', array( 'id' => 'aft-feedback-count-total' ), '0')
 57+ Html::element( 'span', array( 'id' => 'aft-feedback-count-shown' ), '0' ),
 58+ Html::element( 'span', array( 'id' => 'aft-feedback-count-total' ), '0' )
5959 );
6060
6161 $out->addJsConfigVars( 'afPageId', $pageId );
@@ -62,29 +62,37 @@
6363
6464 $filterSelect = new XmlSelect( false, 'aft5-filter' );
6565 $filterSelect->addOptions( $this->selectMsg( array(
66 - 'articlefeedbackv5-special-filter-visible' => 'visible',
67 - 'articlefeedbackv5-special-filter-invisible' => 'invisible',
68 - 'articlefeedbackv5-special-filter-all' => 'all',
69 - ) ) );
 66+ 'articlefeedbackv5-special-filter-visible' => 'visible',
 67+ 'articlefeedbackv5-special-filter-invisible' => 'invisible',
 68+ 'articlefeedbackv5-special-filter-all' => 'all',
 69+ )
 70+ )
 71+ );
7072
7173 $sortSelect = new XmlSelect( false, 'aft5-sort' );
7274 $sortSelect->addOptions( $this->selectMsg( array(
73 - 'articlefeedbackv5-special-sort-newest' => 'newest',
74 - 'articlefeedbackv5-special-sort-oldest' => 'oldest',
75 - ) ) );
 75+ 'articlefeedbackv5-special-sort-newest' => 'newest',
 76+ 'articlefeedbackv5-special-sort-oldest' => 'oldest',
 77+ )
 78+ )
 79+ );
7680
77 - $out->addHTML($this->msg('articlefeedbackv5-special-filter-label-before')->escaped()
78 - . $filterSelect->getHTML()
79 - . $this->msg('articlefeedbackv5-special-filter-label-after')->escaped()
80 - . ' | '
81 - . $this->msg('articlefeedbackv5-special-sort-label-before')->escaped()
82 - . $sortSelect->getHTML()
83 - . $this->msg('articlefeedbackv5-special-sort-label-after')->escaped()
84 - . Html::element( 'span', array( 'id' => 'aft-showing' ), $showing )
85 - . Html::element( 'div', array( 'id' => 'aft5-show-feedback',
86 - 'style' => 'border:1px solid red;' ), '' )
87 - . Html::element( 'a', array( 'href' => '#', 'id' => 'aft5-show-more' ),
88 - $this->msg( 'articlefeedbackv5-special-more' )->escaped() )
 81+ $out->addHTML( $this->msg( 'articlefeedbackv5-special-filter-label-before' )->escaped()
 82+ . $filterSelect->getHTML()
 83+ . $this->msg( 'articlefeedbackv5-special-filter-label-after' )->escaped()
 84+ . ' | '
 85+ . $this->msg( 'articlefeedbackv5-special-sort-label-before' )->escaped()
 86+ . $sortSelect->getHTML()
 87+ . $this->msg( 'articlefeedbackv5-special-sort-label-after' )->escaped()
 88+ . Html::element( 'span', array( 'id' => 'aft-showing' ), $showing )
 89+ . Html::element( 'div', array(
 90+ 'id' => 'aft5-show-feedback',
 91+ 'style' => 'border:1px solid red;'
 92+ ), ''
 93+ )
 94+ . Html::element( 'a', array( 'href' => '#', 'id' => 'aft5-show-more' ),
 95+ $this->msg( 'articlefeedbackv5-special-more' )->escaped()
 96+ )
8997 );
9098 }
9199
@@ -105,28 +113,28 @@
106114 }
107115
108116 private function fetchOverallRating( $pageId ) {
109 - $rv = array();
110 - $dbr = wfGetDB( DB_SLAVE );
 117+ $rv = array();
 118+ $dbr = wfGetDB( DB_SLAVE );
111119 $rows = $dbr->select(
112 - array(
 120+ array(
113121 'aft_article_feedback_ratings_rollup',
114 - 'aft_article_field'
 122+ 'aft_article_field'
115123 ),
116 - array(
 124+ array(
117125 'arr_total / arr_count AS rating',
118126 'afi_name'
119127 ),
120 - array(
 128+ array(
121129 'arr_page_id' => $pageId,
122130 'arr_field_id = afi_id',
123131 "afi_name IN ('found', 'rating')"
124132 )
125133 );
126134
127 - foreach( $rows as $row ) {
128 - if( $row->afi_name == 'found' ) {
129 - $rv['found'] = ( int ) ( 100 * $row->rating );
130 - } elseif( $row->afi_name == 'rating' ) {
 135+ foreach ( $rows as $row ) {
 136+ if ( $row->afi_name == 'found' ) {
 137+ $rv['found'] = ( int ) ( 100 * $row->rating );
 138+ } elseif ( $row->afi_name == 'rating' ) {
131139 $rv['rating'] = ( int ) $row->rating;
132140 }
133141 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105726AFTv5 - enable memcache for a couple of common lookup queries.gregchiasson22:20, 9 December 2011

Status & tagging log