summaryrefslogtreecommitdiff
path: root/bin/wiki/vendor/addwiki/mediawiki-api/src/Service/PageProtector.php
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/vendor/addwiki/mediawiki-api/src/Service/PageProtector.php')
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/src/Service/PageProtector.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/src/Service/PageProtector.php b/bin/wiki/vendor/addwiki/mediawiki-api/src/Service/PageProtector.php
new file mode 100644
index 00000000..e3988e84
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/src/Service/PageProtector.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Mediawiki\Api\Service;
+
+use InvalidArgumentException;
+use Mediawiki\Api\SimpleRequest;
+use Mediawiki\DataModel\Page;
+
+/**
+ * @access private
+ *
+ * @author Addshore
+ */
+class PageProtector extends Service {
+
+ /**
+ * @since 0.3
+ *
+ * @param Page $page
+ * @param string[] $protections where the 'key' is the action and the 'value' is the group
+ * @param array $extraParams
+ *
+ * @return bool
+ * @throws InvalidArgumentException
+ */
+ public function protect( Page $page, $protections, array $extraParams = [] ) {
+ if ( !is_array( $protections ) || empty( $protections ) ) {
+ throw new InvalidArgumentException(
+ '$protections must be an array with keys and values'
+ );
+ }
+
+ $params = [
+ 'pageid' => $page->getId(),
+ 'token' => $this->api->getToken( 'protect' ),
+ ];
+ $protectionsString = '';
+ foreach ( $protections as $action => $value ) {
+ if ( !is_string( $action ) || !is_string( $value ) ) {
+ throw new InvalidArgumentException(
+ 'All keys and elements of $protections must be strings'
+ );
+ }
+ $protectionsString = $action . '=' . $value . '|';
+ }
+ $params['protections'] = rtrim( $protectionsString, '|' );
+
+ $this->api->postRequest(
+ new SimpleRequest( 'protect', array_merge( $extraParams, $params ) )
+ );
+
+ return true;
+ }
+
+}