Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/330326 )

Change subject: Validate all pages which are blacklist sources
......................................................................

Validate all pages which are blacklist sources

Previously only MediaWiki:Titleblacklist was validated.

Also makes MediaWiki:Titleblacklist handle disabled
message syntax the same way other MediaWiki pages do.

Bug: T154112
Change-Id: I80ee829aa59e59d481faeeab08e0bfa862164ad2
---
M TitleBlacklist.hooks.php
M TitleBlacklist.list.php
2 files changed, 30 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TitleBlacklist 
refs/changes/26/330326/1

diff --git a/TitleBlacklist.hooks.php b/TitleBlacklist.hooks.php
index 31fc457..9f13e2d 100644
--- a/TitleBlacklist.hooks.php
+++ b/TitleBlacklist.hooks.php
@@ -242,12 +242,15 @@
         * @param $editor EditPage
         */
        public static function validateBlacklist( $editor, $text, $section, 
&$error ) {
-               global $wgUser;
                $title = $editor->mTitle;
+               $blackList = TitleBlacklist::singleton();
 
-               if ( $title->getNamespace() == NS_MEDIAWIKI && 
$title->getDBkey() == 'Titleblacklist' ) {
+               if ( $blackList->isBlacklistSource( $title ) ) {
+                       if ( $title->getNamespace() === NS_MEDIAWIKI && $text 
=== '-' ) {
+                               // disabled message, not a real blacklist
+                               return true;
+                       }
 
-                       $blackList = TitleBlacklist::singleton();
                        $bl = $blackList->parseBlacklist( $text, 'page' );
                        $ok = $blackList->validate( $bl );
                        if ( count( $ok ) == 0 ) {
diff --git a/TitleBlacklist.list.php b/TitleBlacklist.list.php
index efa41e3..8277ca4 100644
--- a/TitleBlacklist.list.php
+++ b/TitleBlacklist.list.php
@@ -17,7 +17,12 @@
  */
 class TitleBlacklist {
        private $mBlacklist = null, $mWhitelist = null;
-       const VERSION = 3;      // Blacklist format
+
+       /** @var array Flipped array holding the titles of local pages which 
contain a blacklist */
+       private $blacklistPages = [];
+
+       /** Blacklist format */
+       const VERSION = 3;
 
        /**
         * Get an instance of this class
@@ -42,8 +47,10 @@
                $cache = ObjectCache::getMainWANInstance();
                // Try to find something in the cache
                $cachedBlacklist = $cache->get( wfMemcKey( 
"title_blacklist_entries" ) );
+               $cachedBlacklistPages = $cache->get( wfMemcKey( 
"title_blacklist_pages" ) );
                if ( is_array( $cachedBlacklist ) && count( $cachedBlacklist ) 
> 0 && ( $cachedBlacklist[0]->getFormatVersion() == self::VERSION ) ) {
                        $this->mBlacklist = $cachedBlacklist;
+                       $this->blacklistPages = $cachedBlacklistPages;
                        return;
                }
 
@@ -54,6 +61,7 @@
                        $this->mBlacklist = array_merge( $this->mBlacklist, 
$this->parseBlacklist( $this->getBlacklistText( $source ), $sourceName ) );
                }
                $cache->set( wfMemcKey( "title_blacklist_entries" ), 
$this->mBlacklist, $wgTitleBlacklistCaching['expiry'] );
+               $cache->set( wfMemcKey( "title_blacklist_pages" ), 
$this->blacklistPages, $wgTitleBlacklistCaching['expiry'] );
                wfDebugLog( 'TitleBlacklist-cache', 'Updated ' . wfMemcKey( 
"title_blacklist_entries" )
                        . ' with ' . count( $this->mBlacklist ) . ' entries.' );
        }
@@ -81,25 +89,24 @@
         * @param string $source A blacklist source from 
$wgTitleBlacklistSources
         * @return string The content of the blacklist source as a string
         */
-       private static function getBlacklistText( $source ) {
+       private function getBlacklistText( $source ) {
                if ( !is_array( $source ) || count( $source ) <= 0 ) {
                        return '';      // Return empty string in error case
                }
 
                if ( $source['type'] == 'message' ) {
-                       return wfMessage( 'titleblacklist' 
)->inContentLanguage()->text();
+                       $this->blacklistPages['MediaWiki:Titleblacklist'] = 
true;
+                       $msg = wfMessage( 'titleblacklist' 
)->inContentLanguage();
+                       return $msg->isDisabled() ? '' : $msg->text();
                } elseif ( $source['type'] == 'localpage' && count( $source ) 
>= 2 ) {
                        $title = Title::newFromText( $source['src'] );
                        if ( is_null( $title ) ) {
                                return '';
                        }
+                       $this->blacklistPages[$title->getPrefixedDBkey()] = 
true;
                        if ( $title->getNamespace() == NS_MEDIAWIKI ) {
                                $msg = wfMessage( $title->getText() 
)->inContentLanguage();
-                               if ( !$msg->isDisabled() ) {
-                                       return $msg->text();
-                               } else {
-                                       return '';
-                               }
+                               return $msg->isDisabled() ? '' : $msg->text();
                        } else {
                                $page = WikiPage::factory( $title );
                                if ( $page->exists() ) {
@@ -304,6 +311,15 @@
                return $user->isAllowed( 'tboverride' ) ||
                        ( $action == 'new-account' && $user->isAllowed( 
'tboverride-account' ) );
        }
+
+       /**
+        * Indicates whether the given page contains a blacklist.
+        * @param Title $title
+        * @return bool
+        */
+       public function isBlacklistSource( Title $title ) {
+               return array_key_exists( $title->getPrefixedDBkey(), 
$this->blacklistPages );
+       }
 }
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/330326
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I80ee829aa59e59d481faeeab08e0bfa862164ad2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TitleBlacklist
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to