Clancer has uploaded a new change for review. https://gerrit.wikimedia.org/r/75109
Change subject: [WIP] Moodle Extension ...................................................................... [WIP] Moodle Extension partially implements grades page. placeholder code for tag extension. placeholder interaction with database. Change-Id: I705e052c85ebc15199c7598f278d61f399572dc8 --- A MoodleWS.alias.php A MoodleWS.body.php A MoodleWS.i18n.php A MoodleWS.php A SpecialMoodleWS.php 5 files changed, 299 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Moodle refs/changes/09/75109/1 diff --git a/MoodleWS.alias.php b/MoodleWS.alias.php new file mode 100644 index 0000000..809302f --- /dev/null +++ b/MoodleWS.alias.php @@ -0,0 +1,25 @@ +<?php +/** + * Aliases for myextension + * + * @file + * @ingroup Extensions + */ + +$specialPageAliases = array(); + +/** English + * @author Clancer + */ +$specialPageAliases[ 'en' ] = array( + 'Moodle Grades' => array( 'Moodle Grades', 'Moodle Grades' ), +); + +/** Deutsch + * @author <your username> + * +$specialPageAliases[ 'de' ] = array( + 'MyExtension' => array( 'MeineErweiterung', 'Meine Erweiterung' ), +); +*/ +?> \ No newline at end of file diff --git a/MoodleWS.body.php b/MoodleWS.body.php new file mode 100644 index 0000000..7fe9497 --- /dev/null +++ b/MoodleWS.body.php @@ -0,0 +1,4 @@ +<?php +# move stuff here soon + +?> \ No newline at end of file diff --git a/MoodleWS.i18n.php b/MoodleWS.i18n.php new file mode 100644 index 0000000..3dd1747 --- /dev/null +++ b/MoodleWS.i18n.php @@ -0,0 +1,12 @@ +<?php +$messages['en'] = array( + 'uploadwizard' => 'uploadwizard' => '{{doc-special|UploadWizard}}, + 'uploadwizard-desc' => 'Upload Wizard, a user-friendly tool for uploading multimedia' +); +$messages['qqq'] = array( + 'uploadwizard' => '{{doc-special|UploadWizard}} +UploadWizard is a wizard to upload multimedia files to a MediaWiki website. +For more information, see [[mw:UploadWizard]].', + 'uploadwizard-desc' => 'Description of extension. It refers to [//blog.wikimedia.org/blog/2009/07/02/ford-foundation-awards-300k-grant-for-wikimedia-commons/ this event], i.e. the development was paid with this $300,000 grant.' +); +?> \ No newline at end of file diff --git a/MoodleWS.php b/MoodleWS.php new file mode 100644 index 0000000..a41a35d --- /dev/null +++ b/MoodleWS.php @@ -0,0 +1,74 @@ +<?php + +//Some globals for later config +$wgMoodleWSInstance = 'local'; +$wgMoodleWSToken = 'abcdefghijklmnopqrstuv1234567890'; + +// Autoload +$wgAutoloadClasses['MoodleWS'] = __DIR__ . '/MoodleWS.body.php'; +$wgAutoloadClasses[ 'SpecialMoodleWS' ] = __DIR__ . '/SpecialMoodleWS.php'; # Location of the SpecialMoodleWS class (Tell MediaWiki to load this file) +$wgExtensionMessagesFiles[ 'MoodleWS' ] = __DIR__ . '/MoodleWS.i18n.php'; # Location of a messages file (Tell MediaWiki to load this file) +$wgExtensionMessagesFiles[ 'MoodleWSAlias' ] = __DIR__ . '/MoodleWS.alias.php'; # Location of an aliases file (Tell MediaWiki to load this file) +$wgSpecialPages[ 'MoodleWS' ] = 'SpecialMoodleWS'; # Tell MediaWiki about the new special page and its class name +$wgSpecialPageGroups[ 'MoodleWS' ] = 'other'; +/* Complex loading +$wgMyExtensionIncludes = __DIR__ . '/includes'; + +## Special page class +$wgAutoloadClasses['SpecialMyExtension'] + = $wgMyExtensionIncludes . '/SpecialMyExtension.php'; + +## Tag class +$wgAutoloadClasses['TagMyExtension'] + = $wgMyExtensionIncludes . '/TagMyExtension.php'; +*/ + +// For permissions not yet used +$wgAvailableRights[] = 'viewgrades'; +$wgGroupPermissions['user']['viewgrades'] = true; + + +// Register +$wgExtensionCredits['validextensionclass'][] = array( + 'path' => __FILE__, + 'name' => 'Example', + 'author' =>'John Doe', + 'url' => 'https://www.mediawiki.org/wiki/Extension:Example', + 'description' => 'This extension is an example and performs no discernible function', + 'version' => 1.5, + ); + +$wgHooks['ParserFirstCallInit'][] = 'wfSampleParserInit'; + +// Hook our callback function into the parser +function wfSampleParserInit( Parser $parser ) { + // When the parser sees the <sample> tag, it executes + // the wfSampleRender function (see below) + $parser->setHook( 'sample', 'wfSampleRender' ); + // Always return true from this function. The return value does not denote + // success or otherwise have meaning - it just must always be true. + return true; +} + +// Execute +function wfSampleRender( $input, array $args, Parser $parser, PPFrame $frame ) { + $parser->disableCache(); + + global $wgMoodleWSInstance; + + //$output = $parser->recursiveTagParse( $text, $frame ); + //return '<div class="wonderful">' . $output . '</div>'; + + $attr = array(); + // This time, make a list of attributes and their values, + // and dump them, along with the user input + foreach( $args as $name => $value ) + $attr[] = '<strong>' . htmlspecialchars( $name ) . '</strong> = ' . htmlspecialchars( $value ); + return implode( '<br />', $attr ) . "\n\n" . htmlspecialchars( $input ) . $wgMoodleWSInstance; + +/* The following lines can be used to get the variable values directly: + $to = $args['to'] ; + $email = $args['email'] ; +*/ +} +?> \ No newline at end of file diff --git a/SpecialMoodleWS.php b/SpecialMoodleWS.php new file mode 100644 index 0000000..7a1edc0 --- /dev/null +++ b/SpecialMoodleWS.php @@ -0,0 +1,184 @@ +<?php +# reference: http://www.mediawiki.org/wiki/Extension:PageSecurity/Create_the_database_tables shows can ask user to create own tables +# reference: http://www.mediawiki.org/wiki/Extension:GetUserName shows how to get username from user objects, also magic word extension + +# notes: + # the queries probably need sanitising as the user is asked to enter their moodle details when setting up grades access + # in addition their mediawiki usernae is also used in the original select query + # + # there is a function to return to main page instead of the hack used in cancel but cant remember it +class SpecialMoodleWS extends SpecialPage { + function __construct() { + //parent::__construct( 'MoodleWS' ); + // To implement permissions (wont show up in specialpages list) for this page + parent::__construct( 'MoodleWS', 'viewgrades' ); + } + + // WIP + function newMoodleUser () { + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin(); + /* Do queries */ + $res = $dbw->insert( + 'moodleUsers', + array('name'=>'rohan'), + __METHOD__, + array() + ); + $dbw->commit(); + //function insert( $table, $a, $fname = 'Database::insert', $options = array() ); + } + + function execute( $par ) { + //execute permission implementation (will give restriction error on direct url access) + if ( !$this->userCanExecute( $this->getUser() ) ) { + $this->displayRestrictionError(); + return; + } + + global $wgMoodleWSInstance; + global $wgMoodleWSToken; + global $wgUser; + + $request = $this->getRequest(); + $output = $this->getOutput(); + $this->setHeaders(); + + # Handle Cancel + if ( $request->wasPosted() && $request->getBool( 'wpCancel' ) ) { + $titleObj = Title::newMainPage(); + $query = $request->getVal( 'returntoquery' ); + $this->getOutput()->redirect( $titleObj->getFullURL( $query ) ); + //$wikitexttest = '\'\'\'Cancel\'\'\''; + //$output->addWikiText( $wikitexttest ); + return; + } + + # To avoid potential database delay the form should post the moodle user data to be used initially + # this should also allow a one time login check to validate the information before associating the user + # and the moodle user in the database + if ( $request->wasPosted() ) { + # perform moodle login check + + # new moodle user + + # query display grades as normal with user info + } else { + + # Get request data from, e.g. + // $param = $request->getText( 'param' ); + + // WIP + // Get relevant information for getting grades via Moodle Web Service + /*$dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( + 'moodleUsers', // $table + array( 'mwname', 'moname' ), // $vars (columns of the table) + 'mwname = ' . $wgUser->getName(), // $conds + __METHOD__, // $fname = 'Database::select', + array() // $options = array() + );*/ + /* Test Output + $output = ''; + foreach( $res as $row ) { + $output .= 'Category ' . $row->cat_title . ' contains ' . $row->cat_pages . " entries.\n"; + } + */ + + # Do stuff + # ... + + // If Found user (WIP) + + // Test call to outside using info set in localsettings.php + // Will later use name from table to get grades + $url = $wgMoodleWSInstance . "webservice/rest/server.php?wstoken=" . $wgMoodleWSToken . "&wsfunction=core_webservice_get_site_info"; + //$url = "http://sandbox.wikiversity.wmflabs.org/moodle/webservice/rest/server.php?wstoken=a133c830a3bbc54a41446740797852eb&wsfunction=core_webservice_get_site_info"; + $req = MWHttpRequest::factory ($url, $options=null); + # $options=array("postData"=>array()) + $status = $req->execute(); + $content = $req->getContent(); + + $wikitext = 'Hello world!' . $content . $url; + $output->addWikiText( $wikitext ); + + // Else allow user to link their moodle account + $this->showRegisterForm(); + } + + } + + // Needs Messages + // Uses structure taken from: SpecialChangePassword.php + function showRegisterForm() { + global $wgUser; + + $prettyFields = array( + array( 'wpName', 'username', 'text', $wgUser->getName() ), + array( 'Moodle Name', 'moodleusername', 'input', null ), + array( 'Moodle Password', 'moodlepassword', 'password', null ), + ); + + $this->getOutput()->addHTML( + Xml::fieldset( $this->msg( 'resetpass_header' )->text() ) . + Xml::openElement( 'form', + array( + 'method' => 'post', + 'action' => $this->getTitle()->getLocalURL(), + 'id' => 'mw-resetpass-form' ) ) . "\n" . + //$hiddenFieldsStr . + //$this->msg( 'resetpass_text' )->parseAsBlock() . "\n" . + Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" . + $this->pretty( $prettyFields ) . "\n" . + //$rememberMe . + "<tr>\n" . + "<td></td>\n" . + '<td class="mw-input">' . + Xml::submitButton( $this->msg( 'moodlews-register' )->text() ) . + Xml::submitButton( $this->msg( 'resetpass-submit-cancel' )->text(), array( 'name' => 'wpCancel' ) ) . + "</td>\n" . + "</tr>\n" . + Xml::closeElement( 'table' ) . + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) . "\n" + ); + } + + /** + * pretty function used in SpecialChangePassword, adapted to autofocus Moodle Name + * @param $fields array + * @return string + */ + function pretty( $fields ) { + $out = ''; + foreach ( $fields as $list ) { + list( $name, $label, $type, $value ) = $list; + if ( $type == 'text' ) { + $field = htmlspecialchars( $value ); + } else { + $attribs = array( 'id' => $name ); + if ( $name == 'Moodle Name' ) { + $attribs[] = 'autofocus'; + } + $field = Html::input( $name, $value, $type, $attribs ); + } + $out .= "<tr>\n"; + $out .= "\t<td class='mw-label'>"; + + if ( $type != 'text' ) { + $out .= Xml::label( $this->msg( $label )->text(), $name ); + } else { + $out .= $this->msg( $label )->escaped(); + } + + $out .= "</td>\n"; + $out .= "\t<td class='mw-input'>"; + $out .= $field; + $out .= "</td>\n"; + $out .= "</tr>"; + } + + return $out; + } +} +?> \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/75109 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I705e052c85ebc15199c7598f278d61f399572dc8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Moodle Gerrit-Branch: master Gerrit-Owner: Clancer <rohan.j.ve...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits