X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecialpage%2FSpecialPageFactory.php;h=2737e356a0d32222dfec58572e41e3ec84516cdf;hb=5a451fd01be397db3209c1881a335423706da5c2;hp=f2c964476c2ef452c947ef6e77699d74e84fec3a;hpb=8d99548cb60347537bbad7f3d5109990c2a5dde9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index f2c964476c..2737e356a0 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -34,6 +34,7 @@ use RequestContext; use SpecialPage; use Title; use User; +use Wikimedia\ObjectFactory; /** * Factory for handling the special page list and generating SpecialPage objects. @@ -221,6 +222,9 @@ class SpecialPageFactory { /** @var Language */ private $contLang; + /** @var ObjectFactory */ + private $objectFactory; + /** * TODO Make this a const when HHVM support is dropped (T192166) * @@ -241,11 +245,17 @@ class SpecialPageFactory { /** * @param ServiceOptions $options * @param Language $contLang + * @param ObjectFactory $objectFactory */ - public function __construct( ServiceOptions $options, Language $contLang ) { + public function __construct( + ServiceOptions $options, + Language $contLang, + ObjectFactory $objectFactory + ) { $options->assertRequiredOptions( self::$constructorOptions ); $this->options = $options; $this->contLang = $contLang; + $this->objectFactory = $objectFactory; } /** @@ -412,14 +422,22 @@ class SpecialPageFactory { if ( isset( $specialPageList[$realName] ) ) { $rec = $specialPageList[$realName]; - if ( is_callable( $rec ) ) { - // Use callback to instantiate the special page - $page = $rec(); - } elseif ( is_string( $rec ) ) { - $className = $rec; - $page = new $className; - } elseif ( $rec instanceof SpecialPage ) { + if ( $rec instanceof SpecialPage ) { + wfDeprecated( + "a SpecialPage instance (for $realName) in " . + '$wgSpecialPages or from the SpecialPage_initList hook', + '1.34' + ); + $page = $rec; // XXX: we should deep clone here + } elseif ( is_array( $rec ) || is_string( $rec ) || is_callable( $rec ) ) { + $page = $this->objectFactory->createObject( + $rec, + [ + 'allowClassName' => true, + 'allowCallable' => true + ] + ); } else { $page = null; } @@ -568,6 +586,7 @@ class SpecialPageFactory { return $title; } + // @phan-suppress-next-line PhanUndeclaredMethod $context->setTitle( $page->getPageTitle( $par ) ); } elseif ( !$page->isIncludable() ) { return false;