| 1 | <?php |
| 2 | /** |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | * http://www.gnu.org/copyleft/gpl.html |
| 17 | * |
| 18 | * @file |
| 19 | */ |
| 20 | |
| 21 | namespace MediaWiki\EditPage\Constraint; |
| 22 | |
| 23 | use StatusValue; |
| 24 | use Wikimedia\Rdbms\ReadOnlyMode; |
| 25 | |
| 26 | /** |
| 27 | * Verify site is not in read only mode |
| 28 | * |
| 29 | * @since 1.36 |
| 30 | * @internal |
| 31 | * @author DannyS712 |
| 32 | */ |
| 33 | class ReadOnlyConstraint implements IEditConstraint { |
| 34 | |
| 35 | private ReadOnlyMode $readOnlyMode; |
| 36 | private string $result; |
| 37 | |
| 38 | /** |
| 39 | * @param ReadOnlyMode $readOnlyMode |
| 40 | */ |
| 41 | public function __construct( ReadOnlyMode $readOnlyMode ) { |
| 42 | $this->readOnlyMode = $readOnlyMode; |
| 43 | } |
| 44 | |
| 45 | public function checkConstraint(): string { |
| 46 | $this->result = $this->readOnlyMode->isReadOnly() ? |
| 47 | self::CONSTRAINT_FAILED : |
| 48 | self::CONSTRAINT_PASSED; |
| 49 | return $this->result; |
| 50 | } |
| 51 | |
| 52 | public function getLegacyStatus(): StatusValue { |
| 53 | $statusValue = StatusValue::newGood(); |
| 54 | |
| 55 | if ( $this->result === self::CONSTRAINT_FAILED ) { |
| 56 | // Saved that this is read only in case getLegacyStatus is called |
| 57 | // after the read only ends, because it still caused the failure |
| 58 | $statusValue->fatal( 'readonlytext' ); |
| 59 | $statusValue->value = self::AS_READ_ONLY_PAGE; |
| 60 | } |
| 61 | |
| 62 | return $statusValue; |
| 63 | } |
| 64 | |
| 65 | } |