Merge "(bug 30600) Simple URL validation"

This commit is contained in:
Siebrand 2012-09-06 19:43:29 +00:00 committed by Gerrit Code Review
commit 95dbca29bc
2 changed files with 14 additions and 3 deletions

View file

@ -84,6 +84,7 @@ Remember that this can break existing links.',
Possibly it does not exist.',
'interwiki-badprefix' => 'Specified interwiki prefix "$1" contains invalid characters',
'interwiki-submit-empty' => 'The prefix and URL cannot be empty.',
'interwiki-submit-invalidurl' => 'The protocol of the URL is invalid.',
# interwiki log
'log-name-interwiki' => 'Interwiki table log',
@ -182,6 +183,7 @@ Parameter $1 contains the following (a link): [//www.mediawiki.org/wiki/Manual:I
'interwiki-badprefix' => 'Error message displayed when trying to save an interwiki prefix that contains invalid characters. Parameters:
* $1 is the interwiki prefix containing invalid characters.',
'interwiki-submit-empty' => 'Error message displayed when trying to save an interwiki prefix with an empty prefix or an empty URL.',
'interwiki-submit-invalidurl' => 'Error message displayed when trying to save an interwiki prefix with an invalid URL.',
'log-name-interwiki' => 'Part of the interwiki extension. This message is shown as page title on Special:Log/interwiki.',
'logentry-interwiki-iw_add' => 'Shows up in "[[Special:Log/interwiki]]" when someone has added a prefix. Leave parameters and text between brackets exactly as it is.
* $1 is the username of the user who added it

View file

@ -132,7 +132,7 @@ class SpecialInterwiki extends SpecialPage {
$button = 'edit';
} elseif ( $action === 'add' ) {
$prefix = $request->getVal( 'wpInterwikiPrefix', $request->getVal( 'prefix' ) );
$prefix = Xml::input( 'wpInterwikiPrefix', 20, $prefix,
$prefixElement = Xml::input( 'wpInterwikiPrefix', 20, $prefix,
array( 'tabindex' => 1, 'id' => 'mw-interwiki-prefix', 'maxlength' => 20 ) );
$local = $request->getCheck( 'wpInterwikiLocal' );
$trans = $request->getCheck( 'wpInterwikiTrans' );
@ -145,7 +145,7 @@ class SpecialInterwiki extends SpecialPage {
if ( $action === 'add' || $action === 'edit' ) {
$formContent = Html::rawElement( 'tr', null,
Html::element( 'td', $label, $this->msg( 'interwiki-prefix-label' )->text() ) .
Html::rawElement( 'td', null, '<tt>' . $prefix . '</tt>' )
Html::rawElement( 'td', null, '<tt>' . $prefixElement . '</tt>' )
) . Html::rawElement( 'tr', null,
Html::rawElement( 'td', $label, Xml::label( $this->msg( 'interwiki-local-label' )->text(), 'mw-interwiki-local' ) ) .
Html::rawElement( 'td', $input, Xml::check( 'wpInterwikiLocal', $local, array( 'id' => 'mw-interwiki-local' ) ) )
@ -161,7 +161,7 @@ class SpecialInterwiki extends SpecialPage {
$form = Xml::fieldset( $topmessage, Html::rawElement( 'form',
array( 'id' => "mw-interwiki-{$action}form", 'method' => 'post',
'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ),
'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit', 'prefix' => $prefix ) ) ),
Html::rawElement( 'p', null, $intromessage ) .
Html::rawElement( 'table', array( 'id' => "mw-interwiki-{$action}" ),
$formContent . Html::rawElement( 'tr', null,
@ -236,6 +236,15 @@ class SpecialInterwiki extends SpecialPage {
return;
}
// Simple URL validation: check that the protocol is one of
// the supported protocols for this wiki.
// (bug 30600)
if ( !wfParseUrl( $theurl ) ) {
$this->error( 'interwiki-submit-invalidurl' );
$this->showForm( $do );
return;
}
if ( $do === 'add' ) {
$dbw->insert( 'interwiki', $data, __METHOD__, 'IGNORE' );
} else { // $do === 'edit'