jenkins-bot has submitted this change and it was merged.
Change subject: Convert Parsoid extension to use extension registration
......................................................................
Convert Parsoid extension to use extension registration
* Removes the setup class to get convertExtensionToRegistration.php to
run.
* Adds Marc and Arlo to the credits.
Bug: T87956
Change-Id: I4ed79f23f408afdbff89fc8d4b7e90bec1de6ffd
---
M Parsoid.php
M ParsoidCacheUpdateJob.php
A extension.json
3 files changed, 168 insertions(+), 134 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
Legoktm: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/Parsoid.php b/Parsoid.php
index 768502a..8a4f678 100644
--- a/Parsoid.php
+++ b/Parsoid.php
@@ -1,145 +1,104 @@
<?php
-/**
- * Basic cache invalidation for Parsoid
- */
+// Needs to be called within MediaWiki; not standalone
if ( !defined( 'MEDIAWIKI' ) ) {
- echo "Parsoid extension\n";
- exit( 1 );
+ echo "Parsoid extension.\n";
+ die( -1 );
}
+
+$wgExtensionCredits['other'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'Parsoid',
+ 'author' => array(
+ 'Gabriel Wicke',
+ 'Subramanya Sastry',
+ 'Mark Holmquist',
+ 'Adam Wight',
+ 'C. Scott Ananian',
+ 'Marc Ordinas i Llopis',
+ 'Arlo Breault',
+ ),
+ 'version' => '0.2.0',
+ 'url' => 'https://www.mediawiki.org/wiki/Extension:Parsoid',
+ 'descriptionmsg' => 'parsoid-desc',
+ 'license-name' => 'GPL-2.0+',
+);
+
+$dir = __DIR__;
+
+# Set up class autoloading
+$wgAutoloadClasses['ParsoidHooks'] = "$dir/Parsoid.hooks.php";
+$wgAutoloadClasses['ParsoidCacheUpdateJob'] = "$dir/ParsoidCacheUpdateJob.php";
+$wgAutoloadClasses['CurlMultiClient'] = "$dir/CurlMultiClient.php";
+
+# Add the parsoid job types
+$wgJobClasses['ParsoidCacheUpdateJobOnEdit'] = 'ParsoidCacheUpdateJob';
+$wgJobClasses['ParsoidCacheUpdateJobOnDependencyChange'] =
'ParsoidCacheUpdateJob';
+# Old type for transition
+# @TODO: remove when old jobs are drained
+$wgJobClasses['ParsoidCacheUpdateJob'] = 'ParsoidCacheUpdateJob';
+
+# Register localizations.
+$wgMessagesDirs['Parsoid'] = $dir . '/i18n';
+$wgExtensionMessagesFiles['Parsoid'] = $dir . '/Parsoid.i18n.php';
+
+# Name modules
+$wgResourceModules += array(
+ 'ext.parsoid.styles' => array(
+ 'localBasePath' => $dir . '/modules',
+ 'remoteExtPath' => 'Parsoid/modules',
+ 'styles' => 'parsoid.styles.css',
+ 'targets' => array( 'desktop', 'mobile' ),
+ ),
+);
+
+
+// Set up default config values. Override after requiring the extension.
/**
- * Class containing basic setup functions.
+ * An array of Varnish caches in front of Parsoid to keep up to date.
+ *
+ * Formats:
+ * 'http://localhost'
+ * 'http://localhost:80'
+ * 'https://127.0.0.1:8080'
*/
-class ParsoidSetup {
- /**
- * Set up Parsoid.
- *
- * @return void
- */
- public static function setup() {
- global $wgAutoloadClasses, $wgJobClasses,
- $wgExtensionCredits, $wgExtensionMessagesFiles,
$wgMessagesDirs,
- $wgResourceModules;
+$wgParsoidCacheServers = array( 'http://localhost' );
- $dir = __DIR__;
+/**
+ * The wiki prefix sent to Parsoid. You can add these with
+ * parsoidConfig.setInterwiki in the Parsoid localsettings.js.
+ */
+$wgParsoidWikiPrefix = null;
- # Set up class autoloading
- $wgAutoloadClasses['ParsoidHooks'] = "$dir/Parsoid.hooks.php";
- $wgAutoloadClasses['ParsoidCacheUpdateJob'] =
"$dir/ParsoidCacheUpdateJob.php";
- $wgAutoloadClasses['CurlMultiClient'] =
"$dir/CurlMultiClient.php";
+/**
+ * The maximum number of backlinks (templates and files) to update.
+ */
+$wgParsoidMaxBacklinksInvalidate = false;
- # Add the parsoid job types
- $wgJobClasses['ParsoidCacheUpdateJobOnEdit'] =
'ParsoidCacheUpdateJob';
- $wgJobClasses['ParsoidCacheUpdateJobOnDependencyChange'] =
'ParsoidCacheUpdateJob';
- # Old type for transition
- # @TODO: remove when old jobs are drained
- $wgJobClasses['ParsoidCacheUpdateJob'] =
'ParsoidCacheUpdateJob';
+/**
+ * The maximum number of titles to process in a single
+ * ParsoidCacheUpdateJob
+ */
+$wgParsoidCacheUpdateTitlesPerJob = 50;
- $wgExtensionCredits['other'][] = array(
- 'path' => __FILE__,
- 'name' => 'Parsoid',
- 'author' => array(
- 'Gabriel Wicke',
- 'Subramanya Sastry',
- 'Mark Holmquist',
- 'Adam Wight',
- 'C. Scott Ananian'
- ),
- 'version' => '0.2.0',
- 'url' =>
'https://www.mediawiki.org/wiki/Extension:Parsoid',
- 'descriptionmsg' => 'parsoid-desc',
- 'license-name' => 'GPL-2.0+',
- );
-
- # Register localizations.
- $wgMessagesDirs['Parsoid'] = __DIR__ . '/i18n';
- $wgExtensionMessagesFiles['Parsoid'] = $dir .
'/Parsoid.i18n.php';
-
- # Name modules
- $wgResourceModules += array(
- 'ext.parsoid.styles' => array(
- 'localBasePath' => __DIR__ . '/modules',
- 'remoteExtPath' => 'Parsoid/modules',
- 'styles' => 'parsoid.styles.css',
- 'targets' => array( 'desktop', 'mobile' ),
- ),
- );
-
- # Set up a default configuration
- self::setupDefaultConfig();
-
- # Now register our hooks.
- self::registerHooks();
- }
+/**
+ * The portion of update requests to skip for basic load shedding. A
+ * float between 0 (none are skipped) and 1 (all are skipped).
+ */
+$wgParsoidSkipRatio = 0.0;
- /**
- * Set up default config values. Override after requiring the extension.
- *
- * @return void
- */
- protected static function setupDefaultConfig() {
- global $wgParsoidCacheServers, $wgParsoidSkipRatio, $wgDBname,
- $wgParsoidCacheUpdateTitlesPerJob,
$wgParsoidMaxBacklinksInvalidate,
- $wgParsoidWikiPrefix;
+// Register Hooks
- /**
- * An array of Varnish caches in front of Parsoid to keep up to
date.
- *
- * Formats:
- * 'http://localhost'
- * 'http://localhost:80'
- * 'https://127.0.0.1:8080'
- */
- $wgParsoidCacheServers = array( 'http://localhost' );
-
- /**
- * The wiki prefix sent to Parsoid. You can add these with
- * parsoidConfig.setInterwiki in the Parsoid localsettings.js.
- */
- $wgParsoidWikiPrefix = $wgDBname;
-
- /**
- * The maximum number of backlinks (templates and files) to
update.
- */
- $wgParsoidMaxBacklinksInvalidate = false;
-
- /**
- * The maximum number of titles to process in a single
- * ParsoidCacheUpdateJob
- */
- $wgParsoidCacheUpdateTitlesPerJob = 50;
-
- /**
- * The portion of update requests to skip for basic load
shedding. A
- * float between 0 (none are skipped) and 1 (all are skipped).
- */
- $wgParsoidSkipRatio = 0.0;
- }
-
-
- /**
- * Register hook handlers.
- *
- * @return void
- */
- protected static function registerHooks() {
- global $wgHooks;
-
- # Article edit/create
- $wgHooks['ArticleEditUpdates'][] =
'ParsoidHooks::onArticleEditUpdates';
- # Article delete/restore
- $wgHooks['ArticleDeleteComplete'][] =
'ParsoidHooks::onArticleDeleteComplete';
- $wgHooks['ArticleUndelete'][] =
'ParsoidHooks::onArticleUndelete';
- # Revision delete/restore
- $wgHooks['ArticleRevisionVisibilitySet'][] =
'ParsoidHooks::onArticleRevisionVisibilitySet';
- # Article move
- $wgHooks['TitleMoveComplete'][] =
'ParsoidHooks::onTitleMoveComplete';
- # File upload
- $wgHooks['FileUpload'][] = 'ParsoidHooks::onFileUpload';
- }
-}
-
-# Load hooks that are always set
-ParsoidSetup::setup();
+# Article edit/create
+$wgHooks['ArticleEditUpdates'][] = 'ParsoidHooks::onArticleEditUpdates';
+# Article delete/restore
+$wgHooks['ArticleDeleteComplete'][] = 'ParsoidHooks::onArticleDeleteComplete';
+$wgHooks['ArticleUndelete'][] = 'ParsoidHooks::onArticleUndelete';
+# Revision delete/restore
+$wgHooks['ArticleRevisionVisibilitySet'][] =
'ParsoidHooks::onArticleRevisionVisibilitySet';
+# Article move
+$wgHooks['TitleMoveComplete'][] = 'ParsoidHooks::onTitleMoveComplete';
+# File upload
+$wgHooks['FileUpload'][] = 'ParsoidHooks::onFileUpload';
diff --git a/ParsoidCacheUpdateJob.php b/ParsoidCacheUpdateJob.php
index 867f7af..fb86f2a 100644
--- a/ParsoidCacheUpdateJob.php
+++ b/ParsoidCacheUpdateJob.php
@@ -74,14 +74,14 @@
* @return string an absolute URL for the article on the given server
*/
protected function getParsoidURL( Title $title, $server, $prev = false
) {
- global $wgParsoidWikiPrefix;
+ global $wgParsoidWikiPrefix, $wgDBname;
$oldid = $prev ?
$title->getPreviousRevisionID( $title->getLatestRevID()
) :
$title->getLatestRevID();
// Construct Parsoid web service URL
- return $server . '/' . $wgParsoidWikiPrefix . '/' .
+ return $server . '/' . ( $wgParsoidWikiPrefix ?: $wgDBname ) .
'/' .
wfUrlencode( $title->getPrefixedDBkey() ) . '?oldid=' .
$oldid;
}
@@ -91,7 +91,7 @@
* @param $results CurlMultiClient result array
*/
protected function checkCurlResults( $results ) {
- foreach( $results as $k => $result ) {
+ foreach ( $results as $k => $result ) {
if ($results[$k]['error'] != null) {
$this->setLastError($results[$k]['error']);
return false;
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..ffc1157
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,75 @@
+{
+ "name": "Parsoid",
+ "version": "0.2.0",
+ "author": [
+ "Gabriel Wicke",
+ "Subramanya Sastry",
+ "Mark Holmquist",
+ "Adam Wight",
+ "C. Scott Ananian",
+ "Marc Ordinas i Llopis",
+ "Arlo Breault"
+ ],
+ "url": "https://www.mediawiki.org/wiki/Extension:Parsoid",
+ "descriptionmsg": "parsoid-desc",
+ "license-name": "GPL-2.0+",
+ "type": "other",
+ "JobClasses": {
+ "ParsoidCacheUpdateJobOnEdit": "ParsoidCacheUpdateJob",
+ "ParsoidCacheUpdateJobOnDependencyChange":
"ParsoidCacheUpdateJob",
+ "ParsoidCacheUpdateJob": "ParsoidCacheUpdateJob"
+ },
+ "MessagesDirs": {
+ "Parsoid": [
+ "i18n"
+ ]
+ },
+ "ExtensionMessagesFiles": {
+ "Parsoid": "Parsoid.i18n.php"
+ },
+ "AutoloadClasses": {
+ "ParsoidHooks": "Parsoid.hooks.php",
+ "ParsoidCacheUpdateJob": "ParsoidCacheUpdateJob.php",
+ "CurlMultiClient": "CurlMultiClient.php"
+ },
+ "ResourceModules": {
+ "ext.parsoid.styles": {
+ "localBasePath": "modules",
+ "remoteExtPath": "Parsoid/modules",
+ "styles": "parsoid.styles.css",
+ "targets": [
+ "desktop",
+ "mobile"
+ ]
+ }
+ },
+ "Hooks": {
+ "ArticleEditUpdates": [
+ "ParsoidHooks::onArticleEditUpdates"
+ ],
+ "ArticleDeleteComplete": [
+ "ParsoidHooks::onArticleDeleteComplete"
+ ],
+ "ArticleUndelete": [
+ "ParsoidHooks::onArticleUndelete"
+ ],
+ "ArticleRevisionVisibilitySet": [
+ "ParsoidHooks::onArticleRevisionVisibilitySet"
+ ],
+ "TitleMoveComplete": [
+ "ParsoidHooks::onTitleMoveComplete"
+ ],
+ "FileUpload": [
+ "ParsoidHooks::onFileUpload"
+ ]
+ },
+ "config": {
+ "ParsoidCacheServers": [
+ "http://localhost"
+ ],
+ "ParsoidWikiPrefix": null,
+ "ParsoidMaxBacklinksInvalidate": false,
+ "ParsoidCacheUpdateTitlesPerJob": 50,
+ "ParsoidSkipRatio": 0
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/188411
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4ed79f23f408afdbff89fc8d4b7e90bec1de6ffd
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Marcoil <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits