Adding support for domains in SpecialPasswordReset.php.
[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 $this->setHeaders();
37
38 # Permission check
39 if( !$this->userCanExecute( $this->getUser() ) ) {
40 $this->displayRestrictionError();
41 return;
42 }
43
44 $this->outputHeader();
45
46 $request = $this->getRequest();
47 $action = $request->getVal( 'action' );
48
49 if ( $action == 'success' ) {
50 $this->showSuccess();
51 } elseif ( $action == 'submit' && $request->wasPosted() &&
52 $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
53 $this->doSubmit();
54 } else {
55 $this->showForm();
56 }
57 }
58
59 private function showForm( $err = '' ) {
60 global $wgReadOnlyFile;
61
62 $out = $this->getOutput();
63
64 if( !file_exists( $wgReadOnlyFile ) ) {
65 $out->addWikiMsg( 'databasenotlocked' );
66 return;
67 }
68
69 $out->addWikiMsg( 'unlockdbtext' );
70
71 if ( $err != '' ) {
72 $out->setSubtitle( wfMsg( 'formerror' ) );
73 $out->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
74 }
75
76 $out->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', array( 'id' => 'mw-input-wpunlockconfirm' ) ) . "
83 </td>
84 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
85 Html::openElement( 'label', array( 'for' => 'mw-input-wpunlockconfirm' ) ) .
86 wfMsgHtml( 'unlockconfirm' ) . "</label>
87 </td>
88 </tr>
89 <tr>
90 <td>&#160;</td>
91 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
92 " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
93 </td>
94 </tr>
95 </table>\n" .
96 Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" .
97 Html::closeElement( 'form' )
98 );
99
100 }
101
102 private function doSubmit() {
103 global $wgReadOnlyFile;
104
105 if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) {
106 $this->showForm( wfMsg( 'locknoconfirm' ) );
107 return;
108 }
109
110 wfSuppressWarnings();
111 $res = unlink( $wgReadOnlyFile );
112 wfRestoreWarnings();
113
114 if ( $res ) {
115 $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
116 } else {
117 $this->getOutput()->addWikiMsg( 'filedeleteerror', $wgReadOnlyFile );
118 }
119 }
120
121 private function showSuccess() {
122 $out = $this->getOutput();
123 $out->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
124 $out->addWikiMsg( 'unlockdbsuccesstext' );
125 }
126 }