Ticket #5085 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

Unify generator strings

Reported by: docwhat Owned by: westi
Priority: normal Milestone: 2.5
Component: General Version: 2.3
Severity: normal Keywords: privacy generator has-patch
Cc:

Description

In WordPress 2.3, there are about a dozen plus places that use a generator comment or a generator XML element.

I would like to suggest adding an API for building the generator interfaces. However, to me, the only obvious (and consistent) generator string is the XML comment.

wp_generator_comment() would generate an XML comment such as:

<!-- generator="wordpress/2.3" -->

I need help figuring out an API for the various XML node formats, such as:

<generator uri="http://wordpress.com/" version="1.0.5-dc">WordPress.com Atom API</generator>
<generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
<generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
<generator uri="http://wordpress.org/" version="<?php bloginfo_rss('version'); ?>">WordPress</generator>
<generator uri="http://wordpress.org/" version="<?php bloginfo('version'); ?>">WordPress</generator>
<admin:generatorAgent rdf:resource="http://wordpress.org/?v=<?php echo $wp_version ?>"/>

Tracing through the code I couldn't easily tell what bloginfo_rss returns, I assume it returns $wp_version;

This would prevent repetition of code and allow for admins or plugin developers to add or remove information they are not comfortable sending out.

Ciao!

PS: This is related to bug #5065 in spirit.

Attachments

wp-generator.patch Download (8.8 KB) - added by docwhat 4 years ago.
wp-free-gen.php Download (841 bytes) - added by docwhat 4 years ago.
generator.diff Download (9.6 KB) - added by westi 4 years ago.
Updated patch

Change History

Most of the feeds and such have their own syntax for expressing the generator. So there's no one universal way.

I'd suggest something like this:

function get_generator($type='comment')
{
	switch ($type) {
	case 'meta':
		$gen = '<meta name="generator" content="WordPress/'. bloginfo('version') .'" />';
		break;
	case 'atom':
		$gen = '<generator uri="http://wordpress.org/" version="'.bloginfo_rss('version').'">WordPress</generator>';
		break;
	case 'rss2':
		$gen = '<generator>http://wordpress.org/?v='.bloginfo_rss('version').'</generator>';
		break;
	case 'rdf':
		$gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v='.bloginfo_rss('version').'" />';
		break;
	default: // case 'comment':
		$gen = '<!-- generator="WordPress/'.bloginfo('version').'" -->";
		break;
	}
	
	return apply_filters('get_generator',$gen);
}

Then call the appropriate one with <?php echo get_generator('whatever'); ?> at the right point in the code.

Thank you, I think that's a great idea. I'll do that.

Ciao!

comment:3 follow-up: ↓ 4   JeremyVisser4 years ago

  • Owner changed from anonymous to docwhat
  • Milestone changed from 2.5 to 2.4

I like it. It's somewhat related to #4803, also.

comment:4 in reply to: ↑ 3 ; follow-up: ↓ 7   foolswisdom4 years ago

Replying to JeremyVisser:

milestone changed from 2.5 to 2.4.

Generally, I've been leaving things without core developer owner or patch to trunk+1 .

docwhat4 years ago

docwhat4 years ago

  • Keywords privacy generator added

JeremyVisser: Thanks for the info. Some of the concerns there applied to my patch, too.

Everyone: I have attached a patch. The only problems I can think of is where it's located in the file or it's name. I can make those changes quickly, feel free to give me feedback.

Ciao!

  • Keywords has-patch added

comment:7 in reply to: ↑ 4   JeremyVisser4 years ago

Replying to foolswisdom:

Replying to JeremyVisser:

milestone changed from 2.5 to 2.4.

Generally, I've been leaving things without core developer owner or patch to trunk+1 .

Thanks for that Lloyd. I'll try and remember that for next time. :) Part of the reason I changed it to 2.4 was that #4803's milestone was 2.4.

comment:8 follow-up: ↓ 9   JeremyVisser4 years ago

In line with #4803, the generator tags could then be stripped out of the templates, and adding something like this somewhere:

add_action( 'wp_head', create_function('', "wp_get_generator('xhtml');") );

comment:9 in reply to: ↑ 8   docwhat4 years ago

Replying to JeremyVisser:

In line with #4803, the generator tags could then be stripped out of the templates, and adding something like this somewhere:

Even better, you can detect the DTD and user 'xhtml' or 'html' as appropriate!

Ciao!

  • Owner changed from docwhat to westi
  • Status changed from new to assigned

I will take a look at these patches and review them.

Ok I've reworked the patch to include the changes from #4803 and to improve the functionality a little bit.

New patch about to be attached.

Here is a summary of the changes:

 wp-app.php                           |    2 -
 wp-content/themes/classic/header.php |    2 -
 wp-content/themes/default/header.php |    2 -
 wp-includes/default-filters.php      |    3 +-
 wp-includes/feed-atom-comments.php   |    2 -
 wp-includes/feed-atom.php            |    2 -
 wp-includes/feed-rdf.php             |    4 +--
 wp-includes/feed-rss.php             |    2 -
 wp-includes/feed-rss2-comments.php   |    4 +--
 wp-includes/feed-rss2.php            |    4 +--
 wp-includes/general-template.php     |   43 +++++++++++++++++++++++++++++++++++
 wp-links-opml.php                    |    2 -
 12 files changed, 56 insertions(+), 16 deletions(-)

westi4 years ago

Updated patch

Suggestion: In feed-rss2.php, feed-rss2-comments.php, and feed-rdf.php, remove the call to <?php the_generator( 'comment' ); ?>. It's unnecessary, the rss2 format contains the stuff for a generator explicitly, we don't need an extra comment type thing in there. It's just taking up space to give the same information that's available in there already.

Other than that, +1.

Note to self: We also need to include the generator for the export file in these changes

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

(In [6195]) Centralise generator generation, move theme generator generation to wp-head hook. Fixes #5085, #4803. props docwhat, Viper007Bond.

  • Status changed from closed to reopened
  • Type changed from defect to enhancement
  • Version set to 2.3
  • Resolution fixed deleted

Shouldn't we use GMT for the generation time (in the export one)?

Also, a small nitpick: spaces after the commas in the_generator().

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

Sorry, I'll make a new ticket.

I always forget.

Note: See TracTickets for help on using tickets.