r20426 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20425‎ | r20426 | r20427 >
Date:01:15, 14 March 2007
Author:aaron
Status:old
Tags:
Comment:
*Add $isvalid arg to newFromURL() for proxy pages like User:#4 or y:y:y
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -161,11 +161,12 @@
162162 * Create a new Title from URL-encoded text. Ensures that
163163 * the given title's length does not exceed the maximum.
164164 * @param string $url the title, as might be taken from a URL
 165+ * @param bool $isvalid, allows for multiple colons and characters set as illegal
165166 * @return Title the new object, or NULL on an error
166167 * @static
167168 * @access public
168169 */
169 - public static function newFromURL( $url ) {
 170+ public static function newFromURL( $url, $isvalid=true ) {
170171 global $wgLegalTitleChars;
171172 $t = new Title();
172173
@@ -177,7 +178,7 @@
178179 }
179180
180181 $t->mDbkeyform = str_replace( ' ', '_', $url );
181 - if( $t->secureAndSplit() ) {
 182+ if( $t->secureAndSplit( $isvalid ) ) {
182183 return $t;
183184 } else {
184185 return NULL;
@@ -1692,10 +1693,11 @@
16931694 * removes illegal characters, splits off the interwiki and
16941695 * namespace prefixes, sets the other forms, and canonicalizes
16951696 * everything.
 1697+ * @param bool $isvalid, allows for multiple colons and characters set as illegal
16961698 * @return bool true on success
16971699 * @private
16981700 */
1699 - /* private */ function secureAndSplit() {
 1701+ /* private */ function secureAndSplit( $isvalid=true ) {
17001702 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
17011703
17021704 # Initialisation
@@ -1796,7 +1798,7 @@
17971799 $this->mArticleID = 0;
17981800 }
17991801 $fragment = strstr( $dbkey, '#' );
1800 - if ( false !== $fragment ) {
 1802+ if ( $isvalid && false !== $fragment ) {
18011803 $this->setFragment( $fragment );
18021804 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
18031805 # remove whitespace again: prevents "Foo_bar_#"
@@ -1806,7 +1808,7 @@
18071809
18081810 # Reject illegal characters.
18091811 #
1810 - if( preg_match( $rxTc, $dbkey ) ) {
 1812+ if( $isvalid && preg_match( $rxTc, $dbkey ) ) {
18111813 return false;
18121814 }
18131815

Follow-up revisions

RevisionCommit summaryAuthorDate
r20756Revert r20426 which added an unused $isvalid parameter on Title::newFromURL()...brion21:43, 27 March 2007