mediawiki-extensions-TitleB.../TitleBlacklist.hooks.php

140 lines
4.4 KiB
PHP
Raw Normal View History

<?php
/**
* Hooks for Title Blacklist
* @author VasilievVV
2007-12-31 10:03:10 +00:00
* @copyright © 2007 VasilievVV
* @license GNU General Public License 2.0 or later
*/
2008-08-09 01:54:39 +00:00
/**
* Hooks for the TitleBlacklist class
* @package MediaWiki
* @subpackage Extensions
*/
class TitleBlacklistHooks {
2008-08-09 01:54:39 +00:00
/** getUserPermissionsErrorsExpensive hook */
public static function userCan( $title, $user, $action, &$result ) {
global $wgTitleBlacklist;
if( $action == 'create' || $action == 'edit' || $action == 'upload' ) {
2008-02-01 14:24:59 +00:00
efInitTitleBlacklist();
$blacklisted = $wgTitleBlacklist->isBlacklisted( $title, $action );
if( $blacklisted instanceof TitleBlacklistEntry ) {
2008-01-14 14:08:49 +00:00
wfLoadExtensionMessages( 'TitleBlacklist' );
$message = $blacklisted->getCustomMessage();
if( is_null( $message ) )
$message = 'titleblacklist-forbidden-edit';
$result = array( $message,
htmlspecialchars( $blacklisted->getRaw() ),
$title->getFullText() );
return false;
}
}
return true;
}
2008-08-09 01:54:39 +00:00
/** AbortMove hook */
public static function abortMove( $old, $nt, $user, &$err ) {
global $wgTitleBlacklist;
2008-02-01 14:24:59 +00:00
efInitTitleBlacklist();
$blacklisted = $wgTitleBlacklist->isBlacklisted( $nt, 'move' );
if( !$blacklisted )
$blacklisted = $wgTitleBlacklist->isBlacklisted( $old, 'edit' );
if( $blacklisted instanceof TitleBlacklistEntry ) {
2008-01-14 14:08:49 +00:00
wfLoadExtensionMessages( 'TitleBlacklist' );
$message = $blacklisted->getCustomMessage();
if( is_null( $message ) )
$message = 'titleblacklist-forbidden-move';
$err = wfMsgWikiHtml( $message,
htmlspecialchars( $blacklisted->getRaw() ),
htmlspecialchars( $nt->getFullText() ),
htmlspecialchars( $old->getFullText() ) );
return false;
}
return true;
}
2008-08-09 01:54:39 +00:00
/** AbortNewAccount hook */
public static function abortNewAccount($user, &$message) {
global $wgTitleBlacklist, $wgUser;
if ( $wgUser->isAllowed( 'tboverride' ) )
return true;
efInitTitleBlacklist();
$title = Title::newFromText( $user->getName() );
$blacklisted = $wgTitleBlacklist->isBlacklisted( $title, 'new-account' );
if( !( $blacklisted instanceof TitleBlacklistEntry ) )
$blacklisted = $wgTitleBlacklist->isBlacklisted( $title, 'create' );
if( $blacklisted instanceof TitleBlacklistEntry ) {
wfLoadExtensionMessages( 'TitleBlacklist' );
$message = $blacklisted->getCustomMessage();
if( is_null( $message ) )
$message = wfMsgWikiHtml( 'titleblacklist-forbidden-new-account',
$blacklisted->getRaw(),
$user->getName() );
$result = array( $message,
htmlspecialchars( $blacklisted->getRaw() ),
$title->getFullText() );
return false;
}
return true;
}
/** EditFilter hook */
public static function validateBlacklist( $editor, $text, $section, $error ) {
global $wgTitleBlacklist;
2008-02-01 14:24:59 +00:00
efInitTitleBlacklist();
$title = $editor->mTitle;
if( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) {
$bl = $wgTitleBlacklist->parseBlacklist( $text );
$ok = $wgTitleBlacklist->validate( $bl );
if( count( $ok ) == 0 ) {
return true;
}
wfLoadExtensionMessages( 'TitleBlacklist' );
$errmsg = wfMsgExt( 'titleblacklist-invalid', array( 'parsemag' ), count( $ok ) );
$errlines = '* <tt>' . implode( "</tt>\n* <tt>", array_map( 'wfEscapeWikiText', $ok ) ) . '</tt>';
$error = '<div class="errorbox">' .
$errmsg .
"\n" .
$errlines .
"</div>\n" .
"<br clear='all' />\n";
// $error will be displayed by the edit class
return true;
} else if (!$section) {
# Block redirects to nonexistent blacklisted titles
$retitle = Title::newFromRedirect( $text );
if ( $retitle !== null && !$retitle->exists() ) {
$blacklisted = $wgTitleBlacklist->isBlacklisted( $retitle, 'create' );
if ( $blacklisted instanceof TitleBlacklistEntry ) {
wfLoadExtensionMessages( 'TitleBlacklist' );
$error = ( '<div class="errorbox">' .
wfMsg( 'titleblacklist-forbidden-edit',
htmlspecialchars( $blacklisted->getRaw() ),
$retitle->getFullText() ) .
"</div>\n" .
"<br clear='all' />\n" );
}
}
return true;
}
2008-09-15 16:33:40 +00:00
return true;
}
2008-08-09 01:54:39 +00:00
/** ArticleSaveComplete hook */
public static function clearBlacklist( &$article, &$user,
$text, $summary, $isminor, $iswatch, $section ) {
$title = $article->getTitle();
if( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) {
global $wgTitleBlacklist;
2008-02-01 14:24:59 +00:00
efInitTitleBlacklist();
$wgTitleBlacklist->invalidate();
}
return true;
}
2008-09-15 16:33:40 +00:00
}