Removed usage of error suppression operator in Special:LockDB and Special:UnlockDB
[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, $wgOut, $wgRequest;
37
38 $this->setHeaders();
39
40 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
41 $wgOut->permissionRequired( 'siteadmin' );
42 return;
43 }
44
45 $this->outputHeader();
46
47 $action = $wgRequest->getVal( 'action' );
48
49 if ( $action == 'success' ) {
50 $this->showSuccess();
51 } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
52 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
53 $this->doSubmit();
54 } else {
55 $this->showForm();
56 }
57 }
58
59 private function showForm( $err = '' ) {
60 global $wgOut, $wgUser;
61
62 global $wgReadOnlyFile;
63 if( !file_exists( $wgReadOnlyFile ) ) {
64 $wgOut->addWikiMsg( 'databasenotlocked' );
65 return;
66 }
67
68 $wgOut->addWikiMsg( 'unlockdbtext' );
69
70 if ( $err != '' ) {
71 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
72 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
73 }
74
75 $wgOut->addHTML(
76 Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
77 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
78 <table>
79 <tr>
80 " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
81 " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
82 </td>
83 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
84 wfMsgHtml( 'unlockconfirm' ) . "</td>
85 </tr>
86 <tr>
87 <td>&#160;</td>
88 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
89 " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
90 </td>
91 </tr>
92 </table>\n" .
93 Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
94 Html::closeElement( 'form' )
95 );
96
97 }
98
99 private function doSubmit() {
100 global $wgOut, $wgRequest, $wgReadOnlyFile;
101
102 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
103 if ( !$wpLockConfirm ) {
104 $this->showForm( wfMsg( 'locknoconfirm' ) );
105 return;
106 }
107
108 wfSuppressWarnings();
109 $res = unlink( $wgReadOnlyFile );
110 wfRestoreWarnings();
111
112 if ( !$res ) {
113 $wgOut->showFileDeleteError( $wgReadOnlyFile );
114 return;
115 }
116
117 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
118 }
119
120 private function showSuccess() {
121 global $wgOut;
122
123 $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
124 $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
125 }
126 }