summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/BlockBatch
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/BlockBatch
first commit
Diffstat (limited to 'www/wiki/extensions/BlockBatch')
-rw-r--r--www/wiki/extensions/BlockBatch/BlockBatch.i18n.php41
-rw-r--r--www/wiki/extensions/BlockBatch/BlockBatch.php36
-rw-r--r--www/wiki/extensions/BlockBatch/LICENSE339
-rw-r--r--www/wiki/extensions/BlockBatch/README.md4
-rw-r--r--www/wiki/extensions/BlockBatch/SpecialBlockBatch.php977
5 files changed, 1397 insertions, 0 deletions
diff --git a/www/wiki/extensions/BlockBatch/BlockBatch.i18n.php b/www/wiki/extensions/BlockBatch/BlockBatch.i18n.php
new file mode 100644
index 00000000..86323a44
--- /dev/null
+++ b/www/wiki/extensions/BlockBatch/BlockBatch.i18n.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Internationalisation for BlockBatch
+ *
+ * @file
+ * @ingroup Extensions
+ */
+$messages = array();
+
+/** English
+ * @author Leucosticte
+ */
+$messages[ 'en' ] = array(
+ 'blockbatch' => "Block batch of users", // Important! This is the string that appears on Special:SpecialPages
+ 'blockbatch-desc' => "[[Special:BlockBatch|Special page]] to block a batch of users",
+ 'blockbatch-iptext' => 'Use the form below to block write access from specific IP addresses or usernames.
+This should be done only to prevent vandalism, and in accordance with [[{{MediaWiki:Policy-url}}|policy]].
+Fill in a specific reason below (for example, citing particular pages that were vandalized).',
+ 'blockbatch-ipbsubmit' => 'Block these users'
+);
+
+/** German (Deutsch)
+* @author Kghbln
+*/
+$messages[ 'de' ] = array(
+ 'blockbatch' => "BlockBatch",
+ 'blockbatch-desc' => "Ergänzt eine [[Special:BlockBatch|Spezialseite]] zum gesammelten Sperren von Benutzern",
+ 'blockbatch-iptext' => 'Nutze das untenstehende Forumlar, um den Schreibzugriff bestimmter Benutzer oder IP-Adressen zu sperren.
+Dies sollte ausschließlich zur Verhinderung von Vandalismus und in Übereinstimmung mit der [[{{MediaWiki:Policy-url}}|Richtlinie diese Wikis]] erfolgen.
+Gib zudem einen Grund für die Sperrung an, bspw. den Hinweis auf die vadalisierten Inhalte.',
+ 'blockbatch-ipbsubmit' => 'Benutzer sperren'
+);
+
+/** German (formal address) (Deutsch (Sie-Form)‎)
+ * @author Kghbln
+ */
+$messages[ 'de-formal' ] = array(
+ 'blockbatch-iptext' => 'Nutzen Sie das untenstehende Forumlar, um den Schreibzugriff bestimmter Benutzer oder IP-Adressen zu sperren.
+Dies sollte ausschließlich zur Verhinderung von Vandalismus und in Übereinstimmung mit der [[{{MediaWiki:Policy-url}}|Richtlinie diese Wikis]] erfolgen.
+Geben Sie zudem einen Grund für die Sperrung an, bspw. den Hinweis auf die vadalisierten Inhalte.'
+ );
diff --git a/www/wiki/extensions/BlockBatch/BlockBatch.php b/www/wiki/extensions/BlockBatch/BlockBatch.php
new file mode 100644
index 00000000..5a63b6ec
--- /dev/null
+++ b/www/wiki/extensions/BlockBatch/BlockBatch.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * BlockBatch extension by Leucosticte
+ * URL: http://www.mediawiki.org/wiki/Extension:BlockBatch
+ *
+ * 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 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+/* Alert the user that this is not a valid entry point to MediaWiki if they try to access the
+special pages file directly.*/
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+ echo <<<EOT
+ To install the RPED extension, put the following line in LocalSettings.php:
+ require( "extensions/RPED/RPED.php" );
+EOT;
+ exit( 1 );
+}
+
+$wgExtensionCredits['specialpage'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'BlockBatch',
+ 'author' => 'Leucosticte',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:BlockBatch',
+ 'descriptionmsg' => 'blockbatch-desc',
+ 'version' => '1.0.1'
+);
+
+$wgAutoloadClasses[ 'SpecialBlockBatch' ] = __DIR__ . '/SpecialBlockBatch.php';
+$wgExtensionMessagesFiles[ 'BlockBatch' ] = __DIR__ . '/BlockBatch.i18n.php';
+$wgSpecialPages[ 'BlockBatch' ] = 'SpecialBlockBatch';
+$wgGroupPermissions['bureaucrat']['blockbatch'] = true; \ No newline at end of file
diff --git a/www/wiki/extensions/BlockBatch/LICENSE b/www/wiki/extensions/BlockBatch/LICENSE
new file mode 100644
index 00000000..22fbe5db
--- /dev/null
+++ b/www/wiki/extensions/BlockBatch/LICENSE
@@ -0,0 +1,339 @@
+GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ {description}
+ Copyright (C) {year} {fullname}
+
+ 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 2 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.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ {signature of Ty Coon}, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. \ No newline at end of file
diff --git a/www/wiki/extensions/BlockBatch/README.md b/www/wiki/extensions/BlockBatch/README.md
new file mode 100644
index 00000000..81074abe
--- /dev/null
+++ b/www/wiki/extensions/BlockBatch/README.md
@@ -0,0 +1,4 @@
+BlockBatch
+==========
+
+Block a batch of users in MediaWiki
diff --git a/www/wiki/extensions/BlockBatch/SpecialBlockBatch.php b/www/wiki/extensions/BlockBatch/SpecialBlockBatch.php
new file mode 100644
index 00000000..85edb729
--- /dev/null
+++ b/www/wiki/extensions/BlockBatch/SpecialBlockBatch.php
@@ -0,0 +1,977 @@
+<?php
+/**
+ * Implements Special:Block
+ *
+ * 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 2 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
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
+
+/**
+ * A special page that allows users with 'block' right to block users from
+ * editing pages and other actions
+ *
+ * @ingroup SpecialPage
+ */
+class SpecialBlockBatch extends FormSpecialPage {
+ /** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
+ * or as subpage (Special:Block/Foo) */
+ protected $target;
+
+ /// @var Block::TYPE_ constant
+ protected $type;
+
+ /// @var User|String the previous block target
+ protected $previousTarget;
+
+ /// @var Bool whether the previous submission of the form asked for HideUser
+ protected $requestedHideUser;
+
+ /// @var Bool
+ protected $alreadyBlocked;
+
+ /// @var Array
+ protected $preErrors = array();
+
+ public function __construct() {
+ parent::__construct( 'BlockBatch', 'blockbatch' );
+ }
+
+ /**
+ * Checks that the user can unblock themselves if they are trying to do so
+ *
+ * @param User $user
+ * @throws ErrorPageError
+ */
+ protected function checkExecutePermissions( User $user ) {
+ parent::checkExecutePermissions( $user );
+
+ # bug 15810: blocked admins should have limited access here
+ $status = self::checkUnblockSelf( $this->target, $user );
+ if ( $status !== true ) {
+ throw new ErrorPageError( 'badaccess', $status );
+ }
+ }
+
+ /**
+ * Handle some magic here
+ *
+ * @param $par String
+ */
+ protected function setParameter( $par ) {
+ # Extract variables from the request. Try not to get into a situation where we
+ # need to extract *every* variable from the form just for processing here, but
+ # there are legitimate uses for some variables
+ $request = $this->getRequest();
+ list( $this->target, $this->type ) = self::getTargetAndType( $par, $request );
+ if ( $this->target instanceof User ) {
+ # Set the 'relevant user' in the skin, so it displays links like Contributions,
+ # User logs, UserRights, etc.
+ $this->getSkin()->setRelevantUser( $this->target );
+ }
+
+ list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
+ $this->requestedHideUser = $request->getBool( 'wpHideUser' );
+ }
+
+ /**
+ * Customizes the HTMLForm a bit
+ *
+ * @param $form HTMLForm
+ */
+ protected function alterForm( HTMLForm $form ) {
+ $form->setWrapperLegendMsg( 'blockip-legend' );
+ $form->setHeaderText( '' );
+ $form->setSubmitCallback( array( __CLASS__, 'processUIForm' ) );
+
+ $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'blockbatch-ipbsubmit';
+ $form->setSubmitTextMsg( $msg );
+
+ # Don't need to do anything if the form has been posted
+ if ( !$this->getRequest()->wasPosted() && $this->preErrors ) {
+ $s = HTMLForm::formatErrors( $this->preErrors );
+ if ( $s ) {
+ $form->addHeaderText( Html::rawElement(
+ 'div',
+ array( 'class' => 'error' ),
+ $s
+ ) );
+ }
+ }
+ }
+
+ /**
+ * Get the HTMLForm descriptor array for the block form
+ * @return Array
+ */
+ protected function getFormFields() {
+ global $wgBlockAllowsUTEdit, $fooBar;
+ $fooBar = true;
+
+ $user = $this->getUser();
+
+ $suggestedDurations = self::getSuggestedDurations();
+
+ $a = array(
+ 'Target' => array(
+ 'type' => 'textarea',
+ 'label-message' => 'ipadressorusername',
+ 'tabindex' => '1',
+ 'rows' => '32',
+ 'id' => 'mw-bi-target',
+ 'size' => '45',
+ 'autofocus' => true,
+ 'required' => true,
+ 'validation-callback' => array( __CLASS__, 'validateTargetField' ),
+ ),
+ 'Expiry' => array(
+ 'type' => !count( $suggestedDurations ) ? 'text' : 'selectorother',
+ 'label-message' => 'ipbexpiry',
+ 'required' => true,
+ 'tabindex' => '2',
+ 'options' => $suggestedDurations,
+ 'other' => $this->msg( 'ipbother' )->text(),
+ 'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
+ ),
+ 'Reason' => array(
+ 'type' => 'selectandother',
+ 'label-message' => 'ipbreason',
+ 'options-message' => 'ipbreason-dropdown',
+ ),
+ 'CreateAccount' => array(
+ 'type' => 'check',
+ 'label-message' => 'ipbcreateaccount',
+ 'default' => true,
+ ),
+ );
+
+ if ( self::canBlockEmail( $user ) ) {
+ $a['DisableEmail'] = array(
+ 'type' => 'check',
+ 'label-message' => 'ipbemailban',
+ );
+ }
+
+ if ( $wgBlockAllowsUTEdit ) {
+ $a['DisableUTEdit'] = array(
+ 'type' => 'check',
+ 'label-message' => 'ipb-disableusertalk',
+ 'default' => false,
+ );
+ }
+
+ $a['AutoBlock'] = array(
+ 'type' => 'check',
+ 'label-message' => 'ipbenableautoblock',
+ 'default' => true,
+ );
+
+ # Allow some users to hide name from block log, blocklist and listusers
+ if ( $user->isAllowed( 'hideuser' ) ) {
+ $a['HideUser'] = array(
+ 'type' => 'check',
+ 'label-message' => 'ipbhidename',
+ 'cssclass' => 'mw-block-hideuser',
+ );
+ }
+
+ # Watchlist their user page? (Only if user is logged in)
+ if ( $user->isLoggedIn() ) {
+ $a['Watch'] = array(
+ 'type' => 'check',
+ 'label-message' => 'ipbwatchuser',
+ );
+ }
+
+ $a['HardBlock'] = array(
+ 'type' => 'check',
+ 'label-message' => 'ipb-hardblock',
+ 'default' => false,
+ );
+
+ # This is basically a copy of the Target field, but the user can't change it, so we
+ # can see if the warnings we maybe showed to the user before still apply
+ $a['PreviousTarget'] = array(
+ 'type' => 'hidden',
+ 'default' => false,
+ );
+
+ # We'll turn this into a checkbox if we need to
+ $a['Confirm'] = array(
+ 'type' => 'hidden',
+ 'default' => '',
+ 'label-message' => 'ipb-confirm',
+ );
+
+ $this->maybeAlterFormDefaults( $a );
+
+ // Allow extensions to add more fields
+ wfRunHooks( 'SpecialBlockModifyFormFields', array( $this, &$a ) );
+
+ return $a;
+ }
+
+ /**
+ * If the user has already been blocked with similar settings, load that block
+ * and change the defaults for the form fields to match the existing settings.
+ * @param array $fields HTMLForm descriptor array
+ * @return Bool whether fields were altered (that is, whether the target is
+ * already blocked)
+ */
+ protected function maybeAlterFormDefaults( &$fields ) {
+ # This will be overwritten by request data
+ $fields['Target']['default'] = (string)$this->target;
+
+ # This won't be
+ $fields['PreviousTarget']['default'] = (string)$this->target;
+
+ $block = Block::newFromTarget( $this->target );
+
+ if ( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
+ && ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock
+ || $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block
+ ) {
+ $fields['HardBlock']['default'] = $block->isHardblock();
+ $fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
+ $fields['AutoBlock']['default'] = $block->isAutoblocking();
+
+ if ( isset( $fields['DisableEmail'] ) ) {
+ $fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
+ }
+
+ if ( isset( $fields['HideUser'] ) ) {
+ $fields['HideUser']['default'] = $block->mHideName;
+ }
+
+ if ( isset( $fields['DisableUTEdit'] ) ) {
+ $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
+ }
+
+ // If the username was hidden (ipb_deleted == 1), don't show the reason
+ // unless this user also has rights to hideuser: Bug 35839
+ if ( !$block->mHideName || $this->getUser()->isAllowed( 'hideuser' ) ) {
+ $fields['Reason']['default'] = $block->mReason;
+ } else {
+ $fields['Reason']['default'] = '';
+ }
+
+ if ( $this->getRequest()->wasPosted() ) {
+ # Ok, so we got a POST submission asking us to reblock a user. So show the
+ # confirm checkbox; the user will only see it if they haven't previously
+ $fields['Confirm']['type'] = 'check';
+ } else {
+ # We got a target, but it wasn't a POST request, so the user must have gone
+ # to a link like [[Special:Block/User]]. We don't need to show the checkbox
+ # as long as they go ahead and block *that* user
+ $fields['Confirm']['default'] = 1;
+ }
+
+ if ( $block->mExpiry == 'infinity' ) {
+ $fields['Expiry']['default'] = 'infinite';
+ } else {
+ $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry );
+ }
+
+ $this->alreadyBlocked = true;
+ $this->preErrors[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
+ }
+
+ # We always need confirmation to do HideUser
+ if ( $this->requestedHideUser ) {
+ $fields['Confirm']['type'] = 'check';
+ unset( $fields['Confirm']['default'] );
+ $this->preErrors[] = array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
+ }
+
+ # Or if the user is trying to block themselves
+ if ( (string)$this->target === $this->getUser()->getName() ) {
+ $fields['Confirm']['type'] = 'check';
+ unset( $fields['Confirm']['default'] );
+ $this->preErrors[] = array( 'ipb-blockingself', 'ipb-confirmaction' );
+ }
+ }
+
+ /**
+ * Add header elements like block log entries, etc.
+ * @return String
+ */
+ protected function preText() {
+ $this->getOutput()->addModules( 'mediawiki.special.block' );
+
+ $text = $this->msg( 'blockbatch-iptext' )->parse();
+
+ $otherBlockMessages = array();
+ if ( $this->target !== null ) {
+ # Get other blocks, i.e. from GlobalBlocking or TorBlock extension
+ wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) );
+
+ if ( count( $otherBlockMessages ) ) {
+ $s = Html::rawElement(
+ 'h2',
+ array(),
+ $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
+ ) . "\n";
+
+ $list = '';
+
+ foreach ( $otherBlockMessages as $link ) {
+ $list .= Html::rawElement( 'li', array(), $link ) . "\n";
+ }
+
+ $s .= Html::rawElement(
+ 'ul',
+ array( 'class' => 'mw-blockip-alreadyblocked' ),
+ $list
+ ) . "\n";
+
+ $text .= $s;
+ }
+ }
+
+ return $text;
+ }
+
+ /**
+ * Add footer elements to the form
+ * @return string
+ */
+ protected function postText() {
+ $links = array();
+
+ # Link to the user's contributions, if applicable
+ if ( $this->target instanceof User ) {
+ $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
+ $links[] = Linker::link(
+ $contribsPage,
+ $this->msg( 'ipb-blocklist-contribs', $this->target->getName() )->escaped()
+ );
+ }
+
+ # Link to unblock the specified user, or to a blank unblock form
+ if ( $this->target instanceof User ) {
+ $message = $this->msg( 'ipb-unblock-addr', wfEscapeWikiText( $this->target->getName() ) )->parse();
+ $list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() );
+ } else {
+ $message = $this->msg( 'ipb-unblock' )->parse();
+ $list = SpecialPage::getTitleFor( 'Unblock' );
+ }
+ $links[] = Linker::linkKnown( $list, $message, array() );
+
+ # Link to the block list
+ $links[] = Linker::linkKnown(
+ SpecialPage::getTitleFor( 'BlockList' ),
+ $this->msg( 'ipb-blocklist' )->escaped()
+ );
+
+ $user = $this->getUser();
+
+ # Link to edit the block dropdown reasons, if applicable
+ if ( $user->isAllowed( 'editinterface' ) ) {
+ $links[] = Linker::link(
+ Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ),
+ $this->msg( 'ipb-edit-dropdown' )->escaped(),
+ array(),
+ array( 'action' => 'edit' )
+ );
+ }
+
+ $text = Html::rawElement(
+ 'p',
+ array( 'class' => 'mw-ipb-conveniencelinks' ),
+ $this->getLanguage()->pipeList( $links )
+ );
+
+ $userTitle = self::getTargetUserTitle( $this->target );
+ if ( $userTitle ) {
+ # Get relevant extracts from the block and suppression logs, if possible
+ $out = '';
+
+ LogEventsList::showLogExtract(
+ $out,
+ 'block',
+ $userTitle,
+ '',
+ array(
+ 'lim' => 10,
+ 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
+ 'showIfEmpty' => false
+ )
+ );
+ $text .= $out;
+
+ # Add suppression block entries if allowed
+ if ( $user->isAllowed( 'suppressionlog' ) ) {
+ LogEventsList::showLogExtract(
+ $out,
+ 'suppress',
+ $userTitle,
+ '',
+ array(
+ 'lim' => 10,
+ 'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
+ 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
+ 'showIfEmpty' => false
+ )
+ );
+
+ $text .= $out;
+ }
+ }
+
+ return $text;
+ }
+
+ /**
+ * Get a user page target for things like logs.
+ * This handles account and IP range targets.
+ * @param $target User|string
+ * @return Title|null
+ */
+ protected static function getTargetUserTitle( $target ) {
+ if ( $target instanceof User ) {
+ return $target->getUserPage();
+ } elseif ( IP::isIPAddress( $target ) ) {
+ return Title::makeTitleSafe( NS_USER, $target );
+ }
+
+ return null;
+ }
+
+ /**
+ * Determine the target of the block, and the type of target
+ * TODO: should be in Block.php?
+ * @param string $par subpage parameter passed to setup, or data value from
+ * the HTMLForm
+ * @param $request WebRequest optionally try and get data from a request too
+ * @return array( User|string|null, Block::TYPE_ constant|null )
+ */
+ public static function getTargetAndType( $par, WebRequest $request = null ) {
+ $i = 0;
+ $target = null;
+
+ while ( true ) {
+ switch ( $i++ ) {
+ case 0:
+ # The HTMLForm will check wpTarget first and only if it doesn't get
+ # a value use the default, which will be generated from the options
+ # below; so this has to have a higher precedence here than $par, or
+ # we could end up with different values in $this->target and the HTMLForm!
+ if ( $request instanceof WebRequest ) {
+ $target = $request->getText( 'wpTarget', null );
+ }
+ break;
+ case 1:
+ $target = $par;
+ break;
+ case 2:
+ if ( $request instanceof WebRequest ) {
+ $target = $request->getText( 'ip', null );
+ }
+ break;
+ case 3:
+ # B/C @since 1.18
+ if ( $request instanceof WebRequest ) {
+ $target = $request->getText( 'wpBlockAddress', null );
+ }
+ break;
+ case 4:
+ break 2;
+ }
+
+ list( $target, $type ) = Block::parseTarget( $target );
+
+ if ( $type !== null ) {
+ return array( $target, $type );
+ }
+ }
+
+ return array( null, null );
+ }
+
+ /**
+ * HTMLForm field validation-callback for Target field.
+ * @since 1.18
+ * @param $value String
+ * @param $alldata Array
+ * @param $form HTMLForm
+ * @return Message
+ */
+ public static function validateTargetField( $value, $alldata, $form ) {
+ foreach ( explode( "\n", $value ) as $thisValue ) {
+ $status = self::validateTarget( $thisValue, $form->getUser() );
+ if ( !$status->isOK() ) {
+ $errors = $status->getErrorsArray();
+
+ return call_user_func_array( array( $form, 'msg' ), $errors[0] );
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Validate a block target.
+ *
+ * @since 1.21
+ * @param string $value Block target to check
+ * @param User $user Performer of the block
+ * @return Status
+ */
+ public static function validateTarget( $value, User $user ) {
+ global $wgBlockCIDRLimit;
+
+ /** @var User $target */
+ list( $target, $type ) = self::getTargetAndType( $value );
+ $status = Status::newGood( $target );
+
+ if ( $type == Block::TYPE_USER ) {
+ if ( $target->isAnon() ) {
+ $status->fatal(
+ 'nosuchusershort',
+ wfEscapeWikiText( $target->getName() )
+ );
+ }
+
+ $unblockStatus = self::checkUnblockSelf( $target, $user );
+ if ( $unblockStatus !== true ) {
+ $status->fatal( 'badaccess', $unblockStatus );
+ }
+ } elseif ( $type == Block::TYPE_RANGE ) {
+ list( $ip, $range ) = explode( '/', $target, 2 );
+
+ if (
+ ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
+ ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
+ ) {
+ // Range block effectively disabled
+ $status->fatal( 'range_block_disabled' );
+ }
+
+ if (
+ ( IP::isIPv4( $ip ) && $range > 32 ) ||
+ ( IP::isIPv6( $ip ) && $range > 128 )
+ ) {
+ // Dodgy range
+ $status->fatal( 'ip_range_invalid' );
+ }
+
+ if ( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
+ $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
+ }
+
+ if ( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
+ $status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
+ }
+ } elseif ( $type == Block::TYPE_IP ) {
+ # All is well
+ } else {
+ $status->fatal( 'badipaddress' );
+ }
+
+ return $status;
+ }
+
+ /**
+ * Submit callback for an HTMLForm object, will simply pass
+ * @param $data array
+ * @param $form HTMLForm
+ * @return Bool|String
+ */
+ public static function processUIForm( array $data, HTMLForm $form ) {
+ return self::processForm( $data, $form->getContext() );
+ }
+
+ /**
+ * Given the form data, actually implement a block
+ * @param $data Array
+ * @param $context IContextSource
+ * @return Bool|String
+ */
+ public static function processForm( array $data, IContextSource $context ) {
+ global $wgBlockAllowsUTEdit, $wgHideUserContribLimit;
+ global $targetList;
+
+ $performer = $context->getUser();
+
+ // Handled by field validator callback
+ // self::validateTargetField( $data['Target'] );
+
+ # This might have been a hidden field or a checkbox, so interesting data
+ # can come from it
+ $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true );
+
+ foreach( explode( "\n", $data['Target'] ) as $thisTarget ) {
+ /** @var User $target */
+ list( $target, $type ) = self::getTargetAndType( $thisTarget );
+ if ( $type == Block::TYPE_USER ) {
+ $user = $target;
+ $target = $user->getName();
+ $userId = $user->getId();
+
+ # Give admins a heads-up before they go and block themselves. Much messier
+ # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
+ # permission anyway, although the code does allow for it.
+ # Note: Important to use $target instead of $data['Target']
+ # since both $data['PreviousTarget'] and $target are normalized
+ # but $data['target'] gets overriden by (non-normalized) request variable
+ # from previous request.
+ if ( $target === $performer->getName() &&
+ ( $data['PreviousTarget'] !== $target || !$data['Confirm'] )
+ ) {
+ return array( 'ipb-blockingself', 'ipb-confirmaction' );
+ }
+ } elseif ( $type == Block::TYPE_RANGE ) {
+ $userId = 0;
+ } elseif ( $type == Block::TYPE_IP ) {
+ $target = $target->getName();
+ $userId = 0;
+ } else {
+ # This should have been caught in the form field validation
+ return array( 'badipaddress' );
+ }
+
+ if ( ( strlen( $data['Expiry'] ) == 0 ) || ( strlen( $data['Expiry'] ) > 50 )
+ || !self::parseExpiryInput( $data['Expiry'] )
+ ) {
+ return array( 'ipb_expiry_invalid' );
+ }
+
+ if ( !isset( $data['DisableEmail'] ) ) {
+ $data['DisableEmail'] = false;
+ }
+
+ # If the user has done the form 'properly', they won't even have been given the
+ # option to suppress-block unless they have the 'hideuser' permission
+ if ( !isset( $data['HideUser'] ) ) {
+ $data['HideUser'] = false;
+ }
+
+ if ( $data['HideUser'] ) {
+ if ( !$performer->isAllowed( 'hideuser' ) ) {
+ # this codepath is unreachable except by a malicious user spoofing forms,
+ # or by race conditions (user has oversight and sysop, loads block form,
+ # and is de-oversighted before submission); so need to fail completely
+ # rather than just silently disable hiding
+ return array( 'badaccess-group0' );
+ }
+
+ # Recheck params here...
+ if ( $type != Block::TYPE_USER ) {
+ $data['HideUser'] = false; # IP users should not be hidden
+ } elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
+ # Bad expiry.
+ return array( 'ipb_expiry_temp' );
+ } elseif ( $wgHideUserContribLimit !== false
+ && $user->getEditCount() > $wgHideUserContribLimit
+ ) {
+ # Typically, the user should have a handful of edits.
+ # Disallow hiding users with many edits for performance.
+ return array( array( 'ipb_hide_invalid',
+ Message::numParam( $wgHideUserContribLimit ) ) );
+ } elseif ( !$data['Confirm'] ) {
+ return array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
+ }
+ }
+
+ # Create block object.
+ $block = new Block();
+ $block->setTarget( $target );
+ $block->setBlocker( $performer );
+ $block->mReason = $data['Reason'][0];
+ $block->mExpiry = self::parseExpiryInput( $data['Expiry'] );
+ $block->prevents( 'createaccount', $data['CreateAccount'] );
+ $block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
+ $block->prevents( 'sendemail', $data['DisableEmail'] );
+ $block->isHardblock( $data['HardBlock'] );
+ $block->isAutoblocking( $data['AutoBlock'] );
+ $block->mHideName = $data['HideUser'];
+
+ $reason = array( 'hookaborted' );
+ if ( !wfRunHooks( 'BlockIp', array( &$block, &$performer, &$reason ) ) ) {
+ return $reason;
+ }
+
+ # Try to insert block. Is there a conflicting block?
+ $status = $block->insert();
+ if ( !$status ) {
+ # Indicates whether the user is confirming the block and is aware of
+ # the conflict (did not change the block target in the meantime)
+ $blockNotConfirmed = !$data['Confirm'] || ( array_key_exists( 'PreviousTarget', $data )
+ && $data['PreviousTarget'] !== $target );
+
+ # Special case for API - bug 32434
+ $reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] );
+
+ # Show form unless the user is already aware of this...
+ if ( $blockNotConfirmed || $reblockNotAllowed ) {
+ return array( array( 'ipb_already_blocked', $block->getTarget() ) );
+ # Otherwise, try to update the block...
+ } else {
+ # This returns direct blocks before autoblocks/rangeblocks, since we should
+ # be sure the user is blocked by now it should work for our purposes
+ $currentBlock = Block::newFromTarget( $target );
+
+ if ( $block->equals( $currentBlock ) ) {
+ return array( array( 'ipb_already_blocked', $block->getTarget() ) );
+ }
+
+ # If the name was hidden and the blocking user cannot hide
+ # names, then don't allow any block changes...
+ if ( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) {
+ return array( 'cant-see-hidden-user' );
+ }
+
+ $currentBlock->delete();
+ $status = $block->insert();
+ $logaction = 'reblock';
+
+ # Unset _deleted fields if requested
+ if ( $currentBlock->mHideName && !$data['HideUser'] ) {
+ RevisionDeleteUser::unsuppressUserName( $target, $userId );
+ }
+
+ # If hiding/unhiding a name, this should go in the private logs
+ if ( (bool)$currentBlock->mHideName ) {
+ $data['HideUser'] = true;
+ }
+ }
+ } else {
+ $logaction = 'block';
+ }
+
+ wfRunHooks( 'BlockIpComplete', array( $block, $performer ) );
+
+ # Set *_deleted fields if requested
+ if ( $data['HideUser'] ) {
+ RevisionDeleteUser::suppressUserName( $target, $userId );
+ }
+
+ # Can't watch a rangeblock
+ if ( $type != Block::TYPE_RANGE && $data['Watch'] ) {
+ WatchAction::doWatch( Title::makeTitle( NS_USER, $target ), $performer, WatchedItem::IGNORE_USER_RIGHTS );
+ }
+
+ # Block constructor sanitizes certain block options on insert
+ $data['BlockEmail'] = $block->prevents( 'sendemail' );
+ $data['AutoBlock'] = $block->isAutoblocking();
+
+ # Prepare log parameters
+ $logParams = array();
+ $logParams[] = $data['Expiry'];
+ $logParams[] = self::blockLogFlags( $data, $type );
+
+ # Make log entry, if the name is hidden, put it in the oversight log
+ $log_type = $data['HideUser'] ? 'suppress' : 'block';
+ $log = new LogPage( $log_type );
+ $log_id = $log->addEntry(
+ $logaction,
+ Title::makeTitle( NS_USER, $target ),
+ $data['Reason'][0],
+ $logParams,
+ $performer
+ );
+ # Relate log ID to block IDs (bug 25763)
+ $blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
+ $log->addRelations( 'ipb_id', $blockIds, $log_id );
+
+ $targetList[] = $user->getName();
+
+ # Report to the user
+ }
+ return true;
+ }
+
+ /**
+ * Get an array of suggested block durations from MediaWiki:Ipboptions
+ * @todo FIXME: This uses a rather odd syntax for the options, should it be converted
+ * to the standard "**<duration>|<displayname>" format?
+ * @param $lang Language|null the language to get the durations in, or null to use
+ * the wiki's content language
+ * @return Array
+ */
+ public static function getSuggestedDurations( $lang = null ) {
+ $a = array();
+ $msg = $lang === null
+ ? wfMessage( 'ipboptions' )->inContentLanguage()->text()
+ : wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
+
+ if ( $msg == '-' ) {
+ return array();
+ }
+
+ foreach ( explode( ',', $msg ) as $option ) {
+ if ( strpos( $option, ':' ) === false ) {
+ $option = "$option:$option";
+ }
+
+ list( $show, $value ) = explode( ':', $option );
+ $a[htmlspecialchars( $show )] = htmlspecialchars( $value );
+ }
+
+ return $a;
+ }
+
+ /**
+ * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
+ * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
+ * @param string $expiry whatever was typed into the form
+ * @return String: timestamp or "infinity" string for the DB implementation
+ */
+ public static function parseExpiryInput( $expiry ) {
+ static $infinity;
+ if ( $infinity == null ) {
+ $infinity = wfGetDB( DB_SLAVE )->getInfinity();
+ }
+
+ if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
+ $expiry = $infinity;
+ } else {
+ $expiry = strtotime( $expiry );
+
+ if ( $expiry < 0 || $expiry === false ) {
+ return false;
+ }
+
+ $expiry = wfTimestamp( TS_MW, $expiry );
+ }
+
+ return $expiry;
+ }
+
+ /**
+ * Can we do an email block?
+ * @param $user User: the sysop wanting to make a block
+ * @return Boolean
+ */
+ public static function canBlockEmail( $user ) {
+ global $wgEnableUserEmail, $wgSysopEmailBans;
+
+ return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
+ }
+
+ /**
+ * bug 15810: blocked admins should not be able to block/unblock
+ * others, and probably shouldn't be able to unblock themselves
+ * either.
+ * @param $user User|Int|String
+ * @param $performer User user doing the request
+ * @return Bool|String true or error message key
+ */
+ public static function checkUnblockSelf( $user, User $performer ) {
+ if ( is_int( $user ) ) {
+ $user = User::newFromId( $user );
+ } elseif ( is_string( $user ) ) {
+ $user = User::newFromName( $user );
+ }
+
+ if ( $performer->isBlocked() ) {
+ if ( $user instanceof User && $user->getId() == $performer->getId() ) {
+ # User is trying to unblock themselves
+ if ( $performer->isAllowed( 'unblockself' ) ) {
+ return true;
+ # User blocked themselves and is now trying to reverse it
+ } elseif ( $performer->blockedBy() === $performer->getName() ) {
+ return true;
+ } else {
+ return 'ipbnounblockself';
+ }
+ } else {
+ # User is trying to block/unblock someone else
+ return 'ipbblocked';
+ }
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Return a comma-delimited list of "flags" to be passed to the log
+ * reader for this block, to provide more information in the logs
+ * @param array $data from HTMLForm data
+ * @param $type Block::TYPE_ constant (USER, RANGE, or IP)
+ * @return string
+ */
+ protected static function blockLogFlags( array $data, $type ) {
+ global $wgBlockAllowsUTEdit;
+ $flags = array();
+
+ # when blocking a user the option 'anononly' is not available/has no effect
+ # -> do not write this into log
+ if ( !$data['HardBlock'] && $type != Block::TYPE_USER ) {
+ // For grepping: message block-log-flags-anononly
+ $flags[] = 'anononly';
+ }
+
+ if ( $data['CreateAccount'] ) {
+ // For grepping: message block-log-flags-nocreate
+ $flags[] = 'nocreate';
+ }
+
+ # Same as anononly, this is not displayed when blocking an IP address
+ if ( !$data['AutoBlock'] && $type == Block::TYPE_USER ) {
+ // For grepping: message block-log-flags-noautoblock
+ $flags[] = 'noautoblock';
+ }
+
+ if ( $data['DisableEmail'] ) {
+ // For grepping: message block-log-flags-noemail
+ $flags[] = 'noemail';
+ }
+
+ if ( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ) {
+ // For grepping: message block-log-flags-nousertalk
+ $flags[] = 'nousertalk';
+ }
+
+ if ( $data['HideUser'] ) {
+ // For grepping: message block-log-flags-hiddenname
+ $flags[] = 'hiddenname';
+ }
+
+ return implode( ',', $flags );
+ }
+
+ /**
+ * Process the form on POST submission.
+ * @param $data Array
+ * @return Bool|Array true for success, false for didn't-try, array of errors on failure
+ */
+ public function onSubmit( array $data ) {
+ // This isn't used since we need that HTMLForm that's passed in the
+ // second parameter. See alterForm for the real function
+ }
+
+ /**
+ * Do something exciting on successful processing of the form, most likely to show a
+ * confirmation message
+ */
+ public function onSuccess() {
+ $out = $this->getOutput();
+ $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
+ global $targetList;
+ foreach ( $targetList as $thisTarget ) {
+ $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $thisTarget ) );
+ }
+ }
+
+ protected function getGroupName() {
+ return 'users';
+ }
+}
+
+# BC @since 1.18
+#class IPBlockForm extends SpecialBlock {
+#} \ No newline at end of file