Don't reparse infoboxes in templates every time in PIDataService

This commit is contained in:
Luqgreg 2018-10-19 20:06:16 +02:00
parent 2c2553a253
commit 30a6c6a094
3 changed files with 10 additions and 8 deletions

View file

@ -36,7 +36,12 @@ class PortableInfoboxHooks {
* @return bool
*/
public static function onPageContentSave( Page $article ) {
PortableInfoboxDataService::newFromTitle( $article->getTitle() )->delete();
$dataService = PortableInfoboxDataService::newFromTitle( $article->getTitle() );
$dataService->delete();
if ( $article->getTitle()->inNamespace( NS_TEMPLATE ) ) {
$dataService->reparseArticle( true );
}
return true;
}

View file

@ -62,11 +62,7 @@ class PortableInfoboxDataService {
* @return array in format [ [ 'data' => [], 'metadata' => [] ] or [] will be returned
*/
public function getData() {
if ( $this->title->exists() && $this->title->inNamespace( NS_TEMPLATE ) ) {
$result = $this->reparseArticle();
} else {
$result = $this->get();
}
$result = $this->get();
return $result ? $result : [];
}
@ -197,7 +193,7 @@ class PortableInfoboxDataService {
return [];
}
protected function reparseArticle() {
public function reparseArticle() {
if ( $this->title->inNamespace( NS_TEMPLATE ) ) {
$result = $this->parsingHelper->parseIncludeonlyInfoboxes( $this->title );
} else {
@ -231,6 +227,7 @@ class PortableInfoboxDataService {
$infobox['parser_tag_version'] !== PortableInfoboxParserTagController::PARSER_TAG_VERSION
) {
$infoboxes = $this->reparseArticle();
break;
}
}
}

View file

@ -101,7 +101,7 @@ class PortableInfoboxDataServiceTest extends MediaWikiTestCase {
->purge()
->setPagePropsProxy( new PagePropsProxyDummy() )
->setParsingHelper( new ParsingHelperDummy( null, $data ) )
->getData();
->reparseArticle();
$this->assertEquals( $data, $result );
}