The final bits of GSoCSeptember 16, 2007
I am now considering finalized my work on the GSoC project (from now on call it voluntary work… ;)). After a lot of bug fixing and some documentation, I am releasing the 1.0 version of both NestedSortables jQuery plugins. Please, visit the plugins’ homepage to check out and comment on the documentation. I have compiled the scripts into compressed format and they are now about 75% smaller, and will download pretty fast.
After a lot of helpful comments from folks at the WP-Hackers list, I improved a few details in the WordPress page ordering. I also managed to fix all the remaining problems I mentioned in my last post (more about them later on), so I believe it is now ready to be rolled out in the development version. To try it out, you can check my sandbox (user: test / pass: test), download the development version of WordPress with it (up-to-date as of 19-Sep 2007
16-Sep-2007 WP from trunk), or apply it to your own working copy of WordPress from SVN trunk using this patch (you will probably also need this image, which I think can’t be included in the patch). I will submit the patch to the WordPress TRAC. I hope it gets reviewed and accepted.
Besides cosmetic improvements (animations, button position), I changed two configuration parameters for the NestedSortable Widget (can be easily reverted at wp-admin/js/edit-page-order.js), when compared to the first showcase. It is now paginating at 20 items. I also am turning on the “greddy” option, what means the list will be downloaded all at once, even though it will be displayed paginated. Why would I want to do that? Three reasons:
- Each additional item in the list takes about 90 bytes, on average. So, if you had 1000 pages, it would be only 90kB to download. Downloading 90kB at once is way faster than downloading 5kB 20 times, mostly because of server processing.
- Server processing is what takes longer here. When fetching just 50 items out of 1000, the server is actually loading the whole list, then filtering only what we want (yes, this could be optimized, but the issues with hierarchies make it a complex task). So, if we load tiny parts of the list 20 times, it should take 20 times more processing than loading the whole thing at once.
If you still prefer the old fashioned way, all it takes is setting ‘greddy’ to false in wp-admin/js/edit-page-order.js.
What did I have to change in WordPress?
I will briefly describe the files that were altered/added:
wp-includes/class-page-order.php – added – this class encapsulates most of the “data-source” functionality, and takes care of both loading the page list, with pagination support, and saving it back to the DB.
wp-includes/class-JSON.php – added – class by Michal Migurski that will convert php data structures to JSON (and also from, but I didn’t need it).
wp-admin/admin-ajax.php – altered – Added two actions to serve as the data source for the widget, one for fetching ( ‘page-order-load’) and other for saving (‘page-order-save’) the order. The actions are small, since they use the Page_Order class.
wp-admin/js/edit-page-order.js – added – This script will add the “Edit Page Order” button, that will build the NestedSortable Widget on the user’s demand. It also holds the configuration of the widget.
wp-admin/css/nestedsortablewidget.css – added – CSS for the plugin.
wp-admin/images/progress_indicator.gif – added – AJAX loading animated gif.
wp-admin/includes/schema.php – altered – Had to change this to add a ‘order-pages’ type of permission to the database. This is likely to break as the DB version number evolves.
wp-admin/includes/upgrade.php – altered – Had to change this to add a ‘order-pages’ type of permission to the database. This is likely to break as the DB version number evolves.
wp-includes/version.php – altered – I had to increment the DB version to make WP upgrade the DB and add the ‘order-pages’ permission.
wp-includes/js/jquery/inestedsortable.js – added – the first of my two jQuery plugins, compressed
wp-includes/js/jquery/jquery.nestedsortablewidget.js – added – the second of my two jQuery plugins, compressed
Will I assemble it as a WordPress plugin?
The sort answer is no, unless there is great demand and strong reasons not to apply this to the core WordPress. Don’t take me wrong, I love plugins. But I don’t think this is good for a plugin, it is too much of a basic functionality. Most people won’t ever even look for a plugin to make sorting their pages faster, only in very special cases; they will just go ahead and sort them the hard way. There is already a plugin with this intention (my page order) and the author admits it doesn’t have that much demand. Making an analogy: car accessories are also great; but you wouldn’t be very happy with a car where the tires and the steering wheel were accessories.