diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-02-26 09:58:57 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-02-26 09:58:57 -0800 |
commit | f28b80fcf43e02ca65f419eb6774321dc30a2a37 (patch) | |
tree | 34d3e44e5716751f71d10de623228bd541b487ae /modules/gallery | |
parent | 9f810150532a2511bfc5f03c9d24fd592d2f803f (diff) | |
parent | b4922f4d176662976c9d2b249edf0e50a0cdfdf1 (diff) |
Merge branch 'master' into talmdal_dev
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/controllers/admin_maintenance.php | 5 | ||||
-rw-r--r-- | modules/gallery/controllers/l10n_client.php | 2 | ||||
-rw-r--r-- | modules/gallery/controllers/packager.php | 1 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 12 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/locales.php | 1 | ||||
-rw-r--r-- | modules/gallery/libraries/Gallery_I18n.php | 46 | ||||
-rw-r--r-- | modules/gallery/libraries/Menu.php | 17 | ||||
-rw-r--r-- | modules/gallery/libraries/drivers/Cache/Database.php | 14 | ||||
-rw-r--r-- | modules/gallery/module.info | 2 | ||||
-rw-r--r-- | modules/gallery/tests/Access_Helper_Test.php | 9 | ||||
-rw-r--r-- | modules/gallery/tests/Cache_Test.php | 4 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Helper_Test.php | 3 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Rest_Helper_Test.php | 4 | ||||
-rw-r--r-- | modules/gallery/tests/xss_data.txt | 41 | ||||
-rw-r--r-- | modules/gallery/views/admin_languages.html.php | 15 |
17 files changed, 117 insertions, 63 deletions
diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index d90fe0ea..c16c5c41 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -209,9 +209,10 @@ class Admin_Maintenance_Controller extends Admin_Controller { message::success(t("Task failed")); break; } + // Using sprintf("%F") to avoid comma as decimal separator. print json_encode(array("result" => "success", "task" => array( - "percent_complete" => $task->percent_complete, + "percent_complete" => sprintf("%F", $task->percent_complete), "status" => (string) $task->status, "done" => (bool) $task->done), "location" => url::site("admin/maintenance"))); @@ -219,7 +220,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { } else { print json_encode(array("result" => "in_progress", "task" => array( - "percent_complete" => $task->percent_complete, + "percent_complete" => sprintf("%F", $task->percent_complete), "status" => (string) $task->status, "done" => (bool) $task->done))); } diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index e20bab50..be0aaa11 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -80,6 +80,8 @@ class L10n_Client_Controller extends Controller { $entry->save(); + Gallery_I18n::clear_cache($locale); + print json_encode(new stdClass()); } diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 66626483..aef032a0 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -82,6 +82,7 @@ class Packager_Controller extends Controller { module::set_var("gallery", "blocks_{$key}", serialize($blocks)); } + Database::instance()->query("TRUNCATE {caches}"); Database::instance()->query("TRUNCATE {sessions}"); Database::instance()->query("TRUNCATE {logs}"); db::build() diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 84f8a7fb..a43b180b 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_Core { - const VERSION = "3.0 git (pre-RC1)"; + const VERSION = "3.0 RC1 (Santa Fe)"; /** * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index b594ddcf..6f8a6688 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -32,6 +32,10 @@ class gallery_installer { PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;"); + // Using a simple index instead of a unique key for the + // key column to avoid handling of concurrency issues + // on insert. Thus allowing concurrent inserts on the + // same cache key, as does Memcache / xcache. $db->query("CREATE TABLE {caches} ( `id` int(9) NOT NULL auto_increment, `key` varchar(255) NOT NULL, @@ -39,6 +43,7 @@ class gallery_installer { `expiration` int(9) NOT NULL, `cache` longblob, PRIMARY KEY (`id`), + KEY (`key`), KEY (`tags`)) DEFAULT CHARSET=utf8;"); @@ -290,7 +295,7 @@ class gallery_installer { module::set_var("gallery", "credits", (string) $powered_by_string); module::set_var("gallery", "simultaneous_upload_limit", 5); module::set_var("gallery", "admin_area_timeout", 90 * 60); - module::set_version("gallery", 29); + module::set_version("gallery", 30); } static function upgrade($version) { @@ -545,6 +550,11 @@ class gallery_installer { module::set_var("gallery", "credits", "Powered by <a href=\"%url\">%gallery_version</a>"); module::set_version("gallery", $version = 29); } + + if ($version == 29) { + $db->query("ALTER TABLE {caches} ADD KEY (`key`);"); + module::set_version("gallery", $version = 30); + } } static function uninstall() { diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 3e6278e5..617f7f48 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -201,6 +201,8 @@ class gallery_task_Core { $total = $num_fetched + $num_remaining; $task->percent_complete = 70 + 30 * ((float) $num_fetched / $total); } else { + Gallery_I18n::clear_cache(); + $task->done = true; $task->state = "success"; $task->status = t("Translations installed/updated"); diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index e72d7ed9..62b08fb9 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -81,6 +81,7 @@ class locales_Core { $l["eu_ES"] = "Euskara"; // Basque $l["fa_IR"] = "فارس"; // Farsi $l["fi_FI"] = "Suomi"; // Finnish + $l["fo_FO"] = "Føroyskt"; // Faroese $l["fr_FR"] = "Français"; // French $l["ga_IE"] = "Gaeilge"; // Irish $l["he_IL"] = "עברית"; // Hebrew diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php index ac0588e3..f1e77744 100644 --- a/modules/gallery/libraries/Gallery_I18n.php +++ b/modules/gallery/libraries/Gallery_I18n.php @@ -150,33 +150,44 @@ class Gallery_I18n_Core { private function lookup($locale, $message) { if (!isset($this->_cache[$locale])) { - $this->_cache[$locale] = array(); - // TODO: Load data from locale file instead of the DB. + $this->_cache[$locale] = self::load_translations($locale); + } + + $key = self::get_message_key($message); + + if (isset($this->_cache[$locale][$key])) { + return $this->_cache[$locale][$key]; + } else { + return null; + } + } + + private static function load_translations($locale) { + $cache_key = "translation|" . $locale; + $cache = Cache::instance(); + $translations = $cache->get($cache_key); + if (!isset($translations) || !is_array($translations)) { + $translations = array(); foreach (db::build() ->select("key", "translation") ->from("incoming_translations") ->where("locale", "=", $locale) ->execute() as $row) { - $this->_cache[$locale][$row->key] = unserialize($row->translation); + $translations[$row->key] = unserialize($row->translation); } - + // Override incoming with outgoing... foreach (db::build() ->select("key", "translation") ->from("outgoing_translations") ->where("locale", "=", $locale) ->execute() as $row) { - $this->_cache[$locale][$row->key] = unserialize($row->translation); + $translations[$row->key] = unserialize($row->translation); } + + $cache->set($cache_key, $translations, array("translation"), 0); } - - $key = self::get_message_key($message); - - if (isset($this->_cache[$locale][$key])) { - return $this->_cache[$locale][$key]; - } else { - return null; - } + return $translations; } public function has_translation($message, $options=null) { @@ -256,6 +267,15 @@ class Gallery_I18n_Core { return $this->_call_log; } + public static function clear_cache($locale=null) { + $cache = Cache::instance(); + if ($locale) { + $cache->delete("translation|" . $locale); + } else { + $cache->delete_tag("translation"); + } + } + private static function get_plural_key($locale, $count) { $parts = explode('_', $locale); $language = $parts[0]; diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php index 7c76ab04..fef07916 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -184,7 +184,7 @@ class Menu_Core extends Menu_Element { } /** - * Add a new element to this menu + * Add a new element to this menu, after the specific element */ public function add_after($target_id, $new_menu_element) { $copy = array(); @@ -199,6 +199,21 @@ class Menu_Core extends Menu_Element { } /** + * Add a new element to this menu, before the specific element + */ + public function add_before($target_id, $new_menu_element) { + $copy = array(); + foreach ($this->elements as $id => $menu_element) { + if ($id == $target_id) { + $copy[$new_menu_element->id] = $new_menu_element; + } + $copy[$id] = $menu_element; + } + $this->elements = $copy; + return $this; + } + + /** * Remove an element from the menu */ public function remove($target_id) { diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index 82a09ab9..ff982396 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -130,7 +130,7 @@ class Cache_Database_Driver extends Cache_Driver { // Make sure the expiration is valid and that the hash matches if ($cache->expiration != 0 && $cache->expiration <= time()) { // Cache is not valid, delete it now - $this->delete($cache->id); + $this->delete(array($cache->id)); } else { // Disable notices for unserializing $ER = error_reporting(~E_NOTICE); @@ -153,15 +153,17 @@ class Cache_Database_Driver extends Cache_Driver { * @param bool delete a tag * @return bool */ - public function delete($id, $tag=false) { + public function delete($keys, $is_tag=false) { $db = db::build() ->delete("caches"); - if ($id === true) { + if ($keys === true) { // Delete all caches - } else if ($tag === true) { - $db->where("tags", "LIKE", "%<$id>%"); + } else if ($is_tag === true) { + foreach ($keys as $tag) { + $db->where("tags", "LIKE", "%<$tag>%"); + } } else { - $db->where("key", "=", $id); + $db->where("key", "IN", $keys); } $status = $db->execute(); diff --git a/modules/gallery/module.info b/modules/gallery/module.info index 39615e1c..df2be978 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 29 +version = 30 diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 5331117d..6eca396c 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -20,6 +20,10 @@ class Access_Helper_Test extends Gallery_Unit_Test_Case { private $_group; + public function setup() { + identity::set_active_user(identity::guest()); + } + public function teardown() { try { $group = identity::lookup_group_by_name("access_test"); @@ -41,10 +45,7 @@ class Access_Helper_Test extends Gallery_Unit_Test_Case { // Reset some permissions that we mangle below access::allow(identity::everybody(), "view", item::root()); - } - - public function setup() { - identity::set_active_user(identity::guest()); + identity::set_active_user(identity::admin_user()); } public function groups_and_permissions_are_bound_to_columns_test() { diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index 1023568b..a942a292 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -118,7 +118,7 @@ class Cache_Test extends Gallery_Unit_Test_Case { $value3 = array("field5" => "value5", "field6" => "value6"); $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); - $this->_driver->delete($id1); + $this->_driver->delete(array($id1)); $this->assert_false($this->_driver->exists($id1), "$id1 should have been deleted"); $this->assert_true($this->_driver->exists($id2), "$id2 should not have been deleted"); @@ -138,7 +138,7 @@ class Cache_Test extends Gallery_Unit_Test_Case { $value3 = array("field5" => "value5", "field6" => "value6"); $this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600); - $data = $this->_driver->delete("tag3", true); + $data = $this->_driver->delete_tag(array("tag3")); $this->assert_true($this->_driver->exists($id1), "$id1 should not have been deleted"); $this->assert_false($this->_driver->exists($id2), "$id2 should have been deleted"); diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 50587702..90106562 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -18,8 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Item_Helper_Test extends Gallery_Unit_Test_Case { - - public function setup() { + public function teardown() { identity::set_active_user(identity::admin_user()); } diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 6d1dd864..7b86c153 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { + public function teardown() { + identity::set_active_user(identity::admin_user()); + } + public function resolve_test() { $album = test::random_album(); $resolved = rest::resolve(rest::url("item", $album)); diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 44233459..a3ca31f4 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -218,8 +218,8 @@ modules/gallery/views/upgrader.html.php 77 DIRTY $modul modules/gallery/views/upgrader.html.php 99 DIRTY_ATTR $done?"muted":"" modules/gallery/views/upgrader.html.php 102 DIRTY_ATTR $done?"muted":"" modules/gallery/views/user_languages_block.html.php 2 DIRTY form::dropdown("g-select-session-locale",$installed_locales,$selected) -modules/gallery/views/user_profile.html.php 36 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true)) -modules/gallery/views/user_profile.html.php 47 DIRTY $info->view +modules/gallery/views/user_profile.html.php 34 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true)) +modules/gallery/views/user_profile.html.php 43 DIRTY $info->view modules/image_block/views/image_block_block.html.php 3 DIRTY_JS $item->url() modules/image_block/views/image_block_block.html.php 4 DIRTY $item->thumb_img(array("class"=>"g-thumbnail")) modules/info/views/info_block.html.php 22 DIRTY date("M j, Y H:i:s",$item->captured) @@ -250,11 +250,11 @@ modules/organize/views/organize_tree.html.php 2 DIRTY_ATTR acce modules/organize/views/organize_tree.html.php 3 DIRTY_ATTR $album->id modules/organize/views/organize_tree.html.php 6 DIRTY_ATTR $selected&&$album->id==$selected->id?"ui-state-focus":"" modules/organize/views/organize_tree.html.php 7 DIRTY_ATTR $album->id -modules/organize/views/organize_tree.html.php 13 DIRTY View::factory("organize_tree.html",array("selected"=>$selected,"album"=>$child)); -modules/organize/views/organize_tree.html.php 15 DIRTY_ATTR access::can("edit",$child)?"":"g-view-only" -modules/organize/views/organize_tree.html.php 16 DIRTY_ATTR $child->id -modules/organize/views/organize_tree.html.php 18 DIRTY_ATTR $selected&&$child->id==$selected->id?"ui-state-focus":"" +modules/organize/views/organize_tree.html.php 15 DIRTY View::factory("organize_tree.html",array("selected"=>$selected,"album"=>$child)); +modules/organize/views/organize_tree.html.php 17 DIRTY_ATTR access::can("edit",$child)?"":"g-view-only" modules/organize/views/organize_tree.html.php 18 DIRTY_ATTR $child->id +modules/organize/views/organize_tree.html.php 20 DIRTY_ATTR $selected&&$child->id==$selected->id?"ui-state-focus":"" +modules/organize/views/organize_tree.html.php 20 DIRTY_ATTR $child->id modules/recaptcha/views/admin_recaptcha.html.php 11 DIRTY $form modules/recaptcha/views/admin_recaptcha.html.php 23 DIRTY_JS $public_key modules/recaptcha/views/form_recaptcha.html.php 7 DIRTY_JS $public_key @@ -274,21 +274,16 @@ modules/rss/views/feed.mrss.php 42 DIRTY_ATTR $chi modules/rss/views/feed.mrss.php 48 DIRTY_ATTR $child->thumb_url(true) modules/rss/views/feed.mrss.php 49 DIRTY_ATTR $child->thumb_height modules/rss/views/feed.mrss.php 50 DIRTY_ATTR $child->thumb_width -modules/rss/views/feed.mrss.php 54 DIRTY_ATTR $child->resize_url(true) -modules/rss/views/feed.mrss.php 55 DIRTY_ATTR @filesize($child->resize_path()) -modules/rss/views/feed.mrss.php 56 DIRTY_ATTR $child->mime_type -modules/rss/views/feed.mrss.php 57 DIRTY_ATTR $child->resize_height -modules/rss/views/feed.mrss.php 58 DIRTY_ATTR $child->resize_width -modules/rss/views/feed.mrss.php 61 DIRTY_ATTR $child->file_url(true) -modules/rss/views/feed.mrss.php 62 DIRTY_ATTR @filesize($child->file_path()) -modules/rss/views/feed.mrss.php 63 DIRTY_ATTR $child->mime_type -modules/rss/views/feed.mrss.php 64 DIRTY_ATTR $child->height -modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->width -modules/rss/views/feed.mrss.php 70 DIRTY_ATTR $child->file_url(true) -modules/rss/views/feed.mrss.php 71 DIRTY_ATTR @filesize($child->file_path()) -modules/rss/views/feed.mrss.php 72 DIRTY_ATTR $child->height -modules/rss/views/feed.mrss.php 73 DIRTY_ATTR $child->width -modules/rss/views/feed.mrss.php 74 DIRTY_ATTR $child->mime_type +modules/rss/views/feed.mrss.php 57 DIRTY_ATTR $child->resize_url(true) +modules/rss/views/feed.mrss.php 58 DIRTY_ATTR @filesize($child->resize_path()) +modules/rss/views/feed.mrss.php 59 DIRTY_ATTR $child->mime_type +modules/rss/views/feed.mrss.php 60 DIRTY_ATTR $child->resize_height +modules/rss/views/feed.mrss.php 61 DIRTY_ATTR $child->resize_width +modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->file_url(true) +modules/rss/views/feed.mrss.php 66 DIRTY_ATTR @filesize($child->file_path()) +modules/rss/views/feed.mrss.php 67 DIRTY_ATTR $child->mime_type +modules/rss/views/feed.mrss.php 68 DIRTY_ATTR $child->height +modules/rss/views/feed.mrss.php 69 DIRTY_ATTR $child->width modules/rss/views/rss_block.html.php 6 DIRTY_JS rss::url($url) modules/search/views/search.html.php 27 DIRTY_ATTR $item_class modules/search/views/search.html.php 28 DIRTY_JS $item->url() @@ -320,8 +315,8 @@ modules/user/views/admin_users.html.php 87 DIRTY ($user modules/user/views/admin_users.html.php 123 DIRTY_ATTR $group->id modules/user/views/admin_users.html.php 123 DIRTY_ATTR ($group->special?"g-default-group":"") modules/user/views/admin_users.html.php 125 DIRTY $v -modules/user/views/admin_users_group.html.php 22 DIRTY_JS $user->id -modules/user/views/admin_users_group.html.php 22 DIRTY_JS $group->id +modules/user/views/admin_users_group.html.php 24 DIRTY_JS $user->id +modules/user/views/admin_users_group.html.php 24 DIRTY_JS $group->id modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $width modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $height modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $url diff --git a/modules/gallery/views/admin_languages.html.php b/modules/gallery/views/admin_languages.html.php index 07134475..d4b7b0c1 100644 --- a/modules/gallery/views/admin_languages.html.php +++ b/modules/gallery/views/admin_languages.html.php @@ -49,13 +49,14 @@ </tr> <? $i = 0 ?> <? foreach ($available_locales as $code => $display_name): ?> - <? if ($i == (count($available_locales)/2)): ?> - <table> - <tr> - <th> <?= t("Installed") ?> </th> - <th> <?= t("Language") ?> </th> - <th> <?= t("Default language") ?> </th> - </tr> + <? if ($i == (int) (count($available_locales)/2)): ?> + </table> + <table> + <tr> + <th> <?= t("Installed") ?> </th> + <th> <?= t("Language") ?> </th> + <th> <?= t("Default language") ?> </th> + </tr> <? endif ?> <tr class="<?= (isset($installed_locales[$code])) ? "g-available" : "" ?><?= ($default_locale == $code) ? " g-selected" : "" ?>"> <td> <?= form::checkbox("installed_locales[]", $code, isset($installed_locales[$code])) ?> </td> |