Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Community
WSSpaces
Commits
12d9ec49
Verified
Commit
12d9ec49
authored
Nov 26, 2021
by
Marijn van Wezel
❤
Browse files
Cleanup to meet MediaWiki coding standards
parent
4faccf55
Pipeline
#1320
passed with stages
in 29 seconds
Changes
30
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/API/ApiAddSpace.php
View file @
12d9ec49
...
...
@@ -3,9 +3,7 @@
namespace
WSS\API
;
use
ApiUsageException
;
use
MediaWiki\MediaWikiServices
;
use
MWException
;
use
User
;
use
WSS\NamespaceRepository
;
use
WSS\Space
;
use
WSS\Validation\AddSpaceValidationCallback
;
...
...
@@ -79,25 +77,25 @@ class ApiAddSpace extends ApiBase {
$ns_key
=
isset
(
$request_params
[
"nskey"
]
)
?
$request_params
[
"nskey"
]
:
false
;
if
(
$ns_key
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nskey"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nskey"
)
);
}
$ns_name
=
isset
(
$request_params
[
"nsname"
]
)
?
$request_params
[
"nsname"
]
:
false
;
if
(
$ns_name
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsname"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsname"
)
);
}
$ns_description
=
isset
(
$request_params
[
"nsdescription"
]
)
?
$request_params
[
"nsdescription"
]
:
false
;
if
(
$ns_description
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsdescription"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsdescription"
)
);
}
$ns_admins
=
isset
(
$request_params
[
"nsadmins"
]
)
?
$request_params
[
"nsadmins"
]
:
false
;
if
(
$ns_admins
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsadmins"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsadmins"
)
);
}
// Although this validation is made for HTMLForm, we use it here to avoid repeating ourselves
...
...
@@ -111,18 +109,18 @@ class ApiAddSpace extends ApiBase {
// Validate "nskey"
$error_or_true
=
$add_space_validation_callback
->
validateField
(
"namespace"
,
$ns_key
,
$request_data
);
if
(
$error_or_true
!==
true
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-invalid-param-detailed-nskey"
,
$error_or_true
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-invalid-param-detailed-nskey"
,
$error_or_true
)
);
}
// Validate "nsname"
$error_or_true
=
$add_space_validation_callback
->
validateField
(
"namespace_name"
,
$ns_name
,
$request_data
);
if
(
$error_or_true
!==
true
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-invalid-param-detailed-nsname"
,
$error_or_true
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-invalid-param-detailed-nsname"
,
$error_or_true
)
);
}
// Validate "nsdescription"
if
(
$add_space_validation_callback
->
validateRequired
(
$ns_description
)
!==
true
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-invalid-param-nsdescription"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-invalid-param-nsdescription"
)
);
}
}
...
...
src/API/ApiArchiveSpace.php
View file @
12d9ec49
...
...
@@ -35,16 +35,16 @@ class ApiArchiveSpace extends ApiBase {
$request_params
=
$this
->
extractRequestParams
();
if
(
!
isset
(
$request_params
[
"nsid"
]
)
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsid"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsid"
)
);
}
$space
=
Space
::
newFromConstant
(
$request_params
[
"nsid"
]
);
if
(
!
$space
instanceof
Space
)
{
$this
->
dieWithError
(
wfMessage
(
$this
->
msg
(
"wss-api-invalid-param-detailed-nsid"
,
wfMessage
(
"wss-api-space-does-not-exist"
,
$request_params
[
"nsid"
]
)
->
parse
()
$this
->
msg
(
"wss-api-space-does-not-exist"
,
$request_params
[
"nsid"
]
)
->
parse
()
)
->
parse
()
);
}
...
...
src/API/ApiEditSpace.php
View file @
12d9ec49
...
...
@@ -3,9 +3,7 @@
namespace
WSS\API
;
use
ApiUsageException
;
use
MediaWiki\MediaWikiServices
;
use
MWException
;
use
User
;
use
WSS\NamespaceRepository
;
use
WSS\Space
;
use
WSS\Validation\AddSpaceValidationCallback
;
...
...
@@ -74,40 +72,40 @@ class ApiEditSpace extends ApiBase {
$ns_id
=
isset
(
$request_params
[
"nsid"
]
)
?
$request_params
[
"nsid"
]
:
false
;
if
(
$ns_id
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsid"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsid"
)
);
}
$ns_key
=
isset
(
$request_params
[
"nskey"
]
)
?
$request_params
[
"nskey"
]
:
false
;
if
(
$ns_key
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nskey"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nskey"
)
);
}
$ns_name
=
isset
(
$request_params
[
"nsname"
]
)
?
$request_params
[
"nsname"
]
:
false
;
if
(
$ns_name
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsname"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsname"
)
);
}
$ns_description
=
isset
(
$request_params
[
"nsdescription"
]
)
?
$request_params
[
"nsdescription"
]
:
false
;
if
(
$ns_description
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsdescription"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsdescription"
)
);
}
$ns_admins
=
isset
(
$request_params
[
"nsadmins"
]
)
?
$request_params
[
"nsadmins"
]
:
false
;
if
(
$ns_admins
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsadmins"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsadmins"
)
);
}
$space
=
Space
::
newFromConstant
(
$ns_id
);
if
(
!
$space
instanceof
Space
)
{
$this
->
dieWithError
(
wfMessage
(
$this
->
msg
(
"wss-api-invalid-param-detailed-nsid"
,
wfMessage
(
"wss-api-space-does-not-exist"
,
$request_params
[
"nsid"
]
)
->
parse
()
$this
->
msg
(
"wss-api-space-does-not-exist"
,
$request_params
[
"nsid"
]
)
->
parse
()
)
);
}
...
...
@@ -127,17 +125,17 @@ class ApiEditSpace extends ApiBase {
// Validate "nskey"
if
(
$add_space_validation_callback
->
validateField
(
"namespace"
,
$ns_key
,
$request_data
)
!==
true
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-invalid-param-nskey"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-invalid-param-nskey"
)
);
}
// Validate "nsname"
if
(
$add_space_validation_callback
->
validateField
(
"namespace_name"
,
$ns_name
,
$request_data
)
!==
true
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-invalid-param-nsname"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-invalid-param-nsname"
)
);
}
// Validate "nsdescription"
if
(
$add_space_validation_callback
->
validateRequired
(
$ns_description
)
!==
true
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-invalid-param-nsdescription"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-invalid-param-nsdescription"
)
);
}
}
...
...
src/API/ApiQuerySpaceAdmins.php
View file @
12d9ec49
<?php
namespace
WSS\API
;
use
MediaWiki\MediaWikiServices
;
use
User
;
use
WSS\NamespaceRepository
;
...
...
@@ -12,24 +11,16 @@ class ApiQuerySpaceAdmins extends \ApiQueryBase {
* @throws \ApiUsageException
*/
public
function
execute
()
{
$this
->
checkUserRightsAny
(
'wss-view-space-admins'
);
$this
->
checkUserRightsAny
(
'wss-view-space-admins'
);
$request_params
=
$this
->
extractRequestParams
();
$request_params
=
$this
->
extractRequestParams
();
$space_id
=
isset
(
$request_params
[
"namespace"
]
)
?
$request_params
[
"namespace"
]
:
false
;
if
(
$space_id
===
false
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-namespace"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-namespace"
)
);
}
// $user = \RequestContext::getMain()->getUser();
// $group_manager = MediaWikiServices::getInstance()->getUserGroupManager();
// $user_groups = $group_manager->getUserGroups( $user );
// if ( !in_array( $space_id . "Admin", $user_groups ) && !in_array( "sysop", $user_groups ) ) {
// $this->dieWithError( wfMessage( "wss-permission-denied-spaceadmins" ) );
// }
$namespace_repository
=
new
NamespaceRepository
();
// Get all admin ids for a namespace
...
...
src/API/ApiUnarchiveSpace.php
View file @
12d9ec49
...
...
@@ -35,16 +35,16 @@ class ApiUnarchiveSpace extends ApiBase {
$request_params
=
$this
->
extractRequestParams
();
if
(
!
isset
(
$request_params
[
"nsid"
]
)
)
{
$this
->
dieWithError
(
wfMessage
(
"wss-api-missing-param-nsid"
)
);
$this
->
dieWithError
(
$this
->
msg
(
"wss-api-missing-param-nsid"
)
);
}
$space
=
Space
::
newFromConstant
(
$request_params
[
"nsid"
]
);
if
(
!
$space
instanceof
Space
)
{
$this
->
dieWithError
(
wfMessage
(
$this
->
msg
(
"wss-api-invalid-param-detailed-nsid"
,
wfMessage
(
"wss-api-space-does-not-exist"
,
$request_params
[
"nsid"
]
)
->
parse
()
$this
->
msg
(
"wss-api-space-does-not-exist"
,
$request_params
[
"nsid"
]
)
->
parse
()
)
->
parse
()
);
}
...
...
src/ArchivedSpacePager.php
View file @
12d9ec49
...
...
@@ -90,6 +90,9 @@ class ArchivedSpacePager extends Pager {
return
'namespace_id'
;
}
/**
* @inheritDoc
*/
public
function
getDefaultDirections
()
{
return
parent
::
DIR_DESCENDING
;
}
...
...
src/Form/AbstractForm.php
View file @
12d9ec49
...
...
@@ -36,7 +36,11 @@ abstract class AbstractForm {
* @param SubmitCallback $submit_callback
* @param AbstractValidationCallback|null $validation_callback
*/
public
function
__construct
(
OutputPage
$page
,
SubmitCallback
$submit_callback
,
AbstractValidationCallback
$validation_callback
=
null
)
{
public
function
__construct
(
OutputPage
$page
,
SubmitCallback
$submit_callback
,
AbstractValidationCallback
$validation_callback
=
null
)
{
$this
->
page
=
$page
;
$this
->
setSubmitCallback
(
$submit_callback
);
...
...
src/Form/EditSpaceForm.php
View file @
12d9ec49
...
...
@@ -13,6 +13,14 @@ class EditSpaceForm extends AbstractForm {
*/
private
$space
;
/**
* EditSpaceForm constructor.
*
* @param Space $space
* @param OutputPage $page
* @param SubmitCallback $submit_callback
* @param AbstractValidationCallback|null $validation_callback
*/
public
function
__construct
(
Space
$space
,
OutputPage
$page
,
...
...
src/Form/UnarchiveSpaceForm.php
View file @
12d9ec49
...
...
@@ -13,6 +13,14 @@ class UnarchiveSpaceForm extends AbstractForm {
*/
private
$space
;
/**
* UnarchiveSpaceForm constructor.
*
* @param Space $space
* @param OutputPage $page
* @param SubmitCallback $submit_callback
* @param AbstractValidationCallback|null $validation_callback
*/
public
function
__construct
(
Space
$space
,
OutputPage
$page
,
...
...
src/Log/Log.php
View file @
12d9ec49
...
...
@@ -9,6 +9,7 @@ use Title;
use
User
;
abstract
class
Log
{
// phpcs:ignore
const
LOG_TYPE
=
'space'
;
/**
...
...
@@ -57,7 +58,6 @@ abstract class Log {
* Logger constructor.
*
* @param Title $title
* @param string $type
* @param string $subtype
*/
public
function
__construct
(
Title
$title
,
string
$subtype
)
{
...
...
src/Log/UpdateSpaceLog.php
View file @
12d9ec49
...
...
@@ -30,7 +30,9 @@ class UpdateSpaceLog extends Log {
$old_admins_comment
=
$old_admins
===
[]
?
"(none)"
:
implode
(
", "
,
$old_admins
);
$new_admins_comment
=
$new_admins
===
[]
?
"(none)"
:
implode
(
", "
,
$new_admins
);
$this
->
setComment
(
wfMessage
(
'wss-update-log-changed-admins'
,
$old_admins_comment
,
$new_admins_comment
)
->
plain
()
);
$this
->
setComment
(
wfMessage
(
'wss-update-log-changed-admins'
,
$old_admins_comment
,
$new_admins_comment
)
->
plain
()
);
}
$this
->
space
=
$new_space
;
...
...
src/NamespaceRepository.php
View file @
12d9ec49
...
...
@@ -18,6 +18,7 @@ use WSS\Log\UpdateSpaceLog;
class
NamespaceRepository
{
// Lowest allowed ID for a space.
// phpcs:ignore
const
MIN_SPACE_ID
=
50000
;
/**
...
...
@@ -42,6 +43,8 @@ class NamespaceRepository {
/**
* Returns the next available namespace id.
*
* @return int
*/
public
static
function
getNextAvailableNamespaceId
():
int
{
$dbr
=
wfGetDB
(
DB_MASTER
);
...
...
@@ -196,7 +199,9 @@ class NamespaceRepository {
*/
public
function
addSpace
(
Space
$space
):
int
{
if
(
$space
->
exists
()
)
{
throw
new
\
InvalidArgumentException
(
"Cannot add existing space to database, use NamespaceRepository::updateSpace() instead."
);
throw
new
\
InvalidArgumentException
(
"Cannot add existing space to database, use NamespaceRepository::updateSpace() instead."
);
}
// We publish the log first, since we ...?
...
...
@@ -226,11 +231,11 @@ class NamespaceRepository {
[
$space
]
);
// Set the admins. Do this after running the WSSpacesAfterCreateSpace hook!
$space
->
setSpaceAdministrators
(
[
$space
->
getOwner
()
->
getName
()
]
);
$this
->
updateSpaceAdministrators
(
$database
,
$space
);
// Set the admins. Do this after running the WSSpacesAfterCreateSpace hook!
$space
->
setSpaceAdministrators
(
[
$space
->
getOwner
()
->
getName
()
]
);
$this
->
updateSpaceAdministrators
(
$database
,
$space
);
$log
->
publish
();
$log
->
publish
();
return
$namespace_id
;
}
...
...
@@ -248,7 +253,9 @@ class NamespaceRepository {
*/
public
function
updateSpace
(
$old_space
,
Space
$new_space
,
bool
$force
=
false
,
bool
$log
=
true
)
{
if
(
$old_space
===
false
||
!
$old_space
->
exists
()
)
{
throw
new
\
InvalidArgumentException
(
"Cannot update non-existing space in database, use NamespaceRepository::addSpace() instead."
);
throw
new
\
InvalidArgumentException
(
"Cannot update non-existing space in database, use NamespaceRepository::addSpace() instead."
);
}
// Last minute check to see if the user actually does have enough permissions to edit this space.
...
...
@@ -493,7 +500,7 @@ class NamespaceRepository {
/**
* @param array $administrators
* @param $namespace_id
* @param
int
$namespace_id
* @return array
*/
private
function
createRowsFromSpaceAdministrators
(
array
$administrators
,
$namespace_id
)
{
...
...
src/Pager.php
View file @
12d9ec49
...
...
@@ -2,8 +2,6 @@
namespace
WSS
;
use
Wikimedia\Rdbms\ResultWrapper
;
/**
* Class WSSPager
*
...
...
src/Space.php
View file @
12d9ec49
...
...
@@ -7,6 +7,7 @@ use RequestContext;
use
User
;
class
Space
{
// phpcs:ignore
const
DEFAULT_NAMESPACE_CONSTANT
=
0
;
/**
...
...
@@ -70,7 +71,9 @@ class Space {
array
$namespace_administrators
=
[]
)
{
if
(
$namespace_id
%
2
!==
0
)
{
throw
new
\
InvalidArgumentException
(
"Namespace ID must be an even number; '
$namespace_id
' is not even'"
);
throw
new
\
InvalidArgumentException
(
"Namespace ID must be an even number; '
$namespace_id
' is not even'"
);
}
if
(
empty
(
$namespace_key
)
)
{
...
...
@@ -78,7 +81,10 @@ class Space {
}
if
(
!
ctype_alnum
(
$namespace_key
)
)
{
throw
new
\
InvalidArgumentException
(
"A namespace name can only consist of alphanumerical characters, therefore
$namespace_key
is invalid."
);
throw
new
\
InvalidArgumentException
(
"A namespace name can only consist of alphanumerical characters, "
.
"therefore
$namespace_key
is invalid."
);
}
$this
->
namespace_id
=
$namespace_id
;
...
...
src/SpacePager.php
View file @
12d9ec49
...
...
@@ -98,6 +98,9 @@ class SpacePager extends Pager {
return
'created_on'
;
}
/**
* @inheritDoc
*/
public
function
getDefaultDirections
()
{
return
parent
::
DIR_DESCENDING
;
}
...
...
src/Special/SpecialActiveSpaces.php
View file @
12d9ec49
...
...
@@ -53,7 +53,7 @@ class SpecialActiveSpaces extends SpecialPage {
* @inheritDoc
*/
public
function
getDescription
()
{
return
wfMessage
(
'wss-active-spaces-header'
)
->
plain
();
return
$this
->
msg
(
'wss-active-spaces-header'
)
->
plain
();
}
/**
...
...
@@ -67,11 +67,11 @@ class SpecialActiveSpaces extends SpecialPage {
* The main method that gets invoked upon successfully loading the special page, after preExecuteChecks have
* been performed.
*
* @param $parameter
* @param
string
$parameter
* @return void
* @throws \MWException
*/
function
doExecute
(
string
$parameter
)
{
public
function
doExecute
(
string
$parameter
)
{
$output
=
$this
->
getOutput
();
$renderer
=
$this
->
getLinkRenderer
();
...
...
src/Special/SpecialAddSpace.php
View file @
12d9ec49
...
...
@@ -15,8 +15,6 @@ use WSS\UI\InvalidPageUI;
class
SpecialAddSpace
extends
SpecialPage
{
/**
* SpecialPermissions constructor.
*
* @throws \UserNotLoggedIn
*/
public
function
__construct
()
{
parent
::
__construct
(
self
::
getName
(),
self
::
getRestriction
(),
true
);
...
...
@@ -47,7 +45,7 @@ class SpecialAddSpace extends SpecialPage {
* @inheritDoc
*/
public
function
getDescription
()
{
return
wfMessage
(
'wss-add-space-header'
)
->
plain
();
return
$this
->
msg
(
'wss-add-space-header'
)
->
plain
();
}
/**
...
...
src/Special/SpecialArchivedSpaces.php
View file @
12d9ec49
...
...
@@ -53,7 +53,7 @@ class SpecialArchivedSpaces extends SpecialPage {
* @inheritDoc
*/
public
function
getDescription
()
{
return
wfMessage
(
'wss-archived-spaces-header'
)
->
plain
();
return
$this
->
msg
(
'wss-archived-spaces-header'
)
->
plain
();
}
/**
...
...
src/SpecialPage.php
View file @
12d9ec49
...
...
@@ -57,8 +57,8 @@ abstract class SpecialPage extends \SpecialPage {
* The main method that gets invoked upon successfully loading the special page, after preExecuteChecks have
* been performed.
*
* @param $parameter
* @param
string
$parameter
* @return void
*/
abstract
function
doExecute
(
string
$parameter
);
abstract
public
function
doExecute
(
string
$parameter
);
}
src/SubmitCallback/AddSpaceSubmitCallback.php
View file @
12d9ec49
...
...
@@ -48,7 +48,12 @@ class AddSpaceSubmitCallback implements SubmitCallback {
$namespace_key
=
$form_data
[
'namespace'
];
$namespace_name
=
$form_data
[
'namespace_name'
];
$space
=
Space
::
newFromValues
(
$namespace_key
,
$namespace_name
,
$description
,
\
RequestContext
::
getMain
()
->
getUser
()
);
$space
=
Space
::
newFromValues
(
$namespace_key
,
$namespace_name
,
$description
,
\
RequestContext
::
getMain
()
->
getUser
()
);
$namespace_repository
=
new
NamespaceRepository
();
$namespace_repository
->
addSpace
(
$space
);
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment