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