From 89737c09d572efe35014e668cdd06407c2c19d62 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sun, 9 Jan 2011 20:52:31 +0100 Subject: Paginator for user manager admin view Closes ticket #1557 Note: also optimizes the way item count is retrieved for users, saving -1 queries when displaying this page --- modules/gallery/libraries/MY_Controller.php | 26 ++++++++++++++++++++++ modules/user/controllers/admin_users.php | 34 ++++++++++++++++++++++++++++- modules/user/views/admin_users.html.php | 31 +++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 modules/gallery/libraries/MY_Controller.php (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Controller.php b/modules/gallery/libraries/MY_Controller.php new file mode 100644 index 00000000..ea2a7502 --- /dev/null +++ b/modules/gallery/libraries/MY_Controller.php @@ -0,0 +1,26 @@ +page_title = t("Users and groups"); $view->content = new View("admin_users.html"); - $view->content->users = ORM::factory("user")->order_by("name", "ASC")->find_all(); + + // @todo: add this as a config option + $page_size = module::get_var("user", "page_size", 10); + $page = Input::instance()->get("page", "1"); + $builder = db::build(); + $user_count = $builder->from("users")->count_records(); + list($offset, $max_pages) = Controller::get_pager_params($page, $user_count, $page_size); + + // Make sure that the page references a valid offset + if ($page < 1) { + url::redirect(url::merge(array("page" => 1))); + } else if ($page > $max_pages) { + url::redirect(url::merge(array("page" => $max_pages))); + } + $view->content->users = ORM::factory("user") + ->select(array("users.id", "users.admin", "users.name", "users.email", "users.full_name", + "users.last_login", "users.guest", db::expr("COUNT(items.id) as item_count"))) + ->join("items", "items.owner_id", "users.id", "LEFT") + ->group_by("users.id") + ->order_by("users.name", "ASC") + ->find_all($page_size, $offset); + $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all(); + $view->content->page = $page; + $view->content->max_pages = $max_pages; + + if ($page < $max_pages) { + $view->content->next_page_url = url::site(url::merge(array("page" => $page + 1))); + } + if ( $page > 1 ) + { + $view->content->previous_page_url = url::site(url::merge(array("page" => $page - 1))); + } + print $view; } diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index f067cae8..028d44eb 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -88,7 +88,7 @@ last_login == 0) ? "" : gallery::date($user->last_login) ?> - from("items")->where("owner_id", "=", $user->id)->count_records() ?> + item_count ?> id") ?>" @@ -108,6 +108,35 @@ + + + -- cgit v1.2.3 From 97fc535411478f939b303c75a067b7dad9123112 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sun, 9 Jan 2011 21:19:55 +0100 Subject: Minor css mod to make it obvious paging belongs to user block --- modules/user/css/user.css | 1 + 1 file changed, 1 insertion(+) (limited to 'modules') diff --git a/modules/user/css/user.css b/modules/user/css/user.css index 084eac31..93e3d02e 100644 --- a/modules/user/css/user.css +++ b/modules/user/css/user.css @@ -12,6 +12,7 @@ #g-user-admin { width: auto; + margin-bottom: 4em; } #g-group-admin { -- cgit v1.2.3 From 00b520fffd867389b5a030ddefee9f468cad044c Mon Sep 17 00:00:00 2001 From: Joe7 Date: Tue, 11 Jan 2011 20:53:48 +0100 Subject: coding style --- modules/user/controllers/admin_users.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 6850f8af..2ae9788e 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -51,8 +51,7 @@ class Admin_Users_Controller extends Admin_Controller { if ($page < $max_pages) { $view->content->next_page_url = url::site(url::merge(array("page" => $page + 1))); } - if ( $page > 1 ) - { + if ($page > 1) { $view->content->previous_page_url = url::site(url::merge(array("page" => $page - 1))); } -- cgit v1.2.3 From df802de6ae3cc0c294a1a3dc76db29ff21949b9f Mon Sep 17 00:00:00 2001 From: Joe7 Date: Tue, 11 Jan 2011 21:28:25 +0100 Subject: Making good use of Pagination class to reduce code (removed MY_Controller which duplicated some functionality available in Pagination as well) --- modules/gallery/libraries/MY_Controller.php | 26 -------------------------- modules/user/controllers/admin_users.php | 24 +++++++++++------------- modules/user/views/admin_users.html.php | 28 ++-------------------------- 3 files changed, 13 insertions(+), 65 deletions(-) delete mode 100644 modules/gallery/libraries/MY_Controller.php (limited to 'modules') diff --git a/modules/gallery/libraries/MY_Controller.php b/modules/gallery/libraries/MY_Controller.php deleted file mode 100644 index ea2a7502..00000000 --- a/modules/gallery/libraries/MY_Controller.php +++ /dev/null @@ -1,26 +0,0 @@ -get("page", "1"); $builder = db::build(); $user_count = $builder->from("users")->count_records(); - list($offset, $max_pages) = Controller::get_pager_params($page, $user_count, $page_size); + + $view->content->pager = new Pagination(); + $view->content->pager->initialize( + array("query_string" => "page", + "total_items" => $user_count, + "items_per_page" => $page_size, + "style" => "classic")); // Make sure that the page references a valid offset if ($page < 1) { url::redirect(url::merge(array("page" => 1))); - } else if ($page > $max_pages) { - url::redirect(url::merge(array("page" => $max_pages))); + } else if ($page > $view->content->pager->total_pages) { + url::redirect(url::merge(array("page" => $view->content->pager->total_pages))); } + $view->content->users = ORM::factory("user") ->select(array("users.id", "users.admin", "users.name", "users.email", "users.full_name", "users.last_login", "users.guest", db::expr("COUNT(items.id) as item_count"))) ->join("items", "items.owner_id", "users.id", "LEFT") ->group_by("users.id") ->order_by("users.name", "ASC") - ->find_all($page_size, $offset); + ->find_all($page_size, $view->content->pager->sql_offset); $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all(); - $view->content->page = $page; - $view->content->max_pages = $max_pages; - - if ($page < $max_pages) { - $view->content->next_page_url = url::site(url::merge(array("page" => $page + 1))); - } - if ($page > 1) { - $view->content->previous_page_url = url::site(url::merge(array("page" => $page - 1))); - } print $view; } diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 028d44eb..74b13ec5 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -109,32 +109,8 @@ - -- cgit v1.2.3 From d511fc77adfa628b04968d153e397425e3a93358 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 12:33:51 -0800 Subject: Tweake Joe's change to admin_users to revert the code that joins against the items table; it's not clear that this is going to be efficient for large data sets. --- modules/user/controllers/admin_users.php | 7 ++----- modules/user/views/admin_users.html.php | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index e11145de..8dbc4cbb 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -43,14 +43,11 @@ class Admin_Users_Controller extends Admin_Controller { url::redirect(url::merge(array("page" => $view->content->pager->total_pages))); } + // Join our users against the items table so that we can get a count of their items + // in the same query. $view->content->users = ORM::factory("user") - ->select(array("users.id", "users.admin", "users.name", "users.email", "users.full_name", - "users.last_login", "users.guest", db::expr("COUNT(items.id) as item_count"))) - ->join("items", "items.owner_id", "users.id", "LEFT") - ->group_by("users.id") ->order_by("users.name", "ASC") ->find_all($page_size, $view->content->pager->sql_offset); - $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all(); print $view; diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 74b13ec5..a7bd6b27 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -88,7 +88,7 @@ last_login == 0) ? "" : gallery::date($user->last_login) ?> - item_count ?> + from("items")->where("owner_id", "=", $user->id)->count_records() ?> id") ?>" -- cgit v1.2.3 From 376f09c4e171e03a5b3764e51e0d28f1f57a233b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 12:47:15 -0800 Subject: Reorganize the url() function out from in the middle of the script/css combining functions. --- modules/gallery/libraries/Gallery_View.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 8befda95..e27dc41a 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -21,6 +21,15 @@ class Gallery_View_Core extends View { protected $theme_name = null; protected $combine_queue = array(); + /** + * Provide a url to a resource within the current theme. This allows us to refer to theme + * resources without naming the theme itself which makes themes easier to copy. + */ + public function url($path, $absolute_url=false) { + $arg = "themes/{$this->theme_name}/$path"; + return $absolute_url ? url::abs_file($arg) : url::file($arg); + } + /** * Begin gather up scripts or css files so that they can be combined into a single request. * @@ -53,15 +62,6 @@ class Gallery_View_Core extends View { } } - /** - * Provide a url to a resource within the current theme. This allows us to refer to theme - * resources without naming the theme itself which makes themes easier to copy. - */ - public function url($path, $absolute_url=false) { - $arg = "themes/{$this->theme_name}/$path"; - return $absolute_url ? url::abs_file($arg) : url::file($arg); - } - /** * If css combining is enabled, add this css to the list of css that will be * combined into a single style element. When combined, the order of style elements -- cgit v1.2.3 From 38b74932878e8e0c7eb071552568bbb014355996 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 13:07:14 -0800 Subject: whitespace fix. --- modules/search/helpers/search_theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/search/helpers/search_theme.php b/modules/search/helpers/search_theme.php index 07066caa..45a88dc2 100644 --- a/modules/search/helpers/search_theme.php +++ b/modules/search/helpers/search_theme.php @@ -22,7 +22,7 @@ class search_theme_Core { if ($theme->page_subtype() != "login") { $view = new View("search_link.html"); return $view->render(); - }else { + } else { return ""; } } -- cgit v1.2.3 From ee13b934f46d67982e5eeea21f81ac58f166741c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 13:14:43 -0800 Subject: Fix all the head() and admin_head() theme callbacks to return the results of the $theme->css() and $theme->script() calls. This handles the case where combining scripts/css returns HTML instead of putting it in the queue for combination. Fixes #1611. --- modules/comment/helpers/comment_theme.php | 8 +++----- modules/digibug/helpers/digibug_theme.php | 2 +- modules/gallery/helpers/gallery_theme.php | 27 +++++++++++++------------ modules/recaptcha/helpers/recaptcha_theme.php | 4 ++-- modules/server_add/helpers/server_add_theme.php | 18 ++++++++--------- modules/tag/helpers/tag_theme.php | 10 ++++----- modules/user/helpers/user_theme.php | 8 ++++---- 7 files changed, 38 insertions(+), 39 deletions(-) (limited to 'modules') diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index b993cdae..9cc93fa1 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -19,14 +19,12 @@ */ class comment_theme_Core { static function head($theme) { - $theme->css("comment.css"); - $theme->script("comment.js"); - return ""; + return $theme->css("comment.css") + . $theme->script("comment.js"); } static function admin_head($theme) { - $theme->css("comment.css"); - return ""; + return $theme->css("comment.css"); } static function photo_bottom($theme) { diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php index d146e17d..1106910e 100644 --- a/modules/digibug/helpers/digibug_theme.php +++ b/modules/digibug/helpers/digibug_theme.php @@ -19,6 +19,6 @@ */ class digibug_theme_Core { static function head($theme) { - $theme->script("digibug.js"); + return $theme->script("digibug.js"); } } diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 978c69a6..ebf8f38e 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -21,9 +21,9 @@ class gallery_theme_Core { static function head($theme) { $session = Session::instance(); $buf = ""; - $theme->css("gallery.css"); + $buf .= $theme->css("gallery.css"); if ($session->get("debug")) { - $theme->css("debug.css"); + $buf .= $theme->css("debug.css"); } if (module::is_active("rss")) { @@ -40,32 +40,33 @@ class gallery_theme_Core { if (count(locales::installed())) { // Needed by the languages block - $theme->script("jquery.cookie.js"); + $buf .= $theme->script("jquery.cookie.js"); } if ($session->get("l10n_mode", false)) { - $theme->css("l10n_client.css"); - $theme->script("jquery.cookie.js"); - $theme->script("l10n_client.js"); + $buf .= $theme->css("l10n_client.css") + . $theme->script("jquery.cookie.js") + . $theme->script("l10n_client.js"); } - $theme->css("uploadify/uploadify.css"); + $buf .= $theme->css("uploadify/uploadify.css"); return $buf; } static function admin_head($theme) { - $theme->css("gallery.css"); - $theme->script("gallery.panel.js"); + $buf = $theme->css("gallery.css"); + $buf .= $theme->script("gallery.panel.js"); $session = Session::instance(); if ($session->get("debug")) { - $theme->css("debug.css"); + $buf .= $theme->css("debug.css"); } if ($session->get("l10n_mode", false)) { - $theme->css("l10n_client.css"); - $theme->script("jquery.cookie.js"); - $theme->script("l10n_client.js"); + $buf .= $theme->css("l10n_client.css"); + $buf .= $theme->script("jquery.cookie.js"); + $buf .=$theme->script("l10n_client.js"); } + return $buf; } static function page_bottom($theme) { diff --git a/modules/recaptcha/helpers/recaptcha_theme.php b/modules/recaptcha/helpers/recaptcha_theme.php index ee880986..3677a7c7 100644 --- a/modules/recaptcha/helpers/recaptcha_theme.php +++ b/modules/recaptcha/helpers/recaptcha_theme.php @@ -19,10 +19,10 @@ */ class recaptcha_theme_Core { static function head($theme) { - $theme->css("recaptcha.css"); + return $theme->css("recaptcha.css"); } static function admin_head($theme) { - $theme->css("recaptcha.css"); + return $theme->css("recaptcha.css"); } } \ No newline at end of file diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index 53f78772..6395c2f0 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -20,24 +20,24 @@ class server_add_theme_Core { static function head($theme) { if (identity::active_user()->admin) { - $theme->css("server_add.css"); - $theme->script("server_add.js"); + return $theme->css("server_add.css") + . $theme->script("server_add.js"); } } static function admin_head($theme) { - $head = array(); + $buf = ""; if (strpos(Router::$current_uri, "admin/server_add") !== false) { - $theme->css("server_add.css"); - $theme->css("jquery.autocomplete.css"); + $buf .= $theme->css("server_add.css") + . $theme->css("jquery.autocomplete.css"); $base = url::site("__ARGS__"); $csrf = access::csrf_token(); - $head[] = ""; + $buf .= ""; - $theme->script("jquery.autocomplete.js"); - $theme->script("admin.js"); + $buf .= $theme->script("jquery.autocomplete.js") + . $theme->script("admin.js"); } - return implode("\n", $head); + return $buf; } } \ No newline at end of file diff --git a/modules/tag/helpers/tag_theme.php b/modules/tag/helpers/tag_theme.php index f731dbb7..3325a832 100644 --- a/modules/tag/helpers/tag_theme.php +++ b/modules/tag/helpers/tag_theme.php @@ -19,13 +19,13 @@ */ class tag_theme_Core { static function head($theme) { - $theme->css("jquery.autocomplete.css"); - $theme->script("jquery.autocomplete.js"); - $theme->css("tag.css"); + return $theme->css("jquery.autocomplete.css") + . $theme->script("jquery.autocomplete.js") + . $theme->css("tag.css"); } static function admin_head($theme) { - $theme->css("tag.css"); - $theme->script("gallery.in_place_edit.js"); + return $theme->css("tag.css") + . $theme->script("gallery.in_place_edit.js"); } } \ No newline at end of file diff --git a/modules/user/helpers/user_theme.php b/modules/user/helpers/user_theme.php index 5a7161ed..70e96f70 100644 --- a/modules/user/helpers/user_theme.php +++ b/modules/user/helpers/user_theme.php @@ -19,12 +19,12 @@ */ class user_theme_Core { static function head($theme) { - $theme->css("user.css"); - $theme->script("password_strength.js"); + return $theme->css("user.css") + . $theme->script("password_strength.js"); } static function admin_head($theme) { - $theme->css("user.css"); - $theme->script("password_strength.js"); + return $theme->css("user.css") + . $theme->script("password_strength.js"); } } \ No newline at end of file -- cgit v1.2.3 From 02f30b91bf8f68118a578de2194e66a7a16a291a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 14:20:26 -0800 Subject: Follow on to 966dee8628293f78fbf9431281709ceba011d3c2 for #1586 -- don't try to update the tag item count if we didn't change any items with this change (ie: a tag rename). In that case, we haven't loaded the related items so we don't have any idea what the count is going to be. --- modules/tag/models/tag.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index 25df87e0..2b73b5be 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -78,12 +78,14 @@ class Tag_Model_Core extends ORM { $related_item_ids[$row->item_id] = 1; } - $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]); - $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]); - if (isset($this->changed_relations["items"])) { - $changed = array_merge($added, $removed); + if (isset($this->object_relations["items"])) { + $added = array_diff($this->changed_relations["items"], $this->object_relations["items"]); + $removed = array_diff($this->object_relations["items"], $this->changed_relations["items"]); + if (isset($this->changed_relations["items"])) { + $changed = array_merge($added, $removed); + } + $this->count = count($this->object_relations["items"]) + count($added) - count($removed); } - $this->count = count($this->object_relations["items"]) + count($added) - count($removed); $result = parent::save(); -- cgit v1.2.3 From f0dd16efc428d372cca6ec90ca31251e3ce24382 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 14:59:25 -0800 Subject: Revive the code from Cache_Driver::exists and put it into a helper function in the test so that we can keep our tests functioning. Follow on to 66fd8c7518ab71466aca72d20fb7bcd5f374af26 for #1559. --- modules/gallery/tests/Cache_Test.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index b95ef0a2..5e14051a 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -24,8 +24,16 @@ class Cache_Test extends Gallery_Unit_Test_Case { $this->_driver = new Cache_Database_Driver(); } - public function cache_exists_test() { - $this->assert_false($this->_driver->exists("test_key"), "test_key should not be defined"); + private function _exists($id) { + return db::build() + ->where("key", "=", $id) + ->where("expiration", ">=", time()) + ->limit("1") + ->count_records("caches") > 0; + } + + public function cache_exists_test_helper_function_test() { + $this->assert_false($this->_exists("test_key"), "test_key should not be defined"); $id = random::hash(); db::build() @@ -34,7 +42,7 @@ class Cache_Test extends Gallery_Unit_Test_Case { ->values($id, ", ", 84600 + time(), serialize("some test data")) ->execute(); - $this->assert_true($this->_driver->exists($id), "test_key should be defined"); + $this->assert_true($this->_exists($id), "test_key should be defined"); } public function cache_get_test() { @@ -100,9 +108,9 @@ class Cache_Test extends Gallery_Unit_Test_Case { $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"); - $this->assert_true($this->_driver->exists($id3), "$id3 should not have been deleted"); + $this->assert_false($this->_exists($id1), "$id1 should have been deleted"); + $this->assert_true($this->_exists($id2), "$id2 should not have been deleted"); + $this->assert_true($this->_exists($id3), "$id3 should not have been deleted"); } public function cache_delete_tag_test() { @@ -120,9 +128,9 @@ class Cache_Test extends Gallery_Unit_Test_Case { $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"); - $this->assert_false($this->_driver->exists($id3), "$id3 should have been deleted"); + $this->assert_true($this->_exists($id1), "$id1 should not have been deleted"); + $this->assert_false($this->_exists($id2), "$id2 should have been deleted"); + $this->assert_false($this->_exists($id3), "$id3 should have been deleted"); } public function cache_delete_all_test() { @@ -140,8 +148,8 @@ class Cache_Test extends Gallery_Unit_Test_Case { $data = $this->_driver->delete(true); - $this->assert_false($this->_driver->exists($id1), "$id1 should have been deleted"); - $this->assert_false($this->_driver->exists($id2), "$id2 should have been deleted"); - $this->assert_false($this->_driver->exists($id3), "$id3 should have been deleted"); + $this->assert_false($this->_exists($id1), "$id1 should have been deleted"); + $this->assert_false($this->_exists($id2), "$id2 should have been deleted"); + $this->assert_false($this->_exists($id3), "$id3 should have been deleted"); } } \ No newline at end of file -- cgit v1.2.3 From 8583c1d259e33ab8c85ade70ee521bb21452cff5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 15:10:27 -0800 Subject: Style fixes. --- modules/user/controllers/admin_users.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 8dbc4cbb..9ef6f8c1 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -46,8 +46,8 @@ class Admin_Users_Controller extends Admin_Controller { // Join our users against the items table so that we can get a count of their items // in the same query. $view->content->users = ORM::factory("user") - ->order_by("users.name", "ASC") - ->find_all($page_size, $view->content->pager->sql_offset); + ->order_by("users.name", "ASC") + ->find_all($page_size, $view->content->pager->sql_offset); $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all(); print $view; -- cgit v1.2.3 From 44da46abd4aa2e210300d1d54c1d6896988fd71b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 15 Jan 2011 15:11:37 -0800 Subject: Golden file updates for xss and controller authentication. --- modules/gallery/tests/controller_auth_data.txt | 5 +- modules/gallery/tests/xss_data.txt | 106 ++++++++++++++----------- 2 files changed, 62 insertions(+), 49 deletions(-) (limited to 'modules') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 24170092..f1192071 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -22,8 +22,8 @@ modules/gallery/controllers/user_profile.php show modules/gallery/controllers/user_profile.php contact DIRTY_AUTH modules/gallery/controllers/user_profile.php send DIRTY_AUTH modules/gallery/controllers/welcome_message.php index DIRTY_AUTH -modules/organize/controllers/organize.php dialog DIRTY_CSRF -modules/organize/controllers/organize.php add_album_fields DIRTY_AUTH +modules/organize/controllers/organize.php tree DIRTY_CSRF +modules/organize/controllers/organize.php delete DIRTY_AUTH modules/rest/controllers/rest.php index DIRTY_CSRF|DIRTY_AUTH modules/rest/controllers/rest.php reset_api_key_confirm DIRTY_AUTH modules/rest/controllers/rest.php reset_api_key DIRTY_AUTH @@ -35,5 +35,6 @@ modules/server_add/controllers/server_add.php children modules/tag/controllers/admin_tags.php index DIRTY_CSRF modules/tag/controllers/tag.php __call DIRTY_CSRF|DIRTY_AUTH modules/tag/controllers/tags.php autocomplete DIRTY_CSRF|DIRTY_AUTH +modules/user/controllers/admin_users.php index DIRTY_CSRF modules/user/controllers/password.php reset DIRTY_AUTH modules/user/controllers/password.php do_reset DIRTY_CSRF|DIRTY_AUTH diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 366391cf..609f786a 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -213,7 +213,7 @@ modules/gallery/views/menu_link.html.php 5 DIRTY_JS $menu- modules/gallery/views/movieplayer.html.php 2 DIRTY html::anchor($item->file_url(true),"",$attrs) modules/gallery/views/movieplayer.html.php 5 DIRTY_JS $attrs["id"] modules/gallery/views/movieplayer.html.php 7 DIRTY_JS url::abs_file("lib/flowplayer.swf") -modules/gallery/views/movieplayer.html.php 14 DIRTY_JS url::abs_file("lib/flowplayer.pseudostreaming.swf") +modules/gallery/views/movieplayer.html.php 17 DIRTY_JS url::abs_file("lib/flowplayer.pseudostreaming.swf") modules/gallery/views/permissions_browse.html.php 3 DIRTY_JS url::site("permissions/form/__ITEM__") modules/gallery/views/permissions_browse.html.php 16 DIRTY_JS url::site("permissions/change/__CMD__/__GROUP__/__PERM__/__ITEM__?csrf=$csrf") modules/gallery/views/permissions_browse.html.php 43 DIRTY_ATTR $parent->id @@ -262,8 +262,8 @@ modules/gallery/views/user_profile.html.php 34 DIRTY_ATTR $use modules/gallery/views/user_profile.html.php 43 DIRTY $info->view modules/image_block/views/image_block_block.html.php 4 DIRTY_JS $item->url() modules/image_block/views/image_block_block.html.php 5 DIRTY $item->thumb_img(array("class"=>"g-thumbnail")) -modules/info/views/info_block.html.php 22 DIRTY gallery::date_time($item->captured) -modules/info/views/info_block.html.php 29 DIRTY_JS $item->owner->url +modules/info/views/info_block.html.php 5 DIRTY $info["label"] +modules/info/views/info_block.html.php 5 DIRTY $info["value"] modules/notification/views/comment_published.html.php 28 DIRTY_JS $comment->item()->abs_url() modules/notification/views/comment_published.html.php 29 DIRTY $comment->item()->abs_url() modules/notification/views/item_added.html.php 16 DIRTY_JS $item->abs_url() @@ -274,22 +274,29 @@ modules/notification/views/item_updated.html.php 20 DIRTY_JS $item- modules/notification/views/item_updated.html.php 20 DIRTY $item->abs_url() modules/notification/views/user_profile_notification.html.php 5 DIRTY_ATTR $subscription->id modules/notification/views/user_profile_notification.html.php 6 DIRTY_JS $subscription->url -modules/organize/views/organize_dialog.html.php 94 DIRTY_JS $domain -modules/organize/views/organize_dialog.html.php 95 DIRTY_JS $access_key -modules/organize/views/organize_dialog.html.php 96 DIRTY_JS request::protocol() -modules/organize/views/organize_dialog.html.php 97 DIRTY_JS $file_filter -modules/organize/views/organize_dialog.html.php 98 DIRTY_JS $sort_order -modules/organize/views/organize_dialog.html.php 99 DIRTY_JS $sort_fields -modules/organize/views/organize_dialog.html.php 100 DIRTY_JS $album->id -modules/organize/views/organize_dialog.html.php 101 DIRTY_JS $selected_id -modules/organize/views/organize_dialog.html.php 102 DIRTY_JS $rest_uri -modules/organize/views/organize_dialog.html.php 103 DIRTY_JS $controller_uri -modules/organize/views/organize_dialog.html.php 109 DIRTY_JS $flash_minimum_version="10.0.0" -modules/organize/views/organize_dialog.html.php 127 DIRTY_JS $swf_uri -modules/organize/views/organize_dialog.html.php 140 DIRTY_ATTR request::protocol() +modules/organize/views/organize_dialog.html.php 8 DIRTY_JS url::site("items/__ID__") +modules/organize/views/organize_dialog.html.php 14 DIRTY_JS $album->title +modules/organize/views/organize_frame.html.php 12 DIRTY_JS url::file("modules/organize/vendor/ext/images/default/s.gif") +modules/organize/views/organize_frame.html.php 56 DIRTY_JS url::site("organize/album_info/__ID__") +modules/organize/views/organize_frame.html.php 94 DIRTY_JS access::csrf_token() +modules/organize/views/organize_frame.html.php 96 DIRTY_JS url::site("organize/set_sort/__ID__") +modules/organize/views/organize_frame.html.php 116 DIRTY_JS url::site("organize/delete") +modules/organize/views/organize_frame.html.php 125 DIRTY_JS access::csrf_token() +modules/organize/views/organize_frame.html.php 226 DIRTY_JS url::site("organize/rearrange") +modules/organize/views/organize_frame.html.php 237 DIRTY_JS access::csrf_token() +modules/organize/views/organize_frame.html.php 275 DIRTY_JS $key +modules/organize/views/organize_frame.html.php 398 DIRTY_JS url::site("organize/tree/{$album->id}") +modules/organize/views/organize_frame.html.php 456 DIRTY_JS url::site("organize/reparent") +modules/organize/views/organize_frame.html.php 479 DIRTY_JS access::csrf_token() +modules/organize/views/organize_frame.html.php 495 DIRTY_JS access::can("edit",item::root()) +modules/organize/views/organize_frame.html.php 497 DIRTY_JS item::root()->title +modules/organize/views/organize_frame.html.php 499 DIRTY_JS item::root()->id +modules/organize/views/organize_frame.html.php 507 DIRTY_JS $album->id +modules/organize/views/organize_frame.html.php 508 DIRTY_JS $album->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 +modules/recaptcha/views/form_recaptcha.html.php 3 DIRTY_ATTR request::protocol() +modules/recaptcha/views/form_recaptcha.html.php 8 DIRTY_JS $public_key modules/rest/views/reset_api_key_confirm.html.php 6 DIRTY $form modules/rss/views/feed.mrss.php 10 DIRTY $feed->uri modules/rss/views/feed.mrss.php 13 DIRTY_JS $feed->uri @@ -346,28 +353,31 @@ modules/user/views/admin_users.html.php 73 DIRTY_ATTR $use modules/user/views/admin_users.html.php 74 DIRTY_ATTR $user->avatar_url(20,$theme->url(,true)) modules/user/views/admin_users.html.php 88 DIRTY ($user->last_login==0)?"":gallery::date($user->last_login) modules/user/views/admin_users.html.php 91 DIRTY db::build()->from("items")->where("owner_id","=",$user->id)->count_records() -modules/user/views/admin_users.html.php 127 DIRTY_ATTR $group->id -modules/user/views/admin_users.html.php 127 DIRTY_ATTR ($group->special?"g-default-group":"") -modules/user/views/admin_users.html.php 129 DIRTY $v +modules/user/views/admin_users.html.php 113 DIRTY $pager +modules/user/views/admin_users.html.php 132 DIRTY_ATTR $group->id +modules/user/views/admin_users.html.php 132 DIRTY_ATTR ($group->special?"g-default-group":"") +modules/user/views/admin_users.html.php 134 DIRTY $v modules/user/views/admin_users_delete_user.html.php 6 DIRTY $form 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 -themes/admin_wind/views/admin.html.php 21 DIRTY_JS $theme->url() -themes/admin_wind/views/admin.html.php 38 DIRTY $theme->admin_head() -themes/admin_wind/views/admin.html.php 42 DIRTY $theme->admin_page_top() -themes/admin_wind/views/admin.html.php 50 DIRTY $theme->admin_header_top() -themes/admin_wind/views/admin.html.php 51 DIRTY_JS item::root()->url() -themes/admin_wind/views/admin.html.php 54 DIRTY $theme->user_menu() -themes/admin_wind/views/admin.html.php 57 DIRTY $theme->admin_menu() -themes/admin_wind/views/admin.html.php 60 DIRTY $theme->admin_header_bottom() -themes/admin_wind/views/admin.html.php 67 DIRTY $content -themes/admin_wind/views/admin.html.php 73 DIRTY $sidebar -themes/admin_wind/views/admin.html.php 78 DIRTY $theme->admin_footer() -themes/admin_wind/views/admin.html.php 81 DIRTY $theme->admin_credits() -themes/admin_wind/views/admin.html.php 86 DIRTY $theme->admin_page_bottom() +themes/admin_wind/views/admin.html.php 31 DIRTY $theme->admin_head() +themes/admin_wind/views/admin.html.php 40 DIRTY_JS $theme->url() +themes/admin_wind/views/admin.html.php 45 DIRTY $theme->get_combined("script") +themes/admin_wind/views/admin.html.php 48 DIRTY $theme->get_combined("css") +themes/admin_wind/views/admin.html.php 52 DIRTY $theme->admin_page_top() +themes/admin_wind/views/admin.html.php 60 DIRTY $theme->admin_header_top() +themes/admin_wind/views/admin.html.php 61 DIRTY_JS item::root()->url() +themes/admin_wind/views/admin.html.php 64 DIRTY $theme->user_menu() +themes/admin_wind/views/admin.html.php 67 DIRTY $theme->admin_menu() +themes/admin_wind/views/admin.html.php 70 DIRTY $theme->admin_header_bottom() +themes/admin_wind/views/admin.html.php 77 DIRTY $content +themes/admin_wind/views/admin.html.php 83 DIRTY $sidebar +themes/admin_wind/views/admin.html.php 88 DIRTY $theme->admin_footer() +themes/admin_wind/views/admin.html.php 91 DIRTY $theme->admin_credits() +themes/admin_wind/views/admin.html.php 96 DIRTY $theme->admin_page_bottom() themes/admin_wind/views/block.html.php 3 DIRTY_ATTR $anchor themes/admin_wind/views/block.html.php 5 DIRTY $id themes/admin_wind/views/block.html.php 5 DIRTY_ATTR $css_id @@ -398,20 +408,22 @@ themes/wind/views/dynamic.html.php 17 DIRTY_ATTR $chi themes/wind/views/dynamic.html.php 29 DIRTY $theme->paginator() themes/wind/views/movie.html.php 5 DIRTY $theme->paginator() themes/wind/views/movie.html.php 9 DIRTY $item->movie_img(array("class"=>"g-movie","id"=>"g-item-id-{$item->id}")) -themes/wind/views/page.html.php 9 DIRTY $page_title -themes/wind/views/page.html.php 12 DIRTY $theme->item()->title -themes/wind/views/page.html.php 16 DIRTY item::root()->title -themes/wind/views/page.html.php 26 DIRTY_JS $theme->url() -themes/wind/views/page.html.php 35 DIRTY $new_width -themes/wind/views/page.html.php 36 DIRTY $new_height -themes/wind/views/page.html.php 37 DIRTY $thumb_proportion -themes/wind/views/page.html.php 74 DIRTY $header_text -themes/wind/views/page.html.php 76 DIRTY_JS item::root()->url() -themes/wind/views/page.html.php 80 DIRTY $theme->user_menu() -themes/wind/views/page.html.php 101 DIRTY_JS $parent->url($parent->id==$theme->item()->parent_id?"show={$theme->item()->id}":null) -themes/wind/views/page.html.php 122 DIRTY $content -themes/wind/views/page.html.php 128 DIRTY newView("sidebar.html") -themes/wind/views/page.html.php 135 DIRTY $footer_text +themes/wind/views/page.html.php 10 DIRTY $page_title +themes/wind/views/page.html.php 13 DIRTY $theme->item()->title +themes/wind/views/page.html.php 17 DIRTY item::root()->title +themes/wind/views/page.html.php 31 DIRTY $new_width +themes/wind/views/page.html.php 32 DIRTY $new_height +themes/wind/views/page.html.php 33 DIRTY $thumb_proportion +themes/wind/views/page.html.php 70 DIRTY_JS $theme->url() +themes/wind/views/page.html.php 75 DIRTY $theme->get_combined("script") +themes/wind/views/page.html.php 78 DIRTY $theme->get_combined("css") +themes/wind/views/page.html.php 88 DIRTY $header_text +themes/wind/views/page.html.php 90 DIRTY_JS item::root()->url() +themes/wind/views/page.html.php 94 DIRTY $theme->user_menu() +themes/wind/views/page.html.php 115 DIRTY_JS $parent->url($parent->id==$theme->item()->parent_id?"show={$theme->item()->id}":null) +themes/wind/views/page.html.php 136 DIRTY $content +themes/wind/views/page.html.php 142 DIRTY newView("sidebar.html") +themes/wind/views/page.html.php 149 DIRTY $footer_text themes/wind/views/paginator.html.php 33 DIRTY_JS $first_page_url themes/wind/views/paginator.html.php 42 DIRTY_JS $previous_page_url themes/wind/views/paginator.html.php 70 DIRTY_JS $next_page_url -- cgit v1.2.3 From 0020f87d6a23ce00200074b678a9293d055e27a3 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sat, 15 Jan 2011 21:49:22 +0100 Subject: Fixed paging for albums ordered by random. MySql has problems when comparing float values against -seemingly same- float input, see http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html for details. Fixes #1610 --- installer/install.sql | 4 ++-- modules/gallery/helpers/gallery_installer.php | 9 +++++++-- modules/gallery/module.info | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/installer/install.sql b/installer/install.sql index 0ed7f2f3..07aae36d 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -160,7 +160,7 @@ CREATE TABLE {items} ( `name` varchar(255) DEFAULT NULL, `owner_id` int(9) DEFAULT NULL, `parent_id` int(9) NOT NULL, - `rand_key` float DEFAULT NULL, + `rand_key` decimal(11,10) DEFAULT NULL, `relative_path_cache` varchar(255) DEFAULT NULL, `relative_url_cache` varchar(255) DEFAULT NULL, `resize_dirty` tinyint(1) DEFAULT '1', @@ -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',43,1); +INSERT INTO {modules} VALUES (1,1,'gallery',44,1); INSERT INTO {modules} VALUES (2,1,'user',3,2); INSERT INTO {modules} VALUES (3,1,'comment',3,3); INSERT INTO {modules} VALUES (4,1,'organize',3,4); diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index f7b8da5f..3c7b1c84 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -92,7 +92,7 @@ class gallery_installer { `name` varchar(255) default NULL, `owner_id` int(9) default NULL, `parent_id` int(9) NOT NULL, - `rand_key` float default NULL, + `rand_key` decimal(11,10) default NULL, `relative_path_cache` varchar(255) default NULL, `relative_url_cache` varchar(255) default NULL, `resize_dirty` boolean default 1, @@ -309,7 +309,7 @@ class gallery_installer { module::set_var("gallery", "show_user_profiles_to", "registered_users"); module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin"); - module::set_version("gallery", 43); + module::set_version("gallery", 44); } static function upgrade($version) { @@ -653,6 +653,11 @@ class gallery_installer { $db->query("ALTER TABLE {items} CHANGE `description` `description` text DEFAULT NULL"); module::set_version("gallery", $version = 43); } + + if ($version == 43) { + $db->query("ALTER TABLE {items} CHANGE `rand_key` `rand_key` DECIMAL(11, 10)"); + module::set_version("gallery", $version = 44); + } } static function uninstall() { diff --git a/modules/gallery/module.info b/modules/gallery/module.info index eb579ab6..4c4e63a1 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 43 +version = 44 -- cgit v1.2.3 From ac44e9c930ec83545b37e1e31381919fbd849d26 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 16 Jan 2011 15:49:34 -0800 Subject: First step in setting up version checking. We now have two types of packages (release, git). Instead of using constants, we now have gallery::version_string() which returns the current version string. If you're on a release package, then the version string looks like: 3.0 (Santa Fe) If you're on a git package, then the version string looks like this: 3.0.1 (branch 3.0.x build 3) We track the build number in a new file in the gallery3 root called BUILD_NUMBER which we will update periodically with the latest build number for each branch. --- BUILD_NUMBER | 1 + modules/gallery/helpers/gallery.php | 25 +++++++++++++++++++++++- modules/gallery/helpers/gallery_theme.php | 2 +- modules/gallery/views/admin_block_stats.html.php | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 BUILD_NUMBER (limited to 'modules') diff --git a/BUILD_NUMBER b/BUILD_NUMBER new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/BUILD_NUMBER @@ -0,0 +1 @@ +1 diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 282289b5..c4a6286c 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -18,7 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_Core { - const VERSION = "3.0+ (git)"; + const VERSION = "3.0+"; + const CODE_NAME = ""; + const RELEASE_CHANNEL = "git"; + const RELEASE_BRANCH = "master"; /** * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is @@ -184,4 +187,24 @@ class gallery_Core { } putenv("PATH=" . implode(":", $path_env)); } + + /** + * Return a string describing this version of Gallery and the type of release. + */ + static function version_string() { + if (gallery::RELEASE_CHANNEL == "git") { + return sprintf( + "%s (branch %s build %s)", gallery::VERSION, gallery::RELEASE_BRANCH, gallery::build_number()); + } else { + return sprintf("%s (%s)", gallery::VERSION, gallery::CODE_NAME); + } + } + + /** + * Return the contents of the BUILD_NUMBER file, which should be a single integer. + */ + static function build_number() { + $lines = file(DOCROOT . "BUILD_NUMBER", FILE_IGNORE_NEW_LINES); + return $lines[0]; + } } \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index ebf8f38e..d75c6fc6 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -115,7 +115,7 @@ class gallery_theme_Core { static function credits() { $version_string = SafeString::of_safe_html( - 'Gallery ' . gallery::VERSION . ''); + 'Gallery ' . gallery::version_string() . ''); return "
  • " . t(module::get_var("gallery", "credits"), array("url" => "http://gallery.menalto.com", diff --git a/modules/gallery/views/admin_block_stats.html.php b/modules/gallery/views/admin_block_stats.html.php index 1dec8ccd..c8c54765 100644 --- a/modules/gallery/views/admin_block_stats.html.php +++ b/modules/gallery/views/admin_block_stats.html.php @@ -1,7 +1,7 @@