Format number for message 'title-invalid-too-long'
[lhc/web/wiklou.git] / includes / title / MediaWikiTitleCodec.php
index 20034b7..01575ac 100644 (file)
@@ -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'] );
@@ -232,7 +232,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
 
                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