2007-12-08 21:06:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Hooks for Title Blacklist
|
|
|
|
* @author VasilievVV
|
2007-12-31 10:03:10 +00:00
|
|
|
* @copyright © 2007 VasilievVV
|
2007-12-29 04:23:57 +00:00
|
|
|
* @license GNU General Public License 2.0 or later
|
2007-12-08 21:06:21 +00:00
|
|
|
*/
|
2008-08-09 01:54:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hooks for the TitleBlacklist class
|
2010-06-06 15:12:22 +00:00
|
|
|
*
|
|
|
|
* @ingroup Extensions
|
2008-08-09 01:54:39 +00:00
|
|
|
*/
|
2007-12-08 21:06:21 +00:00
|
|
|
class TitleBlacklistHooks {
|
2008-08-09 01:54:39 +00:00
|
|
|
/** getUserPermissionsErrorsExpensive hook */
|
2007-12-29 04:23:57 +00:00
|
|
|
public static function userCan( $title, $user, $action, &$result ) {
|
2007-12-08 21:06:21 +00:00
|
|
|
global $wgTitleBlacklist;
|
2008-05-22 01:35:48 +00:00
|
|
|
if( $action == 'create' || $action == 'edit' || $action == 'upload' ) {
|
2008-02-01 14:24:59 +00:00
|
|
|
efInitTitleBlacklist();
|
2007-12-29 04:23:57 +00:00
|
|
|
$blacklisted = $wgTitleBlacklist->isBlacklisted( $title, $action );
|
|
|
|
if( $blacklisted instanceof TitleBlacklistEntry ) {
|
2010-05-27 15:56:53 +00:00
|
|
|
wfLoadExtensionMessages( 'TitleBlacklist' );
|
2007-12-29 04:23:57 +00:00
|
|
|
$message = $blacklisted->getCustomMessage();
|
|
|
|
if( is_null( $message ) )
|
|
|
|
$message = 'titleblacklist-forbidden-edit';
|
|
|
|
$result = array( $message,
|
|
|
|
htmlspecialchars( $blacklisted->getRaw() ),
|
|
|
|
$title->getFullText() );
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
2007-12-29 04:23:57 +00:00
|
|
|
return true;
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/** AbortMove hook */
|
2007-12-08 21:06:21 +00:00
|
|
|
public static function abortMove( $old, $nt, $user, &$err ) {
|
|
|
|
global $wgTitleBlacklist;
|
2008-02-01 14:24:59 +00:00
|
|
|
efInitTitleBlacklist();
|
2007-12-10 19:02:38 +00:00
|
|
|
$blacklisted = $wgTitleBlacklist->isBlacklisted( $nt, 'move' );
|
2007-12-17 18:38:34 +00:00
|
|
|
if( !$blacklisted )
|
|
|
|
$blacklisted = $wgTitleBlacklist->isBlacklisted( $old, 'edit' );
|
|
|
|
if( $blacklisted instanceof TitleBlacklistEntry ) {
|
2010-05-27 15:56:53 +00:00
|
|
|
wfLoadExtensionMessages( 'TitleBlacklist' );
|
2007-12-17 18:38:34 +00:00
|
|
|
$message = $blacklisted->getCustomMessage();
|
|
|
|
if( is_null( $message ) )
|
|
|
|
$message = 'titleblacklist-forbidden-move';
|
2007-12-29 04:23:57 +00:00
|
|
|
$err = wfMsgWikiHtml( $message,
|
|
|
|
htmlspecialchars( $blacklisted->getRaw() ),
|
2009-01-18 14:42:07 +00:00
|
|
|
htmlspecialchars( $old->getFullText() ),
|
|
|
|
htmlspecialchars( $nt->getFullText() ) );
|
2007-12-08 21:06:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-08-09 01:54:39 +00:00
|
|
|
|
2010-06-04 13:36:29 +00:00
|
|
|
/**
|
|
|
|
* Check whether a user name is acceptable,
|
|
|
|
* and set a message if unacceptable.
|
|
|
|
*
|
|
|
|
* Used by abortNewAccount and centralAuthAutoCreate
|
|
|
|
*
|
|
|
|
* @return bool Acceptable
|
|
|
|
*/
|
2010-08-12 08:38:05 +00:00
|
|
|
private static function acceptNewUserName( $userName, &$err ) {
|
2010-06-07 18:47:18 +00:00
|
|
|
global $wgTitleBlacklist;
|
2008-08-09 01:54:39 +00:00
|
|
|
efInitTitleBlacklist();
|
2010-08-12 08:38:05 +00:00
|
|
|
$title = Title::newFromText( $userName, NS_USER );
|
2008-08-09 01:54:39 +00:00
|
|
|
$blacklisted = $wgTitleBlacklist->isBlacklisted( $title, 'new-account' );
|
|
|
|
if( !( $blacklisted instanceof TitleBlacklistEntry ) )
|
|
|
|
$blacklisted = $wgTitleBlacklist->isBlacklisted( $title, 'create' );
|
|
|
|
if( $blacklisted instanceof TitleBlacklistEntry ) {
|
2010-05-27 15:56:53 +00:00
|
|
|
wfLoadExtensionMessages( 'TitleBlacklist' );
|
2008-08-09 01:54:39 +00:00
|
|
|
$message = $blacklisted->getCustomMessage();
|
2010-08-12 08:38:05 +00:00
|
|
|
if ( is_null( $message ) )
|
|
|
|
$message = 'titleblacklist-forbidden-new-account';
|
|
|
|
$err = wfMsgWikiHtml( $message, $blacklisted->getRaw(), $userName );
|
2008-08-09 01:54:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-04 13:36:29 +00:00
|
|
|
|
|
|
|
/** AbortNewAccount hook */
|
2010-08-12 08:38:05 +00:00
|
|
|
public static function abortNewAccount( $user, &$message ) {
|
2010-06-08 04:34:31 +00:00
|
|
|
global $wgUser;
|
2010-08-12 08:38:05 +00:00
|
|
|
if( $wgUser->isAllowed( 'tboverride' ) )
|
2010-06-04 13:36:29 +00:00
|
|
|
return true;
|
|
|
|
return self::acceptNewUserName( $user->getName(), $message );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** CentralAuthAutoCreate hook */
|
|
|
|
public static function centralAuthAutoCreate( $user, $userName ) {
|
|
|
|
$message = ''; # Will be ignored
|
|
|
|
return self::acceptNewUserName( $userName, $message );
|
|
|
|
}
|
2010-08-12 08:38:05 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/** EditFilter hook */
|
2007-12-23 09:47:36 +00:00
|
|
|
public static function validateBlacklist( $editor, $text, $section, $error ) {
|
|
|
|
global $wgTitleBlacklist;
|
2008-02-01 14:24:59 +00:00
|
|
|
efInitTitleBlacklist();
|
2007-12-23 09:47:36 +00:00
|
|
|
$title = $editor->mTitle;
|
2008-09-14 01:44:04 +00:00
|
|
|
if( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) {
|
|
|
|
|
|
|
|
$bl = $wgTitleBlacklist->parseBlacklist( $text );
|
|
|
|
$ok = $wgTitleBlacklist->validate( $bl );
|
|
|
|
if( count( $ok ) == 0 ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-27 15:56:53 +00:00
|
|
|
wfLoadExtensionMessages( 'TitleBlacklist' );
|
2008-09-14 01:44:04 +00:00
|
|
|
$errmsg = wfMsgExt( 'titleblacklist-invalid', array( 'parsemag' ), count( $ok ) );
|
|
|
|
$errlines = '* <tt>' . implode( "</tt>\n* <tt>", array_map( 'wfEscapeWikiText', $ok ) ) . '</tt>';
|
2010-08-12 08:38:05 +00:00
|
|
|
$error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
|
2008-09-14 01:44:04 +00:00
|
|
|
$errmsg .
|
|
|
|
"\n" .
|
|
|
|
$errlines .
|
2010-08-12 08:38:05 +00:00
|
|
|
Html::closeElement( 'div' ) . "\n" .
|
|
|
|
Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
|
|
|
|
|
2008-09-14 01:44:04 +00:00
|
|
|
// $error will be displayed by the edit class
|
2007-12-23 09:47:36 +00:00
|
|
|
return true;
|
2010-08-12 08:38:05 +00:00
|
|
|
} elseif( !$section ) {
|
2008-09-14 01:44:04 +00:00
|
|
|
# Block redirects to nonexistent blacklisted titles
|
|
|
|
$retitle = Title::newFromRedirect( $text );
|
2010-08-12 08:38:05 +00:00
|
|
|
if( $retitle !== null && !$retitle->exists() ) {
|
2008-09-14 01:44:04 +00:00
|
|
|
$blacklisted = $wgTitleBlacklist->isBlacklisted( $retitle, 'create' );
|
2010-08-12 08:38:05 +00:00
|
|
|
if( $blacklisted instanceof TitleBlacklistEntry ) {
|
2010-05-27 15:56:53 +00:00
|
|
|
wfLoadExtensionMessages( 'TitleBlacklist' );
|
2010-08-12 08:38:05 +00:00
|
|
|
$error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) .
|
|
|
|
wfMsg( 'titleblacklist-forbidden-edit',
|
|
|
|
htmlspecialchars( $blacklisted->getRaw() ),
|
|
|
|
$retitle->getFullText() ) .
|
|
|
|
Html::closeElement( 'div' ) . "\n" .
|
|
|
|
Html::element( 'br', array( 'clear' => 'all' ) ) . "\n";
|
2008-09-14 01:44:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-23 09:47:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-09-15 16:33:40 +00:00
|
|
|
return true;
|
2007-12-29 04:23:57 +00:00
|
|
|
}
|
2010-08-12 08:38:05 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/** ArticleSaveComplete hook */
|
2007-12-29 04:23:57 +00:00
|
|
|
public static function clearBlacklist( &$article, &$user,
|
2010-08-12 08:38:05 +00:00
|
|
|
$text, $summary, $isminor, $iswatch, $section )
|
|
|
|
{
|
2007-12-29 04:23:57 +00:00
|
|
|
$title = $article->getTitle();
|
2008-01-14 10:09:08 +00:00
|
|
|
if( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) {
|
2007-12-29 04:23:57 +00:00
|
|
|
global $wgTitleBlacklist;
|
2008-02-01 14:24:59 +00:00
|
|
|
efInitTitleBlacklist();
|
2007-12-29 04:23:57 +00:00
|
|
|
$wgTitleBlacklist->invalidate();
|
|
|
|
}
|
2007-12-23 09:47:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-09-15 16:33:40 +00:00
|
|
|
}
|