Introducing broken changes in commits meant to fix broken changes is vaguely ironic.
[lhc/web/wiklou.git] / includes / SpecialUnlockdb.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 function wfSpecialUnlockdb() {
11 global $wgUser, $wgOut, $wgRequest;
12
13 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
14 $wgOut->permissionRequired( 'siteadmin' );
15 return;
16 }
17
18 $action = $wgRequest->getVal( 'action' );
19 $f = new DBUnlockForm();
20
21 if ( "success" == $action ) {
22 $f->showSuccess();
23 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
24 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
25 $f->doSubmit();
26 } else {
27 $f->showForm( "" );
28 }
29 }
30
31 /**
32 *
33 * @addtogroup SpecialPage
34 */
35 class DBUnlockForm {
36 function showForm( $err )
37 {
38 global $wgOut, $wgUser;
39
40 global $wgReadOnlyFile;
41 if( !file_exists( $wgReadOnlyFile ) ) {
42 $wgOut->addWikiText( wfMsg( 'databasenotlocked' ) );
43 return;
44 }
45
46 $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
47 $wgOut->addWikiText( wfMsg( "unlockdbtext" ) );
48
49 if ( "" != $err ) {
50 $wgOut->setSubtitle( wfMsg( "formerror" ) );
51 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
52 }
53 $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
54 $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
55 $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
56 $action = $titleObj->escapeLocalURL( "action=submit" );
57 $token = htmlspecialchars( $wgUser->editToken() );
58
59 $wgOut->addHTML( <<<END
60
61 <form id="unlockdb" method="post" action="{$action}">
62 <table border="0">
63 <tr>
64 <td align="right">
65 <input type="checkbox" name="wpLockConfirm" />
66 </td>
67 <td align="left">{$lc}</td>
68 </tr>
69 <tr>
70 <td>&nbsp;</td>
71 <td align="left">
72 <input type="submit" name="wpLock" value="{$lb}" />
73 </td>
74 </tr>
75 </table>
76 <input type="hidden" name="wpEditToken" value="{$token}" />
77 </form>
78 END
79 );
80
81 }
82
83 function doSubmit() {
84 global $wgOut, $wgRequest, $wgReadOnlyFile;
85
86 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
87 if ( ! $wpLockConfirm ) {
88 $this->showForm( wfMsg( "locknoconfirm" ) );
89 return;
90 }
91 if ( @! unlink( $wgReadOnlyFile ) ) {
92 $wgOut->showFileDeleteError( $wgReadOnlyFile );
93 return;
94 }
95 $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
96 $success = $titleObj->getFullURL( "action=success" );
97 $wgOut->redirect( $success );
98 }
99
100 function showSuccess() {
101 global $wgOut;
102 global $ip;
103
104 $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
105 $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
106 $wgOut->addWikiText( wfMsg( "unlockdbsuccesstext", $ip ) );
107 }
108 }
109
110 ?>