jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/373563 )
Change subject: Convert AuthorProtect to use extension registration
..
Convert AuthorProtect to use extension registration
Bug: T174042
Change-Id: I27fec954e8a5c8ea46c8d040051be2288161bcd8
---
A AuthorProtect.hooks.php
M AuthorProtect.php
A AuthorProtectAction.php
A extension.json
M i18n/en.json
M i18n/qqq.json
6 files changed, 281 insertions(+), 261 deletions(-)
Approvals:
Skizzerz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/AuthorProtect.hooks.php b/AuthorProtect.hooks.php
new file mode 100644
index 000..22d3448
--- /dev/null
+++ b/AuthorProtect.hooks.php
@@ -0,0 +1,62 @@
+getTitle();
+
+ if ( self::UserIsAuthor( $user, $title ) ) {
+ $aRights[] = 'author';
+ $aRights = array_unique( $aRights );
+ }
+
+ return true;
+ }
+
+ public static function MakeContentAction( $skin, &$links ) {
+ $title = $skin->getTitle();
+ $user = $skin->getUser();
+ $request = $skin->getRequest();
+
+ if ( self::UserIsAuthor( $user, $title ) && $user->isAllowed(
'authorprotect' ) && !$user->isAllowed( 'protect' ) ) {
+ $action = $request->getText( 'action' );
+ $links['actions']['authorprotect'] = [
+ 'class' => $action == 'authorprotect' ?
'selected' : false,
+ 'text' => wfMessage(
self::AuthorProtectMessage( $title ) ),
+ 'href' => $title->getLocalUrl(
'action=authorprotect' ),
+ ];
+ }
+
+ return true;
+ }
+
+ public static function UserIsAuthor( $user, $title, $checkMaster =
false ) {
+ if ( !$title instanceOf Title ) {
+ return false; // quick hack to prevent the API from
messing up.
+ }
+
+ if ( $user->getID() === 0 ) {
+ return false; // don't allow anons, they shouldn't even
get this far but just in case...
+ }
+
+ $id = $title->getArticleID();
+ $dbr = wfGetDB( $checkMaster ? DB_MASTER : DB_SLAVE );
+ $aid = $dbr->selectField(
+ 'revision',
+ 'rev_user',
+ [ 'rev_page' => $id ],
+ __METHOD__,
+ [ 'ORDER BY' => 'rev_timestamp ASC' ]
+ );
+
+ return $user->getID() == $aid;
+ }
+
+ private static function AuthorProtectMessage( $title ) {
+ foreach ( $title->getRestrictionTypes() as $type ) {
+ if ( in_array( 'author', $title->getRestrictions( $type
) ) ) {
+ return 'unprotect';
+ }
+ }
+ return 'protect';
+ }
+}
diff --git a/AuthorProtect.php b/AuthorProtect.php
index cd4ac49..cbaafb7 100644
--- a/AuthorProtect.php
+++ b/AuthorProtect.php
@@ -4,261 +4,14 @@
* See http://www.mediawiki.org/wiki/Extension:AuthorProtect for more details
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- echo "This file is an extension to MediaWiki and cannot be run
externally\n";
- die( 1 );
-}
-
-$wgExtensionCredits['other'][] = array(
- 'path' => __FILE__,
- 'name' => 'Author Protect',
- 'author' => 'Ryan Schmidt',
- 'url' => 'https://www.mediawiki.org/wiki/Extension:AuthorProtect',
- 'version' => '1.4.0',
- 'descriptionmsg' => 'authorprotect-desc',
- 'license-name' => 'GPL-2.0+'
-);
-
-$wgAvailableRights[] = 'author'; // dynamically assigned to the author of a
page, but can be set w/ wgGroupPermissions too
-$wgAvailableRights[] = 'authorprotect'; // users without this right cannot
protect pages they author
-$wgMessagesDirs['AuthorProtect'] = __DIR__ . '/i18n';
-$wgGroupPermissions['sysop']['author'] = true; // sysops can edit every page
despite author protection
-$wgGroupPermissions['user']['authorprotect'] = true; // registered users can
protect pages they author
-$wgHooks['SkinTemplateNavigation::Universal'][] =
'AuthorProtect::MakeContentAction';
-$wgHooks['UnknownAction'][] = 'AuthorProtect::AuthorProtectForm';
-$wgHooks['userCan'][] = 'AuthorProtect::AuthorProtectDelay';
-$wgHooks['UserGetRights'][] = 'AuthorProtect::AssignAuthor';
-$wgRestrictionLevels[] = 'author'; // so sysops, etc. using the normal
protection interface can protect and unprotect it at the author level
-$wgAvailableRights[] = 'author';
-$wgAvailableRights[] = 'authorprotect';
-
-// internal variables, do not modify
-$wgAuthorProtectDoProtect = false;
-$wgAuthorProtectDelayRun = true;
-
-class AuthorProtect {
- /**
-* Extensions like ConfirmAc