1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Hooks; |
4
|
|
|
|
5
|
|
|
use ParserOutput; |
6
|
|
|
use SMW\ApplicationFactory; |
7
|
|
|
use SMW\EventHandler; |
8
|
|
|
use SMW\MediaWiki\EditInfoProvider; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Hook: NewRevisionFromEditComplete called when a revision was inserted |
12
|
|
|
* due to an edit |
13
|
|
|
* |
14
|
|
|
* Fetch additional information that is related to the saving that has just happened, |
15
|
|
|
* e.g. regarding the last edit date. In runs where this hook is not triggered, the |
16
|
|
|
* last DB entry (of MW) will be used to fill such properties. |
17
|
|
|
* |
18
|
|
|
* Called from LocalFile.php, SpecialImport.php, Article.php, Title.php |
19
|
|
|
* |
20
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/NewRevisionFromEditComplete |
21
|
|
|
* |
22
|
|
|
* @license GNU GPL v2+ |
23
|
|
|
* @since 1.9 |
24
|
|
|
* |
25
|
|
|
* @author mwjames |
26
|
|
|
*/ |
27
|
|
|
class NewRevisionFromEditComplete { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var WikiPage |
31
|
|
|
*/ |
32
|
|
|
private $wikiPage = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Revision |
36
|
|
|
*/ |
37
|
|
|
private $revision = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var integer |
41
|
|
|
*/ |
42
|
|
|
private $baseId = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var User|null |
46
|
|
|
*/ |
47
|
|
|
private $user = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var ParserOutput|null |
51
|
|
|
*/ |
52
|
|
|
private $parserOutput = null; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @since 1.9 |
56
|
|
|
* |
57
|
|
|
* @param WikiPage $article the article edited |
|
|
|
|
58
|
|
|
* @param Revision $rev the new revision. Revision object |
|
|
|
|
59
|
|
|
* @param $baseId the revision ID this was based off, if any |
60
|
|
|
* @param User $user the revision author. User object |
61
|
|
|
*/ |
62
|
152 |
|
public function __construct( $wikiPage, $revision, $baseId, $user = null ) { |
63
|
152 |
|
$this->wikiPage = $wikiPage; |
64
|
152 |
|
$this->revision = $revision; |
65
|
152 |
|
$this->baseId = $baseId; |
66
|
152 |
|
$this->user = $user; |
67
|
152 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @since 1.9 |
71
|
|
|
* |
72
|
|
|
* @return boolean |
73
|
|
|
*/ |
74
|
151 |
|
public function process() { |
75
|
151 |
|
return $this->canUseParserOutputFromEditInfo() ? $this->doProcess() : true; |
76
|
|
|
} |
77
|
|
|
|
78
|
151 |
|
private function canUseParserOutputFromEditInfo() { |
79
|
|
|
|
80
|
151 |
|
$editInfoProvider = new EditInfoProvider( |
81
|
151 |
|
$this->wikiPage, |
82
|
151 |
|
$this->revision, |
83
|
151 |
|
$this->user |
84
|
|
|
); |
85
|
|
|
|
86
|
151 |
|
$this->parserOutput = $editInfoProvider->fetchEditInfo()->getOutput(); |
|
|
|
|
87
|
|
|
|
88
|
151 |
|
return $this->parserOutput instanceof ParserOutput; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
150 |
|
private function doProcess() { |
92
|
|
|
|
93
|
150 |
|
$applicationFactory = ApplicationFactory::getInstance(); |
94
|
150 |
|
$title = $this->wikiPage->getTitle(); |
95
|
|
|
|
96
|
150 |
|
$parserData = $applicationFactory->newParserData( |
97
|
|
|
$title, |
98
|
150 |
|
$this->parserOutput |
|
|
|
|
99
|
|
|
); |
100
|
|
|
|
101
|
150 |
|
$pageInfoProvider = $applicationFactory->newMwCollaboratorFactory()->newPageInfoProvider( |
102
|
150 |
|
$this->wikiPage, |
103
|
150 |
|
$this->revision, |
104
|
150 |
|
$this->user |
105
|
|
|
); |
106
|
|
|
|
107
|
150 |
|
$propertyAnnotatorFactory = $applicationFactory->newPropertyAnnotatorFactory(); |
108
|
|
|
|
109
|
150 |
|
$propertyAnnotator = $propertyAnnotatorFactory->newPredefinedPropertyAnnotator( |
110
|
150 |
|
$parserData->getSemanticData(), |
111
|
|
|
$pageInfoProvider |
112
|
|
|
); |
113
|
|
|
|
114
|
150 |
|
$propertyAnnotator->addAnnotation(); |
115
|
|
|
|
116
|
150 |
|
$parserData->pushSemanticDataToParserOutput(); |
117
|
|
|
|
118
|
150 |
|
$dispatchContext = EventHandler::getInstance()->newDispatchContext(); |
119
|
150 |
|
$dispatchContext->set( 'title', $this->wikiPage->getTitle() ); |
120
|
|
|
|
121
|
150 |
|
EventHandler::getInstance()->getEventDispatcher()->dispatch( |
122
|
150 |
|
'cached.propertyvalues.prefetcher.reset', |
123
|
|
|
$dispatchContext |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
// If the concept was altered make sure to delete the cache |
127
|
150 |
|
if ( $title->getNamespace() === SMW_NS_CONCEPT ) { |
128
|
5 |
|
$applicationFactory->getStore()->deleteConceptCache( $title ); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
150 |
|
return true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.