From c8b5de87ee62b6e1638b27bc838de08f95301eb3 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Wed, 30 Sep 2009 10:36:22 +0000 Subject: [PATCH] Split out the regex for invalid title characters and sequences so it can be used elsewhere in MediaWiki (will in a moment be used in LiquidThreads). --- includes/Title.php | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index b36f34a841..8d5fa050ca 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2206,21 +2206,11 @@ class Title { } return $p . $name; } - - /** - * Secure and split - main initialisation function for this object - * - * Assumes that mDbkeyform has been set, and is urldecoded - * and uses underscores, but not otherwise munged. This function - * removes illegal characters, splits off the interwiki and - * namespace prefixes, sets the other forms, and canonicalizes - * everything. - * @return \type{\bool} true on success - */ - private function secureAndSplit() { - global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks; - - # Initialisation + + // 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. + static function getTitleInvalidRegex() { static $rxTc = false; if( !$rxTc ) { # Matching titles will be held as illegal. @@ -2236,6 +2226,25 @@ class Title { '|&#x[0-9A-Fa-f]+;' . '/S'; } + + return $rxTc; + } + + /** + * Secure and split - main initialisation function for this object + * + * Assumes that mDbkeyform has been set, and is urldecoded + * and uses underscores, but not otherwise munged. This function + * removes illegal characters, splits off the interwiki and + * namespace prefixes, sets the other forms, and canonicalizes + * everything. + * @return \type{\bool} true on success + */ + private function secureAndSplit() { + global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks; + + # Initialisation + $rxTc = self::getTitleInvalidRegex(); $this->mInterwiki = $this->mFragment = ''; $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN -- 2.20.1