jenkins-bot has submitted this change and it was merged.
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(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/engines/LuaCommon/TitleLibrary.php
b/engines/LuaCommon/TitleLibrary.php
index 44fe8a4..1dd5b06 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: merged
Gerrit-Change-Id: I630033d367a47f7f80809a0918d3e6feede3fe41
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Demon <[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