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 SMWDINumber as DINumber; |
||
| 9 | use SESP\PropertyAnnotator; |
||
| 10 | use SESP\AppFactory; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @private |
||
| 14 | * @ingroup SESP |
||
| 15 | * |
||
| 16 | * @license GNU GPL v2+ |
||
| 17 | * @since 2.0 |
||
| 18 | * |
||
| 19 | * @author mwjames |
||
| 20 | */ |
||
| 21 | class TalkPageNumRevisionPropertyAnnotator implements PropertyAnnotator { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var AppFactory |
||
| 25 | */ |
||
| 26 | private $appFactory; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @since 2.0 |
||
| 30 | * |
||
| 31 | * @param AppFactory $appFactory |
||
| 32 | */ |
||
| 33 | public function __construct( AppFactory $appFactory ) { |
||
| 34 | $this->appFactory = $appFactory; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @since 2.0 |
||
| 39 | * |
||
| 40 | * {@inheritDoc} |
||
| 41 | */ |
||
| 42 | public function isAnnotatorFor( DIProperty $property ) { |
||
| 43 | return $property->getKey() === '___NTREV' ; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @since 2.0 |
||
| 48 | * |
||
| 49 | * {@inheritDoc} |
||
| 50 | */ |
||
| 51 | public function addAnnotation( DIProperty $property, SemanticData $semanticData ) { |
||
| 52 | |||
| 53 | $title = $semanticData->getSubject()->getTitle()->getTalkPage(); |
||
| 54 | |||
| 55 | $numRevisions = $this->getPageRevisions( |
||
| 56 | $title->getArticleID() |
||
| 57 | ); |
||
| 58 | |||
| 59 | $dataItem = null; |
||
| 60 | |||
| 61 | if ( $title->exists() && $numRevisions > 0 ) { |
||
| 62 | $dataItem = new DINumber( $numRevisions ); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ( $dataItem instanceof DataItem ) { |
||
| 66 | $semanticData->addPropertyObjectValue( $property, $dataItem ); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | private function getPageRevisions( $pageId ) { |
||
| 71 | return $this->appFactory->getConnection()->estimateRowCount( |
||
|
0 ignored issues
–
show
|
|||
| 72 | "revision", |
||
| 73 | "*", |
||
| 74 | array( "rev_page" => $pageId ) |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | } |
||
| 79 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.