jenkins-bot has submitted this change and it was merged.

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


Convert Quiz to use extension registration

Bug: T87963
Change-Id: I041814e2788f238c8840f60132784e2bda6a04bc
---
A Quiz.hooks.php
M Quiz.php
A extension.json
3 files changed, 79 insertions(+), 63 deletions(-)

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



diff --git a/Quiz.hooks.php b/Quiz.hooks.php
new file mode 100644
index 0000000..84806fb
--- /dev/null
+++ b/Quiz.hooks.php
@@ -0,0 +1,30 @@
+<?php
+
+class QuizHooks {
+
+       /**
+        * Register the extension with the WikiText parser.
+        * The tag used is <quiz>
+        * @param $parser Parser the wikitext parser
+        * @return Boolean true to continue hook processing
+       */
+       public static function onParserFirstCallInit( &$parser ) {
+               $parser->setHook( 'quiz', 'QuizHooks::renderQuiz' );
+               return true;
+       }
+
+       /**
+        * Call the quiz parser on an input text.
+        *
+        * @param $input String text between <quiz> and </quiz> tags, in quiz 
syntax.
+        * @param $argv Array an array containing any arguments passed to the 
extension
+        * @param $parser Parser the wikitext parser.
+        *
+        * @return string An HTML quiz.
+       */
+       public static function renderQuiz( $input, $argv, $parser ) {
+               $parser->disableCache();
+               $quiz = new Quiz( $argv, $parser );
+               return $quiz->parseQuiz( $input );
+       }
+}
diff --git a/Quiz.php b/Quiz.php
index b92e37f..0bd73c0 100644
--- a/Quiz.php
+++ b/Quiz.php
@@ -35,67 +35,14 @@
 if ( !defined( 'MEDIAWIKI' ) ) {
        die( 'This is not a valid entry point to MediaWiki.' );
 }
-
-/**
- * Extension credits that will show up on Special:Version
- */
-$wgExtensionCredits['parserhook'][] = array(
-       'path'           => __FILE__,
-       'name'           => 'Quiz',
-       'version'        => '1.2.0',
-       'author'         => 'Louis-Rémi Babe',
-       'url'            => 'https://www.mediawiki.org/wiki/Extension:Quiz',
-       'descriptionmsg' => 'quiz_desc',
-       'license-name'   => 'GPL-2.0+'
-);
-
-/**
- * Add this extension to MediaWiki's extensions list.
- */
-$dir = __DIR__ . '/';
-$wgAutoloadClasses['Quiz'] = $dir . 'Quiz.class.php';
-$wgAutoloadClasses['Question'] = $dir . 'Quiz.class.php';
-$wgMessagesDirs['QuizExtension'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['QuizExtension'] = $dir . 'Quiz.i18n.php';
-
-$wgHooks['ParserFirstCallInit'][] = 'wfQuizExtension';
-$wgHooks['ParserClearState'][] = 'Quiz::resetQuizID';
-
-$commonModuleInfo = array(
-       'localBasePath' => dirname( __FILE__ ) . '/modules',
-       'remoteExtPath' => 'Quiz/modules',
-);
-
-// Styles and any code common to all Special:Code subviews:
-$wgResourceModules['ext.quiz'] = array(
-       'scripts' => 'ext.quiz.js',
-       'styles' => 'ext.quiz.css',
-       'position' => 'top',
-) + $commonModuleInfo;
-
-/**
- * Register the extension with the WikiText parser.
- * The tag used is <quiz>
- *
- * @param $parser Parser the wikitext parser
- * @return Boolean true to continue hook processing
- */
-function wfQuizExtension( &$parser ) {
-       $parser->setHook( 'quiz', 'renderQuiz' );
-       return true;
-}
-
-/**
- * Call the quiz parser on an input text.
- *
- * @param $input String text between <quiz> and </quiz> tags, in quiz syntax.
- * @param $argv Array an array containing any arguments passed to the extension
- * @param $parser Parser the wikitext parser.
- *
- * @return string An HTML quiz.
- */
-function renderQuiz( $input, $argv, $parser ) {
-       $parser->disableCache();
-       $quiz = new Quiz( $argv, $parser );
-       return $quiz->parseQuiz( $input );
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'Quiz' );
+       $wgMessagesDirs['QuizExtension'] = __DIR__ . '/i18n';
+       /* wfWarn(
+               'Deprecated PHP entry point used for Quiz extension. Please use 
wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       ); */
+       return;
+} else {
+       die( 'This version of the Quiz extension requires MediaWiki 1.25+' );
 }
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..e530ae2
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,39 @@
+{
+       "name": "Quiz",
+       "version": "1.2.0",
+       "author": "Louis-Rémi Babe",
+       "url": "https://www.mediawiki.org/wiki/Extension:Quiz";,
+       "descriptionmsg": "quiz_desc",
+       "license-name": "GPL-2.0+",
+       "type": "parserhook",
+       "MessagesDirs": {
+               "QuizExtension": [
+                       "i18n"
+               ]
+       },
+       "AutoloadClasses": {
+               "Quiz": "Quiz.class.php",
+               "Question": "Quiz.class.php",
+               "QuizHooks": "Quiz.hooks.php"
+       },
+       "ResourceModules": {
+               "ext.quiz": {
+                       "scripts": "ext.quiz.js",
+                       "styles": "ext.quiz.css",
+                       "position": "top"
+               }
+       },
+       "ResourceFileModulePaths": {
+               "localBasePath": "modules",
+               "remoteExtPath": "Quiz/modules"
+       },
+       "Hooks": {
+               "ParserFirstCallInit": [
+                       "QuizHooks::onParserFirstCallInit"
+               ],
+               "ParserClearState": [
+                       "Quiz::resetQuizID"
+               ]
+       },
+       "manifest_version": 1
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I041814e2788f238c8840f60132784e2bda6a04bc
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Ananay <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to