MGChecker has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/375535 )
Change subject: Convert DeleteOwn to extension.json ...................................................................... Convert DeleteOwn to extension.json Change-Id: Iccf8eacf185550adf76fc7138b1c076f6b829cb9 --- M DeleteOwn.php A DeleteOwn_body.php A extension.json M i18n/en.json M i18n/qqq.json 5 files changed, 187 insertions(+), 195 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DeleteOwn refs/changes/35/375535/1 diff --git a/DeleteOwn.php b/DeleteOwn.php index e13d63d..68d8ca0 100644 --- a/DeleteOwn.php +++ b/DeleteOwn.php @@ -1,197 +1,9 @@ <?php - -/** - * Implements Extension:DeleteOwn for the MediaWiki software. - * Copyright (C) 2014-2015 Tyler Romeo <tylerro...@gmail.com> - * - * 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 3 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 - * - * @ingroup Extensions - * @file - * - * @author Tyler Romeo (Parent5446) <tylerro...@gmail.com> - * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License 3.0 or later - */ - -// Ensure that the script cannot be executed outside of MediaWiki. -if ( !defined( 'MEDIAWIKI' ) ) { - die( 'This is an extension to MediaWiki and cannot be run standalone.' ); +if ( version_compare( $wgVersion, '1.29', '=>' ) ) { + wfLoadExtension( 'DeleteOwn' ); + // Keep i18n globals so mergeMessageFileList.php doesn't break + $wgMessagesDirs['DeleteOwn'] = __DIR__ . '/i18n'; + return; +} else { + die( 'This version of the DelelteOwn extension requires MediaWiki 1.29+' ); } - -// Display extension properties on MediaWiki. -$wgExtensionCredits['other'][] = array( - 'path' => __FILE__, - 'name' => 'DeleteOwn', - 'descriptionmsg' => 'deleteown-desc', - 'version' => '1.2.0', - 'author' => array( - 'Tyler Romeo', - '...' - ), - 'url' => 'https://www.mediawiki.org/wiki/Extension:DeleteOwn', - 'license-name' => 'GPL-3.0+' -); - -// Register extension messages and other localisation. -$wgMessagesDirs['DeleteOwn'] = __DIR__ . '/i18n'; - -/** - * The expiry for when a page can no longer be deleted by its author. - * - * Can be a single integer value, which is applied to all pages, - * or can be an array of namespaces mapped to individual expiry values. - * An expiry of 0 (or not specifying a namespace key) disables deletion - * and an expiry of INF disables the expiry. - */ -$wgDeleteOwnExpiry = INF; - -$wgAvailableRights[] = 'deleteown'; - -Hooks::register( 'TitleQuickPermissions', - /** - * Check if a user can delete a page they authored but has not - * been edited by anybody else and is younger than a threshold. - * - * @param Title $title Title being accessed - * @param User $user User performing the action - * @param string $action The action being performed - * @param array &$errors Permissions errors to be returned - * @param bool $doExpensiveQueries Whether to do expensive DB queries - * @return bool False (to stop permissions checks) if user is allowed to delete - */ - function( Title $title, User $user, $action, array &$errors, $doExpensiveQueries ) { - global $wgDeleteOwnExpiry; - - // If not on the delete action, or if the user can delete normally, return. - // Also, if the user doesn't have the deleteown permissions, none of this is applicable. - if ( $action !== 'delete' || $user->isAllowed( 'delete' ) || !$user->isAllowed( 'deleteown' ) ) { - return true; - } - - // Determine an expiry based on the namespace. - $ns = $title->getNamespace(); - if ( !is_array( $wgDeleteOwnExpiry ) ) { - // Non-array expiry, means apply this expiry to all namespaces. - $expiry = $wgDeleteOwnExpiry; - } elseif ( array_key_exists( $ns, $wgDeleteOwnExpiry ) ) { - // Namespace-specific expiry exists - $expiry = $wgDeleteOwnExpiry[$ns]; - } else { - // Couldn't find an expiry, so disable. - $expiry = INF; - } - - // First check if the user is the author. - $firstRevision = $title->getFirstRevision(); - if ( $firstRevision->getUser() !== $user->getId() ) { - return true; - } - - // Then check if the article is young enough to qualify for deleteown. - $creationTime = new MWTimestamp( $firstRevision->getTimestamp() ); - if ( $creationTime->getTimestamp() + $expiry < time() ) { - return true; - } - - // Bail out here if we're not doing expensive queries. - if ( !$doExpensiveQueries ) { - return false; - } - - $dbr = wfGetDB( DB_SLAVE ); - - // Only bother changing the expiry if different namespaces have different expiries. - if ( is_array( $wgDeleteOwnExpiry ) ) { - // Check if the page was ever moved to a different namespace. - $previousNs = $dbr->select( - 'logging', - 'log_namespace', - array( - 'log_type' => 'move', - 'log_page' => $title->getArticleId(), - $dbr->addIdentifierQuotes( 'log_namespace' ) . ' != ' . $dbr->addQuotes( $title->getNamespace() ) - ), - 'hook-DeleteOwn', - array( 'DISTINCT' ) - ); - - // If the page was moved, use the lowest expiry that isn't disabled. - // That way if a user moves a page, they will still be bound by the original limit. - foreach ( $previousNs as $row ) { - $ns = $row->log_namespace; - if ( isset( $wgDeleteOwnExpiry[$ns] ) && $wgDeleteOwnExpiry[$ns] < $expiry ) { - // More restrictive expiry. - $expiry = $wgDeleteOwnExpiry[$ns]; - } - } - - // Check the expiry again with its new value. - if ( $creationTime->getTimestamp() + $expiry < time() ) { - return true; - } - } - - // Check if anybody else other than bots have made - // non-minor edits to the page. - $botGroups = User::getGroupsWithPermission( 'bot' ); - if ( !$botGroups ) { - // No need to do complicated join if there are no bot groups. - $hasOtherAuthors = (bool)$dbr->selectField( - 'revision', - 'rev_user', - array( - 'rev_page' => $title->getArticleId(), - $dbr->addIdentifierQuotes( 'rev_user_text' ) . ' != ' . $dbr->addQuotes( $user->getName() ), - 'rev_minor_edit' => 0, - ), - 'hook-DeleteOwn' - ); - } else { - $hasOtherAuthors = (bool)$dbr->select( - array( 'revision', 'user_groups' ), - array( - 'rev_user', - 'COUNT(' . $dbr->addIdentifierQuotes( 'ug_group' ) . ')' - ), - array( - 'rev_page' => $title->getArticleId(), - $dbr->addIdentifierQuotes( 'rev_user_text' ) . ' != ' . $dbr->addQuotes( $user->getName() ), - 'rev_minor_edit' => 0, - ), - 'hook-DeleteOwn', - array( - 'LIMIT' => 1, - 'GROUP BY' => 'rev_user', - 'HAVING' => array( - 'COUNT(' . $dbr->addIdentifierQuotes( 'ug_group' ) . ')' => 0 - ) - ), - array( - 'user_groups' => array( 'LEFT JOIN', array( - $dbr->addIdentifierQuotes( 'ug_user' ) . '=' . $dbr->addIdentifierQuotes( 'rev_user' ), - 'ug_group' => User::getGroupsWithPermission( 'bot' ), - ) ) - ) - )->numRows(); - } - - if ( $hasOtherAuthors ) { - return true; - } - - return false; - } -); diff --git a/DeleteOwn_body.php b/DeleteOwn_body.php new file mode 100644 index 0000000..b845bf6 --- /dev/null +++ b/DeleteOwn_body.php @@ -0,0 +1,138 @@ +<?php +class DeleteOwn { + + /** + * Check if a user can delete a page they authored but has not + * been edited by anybody else and is younger than a threshold. + * + * @param Title $title Title being accessed + * @param User $user User performing the action + * @param string $action The action being performed + * @param array &$errors Permissions errors to be returned + * @param bool $doExpensiveQueries Whether to do expensive DB queries + * @return bool False (to stop permissions checks) if user is allowed to delete + */ + static function checkDeletePowersF( Title $title, User $user, $action, array &$errors, $doExpensiveQueries ) { + global $wgDeleteOwnExpiry; + + // If not on the delete action, or if the user can delete normally, return. + // Also, if the user doesn't have the deleteown permissions, none of this is applicable. + if ( $action !== 'delete' || $user->isAllowed( 'delete' ) || !$user->isAllowed( 'deleteown' ) ) { + return true; + } + + // Determine an expiry based on the namespace. + $ns = $title->getNamespace(); + if ( !is_array( $wgDeleteOwnExpiry ) ) { + // Non-array expiry, means apply this expiry to all namespaces. + $expiry = $wgDeleteOwnExpiry; + } elseif ( array_key_exists( $ns, $wgDeleteOwnExpiry ) ) { + // Namespace-specific expiry exists + $expiry = $wgDeleteOwnExpiry[$ns]; + } else { + // Couldn't find an expiry, so disable. + $expiry = INF; + } + + // First check if the user is the author. + $firstRevision = $title->getFirstRevision(); + if ( $firstRevision->getUser() !== $user->getId() ) { + return true; + } + + // Then check if the article is young enough to qualify for deleteown. + $creationTime = new MWTimestamp( $firstRevision->getTimestamp() ); + if ( $creationTime->getTimestamp() + $expiry < time() ) { + return true; + } + + // Bail out here if we're not doing expensive queries. + if ( !$doExpensiveQueries ) { + return false; + } + + $dbr = wfGetDB( DB_SLAVE ); + + // Only bother changing the expiry if different namespaces have different expiries. + if ( is_array( $wgDeleteOwnExpiry ) ) { + // Check if the page was ever moved to a different namespace. + $previousNs = $dbr->select( + 'logging', + 'log_namespace', + array( + 'log_type' => 'move', + 'log_page' => $title->getArticleId(), + $dbr->addIdentifierQuotes( 'log_namespace' ) . ' != ' . $dbr->addQuotes( $title->getNamespace() ) + ), + 'hook-DeleteOwn', + array( 'DISTINCT' ) + ); + + // If the page was moved, use the lowest expiry that isn't disabled. + // That way if a user moves a page, they will still be bound by the original limit. + foreach ( $previousNs as $row ) { + $ns = $row->log_namespace; + if ( isset( $wgDeleteOwnExpiry[$ns] ) && $wgDeleteOwnExpiry[$ns] < $expiry ) { + // More restrictive expiry. + $expiry = $wgDeleteOwnExpiry[$ns]; + } + } + + // Check the expiry again with its new value. + if ( $creationTime->getTimestamp() + $expiry < time() ) { + return true; + } + } + + // Check if anybody else other than bots have made + // non-minor edits to the page. + $botGroups = User::getGroupsWithPermission( 'bot' ); + if ( !$botGroups ) { + // No need to do complicated join if there are no bot groups. + $hasOtherAuthors = (bool)$dbr->selectField( + 'revision', + 'rev_user', + array( + 'rev_page' => $title->getArticleId(), + $dbr->addIdentifierQuotes( 'rev_user_text' ) . ' != ' . $dbr->addQuotes( $user->getName() ), + 'rev_minor_edit' => 0, + ), + 'hook-DeleteOwn' + ); + } else { + $hasOtherAuthors = (bool)$dbr->select( + array( 'revision', 'user_groups' ), + array( + 'rev_user', + 'COUNT(' . $dbr->addIdentifierQuotes( 'ug_group' ) . ')' + ), + array( + 'rev_page' => $title->getArticleId(), + $dbr->addIdentifierQuotes( 'rev_user_text' ) . ' != ' . $dbr->addQuotes( $user->getName() ), + 'rev_minor_edit' => 0, + ), + 'hook-DeleteOwn', + array( + 'LIMIT' => 1, + 'GROUP BY' => 'rev_user', + 'HAVING' => array( + 'COUNT(' . $dbr->addIdentifierQuotes( 'ug_group' ) . ')' => 0 + ) + ), + array( + 'user_groups' => array( 'LEFT JOIN', array( + $dbr->addIdentifierQuotes( 'ug_user' ) . '=' . $dbr->addIdentifierQuotes( 'rev_user' ), + 'ug_group' => User::getGroupsWithPermission( 'bot' ), + ) ) + ) + )->numRows(); + } + + if ( $hasOtherAuthors ) { + return true; + } + + return false; + } + +} \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..241d71d --- /dev/null +++ b/extension.json @@ -0,0 +1,40 @@ +{ + "name": "DeleteOwn", + "version": "1.3.0", + "author": [ + "Tyler Romeo", + "MGChecker" + "..." + ], + "url": "https://www.mediawiki.org/wiki/Extension:DeleteOwn", + "descriptionmsg": "deleteown-desc", + "license-name": "GPL-3.0+", + "type": "other", + "requires": { + "MediaWiki": ">= 1.29.0" + }, + "config": { + "DeleteOwnExpiry": { + "value": INF, + "path": false, + "descriptionmsg": "deleteown-config-deleteownexpiry", + "public": true + }, + "AvailableRights": [ + "deleteown" + ], + "Hooks": { + "TitleQuickPermissions": [ + "DeleteOwn::checkDeletePowers" + ] + }, + "MessagesDirs": { + "DeleteOwn": [ + "i18n" + ] + }, + "AutoloadClasses": { + "DeleteOwn": "DeleteOwn_body.php" + }, + "manifest_version": 2 +} \ No newline at end of file diff --git a/i18n/en.json b/i18n/en.json index dd883e9..2b59748 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,5 +5,6 @@ ] }, "deleteown-desc": "Allows users to delete young pages they authored", + "deleteown-config-deleteownexpiry: "The expiry for when a page can no longer be deleted by its author. (Can be a single integer value, which is applied to all pages, or can be an array of namespaces mapped to individual expiry values. An expiry of 0 (or not specifying a namespace key) disables deletion and an expiry of INF disables the expiry.)", "right-deleteown": "Delete own pages" } \ No newline at end of file diff --git a/i18n/qqq.json b/i18n/qqq.json index 831134a..b67528f 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -6,5 +6,6 @@ ] }, "deleteown-desc": "{{desc|name=Delete Own|url=https://www.mediawiki.org/wiki/Extension:DeleteOwn}}", + "deleteown-config-deleteownexpiry: "configuration setting description of $wgDeleteOwnExpiry", "right-deleteown": "{{doc-right|deleteown}}" } -- To view, visit https://gerrit.wikimedia.org/r/375535 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iccf8eacf185550adf76fc7138b1c076f6b829cb9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DeleteOwn Gerrit-Branch: master Gerrit-Owner: MGChecker <hgasu...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits