1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Specials\Admin; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
use SMW\MediaWiki\Renderer\HtmlFormRenderer; |
7
|
|
|
use Onoi\MessageReporter\MessageReporterFactory; |
8
|
|
|
use SMW\SQLStore\Installer; |
9
|
|
|
use SMW\Message; |
10
|
|
|
use SMW\Store; |
11
|
|
|
use Html; |
12
|
|
|
use WebRequest; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 2.5 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class TableSchemaUpdaterSection { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Store |
24
|
|
|
*/ |
25
|
|
|
private $store; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var HtmlFormRenderer |
29
|
|
|
*/ |
30
|
|
|
private $htmlFormRenderer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var boolean |
34
|
|
|
*/ |
35
|
|
|
private $enabledSetupStore = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var OutputFormatter |
39
|
|
|
*/ |
40
|
|
|
private $outputFormatter; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @since 2.5 |
44
|
3 |
|
* |
45
|
3 |
|
* @param Store $store |
46
|
3 |
|
* @param HtmlFormRenderer $htmlFormRenderer |
47
|
3 |
|
* @param OutputFormatter $outputFormatter |
48
|
3 |
|
*/ |
49
|
|
|
public function __construct( Store $store, HtmlFormRenderer $htmlFormRenderer, OutputFormatter $outputFormatter ) { |
50
|
|
|
$this->store = $store; |
51
|
|
|
$this->htmlFormRenderer = $htmlFormRenderer; |
52
|
|
|
$this->outputFormatter = $outputFormatter; |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
/** |
56
|
|
|
* @since 2.5 |
57
|
1 |
|
* |
58
|
1 |
|
* @param boolean $enabledSetupStore |
59
|
1 |
|
*/ |
60
|
1 |
|
public function enabledSetupStore( $enabledSetupStore ) { |
61
|
1 |
|
$this->enabledSetupStore = (bool)$enabledSetupStore; |
62
|
1 |
|
} |
63
|
1 |
|
|
64
|
1 |
|
/** |
65
|
1 |
|
* @since 2.5 |
66
|
|
|
* |
67
|
1 |
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getForm() { |
70
|
|
|
|
71
|
|
|
$this->htmlFormRenderer |
72
|
|
|
->setName( 'buildtables' ) |
73
|
|
|
->setMethod( 'get' ) |
74
|
|
|
->addHiddenField( 'action', 'updatetables' ) |
75
|
|
|
->addHeader( 'h2', $this->getMessage( 'smw_smwadmin_db' ) ); |
76
|
|
|
|
77
|
1 |
|
if ( $this->enabledSetupStore ) { |
78
|
|
|
$this->htmlFormRenderer |
79
|
1 |
|
->addParagraph( $this->getMessage( 'smw_smwadmin_dbdocu' ) ) |
80
|
1 |
|
->addHiddenField( 'udsure', 'yes' ) |
81
|
|
|
->addSubmitButton( $this->getMessage( 'smw_smwadmin_dbbutton' ) ); |
82
|
1 |
|
} else { |
83
|
1 |
|
$this->htmlFormRenderer |
84
|
|
|
->addParagraph( $this->getMessage( 'smw-smwadmin-dbsetup-disabled' ) ); |
85
|
1 |
|
} |
86
|
|
|
|
87
|
1 |
|
return $this->htmlFormRenderer->getForm() . Html::element( 'p', array(), '' ); |
88
|
|
|
} |
89
|
1 |
|
|
90
|
|
|
/** |
91
|
|
|
* @since 2.5 |
92
|
1 |
|
* |
93
|
|
|
* @param WebRequest $webRequest |
94
|
1 |
|
* |
95
|
|
|
* @return callable |
96
|
1 |
|
*/ |
97
|
|
|
public function doUpdate( WebRequest $webRequest ) { |
98
|
|
|
|
99
|
1 |
|
if ( !$this->enabledSetupStore ) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$messageReporter = MessageReporterFactory::getInstance()->newObservableMessageReporter(); |
104
|
|
|
$messageReporter->registerReporterCallback( array( $this, 'reportMessage' ) ); |
105
|
|
|
|
106
|
|
|
$this->outputFormatter->setPageTitle( $this->getMessage( 'smw_smwadmin_db' ) ); |
107
|
|
|
$this->outputFormatter->addParentLink(); |
108
|
|
|
|
109
|
|
|
$this->store->getOptions()->set( Installer::OPT_MESSAGEREPORTER, $messageReporter ); |
110
|
|
|
|
111
|
|
|
$this->outputFormatter->addHTML( Html::rawElement( 'p', array(), $this->getMessage( 'smw_smwadmin_permissionswarn' ) ) ); |
112
|
|
|
|
113
|
|
|
$this->outputFormatter->addHTML( '<pre>' ); |
114
|
|
|
|
115
|
|
|
// Output is generated by the injected 'installer.messagereporter' |
116
|
|
|
$result = $this->store->setup(); |
117
|
|
|
|
118
|
|
|
$this->outputFormatter->addHTML( '</pre>' ); |
119
|
|
|
|
120
|
|
|
if ( $result === true && $webRequest->getText( 'udsure' ) == 'yes' ) { |
121
|
|
|
$this->outputFormatter->addWikiText( '<p><b>' . $this->getMessage( 'smw_smwadmin_setupsuccess' ) . "</b></p>" ); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @since 2.5 |
127
|
|
|
* |
128
|
|
|
* @param string $message |
129
|
|
|
*/ |
130
|
|
|
public function reportMessage( $message ) { |
131
|
|
|
$this->outputFormatter->addHTML( $message ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
private function getMessage( $key, $type = Message::TEXT ) { |
135
|
|
|
return Message::get( $key, $type, Message::USER_LANGUAGE ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
|