Index: trunk/phase3/includes/specials/SpecialLockdb.php |
— | — | @@ -26,88 +26,53 @@ |
27 | 27 | * |
28 | 28 | * @ingroup SpecialPage |
29 | 29 | */ |
30 | | -class SpecialLockdb extends SpecialPage { |
| 30 | +class SpecialLockdb extends FormSpecialPage { |
31 | 31 | var $reason = ''; |
32 | 32 | |
33 | 33 | public function __construct() { |
34 | 34 | parent::__construct( 'Lockdb', 'siteadmin' ); |
35 | 35 | } |
36 | 36 | |
37 | | - public function execute( $par ) { |
38 | | - $this->setHeaders(); |
| 37 | + public function requiresWrite() { |
| 38 | + return false; |
| 39 | + } |
39 | 40 | |
40 | | - # Permission check |
41 | | - if( !$this->userCanExecute( $this->getUser() ) ) { |
42 | | - $this->displayRestrictionError(); |
43 | | - return; |
44 | | - } |
| 41 | + public function userCanExecute( User $user ) { |
| 42 | + parent::userCanExecute( $user ); |
45 | 43 | |
46 | | - $this->outputHeader(); |
47 | | - |
48 | 44 | # If the lock file isn't writable, we can do sweet bugger all |
49 | 45 | global $wgReadOnlyFile; |
50 | | - if( !is_writable( dirname( $wgReadOnlyFile ) ) ) { |
51 | | - $this->getOutput()->addWikiMsg( 'lockfilenotwritable' ); |
52 | | - return; |
| 46 | + if ( !is_writable( dirname( $wgReadOnlyFile ) ) ) { |
| 47 | + throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' ); |
53 | 48 | } |
54 | | - |
55 | | - $request = $this->getRequest(); |
56 | | - $action = $request->getVal( 'action' ); |
57 | | - $this->reason = $request->getVal( 'wpLockReason', '' ); |
58 | | - |
59 | | - if ( $action == 'success' ) { |
60 | | - $this->showSuccess(); |
61 | | - } elseif ( $action == 'submit' && $request->wasPosted() && |
62 | | - $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) { |
63 | | - $this->doSubmit(); |
64 | | - } else { |
65 | | - $this->showForm(); |
66 | | - } |
67 | 49 | } |
68 | 50 | |
69 | | - private function showForm( $err = '' ) { |
70 | | - $out = $this->getOutput(); |
71 | | - $out->addWikiMsg( 'lockdbtext' ); |
72 | | - |
73 | | - if ( $err != '' ) { |
74 | | - $out->setSubtitle( wfMsg( 'formerror' ) ); |
75 | | - $out->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" ); |
76 | | - } |
77 | | - |
78 | | - $out->addHTML( |
79 | | - Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST', |
80 | | - 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" . |
81 | | - wfMsgHtml( 'enterlockreason' ) . ":\n" . |
82 | | - Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). " |
83 | | -<table> |
84 | | - <tr> |
85 | | - " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . " |
86 | | - " . Html::input( 'wpLockConfirm', null, 'checkbox', array( 'id' => 'mw-input-wplockconfirm' ) ) . " |
87 | | - </td> |
88 | | - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . |
89 | | - Html::openElement( 'label', array( 'for' => 'mw-input-wplockconfirm' ) ) . |
90 | | - wfMsgHtml( 'lockconfirm' ) . "</label> |
91 | | - </td> |
92 | | - </tr> |
93 | | - <tr> |
94 | | - <td> </td> |
95 | | - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . " |
96 | | - " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . " |
97 | | - </td> |
98 | | - </tr> |
99 | | -</table>\n" . |
100 | | - Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" . |
101 | | - Html::closeElement( 'form' ) |
| 51 | + protected function getFormFields() { |
| 52 | + return array( |
| 53 | + 'Reason' => array( |
| 54 | + 'type' => 'textarea', |
| 55 | + 'rows' => 4, |
| 56 | + 'vertical-label' => true, |
| 57 | + 'label-message' => 'enterlockreason', |
| 58 | + ), |
| 59 | + 'Confirm' => array( |
| 60 | + 'type' => 'toggle', |
| 61 | + 'label-message' => 'lockconfirm', |
| 62 | + ), |
102 | 63 | ); |
| 64 | + } |
103 | 65 | |
| 66 | + protected function alterForm( HTMLForm $form ) { |
| 67 | + $form->setWrapperLegend( false ); |
| 68 | + $form->setHeaderText( $this->msg( 'lockdbtext' )->parseAsBlock() ); |
| 69 | + $form->setSubmitTextMsg( 'lockbtn' ); |
104 | 70 | } |
105 | 71 | |
106 | | - private function doSubmit() { |
| 72 | + public function onSubmit( array $data ) { |
107 | 73 | global $wgContLang, $wgReadOnlyFile; |
108 | 74 | |
109 | | - if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) { |
110 | | - $this->showForm( wfMsg( 'locknoconfirm' ) ); |
111 | | - return; |
| 75 | + if ( !$data['Confirm'] ) { |
| 76 | + return Status::newFatal( 'locknoconfirm' ); |
112 | 77 | } |
113 | 78 | |
114 | 79 | wfSuppressWarnings(); |
— | — | @@ -118,10 +83,9 @@ |
119 | 84 | # This used to show a file not found error, but the likeliest reason for fopen() |
120 | 85 | # to fail at this point is insufficient permission to write to the file...good old |
121 | 86 | # is_writable() is plain wrong in some cases, it seems... |
122 | | - $this->getOutput()->addWikiMsg( 'lockfilenotwritable' ); |
123 | | - return; |
| 87 | + return Status::newFatal( 'lockfilenotwritable' ); |
124 | 88 | } |
125 | | - fwrite( $fp, $this->reason ); |
| 89 | + fwrite( $fp, $data['Reason'] ); |
126 | 90 | $timestamp = wfTimestampNow(); |
127 | 91 | fwrite( $fp, "\n<p>" . wfMsgExt( |
128 | 92 | 'lockedbyandtime', |
— | — | @@ -132,12 +96,11 @@ |
133 | 97 | ) . "</p>\n" ); |
134 | 98 | fclose( $fp ); |
135 | 99 | |
136 | | - $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) ); |
| 100 | + return Status::newGood(); |
137 | 101 | } |
138 | 102 | |
139 | | - private function showSuccess() { |
| 103 | + public function onSuccess() { |
140 | 104 | $out = $this->getOutput(); |
141 | | - $out->setPagetitle( wfMsg( 'lockdb' ) ); |
142 | 105 | $out->setSubtitle( wfMsg( 'lockdbsuccesssub' ) ); |
143 | 106 | $out->addWikiMsg( 'lockdbsuccesstext' ); |
144 | 107 | } |
Index: trunk/phase3/includes/specials/SpecialUnlockdb.php |
— | — | @@ -26,85 +26,46 @@ |
27 | 27 | * |
28 | 28 | * @ingroup SpecialPage |
29 | 29 | */ |
30 | | -class SpecialUnlockdb extends SpecialPage { |
| 30 | +class SpecialUnlockdb extends FormSpecialPage { |
31 | 31 | |
32 | 32 | public function __construct() { |
33 | 33 | parent::__construct( 'Unlockdb', 'siteadmin' ); |
34 | 34 | } |
35 | 35 | |
36 | | - public function execute( $par ) { |
37 | | - $this->setHeaders(); |
| 36 | + public function requiresWrite() { |
| 37 | + return false; |
| 38 | + } |
38 | 39 | |
39 | | - # Permission check |
40 | | - if( !$this->userCanExecute( $this->getUser() ) ) { |
41 | | - $this->displayRestrictionError(); |
42 | | - return; |
43 | | - } |
| 40 | + public function userCanExecute( User $user ) { |
| 41 | + parent::userCanExecute( $user ); |
44 | 42 | |
45 | | - $this->outputHeader(); |
46 | | - |
47 | | - $request = $this->getRequest(); |
48 | | - $action = $request->getVal( 'action' ); |
49 | | - |
50 | | - if ( $action == 'success' ) { |
51 | | - $this->showSuccess(); |
52 | | - } elseif ( $action == 'submit' && $request->wasPosted() && |
53 | | - $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) { |
54 | | - $this->doSubmit(); |
55 | | - } else { |
56 | | - $this->showForm(); |
| 43 | + # If the lock file isn't writable, we can do sweet bugger all |
| 44 | + global $wgReadOnlyFile; |
| 45 | + if ( !file_exists( $wgReadOnlyFile ) ) { |
| 46 | + throw new ErrorPageError( 'lockdb', 'databasenotlocked' ); |
57 | 47 | } |
58 | 48 | } |
59 | 49 | |
60 | | - private function showForm( $err = '' ) { |
61 | | - global $wgReadOnlyFile; |
62 | | - |
63 | | - $out = $this->getOutput(); |
64 | | - |
65 | | - if( !file_exists( $wgReadOnlyFile ) ) { |
66 | | - $out->addWikiMsg( 'databasenotlocked' ); |
67 | | - return; |
68 | | - } |
69 | | - |
70 | | - $out->addWikiMsg( 'unlockdbtext' ); |
71 | | - |
72 | | - if ( $err != '' ) { |
73 | | - $out->setSubtitle( wfMsg( 'formerror' ) ); |
74 | | - $out->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" ); |
75 | | - } |
76 | | - |
77 | | - $out->addHTML( |
78 | | - Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST', |
79 | | - 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . " |
80 | | -<table> |
81 | | - <tr> |
82 | | - " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . " |
83 | | - " . Html::input( 'wpLockConfirm', null, 'checkbox', array( 'id' => 'mw-input-wpunlockconfirm' ) ) . " |
84 | | - </td> |
85 | | - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . |
86 | | - Html::openElement( 'label', array( 'for' => 'mw-input-wpunlockconfirm' ) ) . |
87 | | - wfMsgHtml( 'unlockconfirm' ) . "</label> |
88 | | - </td> |
89 | | - </tr> |
90 | | - <tr> |
91 | | - <td> </td> |
92 | | - " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . " |
93 | | - " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . " |
94 | | - </td> |
95 | | - </tr> |
96 | | -</table>\n" . |
97 | | - Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" . |
98 | | - Html::closeElement( 'form' ) |
| 50 | + protected function getFormFields() { |
| 51 | + return array( |
| 52 | + 'Confirm' => array( |
| 53 | + 'type' => 'toggle', |
| 54 | + 'label-message' => 'unlockconfirm', |
| 55 | + ), |
99 | 56 | ); |
| 57 | + } |
100 | 58 | |
| 59 | + protected function alterForm( HTMLForm $form ) { |
| 60 | + $form->setWrapperLegend( false ); |
| 61 | + $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() ); |
| 62 | + $form->setSubmitTextMsg( 'unlockbtn' ); |
101 | 63 | } |
102 | 64 | |
103 | | - private function doSubmit() { |
| 65 | + public function onSubmit( array $data ) { |
104 | 66 | global $wgReadOnlyFile; |
105 | 67 | |
106 | | - if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) { |
107 | | - $this->showForm( wfMsg( 'locknoconfirm' ) ); |
108 | | - return; |
| 68 | + if ( !$data['Confirm'] ) { |
| 69 | + return Status::newFatal( 'locknoconfirm' ); |
109 | 70 | } |
110 | 71 | |
111 | 72 | wfSuppressWarnings(); |
— | — | @@ -112,13 +73,13 @@ |
113 | 74 | wfRestoreWarnings(); |
114 | 75 | |
115 | 76 | if ( $res ) { |
116 | | - $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) ); |
| 77 | + return Status::newGood(); |
117 | 78 | } else { |
118 | | - $this->getOutput()->addWikiMsg( 'filedeleteerror', $wgReadOnlyFile ); |
| 79 | + return Status::newFatal( 'filedeleteerror', $wgReadOnlyFile ); |
119 | 80 | } |
120 | 81 | } |
121 | 82 | |
122 | | - private function showSuccess() { |
| 83 | + public function onSuccess() { |
123 | 84 | $out = $this->getOutput(); |
124 | 85 | $out->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) ); |
125 | 86 | $out->addWikiMsg( 'unlockdbsuccesstext' ); |