Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/52203


Change subject: (bug 45512) Add mw.title:getContent()
......................................................................

(bug 45512) Add mw.title:getContent()

Bug: 45512
Change-Id: I630033d367a47f7f80809a0918d3e6feede3fe41
---
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, 42 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/03/52203/1

diff --git a/engines/LuaCommon/TitleLibrary.php 
b/engines/LuaCommon/TitleLibrary.php
index b97c68c..860e69c 100644
--- a/engines/LuaCommon/TitleLibrary.php
+++ b/engines/LuaCommon/TitleLibrary.php
@@ -13,6 +13,7 @@
                        'newTitle' => array( $this, 'newTitle' ),
                        'makeTitle' => array( $this, 'makeTitle' ),
                        'getUrl' => array( $this, 'getUrl' ),
+                       'getContent' => array( $this, 'getContent' ),
                );
                $this->getEngine()->registerInterface( 'mw.title.lua', $lib, 
array(
                        'thisTitle' => $this->returnTitleToLua( 
$this->getTitle() ),
@@ -195,4 +196,20 @@
                }
                return array( call_user_func_array( array( $title, $func ), 
$args ) );
        }
+
+       function getContent( $text ) {
+               $title = Title::newFromText( $text );
+               if ( !$title ) {
+                       return array( null );
+               }
+               $rev = Revision::newFromTitle( $title );
+               if ( !$rev ) {
+                       return array( null );
+               }
+               $content = $rev->getContent();
+               if ( !$content ) {
+                       return array( null );
+               }
+               return array( $content->serialize() );
+       }
 }
diff --git a/engines/LuaCommon/lualib/mw.title.lua 
b/engines/LuaCommon/lualib/mw.title.lua
index 6f51d9b..afbbdd1 100644
--- a/engines/LuaCommon/lualib/mw.title.lua
+++ b/engines/LuaCommon/lualib/mw.title.lua
@@ -144,6 +144,16 @@
                return php.getUrl( self.fullText, 'canonicalUrl', query )
        end
 
+       function data:getContent()
+               checkSelf( self, 'getContent' )
+               local content = php.getContent( self.fullText )
+               data.getContent = function ( self )
+                       checkSelf( self, 'getContent' )
+                       return content
+               end
+               return content
+       end
+
        return setmetatable( obj, {
                __eq = title.equals,
                __lt = lt,
diff --git a/tests/engines/LuaCommon/TitleLibraryTest.php 
b/tests/engines/LuaCommon/TitleLibraryTest.php
index 3d57787..2b5d366 100644
--- a/tests/engines/LuaCommon/TitleLibraryTest.php
+++ b/tests/engines/LuaCommon/TitleLibraryTest.php
@@ -39,6 +39,13 @@
        function setUp() {
                parent::setUp();
 
+               // Page for getContent test
+               $page = WikiPage::factory( Title::newFromText( 
'ScribuntoTestPage' ) );
+               $page->doEditContent(
+                       new WikitextContent( 
'{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>' ),
+                       'Summary'
+               );
+
                // 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 500bdbc..4370c7e 100644
--- a/tests/engines/LuaCommon/TitleLibraryTests.lua
+++ b/tests/engines/LuaCommon/TitleLibraryTests.lua
@@ -40,6 +40,10 @@
        return 'did not error'
 end
 
+local function test_getContent()
+       return mw.title.new( 'ScribuntoTestPage' ):getContent()
+end
+
 -- Tests
 local tests = {
        { name = 'tostring', func = identity, type = 'ToString',
@@ -257,6 +261,10 @@
          }
        },
 
+       { name = '.getContent()', func = test_getContent,
+         expect = { 
'{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>' }
+       },
+
        { name = 'expensive functions', func = test_expensive,
          expect = 'too many expensive function calls'
        },

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I630033d367a47f7f80809a0918d3e6feede3fe41
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

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

Reply via email to