2020-10-23 03:17:31 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\EditPage\Constraint;
|
|
|
|
|
|
2024-08-08 09:14:35 +00:00
|
|
|
use MediaWiki\Content\Content;
|
2020-10-23 03:17:31 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2021-03-02 22:28:04 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2020-10-23 03:17:31 +00:00
|
|
|
use StatusValue;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify user permissions:
|
|
|
|
|
* If creating a redirect in the file namespace, must have upload rights
|
|
|
|
|
*
|
|
|
|
|
* @since 1.36
|
|
|
|
|
* @internal
|
|
|
|
|
* @author DannyS712
|
|
|
|
|
*/
|
|
|
|
|
class ImageRedirectConstraint implements IEditConstraint {
|
|
|
|
|
|
2024-07-10 15:22:01 +00:00
|
|
|
private Content $newContent;
|
|
|
|
|
private LinkTarget $title;
|
|
|
|
|
private Authority $performer;
|
|
|
|
|
private string $result;
|
2020-10-23 03:17:31 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-12-09 21:25:28 +00:00
|
|
|
* @param Content $newContent
|
2020-10-23 03:17:31 +00:00
|
|
|
* @param LinkTarget $title
|
2021-03-02 22:28:04 +00:00
|
|
|
* @param Authority $performer
|
2020-10-23 03:17:31 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2020-12-09 21:25:28 +00:00
|
|
|
Content $newContent,
|
2020-10-23 03:17:31 +00:00
|
|
|
LinkTarget $title,
|
2021-03-02 22:28:04 +00:00
|
|
|
Authority $performer
|
2020-10-23 03:17:31 +00:00
|
|
|
) {
|
2020-12-09 21:25:28 +00:00
|
|
|
$this->newContent = $newContent;
|
2020-10-23 03:17:31 +00:00
|
|
|
$this->title = $title;
|
2021-03-02 22:28:04 +00:00
|
|
|
$this->performer = $performer;
|
2020-10-23 03:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
public function checkConstraint(): string {
|
2020-10-23 03:17:31 +00:00
|
|
|
// Check isn't simple enough to just repeat when getting the status
|
|
|
|
|
if ( $this->title->getNamespace() === NS_FILE &&
|
2020-12-09 21:25:28 +00:00
|
|
|
$this->newContent->isRedirect() &&
|
2021-03-02 22:28:04 +00:00
|
|
|
!$this->performer->isAllowed( 'upload' )
|
2020-10-23 03:17:31 +00:00
|
|
|
) {
|
|
|
|
|
$this->result = self::CONSTRAINT_FAILED;
|
|
|
|
|
return self::CONSTRAINT_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->result = self::CONSTRAINT_PASSED;
|
|
|
|
|
return self::CONSTRAINT_PASSED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
public function getLegacyStatus(): StatusValue {
|
2020-10-23 03:17:31 +00:00
|
|
|
$statusValue = StatusValue::newGood();
|
|
|
|
|
|
|
|
|
|
if ( $this->result === self::CONSTRAINT_FAILED ) {
|
2021-03-04 19:45:28 +00:00
|
|
|
$errorCode = $this->performer->getUser()->isRegistered() ?
|
2021-03-02 22:28:04 +00:00
|
|
|
self::AS_IMAGE_REDIRECT_LOGGED :
|
|
|
|
|
self::AS_IMAGE_REDIRECT_ANON;
|
2020-10-23 03:17:31 +00:00
|
|
|
$statusValue->setResult( false, $errorCode );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $statusValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|