Jump to content

Difference in length between PageName returned from sanitizer and actual page name created.


millipedia
 Share

Recommended Posts

I'm building an import tool for sucking in data from a Google spreadsheet. I'm creating pages from each row and that's all working fine.

When I'm running the import I want to check we haven't already created a page with this title, so I'm taking the title field of the data, converting it into what I expect the name of the new page to be and then seeing it we already have a page with that name.

This works fine most of the time, but when we have a long title the values I get from sanitizing to PageName are not the actual length of the page name created. For example:

$title='What to do with ‘white working-class’ underachievement? Framing ‘white working-class’ underachievement in post-Brexit Referendum England';
echo '<br>' . $title;

$nice_name = $this->sanitizer->pageName($title);
echo '<br> Pagename : '  . $nice_name ;

$nice_name = $this->sanitizer->pageName($title, true);
echo '<br> Pagename with beautify: '  . $nice_name ;

$nice_name = $this->sanitizer->pageNameTranslate($title);
echo '<br> PagenameTranslate : '  . $nice_name;

gives the result

What to do with ‘white working-class’ underachievement? Framing ‘white working-class’ underachievement in post-Brexit Referendum England

Pagename : what-to-do-with-white-working-class-underachievement--framing-white-working-class-underachievement-in-post-brexit-re
Pagename with beautify: what-to-do-with-white-working-class-underachievement-framing-white-working-class-underachievement-in-post-brexit-referendum
PagenameTranslate : what-to-do-with-white-working-class-underachievement-framing-white-working-class-underachievement-in-post-brexit-referendum 

but the page name that is actually created by that title when I do $pages->add  is:

what-to-do-with-white-working-class-underachievement-framing-white-working-class-underachievement-in-post

even stripping out quote marks etc I can't reliably get it to be the same length so can't test against it.

Any clues as to what I should be using?

 

Link to comment
Share on other sites

At the time of import of new pages you should use the same sanitizer that you use later for the exist check and assign the page name manually when creating. That should give you consistency. 

  • Like 3
Link to comment
Share on other sites

1 hour ago, gebeer said:

At the time of import of new pages you should use the same sanitizer that you use later for the exist check and assign the page name manually when creating. That should give you consistency. 

That's such a sensible idea. I only wish I'd thought of it 3 hours ago...

I'd still kind of like to know what the default page add is doing, but this absolutely works. Thanks for your help.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...