Parent5446 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/52811
Change subject: Add permission for users deleting pages only they edited.
......................................................................
Add permission for users deleting pages only they edited.
Added the deleteown permission which, if granted, allows
users to delete pages they created but are younger than
a certain threshold and have not been edited by anybody
else (ignoring minor edits).
Bug: 45898
Change-Id: Iba479c246f94559e713f7a21936c50e49c826fbc
---
M includes/DefaultSettings.php
M includes/Title.php
2 files changed, 44 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/11/52811/1
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 8ca5fa9..9c440b5 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -4242,6 +4242,12 @@
$wgDeleteRevisionsLimit = 0;
/**
+ * Time limit for users with the deleteown permission deleting pages
+ * only they have edited. Default is ninety days.
+ */
+$wgDeleteOwnExpiry = 3600 * 24 * 90;
+
+/**
* Number of accounts each IP address may create, 0 to disable.
*
* @warning Requires memcached
diff --git a/includes/Title.php b/includes/Title.php
index 46b0524..330fb97 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1731,6 +1731,8 @@
* @return Array list of errors
*/
private function checkQuickPermissions( $action, $user, $errors,
$doExpensiveQueries, $short ) {
+ global $wgDeleteOwnExpiry;
+
if ( $action == 'create' ) {
if (
( $this->isTalkPage() && !$user->isAllowed(
'createtalk' ) ) ||
@@ -1769,6 +1771,24 @@
&& $this->mNamespace == NS_USER &&
!$this->isSubpage() ) {
// Show user page-specific message only if the
user can move other pages
$errors[] = array( 'cant-move-to-user-page' );
+ }
+ } elseif ( $action == 'delete' ) {
+ $options = array( 'include_both', 'ignore_minor' );
+ $first = $this->getFirstRevision();
+ $latestTime = new MWTimestamp(
Revision::getTimestampFromId( $this, $this->getLatestRevID() ) );
+ if (
+ // Check general delete permission
+ !$user->isAllowed( 'delete' ) &&
+ // Check if user is only author on page and can
deleteown
+ !$user->isAllowed( 'deleteown' ) &&
+ $first->getUser( Revision::RAW ) ===
$user->getId() &&
+ $latestTime->getTimestamp() <= time() +
$wgDeleteOwnExpiry
+ (
+ !$doExpensiveQueries ||
+ $this->countAuthorsBetween( $first, 0,
1, $options ) === 1
+ )
+ ) {
+ $errors[] = $this->missingPermissionError(
'deleteown', $short );
}
} elseif ( !$user->isAllowed( $action ) ) {
$errors[] = $this->missingPermissionError( $action,
$short );
@@ -4325,14 +4345,26 @@
}
return ( $old->getRawUserText() ===
$new->getRawUserText() ) ? 1 : 2;
}
+
+ $conds = array(
+ 'rev_page' => $this->getArticleID(),
+ "rev_timestamp $old_cmp " . $dbr->addQuotes(
$dbr->timestamp( $old->getTimestamp() ) ),
+ "rev_timestamp $new_cmp " . $dbr->addQuotes(
$dbr->timestamp( $new->getTimestamp() ) )
+ );
+ if ( in_array( 'ignore_minor', $options ) ) {
+ $conds['rev_minor_edit'] = 0;
+ }
+
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'revision', 'DISTINCT rev_user_text',
+ $res = $dbr->select(
+ 'revision',
+ 'rev_user_text',
+ $conds,
+ __METHOD__,
array(
- 'rev_page' => $this->getArticleID(),
- "rev_timestamp $old_cmp " . $dbr->addQuotes(
$dbr->timestamp( $old->getTimestamp() ) ),
- "rev_timestamp $new_cmp " . $dbr->addQuotes(
$dbr->timestamp( $new->getTimestamp() ) )
- ), __METHOD__,
- array( 'LIMIT' => $limit + 1 ) // add one so caller
knows it was truncated
+ 'DISTINCT',
+ 'LIMIT' => $limit + 1 // add one so caller
knows it was truncated
+ )
);
return (int)$dbr->numRows( $res );
}
--
To view, visit https://gerrit.wikimedia.org/r/52811
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba479c246f94559e713f7a21936c50e49c826fbc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Parent5446 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits