jenkins-bot has submitted this change and it was merged.
Change subject: Title: Add warning if newFromText is given non-string/non-null
value
......................................................................
Title: Add warning if newFromText is given non-string/non-null value
Specify null as allowed value to make this method more easy to use.
The method is often used like that already and this makes it official.
Previously we were on a months-long trajectory to try and remove all
instances of passing null, but it was a never-ending quest (with new
ones introduced all the time). And in all cases the added handling
in the caller is the same as the handling for when this method
returns null. Requiring the caller to bounce null makes code more
complex, duplicates logic and serves no reason. Let this method be
a non-throwing validation method that returns null if given null.
Bug: T76305
Change-Id: I47517021471ac6fd6daca6deee039c8047224a33
(cherry picked from commit dbd6b4af3f1ffd120918c9bf2096ba6bfd7efc47)
---
M includes/Title.php
1 file changed, 8 insertions(+), 8 deletions(-)
Approvals:
Gilles: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Title.php b/includes/Title.php
index 9ada4f3..82df19f 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -252,7 +252,7 @@
* Create a new Title from text, such as what one would find in a link.
De-
* codes any HTML entities in the text.
*
- * @param string $text The link text; spaces, prefixes, and an
+ * @param string|null $text The link text; spaces, prefixes, and an
* initial ':' indicating the main namespace are accepted.
* @param int $defaultNamespace The namespace to use if none is
specified
* by a prefix. If you want to force a specific namespace even if
@@ -264,13 +264,13 @@
public static function newFromText( $text, $defaultNamespace = NS_MAIN
) {
if ( is_object( $text ) ) {
throw new InvalidArgumentException( '$text must be a
string.' );
- } elseif ( !is_string( $text ) ) {
+ }
+ if ( $text !== null && !is_string( $text ) ) {
wfDebugLog( 'T76305', wfGetAllCallers( 5 ) );
- wfWarn(
- __METHOD__ . ': $text must be a string. ' .
- 'This will throw an
InvalidArgumentException in future.',
- 2
- );
+ return null;
+ }
+ if ( $text === null ) {
+ return null;
}
try {
@@ -296,7 +296,7 @@
*/
public static function newFromTextThrow( $text, $defaultNamespace =
NS_MAIN ) {
if ( is_object( $text ) ) {
- throw new MWException( 'Title::newFromTextThrow given
an object' );
+ throw new MWException( '$text must be a string, given
an object' );
}
$cache = self::getTitleCache();
--
To view, visit https://gerrit.wikimedia.org/r/250883
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I47517021471ac6fd6daca6deee039c8047224a33
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.27.0-wmf.5
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits