f4e0dd9600fdcd79f1fa430d56b678108887f644
[lhc/web/wiklou.git] / includes / SpecialLockdb.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Constructor
10 */
11 function wfSpecialLockdb() {
12 global $wgUser, $wgOut, $wgRequest;
13
14 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
15 $wgOut->permissionRequired( 'siteadmin' );
16 return;
17 }
18
19 # If the lock file isn't writable, we can do sweet bugger all
20 global $wgReadOnlyFile;
21 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
22 DBLockForm::notWritable();
23 return;
24 }
25
26 $action = $wgRequest->getVal( 'action' );
27 $f = new DBLockForm();
28
29 if ( 'success' == $action ) {
30 $f->showSuccess();
31 } else if ( 'submit' == $action && $wgRequest->wasPosted() &&
32 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
33 $f->doSubmit();
34 } else {
35 $f->showForm( '' );
36 }
37 }
38
39 /**
40 *
41 * @package MediaWiki
42 * @subpackage SpecialPage
43 */
44 class DBLockForm {
45 var $reason = '';
46
47 function DBLockForm() {
48 global $wgRequest;
49 $this->reason = $wgRequest->getText( 'wpLockReason' );
50 }
51
52 function showForm( $err ) {
53 global $wgOut, $wgUser;
54
55 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
56 $wgOut->addWikiText( wfMsg( 'lockdbtext' ) );
57
58 if ( "" != $err ) {
59 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
60 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
61 }
62 $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) );
63 $lb = htmlspecialchars( wfMsg( 'lockbtn' ) );
64 $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) );
65 $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
66 $action = $titleObj->escapeLocalURL( 'action=submit' );
67 $reason = htmlspecialchars( $this->reason );
68 $token = htmlspecialchars( $wgUser->editToken() );
69
70 $wgOut->addHTML( <<<END
71 <form id="lockdb" method="post" action="{$action}">
72 {$elr}:
73 <textarea name="wpLockReason" rows="10" cols="60" wrap="virtual">{$reason}</textarea>
74 <table border="0">
75 <tr>
76 <td align="right">
77 <input type="checkbox" name="wpLockConfirm" />
78 </td>
79 <td align="left">{$lc}</td>
80 </tr>
81 <tr>
82 <td>&nbsp;</td>
83 <td align="left">
84 <input type="submit" name="wpLock" value="{$lb}" />
85 </td>
86 </tr>
87 </table>
88 <input type="hidden" name="wpEditToken" value="{$token}" />
89 </form>
90 END
91 );
92
93 }
94
95 function doSubmit() {
96 global $wgOut, $wgUser, $wgLang, $wgRequest;
97 global $wgReadOnlyFile;
98
99 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
100 $this->showForm( wfMsg( 'locknoconfirm' ) );
101 return;
102 }
103 $fp = @fopen( $wgReadOnlyFile, 'w' );
104
105 if ( false === $fp ) {
106 # This used to show a file not found error, but the likeliest reason for fopen()
107 # to fail at this point is insufficient permission to write to the file...good old
108 # is_writable() is plain wrong in some cases, it seems...
109 $this->notWritable();
110 return;
111 }
112 fwrite( $fp, $this->reason );
113 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
114 $wgLang->timeanddate( wfTimestampNow() ) . ")\n" );
115 fclose( $fp );
116
117 $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
118 $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
119 }
120
121 function showSuccess() {
122 global $wgOut;
123
124 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
125 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
126 $wgOut->addWikiText( wfMsg( 'lockdbsuccesstext' ) );
127 }
128
129 public static function notWritable() {
130 global $wgOut;
131 $wgOut->errorPage( 'lockdb', 'lockfilenotwritable' );
132 }
133
134 }
135
136 ?>