Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion controller/contribution/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public function manage($contrib_type, $contrib)
$authors,
$this->settings['custom'],
$this->contrib->contrib_name_clean,
$this->settings['permalink']
$this->settings['permalink'],
$old_settings['contrib_name']
));

// Did we succeed or have an error?
Expand Down
24 changes: 23 additions & 1 deletion includes/objects/contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1590,10 +1590,11 @@ public function change_permalink($new_permalink)
* @param array $custom_fields Custom field values.
* @param string $old_permalink Old permalink. Defaults to empty string.
* @param string|null $new_permalink Submitted permalink. Defaults to the value on the entity.
* @param string $old_name Old contribution name. Defaults to empty string.
*
* @return array Returns array containing any errors found.
*/
public function validate($contrib_categories, $authors, $custom_fields, $old_permalink = '', $new_permalink = null)
public function validate($contrib_categories, $authors, $custom_fields, $old_permalink = '', $new_permalink = null, $old_name = '')
{
phpbb::$user->add_lang('ucp');

Expand All @@ -1603,6 +1604,10 @@ public function validate($contrib_categories, $authors, $custom_fields, $old_per
{
$error[] = phpbb::$user->lang['EMPTY_CONTRIB_NAME'];
}
else if ($this->contrib_name !== $old_name && $this->is_link($this->contrib_name))
{
$error[] = phpbb::$user->lang['CONTRIB_NAME_IS_LINK'];
}

$metadata = array(
$this->contrib_name,
Expand Down Expand Up @@ -1800,6 +1805,17 @@ protected function generate_permalink_slug($value)
return preg_replace('/[^\p{L}\p{M}\p{N}_]+/u', '_', url::generate_slug($value));
}

/**
* Check whether a value is shaped like a link rather than a name.
*
* @param string $value
* @return bool
*/
protected function is_link($value)
{
return (bool) preg_match('#^(?:[a-z][a-z0-9+.\-]*://|www\.)#i', trim($value));
}

/*
* Validate a contrib permalink
*
Expand All @@ -1816,6 +1832,12 @@ public function validate_permalink($permalink, $old_permalink)
return false;
}

// A pasted link must not be echoed back as a valid permalink example.
if ($this->is_link($permalink))
{
return phpbb::$user->lang['CONTRIB_PERMALINK_IS_LINK'];
}

$generated_permalink = $this->generate_permalink_slug($permalink);
if ($generated_permalink !== $permalink)
{
Expand Down
2 changes: 2 additions & 0 deletions language/en/contributions.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'CONTRIB_LOCAL_NAME' => 'Local name',
'CONTRIB_LOCAL_NAME_EXPLAIN' => 'The localized name of the language, e.g. <em>Français</em>.',
'CONTRIB_NAME' => 'Contribution Name',
'CONTRIB_NAME_IS_LINK' => 'The contribution name cannot be a link. Please enter the name of your contribution.',
'CONTRIB_NEW' => 'New',
'CONTRIB_NONACTIVE_AUTHORS' => 'Non-Active Co-Authors (Past Contributors)',
'CONTRIB_NONACTIVE_AUTHORS_EXPLAIN' => 'Non-Active Co-Authors can not manage anything for the contribution and are only listed as previous authors.',
Expand All @@ -87,6 +88,7 @@
'CONTRIB_PERMALINK' => 'Contribution Permalink',
'CONTRIB_PERMALINK_EXISTS' => 'That contribution permalink is already in use.',
'CONTRIB_PERMALINK_EXPLAIN' => 'Cleaned version of the contribution name, used to build the url for the contribution.<br /><strong>Leave blank to have one automatically created based on the contribution name.</strong>',
'CONTRIB_PERMALINK_IS_LINK' => 'The permalink cannot be a link. It is the short address of the contribution page, built from the contribution name.',
'CONTRIB_RELEASE_DATE' => 'Release date',
'CONTRIB_STATUS' => 'Contribution status',
'CONTRIB_STATUS_EXPLAIN' => 'Change the contribution status',
Expand Down