Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#2499 closed defect (bug) (fixed)

Rework Link Categories

Reported by: ryan's profile ryan Owned by: ryan's profile ryan
Milestone: 2.1 Priority: low
Severity: normal Version: 2.0.1
Component: Administration Keywords: links has-patch
Focuses: Cc:

Description

Link categories have a number of options associated with them that could be blog level options. Also, links could reuse the regular post categories for their purposes instead of having separate link-specific categories. Let's get rid of the linkcategories table, move the link category options into the options table and apply them uniformly to all links, and add a link2cat table for assocating links to categories. This allows us to get rid of the busy link-categories.php page entirely and reuse all of the post category stuff. Categories that have no links associated with them will be ignored when listing links by category.

Attachments (12)

link_categories.diff (98.7 KB) - added by ryan 16 years ago.
More cleanups. Looking pretty good.
link_categories.2.diff (106.6 KB) - added by ryan 16 years ago.
link_count, links_visible, link category manager
link_categories.3.diff (107.4 KB) - added by ryan 16 years ago.
Fix link deletion
link_categories.4.diff (107.5 KB) - added by ryan 16 years ago.
Visibility and update time fixes.
link_categories.5.diff (108.3 KB) - added by ryan 16 years ago.
More fixes.
link_categories.6.diff (108.5 KB) - added by ryan 16 years ago.
Unified category manager, name change
link_categories.7.diff (110.7 KB) - added by ryan 16 years ago.
Tweakage
link_categories.8.diff (110.7 KB) - added by ryan 16 years ago.
get_links() fix
link_categories.9.diff (110.6 KB) - added by ryan 16 years ago.
Toggle and ID sort fixes
link_categories.10.diff (110.9 KB) - added by ryan 16 years ago.
Fix category list in opml importer.
link_categories.11.diff (111.8 KB) - added by ryan 16 years ago.
Better category deletion behavior, bulk delete, remove bulk visibility toggle, remove reassign
link_categories.12.diff (111.8 KB) - added by ryan 16 years ago.
More fixes.

Download all attachments as: .zip

Change History (52)

#1 @markjaquith
16 years ago

Also (dunno if it's in your patch) when listing posts by category, even if you have it set to display empty categories, it should maybe skip categories that are only filled with links.

#2 @ryan
16 years ago

So, I have to count the number of links in a category to be able to hide empty categories. The counts need to be cached to the DB like we do with the post counts. Another field in the categories table, I guess.

#3 @ryan
16 years ago

Anyone use that auto toggle stuff? I'm not even sure what it is, and it looks like it is partially broken in 2.0.x.

#4 @markjaquith
16 years ago

Seems broken.

It would work like this: if a new link was added to that category, all other links in that category wouuld switch to being invisible. The reason you can't just say "limit 1" and have it work the same way is that there is no way to sort links by date added (because there is no date field for links), so this toggle was a way to rig it to work, but only for one post.

I actually used it for a client about a year ago. She wanted a rotating "link of the week feature" at the top of her sidebar. I used the toggle feature and whenever she added a new link, the old one would go invisible.

I think if we add a date field to the links, there will be no need for this toggle, as you'll just be able to limit it to showing 1 link and sort by date DESC.

Actually, it would be really cool if the links had full date functionality... one could use it to run their own linklog in-house without resorting to hacks to get WP posts to do it. I may have submitted a ticket for this way back in the day.

#5 @ryan
16 years ago

Yes, timestamps seem better than auto toggling. I've purged the auto toggling for now.

#6 @MichaelH
16 years ago

  1. Consider adding category_type field to wp_categories (links, posts, pages)
  1. Does there need to be a default Category for Links designation just like the default Post Category in Options-Writing?
  1. Visible should be set to Yes (now nothing is checked).
  1. Error when displaying site with default theme where sidebar.php uses get_links_list (did upgrade.php from 2.0.1 alpha1)

Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\xampp\htdocs\wp201test\wp-includes\links.php on line 162

  1. No links display on site after doing install.php--wp_link2cat has no data
  1. Maybe I applied the patch wrong, but where is wp-admin/link.php?
  1. Regarding timestamps, the wp_links field, link_updated, is all zeros in several blogs (1.5.2 and 2.0.1) I checked.

#7 @ryan
16 years ago

  1. Maybe. I kinda like having categories shared. But, we'll have to see how usable that is in practice.
  1. I plan to add a default link category dropdown to Options->Links along with the options for link sorting, etc.
  1. Yes, I'll fix that.
  1. That's the typical error that happens when trying to get the permalink of a non-existent post. Weird that it is happening here. I don't see this with the default theme.
  1. I'll fix that.
  1. It's in the patch. Maybe patch isn't creating the file.
  1. I think you have to have link updating turned on. See Options-Misc (I'll probably move that option to Options-Link).

#8 @ryan
16 years ago

  1. Default link category in Options->Writing next to default post category.
  1. Fixed.
  1. Couldn't reproduce.
  1. Fixed.

@ryan
16 years ago

More cleanups. Looking pretty good.

#9 @MichaelH
16 years ago

Did install.php with links_category.4.diff installed

  1. wp_linkcategories table shouldn't be created
  1. When Viewing Site, this in sidebar using default theme caused by get_links_list I believe:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near at line 1]
SELECT wp_links.link_id, link_url, link_name, link_image, link_target, link_description, link_rating, link_rel , IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated FROM wp_links WHERE link_visible = 'Y' ORDER BY link_ ASC LIMIT

  1. This error page when either to click on Edit to edit the link. Also get same error page when clicking on Add Link:

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
localhost
02/23/06 20:32:40
Apache/2.0.54 (Win32) mod_ssl/2.0.54 OpenSSL/0.9.7g PHP/5.0.4

  1. Visible is still not set when Adding a Link

#10 @ryan
16 years ago

  1. I'm leaving linkcategories around for now. Disaster recovery. :-)
  1. That query is an old one. The query is different in the latest patch.
  1. Maybe the patch didn't apply fully.
  1. Hmm, works for me.

New patch coming up.

@ryan
16 years ago

link_count, links_visible, link category manager

#11 @MichaelH
16 years ago

Deleted Link but it didn't get deleted from wp_link2cat table.

#12 @ryan
16 years ago

New patch adds two new fields to the categories table. link_count counts the number of links assigned to a category. links_visible will toggle visibility for all links in that category, in case you want to hide your pron links. links_visible isn't fully implemented yet. TODO.

The "Link Categories" page is back. It's the same as Manage->Categories but shows the # of links per cat and the default link cat. link-categories.php and categories.php need to have the common bits factored out into category.php. That's not a big deal though since all of the heavy lifting is done in the wp_*_category functions that are used by both files.

@ryan
16 years ago

Fix link deletion

#13 @ryan
16 years ago

Link delete fixed. link2cat is updated as is link_count. Our AJAX list manipulation was calling the wrong thing.

#14 @MichaelH
16 years ago

After installing link_categories.2.diff and doing a install.php, looks good except:

  1. Visible still not set in Add Link (wp-admin/link-add.php).
  1. Deleting Link didn't delete it from link2cat table and looks like it didn't updated the link_count in wp_categories.
  1. I've got two Link Categories (Blogroll and Mylinkcat) and 10 Links. The Blogroll Category has 9 Links, the other 2 Links (one of the Links is assigned both Categories). When I View the site, the Blogroll Category displays this error 10 times then displays 10 (should be nine) Links. Then Mylinkcat displays, followed the same error, 10 times, followed by 10 (should be two) Links:

Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\xampp\htdocs\wp16\wp-includes\links.php on line 161

Otherwise, couldn't duplicate any of the previous issues reported before.

Nice work Ryan!

Darn, see you added another patch so ignore number 2 above.

@ryan
16 years ago

Visibility and update time fixes.

#15 @ryan
16 years ago

  1. Fixed.
  1. Fixed, I think.

#16 @MichaelH
16 years ago

After installing link_categories.4.diff and doing a install.php;

  1. Fresh install, wp_categories table, the Blogroll category should have a link_count=7 not category_count=1
  1. Having the same Categories in Manage->Categories, and Links-Link Categories is interesting ;)
  1. wp-admin/link-categories.php has this message but the default Link Category is Blogroll:

Deleting a category does not delete posts from that category, it will just set them back to the default category Uncategorized.

should read

Deleting a category does not delete LINKS from that category, it will just set them back to the default category Blogroll.

  1. Deleting a Link Category kind of hangs with a message, Processing Data..., displayed at the bottom of the Categories box (wp-admin/link-categories.php). Never does do the delete.

@ryan
16 years ago

More fixes.

#17 @ryan
16 years ago

  • 1. Fixed
  • 2. Well... :-)
  • 3. Fixed.
  • 4. Not sure about that one. I think I got it. Works for me.

#18 @MichaelH
16 years ago

After installing link_categories.4.diff and doing a install.php;

  1. Deleting a Link Category assigns Links to the "Uncategorized" Category rather than default "Blogroll". Add a new Link Category (Mylinkcat), edit one of the existing Links and check both Blogroll and Mylinkcat and save it. Then delete the Mylinkcat Category. Table wp_link2cat shows the wrong Category for that link. Not to sure link_count in wp_categories is getting updated correctly there either.
  1. When trying to delete a Category in Manage->Categories, where that Category is not assigned to any Posts, but is assigned to a Link, it displays the message "Processing Data...". This is probably what I saw last night when I descibed it as "hanging". It should display a message saying "You can't delete this Category because it is assigned to one or more Links." The same thing happens in Links->Link Categories when you delete a Category that is not assigned to any Links but is assigned to Posts. Or course, there is the possiblility that if you delete a Category in either place, both the Posts and the Links should be assigned their corresponding "default" Category, but in that case the warning message should note that both Posts AND Links will be assigned their respective default Category.
  1. You should not be allowed to delete a Category in Links->Link Categories when it is used as the "default" Category for Posts even though it is not assigned to any Posts. This probably is working okay, but again when trying to delete a Category in this scenario it just displays the "Processing Data..." data message. Is a different message warranted saying that Category is designated as a "default" Category on the Options->Writing page?
  1. Still wonder how people with many Categories are going to react to seeing what they consider Link Categories when writing Posts?
  1. While digging in this, is it proper to consider assigning Categories to Pages?

@ryan
16 years ago

Unified category manager, name change

#19 @ryan
16 years ago

Okay. This patch goes back to having a unified category manager. It shows the number of posts and number of links per category and updates the delete messages to note that both links and posts will be reassigned to their respective defaults.

  1. I think I got this sorted.
  2. I still need to look at this.
  3. The default link and post cats are now designated as defaults and protected from deletion.
  4. The new unified category manager makes it clearer that categories are a shared resource. We'll see how that flies.
  5. Matt and I have kicked the idea around but are still siding on leaving categories off of pages unless a persuasive reason to have them pops up. Categories on pages are useful when trying to do Wiki-like things, but WP is not a Wiki out of the box.

#20 @ryan
16 years ago

Also, the latest patch uses the term Bookmarks instead of Links. Links is a rather overloaded term in WP, so lets experiment with other naming. I considered Favorites since IE made it so common, but in the context of a weblog links are not the only things that can be favored. So, I'm trying out Bookmarks for now. Another possibility is Blogroll/Blog Links. The terminology change is not complete. I'm just trying it out in a few places to see how it looks. If we add Firefox bookmark sync or the like, a terminology change looks more attractive.

#21 @MichaelH
16 years ago

After installing link_categories.6.diff and doing a new install.php;

  1. In options-writing.php change "Default link category" to "Default Bookmark Category". Of course I vote for cap letters on Bookmark and Category everywhere ;)
  1. In options-misc.php change "Track Links’ Update Times" to "Track Bookmarks’ Update Times"
  1. In link-import.php change the title "Import your blogroll from another system" change to "Import your Bookmarks from another system". Change "Now select a category you want to put these links in." to "Now select a category you want to put these Bookmarks in." And what do you want to do with this text "If a program or website you use allows you to export your links or subscriptions as OPML you may import them here."?
  1. In categories.php change "Deleting a category does not delete the posts and links in that category. Instead, posts in the deleted category are set to the category Uncategorized and links are set to Blogroll" to "Deleting a category does not delete the posts and Bookmarks in that Category. Instead, posts in the deleted Category are set to the Category Uncategorized and Bookmarks are set to Blogroll."
  1. In link-manager.php change "Manage Multiple Links:" to "Manage Multiple Bookmarks:" and "Use the checkboxes on the right to select multiple links and choose an action below:" to "Use the checkboxes on the right to select multiple Bookmarks and choose an action below:"
  1. In link-add.php change "Add Link" button to "Add Bookmark"
  1. In link-manager.php in the Order by pull down box should "Link ID" be "Bookmark ID"?
  1. In link-manager.php when you delete a Bookmark the confirmation message refers to link not Bookmark.
  1. Just in case you thought there was no meat in this list, in link-add.php when I added a Category called Mycat, unchecked Blogroll, checked Mycat, then added a Bookmark, ts put that Bookmark in the "Uncategorized" Category. The Category "Mycat" did get created properly.
  1. In categories.php, deleting a Category with one Bookmark using that Category, the link_id in wp_link2cat got set to zero (0) so of course in wp-admin/link-manager.php that Bookmark has nothing under the Category column.
  1. In categories.php the delete confirmation message refers to "links" but should be "Bookmarks".
  1. How about changing the the table name wp_link2cat to wp_bookmark2cat and wp_links to wp_bookmarks. And how about some of those field names like link_count? I'm sure this will go over big!

#22 @MichaelH
16 years ago

continuing from before:

  1. Assigned all eight Bookmarks to four Categories. View Site, and each of the four Categories shows all eight of Bookmarks.
  1. In link-manager.php separate each Bookmark's Categories with commas (it does that in edit.php).
  1. In link-manager.php, in the "Show bookmarks in category:" pull-down, select the "Uncategoried" Category where I have but one Bookmark, and this error happens when clicking Show:

WordPress database error: [Column 'link_id' in order clause is ambiguous]
SELECT * , IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated FROM wp_links LEFT JOIN wp_link2cat ON (wp_links.link_id = wp_link2cat.link_id) WHERE 1=1 AND category_id = 1 ORDER BY link_id ASC

  1. In link-manager.php, every "Order by:" choice should be a column on that screen. Either delete them from the the Order by: pull-down or add those columns (e.g. Owner and Rating).
  1. In link-manager.php, Toggle Visibility in the Manage Multiple Links section doesn't work

@ryan
16 years ago

Tweakage

#23 @ryan
16 years ago

1 - 11. Done

  1. Renaming the links table will cause consternation. I think we should leave 'links' in the guts.
  1. That's a feature. :-)

14 - 17. In the works.

#24 @MichaelH
16 years ago

Redescribing 13 above--assigned 1 Bookmark to Category 1, 1 Bookmark to Category 2, 1 Bookmark to Category 3, and 6 Bookmarks to Category 4, but all 8 Bookmarks get listed under each Category. That is a nice feature ;-)

@ryan
16 years ago

get_links() fix

#25 @ryan
16 years ago

Ah. Fixed.

@ryan
16 years ago

Toggle and ID sort fixes

#26 @ryan
16 years ago

Everything done but 14.

@ryan
16 years ago

Fix category list in opml importer.

#27 @MichaelH
16 years ago

After installing link_categories.10.diff and doing a new install.php;

  1. In link-manager.php separate each Bookmark's Categories with commas (it does that in edit.php) (was 14 before).
  1. In link-import.php, after the import is done it says "Inserted 50 links into category 1. All done! Go manage those links." Change the two references from links to Bookmarks.
  1. In link-import.php, it also says it imported into category 1, but it didn't write any records to wp_link2cat. It also didn't update the link_count in wp_categories.
  1. In categories.php the delete confirmation message refers to "links" but should be "Bookmarks".
  1. In categories.php, deleting a Category with one Bookmark updates wp_link2cat properly but not the link_count in wp_categories.
  1. If you have a Bookmark in two Categories (MyCat1 and MyCat2), and neither Category is the default Bookmark Category, if you delete the Category MyCat1, that Bookmark is left assigned to MyCat2 AND gets newly assigned the default (Blogroll) Category. Just not sure if that Bookmark should get assigned that default Category... Regardless, even though it does update wp_link2cat, it doesn't update the link_count in wp_categories.
  1. In categories.php, if you have both a Bookmark and a POST assigned to a Category that is not designated as a default, when you delete the Category it updates the link_count correctly in wp_categories but the category_count doesn't get updated (wp_post2cat gets updated okay though).
  1. Consider dividing the Bookmarks menu choices up and put them under the Write, Manage, and Import menus?

#28 @MichaelH
16 years ago

Oops, regarding 3 above, it should say it Inserted 50 Bookmarks into Category 2 (not Category 1). Actually displaying the correct Category Name rather than the ID would be nice ;-)

@ryan
16 years ago

Better category deletion behavior, bulk delete, remove bulk visibility toggle, remove reassign

#29 @ryan
16 years ago

Okay. Patch 11 adds a bulk delete option but removes bulk reassignment and bulk visibility toggle. Link ownership is going away entirely and soon visibility can be controlled on a per category level. I added links_private and posts_private to the category table in anticipation of private categories.

  1. On the todo.
  1. and 3. I made some changes here but haven't tested yet. I'll probably overhaul the importer soon.
  1. Fixed.
  1. Fixed.
  1. This has long been an issue with posts. Assignment to the default category should no longer happen if the post or bookmark has more than one category assigned to it.
  1. Fixed.
  1. Actually, Manage is getting pretty big. We might move things in Manage up a level so that you can get at more things with one click. We can tackle that in another bug.

#30 @MichaelH
16 years ago

After installing link_categories.11.diff and doing a new install.php;

  1. This in the address bar, http://localhost/wp21/wp-admin/link.php?link_id=6&action=edit, after adding two Categories 'on the fly' -- Mycat1,Mycat2. It put those Categories in the list of available Categories and also displayed 12 instances of "undefined". Strange order there also. But it didn't update wp_categories or wp_link2cat. Problem happens adding even one Category there. Does the same thing writing a post.
  1. In categories.php it allows you to Add a Category but the tables never get written though it does splash the message "Category added". This is left in the address bar: http://localhost/wp21/wp-admin/categories.php?message=1#addcat
  1. In link-manager.php, the box at the bottom says "Delete Checked Links". Should be "Delete Checked Bookmarks".
  1. In wp-admin/link-manager.php?deleted=5 the splash message say "! 5 comments deleted" should be "! 5 Bookmarks deleted". Also, the box at the bottom then says "Deleted Checked Links" should be "Deleted Checked Bookmarks".
  1. Imported bookmarks got put into Category ID 1 (Uncategorized0 even though told it to put in Category 2 (Blogroll). Actually it suggested Blogroll as the import Category so I never changed it.
  1. Even doing a bulk delete of 50 Bookmarks, then doing a new "Order by:" and clicking the Show button, it still shows this in the address bar: http://localhost/wp21/wp-admin/link-manager.php?deleted=50 and again displays the splash message that "! 50 comments deleted".
  1. Starting with two Categories--in categories.php, after deleting a Category with one Bookmark it redislays the first and only Category, but shows the wrong Link Count. Doing a browser refresh caused it to display correctly.

#31 @MichaelH
16 years ago

continued:

  1. This error when doing upgrade.php from a 1.5.2 database;

WordPress database error: [Unknown column 'links_visible' in 'field list'] INSERT INTO wp_categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_visible) VALUES ('0', 'Blogroll delivered with WordPress', 'blogroll-delivered-with-wordpress', , '0', )

#32 @ryan
16 years ago

  1. and 2. I can't reproduce, but I think its failing for you because of 8.
  1. Fixed.
  1. Fixed.
  1. Fixed, I think.
  1. Yeah, that message is going to stick around as long as deleted= is in the URI.
  1. The AJAX removes the deleted bookmark from the list but doesn't refresh the rest of the list. Don't know what to do about that.
  1. Fixed. Should fix 1. and 2. as well.

@ryan
16 years ago

More fixes.

#33 @ryan
16 years ago

[3570]

It's in. I'll keep this bug open while things settles.

#34 @szepter
16 years ago

Hence categories are unified now, I think we should delete the "linkcategories"-table on upgrades. On fresh installs it even shouldn't be created.

#35 @ryan
16 years ago

[3598] removes linkcategories from the schema so that it is not created for fresh installs. Let's hold off on dropping it during upgrades until we're happy with the new design and code.

#37 @karmadude
16 years ago

I like the link categories being there, but it would be more powerful if it were a tree structure like the post categories. And then if a link category tree can be associated with a post category or categories, that would be perfect. The reason I am seeking this feature, is because on my blog (http://www.counterjumper.com), I have context sensitive links, and I want the links to change according to the category of post one is viewing.

I kind of achive this with the current version of wordpress, but it would be more powerful and easier to implement, if wordress supported a category tree for links, and then having the ability to associate that with a post category. I also feel we should not get rid of the link categories, it is important to keep it seperate.

Here is the get_linkobjectsin method I have added to links.php to get links from multiple link categories.

function get_linkobjectsin($category = "-1", $orderby = 'name', $limit = -1) {
    global $wpdb;

    $sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
    if ($category != -1) {
        $sql .= " AND link_category IN ($category) ";
    }
    if ($orderby == '')
        $orderby = 'id';
    if (substr($orderby,0,1) == '_') {
        $direction = ' DESC';
        $orderby = substr($orderby,1);
    }
    if (strcasecmp('rand',$orderby) == 0) {
        $orderby = 'rand()';
    } else {
        $orderby = " link_" . $orderby;
    }
    $sql .= ' ORDER BY ' . $orderby;
    $sql .= $direction;
    /* The next 2 lines implement LIMIT TO processing */
    if ($limit != -1)
        $sql .= " LIMIT $limit";

    $results = $wpdb->get_results($sql);
    if ($results) {
        foreach ($results as $result) {
            $result->link_url         = $result->link_url;
            $result->link_name        = $result->link_name;
            $result->link_description = $result->link_description;
            $result->link_notes       = $result->link_notes;
            $newresults[] = $result;
        }
    }
    return $newresults;
}

#38 @rgovostes
16 years ago

  • Keywords has-patch added

#39 @westi
16 years ago

Whilest reviewing the link / post categories stuff in relation to a recent testers post (http://comox.textdrive.com/pipermail/wp-testers/2006-September/002838.html)

  1. Create Bookmark doesn't only lists categories which already contain links - this can exclude the default bookmark category if it has no links in it.

#40 @ryan
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Let's track further issues in separate bugs. Closing this one.

Note: See TracTickets for help on using tickets.