r106611 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106610‎ | r106611 | r106612 >
Date:23:34, 18 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on course and term management
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMentor.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditCourse.php (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditTerm.php (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutions.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerm.php (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerms.php (added) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php
@@ -23,6 +23,10 @@
2424 'Students' => array( 'Students' ),
2525 'Course' => array( 'Course' ),
2626 'Courses' => array( 'Courses' ),
 27+ 'Term' => array( 'Term' ),
 28+ 'Terms' => array( 'Terms' ),
2729 'EducationProgram' => array( 'EducationProgram' ),
 30+ 'EditCourse' => array( 'EditCourse' ),
2831 'EditInstitution' => array( 'EditInstitution' ),
 32+ 'EditTerm' => array( 'EditTerm' ),
2933 );
Index: trunk/extensions/EducationProgram/specials/SpecialTerms.php
@@ -0,0 +1,130 @@
 2+<?php
 3+
 4+/**
 5+ * Page listing all terms in a pager with filter control.
 6+ * Also has a form for adding new items for those with matching priviliges.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file SpecialTerms.php
 11+ * @ingroup EducationProgram
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class SpecialTerms extends SpecialEPPage {
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 0.1
 22+ */
 23+ public function __construct() {
 24+ parent::__construct( 'Terms' );
 25+ }
 26+
 27+ /**
 28+ * Main method.
 29+ *
 30+ * @since 0.1
 31+ *
 32+ * @param string|null $arg
 33+ */
 34+ public function execute( $subPage ) {
 35+ parent::execute( $subPage );
 36+
 37+ $out = $this->getOutput();
 38+
 39+ if ( $this->subPage === '' ) {
 40+ $this->displayPage();
 41+ }
 42+ else {
 43+ $org = EPOrg::has( array( 'name' => $this->subPage ) );
 44+
 45+ if ( $org === false ) {
 46+ $this->showError( wfMessage( 'ep-terms-nosuchcourses', $this->subPage ) );
 47+ $this->displayPage();
 48+ }
 49+ else {
 50+ $out->redirect( SpecialPage::getTitleFor( 'Term', $this->subPage )->getLocalURL() );
 51+ }
 52+ }
 53+ }
 54+
 55+ /**
 56+ * Display all the stuff that should be on the page.
 57+ *
 58+ * @since 0.1
 59+ */
 60+ protected function displayPage() {
 61+ $user = $this->getUser();
 62+
 63+ if ( $user->isAllowed( 'epadmin' ) ) {
 64+ $this->displayAddNewControl();
 65+ }
 66+ elseif ( $user->isAllowed( 'epmentor' ) ) {
 67+ $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) );
 68+
 69+ if ( $mentor !== false && count( $mentor->getOrgs() ) > 0 ) {
 70+ $this->displayAddNewControl();
 71+ }
 72+ }
 73+
 74+ $pager = new EPTermPager( $this->getContext() );
 75+
 76+ if ( $pager->getNumRows() ) {
 77+ $this->getOutput()->addHTML(
 78+ $pager->getFilterControl() .
 79+ $pager->getNavigationBar() .
 80+ $pager->getBody() .
 81+ $pager->getNavigationBar()
 82+ );
 83+ }
 84+ else {
 85+ $this->getOutput()->addHTML( $pager->getFilterControl( true ) );
 86+ $this->getOutput()->addWikiMsg( 'ep-terms-noresults' );
 87+ }
 88+ }
 89+
 90+ /**
 91+ * Displays a small form to add a new institution.
 92+ *
 93+ * @since 0.1
 94+ */
 95+ protected function displayAddNewControl() {
 96+ $out = $this->getOutput();
 97+
 98+ $out->addHTML( Html::openElement(
 99+ 'form',
 100+ array(
 101+ 'method' => 'post',
 102+ 'action' => SpecialPage::getTitleFor( 'EditTerm' )->getLocalURL(),
 103+ )
 104+ ) );
 105+
 106+ $out->addHTML( '<fieldset>' );
 107+
 108+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' );
 109+
 110+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) );
 111+
 112+ $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
 113+
 114+ $select = new XmlSelect( 'newcourse', 'newcourse' );
 115+ $select->addOptions( EPCourse::getCoursesForAdmin( $this->getUser() ) );
 116+ $out->addHTML( $select->getHTML() );
 117+
 118+ $out->addHTML( Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear' ) );
 119+
 120+ $out->addHTML( '&#160;' . Html::input(
 121+ 'addnewterm',
 122+ wfMsg( 'ep-terms-add' ),
 123+ 'submit'
 124+ ) );
 125+
 126+ $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
 127+
 128+ $out->addHTML( '</fieldset></form>' );
 129+ }
 130+
 131+}
Property changes on: trunk/extensions/EducationProgram/specials/SpecialTerms.php
___________________________________________________________________
Added: svn:eol-style
1132 + native
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -1,7 +1,8 @@
22 <?php
33
44 /**
5 - *
 5+ * Page listing all insitutions in a pager with filter control.
 6+ * Also has a form for adding new items for those with matching priviliges.
67 *
78 * @since 0.1
89 *
Index: trunk/extensions/EducationProgram/specials/SpecialEditTerm.php
@@ -0,0 +1 @@
 2+<?php
Property changes on: trunk/extensions/EducationProgram/specials/SpecialEditTerm.php
___________________________________________________________________
Added: svn:eol-style
13 + native
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php
@@ -1,7 +1,8 @@
22 <?php
33
44 /**
5 - *
 5+ * Page listing all courses in a pager with filter control.
 6+ * Also has a form for adding new items for those with matching priviliges.
67 *
78 * @since 0.1
89 *
@@ -27,14 +28,97 @@
2829 *
2930 * @since 0.1
3031 *
31 - * @param string $arg
 32+ * @param string|null $arg
3233 */
3334 public function execute( $subPage ) {
3435 parent::execute( $subPage );
3536
3637 $out = $this->getOutput();
3738
38 - // TODO: AUTH
 39+ if ( $this->subPage === '' ) {
 40+ $this->displayPage();
 41+ }
 42+ else {
 43+ $org = EPOrg::has( array( 'name' => $this->subPage ) );
 44+
 45+ if ( $org === false ) {
 46+ $this->showError( wfMessage( 'ep-courses-nosuchcourses', $this->subPage ) );
 47+ $this->displayPage();
 48+ }
 49+ else {
 50+ $out->redirect( SpecialPage::getTitleFor( 'Course', $this->subPage )->getLocalURL() );
 51+ }
 52+ }
3953 }
 54+
 55+ /**
 56+ * Display all the stuff that should be on the page.
 57+ *
 58+ * @since 0.1
 59+ */
 60+ protected function displayPage() {
 61+ $user = $this->getUser();
 62+
 63+ if ( $user->isAllowed( 'epadmin' ) ) {
 64+ $this->displayAddNewControl();
 65+ }
 66+ elseif ( $user->isAllowed( 'epmentor' ) ) {
 67+ $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) );
 68+
 69+ if ( $mentor !== false && count( $mentor->getOrgs() ) > 0 ) {
 70+ $this->displayAddNewControl();
 71+ }
 72+ }
 73+
 74+ $pager = new EPCoursePager( $this->getContext() );
 75+
 76+ if ( $pager->getNumRows() ) {
 77+ $this->getOutput()->addHTML(
 78+ $pager->getFilterControl() .
 79+ $pager->getNavigationBar() .
 80+ $pager->getBody() .
 81+ $pager->getNavigationBar()
 82+ );
 83+ }
 84+ else {
 85+ $this->getOutput()->addHTML( $pager->getFilterControl( true ) );
 86+ $this->getOutput()->addWikiMsg( 'ep-courses-noresults' );
 87+ }
 88+ }
 89+
 90+ /**
 91+ * Displays a small form to add a new institution.
 92+ *
 93+ * @since 0.1
 94+ */
 95+ protected function displayAddNewControl() {
 96+ $out = $this->getOutput();
4097
 98+ $out->addHTML( Html::openElement(
 99+ 'form',
 100+ array(
 101+ 'method' => 'post',
 102+ 'action' => SpecialPage::getTitleFor( 'EditCourse' )->getLocalURL(),
 103+ )
 104+ ) );
 105+
 106+ $out->addHTML( '<fieldset>' );
 107+
 108+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) . '</legend>' );
 109+
 110+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-courses-namedoc' ) ) );
 111+
 112+ $out->addHTML( Xml::inputLabel( wfMsg( 'ep-courses-newname' ), 'newname', 'newname' ) );
 113+
 114+ $out->addHTML( '&#160;' . Html::input(
 115+ 'addneworg',
 116+ wfMsg( 'ep-courses-add' ),
 117+ 'submit'
 118+ ) );
 119+
 120+ $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
 121+
 122+ $out->addHTML( '</fieldset></form>' );
 123+ }
 124+
41125 }
Index: trunk/extensions/EducationProgram/specials/SpecialEditCourse.php
@@ -0,0 +1 @@
 2+<?php
Property changes on: trunk/extensions/EducationProgram/specials/SpecialEditCourse.php
___________________________________________________________________
Added: svn:eol-style
13 + native
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php
Property changes on: trunk/extensions/EducationProgram/specials/SpecialTerm.php
___________________________________________________________________
Added: svn:eol-style
24 + native
Index: trunk/extensions/EducationProgram/includes/EPMentor.php
@@ -45,7 +45,34 @@
4646 protected static function getFieldTypes() {
4747 return array(
4848 'id' => 'id',
 49+ 'user_id' => 'id',
4950 );
5051 }
 52+
 53+ /**
 54+ * Returns the orgs this mentor is part of.
 55+ *
 56+ * @since 0.1
 57+ *
 58+ * @param array|null $fields
 59+ *
 60+ * @return array of EPOrg
 61+ */
 62+ public function getOrgs( array $fields = null ) {
 63+ return array(); // TODO
 64+ }
 65+
 66+ /**
 67+ * Retruns the courses this mentor can manage.
 68+ *
 69+ * @since 0.1
 70+ *
 71+ * @param array|null $fields
 72+ *
 73+ * @return array of EPCourse
 74+ */
 75+ public function getCourses( array $fields = null ) {
 76+ return array(); // TODO
 77+ }
5178
5279 }
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -45,6 +45,7 @@
4646 protected static function getFieldTypes() {
4747 return array(
4848 'id' => 'id',
 49+ 'user_id' => 'id',
4950 );
5051 }
5152
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -0,0 +1,81 @@
 2+<?php
 3+
 4+/**
 5+ * Term pager, primarily for Special:Terms.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPTermPager.php
 10+ * @ingroup EductaionProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPTermPager extends EPPager {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @param IContextSource $context
 21+ * @param array $conds
 22+ */
 23+ public function __construct( IContextSource $context, array $conds = array() ) {
 24+ $this->mDefaultDirection = true;
 25+
 26+ // when MW 1.19 becomes min, we want to pass an IContextSource $context here.
 27+ parent::__construct( $context, $conds, 'EPTerm' );
 28+ }
 29+
 30+ /**
 31+ * (non-PHPdoc)
 32+ * @see TablePager::getFieldNames()
 33+ */
 34+ public function getFieldNames() {
 35+ return parent::getFieldNameList( array(
 36+ // TODO
 37+ ) );
 38+ }
 39+
 40+ /**
 41+ * (non-PHPdoc)
 42+ * @see TablePager::getRowClass()
 43+ */
 44+ function getRowClass( $row ) {
 45+ return 'ep-course-row';
 46+ }
 47+
 48+ /**
 49+ * (non-PHPdoc)
 50+ * @see TablePager::getTableClass()
 51+ */
 52+ public function getTableClass(){
 53+ return 'TablePager ep-courses';
 54+ }
 55+
 56+ /**
 57+ * (non-PHPdoc)
 58+ * @see TablePager::formatValue()
 59+ */
 60+ public function formatValue( $name, $value ) {
 61+ switch ( $name ) {
 62+ case '': // TODO
 63+ $value = $value;
 64+ break;
 65+ }
 66+
 67+ return $value;
 68+ }
 69+
 70+ function getDefaultSort() {
 71+ return ''; // TODO
 72+ }
 73+
 74+ /**
 75+ * (non-PHPdoc)
 76+ * @see EPPager::getSortableFields()
 77+ */
 78+ protected function getSortableFields() {
 79+ return array();
 80+ }
 81+
 82+}
Property changes on: trunk/extensions/EducationProgram/includes/EPTermPager.php
___________________________________________________________________
Added: svn:eol-style
183 + native
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -52,5 +52,48 @@
5353 'description' => 'str',
5454 );
5555 }
 56+
 57+ /**
 58+ * Returns a lift of courses that can be administered by the provided user.
 59+ *
 60+ * @since 0.1
 61+ *
 62+ * @param User|int $user User object or user id
 63+ *
 64+ * @return array of EPCourse
 65+ */
 66+ public static function getCoursesForAdmin( $user ) {
 67+ static $cache = array();
 68+
 69+ if ( is_int( $user ) ) {
 70+ $userId = $user;
 71+ }
 72+ else {
 73+ $userId = $user->getId();
 74+ }
 75+
 76+ if ( !array_key_exists( $userId, $cache ) ) {
 77+ if ( is_int( $user ) ) {
 78+ $user = User::newFromId( $userId );
 79+ }
 80+
 81+ $courses = array();
 82+
 83+ if ( $user->isAllowed( 'epadmin' ) ) {
 84+ $courses = self::select();
 85+ }
 86+ elseif ( $user->isAllowed( 'epmentor' ) ) {
 87+ $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) );
 88+
 89+ if ( $mentor !== false ) {
 90+ $courses = $mentor->getCourses();
 91+ }
 92+ }
 93+
 94+ $cache[$userId] = $courses;
 95+ }
 96+
 97+ return $cache[$userId];
 98+ }
5699
57100 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -55,6 +55,12 @@
5656 'special-educationprogram' => 'Education Program',
5757 'special-editinstitution-add' => 'Add institution',
5858 'special-editinstitution-edit' => 'Edit institution',
 59+ 'special-terms' => 'Terms',
 60+ 'special-term' => 'Term',
 61+ 'special-editterm-add' => 'Add term',
 62+ 'special-editterm-edit' => 'Edit term',
 63+ 'special-editcourse-add' => 'Add course',
 64+ 'special-editcourse-edit' => 'Edit course',
5965
6066 // Special:Institutions
6167 'ep-institutions-nosuchinstitution' => 'There is no institution with name "$1". Existing institutions are listed below.',
@@ -64,6 +70,23 @@
6571 'ep-institutions-newname' => 'Institution name:',
6672 'ep-institutions-add' => 'Add institution',
6773
 74+ // Special:Courses
 75+ 'ep-courses-nosuchcourse' => 'There is no course with name "$1". Existing courses are listed below.',
 76+ 'ep-courses-noresults' => 'There are no courses to list.',
 77+ 'ep-courses-addnew' => 'Add a new course',
 78+ 'ep-courses-namedoc' => 'Enter the name for the new course (which should be unique) and hit the button.',
 79+ 'ep-courses-newname' => 'Course name:',
 80+ 'ep-courses-add' => 'Add course',
 81+
 82+ // Special:Terms
 83+ 'ep-terms-nosuchterm' => 'There is no term with id "$1". Existing terms are listed below.',
 84+ 'ep-terms-noresults' => 'There are no terms to list.',
 85+ 'ep-terms-addnew' => 'Add a new term',
 86+ 'ep-terms-namedoc' => 'Enter the course the term belongs to and the year in which it is active.',
 87+ 'ep-terms-newyear' => 'Term year:',
 88+ 'ep-terms-newcourse' => 'Term course:',
 89+ 'ep-terms-add' => 'Add term',
 90+
6891 // Pager
6992 'ep-pager-showonly' => 'Show only items with',
7093 'ep-pager-clear' => 'Clear filters',
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -59,10 +59,13 @@
6060 $wgAutoloadClasses['EPStudent'] = dirname( __FILE__ ) . '/includes/EPStudent.php';
6161 $wgAutoloadClasses['EPStudentPager'] = dirname( __FILE__ ) . '/includes/EPStudentPager.php';
6262 $wgAutoloadClasses['EPTerm'] = dirname( __FILE__ ) . '/includes/EPTerm.php';
 63+$wgAutoloadClasses['EPTermPager'] = dirname( __FILE__ ) . '/includes/EPTermPager.php';
6364
6465 $wgAutoloadClasses['SpecialCourse'] = dirname( __FILE__ ) . '/specials/SpecialCourse.php';
6566 $wgAutoloadClasses['SpecialCourses'] = dirname( __FILE__ ) . '/specials/SpecialCourses.php';
 67+$wgAutoloadClasses['SpecialEditCourse'] = dirname( __FILE__ ) . '/specials/SpecialEditCourse.php';
6668 $wgAutoloadClasses['SpecialEditInstitution'] = dirname( __FILE__ ) . '/specials/SpecialEditInstitution.php';
 69+$wgAutoloadClasses['SpecialEditTerm'] = dirname( __FILE__ ) . '/specials/SpecialEditTerm.php';
6770 $wgAutoloadClasses['SpecialEducationProgram'] = dirname( __FILE__ ) . '/specials/SpecialEducationProgram.php';
6871 $wgAutoloadClasses['SpecialEPFormPage'] = dirname( __FILE__ ) . '/specials/SpecialEPFormPage.php';
6972 $wgAutoloadClasses['SpecialEPPage'] = dirname( __FILE__ ) . '/specials/SpecialEPPage.php';
@@ -71,6 +74,8 @@
7275 $wgAutoloadClasses['SpecialMyCourses'] = dirname( __FILE__ ) . '/specials/SpecialMyCourses.php';
7376 $wgAutoloadClasses['SpecialStudent'] = dirname( __FILE__ ) . '/specials/SpecialStudent.php';
7477 $wgAutoloadClasses['SpecialStudents'] = dirname( __FILE__ ) . '/specials/SpecialStudents.php';
 78+$wgAutoloadClasses['SpecialTerm'] = dirname( __FILE__ ) . '/specials/SpecialTerm.php';
 79+$wgAutoloadClasses['SpecialTerms'] = dirname( __FILE__ ) . '/specials/SpecialTerms.php';
7580
7681 // Special pages
7782 $wgSpecialPages['MyCourses'] = 'SpecialMyCourses';
@@ -80,8 +85,12 @@
8186 $wgSpecialPages['Students'] = 'SpecialStudents';
8287 $wgSpecialPages['Course'] = 'SpecialCourse';
8388 $wgSpecialPages['Courses'] = 'SpecialCourses';
 89+$wgSpecialPages['Term'] = 'SpecialTerm';
 90+$wgSpecialPages['Terms'] = 'SpecialTerms';
8491 $wgSpecialPages['EducationProgram'] = 'SpecialEducationProgram';
 92+$wgSpecialPages['EditCourse'] = 'SpecialEditCourse';
8593 $wgSpecialPages['EditInstitution'] = 'SpecialEditInstitution';
 94+$wgSpecialPages['EditTerm'] = 'SpecialEditTerm';
8695
8796 $wgSpecialPageGroups['MyCourses'] = 'education';
8897 $wgSpecialPageGroups['Institution'] = 'education';
@@ -90,8 +99,12 @@
91100 $wgSpecialPageGroups['Students'] = 'education';
92101 $wgSpecialPageGroups['Course'] = 'education';
93102 $wgSpecialPageGroups['Courses'] = 'education';
 103+$wgSpecialPageGroups['Term'] = 'education';
 104+$wgSpecialPageGroups['Terms'] = 'education';
94105 $wgSpecialPageGroups['EducationProgram'] = 'education';
 106+$wgSpecialPageGroups['EditCourse'] = 'education';
95107 $wgSpecialPageGroups['EditInstitution'] = 'education';
 108+$wgSpecialPageGroups['EditTerm'] = 'education';
96109
97110 // API
98111

Status & tagging log