* Use standard method to check user permissions
[lhc/web/wiklou.git] / includes / specials / SpecialUnlockdb.php
1 <?php
2 /**
3 * Implements Special:Unlockdb
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * Implements Special:Unlockdb
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialUnlockdb extends SpecialPage {
30
31 public function __construct() {
32 parent::__construct( 'Unlockdb', 'siteadmin' );
33 }
34
35 public function execute( $par ) {
36 global $wgUser, $wgRequest;
37
38 $this->setHeaders();
39
40 # Permission check
41 if( !$this->userCanExecute( $wgUser ) ) {
42 $this->displayRestrictionError();
43 return;
44 }
45
46 $this->outputHeader();
47
48 $action = $wgRequest->getVal( 'action' );
49
50 if ( $action == 'success' ) {
51 $this->showSuccess();
52 } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
53 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
54 $this->doSubmit();
55 } else {
56 $this->showForm();
57 }
58 }
59
60 private function showForm( $err = '' ) {
61 global $wgOut, $wgUser;
62
63 global $wgReadOnlyFile;
64 if( !file_exists( $wgReadOnlyFile ) ) {
65 $wgOut->addWikiMsg( 'databasenotlocked' );
66 return;
67 }
68
69 $wgOut->addWikiMsg( 'unlockdbtext' );
70
71 if ( $err != '' ) {
72 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
73 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
74 }
75
76 $wgOut->addHTML(
77 Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
78 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
79 <table>
80 <tr>
81 " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
82 " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
83 </td>
84 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
85 wfMsgHtml( 'unlockconfirm' ) . "</td>
86 </tr>
87 <tr>
88 <td>&#160;</td>
89 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
90 " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
91 </td>
92 </tr>
93 </table>\n" .
94 Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
95 Html::closeElement( 'form' )
96 );
97
98 }
99
100 private function doSubmit() {
101 global $wgOut, $wgRequest, $wgReadOnlyFile;
102
103 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
104 if ( !$wpLockConfirm ) {
105 $this->showForm( wfMsg( 'locknoconfirm' ) );
106 return;
107 }
108
109 wfSuppressWarnings();
110 $res = unlink( $wgReadOnlyFile );
111 wfRestoreWarnings();
112
113 if ( !$res ) {
114 $wgOut->showFileDeleteError( $wgReadOnlyFile );
115 return;
116 }
117
118 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
119 }
120
121 private function showSuccess() {
122 global $wgOut;
123
124 $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
125 $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
126 }
127 }