示例#1
0
 /**
  * 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.
  *
  * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead
  *
  * @return string Regex string
  */
 static function getTitleInvalidRegex()
 {
     wfDeprecated(__METHOD__, '1.25');
     return MediaWikiTitleCodec::getTitleInvalidRegex();
 }
示例#2
0
 public static function makeTitleValid($text)
 {
     $text = self::stripWikitext($text);
     $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
     static $rxTc;
     if (is_callable('MediaWikiTitleCodec::getTitleInvalidRegex')) {
         $rxTc = MediaWikiTitleCodec::getTitleInvalidRegex();
     } elseif (is_callable(array('Title', 'getTitleInvalidRegex'))) {
         // Pre-1.25 compat
         $rxTc = Title::getTitleInvalidRegex();
     } elseif (!$rxTc) {
         // Back-compat
         $rxTc = '/' . '[^' . Title::legalChars() . ']' . '|%[0-9A-Fa-f]{2}' . '|&[A-Za-z0-9\\x80-\\xff]+;' . '|&#[0-9]+;' . '|&#x[0-9A-Fa-f]+;' . '/S';
     }
     $text = preg_replace($rxTc, '_', $text);
     return $text;
 }
示例#3
0
 /**
  * Returns true if a language code string is of a valid form, whether or
  * not it exists. This includes codes which are used solely for
  * customisation via the MediaWiki namespace.
  *
  * @param string $code
  *
  * @return bool
  */
 public static function isValidCode($code)
 {
     static $cache = array();
     if (isset($cache[$code])) {
         return $cache[$code];
     }
     // People think language codes are html safe, so enforce it.
     // Ideally we should only allow a-zA-Z0-9-
     // but, .+ and other chars are often used for {{int:}} hacks
     // see bugs 37564, 37587, 36938
     $cache[$code] = strcspn($code, ":/\\&<>'\"") === strlen($code) && !preg_match(MediaWikiTitleCodec::getTitleInvalidRegex(), $code);
     return $cache[$code];
 }