Index: trunk/extensions/TitleBlacklist/TitleBlacklist.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | 'author' => 'VasilievVV', |
10 | 10 | 'version' => '1.4', |
11 | 11 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Title_Blacklist', |
12 | | - 'description' => 'Allows to forbide creation of pages with specified titles' |
| 12 | + 'description' => 'Allows to forbid creation of pages with specified titles' |
13 | 13 | ); |
14 | 14 | |
15 | 15 | $wgExtensionMessagesFiles['TitleBlacklist'] = dirname( __FILE__ ) . '/TitleBlacklist.i18n.php'; |
— | — | @@ -18,10 +18,10 @@ |
19 | 19 | $wgExtensionFunctions[] = 'efInitTitleBlacklist'; |
20 | 20 | |
21 | 21 | // Sources of TitleBlacklist |
22 | | -define( 'TBLSRC_MSG', 0 ); //For internal usage |
23 | | -define( 'TBLSRC_LOCALPAGE', 1 ); //Local wiki page |
24 | | -define( 'TBLSRC_URL', 2 ); //Load blacklist from URL |
25 | | -define( 'TBLSRC_FILE', 3 ); //Load from file |
| 22 | +define( 'TBLSRC_MSG', 0 ); // For internal usage |
| 23 | +define( 'TBLSRC_LOCALPAGE', 1 ); // Local wiki page |
| 24 | +define( 'TBLSRC_URL', 2 ); // Load blacklist from URL |
| 25 | +define( 'TBLSRC_FILE', 3 ); // Load from file |
26 | 26 | $wgTitleBlacklistSources = array(); |
27 | 27 | |
28 | 28 | $wgTitleBlacklistCaching = array( |
— | — | @@ -42,8 +42,9 @@ |
43 | 43 | |
44 | 44 | function efSetupTitleBlacklistHooks() { |
45 | 45 | global $wgHooks; |
46 | | - $wgHooks['getUserPermissionsErrors'][] = 'TitleBlacklistHooks::userCan'; |
| 46 | + $wgHooks['getUserPermissionsErrors'][] = 'TitleBlacklistHooks::userCan'; |
47 | 47 | $wgHooks['AbortMove'][] = 'TitleBlacklistHooks::abortMove'; |
48 | 48 | $wgHooks['UploadVerification'][] = 'TitleBlacklistHooks::verifyUpload'; |
49 | 49 | $wgHooks['EditFilter'][] = 'TitleBlacklistHooks::validateBlacklist'; |
| 50 | + $wgHooks['ArticleSaveComplete'][] = 'TitleBlacklistHooks::clearBlacklist'; |
50 | 51 | } |
Index: trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php |
— | — | @@ -7,27 +7,25 @@ |
8 | 8 | * @subpackage Extensions |
9 | 9 | * @author VasilievVV |
10 | 10 | * @copyright � 2007 VasilievVV |
11 | | - * @licence GNU General Public Licence 2.0 or later |
| 11 | + * @license GNU General Public License 2.0 or later |
12 | 12 | */ |
13 | 13 | |
14 | 14 | class TitleBlacklistHooks { |
15 | | - public static function userCan( $title, $user, $action, &$result ) |
16 | | - { |
| 15 | + public static function userCan( $title, $user, $action, &$result ) { |
17 | 16 | global $wgTitleBlacklist; |
18 | | - if ( $action != 'create' && $action != 'edit' ) { |
19 | | - $result = true; |
20 | | - return $result; |
| 17 | + if( $action == 'create' || $action == 'edit' ) { |
| 18 | + $blacklisted = $wgTitleBlacklist->isBlacklisted( $title, $action ); |
| 19 | + if( $blacklisted instanceof TitleBlacklistEntry ) { |
| 20 | + $message = $blacklisted->getCustomMessage(); |
| 21 | + if( is_null( $message ) ) |
| 22 | + $message = 'titleblacklist-forbidden-edit'; |
| 23 | + $result = array( $message, |
| 24 | + htmlspecialchars( $blacklisted->getRaw() ), |
| 25 | + $title->getFullText() ); |
| 26 | + return false; |
| 27 | + } |
21 | 28 | } |
22 | | - $blacklisted = $wgTitleBlacklist->isBlacklisted( $title, $action ); |
23 | | - if( $blacklisted instanceof TitleBlacklistEntry ) { |
24 | | - $message = $blacklisted->getCustomMessage(); |
25 | | - if( is_null( $message ) ) |
26 | | - $message = 'titleblacklist-forbidden-edit'; |
27 | | - $result = array( $message, htmlspecialchars( $blacklisted->getRaw() ), $title->getFullText() ); |
28 | | - return false; |
29 | | - } |
30 | | - |
31 | | - return $result = true; |
| 29 | + return true; |
32 | 30 | } |
33 | 31 | |
34 | 32 | public static function abortMove( $old, $nt, $user, &$err ) { |
— | — | @@ -39,7 +37,10 @@ |
40 | 38 | $message = $blacklisted->getCustomMessage(); |
41 | 39 | if( is_null( $message ) ) |
42 | 40 | $message = 'titleblacklist-forbidden-move'; |
43 | | - $err = wfMsgWikiHtml( $message, htmlspecialchars( $blacklisted->getRaw() ), $nt->getFullText(), $old->getFullText() ); |
| 41 | + $err = wfMsgWikiHtml( $message, |
| 42 | + htmlspecialchars( $blacklisted->getRaw() ), |
| 43 | + htmlspecialchars( $nt->getFullText() ), |
| 44 | + htmlspecialchars( $old->getFullText() ) ); |
44 | 45 | return false; |
45 | 46 | } |
46 | 47 | return true; |
— | — | @@ -67,7 +68,6 @@ |
68 | 69 | $bl = $wgTitleBlacklist->parseBlacklist( $text ); |
69 | 70 | $ok = $wgTitleBlacklist->validate( $bl ); |
70 | 71 | if( count( $ok ) == 0 ) { |
71 | | - $wgTitleBlacklist->invalidate(); |
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | |
— | — | @@ -79,6 +79,18 @@ |
80 | 80 | $errlines . |
81 | 81 | "</div>\n" . |
82 | 82 | "<br clear='all' />\n"; |
| 83 | + |
| 84 | + // $error will be displayed by the edit class |
83 | 85 | return true; |
84 | 86 | } |
| 87 | + |
| 88 | + public static function clearBlacklist( &$article, &$user, |
| 89 | + $text, $summary, $isminor, $iswatch, $section ) { |
| 90 | + $title = $article->getTitle(); |
| 91 | + if( $title->getNamespace() == NS_MEDIAWIKI && $title->getDbKey() == 'Titleblacklist' ) { |
| 92 | + global $wgTitleBlacklist; |
| 93 | + $wgTitleBlacklist->invalidate(); |
| 94 | + } |
| 95 | + return true; |
| 96 | + } |
85 | 97 | } |
\ No newline at end of file |
Index: trunk/extensions/TitleBlacklist/TitleBlacklist.list.php |
— | — | @@ -156,7 +156,7 @@ |
157 | 157 | return true; |
158 | 158 | } |
159 | 159 | wfSuppressWarnings(); |
160 | | - $match = preg_match( "/^{$this->mRegex}$/s" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), $title->getFullText() ); |
| 160 | + $match = preg_match( "/^{$this->mRegex}$/us" . ( isset( $this->mParams['casesensitive'] ) ? '' : 'i' ), $title->getFullText() ); |
161 | 161 | wfRestoreWarnings(); |
162 | 162 | if( $match ) { |
163 | 163 | if( isset( $this->mParams['autoconfirmed'] ) && $user->isAllowed( 'autoconfirmed' ) ) { |
— | — | @@ -171,18 +171,18 @@ |
172 | 172 | } |
173 | 173 | |
174 | 174 | public static function newFromString( $line ) { |
175 | | - $raw = $line; #Keep line for raw data |
| 175 | + $raw = $line; // Keep line for raw data |
176 | 176 | $regex = ""; |
177 | 177 | $options = array(); |
178 | | - //Strip comments |
| 178 | + // Strip comments |
179 | 179 | $line = preg_replace( "/^\\s*([^#]*)\\s*((.*)?)$/", "\\1", $line ); |
180 | 180 | $line = trim( $line ); |
181 | | - //Parse the rest of message |
| 181 | + // Parse the rest of message |
182 | 182 | preg_match( '/^(.*?)(\s*<(.*)>)?$/', $line, $pockets ); |
183 | 183 | @list( $full, $regex, $null, $opts_str ) = $pockets; |
184 | 184 | $regex = trim( $regex ); |
185 | 185 | $opts_str = trim( $opts_str ); |
186 | | - //Parse opts |
| 186 | + // Parse opts |
187 | 187 | $opts = preg_split( '/\s*\|\s*/', $opts_str ); |
188 | 188 | foreach( $opts as $opt ) { |
189 | 189 | $opt2 = strtolower( $opt ); |
— | — | @@ -199,15 +199,15 @@ |
200 | 200 | $options['errmsg'] = $matches[1]; |
201 | 201 | } |
202 | 202 | } |
203 | | - //Process magic words |
| 203 | + // Process magic words |
204 | 204 | preg_match_all( '/{{\s*([a-z]+)\s*:\s*(.+?)\s*}}/', $regex, $magicwords, PREG_SET_ORDER ); |
205 | 205 | foreach( $magicwords as $mword ) { |
206 | | - global $wgParser; //Functions we're calling don't need, nevertheless let's use it |
| 206 | + global $wgParser; // Functions we're calling don't need, nevertheless let's use it |
207 | 207 | switch( strtolower( $mword[1] ) ) { |
208 | 208 | case 'ns': |
209 | 209 | $cpf_result = CoreParserFunctions::ns( $wgParser, $mword[2] ); |
210 | 210 | if( is_string( $cpf_result ) ) { |
211 | | - $regex = str_replace( $mword[0], $cpf_result, $regex ); //All result will have the same value, so we can just use str_seplace() |
| 211 | + $regex = str_replace( $mword[0], $cpf_result, $regex ); // All result will have the same value, so we can just use str_seplace() |
212 | 212 | } |
213 | 213 | break; |
214 | 214 | case 'int': |
— | — | @@ -217,7 +217,7 @@ |
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
221 | | - //Return result |
| 221 | + // Return result |
222 | 222 | if( $regex ) { |
223 | 223 | return new TitleBlacklistEntry( $regex, $options, $raw ); |
224 | 224 | } else { |