Some documentation. Let's talk about it in wikitech-l.
[mediawiki.git] / includes / SpecialLockdb.php
blob2e758ad68704676d3d5a100e4a25314f678b5742
1 <?php
2 /**
4 */
6 /**
7 * Constructor
8 */
9 function wfSpecialLockdb()
11 global $wgUser, $wgOut, $wgRequest;
13 if ( ! $wgUser->isDeveloper() ) {
14 $wgOut->developerRequired();
15 return;
17 $action = $wgRequest->getText( 'action' );
18 $f = new DBLockForm();
20 if ( "success" == $action ) { $f->showSuccess(); }
21 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
22 else { $f->showForm( "" ); }
25 /**
28 class DBLockForm {
29 var $reason = '';
31 function DBLockForm() {
32 global $wgRequest;
33 $this->reason = $wgRequest->getText( 'wpLockReason' );
36 function showForm( $err )
38 global $wgOut, $wgUser, $wgLang;
40 $wgOut->setPagetitle( wfMsg( "lockdb" ) );
41 $wgOut->addWikiText( wfMsg( "lockdbtext" ) );
43 if ( "" != $err ) {
44 $wgOut->setSubtitle( wfMsg( "formerror" ) );
45 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
47 $lc = wfMsg( "lockconfirm" );
48 $lb = wfMsg( "lockbtn" );
49 $elr = wfMsg( "enterlockreason" );
50 $titleObj = Title::makeTitle( NS_SPECIAL, "Lockdb" );
51 $action = $titleObj->escapeLocalURL( "action=submit" );
53 $wgOut->addHTML( "<p>
54 <form id=\"lockdb\" method=\"post\" action=\"{$action}\">
55 {$elr}:
56 <textarea name=\"wpLockReason\" rows=10 cols=60 wrap=virtual>
57 </textarea>
58 <table border=0><tr>
59 <td align=right>
60 <input type=checkbox name=\"wpLockConfirm\">
61 </td>
62 <td align=left>{$lc}<td>
63 </tr><tr>
64 <td>&nbsp;</td><td align=left>
65 <input type=submit name=\"wpLock\" value=\"{$lb}\">
66 </td></tr></table>
67 </form>\n" );
71 function doSubmit() {
72 global $wgOut, $wgUser, $wgLang, $wgRequest;
73 global $wgReadOnlyFile;
75 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
76 $this->showForm( wfMsg( "locknoconfirm" ) );
77 return;
79 $fp = fopen( $wgReadOnlyFile, "w" );
81 if ( false === $fp ) {
82 $wgOut->fileNotFoundError( $wgReadOnlyFile );
83 return;
85 fwrite( $fp, $this->reason );
86 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
87 $wgLang->timeanddate( wfTimestampNow() ) . ")\n" );
88 fclose( $fp );
90 $titleObj = Title::makeTitle( NS_SPECIAL, "Lockdb" );
91 $wgOut->redirect( $titleObj->getFullURL( "action=success" ) );
94 function showSuccess() {
95 global $wgOut, $wgUser;
97 $wgOut->setPagetitle( wfMsg( "lockdb" ) );
98 $wgOut->setSubtitle( wfMsg( "lockdbsuccesssub" ) );
99 $wgOut->addWikiText( wfMsg( "lockdbsuccesstext" ) );