diff --git a/.gitignore b/.gitignore index ff72e2d..e794f92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /composer.lock /vendor +.github/* diff --git a/includes/PortableInfoboxHooks.php b/includes/PortableInfoboxHooks.php index 09a7cf8..9d1e7fd 100644 --- a/includes/PortableInfoboxHooks.php +++ b/includes/PortableInfoboxHooks.php @@ -2,6 +2,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RenderedRevision; +use PortableInfobox\Helpers\PortableInfoboxDataBag; class PortableInfoboxHooks { @@ -14,7 +15,7 @@ class PortableInfoboxHooks { public static function onBeforeParserrenderImageGallery( Parser &$parser, ImageGalleryBase &$gallery ) { - PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery( + PortableInfoboxDataBag::getInstance()->setGallery( // @phan-suppress-next-line PhanDeprecatedProperty Parser::MARKER_PREFIX . '-gallery-' . sprintf( '%08X', $parser->mMarkerIndex - 1 ) . Parser::MARKER_SUFFIX, diff --git a/includes/controllers/ApiPortableInfobox.php b/includes/controllers/ApiPortableInfobox.php index 696eadd..792639a 100644 --- a/includes/controllers/ApiPortableInfobox.php +++ b/includes/controllers/ApiPortableInfobox.php @@ -1,6 +1,9 @@ render( $text, $parser, $frame ); $this->getResult()->addValue( null, $this->getModuleName(), [ 'text' => [ '*' => $output ] ] ); - } catch ( \PortableInfobox\Parser\Nodes\UnimplementedNodeException $e ) { + } catch ( UnimplementedNodeException $e ) { $this->dieWithError( $this->msg( 'portable-infobox-unimplemented-infobox-tag', [ $e->getMessage() ] )->escaped(), 'notimplemented' ); - } catch ( \PortableInfobox\Parser\XmlMarkupParseErrorException $e ) { + } catch ( XmlMarkupParseErrorException $e ) { $this->dieWithError( $this->msg( 'portable-infobox-xml-parse-error' )->text(), 'badxml' ); - } catch ( \PortableInfobox\Helpers\InvalidInfoboxParamsException $e ) { + } catch ( InvalidInfoboxParamsException $e ) { $this->dieWithError( $this->msg( 'portable-infobox-xml-parse-error-infobox-tag-attribute-unsupported', diff --git a/includes/controllers/PortableInfoboxParserTagController.php b/includes/controllers/PortableInfoboxParserTagController.php index 7808a8d..23cd04f 100644 --- a/includes/controllers/PortableInfoboxParserTagController.php +++ b/includes/controllers/PortableInfoboxParserTagController.php @@ -3,7 +3,9 @@ use MediaWiki\MediaWikiServices; use PortableInfobox\Helpers\InfoboxParamsValidator; use PortableInfobox\Helpers\InvalidInfoboxParamsException; -use PortableInfobox\Parser\Nodes; +use PortableInfobox\Parser\MediaWikiParserService; +use PortableInfobox\Parser\Nodes\NodeFactory; +use PortableInfobox\Parser\Nodes\NodeInfobox; use PortableInfobox\Parser\Nodes\UnimplementedNodeException; use PortableInfobox\Parser\XmlMarkupParseErrorException; @@ -89,14 +91,14 @@ class PortableInfoboxParserTagController { */ public function prepareInfobox( $markup, Parser $parser, PPFrame $frame, $params = null ) { $frameArguments = $frame->getArguments(); - $infoboxNode = Nodes\NodeFactory::newFromXML( $markup, $frameArguments ?: [] ); + $infoboxNode = NodeFactory::newFromXML( $markup, $frameArguments ?: [] ); $infoboxNode->setExternalParser( - new PortableInfobox\Parser\MediaWikiParserService( $parser, $frame ) + new MediaWikiParserService( $parser, $frame ) ); // get params if not overridden if ( !isset( $params ) ) { - $params = ( $infoboxNode instanceof Nodes\NodeInfobox ) ? $infoboxNode->getParams() : []; + $params = ( $infoboxNode instanceof NodeInfobox ) ? $infoboxNode->getParams() : []; } $this->getParamsValidator()->validateParams( $params ); @@ -148,7 +150,7 @@ class PortableInfoboxParserTagController { return [ $renderedValue, 'markerType' => 'nowiki' ]; } - protected function saveToParserOutput( \ParserOutput $parserOutput, Nodes\NodeInfobox $raw ) { + protected function saveToParserOutput( ParserOutput $parserOutput, NodeInfobox $raw ) { // parser output stores this in page_props table, // therefore we can reuse the data in data provider service // (see: PortableInfoboxDataService.class.php) diff --git a/includes/services/Helpers/FileNamespaceSanitizeHelper.php b/includes/services/Helpers/FileNamespaceSanitizeHelper.php index ab88066..b9af992 100644 --- a/includes/services/Helpers/FileNamespaceSanitizeHelper.php +++ b/includes/services/Helpers/FileNamespaceSanitizeHelper.php @@ -2,6 +2,7 @@ namespace PortableInfobox\Helpers; +use Language; use MediaWiki\MediaWikiServices; // original class & authors: @@ -25,7 +26,7 @@ class FileNamespaceSanitizeHelper { } /** - * @param \Language $contLang + * @param Language $contLang * Used as local cache for getting string to remove */ private function getFilePrefixRegex( $contLang ) { @@ -65,7 +66,7 @@ class FileNamespaceSanitizeHelper { /** * @param string $filename - * @param \Language $contLang + * @param Language $contLang * * @return mixed */ diff --git a/includes/services/Helpers/InfoboxParamsValidator.php b/includes/services/Helpers/InfoboxParamsValidator.php index 04ce048..d32cee0 100644 --- a/includes/services/Helpers/InfoboxParamsValidator.php +++ b/includes/services/Helpers/InfoboxParamsValidator.php @@ -1,6 +1,9 @@ getRepoGroup(); $file = $repoGroup->findFile( $file ); } - if ( $file instanceof \File && $file->exists() ) { + if ( $file instanceof File && $file->exists() ) { return $file; } diff --git a/includes/services/Helpers/PortableInfoboxParsingHelper.php b/includes/services/Helpers/PortableInfoboxParsingHelper.php index 45adbfc..038093a 100644 --- a/includes/services/Helpers/PortableInfoboxParsingHelper.php +++ b/includes/services/Helpers/PortableInfoboxParsingHelper.php @@ -2,8 +2,14 @@ namespace PortableInfobox\Helpers; +use Exception; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; +use ParserOptions; +use PortableInfoboxDataService; +use PortableInfoboxParserTagController; +use RequestContext; +use Title; class PortableInfoboxParsingHelper { @@ -11,25 +17,25 @@ class PortableInfoboxParsingHelper { protected $logger; public function __construct() { - $this->parserTagController = \PortableInfoboxParserTagController::getInstance(); + $this->parserTagController = PortableInfoboxParserTagController::getInstance(); $this->logger = LoggerFactory::getInstance( 'PortableInfobox' ); } /** * Try to find out if infobox got "hidden" inside includeonly tag. Parse it if that's the case. * - * @param \Title $title + * @param Title $title * * @return mixed false when no infoboxes found, Array with infoboxes on success */ - public function parseIncludeonlyInfoboxes( \Title $title ) { + public function parseIncludeonlyInfoboxes( Title $title ) { // for templates we need to check for include tags $templateText = $this->fetchArticleContent( $title ); if ( $templateText ) { $parser = MediaWikiServices::getInstance()->getParser(); $parser->setPage( $title ); - $parserOptions = \ParserOptions::newFromAnon(); + $parserOptions = ParserOptions::newFromAnon(); $parser->setOptions( $parserOptions ); $frame = $parser->getPreprocessor()->newFrame(); @@ -40,13 +46,13 @@ class PortableInfoboxParsingHelper { foreach ( $infoboxes as $infobox ) { try { $this->parserTagController->prepareInfobox( $infobox, $parser, $frame ); - } catch ( \Exception $e ) { + } catch ( Exception $e ) { $this->logger->info( 'Invalid infobox syntax' ); } } return json_decode( - $parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); } @@ -54,25 +60,25 @@ class PortableInfoboxParsingHelper { return false; } - public function reparseArticle( \Title $title ) { + public function reparseArticle( Title $title ) { $parser = MediaWikiServices::getInstance()->getParser(); - $user = \RequestContext::getMain()->getUser(); + $user = RequestContext::getMain()->getUser(); - $parserOptions = new \ParserOptions( $user ); + $parserOptions = new ParserOptions( $user ); $parser->parse( $this->fetchArticleContent( $title ), $title, $parserOptions ); return json_decode( - $parser->getOutput()->getProperty( \PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); } /** - * @param \Title $title + * @param Title $title * * @return string */ - protected function fetchArticleContent( \Title $title ) { + protected function fetchArticleContent( Title $title ) { if ( $title->exists() ) { // @phan-suppress-next-line PhanDeprecatedFunction $content = MediaWikiServices::getInstance() @@ -86,10 +92,10 @@ class PortableInfoboxParsingHelper { } /** - * @param \Title $title + * @param Title $title * @return string[] array of strings (infobox markups) */ - public function getMarkup( \Title $title ) { + public function getMarkup( Title $title ) { $content = $this->fetchArticleContent( $title ); return $this->getInfoboxes( $content ); } diff --git a/includes/services/Helpers/PortableInfoboxTemplateEngine.php b/includes/services/Helpers/PortableInfoboxTemplateEngine.php index d591784..dda01a6 100644 --- a/includes/services/Helpers/PortableInfoboxTemplateEngine.php +++ b/includes/services/Helpers/PortableInfoboxTemplateEngine.php @@ -2,8 +2,11 @@ namespace PortableInfobox\Helpers; +use Closure; +use LightnCandy\LightnCandy; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; +use PortableInfoboxParserTagController; class PortableInfoboxTemplateEngine { private const CACHE_TTL = 86400; @@ -31,7 +34,7 @@ class PortableInfoboxTemplateEngine { public function __construct() { if ( !isset( self::$lightncandy ) ) { - self::$lightncandy = \LightnCandy\LightnCandy::class; + self::$lightncandy = LightnCandy::class; self::$compileFlags = self::$lightncandy::FLAG_BESTPERFORMANCE | self::$lightncandy::FLAG_PARENT | self::$lightncandy::FLAG_HANDLEBARS; } @@ -60,7 +63,7 @@ class PortableInfoboxTemplateEngine { * Returns a template renderer * * @param string $type Template type - * @return \Closure + * @return Closure */ public function getRenderer( $type ) { global $wgPortableInfoboxCacheRenderers; @@ -70,7 +73,7 @@ class PortableInfoboxTemplateEngine { if ( $wgPortableInfoboxCacheRenderers ) { $cachekey = self::$memcache->makeKey( - __CLASS__, \PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type + __CLASS__, PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type ); $template = self::$memcache->getWithSetCallback( $cachekey, self::CACHE_TTL, static function () use ( $path ) { diff --git a/includes/services/Parser/ExternalParser.php b/includes/services/Parser/ExternalParser.php index abbe5d8..ae25935 100644 --- a/includes/services/Parser/ExternalParser.php +++ b/includes/services/Parser/ExternalParser.php @@ -1,4 +1,5 @@ parser = $parser; $this->frame = $frame; - if ( $wgPortableInfoboxUseTidy && class_exists( '\MediaWiki\Tidy\RemexDriver' ) ) { + if ( $wgPortableInfoboxUseTidy && class_exists( RemexDriver::class ) ) { global $wgTidyConfig; $wgTidyConfig = [ @@ -49,7 +55,7 @@ class MediaWikiParserService implements ExternalParser { } // @phan-suppress-next-line PhanAccessMethodInternal - $output = \BlockLevelPass::doBlockLevels( $parsed, false ); + $output = BlockLevelPass::doBlockLevels( $parsed, false ); $ready = $this->parser->getStripState()->unstripBoth( $output ); // @phan-suppress-next-line PhanDeprecatedFunction @@ -76,7 +82,7 @@ class MediaWikiParserService implements ExternalParser { /** * Add image to parser output for later usage * - * @param \Title $title + * @param Title $title */ public function addImage( $title ) { $repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); @@ -87,11 +93,11 @@ class MediaWikiParserService implements ExternalParser { $this->parser->getOutput()->addImage( $title->getDBkey(), $tmstmp, $sha1 ); // Pass PI images to PageImages extension if available (Popups and og:image) - if ( \method_exists( - '\PageImages\Hooks\ParserFileProcessingHookHandlers', 'onParserMakeImageParams' + if ( method_exists( + ParserFileProcessingHookHandlers::class, 'onParserMakeImageParams' ) ) { $params = []; - \PageImages\Hooks\ParserFileProcessingHookHandlers::onParserMakeImageParams( + ParserFileProcessingHookHandlers::onParserMakeImageParams( $title, $file, $params, $this->parser ); } diff --git a/includes/services/Parser/Nodes/Node.php b/includes/services/Parser/Nodes/Node.php index 66e584f..75f4776 100644 --- a/includes/services/Parser/Nodes/Node.php +++ b/includes/services/Parser/Nodes/Node.php @@ -1,8 +1,11 @@ xmlNode = $xmlNode; $this->infoboxData = $infoboxData; } @@ -43,7 +46,7 @@ class Node { $metadata = []; $sources = $this->getSources(); $sourcesLength = count( $sources ); - $baseLabel = \Sanitizer::stripAllTags( + $baseLabel = Sanitizer::stripAllTags( $this->getInnerValue( $this->xmlNode->{self::LABEL_TAG_NAME} ) ); @@ -196,7 +199,7 @@ class Node { }, $this->getChildNodes() ); } - protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) { + protected function getValueWithDefault( SimpleXMLElement $xmlNode ) { $value = $this->extractDataFromSource( $xmlNode ); $isEmpty = $value === null || $value === ''; if ( $isEmpty && $xmlNode->{self::DEFAULT_TAG_NAME} ) { @@ -209,7 +212,7 @@ class Node { return $value; } - protected function getRawValueWithDefault( \SimpleXMLElement $xmlNode ) { + protected function getRawValueWithDefault( SimpleXMLElement $xmlNode ) { $value = $this->getRawInfoboxData( $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ); if ( !$value && $xmlNode->{self::DEFAULT_TAG_NAME} ) { $value = $this->getExternalParser()->replaceVariables( @@ -220,17 +223,17 @@ class Node { return $value; } - protected function getValueWithData( \SimpleXMLElement $xmlNode ) { + protected function getValueWithData( SimpleXMLElement $xmlNode ) { $value = $this->extractDataFromSource( $xmlNode ); return $value ?: $this->getInnerValue( $xmlNode ); } - protected function getInnerValue( \SimpleXMLElement $xmlNode ) { + protected function getInnerValue( SimpleXMLElement $xmlNode ) { return $this->getExternalParser()->parseRecursive( (string)$xmlNode ); } - protected function getXmlAttribute( \SimpleXMLElement $xmlNode, $attribute ) { + protected function getXmlAttribute( SimpleXMLElement $xmlNode, $attribute ) { return ( isset( $xmlNode[$attribute] ) ) ? (string)$xmlNode[$attribute] : null; } @@ -244,11 +247,11 @@ class Node { } /** - * @param \SimpleXMLElement $xmlNode + * @param SimpleXMLElement $xmlNode * * @return mixed */ - protected function extractDataFromSource( \SimpleXMLElement $xmlNode ) { + protected function extractDataFromSource( SimpleXMLElement $xmlNode ) { $source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); return ( !empty( $source ) || $source == '0' ) ? $this->getInfoboxData( $source ) @@ -256,11 +259,11 @@ class Node { } /** - * @param \SimpleXMLElement $xmlNode + * @param SimpleXMLElement $xmlNode * * @return array */ - protected function extractSourcesFromNode( \SimpleXMLElement $xmlNode ) { + protected function extractSourcesFromNode( SimpleXMLElement $xmlNode ) { $sources = $this->hasPrimarySource( $xmlNode ) ? [ $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ] : []; @@ -274,11 +277,11 @@ class Node { return $sources; } - protected function hasPrimarySource( \SimpleXMLElement $xmlNode ) { + protected function hasPrimarySource( SimpleXMLElement $xmlNode ) { return (bool)$this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); } - protected function matchVariables( \SimpleXMLElement $node, array $source ) { + protected function matchVariables( SimpleXMLElement $node, array $source ) { preg_match_all( self::EXTRACT_SOURCE_REGEX, (string)$node, $sources ); return array_unique( array_merge( $source, $sources[1] ) ); diff --git a/includes/services/Parser/Nodes/NodeAudio.php b/includes/services/Parser/Nodes/NodeAudio.php index 73d7363..0f524f3 100644 --- a/includes/services/Parser/Nodes/NodeAudio.php +++ b/includes/services/Parser/Nodes/NodeAudio.php @@ -1,4 +1,5 @@ getName(); - $className = 'PortableInfobox\\Parser\\Nodes\\' . 'Node' . - mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE ); + $className = Node::class . mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE ); if ( class_exists( $className ) ) { - /* @var $instance \PortableInfobox\Parser\Nodes\Node */ + /* @var $instance Node */ $instance = new $className( $xmlNode, $data ); if ( $instance instanceof Node ) { diff --git a/includes/services/Parser/Nodes/NodeGroup.php b/includes/services/Parser/Nodes/NodeGroup.php index 2582748..f2c1c26 100644 --- a/includes/services/Parser/Nodes/NodeGroup.php +++ b/includes/services/Parser/Nodes/NodeGroup.php @@ -1,4 +1,5 @@ query( '//div[@class=\'tabbertab\']' ); foreach ( $divs as $div ) { if ( preg_match( '# src="(?:[^"]*/)?(?:\d+px-)?([^"]*?)"#', $doc->saveXml( $div ), $out ) ) { @@ -137,14 +143,14 @@ class NodeMedia extends Node { */ private function getImageData( $title, $alt, $caption ) { $helper = $this->getImageHelper(); - $titleObj = $title instanceof \Title ? $title : $this->getImageAsTitleObject( $title ); + $titleObj = $title instanceof Title ? $title : $this->getImageAsTitleObject( $title ); $fileObj = $helper->getFile( $titleObj ); if ( !isset( $fileObj ) || !$this->isTypeAllowed( $fileObj->getMediaType() ) ) { return []; } - if ( $titleObj instanceof \Title ) { + if ( $titleObj instanceof Title ) { $this->getExternalParser()->addImage( $titleObj ); } @@ -164,8 +170,8 @@ class NodeMedia extends Node { if ( $image['isImage'] ) { $image = array_merge( $image, $helper->extendImageData( $fileObj, - \PortableInfoboxRenderService::DEFAULT_DESKTOP_THUMBNAIL_WIDTH, - \PortableInfoboxRenderService::DEFAULT_DESKTOP_INFOBOX_WIDTH + PortableInfoboxRenderService::DEFAULT_DESKTOP_THUMBNAIL_WIDTH, + PortableInfoboxRenderService::DEFAULT_DESKTOP_INFOBOX_WIDTH ) ); } @@ -199,7 +205,7 @@ class NodeMedia extends Node { private function getImageAsTitleObject( $imageName ) { $contLang = MediaWikiServices::getInstance()->getContentLanguage(); - $title = \Title::makeTitleSafe( + $title = Title::makeTitleSafe( NS_FILE, FileNamespaceSanitizeHelper::getInstance()->sanitizeImageFileName( $imageName, $contLang ) ); @@ -216,7 +222,7 @@ class NodeMedia extends Node { /** * Returns image url for given image title - * @param \File|null $file + * @param File|null $file * @return string url or '' if image doesn't exist */ public function resolveImageUrl( $file ) { diff --git a/includes/services/Parser/Nodes/NodeNavigation.php b/includes/services/Parser/Nodes/NodeNavigation.php index e155362..ed0e9c4 100644 --- a/includes/services/Parser/Nodes/NodeNavigation.php +++ b/includes/services/Parser/Nodes/NodeNavigation.php @@ -1,4 +1,5 @@ 'XML_ERR_TAG_NOT_FINISHED' ]; - /* @var $templateEngine PortableInfobox\Helpers\PortableInfoboxTemplateEngine */ + /* @var $templateEngine PortableInfoboxTemplateEngine */ private $templateEngine; public function __construct( $errorList ) { diff --git a/includes/specials/SpecialPortableInfoboxBuilder.php b/includes/specials/SpecialPortableInfoboxBuilder.php index 780d93f..5ec5513 100644 --- a/includes/specials/SpecialPortableInfoboxBuilder.php +++ b/includes/specials/SpecialPortableInfoboxBuilder.php @@ -1,5 +1,7 @@ getConfig()->get( 'NamespaceProtection' )[NS_TEMPLATE][0] ?? ''; @@ -17,7 +19,7 @@ class SpecialPortableInfoboxBuilder extends SpecialPage { $out->addModules( [ 'ext.PortableInfobox.styles', 'ext.PortableInfoboxBuilder' ] ); $out->addHTML( '