r96092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96091‎ | r96092 | r96093 >
Date:11:37, 2 September 2011
Author:reedy
Status:ok
Tags:
Comment:
Whitespace, braces, unused variables and some documentation
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeRevision.php (modified) (history)
  • /trunk/extensions/GlobalUsage/ApiQueryGlobalUsage.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsage.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageHooks.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageQuery.php (modified) (history)
  • /trunk/extensions/GlobalUsage/SpecialGlobalUsage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/GlobalUsageQuery.php
@@ -1,7 +1,7 @@
22 <?php
33 /**
44 * A helper class to query the globalimagelinks table
5 - *
 5+ *
66 */
77 class GlobalUsageQuery {
88 private $limit = 50;
@@ -27,7 +27,6 @@
2828 $this->target = Title::makeTitleSafe( NS_FILE, $target );
2929 }
3030 $this->offset = array();
31 -
3231 }
3332
3433 /**
@@ -37,11 +36,13 @@
3837 * @param $reversed bool True if this is the upper offset
3938 */
4039 public function setOffset( $offset, $reversed = null ) {
41 - if ( !is_null( $reversed ) )
 40+ if ( !is_null( $reversed ) ) {
4241 $this->reversed = $reversed;
43 -
44 - if ( !is_array( $offset ) )
 42+ }
 43+
 44+ if ( !is_array( $offset ) ) {
4545 $offset = explode( '|', $offset );
 46+ }
4647
4748 if ( count( $offset ) == 3 ) {
4849 $this->offset = $offset;
@@ -50,6 +51,7 @@
5152 return false;
5253 }
5354 }
 55+
5456 /**
5557 * Return the offset set by the user
5658 *
@@ -58,19 +60,21 @@
5961 public function getOffsetString() {
6062 return implode( '|', $this->offset );
6163 }
 64+
6265 /**
6366 * Is the result reversed
64 - *
 67+ *
6568 * @return bool
6669 */
6770 public function isReversed() {
6871 return $this->reversed;
6972 }
 73+
7074 /**
7175 * Returns the string used for continuation
72 - *
 76+ *
7377 * @return string
74 - *
 78+ *
7579 */
7680 public function getContinueString() {
7781 if ( $this->hasMore() )
@@ -101,14 +105,13 @@
102106 $this->filterLocal = $value;
103107 }
104108
105 -
106109 /**
107110 * Executes the query
108111 */
109112 public function execute() {
110113 /* Construct the SQL query */
111114 $tables = array( 'globalimagelinks' );
112 -
 115+
113116 // Add target image(s)
114117 if ( is_array( $this->target ) ) {
115118 $namespace = NS_FILE;
@@ -122,21 +125,21 @@
123126 case NS_CATEGORY:
124127 $tables[] = 'categorylinks';
125128 $tables[] = 'page';
126 - $where = array(
 129+ $where = array(
127130 'cl_to' => $this->target->getDbKey(),
128 - 'cl_from = page_id',
129 - 'page_namespace = ' . NS_FILE,
 131+ 'cl_from = page_id',
 132+ 'page_namespace = ' . NS_FILE,
130133 'gil_to = page_title',
131134 );
132135 break;
133136 default:
134137 return array();
135138 }
136 -
137 -
138 - if ( $this->filterLocal )
 139+
 140+ if ( $this->filterLocal ) {
139141 // Don't show local file usage
140142 $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiId() );
 143+ }
141144
142145 // Set the continuation condition
143146 $order = 'ASC';
@@ -144,7 +147,7 @@
145148 $qTo = $this->db->addQuotes( $this->offset[0] );
146149 $qWiki = $this->db->addQuotes( $this->offset[1] );
147150 $qPage = intval( $this->offset[2] );
148 -
 151+
149152 // Check which limit we got in order to determine which way to traverse rows
150153 if ( $this->reversed ) {
151154 // Reversed traversal; do not include offset row
@@ -157,7 +160,7 @@
158161 $op2 = '>=';
159162 $order = 'ASC';
160163 }
161 -
 164+
162165 $where[] = "(gil_to $op1 $qTo) OR " .
163166 "(gil_to = $qTo AND gil_wiki $op1 $qWiki) OR " .
164167 "(gil_to = $qTo AND gil_wiki = $qWiki AND gil_page $op2 $qPage)";
@@ -186,11 +189,13 @@
187190 // Always return the result in the same order; regardless whether reversed was specified
188191 // reversed is really only used to determine from which direction the offset is
189192 $rows = array();
190 - foreach ( $res as $row )
 193+ foreach ( $res as $row ) {
191194 $rows[] = $row;
192 - if ( $this->reversed )
 195+ }
 196+ if ( $this->reversed ) {
193197 $rows = array_reverse( $rows );
194 -
 198+ }
 199+
195200 // Build the result array
196201 $count = 0;
197202 $this->hasMore = false;
@@ -204,10 +209,12 @@
205210 break;
206211 }
207212
208 - if ( !isset( $this->result[$row->gil_to] ) )
 213+ if ( !isset( $this->result[$row->gil_to] ) ) {
209214 $this->result[$row->gil_to] = array();
210 - if ( !isset( $this->result[$row->gil_to][$row->gil_wiki] ) )
 215+ }
 216+ if ( !isset( $this->result[$row->gil_to][$row->gil_wiki] ) ) {
211217 $this->result[$row->gil_to][$row->gil_wiki] = array();
 218+ }
212219
213220 $this->result[$row->gil_to][$row->gil_wiki][] = array(
214221 'image' => $row->gil_to,
@@ -219,26 +226,28 @@
220227 );
221228 }
222229 }
 230+
223231 /**
224232 * Returns the result set. The result is a 4 dimensional array
225233 * (file, wiki, page), whose items are arrays with keys:
226 - * - image: File name
 234+ * - image: File name
227235 * - id: Page id
228236 * - namespace: Page namespace text
229237 * - title: Unprefixed page title
230238 * - wiki: Wiki id
231 - *
 239+ *
232240 * @return array Result set
233241 */
234242 public function getResult() {
235243 return $this->result;
236244 }
 245+
237246 /**
238247 * Returns a 3 dimensional array with the result of the first file. Useful
239248 * if only one image was queried.
240 - *
 249+ *
241250 * For further information see documentation of getResult()
242 - *
 251+ *
243252 * @return array Result set
244253 */
245254 public function getSingleImageResult() {
@@ -259,7 +268,7 @@
260269
261270 /**
262271 * Returns the result length
263 - *
 272+ *
264273 * @return int
265274 */
266275 public function count() {
Index: trunk/extensions/GlobalUsage/ApiQueryGlobalUsage.php
@@ -70,7 +70,7 @@
7171 if ( isset( $prop['namespace'] ) ) {
7272 $result['ns'] = $item['namespace_id'];
7373 }
74 -
 74+
7575 $fit = $apiResult->addValue( array(
7676 'query', 'pages', $pageId, 'globalusage'
7777 ), null, $result );
@@ -126,7 +126,7 @@
127127 );
128128 }
129129
130 - public function getParamDescription () {
 130+ public function getParamDescription() {
131131 return array(
132132 'prop' => array(
133133 'What properties to return',
@@ -143,7 +143,7 @@
144144 public function getDescription() {
145145 return 'Returns global image usage for a certain image';
146146 }
147 -
 147+
148148 public function getPossibleErrors() {
149149 return array_merge( parent::getPossibleErrors(), array(
150150 array ( 'code' => 'badcontinue', 'info' => 'Invalid continue parameter' ),
Index: trunk/extensions/GlobalUsage/GlobalUsage.php
@@ -33,7 +33,6 @@
3434 exit( 1 );
3535 }
3636
37 -
3837 $dir = dirname( __FILE__ ) . '/';
3938
4039 $wgExtensionCredits['specialpage'][] = array(
Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php
@@ -24,8 +24,7 @@
2525
2626 $this->showForm();
2727
28 - if ( is_null( $this->target ) )
29 - {
 28+ if ( is_null( $this->target ) ) {
3029 $wgOut->setPageTitle( wfMsg( 'globalusage' ) );
3130 return;
3231 }
@@ -34,7 +33,7 @@
3534
3635 $this->showResult();
3736 }
38 -
 37+
3938 /**
4039 * Shows the search form
4140 */
@@ -58,12 +57,9 @@
5958 // Filter local checkbox
6059 . "\n\t<p>" . Xml::checkLabel( wfMsg( 'globalusage-filterlocal' ),
6160 'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '</p>';
62 -
 61+
6362 if ( !is_null( $this->target ) && wfFindFile( $this->target ) ) {
6463 // Show the image if it exists
65 - global $wgUser;
66 - $skin = $wgUser->getSkin();
67 -
6864 $html .= Linker::makeThumbLinkObj( $this->target,
6965 wfFindFile( $this->target ),
7066 /* $label */ $this->target->getPrefixedText(),
@@ -71,7 +67,7 @@
7268 /* $handlerParams */ array(), /* $framed */ false,
7369 /* $manualThumb */ false );
7470 }
75 -
 71+
7672 // Wrap the entire form in a nice fieldset
7773 $html .= Xml::fieldSet( wfMsg( 'globalusage-text' ), $formContent ) . "\n</form>";
7874
@@ -87,10 +83,11 @@
8884 $query = new GlobalUsageQuery( $this->target );
8985
9086 // Extract params from $wgRequest
91 - if ( $wgRequest->getText( 'from' ) )
 87+ if ( $wgRequest->getText( 'from' ) ) {
9288 $query->setOffset( $wgRequest->getText( 'from' ) );
93 - elseif ( $wgRequest->getText( 'to' ) )
 89+ } elseif ( $wgRequest->getText( 'to' ) ) {
9490 $query->setOffset( $wgRequest->getText( 'to' ), true );
 91+ }
9592 $query->setLimit( $wgRequest->getInt( 'limit', 50 ) );
9693 $query->filterLocal( $this->filterLocal );
9794
@@ -119,8 +116,9 @@
120117 'globalusage-on-wiki', 'parseinline',
121118 $targetName, WikiMap::getWikiName( $wiki ) )
122119 . "</h2><ul>\n" );
123 - foreach ( $result as $item )
 120+ foreach ( $result as $item ) {
124121 $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
 122+ }
125123 $wgOut->addHtml( "</ul>\n" );
126124 }
127125 $wgOut->addHtml( '</div>' );
@@ -128,14 +126,16 @@
129127 // Bottom navbar
130128 $wgOut->addHtml( $navbar );
131129 }
 130+
132131 /**
133132 * Helper to format a specific item
134133 */
135134 public static function formatItem( $item ) {
136 - if ( !$item['namespace'] )
 135+ if ( !$item['namespace'] ) {
137136 $page = $item['title'];
138 - else
 137+ } else {
139138 $page = "{$item['namespace']}:{$item['title']}";
 139+ }
140140
141141 $link = WikiMap::makeForeignLink( $item['wiki'], $page,
142142 str_replace( '_', ' ', $page ) );
@@ -145,7 +145,7 @@
146146
147147 /**
148148 * Helper function to create the navbar, stolen from wfViewPrevNext
149 - *
 149+ *
150150 * @param $query GlobalUsageQuery An executed GlobalUsageQuery object
151151 * @return string Navbar HTML
152152 */
@@ -157,7 +157,7 @@
158158 $target = $this->target->getText();
159159 $limit = $query->getLimit();
160160 $fmtLimit = $wgLang->formatNum( $limit );
161 -
 161+
162162 # Find out which strings are for the prev and which for the next links
163163 $offset = $query->getOffsetString();
164164 $continue = $query->getContinueString();
@@ -205,7 +205,7 @@
206206 $numLinks = array();
207207 foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
208208 $fmtLimit = $wgLang->formatNum( $num );
209 -
 209+
210210 $q = array( 'offset' => $offset, 'limit' => $num, 'target' => $target );
211211 if ( $this->filterLocal )
212212 $q['filterlocal'] = '1';
Index: trunk/extensions/GlobalUsage/GlobalUsageHooks.php
@@ -43,6 +43,7 @@
4444
4545 return true;
4646 }
 47+
4748 /**
4849 * Hook to TitleMoveComplete
4950 * Sets the page title in usage table to the new name.
@@ -52,6 +53,7 @@
5354 $gu->moveTo( $pageid, $nt );
5455 return true;
5556 }
 57+
5658 /**
5759 * Hook to ArticleDeleteComplete
5860 * Deletes entries from usage table.
@@ -62,6 +64,7 @@
6365
6466 return true;
6567 }
 68+
6669 /**
6770 * Hook to FileDeleteComplete
6871 * Copies the local link table to the global.
@@ -83,6 +86,7 @@
8487 $gu->deleteLinksToFile( $title );
8588 return true;
8689 }
 90+
8791 /**
8892 * Hook to UploadComplete
8993 * Deletes the file from the global link table.
@@ -95,6 +99,8 @@
96100
97101 /**
98102 * Initializes a GlobalUsage object for the current wiki.
 103+ *
 104+ * @return GlobalUsage
99105 */
100106 private static function getGlobalUsage() {
101107 global $wgGlobalUsageDatabase;
@@ -117,6 +123,8 @@
118124
119125 /**
120126 * Hook to apply schema changes
 127+ *
 128+ * @param $updater DatabaseUpdater
121129 */
122130 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
123131 $dir = dirname( __FILE__ );
Index: trunk/extensions/CodeReview/backend/CodeRevision.php
@@ -770,8 +770,11 @@
771771 'cc_repo_id' => $this->repoId,
772772 'cc_rev_id' => $this->id );
773773
774 - if( $attached ) { $conditions['cc_patch_line!'] = null; }
775 - else { $conditions['cc_patch_line'] = null; }
 774+ if( $attached ) {
 775+ $conditions['cc_patch_line!'] = null;
 776+ } else {
 777+ $conditions['cc_patch_line'] = null;
 778+ }
776779
777780 $dbr = wfGetDB( DB_SLAVE );
778781 $result = $dbr->select( 'code_comment',

Status & tagging log