[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Hooks for Title Blacklist 4 * @author Victor Vasiliev 5 * @copyright © 2007-2010 Victor Vasiliev et al 6 * @license GNU General Public License 2.0 or later 7 */ 8 9 /** 10 * Hooks for the TitleBlacklist class 11 * 12 * @ingroup Extensions 13 */ 14 class TitleBlacklistHooks { 15 16 /** 17 * getUserPermissionsErrorsExpensive hook 18 * 19 * @param $title Title 20 * @param $user User 21 * @param $action 22 * @param $result 23 * @return bool 24 */ 25 public static function userCan( $title, $user, $action, &$result ) { 26 # Some places check createpage, while others check create. 27 # As it stands, upload does createpage, but normalize both 28 # to the same action, to stop future similar bugs. 29 if ( $action === 'createpage' || $action === 'createtalk' ) { 30 $action = 'create'; 31 } 32 if ( $action == 'create' || $action == 'edit' || $action == 'upload' ) { 33 $blacklisted = TitleBlacklist::singleton()->userCannot( $title, $user, $action ); 34 if ( $blacklisted instanceof TitleBlacklistEntry ) { 35 $result = array( $blacklisted->getErrorMessage( 'edit' ), 36 htmlspecialchars( $blacklisted->getRaw() ), 37 $title->getFullText() ); 38 return false; 39 } 40 } 41 return true; 42 } 43 44 /** 45 * Display a notice if a user is only able to create or edit a page 46 * because they have tboverride (or autoconfirmed). 47 * 48 * @param Title $title 49 * @param integer $oldid 50 * @param array &$notices 51 */ 52 public static function displayBlacklistOverrideNotice( Title $title, $oldid, array &$notices ) { 53 $blacklisted = TitleBlacklist::singleton()->isBlacklisted( 54 $title, 55 $title->exists() ? 'edit' : 'create' 56 ); 57 if ( $blacklisted ) { 58 $params = $blacklisted->getParams(); 59 $msg = wfMessage( 60 isset( $params['autoconfirmed'] ) ? 61 'titleblacklist-autoconfirmed-warning' : 62 'titleblacklist-warning' 63 ); 64 $notices['titleblacklist'] = $msg->rawParams( 65 htmlspecialchars( $blacklisted->getRaw() ) )->parseAsBlock(); 66 } 67 return true; 68 } 69 70 /** 71 * AbortMove hook 72 * 73 * @param $old Title 74 * @param $nt Title 75 * @param $user User 76 * @param $err 77 * @return bool 78 */ 79 public static function abortMove( $old, $nt, $user, &$err ) { 80 $titleBlacklist = TitleBlacklist::singleton(); 81 $blacklisted = $titleBlacklist->userCannot( $nt, $user, 'move' ); 82 if ( !$blacklisted ) { 83 $blacklisted = $titleBlacklist->userCannot( $old, $user, 'edit' ); 84 } 85 if ( $blacklisted instanceof TitleBlacklistEntry ) { 86 $err = wfMessage( $blacklisted->getErrorMessage( 'move' ), 87 $blacklisted->getRaw(), 88 $old->getFullText(), 89 $nt->getFullText() )->parse(); 90 return false; 91 } 92 return true; 93 } 94 95 /** 96 * Check whether a user name is acceptable, 97 * and set a message if unacceptable. 98 * 99 * Used by abortNewAccount and centralAuthAutoCreate 100 * 101 * @return bool Acceptable 102 */ 103 private static function acceptNewUserName( $userName, $permissionsUser, &$err, $override = true, $log = false ) { 104 global $wgUser; 105 $title = Title::makeTitleSafe( NS_USER, $userName ); 106 $blacklisted = TitleBlacklist::singleton()->userCannot( $title, $permissionsUser, 107 'new-account', $override ); 108 if ( $blacklisted instanceof TitleBlacklistEntry ) { 109 $message = $blacklisted->getErrorMessage( 'new-account' ); 110 $err = wfMessage( $message, $blacklisted->getRaw(), $userName )->parse(); 111 if ( $log ) { 112 self::logFilterHitUsername( $wgUser, $title, $blacklisted->getRaw() ); 113 } 114 return false; 115 } 116 return true; 117 } 118 119 /** 120 * AbortNewAccount hook 121 * 122 * @param User $user 123 */ 124 public static function abortNewAccount( $user, &$message ) { 125 global $wgUser, $wgRequest; 126 $override = $wgRequest->getCheck( 'wpIgnoreTitleBlacklist' ); 127 return self::acceptNewUserName( $user->getName(), $wgUser, $message, $override, true ); 128 } 129 130 /** 131 * EditFilter hook 132 * 133 * @param $editor EditPage 134 */ 135 public static function validateBlacklist( $editor, $text, $section, &$error ) { 136 global $wgUser; 137 $title = $editor->mTitle; 138 139 if ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) { 140 141 $blackList = TitleBlacklist::singleton(); 142 $bl = $blackList->parseBlacklist( $text, 'page' ); 143 $ok = $blackList->validate( $bl ); 144 if ( count( $ok ) == 0 ) { 145 return true; 146 } 147 148 $errmsg = wfMessage( 'titleblacklist-invalid' )->numParams( count( $ok ) )->text(); 149 $errlines = '* <code>' . implode( "</code>\n* <code>", array_map( 'wfEscapeWikiText', $ok ) ) . '</code>'; 150 $error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) . 151 $errmsg . 152 "\n" . 153 $errlines . 154 Html::closeElement( 'div' ) . "\n" . 155 Html::element( 'br', array( 'clear' => 'all' ) ) . "\n"; 156 157 // $error will be displayed by the edit class 158 return true; 159 } elseif ( !$section ) { 160 # Block redirects to nonexistent blacklisted titles 161 $retitle = Title::newFromRedirect( $text ); 162 if ( $retitle !== null && !$retitle->exists() ) { 163 $blacklisted = TitleBlacklist::singleton()->userCannot( $retitle, $wgUser, 'create' ); 164 if ( $blacklisted instanceof TitleBlacklistEntry ) { 165 $error = Html::openElement( 'div', array( 'class' => 'errorbox' ) ) . 166 wfMessage( 'titleblacklist-forbidden-edit', 167 $blacklisted->getRaw(), 168 $retitle->getFullText() )->escaped() . 169 Html::closeElement( 'div' ) . "\n" . 170 Html::element( 'br', array( 'clear' => 'all' ) ) . "\n"; 171 } 172 } 173 174 return true; 175 } 176 return true; 177 } 178 179 /** 180 * ArticleSaveComplete hook 181 * 182 * @param Article $article 183 */ 184 public static function clearBlacklist( &$article, &$user, 185 $text, $summary, $isminor, $iswatch, $section ) 186 { 187 $title = $article->getTitle(); 188 if ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist' ) { 189 TitleBlacklist::singleton()->invalidate(); 190 } 191 return true; 192 } 193 194 /** UserCreateForm hook based on the one from AntiSpoof extension */ 195 public static function addOverrideCheckbox( &$template ) { 196 global $wgRequest, $wgUser; 197 198 if ( TitleBlacklist::userCanOverride( $wgUser, 'new-account' ) ) { 199 $template->addInputItem( 'wpIgnoreTitleBlacklist', 200 $wgRequest->getCheck( 'wpIgnoreTitleBlacklist' ), 201 'checkbox', 'titleblacklist-override' ); 202 } 203 return true; 204 } 205 206 /** 207 * Logs the filter username hit to Special:Log if 208 * $wgTitleBlacklistLogHits is enabled. 209 * 210 * @param User $user 211 * @param Title $title 212 * @param string $entry 213 */ 214 public static function logFilterHitUsername( $user, $title, $entry ) { 215 global $wgTitleBlacklistLogHits; 216 if ( $wgTitleBlacklistLogHits ) { 217 $logEntry = new ManualLogEntry( 'titleblacklist', 'hit-username' ); 218 $logEntry->setPerformer( $user ); 219 $logEntry->setTarget( $title ); 220 $logEntry->setParameters( array( 221 '4::entry' => $entry, 222 ) ); 223 $logid = $logEntry->insert(); 224 $logEntry->publish( $logid ); 225 } 226 } 227 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |