SemanticMediaWiki /
SemanticExtraSpecialProperties
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 SESP\PropertyAnnotators; |
||
| 4 | |||
| 5 | use SMW\DIProperty; |
||
| 6 | use SMW\SemanticData; |
||
| 7 | use SMWDataItem as DataItem; |
||
| 8 | use SMWDIUri as DIUri; |
||
| 9 | use SESP\PropertyAnnotator; |
||
| 10 | use SESP\AppFactory; |
||
| 11 | use RuntimeException; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @private |
||
| 15 | * @ingroup SESP |
||
| 16 | * |
||
| 17 | * @license GNU GPL v2+ |
||
| 18 | * @since 2.0 |
||
| 19 | * |
||
| 20 | * @author mwjames |
||
| 21 | * @author rotsee |
||
| 22 | */ |
||
| 23 | class ShortUrlPropertyAnnotator implements PropertyAnnotator { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var AppFactory |
||
| 27 | */ |
||
| 28 | private $appFactory; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @since 2.0 |
||
| 32 | * |
||
| 33 | * @param AppFactory $appFactory |
||
| 34 | */ |
||
| 35 | public function __construct( AppFactory $appFactory ) { |
||
| 36 | $this->appFactory = $appFactory; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @since 2.0 |
||
| 41 | * |
||
| 42 | * {@inheritDoc} |
||
| 43 | */ |
||
| 44 | public function isAnnotatorFor( DIProperty $property ) { |
||
| 45 | return $property->getKey() === '___SHORTURL' ; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @since 2.0 |
||
| 50 | * |
||
| 51 | * {@inheritDoc} |
||
| 52 | */ |
||
| 53 | public function addAnnotation( DIProperty $property, SemanticData $semanticData ) { |
||
| 54 | |||
| 55 | if ( !$this->hasShortUrlUtils() ) { |
||
| 56 | throw new RuntimeException( 'Class ShortUrlUtils is not available' ); |
||
| 57 | } |
||
| 58 | |||
| 59 | $dataItem = null; |
||
| 60 | $title = $semanticData->getSubject()->getTitle(); |
||
| 61 | |||
| 62 | if ( \ShortUrlUtils::needsShortUrl( $title ) ) { |
||
| 63 | $dataItem = new DIUri( 'http', $this->getUrlPrefix() . \ShortUrlUtils::encodeTitle( $title ), '', '' ); |
||
| 64 | } |
||
| 65 | |||
| 66 | if ( $dataItem instanceof DataItem ) { |
||
| 67 | $semanticData->addPropertyObjectValue( $property, $dataItem ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | protected function getUrlPrefix() { |
||
| 72 | |||
| 73 | $shortUrlPrefix = $this->appFactory->getOption( 'wgShortUrlPrefix', '' ); |
||
|
0 ignored issues
–
show
|
|||
| 74 | |||
| 75 | if ( $shortUrlPrefix === '' ) { |
||
| 76 | return SpecialPage::getTitleFor( 'ShortUrl' )->getFullUrl() . '/'; |
||
| 77 | } |
||
| 78 | |||
| 79 | return $shortUrlPrefix; |
||
| 80 | } |
||
| 81 | |||
| 82 | protected function hasShortUrlUtils() { |
||
| 83 | return class_exists( 'ShortUrlUtils' ); |
||
| 84 | } |
||
| 85 | |||
| 86 | } |
||
| 87 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: