| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use ErrorPageError; |
| 24 |
use MediaWiki\HTMLForm\HTMLForm; |
| 25 |
use MediaWiki\MainConfigNames; |
| 26 |
use MediaWiki\SpecialPage\FormSpecialPage; |
| 27 |
use MediaWiki\Status\Status; |
| 28 |
use MediaWiki\User\User; |
| 29 |
use Wikimedia\AtEase\AtEase; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class SpecialLockdb extends FormSpecialPage { |
| 39 |
|
| 40 |
public function __construct() { |
| 41 |
parent::__construct( 'Lockdb', 'siteadmin' ); |
| 42 |
} |
| 43 |
|
| 44 |
public function doesWrites() { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
public function requiresWrite() { |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
public function checkExecutePermissions( User $user ) { |
| 53 |
parent::checkExecutePermissions( $user ); |
| 54 |
|
| 55 |
if ( !is_writable( dirname( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) ) { |
| 56 |
throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' ); |
| 57 |
} |
| 58 |
if ( file_exists( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ) ) ) { |
| 59 |
throw new ErrorPageError( 'lockdb', 'databaselocked' ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
protected function getFormFields() { |
| 64 |
return [ |
| 65 |
'Reason' => [ |
| 66 |
'type' => 'textarea', |
| 67 |
'rows' => 4, |
| 68 |
'label-message' => 'enterlockreason', |
| 69 |
], |
| 70 |
'Confirm' => [ |
| 71 |
'type' => 'toggle', |
| 72 |
'label-message' => 'lockconfirm', |
| 73 |
], |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
protected function alterForm( HTMLForm $form ) { |
| 78 |
$form->setWrapperLegend( false ) |
| 79 |
->setHeaderHtml( $this->msg( 'lockdbtext' )->parseAsBlock() ) |
| 80 |
->setSubmitTextMsg( 'lockbtn' ); |
| 81 |
} |
| 82 |
|
| 83 |
public function onSubmit( array $data ) { |
| 84 |
if ( !$data['Confirm'] ) { |
| 85 |
return Status::newFatal( 'locknoconfirm' ); |
| 86 |
} |
| 87 |
|
| 88 |
AtEase::suppressWarnings(); |
| 89 |
$fp = fopen( $this->getConfig()->get( MainConfigNames::ReadOnlyFile ), 'w' ); |
| 90 |
AtEase::restoreWarnings(); |
| 91 |
|
| 92 |
if ( $fp === false ) { |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
return Status::newFatal( 'lockfilenotwritable' ); |
| 97 |
} |
| 98 |
fwrite( $fp, $data['Reason'] ); |
| 99 |
$timestamp = wfTimestampNow(); |
| 100 |
$contLang = $this->getContentLanguage(); |
| 101 |
fwrite( $fp, "\n<p>" . $this->msg( 'lockedbyandtime', |
| 102 |
$this->getUser()->getName(), |
| 103 |
$contLang->date( $timestamp, false, false ), |
| 104 |
$contLang->time( $timestamp, false, false ) |
| 105 |
)->inContentLanguage()->text() . "</p>\n" ); |
| 106 |
fclose( $fp ); |
| 107 |
|
| 108 |
return Status::newGood(); |
| 109 |
} |
| 110 |
|
| 111 |
public function onSuccess() { |
| 112 |
$out = $this->getOutput(); |
| 113 |
$out->addSubtitle( $this->msg( 'lockdbsuccesssub' ) ); |
| 114 |
$out->addWikiMsg( 'lockdbsuccesstext' ); |
| 115 |
} |
| 116 |
|
| 117 |
protected function getDisplayFormat() { |
| 118 |
return 'ooui'; |
| 119 |
} |
| 120 |
|
| 121 |
protected function getGroupName() { |
| 122 |
return 'wiki'; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
class_alias( SpecialLockdb::class, 'SpecialLockdb' ); |