BryanDavis has uploaded a new change for review. https://gerrit.wikimedia.org/r/266178
Change subject: Replace array_key_exists with isset ...................................................................... Replace array_key_exists with isset The difference between isset() and array_key_exists() is trivially that array_key_exists() can detect null member values. Most of the time this is unimportant. Change-Id: I79d4c73833912487b24d2b35b0ae7bdeb7b78a8c --- M www/content/list.php M www/content/status.php 2 files changed, 16 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs refs/changes/78/266178/1 diff --git a/www/content/list.php b/www/content/list.php index 5fb09e6..f422c3c 100644 --- a/www/content/list.php +++ b/www/content/list.php @@ -24,13 +24,13 @@ <tbody> <?php function describe( $t ) { - if ( array_key_exists( 'description', $t ) ) { - global $purifier; + global $purifier; + if ( isset( $t['description'] ) ) { echo $purifier->purify( $t['description'] ); - if ( array_key_exists( 'author', $t ) ) { + if ( isset( $t['author'] ) ) { echo '<br><i>Author(s): ', $purifier->purify( $t['author'] ), '</i>'; } - if ( array_key_exists( 'repository', $t ) ) { + if ( isset( $t['repository'] ) ) { echo '<br><a href="', htmlspecialchars( $t['repository'] ), '">Source</a>'; } } @@ -45,8 +45,7 @@ } else { $active_proxies = json_decode( $active_proxies_json, true ); foreach ( $active_proxies as $key => $value ) { - if ( array_key_exists( 'status', $value) && - $value['status'] == 'active' ) { + if ( isset( $value['status'] ) && $value['status'] == 'active' ) { $tooldyn[$key] = 1; } } @@ -72,18 +71,16 @@ $json = array( 'description' => $row['description'] ); } - if ( array_key_exists( 0, $json ) && !array_key_exists( 1, $json ) ) { + if ( isset( $json[0] ) && !isset( $json[1] ) ) { $json = $json[0]; } ?> <tr class="tool" id="toollist-<?= htmlspecialchars( $tool ) ?>"> <td class="tool-name"> <?php - if ( array_key_exists( 'url', $json ) ) { + if ( isset( $json['url'] ) ) { echo '<a class="tool-web" href="', htmlspecialchars( $json['url'] ), '">', htmlspecialchars( $tool ), '</a>'; - } elseif ( array_key_exists( $tool, $tooldyn ) && - !array_key_exists( 0, $json ) - ) { + } elseif ( isset( $tooldyn[$tool] ) && !isset( $json[0] ) ) { echo '<a class="tool-web" href="/', urlencode( $tool ), '/">', htmlspecialchars( $tool ), '</a>'; } else { echo htmlspecialchars( $tool ); @@ -94,7 +91,7 @@ <td class="tool-maintainers"> <?php foreach ( explode (' ', $row['maintainers'] ) as $maint ) { - if ( array_key_exists( $maint, $users ) ) { + if ( isset( $users[$maint] ) ) { $maint = $users[$maint]['wikitech']; ?> <a href="https://wikitech.wikimedia.org/wiki/User:<?= urlencode( $maint ) ?>"><?= htmlspecialchars( ucfirst($maint) ) ?></a> @@ -105,15 +102,15 @@ </td> <td class="tool-desc"> <?php - if ( array_key_exists( 1, $json ) ) { + if ( isset( $json[1] ) ) { $first = ' first'; foreach ( $json as $sub ) { echo '<div class="subtool', $first, '"><span class="subtool-name">'; - if ( array_key_exists( 'url', $sub ) ) { + if ( isset( $sub['url'] ) ) { echo "<a href=\"" . htmlspecialchars( $sub['url'] ) . "\">"; } echo htmlspecialchars( $sub['title'] ); - if ( array_key_exists( 'url', $sub ) ) { + if ( isset( $sub['url'] ) ) { echo '</a>'; } echo '</span><span class="subtool-desc">'; diff --git a/www/content/status.php b/www/content/status.php index 9a1029e..66e4d23 100644 --- a/www/content/status.php +++ b/www/content/status.php @@ -157,7 +157,7 @@ <tbody> <?php foreach ( $jobs as $jobid => $j ) { - if(!array_key_exists('host', $j) || $j['host'] != $host) { + if( !isset( $j['host'] ) || $j['host'] !== $host) { continue; } ?> @@ -167,13 +167,11 @@ <td class="jobtool"><a href="/?tool=<?= urlencode( $j['tool'] ) ?>"><?= htmlspecialchars( $j['tool'] ) ?></a></td> <td class="jobstate"><?= htmlspecialchars( ucfirst( $j['queue'] ) ) ?> / <?= htmlspecialchars( ucfirst( $j['state'] ) ) ?></td> <td class="jobtime"><?= strftime( '%F %T', $j['submit'] ) ?></td> -<td class="jobcpu"><?= array_key_exists('cpu', $j) ? humantime( $j['cpu'] ) : 'n/a' ?></td> +<td class="jobcpu"><?= isset( $j['cpu'] ) ? humantime( $j['cpu'] ) : 'n/a' ?></td> <td class="jobvmem"> -<?= array_key_exists('vmem', $j) ? sprintf( '%d/%d', humanmem( $j['vmem'] / 1024 / 1024 ), humanmem( $j['h_vmem'] / 1024 / 1024 ) ) : 'n/a' ?> +<?= isset( $j['vmem'] ) ? sprintf( '%d/%d', humanmem( $j['vmem'] / 1024 / 1024 ), humanmem( $j['h_vmem'] / 1024 / 1024 ) ) : 'n/a' ?> <?php - if ( array_key_exists('maxvmem', $j) && - $j['maxvmem'] > $j['vmem'] * 1.02 - ) { + if ( isset( $j['maxvmem'] ) && $j['maxvmem'] > $j['vmem'] * 1.02 ) { ?> (peak <?= humanmem( $j['maxvmem'] / 1024 / 1024 ) ?>) <?php } // end if mexvmem ?> -- To view, visit https://gerrit.wikimedia.org/r/266178 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I79d4c73833912487b24d2b35b0ae7bdeb7b78a8c Gerrit-PatchSet: 1 Gerrit-Project: labs/toollabs Gerrit-Branch: master Gerrit-Owner: BryanDavis <bda...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits