Replace a few more logical operators
authorKevin Israel <pleasestand@live.com>
Fri, 24 Oct 2014 14:42:19 +0000 (10:42 -0400)
committerKevin Israel <pleasestand@live.com>
Fri, 24 Oct 2014 15:41:00 +0000 (11:41 -0400)
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
includes/db/DatabaseMssql.php
maintenance/generateSitemap.php

index b4e4e2a..40ebaea 100644 (file)
@@ -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 {
index ab8d366..669525a 100644 (file)
@@ -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 );
index 1930a22..12711ea 100644 (file)
@@ -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
         */