diff --git a/php/Element.php b/php/Element.php
index <HASH>..<HASH> 100644
--- a/php/Element.php
+++ b/php/Element.php
@@ -247,7 +247,8 @@ class Element extends Tag {
 		};
 		array_walk_recursive( $config, $replaceElements );
 		// Set '_' last to ensure that subclasses can't accidentally step on it.
-		$config['_'] = preg_replace( '/^OOUI\\\\/', '', get_class( $this ) );
+		// Strip all namespaces from the class name
+		$config['_'] = end( explode( '\\', get_class( $this ) ) );
 		return $config;
 	}
 
diff --git a/tests/phpunit/ElementTest.php b/tests/phpunit/ElementTest.php
index <HASH>..<HASH> 100644
--- a/tests/phpunit/ElementTest.php
+++ b/tests/phpunit/ElementTest.php
@@ -14,7 +14,7 @@ class ElementTest extends TestCase {
 			),
 			array(
 				new \FooBarBaz\MockWidget( array( 'infusable' => true ) ),
-				'"_":"FooBarBaz\\\\MockWidget"'
+				'"_":"MockWidget"'
 			),
 		);
 	}
Strip all namespaces from infused PHP widgets

This will allow us to put custom MediaWiki specific widgets in their own
namespace, but still be able to infuse them.

Change-Id: I5d<I>e<I>efc<I>ad<I>c<I>e2b<I>dc