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