Adrian Lang has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172547
Change subject: Move templates from lib to repo
......................................................................
Move templates from lib to repo
I'd like to try to refactor the hook setup and TemplateRegistry afterwards
in a separate patch. This change creates a situation where lib depends on stuff
in repo. I do it like that because lib/resources/jquery.wikibase/ is subject to
a lot of pending changes, while these files are probably not touched currently.
Change-Id: Ic79abfbc6aa67320070061008b3a5d81d6bc5f41
---
M lib/WikibaseLib.php
M lib/resources/Resources.php
M lib/tests/qunit/resources.php
M repo/Wikibase.hooks.php
M repo/Wikibase.php
R repo/includes/Template.php
R repo/includes/TemplateRegistry.php
R repo/includes/modules/TemplateModule.php
M repo/resources/Resources.php
R repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
R repo/resources/templates.js
R repo/resources/templates.php
R repo/tests/phpunit/TemplateRegistryTest.php
R repo/tests/phpunit/TemplateTest.php
A repo/tests/qunit/resources.php
R repo/tests/qunit/templates.tests.js
16 files changed, 105 insertions(+), 62 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/47/172547/1
diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php
index afe7ad9..543c842 100644
--- a/lib/WikibaseLib.php
+++ b/lib/WikibaseLib.php
@@ -95,43 +95,6 @@
// @codeCoverageIgnoreEnd
};
- /**
- * Called when setup is done. This is somewhat ugly, find a better time
to register templates.
- * @see https://www.mediawiki.org/wiki/Manual:Hooks/SetupAfterCache
- *
- * @return bool
- */
- $wgHooks['SetupAfterCache'][] = function() {
- \Wikibase\TemplateRegistry::singleton()->addTemplates( include(
__DIR__ . "/resources/templates.php" ) );
- return true;
- };
-
- /**
- * Shorthand function to retrieve a template filled with the specified
parameters.
- *
- * important! note that the Template class does not escape anything.
- * be sure to escape your params before using this function!
- *
- * @since 0.2
- *
- * @param $key string template key
- * Varargs: normal template parameters
- *
- * @return string
- */
- function wfTemplate( $key /*...*/ ) {
- $params = func_get_args();
- array_shift( $params );
-
- if ( isset( $params[0] ) && is_array( $params[0] ) ) {
- $params = $params[0];
- }
-
- $template = new \Wikibase\Template(
\Wikibase\TemplateRegistry::singleton(), $key, $params );
-
- return $template->render();
- }
-
// Resource Loader Modules:
$wgResourceModules = array_merge( $wgResourceModules, include( __DIR__
. "/resources/Resources.php" ) );
diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index bd7ce2a..fbb29e9 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -66,11 +66,6 @@
)
),
- 'wikibase.templates' => $moduleTemplate + array(
- 'class' => 'Wikibase\TemplateModule',
- 'scripts' => 'templates.js',
- ),
-
'wikibase' => $moduleTemplate + array(
'scripts' => array(
'wikibase.js',
@@ -152,17 +147,6 @@
'jquery.effects.blind',
'jquery.inputautoexpand',
'jquery.ui.widget',
- ),
- ),
-
- 'jquery.ui.TemplatedWidget' => $moduleTemplate + array(
- 'scripts' => array(
- 'jquery.ui/jquery.ui.TemplatedWidget.js',
- ),
- 'dependencies' => array(
- 'wikibase.templates',
- 'jquery.ui.widget',
- 'util.inherit',
),
),
diff --git a/lib/tests/qunit/resources.php b/lib/tests/qunit/resources.php
index 6031765..2f58d55 100644
--- a/lib/tests/qunit/resources.php
+++ b/lib/tests/qunit/resources.php
@@ -135,15 +135,6 @@
),
),
- 'templates.tests' => $moduleBase + array(
- 'scripts' => array(
- 'templates.tests.js',
- ),
- 'dependencies' => array(
- 'wikibase.templates',
- ),
- ),
-
'wikibase.Site.tests' => $moduleBase + array(
'scripts' => array(
'wikibase.Site.tests.js',
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index ccae95b..7f6c4c5 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -181,6 +181,25 @@
}
/**
+ * @see
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
+ *
+ * @since 0.2 (in repo as RepoHooks::onResourceLoaderTestModules in 0.1)
+ *
+ * @param array &$testModules
+ * @param \ResourceLoader &$resourceLoader
+ *
+ * @return boolean
+ */
+ public static function registerQUnitTests( array &$testModules,
\ResourceLoader &$resourceLoader ) {
+ $testModules['qunit'] = array_merge(
+ $testModules['qunit'],
+ include( __DIR__ . '/tests/qunit/resources.php' )
+ );
+
+ return true;
+ }
+
+ /**
* Handler for the NamespaceIsMovable hook.
*
* Implemented to prevent moving pages that are in an entity namespace.
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index baafa23..b82b05f 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -185,6 +185,8 @@
$wgHooks['BeforePageDisplay'][]
= 'Wikibase\RepoHooks::onBeforePageDisplay';
$wgHooks['LoadExtensionSchemaUpdates'][] =
'Wikibase\RepoHooks::onSchemaUpdate';
$wgHooks['UnitTestsList'][]
= 'Wikibase\RepoHooks::registerUnitTests';
+ $wgHooks['ResourceLoaderTestModules'][] =
'Wikibase\RepoHooks::registerQUnitTests';
+
$wgHooks['NamespaceIsMovable'][]
= 'Wikibase\RepoHooks::onNamespaceIsMovable';
$wgHooks['NewRevisionFromEditComplete'][] =
'Wikibase\RepoHooks::onNewRevisionFromEditComplete';
$wgHooks['SkinTemplateNavigation'][] =
'Wikibase\RepoHooks::onPageTabs';
@@ -217,6 +219,43 @@
$wgHooks['BaseTemplateToolbox'][] =
'Wikibase\RepoHooks::onBaseTemplateToolbox';
$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] =
'Wikibase\RepoHooks::onSkinTemplateBuildNavUrlsNav_urlsAfterPermalink';
+ /**
+ * Called when setup is done. This is somewhat ugly, find a better time
to register templates.
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/SetupAfterCache
+ *
+ * @return bool
+ */
+ $wgHooks['SetupAfterCache'][] = function() {
+ \Wikibase\TemplateRegistry::singleton()->addTemplates( include(
__DIR__ . "/resources/templates.php" ) );
+ return true;
+ };
+
+ /**
+ * Shorthand function to retrieve a template filled with the specified
parameters.
+ *
+ * important! note that the Template class does not escape anything.
+ * be sure to escape your params before using this function!
+ *
+ * @since 0.2
+ *
+ * @param $key string template key
+ * Varargs: normal template parameters
+ *
+ * @return string
+ */
+ function wfTemplate( $key /*...*/ ) {
+ $params = func_get_args();
+ array_shift( $params );
+
+ if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+ $params = $params[0];
+ }
+
+ $template = new \Wikibase\Template(
\Wikibase\TemplateRegistry::singleton(), $key, $params );
+
+ return $template->render();
+ }
+
// Resource Loader Modules:
$wgResourceModules = array_merge( $wgResourceModules, include( __DIR__
. "/resources/Resources.php" ) );
diff --git a/lib/includes/Template.php b/repo/includes/Template.php
similarity index 100%
rename from lib/includes/Template.php
rename to repo/includes/Template.php
diff --git a/lib/includes/TemplateRegistry.php
b/repo/includes/TemplateRegistry.php
similarity index 100%
rename from lib/includes/TemplateRegistry.php
rename to repo/includes/TemplateRegistry.php
diff --git a/lib/includes/modules/TemplateModule.php
b/repo/includes/modules/TemplateModule.php
similarity index 100%
rename from lib/includes/modules/TemplateModule.php
rename to repo/includes/modules/TemplateModule.php
diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index 1f4a6cc..5418048 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -25,6 +25,17 @@
$modules = array(
+ 'jquery.ui.TemplatedWidget' => $moduleTemplate + array(
+ 'scripts' => array(
+ 'jquery.ui/jquery.ui.TemplatedWidget.js',
+ ),
+ 'dependencies' => array(
+ 'wikibase.templates',
+ 'jquery.ui.widget',
+ 'util.inherit',
+ ),
+ ),
+
'jquery.wikibase.entitysearch' => $moduleTemplate + array(
'scripts' => array(
'jquery.wikibase/jquery.wikibase.entitysearch.js',
@@ -39,6 +50,11 @@
),
),
+ 'wikibase.templates' => $moduleTemplate + array(
+ 'class' => 'Wikibase\TemplateModule',
+ 'scripts' => 'templates.js',
+ ),
+
'wikibase.ui.entityViewInit' => $moduleTemplate + array(
'scripts' => array(
'wikibase.ui.entityViewInit.js' // should
probably be adjusted for more modularity
diff --git a/lib/resources/jquery.ui/jquery.ui.TemplatedWidget.js
b/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
similarity index 100%
rename from lib/resources/jquery.ui/jquery.ui.TemplatedWidget.js
rename to repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
diff --git a/lib/resources/templates.js b/repo/resources/templates.js
similarity index 100%
rename from lib/resources/templates.js
rename to repo/resources/templates.js
diff --git a/lib/resources/templates.php b/repo/resources/templates.php
similarity index 100%
rename from lib/resources/templates.php
rename to repo/resources/templates.php
diff --git a/lib/tests/phpunit/TemplateRegistryTest.php
b/repo/tests/phpunit/TemplateRegistryTest.php
similarity index 100%
rename from lib/tests/phpunit/TemplateRegistryTest.php
rename to repo/tests/phpunit/TemplateRegistryTest.php
diff --git a/lib/tests/phpunit/TemplateTest.php
b/repo/tests/phpunit/TemplateTest.php
similarity index 100%
rename from lib/tests/phpunit/TemplateTest.php
rename to repo/tests/phpunit/TemplateTest.php
diff --git a/repo/tests/qunit/resources.php b/repo/tests/qunit/resources.php
new file mode 100644
index 0000000..fe38f43
--- /dev/null
+++ b/repo/tests/qunit/resources.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ *
+ * @codeCoverageIgnoreStart
+ */
+return call_user_func( function() {
+ $remoteExtPathParts = explode(
+ DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR,
__DIR__, 2
+ );
+ $moduleBase = array(
+ 'localBasePath' => __DIR__,
+ 'remoteExtPath' => $remoteExtPathParts[1],
+ );
+
+ $modules = array(
+ 'templates.tests' => $moduleBase + array(
+ 'scripts' => array(
+ 'templates.tests.js',
+ ),
+ 'dependencies' => array(
+ 'wikibase.templates',
+ ),
+ ),
+ );
+
+ return $modules;
+
+} );
diff --git a/lib/tests/qunit/templates.tests.js
b/repo/tests/qunit/templates.tests.js
similarity index 100%
rename from lib/tests/qunit/templates.tests.js
rename to repo/tests/qunit/templates.tests.js
--
To view, visit https://gerrit.wikimedia.org/r/172547
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic79abfbc6aa67320070061008b3a5d81d6bc5f41
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits