Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-19383: Display a title on createlink #256

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Sereza7
Copy link
Contributor

@Sereza7 Sereza7 commented Mar 6, 2023

Jira: https://jira.xwiki.org/browse/XWIKI-19383
PR Changes:

  • Added a title to the wikicreatelink spans rendered from user generated content
  • Added a default behavior for standalone use of xwiki-rendering, and an endpoint to complete this behaviour from xwiki-platform.

@Sereza7 Sereza7 marked this pull request as ready for review March 16, 2023 16:15
@Sereza7
Copy link
Contributor Author

Sereza7 commented Mar 16, 2023

PR Changes:

  • Solved the mismatch in hints for the URITitleGenerator implementation

NOTE: This commit needs to be merged with/before xwiki/xwiki-platform#2104

Default behavior is to just use the name of the page to create as the title.

@Override
public String generateCreateTitle(ResourceReference reference)
{
return "Create page: " + reference.getReference();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a translation used here no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default behavior, with the rendering module on its own. AFAIK there is no access to translations here.
See the full implementation in xwiki-platform.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we should discuss a way to allow xwiki platform to inject the a translation here. Having some text in an unknown language is not going to help accessibility for non-English speaking users.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, iiuc in relation with xwiki/xwiki-platform#2104, XWikiDocumentURITitleGenerator will be used instead of the default implem. And in this case the returned title is translated.
If that's correct might be worth adding some comments :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is overwritten by the xwiki platform class I linked above.
I followed the pattern used so far when we needed translations in xwiki-rendering.
See Michael's comment on the jira issue.

Other similar uses of this pattern can be found here and here.
I thought it would be better to have, in all cases, a readable english title instead of just a value that could hold anything (possibly complete gibberish). We could remove this default formatting to just return reference.getReference() but I don't think it'd be best.

* @since 15.2-RC1
*/
@Component
@Named("doc")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS this is the default component, so the one to be used "by default", so I don't think it should have a @Named.
Now if it's not the default component, then you should probably rename the class.

Copy link
Contributor Author

@Sereza7 Sereza7 Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default component used when xwiki-rendering runs on its own. This component needs to have an hint that corresponds to the kind of object I want to process. It's not the default on the resourceType axis.
I'm fixing the names of both the classes to make it clearer that the resourceType is document 👍
I replicated the pattern used here.


/**
* Generate Resource Reference titles for URIs. For example an implementation for MAILTO URIs would remove the scheme
* part and the query string part.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you indicated below:

// Look for a component implementing URITitleGenerator with a role hint matching the link scheme.

This should be specified in this documentation here, as it's how the implementation should be named.

@Sereza7
Copy link
Contributor Author

Sereza7 commented Mar 20, 2023

PR Changes:

  • Refactored name
  • Fixed hint to match DocumentXHTMLLinkTypeRenderer.
  • Moved behavior from the AbstractXHTMLLinkTypeRenderer to DocumentXHTMLLinkTypeRenderer
  • Marked the API as unstable
  • Fixed code style
  • Improved comments

* Used to generate a link title.
*/
@Inject
private URITitleGenerator defaultTitleGenerator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not going to work since there's no default implementation.

} catch (Exception e) {
logger.warn("Error while loading component for generating URI title: [{}]",
ExceptionUtils.getRootCauseMessage(e));
logger.debug("Full stack trace: ", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write:

String message = "Error while loading component for generating URI title";
if (logger.isDebugEnabled()) {
    logger.debug(message, e);
} else {
    logger.warn(String.format("%s: [{}]", message), ExceptionUtils.getRootCauseMessage(e));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition you should also log the reference and explain which component we're talking about.

*/
@Role
@Unstable
public interface URITitleGenerator
Copy link
Member

@vmassol vmassol Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why it's a URI. I'd name this: ResourceReferenceTitleGenerator.

EDIT: I've just realized that the implementation is only for wanted links and not to generate titles in general. Thus, I'd name this WantedLinkTitleGenerator.

* @version $Id$
* @since 15.2RC1
*/
@Component(hints = {"doc", "page"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error here, should not contain any hint.

* The implementations should be named according to the kind of reference they process.
*
* @version $Id$
* @since 15.2RC1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be updated to 15.3RC1 now ;)

getXHTMLWikiPrinter().printXMLStartElement(SPAN, new String[][] { { CLASS, "wikigeneratedlinkcontent" } });
getXHTMLWikiPrinter().printXMLStartElement(SPAN, new String[][]
{
{ CLASS, "wikigeneratedlinkcontent" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't change the formatting (unless there's a good reason)

import org.xwiki.rendering.renderer.reference.link.URITitleGenerator;

/**
* Generate link titles for DOC URIs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve the javadoc and explain what it does (use the reference as the title) and explain that it's supposed to be overridden to provide better titles.

@vmassol
Copy link
Member

vmassol commented Mar 29, 2023

Missing some test (which explains why the code is buggy - no default implementation - but it was not noticed). Have you built with -Pquality?

private URITitleGenerator getTitleGenerator(ResourceReference reference)
{
URITitleGenerator titleGenerator = this.defaultTitleGenerator;
if (this.componentManager.hasComponent(URITitleGenerator.class, reference.getType().getScheme())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why need this as the implementation is fixed and doesn't depend on the resource reference type.

@Sereza7 Sereza7 marked this pull request as draft March 31, 2023 08:52
titleGenerator = this.componentManager.getInstance(WantedLinkTitleGenerator.class,
reference.getType().getScheme());
} catch (Exception e) {
String message = "Could not find a [WantedLinkTitleGenerator] component to generate the wanted "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use WantedLinkTitleGenerator.class.getName() instead of hardcoding it IMO.

WantedLinkTitleGenerator titleGenerator = this.defaultTitleGenerator;
try {
titleGenerator = this.componentManager.getInstance(WantedLinkTitleGenerator.class,
reference.getType().getScheme());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, this won't fallback to the default. I think a fallback to the default should be implemented, otherwise I'm not sure why there is a default implementation at all.

Sereza7 and others added 10 commits April 5, 2024 11:14
* Added a title attribute to the generated wikicreatelink span
* Fixed wrong since javadocs tags
* Added an hint on the URITitleGenerator component
* Fixed the hint of the URITitleGenerator implementation
* Refactored name
* Fixed hint to match DocumentXHTMLLinkTypeRenderer.
* Moved behavior from the AbstractXHTMLLinkTypeRenderer to DocumentXHTMLLinkTypeRenderer
* Fixed since annotation format
* Marked the API as unstable
* Fixed comments.
* Inject logger

Co-authored-by: Manuel Leduc <manuel.leduc@xwiki.com>
* Fixed code style
* Used logger injection
* Fixed a constant name
* Added a comment to DefaultDocumentURITileGenerator
* Fixed types and names

TODO:
* Fix tests
* Check DocumentXHTMLLinkTypeRenderer.java L105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants