Brian Wolff has submitted this change and it was merged. Change subject: Stylize ......................................................................
Stylize Change-Id: Ib68918ab6f809f6b2985210135597eb29eaac70b --- M MoodleWS.alias.php M MoodleWS.body.php M MoodleWS.i18n.php M MoodleWS.php M SpecialMoodleWS.php M moodleusers.sql 6 files changed, 180 insertions(+), 196 deletions(-) Approvals: Brian Wolff: Verified; Looks good to me, approved Nemo bis: Looks good to me, but someone else must approve diff --git a/MoodleWS.alias.php b/MoodleWS.alias.php index cb6e76e..0f4e6ef 100644 --- a/MoodleWS.alias.php +++ b/MoodleWS.alias.php @@ -5,21 +5,12 @@ * @file * @ingroup Extensions */ - + $specialPageAliases = array(); - + /** English * @author Clancer */ -$specialPageAliases[ 'en' ] = array( - 'Moodle Grades' => array( 'Moodle Grades', 'Moodle Grades' ), +$specialPageAliases['en'] = array( + 'Moodle Grades' => array( '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 index 5c7a7dc..758092e 100644 --- a/MoodleWS.body.php +++ b/MoodleWS.body.php @@ -1,20 +1,19 @@ <?php # move stuff here soon class MoodleWS { - public static function setupSchema( DatabaseUpdater $updater ) { - $updater->addExtensionTable( 'moodleusers', "/moodleusers.sql" ); + public static function setupSchema( DatabaseUpdater $updater ) { + $updater->addExtensionTable( 'moodleusers', "/moodleusers.sql" ); -$file = 'people.txt'; -// Open the file to get existing content -$current = file_get_contents($file); -// Append a new person to the file -$current .= "John Smith\n"; -// Write the contents back to the file -file_put_contents($file, $current); + $file = 'people.txt'; + // Open the file to get existing content + $current = file_get_contents( $file ); + // Append a new person to the file + $current .= "John Smith\n"; + // Write the contents back to the file + file_put_contents( $file, $current ); - return true; - } + return true; + } } -?> diff --git a/MoodleWS.i18n.php b/MoodleWS.i18n.php index 62e8cec..d276cc6 100644 --- a/MoodleWS.i18n.php +++ b/MoodleWS.i18n.php @@ -5,4 +5,3 @@ $messages['qqq'] = array( '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.' ); -?> diff --git a/MoodleWS.php b/MoodleWS.php index e7b1310..e14a076 100644 --- a/MoodleWS.php +++ b/MoodleWS.php @@ -1,6 +1,6 @@ <?php -//Some globals for later config +// Some globals for later config $wgMoodleWSInstance = 'localhost/moodle/'; $wgMoodleWSToken = '695a8fecb18fb61c2a8bef28080830de'; $wgMoodleWSServiceShortname = 'moodle_mobile_app'; @@ -17,11 +17,11 @@ /* Complex loading $wgMyExtensionIncludes = __DIR__ . '/includes'; - + ## Special page class -$wgAutoloadClasses['SpecialMyExtension'] +$wgAutoloadClasses['SpecialMyExtension'] = $wgMyExtensionIncludes . '/SpecialMyExtension.php'; - + ## Tag class $wgAutoloadClasses['TagMyExtension'] = $wgMyExtensionIncludes . '/TagMyExtension.php'; @@ -33,55 +33,52 @@ // 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, +$wgExtensionCredits['specialpage'][] = array( + 'path' => __FILE__, + 'name' => 'Moodle', + 'author' => 'Clancer', + 'url' => 'https://www.mediawiki.org/wiki/Extension:Moodle', + 'description' => 'Moodle integration', + 'version' => 0.1, ); - + $wgHooks['ParserFirstCallInit'][] = 'wfSampleParserInit'; -//$wgHooks['LoadExtensionSchemaUpdates'][] = 'MoodleWS::setupSchema'; +// $wgHooks['LoadExtensionSchemaUpdates'][] = 'MoodleWS::setupSchema'; /*$wgHooks['LoadExtensionSchemaUpdates'][] = 'fnMyHook'; function fnMyHook( DatabaseUpdater $updater ) { $updater->addExtensionTable( 'moodleusers', dirname( __FILE__ ) . '/moodleusers.sql', true ); return true; }*/ - + // 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; + // 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 + +// 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; - + $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'] ; } - - -?> diff --git a/SpecialMoodleWS.php b/SpecialMoodleWS.php index 2d57fcf..87bf6b8 100644 --- a/SpecialMoodleWS.php +++ b/SpecialMoodleWS.php @@ -8,138 +8,137 @@ # # 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 - # will get sanitised username and password from post - function newMoodleUser () { - global $wgUser; + function __construct() { + # parent::__construct( 'MoodleWS' ); + # To implement permissions (wont show up in specialpages list) for this page + parent::__construct( 'MoodleWS', 'viewgrades' ); + } - $dbw = wfGetDB( DB_MASTER ); - $dbw->begin(); - # Do queries - $res = $dbw->insert( - 'moodleusers', - array('moodle_id'=>'****', - 'mediawiki_id' => $wgUser->getID() - ), - __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 $wgMoodleWSServiceShortname; - 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 ) ); - return; - } - - ## WIP - # 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 (needs to get username and password from post) - $url = "http://" . $wgMoodleWSInstance . "login/token.php?username=*****&password=******&service=" . $wgMoodleWSServiceShortname; - - $content = Http::request( 'POST', $url, $params ); - $obj2 = json_decode($content, true); - if (is_null($obj2['error'])) { - $wikitext = 'Hello world!' . $content . $url; - $this->newMoodleUser(); - } else { - $wikitext = 'uh oh' . $obj2['error'] . $url; - } - $output->addWikiText( $wikitext ); - - # new moodle user - - # query display grades as normal with user info - } else { - - # WIP - # Get relevant information for getting grades via Moodle Web Service - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( - 'moodleusers', # $table - array( 'moodle_id', 'mediawiki_id' ), # $vars (columns of the table) - 'mediawiki_id = ' . $wgUser->getID(), # $conds - __METHOD__, # $fname = 'Database::select', - array() # $options = array() - ); - # Test Output - $found = false; - foreach( $res as $row ) { - if (!is_null($row->moodle_id)) { - $output->addWikiText( "current id: " . $wgUser->getID() . " from database: " . $row->mediawiki_id . " moodle: " . $row->moodle_id ); - $found = true; - } - } - if ($found) { - - # If Found user (WIP) - # This currently needs two modifications to a core installation of moodle - # the first is to get a userid from a username - # the second is to be able to get grades from a course - # I am currently working on my own implementation of these that can be added - # to webservices it will be documented soon - /*$functionname = 'core_user_get_users_by_id';#'core_course_get_courses'; - - - # Test call to outside using info set in localsettings.php - # Will later use name from table to get grades - $getparam = "&userids[]=2"; - $url = "http://" . $wgMoodleWSInstance . "webservice/rest/server.php?wstoken=" . $wgMoodleWSToken . '&wsfunction='.$functionname . $getparam; - $req = MWHttpRequest::factory ($url, $options=null); - $status = $req->execute(); - $content = $req->getContent(); - $wikitext = $wgUser->getID() . 'Hello world!' . $content . $url; - $output->addWikiText( $wikitext ); - */ - } else { - # Else allow user to link their moodle account - $this->showRegisterForm(); - } - } - - } - - # WIP - # Needs Messages - # Uses structure taken from: SpecialChangePassword.php - function showRegisterForm() { + # WIP + # will get sanitised username and password from post + function newMoodleUser () { global $wgUser; - + + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin(); + # Do queries + $res = $dbw->insert( + 'moodleusers', + array( 'moodle_id' => '****', + 'mediawiki_id' => $wgUser->getID() + ), + __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 $wgMoodleWSServiceShortname; + 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 ) ); + return; + } + + ## WIP + # 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 (needs to get username and password from post) + $url = "http://" . $wgMoodleWSInstance . "login/token.php?username=*****&password=******&service=" . $wgMoodleWSServiceShortname; + + $content = Http::request( 'POST', $url, $params ); + $obj2 = json_decode( $content, true ); + if ( is_null( $obj2['error'] ) ) { + $wikitext = 'Hello world!' . $content . $url; + $this->newMoodleUser(); + } else { + $wikitext = 'uh oh' . $obj2['error'] . $url; + } + $output->addWikiText( $wikitext ); + + # new moodle user + + # query display grades as normal with user info + } else { + + # WIP + # Get relevant information for getting grades via Moodle Web Service + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( + 'moodleusers', # $table + array( 'moodle_id', 'mediawiki_id' ), # $vars (columns of the table) + 'mediawiki_id = ' . $wgUser->getID(), # $conds + __METHOD__, # $fname = 'Database::select', + array() # $options = array() + ); + # Test Output + $found = false; + foreach ( $res as $row ) { + if ( !is_null( $row->moodle_id ) ) { + $output->addWikiText( "current id: " . $wgUser->getID() . " from database: " . $row->mediawiki_id . " moodle: " . $row->moodle_id ); + $found = true; + } + } + if ( $found ) { + + # If Found user (WIP) + # This currently needs two modifications to a core installation of moodle + # the first is to get a userid from a username + # the second is to be able to get grades from a course + # I am currently working on my own implementation of these that can be added + # to webservices it will be documented soon + /*$functionname = 'core_user_get_users_by_id';#'core_course_get_courses'; + + + # Test call to outside using info set in localsettings.php + # Will later use name from table to get grades + $getparam = "&userids[]=2"; + $url = "http://" . $wgMoodleWSInstance . "webservice/rest/server.php?wstoken=" . $wgMoodleWSToken . '&wsfunction='.$functionname . $getparam; + $req = MWHttpRequest::factory ($url, $options=null); + $status = $req->execute(); + $content = $req->getContent(); + $wikitext = $wgUser->getID() . 'Hello world!' . $content . $url; + $output->addWikiText( $wikitext ); + */ + } else { + # Else allow user to link their moodle account + $this->showRegisterForm(); + } + } + } + + # WIP + # 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', @@ -147,11 +146,11 @@ 'method' => 'post', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-resetpass-form' ) ) . "\n" . - #$hiddenFieldsStr . - #$this->msg( 'resetpass_text' )->parseAsBlock() . "\n" . + # $hiddenFieldsStr . + # $this->msg( 'resetpass_text' )->parseAsBlock() . "\n" . Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" . $this->pretty( $prettyFields ) . "\n" . - #$rememberMe . + # $rememberMe . "<tr>\n" . "<td></td>\n" . '<td class="mw-input">' . @@ -164,7 +163,7 @@ Xml::closeElement( 'fieldset' ) . "\n" ); } - + /** * pretty function used in SpecialChangePassword, adapted to autofocus Moodle Name * @param $fields array @@ -202,4 +201,3 @@ return $out; } } -?> diff --git a/moodleusers.sql b/moodleusers.sql index 0260b55..a7d98b6 100644 --- a/moodleusers.sql +++ b/moodleusers.sql @@ -3,6 +3,6 @@ moodle_id int(10) unsigned NOT NULL, -- ID of mediawiki user associated with moodle account mediawiki_id varchar(255) binary NOT NULL, - + PRIMARY KEY mediawiki_id (mediawiki_id) ) /*$wgDBTableOptions*/; -- To view, visit https://gerrit.wikimedia.org/r/94129 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib68918ab6f809f6b2985210135597eb29eaac70b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Moodle Gerrit-Branch: master Gerrit-Owner: Brian Wolff <bawolff...@gmail.com> Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com> Gerrit-Reviewer: Nemo bis <federicol...@tiscali.it> Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: jan <j...@jans-seite.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits