* Reorganised the includes directory, creating subdirectories db, parser and specials
[lhc/web/wiklou.git] / includes / specials / Unlockdb.php
1 <?php
2 /**
3 * @file
4 * @ingroup 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 * @ingroup SpecialPage
33 */
34 class DBUnlockForm {
35 function showForm( $err )
36 {
37 global $wgOut, $wgUser;
38
39 global $wgReadOnlyFile;
40 if( !file_exists( $wgReadOnlyFile ) ) {
41 $wgOut->addWikiMsg( 'databasenotlocked' );
42 return;
43 }
44
45 $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
46 $wgOut->addWikiMsg( "unlockdbtext" );
47
48 if ( "" != $err ) {
49 $wgOut->setSubtitle( wfMsg( "formerror" ) );
50 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
51 }
52 $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
53 $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
54 $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
55 $action = $titleObj->escapeLocalURL( "action=submit" );
56 $token = htmlspecialchars( $wgUser->editToken() );
57
58 $wgOut->addHTML( <<<END
59
60 <form id="unlockdb" method="post" action="{$action}">
61 <table border="0">
62 <tr>
63 <td align="right">
64 <input type="checkbox" name="wpLockConfirm" />
65 </td>
66 <td align="left">{$lc}</td>
67 </tr>
68 <tr>
69 <td>&nbsp;</td>
70 <td align="left">
71 <input type="submit" name="wpLock" value="{$lb}" />
72 </td>
73 </tr>
74 </table>
75 <input type="hidden" name="wpEditToken" value="{$token}" />
76 </form>
77 END
78 );
79
80 }
81
82 function doSubmit() {
83 global $wgOut, $wgRequest, $wgReadOnlyFile;
84
85 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
86 if ( ! $wpLockConfirm ) {
87 $this->showForm( wfMsg( "locknoconfirm" ) );
88 return;
89 }
90 if ( @! unlink( $wgReadOnlyFile ) ) {
91 $wgOut->showFileDeleteError( $wgReadOnlyFile );
92 return;
93 }
94 $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
95 $success = $titleObj->getFullURL( "action=success" );
96 $wgOut->redirect( $success );
97 }
98
99 function showSuccess() {
100 global $wgOut;
101 global $ip;
102
103 $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
104 $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
105 $wgOut->addWikiMsg( "unlockdbsuccesstext", $ip );
106 }
107 }