Moved getTitleInvalidRegex() from Title to MediaWikiTitleCodec
authorEvan McIntire <mcintire.evan@gmail.com>
Sat, 27 Dec 2014 23:00:11 +0000 (18:00 -0500)
committerUmherirrender <umherirrender_de.wp@web.de>
Wed, 31 Dec 2014 11:29:36 +0000 (11:29 +0000)
Deprecated it in Title, and updated all current references to use the
non-deprecated version in MediaWikiTitleCodec

Change-Id: I2b9c36992028c97f695f2b95ba027fbb11904b57

includes/Title.php
includes/title/MediaWikiTitleCodec.php
languages/Language.php
resources/src/mediawiki/mediawiki.Title.js

index cf11bd3..d0c8b3b 100644 (file)
@@ -614,28 +614,13 @@ class Title {
         * Note that this doesn't pick up many things that could be wrong with titles, but that
         * replacing this regex with something valid will make many titles valid.
         *
-        * @todo move this into MediaWikiTitleCodec
+        * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead
         *
         * @return string Regex string
         */
        static function getTitleInvalidRegex() {
-               static $rxTc = false;
-               if ( !$rxTc ) {
-                       # Matching titles will be held as illegal.
-                       $rxTc = '/' .
-                               # Any character not allowed is forbidden...
-                               '[^' . self::legalChars() . ']' .
-                               # URL percent encoding sequences interfere with the ability
-                               # to round-trip titles -- you can't link to them consistently.
-                               '|%[0-9A-Fa-f]{2}' .
-                               # XML/HTML character references produce similar issues.
-                               '|&[A-Za-z0-9\x80-\xff]+;' .
-                               '|&#[0-9]+;' .
-                               '|&#x[0-9A-Fa-f]+;' .
-                               '/S';
-               }
-
-               return $rxTc;
+               wfDeprecated( __METHOD__, '1.25' );
+               return MediaWikiTitleCodec::getTitleInvalidRegex();
        }
 
        /**
index 0185b97..c05a87d 100644 (file)
@@ -323,7 +323,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
                }
 
                # Reject illegal characters.
-               $rxTc = Title::getTitleInvalidRegex();
+               $rxTc = self::getTitleInvalidRegex();
                if ( preg_match( $rxTc, $dbkey ) ) {
                        throw new MalformedTitleException( 'Illegal characters found in title: ' . $text );
                }
@@ -398,4 +398,33 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
 
                return $parts;
        }
+
+       /**
+        * Returns a simple regex that will match on characters and sequences invalid in titles.
+        * Note that this doesn't pick up many things that could be wrong with titles, but that
+        * replacing this regex with something valid will make many titles valid.
+        * Previously Title::getTitleInvalidRegex()
+        *
+        * @return string Regex string
+        * @since 1.25
+        */
+       public static function getTitleInvalidRegex() {
+               static $rxTc = false;
+               if ( !$rxTc ) {
+                       # Matching titles will be held as illegal.
+                       $rxTc = '/' .
+                               # Any character not allowed is forbidden...
+                               '[^' . Title::legalChars() . ']' .
+                               # URL percent encoding sequences interfere with the ability
+                               # to round-trip titles -- you can't link to them consistently.
+                               '|%[0-9A-Fa-f]{2}' .
+                               # XML/HTML character references produce similar issues.
+                               '|&[A-Za-z0-9\x80-\xff]+;' .
+                               '|&#[0-9]+;' .
+                               '|&#x[0-9A-Fa-f]+;' .
+                               '/S';
+               }
+
+               return $rxTc;
+       }
 }
index 72cc1ac..d46845f 100644 (file)
@@ -318,7 +318,7 @@ class Language {
                // see bugs 37564, 37587, 36938
                $cache[$code] =
                        strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
-                       && !preg_match( Title::getTitleInvalidRegex(), $code );
+                       && !preg_match( MediaWikiTitleCodec::getTitleInvalidRegex(), $code );
 
                return $cache[$code];
        }
index 5e594ad..eaf079f 100644 (file)
 
        rSplit = /^(.+?)_*:_*(.*)$/,
 
-       // See Title.php#getTitleInvalidRegex
+       // See MediaWikiTitleCodec.php#getTitleInvalidRegex
        rInvalid = new RegExp(
                '[^' + mw.config.get( 'wgLegalTitleChars' ) + ']' +
                // URL percent encoding sequences interfere with the ability