jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/338708 )

Change subject: Convert to extension registration
......................................................................


Convert to extension registration

Add extension.json and refactor the main code into a Hooks class.

Change-Id: I5de7bd3d9779bd6bd8452ea48076abf613c67099
---
M CHANGES
D ExternalArticles.php
A extension.json
A src/Hooks.php
4 files changed, 126 insertions(+), 148 deletions(-)

Approvals:
  jenkins-bot: Verified
  Samwilson: Looks good to me, approved



diff --git a/CHANGES b/CHANGES
index 213c460..cab6d11 100755
--- a/CHANGES
+++ b/CHANGES
@@ -1,28 +1,31 @@
-== 2013-05-31 version 0.1.4 ==
-* Updated to use the MWHttpRequest class (increasing the MediaWiki version
-  requirement to 1.17 when this class was introduced).
-* Code formatting.
-* Code moved to Git.
-* Extension adopted by User:Samwilson (with Nate's permission).
-* In-code license updated to GPL version 3 (to be consistent with the licence
-  named elsewhere).
-
-== 2010-03-05 version 0.1.3 ==
-* Removed dependence on PHP config "allow_url_fopen" by changing to use cURL.
-  Thanks to [[User:Alvinos|Alvinos]].
-
-== Version 0.1.2 ==
-* Rephrased errors, added todo's and other minor changes.
-
-== Version 0.1.1 ==
-* Modified the $wgExtensionCredits:
-  Bug: hmm... defined the 'author' element twice when I meant 'url' the second
-  time.
-  Bug: The url specified was incorrect.
-  Added a contact email address specific to this extension.
-
-== Version 0.1 ==
-* Preloads text into an edit box on article edit.
-* Configure external wiki to draw text from (defaults to Wikipedia).
-* Configure perl-compatible regular expression to include or exclude certain
-  pages (defaults to Templates only).
+== 2017-02-21 version 0.3.0 ==
+* Switch to use the extension registration system (and therefore increase 
MediaWiki version requirement to 1.24).
+
+== 2013-05-31 version 0.1.4 ==
+* Updated to use the MWHttpRequest class (increasing the MediaWiki version
+  requirement to 1.17 when this class was introduced).
+* Code formatting.
+* Code moved to Git.
+* Extension adopted by User:Samwilson (with Nate's permission).
+* In-code license updated to GPL version 3 (to be consistent with the licence
+  named elsewhere).
+
+== 2010-03-05 version 0.1.3 ==
+* Removed dependence on PHP config "allow_url_fopen" by changing to use cURL.
+  Thanks to [[User:Alvinos|Alvinos]].
+
+== Version 0.1.2 ==
+* Rephrased errors, added todo's and other minor changes.
+
+== Version 0.1.1 ==
+* Modified the $wgExtensionCredits:
+  Bug: hmm... defined the 'author' element twice when I meant 'url' the second
+  time.
+  Bug: The url specified was incorrect.
+  Added a contact email address specific to this extension.
+
+== Version 0.1 ==
+* Preloads text into an edit box on article edit.
+* Configure external wiki to draw text from (defaults to Wikipedia).
+* Configure perl-compatible regular expression to include or exclude certain
+  pages (defaults to Templates only).
diff --git a/ExternalArticles.php b/ExternalArticles.php
deleted file mode 100644
index 74f3cc3..0000000
--- a/ExternalArticles.php
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/**
- * ExternalArticles.php
- *
- * The ExternalArticles extension fetches pages from a remote wiki.
- *
- * Copyright (C) 2009-2013 the authors listed below.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @ingroup Extensions
- * @author Nathan Perry <[email protected]>
- * @author Alvinos https://www.mediawiki.org/wiki/User:Alvinos
- * @author Sam Wilson <[email protected]>
- * @link http://www.nateperry.org/wiki/External_Articles
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
- * @file
- */
-/**
- * Protect against register_globals vulnerabilities.
- * This line must be present before any global variable is referenced.
- */
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo <<<EOT
-This file is not a valid entry point.
-To install this extension, put the following line in LocalSettings.php:
-require_once( "\$IP/extensions/ExternalArticles/ExternalArticles.php" );
-EOT;
-       exit( 1 );
-}
-
-/**
- * Extension setup.
- */
-$wgExtensionCredits['other'][] = array(
-       'path' => __FILE__,
-       'name' => 'External Articles',
-       'descriptionmsg' => 'externalarticles-desc',
-       'version' => '0.2.0', // version date 2014-03-31
-       'author' => array( 'Nathan Perry', 'Alvinos', 'Sam Wilson' ),
-       'url' => 'https://www.mediawiki.org/wiki/Extension:ExternalArticles'
-);
-$wgExtensionMessagesFiles['ExternalArticles'] = dirname( __FILE__ ) . 
'/ExternalArticles.i18n.php';
-$wgHooks['EditFormPreloadText'][] = 'ExternalArticles_EditFormPreloadText';
-
-$wgMessagesDirs['ExternalArticles'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['ExternalArticles'] = __DIR__ . 
'/ExternalArticles.i18n.php';
-
-// @todo: change this so each setting is set to it's default if it is not 
defined.
-//       Currently, if anything is overridden, all must be defined.
-if ( !isset( $eagRules ) || is_null( $eagRules ) ) {
-       $eagRules = array();
-       $eagRules['onpreload'] = true;
-       $eagRules['url'] = 'https://en.wikipedia.org/w/index.php?title=';
-
-       // @todo: remove assumption of English.
-       $eagRules['rule'] = '/^Template:.*$/'; // 
http://us3.php.net/manual/en/function.preg-match.php
-} else {
-       // @todo: validate $eagRules URL's, etc...
-}
-
-
-/**
- * Preload text from a remote wiki into the edit form. Called when edit page 
for
- * a new article is shown.
- *
- * @global OutputPage $wgOut OutputPage object for HTTP response
- * @global array $eagRules ExternalArticles configuration array
- * @param string $text Text with which to prefill the edit form
- * @param Title $title Title of the new page
- * @return boolean
- */
-function ExternalArticles_EditFormPreloadText( &$text, &$title ) {
-       global $wgOut, $eagRules;
-
-       $pagename = $title->getPrefixedURL();
-       $url = $eagRules['url'] . $pagename . '&action=raw';
-       $ismatch = preg_match( $eagRules['rule'], $pagename ) > 0;
-
-       if ( defined( 'EXTERNALARTICLES_DEBUG' ) ) {
-               if ( $ismatch ) {
-                       $wgOut->addWikiText( "URL: $url<br />" );
-               } else {
-                       $wgOut->addWikiText( "Page title does not match 
rule.<br />" );
-               }
-       }
-
-       if ( $eagRules['onpreload'] && $ismatch && empty( $text ) ) {
-               $options = array(
-                       'followRedirects' => true,
-               );
-               $httpRequest = MWHttpRequest::factory( $url, $options );
-               $status = $httpRequest->execute();
-               if ( !$status->isOK() ) {
-                       if ( defined( 'EXTERNALARTICLES_DEBUG' ) ) {
-                               $wgOut->addWikiText( "Failed to fetch external 
page: " . $status->getWikiText() );
-                       }
-                       return false;
-               }
-               $wgOut->wrapWikiMsg('<div class="success">$1</div>', 
array('externalarticles-article-loaded', $url));
-               $text = $httpRequest->getContent();
-
-               return true;
-       }
-       return true;
-}
-
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..43050ab
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,24 @@
+{
+       "name": "ExternalArticles",
+       "version": "0.3.0",
+       "author": [
+               "Nathan Perry",
+               "Alvinos",
+               "Sam Wilson"
+       ],
+       "url": "http://www.mediawiki.org/wiki/Extension:ExternalArticles";,
+       "descriptionmsg": "externalarticles-desc",
+       "type": "extension",
+       "AutoloadClasses": {
+               "MediaWiki\\Extensions\\ExternalArticles\\Hooks": 
"src/Hooks.php"
+       },
+       "MessagesDirs": {
+               "ExternalArticles": [
+                       "i18n"
+               ]
+       },
+       "Hooks": {
+               "EditFormPreloadText": 
"MediaWiki\\Extensions\\ExternalArticles\\Hooks::onEditFormPreloadText"
+       },
+       "manifest_version": 1
+}
diff --git a/src/Hooks.php b/src/Hooks.php
new file mode 100644
index 0000000..709373e
--- /dev/null
+++ b/src/Hooks.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace MediaWiki\Extensions\ExternalArticles;
+
+use MWHttpRequest;
+use OutputPage;
+use Title;
+
+class Hooks {
+
+       /**
+        * Preload text from a remote wiki into the edit form. Called when edit 
page for
+        * a new article is shown.
+        *
+        * @global OutputPage $wgOut OutputPage object for HTTP response
+        * @global array $eagRules ExternalArticles configuration array
+        * @param string &$text Text with which to prefill the edit form
+        * @param Title &$title Title of the new page
+        * @return boolean
+        */
+       function onEditFormPreloadText( &$text, Title &$title ) {
+               global $wgOut, $eagRules;
+
+               // @todo: change this so each setting is set to it's default if 
it is not defined.
+               // Currently, if anything is overridden, all must be defined.
+               if ( !isset( $eagRules ) || is_null( $eagRules ) ) {
+                       $eagRules = [];
+                       $eagRules['onpreload'] = true;
+                       $eagRules['url'] = 
'https://en.wikipedia.org/w/index.php?title=';
+
+                       // @todo: remove assumption of English.
+                       $eagRules['rule'] = '/^Template:.*$/';
+               } else {
+                       // @todo: validate $eagRules URL's, etc...
+               }
+
+               $pagename = $title->getPrefixedURL();
+               $url = $eagRules['url'] . $pagename . '&action=raw';
+               $ismatch = preg_match( $eagRules['rule'], $pagename ) > 0;
+
+               if ( defined( 'EXTERNALARTICLES_DEBUG' ) ) {
+                       if ( $ismatch ) {
+                               $wgOut->addWikiText( "URL: $url<br />" );
+                       } else {
+                               $wgOut->addWikiText( "Page title does not match 
rule.<br />" );
+                       }
+               }
+
+               if ( $eagRules['onpreload'] && $ismatch && empty( $text ) ) {
+                       $options = [
+                               'followRedirects' => true,
+                       ];
+                       $httpRequest = MWHttpRequest::factory( $url, $options );
+                       $status = $httpRequest->execute();
+                       if ( !$status->isOK() ) {
+                               if ( defined( 'EXTERNALARTICLES_DEBUG' ) ) {
+                                       $wgOut->addWikiText( "Failed to fetch 
external page: " . $status->getWikiText() );
+                               }
+
+                               return false;
+                       }
+                       $wgOut->wrapWikiMsg( '<div class="success">$1</div>',
+                               [ 'externalarticles-article-loaded', $url ] );
+                       $text = $httpRequest->getContent();
+
+                       return true;
+               }
+
+               return true;
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/338708
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5de7bd3d9779bd6bd8452ea48076abf613c67099
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ExternalArticles
Gerrit-Branch: master
Gerrit-Owner: Samwilson <[email protected]>
Gerrit-Reviewer: Samwilson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to