summaryrefslogtreecommitdiff
path: root/extensions/TitleBlacklist/TitleBlacklist.hooks.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /extensions/TitleBlacklist/TitleBlacklist.hooks.php
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'extensions/TitleBlacklist/TitleBlacklist.hooks.php')
-rw-r--r--extensions/TitleBlacklist/TitleBlacklist.hooks.php108
1 files changed, 79 insertions, 29 deletions
diff --git a/extensions/TitleBlacklist/TitleBlacklist.hooks.php b/extensions/TitleBlacklist/TitleBlacklist.hooks.php
index 78379a3d..34be8eb7 100644
--- a/extensions/TitleBlacklist/TitleBlacklist.hooks.php
+++ b/extensions/TitleBlacklist/TitleBlacklist.hooks.php
@@ -32,7 +32,12 @@ class TitleBlacklistHooks {
if ( $action == 'create' || $action == 'edit' || $action == 'upload' ) {
$blacklisted = TitleBlacklist::singleton()->userCannot( $title, $user, $action );
if ( $blacklisted instanceof TitleBlacklistEntry ) {
- $result = array( $blacklisted->getErrorMessage( 'edit' ),
+ $errmsg = $blacklisted->getErrorMessage( 'edit' );
+ ApiBase::$messageMap[$errmsg] = array(
+ 'code' => $errmsg,
+ 'info' => 'TitleBlacklist prevents this title from being created'
+ );
+ $result = array( $errmsg,
htmlspecialchars( $blacklisted->getRaw() ),
$title->getFullText() );
return false;
@@ -68,31 +73,64 @@ class TitleBlacklistHooks {
}
/**
- * AbortMove hook
+ * MovePageCheckPermissions hook (1.25+)
*
- * @param $old Title
- * @param $nt Title
- * @param $user User
- * @param $err
+ * @param Title $oldTitle
+ * @param Title $newTitle
+ * @param User $user
+ * @param $reason
+ * @param Status $status
* @return bool
*/
- public static function abortMove( $old, $nt, $user, &$err ) {
+ public static function onMovePageCheckPermissions( Title $oldTitle, Title $newTitle, User $user, $reason, Status $status ) {
$titleBlacklist = TitleBlacklist::singleton();
- $blacklisted = $titleBlacklist->userCannot( $nt, $user, 'move' );
+ $blacklisted = $titleBlacklist->userCannot( $newTitle, $user, 'move' );
if ( !$blacklisted ) {
- $blacklisted = $titleBlacklist->userCannot( $old, $user, 'edit' );
+ $blacklisted = $titleBlacklist->userCannot( $oldTitle, $user, 'edit' );
}
if ( $blacklisted instanceof TitleBlacklistEntry ) {
- $err = wfMessage( $blacklisted->getErrorMessage( 'move' ),
+ $errmsg = $blacklisted->getErrorMessage( 'move' );
+ ApiBase::$messageMap[$errmsg] = array(
+ 'code' => $errmsg,
+ 'info' => 'TitleBlacklist prevents this new title from being created or old title from being edited'
+ );
+ $status->fatal( $errmsg,
$blacklisted->getRaw(),
- $old->getFullText(),
- $nt->getFullText() )->parse();
+ $oldTitle->getFullText(),
+ $newTitle->getFullText() );
return false;
}
+
return true;
}
/**
+ * AbortMove hook (<1.24)
+ *
+ * @todo: Remove once 1.24 support is dropped
+ *
+ * @param $old Title
+ * @param $nt Title
+ * @param $user User
+ * @param $err
+ * @return bool
+ */
+ public static function abortMove( $old, $nt, $user, &$err, $reason ) {
+ if ( method_exists( 'MovePage', 'checkPermissions' ) ) {
+ // Don't use this hook, use MovePageCheckPermissions instead
+ return true;
+ }
+
+ $status = new Status();
+ self::onMovePageCheckPermissions( $old, $nt, $user, $reason, $status );
+ if ( !$status->isOK() ) {
+ $err = $status->getHTML();
+ }
+
+ return $status->isOK();
+ }
+
+ /**
* Check whether a user name is acceptable,
* and set a message if unacceptable.
*
@@ -107,6 +145,10 @@ class TitleBlacklistHooks {
'new-account', $override );
if ( $blacklisted instanceof TitleBlacklistEntry ) {
$message = $blacklisted->getErrorMessage( 'new-account' );
+ ApiBase::$messageMap[$message] = array(
+ 'code' => $message,
+ 'info' => 'TitleBlacklist prevents this username from being created'
+ );
$err = wfMessage( $message, $blacklisted->getRaw(), $userName )->parse();
if ( $log ) {
self::logFilterHitUsername( $wgUser, $title, $blacklisted->getRaw() );
@@ -155,23 +197,6 @@ class TitleBlacklistHooks {
Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
// $error will be displayed by the edit class
- return true;
- } elseif ( !$section ) {
- # Block redirects to nonexistent blacklisted titles
- $retitle = Title::newFromRedirect( $text );
- if ( $retitle !== null && !$retitle->exists() ) {
- $blacklisted = TitleBlacklist::singleton()->userCannot( $retitle, $wgUser, 'create' );
- if ( $blacklisted instanceof TitleBlacklistEntry ) {
- $error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
- wfMessage( 'titleblacklist-forbidden-edit',
- $blacklisted->getRaw(),
- $retitle->getFullText() )->escaped() .
- Html::closeElement( 'div' ) . "\n" .
- Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
- }
- }
-
- return true;
}
return true;
}
@@ -224,4 +249,29 @@ class TitleBlacklistHooks {
$logEntry->publish( $logid );
}
}
+
+ /**
+ * Add phpunit tests
+ *
+ * @param array &$files List of test cases and directories to search
+ * @return bool
+ */
+ public static function unitTestsList( &$files ) {
+ $files = array_merge( $files, glob( __DIR__ . '/tests/*Test.php' ) );
+ return true;
+ }
+
+ /**
+ * External Lua library for Scribunto
+ *
+ * @param string $engine
+ * @param array $extraLibraries
+ * @return bool
+ */
+ public static function scribuntoExternalLibraries( $engine, array &$extraLibraries ) {
+ if( $engine == 'lua' ) {
+ $extraLibraries['mw.ext.TitleBlacklist'] = 'Scribunto_LuaTitleBlacklistLibrary';
+ }
+ return true;
+ }
}