SemanticMediaWiki /
SemanticBreadcrumbLinks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SBL; |
||
| 4 | |||
| 5 | use SMW\Store; |
||
| 6 | use SMW\ApplicationFactory; |
||
| 7 | use DummyLinker; |
||
| 8 | use Hooks; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @license GNU GPL v2+ |
||
| 12 | * @since 1.0 |
||
| 13 | * |
||
| 14 | * @author mwjames |
||
| 15 | */ |
||
| 16 | class HookRegistry { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | private $handlers = array(); |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @since 1.0 |
||
| 25 | * |
||
| 26 | * @param Store $store |
||
| 27 | * @param Options $options |
||
| 28 | */ |
||
| 29 | 2 | public function __construct( Store $store, Options $options ) { |
|
| 30 | 2 | $this->addCallbackHandlers( $store, $options ); |
|
| 31 | 2 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @since 1.1 |
||
| 35 | * |
||
| 36 | * @param string $name |
||
| 37 | * |
||
| 38 | * @return boolean |
||
| 39 | */ |
||
| 40 | 1 | public function isRegistered( $name ) { |
|
| 41 | 1 | return Hooks::isRegistered( $name ); |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @since 1.1 |
||
| 46 | * |
||
| 47 | * @param string $name |
||
| 48 | * |
||
| 49 | * @return Callable|false |
||
| 50 | */ |
||
| 51 | 1 | public function getHandlerFor( $name ) { |
|
| 52 | 1 | return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false; |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @since 1.0 |
||
| 57 | */ |
||
| 58 | 1 | public function register() { |
|
| 59 | 1 | foreach ( $this->handlers as $name => $callback ) { |
|
| 60 | 1 | Hooks::register( $name, $callback ); |
|
| 61 | 1 | } |
|
| 62 | 1 | } |
|
| 63 | |||
| 64 | 2 | private function addCallbackHandlers( $store, $options ) { |
|
| 65 | |||
| 66 | 2 | $propertyRegistry = new PropertyRegistry(); |
|
| 67 | |||
| 68 | /** |
||
| 69 | * @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks.md |
||
| 70 | */ |
||
| 71 | $this->handlers['SMW::Property::initProperties'] = function () use ( $propertyRegistry ) { |
||
| 72 | 1 | return $propertyRegistry->register(); |
|
| 73 | }; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateOutputPageBeforeExec |
||
| 77 | */ |
||
| 78 | $this->handlers['SkinTemplateOutputPageBeforeExec'] = function ( &$skin, &$template ) use( $store, $options ) { |
||
| 79 | |||
| 80 | 1 | $bySubpageLinksFinder = new BySubpageLinksFinder(); |
|
| 81 | 1 | $bySubpageLinksFinder->setSubpageDiscoverySupportState( |
|
| 82 | 1 | $options->get( 'useSubpageFinderFallback' ) |
|
| 83 | 1 | ); |
|
| 84 | |||
| 85 | 1 | $byPropertyHierarchicalLinksFinder = new ByPropertyHierarchicalLinksFinder( $store ); |
|
| 86 | 1 | $byPropertyHierarchicalLinksFinder->setFindClosestDescendantState( |
|
| 87 | 1 | $options->get( 'tryToFindClosestDescendant' ) |
|
| 88 | 1 | ); |
|
| 89 | |||
| 90 | 1 | $byPropertyHierarchicalLinksFinder->setPropertySearchPatternByNamespace( |
|
| 91 | 1 | $options->get( 'propertySearchPatternByNamespace' ) |
|
| 92 | 1 | ); |
|
| 93 | |||
| 94 | 1 | $htmlBreadcrumbLinksBuilder = new HtmlBreadcrumbLinksBuilder( |
|
| 95 | 1 | $byPropertyHierarchicalLinksFinder, |
|
| 96 | $bySubpageLinksFinder |
||
| 97 | 1 | ); |
|
| 98 | |||
| 99 | 1 | $htmlBreadcrumbLinksBuilder->setLinker( new DummyLinker() ); |
|
| 100 | 1 | $htmlBreadcrumbLinksBuilder->setBreadcrumbTrailStyleClass( |
|
| 101 | 1 | $options->get( 'breadcrumbTrailStyleClass' ) |
|
| 102 | 1 | ); |
|
| 103 | |||
| 104 | 1 | $htmlBreadcrumbLinksBuilder->setBreadcrumbDividerStyleClass( |
|
| 105 | 1 | $options->get( 'breadcrumbDividerStyleClass' ) |
|
| 106 | 1 | ); |
|
| 107 | |||
| 108 | 1 | $htmlBreadcrumbLinksBuilder->setHideSubpageParentState( |
|
| 109 | 1 | $options->get( 'hideSubpageParent' ) |
|
| 110 | 1 | ); |
|
| 111 | |||
| 112 | 1 | $skinTemplateOutputModifier = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder ); |
|
| 113 | 1 | $skinTemplateOutputModifier->modifyTemplate( $template ); |
|
| 114 | 1 | $skinTemplateOutputModifier->modifyOutput( $skin->getOutput() ); |
|
| 115 | |||
| 116 | 1 | return true; |
|
| 117 | }; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay |
||
| 121 | */ |
||
| 122 | $this->handlers['BeforePageDisplay'] = function ( &$output, &$skin ) use ( $options ) { |
||
| 123 | |||
| 124 | 1 | $pageDisplayOutputModifier = new PageDisplayOutputModifier(); |
|
| 125 | |||
| 126 | 1 | $pageDisplayOutputModifier->setHideSubpageParentState( |
|
| 127 | 1 | $options->get( 'hideSubpageParent' ) |
|
| 128 | 1 | ); |
|
| 129 | |||
| 130 | 1 | $pageDisplayOutputModifier->setSubpageByNamespace( |
|
| 131 | 1 | $options->get( 'wgNamespacesWithSubpages' ) |
|
| 132 | 1 | ); |
|
| 133 | |||
| 134 | 1 | $pageDisplayOutputModifier->modifyOutput( $output ); |
|
| 135 | |||
| 136 | 1 | return true; |
|
| 137 | }; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy |
||
| 141 | */ |
||
| 142 | $this->handlers['ParserAfterTidy'] = function ( &$parser, &$text ) use ( $options ) { |
||
|
0 ignored issues
–
show
|
|||
| 143 | |||
| 144 | // ParserOptions::getInterfaceMessage is being used to identify whether a |
||
| 145 | // parse was initiated by `Message::parse` |
||
| 146 | 1 | if ( $parser->getTitle()->isSpecialPage() || $parser->getOptions()->getInterfaceMessage() ) { |
|
| 147 | 1 | return true; |
|
| 148 | } |
||
| 149 | |||
| 150 | 1 | $parserData = ApplicationFactory::getInstance()->newParserData( |
|
| 151 | 1 | $parser->getTitle(), |
|
| 152 | 1 | $parser->getOutput() |
|
| 153 | 1 | ); |
|
| 154 | |||
| 155 | 1 | $subpageParentAnnotator = new SubpageParentAnnotator( |
|
| 156 | $parserData |
||
| 157 | 1 | ); |
|
| 158 | |||
| 159 | 1 | $subpageParentAnnotator->setSubpageParentAnnotationState( |
|
| 160 | 1 | $options->get( 'enabledSubpageParentAnnotation' ) |
|
| 161 | 1 | ); |
|
| 162 | |||
| 163 | 1 | $subpageParentAnnotator->addAnnotation(); |
|
| 164 | |||
| 165 | 1 | return true; |
|
| 166 | }; |
||
| 167 | 2 | } |
|
| 168 | |||
| 169 | } |
||
| 170 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.