1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Hooks; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
use SMW\Factbox\FactboxCache; |
7
|
|
|
use SMW\EventHandler; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* TitleMoveComplete occurs whenever a request to move an article |
11
|
|
|
* is completed |
12
|
|
|
* |
13
|
|
|
* This method will be called whenever an article is moved so that |
14
|
|
|
* semantic properties are moved accordingly. |
15
|
|
|
* |
16
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete |
17
|
|
|
* |
18
|
|
|
* @license GNU GPL v2+ |
19
|
|
|
* @since 1.9 |
20
|
|
|
* |
21
|
|
|
* @author mwjames |
22
|
|
|
*/ |
23
|
|
|
class TitleMoveComplete { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Title |
27
|
|
|
*/ |
28
|
|
|
protected $oldTitle = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Title |
32
|
|
|
*/ |
33
|
|
|
protected $newTitle = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var User |
37
|
|
|
*/ |
38
|
|
|
protected $user = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var integer |
42
|
|
|
*/ |
43
|
|
|
protected $oldId; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var integer |
47
|
|
|
*/ |
48
|
|
|
protected $newId; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @since 1.9 |
52
|
|
|
* |
53
|
|
|
* @param Title $oldTitle old title |
54
|
|
|
* @param Title $newTitle: new title |
|
|
|
|
55
|
|
|
* @param Use $user user who did the move |
56
|
|
|
* @param $oldId database ID of the page that's been moved |
57
|
|
|
* @param $newId database ID of the created redirect |
58
|
|
|
*/ |
59
|
10 |
|
public function __construct( &$oldTitle, &$newTitle, &$user, $oldId, $newId ) { |
60
|
10 |
|
$this->oldTitle = $oldTitle; |
61
|
10 |
|
$this->newTitle = $newTitle; |
62
|
10 |
|
$this->user = $user; |
|
|
|
|
63
|
10 |
|
$this->oldId = $oldId; |
64
|
10 |
|
$this->newId = $newId; |
65
|
10 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @since 1.9 |
69
|
|
|
* |
70
|
|
|
* @return true |
71
|
|
|
*/ |
72
|
9 |
|
public function process() { |
73
|
|
|
|
74
|
9 |
|
$applicationFactory = ApplicationFactory::getInstance(); |
75
|
|
|
|
76
|
|
|
// Delete all data for a non-enabled target NS |
77
|
9 |
|
if ( !$applicationFactory->getNamespaceExaminer()->isSemanticEnabled( $this->newTitle->getNamespace() ) || $this->newId == 0 ) { |
78
|
|
|
|
79
|
4 |
|
$applicationFactory->getStore()->deleteSubject( |
80
|
4 |
|
$this->oldTitle |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
} else { |
|
|
|
|
84
|
|
|
|
85
|
|
|
// Using a different approach since the hook is not triggered |
86
|
|
|
// by #REDIRECT which can cause inconsistencies |
87
|
|
|
// @see 2.3 / StoreUpdater |
88
|
|
|
|
89
|
|
|
// $applicationFactory->getStore()->changeTitle( |
|
|
|
|
90
|
|
|
// $this->oldTitle, |
91
|
|
|
// $this->newTitle, |
92
|
|
|
// $this->oldId, |
93
|
|
|
// $this->newId |
94
|
|
|
// ); |
95
|
|
|
} |
96
|
|
|
|
97
|
9 |
|
$eventHandler = EventHandler::getInstance(); |
98
|
|
|
|
99
|
9 |
|
$dispatchContext = $eventHandler->newDispatchContext(); |
100
|
9 |
|
$dispatchContext->set( 'title', $this->oldTitle ); |
101
|
|
|
$dispatchContext->set( 'context', 'ArticleMove' ); |
102
|
9 |
|
|
103
|
9 |
|
$eventHandler->getEventDispatcher()->dispatch( |
104
|
|
|
'cached.prefetcher.reset', |
105
|
|
|
$dispatchContext |
106
|
|
|
); |
107
|
9 |
|
|
108
|
9 |
|
$dispatchContext = $eventHandler->newDispatchContext(); |
109
|
9 |
|
$dispatchContext->set( 'title', $this->newTitle ); |
110
|
|
|
$dispatchContext->set( 'context', 'ArticleMove' ); |
111
|
9 |
|
|
112
|
9 |
|
$eventHandler->getEventDispatcher()->dispatch( |
113
|
|
|
'cached.prefetcher.reset', |
114
|
|
|
$dispatchContext |
115
|
|
|
); |
116
|
9 |
|
|
117
|
|
|
return true; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.