Eranroz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/257684
Change subject: Guess parameters when templatedata is missing
......................................................................
Guess parameters when templatedata is missing
TemplateData guess the parameters from template wikitext when TemplateData is
missing.
This doesn't guaranteed to work everywhere, but in most cases it should work.
Bug: T54581
Change-Id: Id3b7d83e68087090c1454d213453e4f5fb6e9630
---
M api/ApiTemplateData.php
1 file changed, 20 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData
refs/changes/84/257684/1
diff --git a/api/ApiTemplateData.php b/api/ApiTemplateData.php
index 2292bc8..169f26d 100644
--- a/api/ApiTemplateData.php
+++ b/api/ApiTemplateData.php
@@ -69,7 +69,6 @@
__METHOD__,
array( 'ORDER BY', 'pp_page' )
);
-
$resp = array();
foreach ( $res as $row ) {
@@ -104,6 +103,26 @@
) + (array) $data;
}
+ // fill with heuristic templatedata for pages missing
templatedata
+ $missingTemplateData = array_diff_key( $titles, $resp );
+ foreach ( $missingTemplateData as $missA => &$missB ) {
+ $page = WikiPage::factory( Title::newFromID( $missA ) );
+ $templateWikitext = $page->getContent()->serialize();
+
+ if ( preg_match_all('/\{{3,}(.*?)[<|}]/',
$templateWikitext, $paramNames ) ){
+ $data = array('params' => array() );
+ foreach ( $paramNames[1] as $paramName ) {
+ $data['params'][$paramName] = array(
'description' => '' );
+ }
+
+ $resp[$missA] = array(
+ 'title' => strval( $missB ),
+ ) + (array) $data;
+
+ $this->setWarning( "$missB doesn't have
templatedata" );
+ }
+ }
+
// Set top level element
$result->addValue( null, 'pages', (object) $resp );
--
To view, visit https://gerrit.wikimedia.org/r/257684
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3b7d83e68087090c1454d213453e4f5fb6e9630
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Eranroz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits