From 36c0da63cdb76cbbfaaf3c8b307cd2831a4643de Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Fri, 24 Oct 2014 10:42:19 -0400 Subject: [PATCH] Replace a few more logical operators Changed all remaining uses of 'and' (T_LOGICAL_AND) and 'or' (T_LOGICAL_OR) except those in includes/libs/lessc.inc.php. In maintenance/generateSitemap.php, also slightly cleaned up touched code: * Inlined GenerateSitemap::init_path(). * Removed the redundant `$fspath && !is_dir( $fspath )` check. * Return a nonzero exit code if wfMkdirParents() fails. There are still uses of 'xor' (T_LOGICAL_XOR) in the following files, which I left as-is: * includes/Export.php * includes/htmlform/HTMLCheckField.php * includes/Autopromote.php * maintenance/importDump.php * maintenance/backup.inc Change-Id: I73cb20da989e90b52782e7499f633debd5ad265d --- includes/Linker.php | 2 +- includes/db/DatabaseMssql.php | 6 +----- maintenance/generateSitemap.php | 23 ++++++++--------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index b4e4e2a0f0..40ebaea70f 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -219,7 +219,7 @@ class Linker { # If we don't know whether the page exists, let's find out. wfProfileIn( __METHOD__ . '-checkPageExistence' ); - if ( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) { + if ( !in_array( 'known', $options ) && !in_array( 'broken', $options ) ) { if ( $target->isKnown() ) { $options[] = 'known'; } else { diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index ab8d366467..669525ac25 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -953,12 +953,8 @@ class DatabaseMssql extends DatabaseBase { // Matches: LIMIT {[offset,] row_count | row_count OFFSET offset} $pattern = '/\bLIMIT\s+((([0-9]+)\s*,\s*)?([0-9]+)(\s+OFFSET\s+([0-9]+))?)/i'; if ( preg_match( $pattern, $sql, $matches ) ) { - // row_count = $matches[4] $row_count = $matches[4]; - // offset = $matches[3] OR $matches[6] - $offset = $matches[3] or - $offset = $matches[6] or - $offset = false; + $offset = $matches[3] ?: $matches[6] ?: false; // strip the matching LIMIT clause out $sql = str_replace( $matches[0], '', $sql ); diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index 1930a22a13..12711ea3ff 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -181,7 +181,14 @@ class GenerateSitemap extends Maintenance { $this->setNamespacePriorities(); $this->url_limit = 50000; $this->size_limit = pow( 2, 20 ) * 10; - $this->fspath = self::init_path( $this->getOption( 'fspath', getcwd() ) ); + + # Create directory if needed + $fspath = $this->getOption( 'fspath', getcwd() ); + if ( !wfMkdirParents( $fspath, null, __METHOD__ ) ) { + $this->error( "Can not create directory $fspath.", 1 ); + } + + $this->fspath = realpath( $fspath ) . DIRECTORY_SEPARATOR; $this->urlpath = $this->getOption( 'urlpath', "" ); if ( $this->urlpath !== "" && substr( $this->urlpath, -1 ) !== '/' ) { $this->urlpath .= '/'; @@ -238,20 +245,6 @@ class GenerateSitemap extends Maintenance { } } - /** - * Create directory if it does not exist and return pathname with a trailing slash - * @param string $fspath - * @return null|string - */ - private static function init_path( $fspath ) { - # Create directory if needed - if ( $fspath && !is_dir( $fspath ) ) { - wfMkdirParents( $fspath, null, __METHOD__ ) or die( "Can not create directory $fspath.\n" ); - } - - return realpath( $fspath ) . DIRECTORY_SEPARATOR; - } - /** * Generate a one-dimensional array of existing namespaces */ -- 2.20.1