From cc2aed656c7289881ba23e8ec700a4daf7889688 Mon Sep 17 00:00:00 2001
From: shadlaws <shad@shadlaws.com>
Date: Sat, 26 Jan 2013 08:38:31 +0100
Subject: #1946, 1947 - Make altered names/slugs more user-friendly, make
 conflict-finding code check filenames with no extensions - Reduced from four
 places that alter names/slugs to two (one to populate empty slugs, one to
 handle conflicting names/slugs). - For empty slugs, fill with generic
 human-readable name (e.g. "photo") instead of random value. - For conflicting
 names/slugs, add suffix that's sequential (e.g. "-01"), only using random
 after 99 conflicts. - Made conflict-finding code check filenames with no
 extensions. - Renamed _randomize_name_or_slug_on_conflict to
 _check_and_fix_conflicts. - Added unit tests.  Also cleaned up existing unit
 tests to reflect new logic and removed a redundant test. - Added installer
 logic to correct existing items now considered in conflict. - Revised
 gallery_task to look for duplicate names based on new criteria.

---
 installer/install.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index b01c5a7c..70cf0c86 100644
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -244,7 +244,7 @@ CREATE TABLE {modules} (
   KEY `weight` (`weight`)
 ) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
-INSERT INTO {modules} VALUES (1,1,'gallery',53,1);
+INSERT INTO {modules} VALUES (1,1,'gallery',54,1);
 INSERT INTO {modules} VALUES (2,1,'user',4,2);
 INSERT INTO {modules} VALUES (3,1,'comment',7,3);
 INSERT INTO {modules} VALUES (4,1,'organize',4,4);
-- 
cgit v1.2.3


From e957c97c947427093d03de3302f4d98909d1ab1a Mon Sep 17 00:00:00 2001
From: Bharat Mediratta <bharat@menalto.com>
Date: Sun, 27 Jan 2013 15:35:42 -0500
Subject: Add a key on relative_path_cache in the items table to improve
 performance on installs that use File_Proxy heavily.  Fixes #1920.

---
 installer/install.sql                         |  5 +++--
 modules/gallery/helpers/gallery_installer.php | 11 +++++++++--
 modules/gallery/module.info                   |  2 +-
 3 files changed, 13 insertions(+), 5 deletions(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index 70cf0c86..4097d51e 100644
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -186,7 +186,8 @@ CREATE TABLE {items} (
   KEY `type` (`type`),
   KEY `random` (`rand_key`),
   KEY `weight` (`weight`),
-  KEY `left_ptr` (`left_ptr`)
+  KEY `left_ptr` (`left_ptr`),
+  KEY `relative_path_cache` (`relative_path_cache`)
 ) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
 INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,2,0,NULL,'','',1,NULL,NULL,2,NULL,'weight','ASC',1,NULL,NULL,'Gallery','album',UNIX_TIMESTAMP(),0,1,NULL,'1','1');
@@ -244,7 +245,7 @@ CREATE TABLE {modules} (
   KEY `weight` (`weight`)
 ) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
-INSERT INTO {modules} VALUES (1,1,'gallery',54,1);
+INSERT INTO {modules} VALUES (1,1,'gallery',55,1);
 INSERT INTO {modules} VALUES (2,1,'user',4,2);
 INSERT INTO {modules} VALUES (3,1,'comment',7,3);
 INSERT INTO {modules} VALUES (4,1,'organize',4,4);
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 86ff7ce5..d4c4de14 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -116,7 +116,8 @@ class gallery_installer {
                  KEY `type` (`type`),
                  KEY `random` (`rand_key`),
                  KEY `weight` (`weight` DESC),
-                 KEY `left_ptr` (`left_ptr`))
+                 KEY `left_ptr` (`left_ptr`),
+                 KEY `relative_path_cache` (`relative_path_cache`))
                DEFAULT CHARSET=utf8;");
 
     $db->query("CREATE TABLE {logs} (
@@ -315,7 +316,7 @@ class gallery_installer {
     module::set_var("gallery", "lock_timeout", 1);
     module::set_var("gallery", "movie_extract_frame_time", 3);
 
-    module::set_version("gallery", 54);
+    module::set_version("gallery", 55);
   }
 
   static function upgrade($version) {
@@ -784,6 +785,12 @@ class gallery_installer {
       }
       module::set_version("gallery", $version = 54);
     }
+
+    if ($version == 54) {
+      $db->query("ALTER TABLE {items} ADD KEY `relative_path_cache` (`relative_path_cache`)");
+      module::set_version("gallery", $version = 55);
+    }
+
   }
 
   static function uninstall() {
diff --git a/modules/gallery/module.info b/modules/gallery/module.info
index b6cefe39..d79a5077 100644
--- a/modules/gallery/module.info
+++ b/modules/gallery/module.info
@@ -1,6 +1,6 @@
 name = "Gallery 3"
 description = "Gallery core application"
-version = 54
+version = 55
 author_name = "Gallery Team"
 author_url = "http://codex.galleryproject.org/Gallery:Team"
 info_url = "http://codex.galleryproject.org/Gallery3:Modules:gallery"
-- 
cgit v1.2.3


From 0a2670a19ab121fe6970f2fcdf1864cb452a76c1 Mon Sep 17 00:00:00 2001
From: shadlaws <shad@shadlaws.com>
Date: Tue, 12 Feb 2013 00:30:30 +0100
Subject: #1988 - Add movie_allow_uploads option ("always", "never", or
 "autodetect"). - gallery_installer, module.info, install.sql - add
 movie_allow_uploads variable - movie::allow_uploads (new) - return true if
 movie_allow_uploads is "always" or "autodetect" and FFmpeg found, false
 otherwise - legal_file - use movie::allow_uploads instead of
 movie::find_ffmpeg - Form_Uploadify - use movie::allow_uploads instead of
 movie::find_ffmpeg

---
 installer/install.sql                         |  5 +++--
 modules/gallery/helpers/gallery_installer.php |  8 ++++++++
 modules/gallery/helpers/legal_file.php        |  4 ++--
 modules/gallery/helpers/movie.php             | 25 +++++++++++++++++++++++++
 modules/gallery/libraries/Form_Uploadify.php  |  2 +-
 modules/gallery/module.info                   |  2 +-
 6 files changed, 40 insertions(+), 6 deletions(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index 4097d51e..b89d6b9b 100644
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -245,7 +245,7 @@ CREATE TABLE {modules} (
   KEY `weight` (`weight`)
 ) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
-INSERT INTO {modules} VALUES (1,1,'gallery',55,1);
+INSERT INTO {modules} VALUES (1,1,'gallery',56,1);
 INSERT INTO {modules} VALUES (2,1,'user',4,2);
 INSERT INTO {modules} VALUES (3,1,'comment',7,3);
 INSERT INTO {modules} VALUES (4,1,'organize',4,4);
@@ -383,7 +383,7 @@ CREATE TABLE {vars} (
   `value` text,
   PRIMARY KEY (`id`),
   UNIQUE KEY `module_name` (`module_name`,`name`)
-) AUTO_INCREMENT=46 DEFAULT CHARSET=utf8;
+) AUTO_INCREMENT=47 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
 INSERT INTO {vars} VALUES (NULL,'gallery','active_site_theme','wind');
 INSERT INTO {vars} VALUES (NULL,'gallery','active_admin_theme','admin_wind');
@@ -417,6 +417,7 @@ INSERT INTO {vars} VALUES (NULL,'gallery','extra_binary_paths','/usr/local/bin:/
 INSERT INTO {vars} VALUES (NULL,'gallery','timezone',NULL);
 INSERT INTO {vars} VALUES (NULL,'gallery','lock_timeout','1');
 INSERT INTO {vars} VALUES (NULL,'gallery','movie_extract_frame_time','3');
+INSERT INTO {vars} VALUES (NULL,'gallery','movie_allow_uploads','autodetect');
 INSERT INTO {vars} VALUES (NULL,'gallery','blocks_site_sidebar','a:4:{i:10;a:2:{i:0;s:7:\"gallery\";i:1;s:8:\"language\";}i:11;a:2:{i:0;s:4:\"info\";i:1;s:8:\"metadata\";}i:12;a:2:{i:0;s:3:\"rss\";i:1;s:9:\"rss_feeds\";}i:13;a:2:{i:0;s:3:\"tag\";i:1;s:3:\"tag\";}}');
 INSERT INTO {vars} VALUES (NULL,'gallery','identity_provider','user');
 INSERT INTO {vars} VALUES (NULL,'user','minimum_password_length','5');
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 7f10cdee..051a66cf 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -315,6 +315,7 @@ class gallery_installer {
     module::set_var("gallery", "timezone", null);
     module::set_var("gallery", "lock_timeout", 1);
     module::set_var("gallery", "movie_extract_frame_time", 3);
+    module::set_var("gallery", "movie_allow_uploads", "autodetect");
   }
 
   static function upgrade($version) {
@@ -789,6 +790,13 @@ class gallery_installer {
       module::set_version("gallery", $version = 55);
     }
 
+    if ($version == 55) {
+      // In v56, we added the ability to change the default behavior regarding movie uploads.  It
+      // can be set to "always", "never", or "autodetect" to match the previous behavior where they
+      // are allowed only if FFmpeg is found.
+      module::set_var("gallery", "movie_allow_uploads", "autodetect");
+      module::set_version("gallery", $version = 56);
+    }
   }
 
   static function uninstall() {
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index ef588ceb..debd1e6d 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -98,7 +98,7 @@ class legal_file_Core {
    */
   static function get_types_by_extension($extension=null) {
     $types_by_extension = legal_file::get_photo_types_by_extension();
-    if (movie::find_ffmpeg()) {
+    if (movie::allow_uploads()) {
       $types_by_extension = array_merge($types_by_extension,
                                         legal_file::get_movie_types_by_extension());
     }
@@ -165,7 +165,7 @@ class legal_file_Core {
    */
   static function get_extensions($extension=null) {
     $extensions = legal_file::get_photo_extensions();
-    if (movie::find_ffmpeg()) {
+    if (movie::allow_uploads()) {
       $extensions = array_merge($extensions, legal_file::get_movie_extensions());
     }
     if ($extension) {
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index d4b907a2..eda478c7 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -24,6 +24,8 @@
  * Note: by design, this class does not do any permission checking.
  */
 class movie_Core {
+  private static $allow_uploads;
+
   static function get_edit_form($movie) {
     $form = new Forge("movies/update/$movie->id", "", "post", array("id" => "g-edit-movie-form"));
     $form->hidden("from_id")->value($movie->id);
@@ -109,6 +111,29 @@ class movie_Core {
     }
   }
 
+  /**
+   * Return true if movie uploads are allowed, false if not.  This is based on the
+   * "movie_allow_uploads" Gallery variable as well as whether or not ffmpeg is found.
+   */
+  static function allow_uploads() {
+    if (empty(self::$allow_uploads)) {
+      // Refresh ffmpeg settings
+      $ffmpeg = movie::find_ffmpeg();
+      switch (module::get_var("gallery", "movie_allow_uploads", "autodetect")) {
+        case "always":
+          self::$allow_uploads = true;
+          break;
+        case "never":
+          self::$allow_uploads = false;
+          break;
+        default:
+          self::$allow_uploads = !empty($ffmpeg);
+          break;
+      }
+    }
+    return self::$allow_uploads;
+  }
+
   /**
    * Return the path to the ffmpeg binary if one exists and is executable, or null.
    */
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index 56793c69..1e58018d 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -46,7 +46,7 @@ class Form_Uploadify_Core extends Form_Input {
     $v->album = $this->data["album"];
     $v->script_data = $this->data["script_data"];
     $v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
-    $v->movies_allowed = (bool) movie::find_ffmpeg();
+    $v->movies_allowed = movie::allow_uploads();
     $v->extensions = legal_file::get_filters();
     $v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
 
diff --git a/modules/gallery/module.info b/modules/gallery/module.info
index d79a5077..2383ec3c 100644
--- a/modules/gallery/module.info
+++ b/modules/gallery/module.info
@@ -1,6 +1,6 @@
 name = "Gallery 3"
 description = "Gallery core application"
-version = 55
+version = 56
 author_name = "Gallery Team"
 author_url = "http://codex.galleryproject.org/Gallery:Team"
 info_url = "http://codex.galleryproject.org/Gallery3:Modules:gallery"
-- 
cgit v1.2.3

