Implementing user levels management. This is only a very basic interface and several...
[lhc/web/wiklou.git] / includes / SpecialLockdb.php
index 5d6be73..1635aa4 100644 (file)
@@ -1,29 +1,45 @@
-<?
-
+<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ * Constructor
+ */
 function wfSpecialLockdb()
 {
-       global $wgUser, $wgOut, $action;
+       global $wgUser, $wgOut, $wgRequest;
 
-       if ( ! $wgUser->isDeveloper() ) {
+       if ( ! $wgUser->isAllowed('siteadmin') ) {
                $wgOut->developerRequired();
                return;
        }
-       $fields = array( "wpLockReason" );
-       wfCleanFormFields( $fields );
-
+       $action = $wgRequest->getVal( 'action' );
        $f = new DBLockForm();
 
        if ( "success" == $action ) { $f->showSuccess(); }
-       else if ( "submit" == $action ) { $f->doSubmit(); }
+       else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
        else { $f->showForm( "" ); }
 }
 
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
 class DBLockForm {
-
+       var $reason = '';
+       
+       function DBLockForm() {
+               global $wgRequest;
+               $this->reason = $wgRequest->getText( 'wpLockReason' );
+       }
+       
        function showForm( $err )
        {
                global $wgOut, $wgUser, $wgLang;
-               global $wpLockConfirm;
 
                $wgOut->setPagetitle( wfMsg( "lockdb" ) );
                $wgOut->addWikiText( wfMsg( "lockdbtext" ) );
@@ -35,33 +51,38 @@ class DBLockForm {
                $lc = wfMsg( "lockconfirm" );
                $lb = wfMsg( "lockbtn" );
                $elr = wfMsg( "enterlockreason" );
-               $action = wfLocalUrlE( $wgLang->specialPage( "Lockdb" ),
-                 "action=submit" );
+               $titleObj = Title::makeTitle( NS_SPECIAL, "Lockdb" );
+               $action = $titleObj->escapeLocalURL( "action=submit" );
 
-               $wgOut->addHTML( "<p>
-<form id=\"lockdb\" method=\"post\" action=\"{$action}\">
+               $wgOut->addHTML( <<<END
+<form id="lockdb" method="post" action="{$action}">
 {$elr}:
-<textarea name=\"wpLockReason\" rows=10 cols=60 wrap=virtual>
-</textarea>
-<table border=0><tr>
-<td align=right>
-<input type=checkbox name=\"wpLockConfirm\">
-</td>
-<td align=left>{$lc}<td>
-</tr><tr>
-<td>&nbsp;</td><td align=left>
-<input type=submit name=\"wpLock\" value=\"{$lb}\">
-</td></tr></table>
-</form>\n" );
+<textarea name="wpLockReason" rows="10" cols="60" wrap="virtual"></textarea>
+<table border="0">
+       <tr>
+               <td align="right">
+                       <input type="checkbox" name="wpLockConfirm" />
+               </td>
+               <td align="left">{$lc}</td>
+       </tr>
+       <tr>
+               <td>&nbsp;</td>
+               <td align="left">
+                       <input type="submit" name="wpLock" value="{$lb}" />
+               </td>
+       </tr>
+</table>
+</form>
+END
+);
 
        }
 
-       function doSubmit()
-       {
-               global $wgOut, $wgUser, $wgLang;
-               global $wpLockConfirm, $wpLockReason, $wgReadOnlyFile;
+       function doSubmit() {
+               global $wgOut, $wgUser, $wgLang, $wgRequest;
+               global $wgReadOnlyFile;
 
-               if ( ! $wpLockConfirm ) {
+               if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
                        $this->showForm( wfMsg( "locknoconfirm" ) );
                        return;
                }
@@ -71,24 +92,21 @@ class DBLockForm {
                        $wgOut->fileNotFoundError( $wgReadOnlyFile );
                        return;
                }
-               fwrite( $fp, $wpLockReason );
+               fwrite( $fp, $this->reason );
                fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
                  $wgLang->timeanddate( wfTimestampNow() ) . ")\n" );
                fclose( $fp );
 
-               $success = wfLocalUrl( $wgLang->specialPage( "Lockdb" ),
-                 "action=success" );
-               $wgOut->redirect( $success );
+               $titleObj = Title::makeTitle( NS_SPECIAL, "Lockdb" );
+               $wgOut->redirect( $titleObj->getFullURL( "action=success" ) );
        }
 
-       function showSuccess()
-       {
+       function showSuccess() {
                global $wgOut, $wgUser;
-               global $ip;
 
                $wgOut->setPagetitle( wfMsg( "lockdb" ) );
                $wgOut->setSubtitle( wfMsg( "lockdbsuccesssub" ) );
-               $wgOut->addWikiText( wfMsg( "lockdbsuccesstext", $ip ) );
+               $wgOut->addWikiText( wfMsg( "lockdbsuccesstext" ) );
        }
 }