X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ftitle%2FMediaWikiTitleCodec.php;h=01575ac0b042b6e36589b6b3c6e8beeeb314e44f;hb=2b368515ecd70aef6e145efcf1727daa875e890b;hp=c05a87dec1cc829a8a57d303a52868a3adff8deb;hpb=b5cf0db5627d6c0bd3483db5ed57e50dfee36227;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index c05a87dec1..01575ac0b0 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -137,12 +137,12 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { // Interwiki links are not supported by TitleValue if ( $parts['interwiki'] !== '' ) { - throw new MalformedTitleException( 'Title must not contain an interwiki prefix: ' . $text ); + throw new MalformedTitleException( 'title-invalid-interwiki', $text ); } // Relative fragment links are not supported by TitleValue if ( $parts['dbkey'] === '' ) { - throw new MalformedTitleException( 'Title must not be empty: ' . $text ); + throw new MalformedTitleException( 'title-invalid-empty', $text ); } return new TitleValue( $parts['namespace'], $parts['dbkey'], $parts['fragment'] ); @@ -230,9 +230,9 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { ); $dbkey = trim( $dbkey, '_' ); - if ( strpos( $dbkey, UTF8_REPLACEMENT ) !== false ) { + if ( strpos( $dbkey, UtfNormal\Constants::UTF8_REPLACEMENT ) !== false ) { # Contained illegal UTF-8 sequences or forbidden Unicode chars. - throw new MalformedTitleException( 'Bad UTF-8 sequences found in title: ' . $text ); + throw new MalformedTitleException( 'title-invalid-utf8', $text ); } $parts['dbkey'] = $dbkey; @@ -246,7 +246,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { } if ( $dbkey == '' ) { - throw new MalformedTitleException( 'Empty title: ' . $text ); + throw new MalformedTitleException( 'title-invalid-empty', $text ); } # Namespace or interwiki prefix @@ -263,11 +263,11 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { if ( $ns == NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) { if ( $this->language->getNsIndex( $x[1] ) ) { # Disallow Talk:File:x type titles... - throw new MalformedTitleException( 'Bad namespace prefix: ' . $text ); + throw new MalformedTitleException( 'title-invalid-talk-namespace', $text ); } elseif ( Interwiki::isValidInterwiki( $x[1] ) ) { //TODO: get rid of global state! # Disallow Talk:Interwiki:x type titles... - throw new MalformedTitleException( 'Interwiki prefix found in title: ' . $text ); + throw new MalformedTitleException( 'title-invalid-talk-namespace', $text ); } } } elseif ( Interwiki::isValidInterwiki( $p ) ) { @@ -324,8 +324,9 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { # Reject illegal characters. $rxTc = self::getTitleInvalidRegex(); - if ( preg_match( $rxTc, $dbkey ) ) { - throw new MalformedTitleException( 'Illegal characters found in title: ' . $text ); + $matches = array(); + if ( preg_match( $rxTc, $dbkey, $matches ) ) { + throw new MalformedTitleException( 'title-invalid-characters', $text, array( $matches[0] ) ); } # Pages with "/./" or "/../" appearing in the URLs will often be un- @@ -343,23 +344,22 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { substr( $dbkey, -3 ) == '/..' ) ) { - throw new MalformedTitleException( 'Bad title: ' . $text ); + throw new MalformedTitleException( 'title-invalid-relative', $text ); } # Magic tilde sequences? Nu-uh! if ( strpos( $dbkey, '~~~' ) !== false ) { - throw new MalformedTitleException( 'Bad title: ' . $text ); + throw new MalformedTitleException( 'title-invalid-magic-tilde', $text ); } # Limit the size of titles to 255 bytes. This is typically the size of the # underlying database field. We make an exception for special pages, which # don't need to be stored in the database, and may edge over 255 bytes due # to subpage syntax for long titles, e.g. [[Special:Block/Long name]] - if ( - ( $parts['namespace'] != NS_SPECIAL && strlen( $dbkey ) > 255 ) - || strlen( $dbkey ) > 512 - ) { - throw new MalformedTitleException( 'Title too long: ' . substr( $dbkey, 0, 255 ) . '...' ); + $maxLength = ( $parts['namespace'] != NS_SPECIAL ) ? 255 : 512; + if ( strlen( $dbkey ) > $maxLength ) { + throw new MalformedTitleException( 'title-invalid-too-long', $text, + array( Message::numParam( $maxLength ) ) ); } # Normally, all wiki links are forced to have an initial capital letter so [[foo]] @@ -374,7 +374,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { # self-links with a fragment identifier. if ( $dbkey == '' && $parts['interwiki'] === '' ) { if ( $parts['namespace'] != NS_MAIN ) { - throw new MalformedTitleException( 'Empty title: ' . $text ); + throw new MalformedTitleException( 'title-invalid-empty', $text ); } } @@ -390,7 +390,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { // Any remaining initial :s are illegal. if ( $dbkey !== '' && ':' == $dbkey[0] ) { - throw new MalformedTitleException( 'Title must not start with a colon: ' . $text ); + throw new MalformedTitleException( 'title-invalid-leading-colon', $text ); } # Fill fields