]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialLockdb.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialLockdb.php
index 8c701dd60b372e54e77c7df216d65c34211f2451..aad3cea41adc2e83e6c86f255c24fcaa3c022baf 100644 (file)
 <?php
 /**
+ * Implements Special:Lockdb
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * Constructor
+ * A form to make the database readonly (eg for maintenance purposes).
+ *
+ * @ingroup SpecialPage
  */
-function wfSpecialLockdb() {
-       global $wgUser, $wgOut, $wgRequest;
+class SpecialLockdb extends SpecialPage {
+       var $reason = '';
 
-       if( !$wgUser->isAllowed( 'siteadmin' ) ) {
-               $wgOut->permissionRequired( 'siteadmin' );
-               return;
+       public function __construct() {
+               parent::__construct( 'Lockdb', 'siteadmin' );
        }
 
-       # If the lock file isn't writable, we can do sweet bugger all
-       global $wgReadOnlyFile;
-       if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
-               DBLockForm::notWritable();
-               return;
-       }
+       public function execute( $par ) {
+               global $wgUser, $wgOut, $wgRequest;
 
-       $action = $wgRequest->getVal( 'action' );
-       $f = new DBLockForm();
+               $this->setHeaders();
 
-       if ( 'success' == $action ) {
-               $f->showSuccess();
-       } else if ( 'submit' == $action && $wgRequest->wasPosted() &&
-               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-               $f->doSubmit();
-       } else {
-               $f->showForm( '' );
-       }
-}
+               if( !$wgUser->isAllowed( 'siteadmin' ) ) {
+                       $wgOut->permissionRequired( 'siteadmin' );
+                       return;
+               }
 
-/**
- * A form to make the database readonly (eg for maintenance purposes).
- * @ingroup SpecialPage
- */
-class DBLockForm {
-       var $reason = '';
+               $this->outputHeader();
 
-       function DBLockForm() {
-               global $wgRequest;
-               $this->reason = $wgRequest->getText( 'wpLockReason' );
+               # If the lock file isn't writable, we can do sweet bugger all
+               global $wgReadOnlyFile;
+               if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
+                       self::notWritable();
+                       return;
+               }
+
+               $action = $wgRequest->getVal( 'action' );
+               $this->reason = $wgRequest->getVal( 'wpLockReason', '' );
+
+               if ( $action == 'success' ) {
+                       $this->showSuccess();
+               } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
+                       $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+                       $this->doSubmit();
+               } else {
+                       $this->showForm();
+               }
        }
 
-       function showForm( $err ) {
+       private function showForm( $err = '' ) {
                global $wgOut, $wgUser;
 
-               $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
                $wgOut->addWikiMsg( 'lockdbtext' );
 
-               if ( $err != "" ) {
+               if ( $err != '' ) {
                        $wgOut->setSubtitle( wfMsg( 'formerror' ) );
                        $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
                }
-               $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) );
-               $lb = htmlspecialchars( wfMsg( 'lockbtn' ) );
-               $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) );
-               $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
-               $action = $titleObj->escapeLocalURL( 'action=submit' );
-               $reason = htmlspecialchars( $this->reason );
-               $token = htmlspecialchars( $wgUser->editToken() );
-
-               $wgOut->addHTML( <<<HTML
-<form id="lockdb" method="post" action="{$action}">
-{$elr}:
-<textarea name="wpLockReason" rows="10" cols="60" wrap="virtual">{$reason}</textarea>
-<table border="0">
+
+               $wgOut->addHTML(
+                       Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
+                               'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
+                       wfMsgHtml( 'enterlockreason' ) . ":\n" .
+                       Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). "
+<table>
        <tr>
-               <td align="right">
-                       <input type="checkbox" name="wpLockConfirm" />
+               " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
+                       " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
                </td>
-               <td align="left">{$lc}</td>
+               " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
+                       wfMsgHtml( 'lockconfirm' ) . "</td>
        </tr>
        <tr>
-               <td>&nbsp;</td>
-               <td align="left">
-                       <input type="submit" name="wpLock" value="{$lb}" />
+               <td>&#160;</td>
+               " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
+                       " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
                </td>
        </tr>
-</table>
-<input type="hidden" name="wpEditToken" value="{$token}" />
-</form>
-HTML
-);
+</table>\n" .
+                       Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
+                       Html::closeElement( 'form' )
+               );
 
        }
 
-       function doSubmit() {
-               global $wgOut, $wgUser, $wgLang, $wgRequest;
+       private function doSubmit() {
+               global $wgOut, $wgUser, $wgContLang, $wgRequest;
                global $wgReadOnlyFile;
 
                if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
@@ -109,14 +120,13 @@ HTML
                }
                fwrite( $fp, $this->reason );
                fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
-                 $wgLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
+                 $wgContLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
                fclose( $fp );
 
-               $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
-               $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
+               $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
        }
 
-       function showSuccess() {
+       private function showSuccess() {
                global $wgOut;
 
                $wgOut->setPagetitle( wfMsg( 'lockdb' ) );