jenkins-bot has submitted this change and it was merged.

Change subject: Expose cascading protection directly to Lua
......................................................................


Expose cascading protection directly to Lua

Add a way to fetch cascading protection information from Lua without
needing to call the CASCADINGSOURCES parser function.

Change-Id: I1b3ac18af11d3066f78d27b31da8d6709a6a2631
---
M engines/LuaCommon/TitleLibrary.php
M engines/LuaCommon/lualib/mw.title.lua
M tests/engines/LuaCommon/TitleLibraryTest.php
M tests/engines/LuaCommon/TitleLibraryTests.lua
4 files changed, 56 insertions(+), 21 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/engines/LuaCommon/TitleLibrary.php 
b/engines/LuaCommon/TitleLibrary.php
index 8d6a3fa..972eaff 100644
--- a/engines/LuaCommon/TitleLibrary.php
+++ b/engines/LuaCommon/TitleLibrary.php
@@ -16,6 +16,7 @@
                        'getContent' => array( $this, 'getContent' ),
                        'fileExists' => array( $this, 'fileExists' ),
                        'protectionLevels' => array( $this, 'protectionLevels' 
),
+                       'cascadingProtection' => array( $this, 
'cascadingProtection' ),
                );
                $this->getEngine()->registerInterface( 'mw.title.lua', $lib, 
array(
                        'thisTitle' => $this->returnTitleToLua( 
$this->getTitle() ),
@@ -256,16 +257,11 @@
                return array( (bool)$file->exists() );
        }
 
-       private function makeRestrictionsArraysOneBased( $restrictions ) {
-               $ret = array();
-               foreach ( $restrictions as $action => $requirements ) {
-                       if ( empty( $requirements ) ) {
-                               $ret[$action] = $requirements;
-                       } else {
-                               $ret[$action] = array_combine( range( 1, count( 
$requirements ) ), array_values( $requirements ) );
-                       }
+       private static function makeArrayOneBased( $arr ) {
+               if ( empty( $arr ) ) {
+                       return $arr;
                }
-               return $ret;
+               return array_combine( range( 1, count( $arr ) ), array_values( 
$arr ) );
        }
 
        public function protectionLevels( $text ) {
@@ -275,19 +271,30 @@
                        return array( null );
                }
 
-               // @todo Once support for MediaWiki prior to 1.23 is dropped, 
remove this if block
-               // (and maybe inline makeRestrictionsArraysOneBased)
-               if ( !is_callable( array( $title, 'areRestrictionsLoaded' ) ) ) 
{
-                       if ( !$title->mRestrictionsLoaded ) {
-                               $this->incrementExpensiveFunctionCount();
-                               $title->loadRestrictions();
-                       }
-                       return array( $this->makeRestrictionsArraysOneBased( 
$title->mRestrictions ) );
-               }
-
                if ( !$title->areRestrictionsLoaded() ) {
                        $this->incrementExpensiveFunctionCount();
                }
-               return array( $this->makeRestrictionsArraysOneBased( 
$title->getAllRestrictions() ) );
+               return array( array_map( 
'Scribunto_LuaTitleLibrary::makeArrayOneBased', $title->getAllRestrictions() ) 
);
+       }
+
+       public function cascadingProtection( $text ) {
+               $this->checkType( 'cascadingProtection', 1, $text, 'string' );
+               $title = Title::newFromText( $text );
+               if ( !$title ) {
+                       return array( null );
+               }
+
+               if ( !$title->areCascadeProtectionSourcesLoaded() ) {
+                       $this->incrementExpensiveFunctionCount();
+               }
+               list( $sources, $restrictions ) = 
$title->getCascadeProtectionSources();
+               return array( array(
+                       'sources' => 
Scribunto_LuaTitleLibrary::makeArrayOneBased( array_map(
+                               function ( $t ) {
+                                       return $t->getPrefixedText();
+                               },
+                               $sources ) ),
+                       'restrictions' => array_map( 
'Scribunto_LuaTitleLibrary::makeArrayOneBased', $restrictions )
+               ) );
        }
 }
diff --git a/engines/LuaCommon/lualib/mw.title.lua 
b/engines/LuaCommon/lualib/mw.title.lua
index 64f1033..bc1caa7 100644
--- a/engines/LuaCommon/lualib/mw.title.lua
+++ b/engines/LuaCommon/lualib/mw.title.lua
@@ -165,6 +165,7 @@
                subjectPageTitle = true,
                fileExists = true,
                protectionLevels = true,
+               cascadingProtection = true,
        }
        for k in pairs( data ) do
                readOnlyFields[k] = true
@@ -236,6 +237,12 @@
                                end
                                return data.protectionLevels
                        end
+                       if k == 'cascadingProtection' then
+                               if data.cascadingProtection == nil then
+                                       data.cascadingProtection = 
php.cascadingProtection( data.prefixedText )
+                               end
+                               return data.cascadingProtection
+                       end
 
                        return data[k]
                end,
diff --git a/tests/engines/LuaCommon/TitleLibraryTest.php 
b/tests/engines/LuaCommon/TitleLibraryTest.php
index d5a90e7..02db20b 100644
--- a/tests/engines/LuaCommon/TitleLibraryTest.php
+++ b/tests/engines/LuaCommon/TitleLibraryTest.php
@@ -49,26 +49,39 @@
                        'Summary'
                );
 
-               // Set restrictions for protectionLevels test
+               // Set restrictions for protectionLevels and 
cascadingProtection tests
                // Since mRestrictionsLoaded is true, they don't count as 
expensive
                $title = Title::newFromText( 'Main Page' );
                $title->mRestrictionsLoaded = true;
                $title->mRestrictions = array( 'edit' => array(), 'move' => 
array() );
+               $title->mCascadeSources = array( Title::makeTitle( NS_MAIN, 
"Lockbox" ), Title::makeTitle( NS_MAIN, "Lockbox2" ) );
+               $title->mCascadingRestrictions = array( 'edit' => array( 
'sysop' ) );
                $title = Title::newFromText( 'Module:TestFramework' );
                $title->mRestrictionsLoaded = true;
                $title->mRestrictions = array( 'edit' => array( 'sysop', 
'bogus' ), 'move' => array( 'sysop', 'bogus' ) );
+               $title->mCascadeSources = array();
+               $title->mCascadingRestrictions = array();
                $title = Title::newFromText( 
'scribuntotitletest:Module:TestFramework' );
                $title->mRestrictionsLoaded = true;
                $title->mRestrictions = array();
+               $title->mCascadeSources = array();
+               $title->mCascadingRestrictions = array();
                $title = Title::newFromText( 'Talk:Has/A/Subpage' );
                $title->mRestrictionsLoaded = true;
                $title->mRestrictions = array( 'create' => array( 'sysop' ) );
+               $title->mCascadeSources = array();
+               $title->mCascadingRestrictions = array();
                $title = Title::newFromText( 'Not/A/Subpage' );
                $title->mRestrictionsLoaded = true;
                $title->mRestrictions = array( 'edit' => array( 'autoconfirmed' 
), 'move' => array( 'sysop' ) );
+               $title->mCascadeSources = array();
+               $title->mCascadingRestrictions = array();
                $title = Title::newFromText( 'Module talk:Test Framework' );
                $title->mRestrictionsLoaded = true;
                $title->mRestrictions = array( 'edit' => array(), 'move' => 
array( 'sysop' ) );
+               $title->mCascadeSources = array();
+               $title->mCascadingRestrictions = array();
+
 
                // Note this depends on every iteration of the data provider 
running with a clean parser
                
$this->getEngine()->getParser()->getOptions()->setExpensiveParserFunctionLimit( 
10 );
diff --git a/tests/engines/LuaCommon/TitleLibraryTests.lua 
b/tests/engines/LuaCommon/TitleLibraryTests.lua
index ba24491..7619b9f 100644
--- a/tests/engines/LuaCommon/TitleLibraryTests.lua
+++ b/tests/engines/LuaCommon/TitleLibraryTests.lua
@@ -252,6 +252,14 @@
                  { edit = {}, move = { 'sysop' } }, { edit = {}, move = { 
'sysop' } }
          }
        },
+       { name = '.cascadingProtection', func = prop_foreach,
+         args = { 'cascadingProtection' },
+         expect = {
+                 { restrictions = { edit = { 'sysop' } }, sources = { 
'Lockbox', 'Lockbox2' } }, { restrictions = {}, sources = {} },
+                 { restrictions = {}, sources = {} }, { restrictions = {}, 
sources = {} }, { restrictions = {}, sources = {} },
+                 { restrictions = {}, sources = {} }, { restrictions = {}, 
sources = {} }
+         }
+       },
        { name = '.inNamespace()', func = func_foreach,
          args = { 'inNamespace', 'Module' },
          expect = { false, true, false, false, false, false, false }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1b3ac18af11d3066f78d27b31da8d6709a6a2631
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to