[EditPage] Move AS_* status constants to a new interface
Interface is @internal and is implemented by EditPage; will be used in the future when the backend is split and common status values are needed for the different classes. Doing separately to avoid cluttering the main work - just moves the constant definitions. Since EditPage implements the new interface, any existing EditPage::AS_* references will continue to work. Bug: T20654 Change-Id: I71dafec2579b4a42dd08f3fc7e569e28c14d8753
This commit is contained in:
parent
84390e9887
commit
615b880051
3 changed files with 145 additions and 145 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
use MediaWiki\Block\DatabaseBlock;
|
use MediaWiki\Block\DatabaseBlock;
|
||||||
use MediaWiki\Content\IContentHandlerFactory;
|
use MediaWiki\Content\IContentHandlerFactory;
|
||||||
|
use MediaWiki\EditPage\IEditObject;
|
||||||
use MediaWiki\EditPage\TextboxBuilder;
|
use MediaWiki\EditPage\TextboxBuilder;
|
||||||
use MediaWiki\EditPage\TextConflictHelper;
|
use MediaWiki\EditPage\TextConflictHelper;
|
||||||
use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
|
use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
|
||||||
|
|
@ -49,7 +50,7 @@ use Wikimedia\ScopedCallback;
|
||||||
* Surgeon General's Warning: prolonged exposure to this class is known to cause
|
* Surgeon General's Warning: prolonged exposure to this class is known to cause
|
||||||
* headaches, which may be fatal.
|
* headaches, which may be fatal.
|
||||||
*/
|
*/
|
||||||
class EditPage {
|
class EditPage implements IEditObject {
|
||||||
use DeprecationHelper;
|
use DeprecationHelper;
|
||||||
use ProtectedHookAccessorTrait;
|
use ProtectedHookAccessorTrait;
|
||||||
|
|
||||||
|
|
@ -58,150 +59,6 @@ class EditPage {
|
||||||
*/
|
*/
|
||||||
public const UNICODE_CHECK = 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ';
|
public const UNICODE_CHECK = 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ';
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: Article successfully updated
|
|
||||||
*/
|
|
||||||
public const AS_SUCCESS_UPDATE = 200;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: Article successfully created
|
|
||||||
*/
|
|
||||||
public const AS_SUCCESS_NEW_ARTICLE = 201;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: Article update aborted by a hook function
|
|
||||||
*/
|
|
||||||
public const AS_HOOK_ERROR = 210;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: A hook function returned an error
|
|
||||||
*/
|
|
||||||
public const AS_HOOK_ERROR_EXPECTED = 212;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: User is blocked from editing this page
|
|
||||||
*/
|
|
||||||
public const AS_BLOCKED_PAGE_FOR_USER = 215;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: Content too big (> $wgMaxArticleSize)
|
|
||||||
*/
|
|
||||||
public const AS_CONTENT_TOO_BIG = 216;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: this anonymous user is not allowed to edit this page
|
|
||||||
*/
|
|
||||||
public const AS_READ_ONLY_PAGE_ANON = 218;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: this logged in user is not allowed to edit this page
|
|
||||||
*/
|
|
||||||
public const AS_READ_ONLY_PAGE_LOGGED = 219;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: wiki is in readonly mode (wfReadOnly() == true)
|
|
||||||
*/
|
|
||||||
public const AS_READ_ONLY_PAGE = 220;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: rate limiter for action 'edit' was tripped
|
|
||||||
*/
|
|
||||||
public const AS_RATE_LIMITED = 221;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: article was deleted while editing and param wpRecreate == false or form
|
|
||||||
* was not posted
|
|
||||||
*/
|
|
||||||
public const AS_ARTICLE_WAS_DELETED = 222;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: user tried to create this page, but is not allowed to do that
|
|
||||||
* ( Title->userCan('create') == false )
|
|
||||||
*/
|
|
||||||
public const AS_NO_CREATE_PERMISSION = 223;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: user tried to create a blank page and wpIgnoreBlankArticle == false
|
|
||||||
*/
|
|
||||||
public const AS_BLANK_ARTICLE = 224;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: (non-resolvable) edit conflict
|
|
||||||
*/
|
|
||||||
public const AS_CONFLICT_DETECTED = 225;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: no edit summary given and the user has forceeditsummary set and the user is not
|
|
||||||
* editing in his own userspace or talkspace and wpIgnoreBlankSummary == false
|
|
||||||
*/
|
|
||||||
public const AS_SUMMARY_NEEDED = 226;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: user tried to create a new section without content
|
|
||||||
*/
|
|
||||||
public const AS_TEXTBOX_EMPTY = 228;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: article is too big (> $wgMaxArticleSize), after merging in the new section
|
|
||||||
*/
|
|
||||||
public const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: WikiPage::doEdit() was unsuccessful
|
|
||||||
*/
|
|
||||||
public const AS_END = 231;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex
|
|
||||||
*/
|
|
||||||
public const AS_SPAM_ERROR = 232;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
|
|
||||||
*/
|
|
||||||
public const AS_IMAGE_REDIRECT_ANON = 233;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
|
|
||||||
*/
|
|
||||||
public const AS_IMAGE_REDIRECT_LOGGED = 234;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: user tried to modify the content model, but is not allowed to do that
|
|
||||||
* ( User::isAllowed('editcontentmodel') == false )
|
|
||||||
*/
|
|
||||||
public const AS_NO_CHANGE_CONTENT_MODEL = 235;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: user tried to create self-redirect (redirect to the same article) and
|
|
||||||
* wpIgnoreSelfRedirect == false
|
|
||||||
*/
|
|
||||||
public const AS_SELF_REDIRECT = 236;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: an error relating to change tagging. Look at the message key for
|
|
||||||
* more details
|
|
||||||
*/
|
|
||||||
public const AS_CHANGE_TAG_ERROR = 237;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: can't parse content
|
|
||||||
*/
|
|
||||||
public const AS_PARSE_ERROR = 240;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: when changing the content model is disallowed due to
|
|
||||||
* $wgContentHandlerUseDB being false
|
|
||||||
*
|
|
||||||
* @deprecated since 1.35, meaningless since $wgContentHandlerUseDB has been removed.
|
|
||||||
*/
|
|
||||||
public const AS_CANNOT_USE_CUSTOM_MODEL = 241;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status: edit rejected because browser doesn't support Unicode.
|
|
||||||
*/
|
|
||||||
public const AS_UNICODE_NOT_SUPPORTED = 242;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML id and name for the beginning of the edit form.
|
* HTML id and name for the beginning of the edit form.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
104
includes/editpage/IEditObject.php
Normal file
104
includes/editpage/IEditObject.php
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MediaWiki\EditPage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serves as a common repository of constants for EditPage edit status results
|
||||||
|
*
|
||||||
|
* Each of these is a possible status value
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
interface IEditObject {
|
||||||
|
/** Status: Article successfully updated */
|
||||||
|
public const AS_SUCCESS_UPDATE = 200;
|
||||||
|
|
||||||
|
/** Status: Article successfully created */
|
||||||
|
public const AS_SUCCESS_NEW_ARTICLE = 201;
|
||||||
|
|
||||||
|
/** Status: Article update aborted by a hook function */
|
||||||
|
public const AS_HOOK_ERROR = 210;
|
||||||
|
|
||||||
|
/** Status: A hook function returned an error */
|
||||||
|
public const AS_HOOK_ERROR_EXPECTED = 212;
|
||||||
|
|
||||||
|
/** Status: User is blocked from editing this page */
|
||||||
|
public const AS_BLOCKED_PAGE_FOR_USER = 215;
|
||||||
|
|
||||||
|
/** Status: Content too big (> $wgMaxArticleSize) */
|
||||||
|
public const AS_CONTENT_TOO_BIG = 216;
|
||||||
|
|
||||||
|
/** Status: this anonymous user is not allowed to edit this page */
|
||||||
|
public const AS_READ_ONLY_PAGE_ANON = 218;
|
||||||
|
|
||||||
|
/** Status: this logged in user is not allowed to edit this page */
|
||||||
|
public const AS_READ_ONLY_PAGE_LOGGED = 219;
|
||||||
|
|
||||||
|
/** Status: wiki is in readonly mode (wfReadOnly() == true) */
|
||||||
|
public const AS_READ_ONLY_PAGE = 220;
|
||||||
|
|
||||||
|
/** Status: rate limiter for action 'edit' was tripped */
|
||||||
|
public const AS_RATE_LIMITED = 221;
|
||||||
|
|
||||||
|
/** Status: article was deleted while editing and wpRecreate == false or form was not posted */
|
||||||
|
public const AS_ARTICLE_WAS_DELETED = 222;
|
||||||
|
|
||||||
|
/** Status: user tried to create this page, but is not allowed to do that */
|
||||||
|
public const AS_NO_CREATE_PERMISSION = 223;
|
||||||
|
|
||||||
|
/** Status: user tried to create a blank page and wpIgnoreBlankArticle == false */
|
||||||
|
public const AS_BLANK_ARTICLE = 224;
|
||||||
|
|
||||||
|
/** Status: (non-resolvable) edit conflict */
|
||||||
|
public const AS_CONFLICT_DETECTED = 225;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status: no edit summary given and the user has forceeditsummary set and the user is not
|
||||||
|
* editing in his own userspace or talkspace and wpIgnoreBlankSummary == false
|
||||||
|
*/
|
||||||
|
public const AS_SUMMARY_NEEDED = 226;
|
||||||
|
|
||||||
|
/** Status: user tried to create a new section without content */
|
||||||
|
public const AS_TEXTBOX_EMPTY = 228;
|
||||||
|
|
||||||
|
/** Status: article is too big (> $wgMaxArticleSize), after merging in the new section */
|
||||||
|
public const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
|
||||||
|
|
||||||
|
/** Status: WikiPage::doEdit() was unsuccessful */
|
||||||
|
public const AS_END = 231;
|
||||||
|
|
||||||
|
/** Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex */
|
||||||
|
public const AS_SPAM_ERROR = 232;
|
||||||
|
|
||||||
|
/** Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false) */
|
||||||
|
public const AS_IMAGE_REDIRECT_ANON = 233;
|
||||||
|
|
||||||
|
/** Status: logged in user is not allowed to upload (User::isAllowed('upload') == false) */
|
||||||
|
public const AS_IMAGE_REDIRECT_LOGGED = 234;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status: user tried to modify the content model, but is not allowed to do that
|
||||||
|
* ( User::isAllowed('editcontentmodel') == false )
|
||||||
|
*/
|
||||||
|
public const AS_NO_CHANGE_CONTENT_MODEL = 235;
|
||||||
|
|
||||||
|
/** Status: user tried to create self-redirect and wpIgnoreSelfRedirect is false */
|
||||||
|
public const AS_SELF_REDIRECT = 236;
|
||||||
|
|
||||||
|
/** Status: an error relating to change tagging. Look at the message key for more details */
|
||||||
|
public const AS_CHANGE_TAG_ERROR = 237;
|
||||||
|
|
||||||
|
/** Status: can't parse content */
|
||||||
|
public const AS_PARSE_ERROR = 240;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status: when changing the content model is disallowed due to
|
||||||
|
* $wgContentHandlerUseDB being false
|
||||||
|
*
|
||||||
|
* @deprecated since 1.35, meaningless since $wgContentHandlerUseDB has been removed.
|
||||||
|
*/
|
||||||
|
public const AS_CANNOT_USE_CUSTOM_MODEL = 241;
|
||||||
|
|
||||||
|
/** Status: edit rejected because browser doesn't support Unicode. */
|
||||||
|
public const AS_UNICODE_NOT_SUPPORTED = 242;
|
||||||
|
}
|
||||||
39
tests/phpunit/unit/includes/editpage/IEditObjectTest.php
Normal file
39
tests/phpunit/unit/includes/editpage/IEditObjectTest.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use MediaWiki\EditPage\IEditObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers EditPage
|
||||||
|
*
|
||||||
|
* MediaWikiCoversValidator fails when trying to say that this covers an interface,
|
||||||
|
* but this covers \MediaWiki\EditPage\IEditObject primarily
|
||||||
|
*
|
||||||
|
* @author DannyS712
|
||||||
|
*/
|
||||||
|
class IEditObjectTest extends MediaWikiUnitTestCase {
|
||||||
|
|
||||||
|
public function testConstants() {
|
||||||
|
// Ensure that each of the constants used as a status is unique
|
||||||
|
$reflection = new ReflectionClass( IEditObject::class );
|
||||||
|
$constants = $reflection->getConstants();
|
||||||
|
|
||||||
|
// Keys (constant names) are required to be unique by php, only need to
|
||||||
|
// test the values
|
||||||
|
$values = array_values( $constants );
|
||||||
|
$uniqueValues = array_unique( $values );
|
||||||
|
$this->assertArrayEquals(
|
||||||
|
$values,
|
||||||
|
$uniqueValues,
|
||||||
|
'All status constants have unique values'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure that any old reference to EditPage::AS_* still works
|
||||||
|
foreach ( $constants as $key => $value ) {
|
||||||
|
$this->assertSame(
|
||||||
|
constant( EditPage::class . '::' . $key ),
|
||||||
|
$value,
|
||||||
|
"EditPage::$key still works properly"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue