Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php |
— | — | @@ -90,6 +90,10 @@ |
91 | 91 | $countries = CountryNames::getNames( $this->getLang()->getCode() ); |
92 | 92 | $stats['country'] = $countries[$org->getField( 'country' )]; |
93 | 93 | |
| 94 | + foreach ( $stats as &$stat ) { |
| 95 | + $stat = htmlspecialchars( $stat ); |
| 96 | + } |
| 97 | + |
94 | 98 | return $stats; |
95 | 99 | } |
96 | 100 | |
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -1,7 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * |
| 5 | + * Special page listing the courses that have at least one term in which the current user |
| 6 | + * is or has been enrolled. When a subpage param is provided, and it's a valid course |
| 7 | + * name, info for that course is shown. |
6 | 8 | * |
7 | 9 | * @since 0.1 |
8 | 10 | * |
— | — | @@ -27,7 +29,7 @@ |
28 | 30 | * |
29 | 31 | * @since 0.1 |
30 | 32 | * |
31 | | - * @param string $arg |
| 33 | + * @param string $subPage |
32 | 34 | */ |
33 | 35 | public function execute( $subPage ) { |
34 | 36 | parent::execute( $subPage ); |
— | — | @@ -37,7 +39,6 @@ |
38 | 40 | } |
39 | 41 | |
40 | 42 | $student = EPStudent::newFromUser( $this->getUser() ); |
41 | | - EPStudent::setReadDb( DB_SLAVE ); |
42 | 43 | |
43 | 44 | if ( $student === false ) { |
44 | 45 | $this->getOutput()->addWikiMsg( 'ep-mycourses-not-a-student' ); |
— | — | @@ -52,6 +53,13 @@ |
53 | 54 | } |
54 | 55 | } |
55 | 56 | |
| 57 | + /** |
| 58 | + * |
| 59 | + * |
| 60 | + * @since 0.1 |
| 61 | + * |
| 62 | + * @param EPStudent $student |
| 63 | + */ |
56 | 64 | protected function displayCourses( EPStudent $student ) { |
57 | 65 | $out = $this->getOutput(); |
58 | 66 | |
— | — | @@ -64,15 +72,51 @@ |
65 | 73 | 'ep-mycourses-enrolled', |
66 | 74 | $term->getCourse()->getField( 'name' ), |
67 | 75 | $term->getOrg()->getField( 'name' ) |
68 | | - ) ); // TODO |
| 76 | + ) ); |
69 | 77 | } |
70 | 78 | } |
| 79 | + |
| 80 | + $currentCourses = $student->getCurrentCourses(); |
| 81 | + $passedCourses = $student->getPassedCourses(); |
| 82 | + |
| 83 | + if ( count( $currentCourses ) > 0 ) { |
| 84 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mycourses-current' ) ) ); |
| 85 | + $this->displayCoursesList( $currentCourses ); |
| 86 | + } |
| 87 | + |
| 88 | + if ( count( $passedCourses ) > 0 ) { |
| 89 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mycourses-passed' ) ) ); |
| 90 | + $this->displayCoursesList( $passedCourses ); |
| 91 | + } |
71 | 92 | } |
72 | 93 | else { |
73 | 94 | $out->addWikiMsg( 'ep-mycourses-not-enrolled' ); |
74 | 95 | } |
75 | 96 | } |
76 | 97 | |
| 98 | + /** |
| 99 | + * |
| 100 | + * |
| 101 | + * @since 0.1 |
| 102 | + * |
| 103 | + * @param array $courses |
| 104 | + */ |
| 105 | + protected function displayCoursesList( array /* of EPCourse */ $courses ) { |
| 106 | + $out = $this->getOutput(); |
| 107 | + |
| 108 | + foreach ( $courses as /* EPCourse */ $course ) { |
| 109 | + |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * |
| 115 | + * |
| 116 | + * @since 0.1 |
| 117 | + * |
| 118 | + * @param EPStudent $student |
| 119 | + * @param string $courseName |
| 120 | + */ |
77 | 121 | protected function displayCourse( EPStudent $student, $courseName ) { |
78 | 122 | $course = EPCourse::selectRow( null, array( 'name' => $courseName ) ); |
79 | 123 | |
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php |
— | — | @@ -91,6 +91,10 @@ |
92 | 92 | $stats['name'] = $course->getField( 'name' ); |
93 | 93 | $stats['org'] = EPOrg::selectFieldsRow( 'name', array( 'id' => $course->getField( 'org_id' ) ) ); |
94 | 94 | |
| 95 | + foreach ( $stats as &$stat ) { |
| 96 | + $stat = htmlspecialchars( $stat ); |
| 97 | + } |
| 98 | + |
95 | 99 | return $stats; |
96 | 100 | } |
97 | 101 | |
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php |
— | — | @@ -199,7 +199,7 @@ |
200 | 200 | wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat ) |
201 | 201 | ) ); |
202 | 202 | |
203 | | - $out->addHTML( Html::element( |
| 203 | + $out->addHTML( Html::rawElement( |
204 | 204 | 'td', |
205 | 205 | array( 'class' => 'ep-summary-value' ), |
206 | 206 | $value |
— | — | @@ -213,6 +213,7 @@ |
214 | 214 | |
215 | 215 | /** |
216 | 216 | * Gets the summary data. |
| 217 | + * Returned values must be escaped. |
217 | 218 | * |
218 | 219 | * @since 0.1 |
219 | 220 | * |
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php |
— | — | @@ -93,9 +93,16 @@ |
94 | 94 | $stats['year'] = $term->getField( 'year' ); // TODO: how to properly i18n this? |
95 | 95 | $stats['start'] = $this->getLanguage()->timeanddate( $term->getField( 'start' ), true ); |
96 | 96 | $stats['end'] = $this->getLanguage()->timeanddate( $term->getField( 'end' ), true ); |
97 | | - |
| 97 | + |
| 98 | + foreach ( $stats as &$stat ) { |
| 99 | + $stat = htmlspecialchars( $stat ); |
| 100 | + } |
| 101 | + |
98 | 102 | if ( $term->useCanManage( $this->getUser() ) ) { |
99 | | - $stats['token'] = $term->getField( 'token' ); |
| 103 | + $stats['token'] = Linker::linkKnown( |
| 104 | + SpecialPage::getTitleFor( 'Enroll', $term->getId() . '/' . $term->getField( 'token' ) ), |
| 105 | + htmlspecialchars( $term->getField( 'token' ) ) |
| 106 | + ); |
100 | 107 | } |
101 | 108 | |
102 | 109 | return $stats; |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -22,6 +22,14 @@ |
23 | 23 | protected $terms = false; |
24 | 24 | |
25 | 25 | /** |
| 26 | + * Cached array of the EPCourse objects. |
| 27 | + * |
| 28 | + * @since 0.1 |
| 29 | + * @var array|false |
| 30 | + */ |
| 31 | + protected $courses = false; |
| 32 | + |
| 33 | + /** |
26 | 34 | * @see parent::getFieldTypes |
27 | 35 | * |
28 | 36 | * @since 0.1 |
— | — | @@ -111,6 +119,46 @@ |
112 | 120 | } |
113 | 121 | |
114 | 122 | /** |
| 123 | + * |
| 124 | + * |
| 125 | + * @since 0.1 |
| 126 | + * |
| 127 | + * @param null $fields |
| 128 | + * @param array $conditions |
| 129 | + * @param array $termConditions |
| 130 | + * |
| 131 | + * @return array |
| 132 | + */ |
| 133 | + public function getCourses( $fields = null, array $conditions = array(), array $termConditions = array() ) { |
| 134 | + $courseIds = array_reduce( |
| 135 | + $this->getTerms( 'course_id', $termConditions ), |
| 136 | + function( array $ids, EPTerm $term ) { |
| 137 | + $ids[] = $term->getField( 'course_id' ); |
| 138 | + }, |
| 139 | + array() ); |
| 140 | + |
| 141 | + if ( count( $courseIds ) < 1 ) { |
| 142 | + return array(); |
| 143 | + } |
| 144 | + |
| 145 | + $conditions['id'] = $courseIds; |
| 146 | + |
| 147 | + return EPCourse::select( $fields, array( 'id' => $conditions ) ); |
| 148 | + } |
| 149 | + |
| 150 | + public function getCurrentCourses( $fields = null, array $conditions = array() ) { |
| 151 | + return $this->getCourses( $fields, $conditions, array( |
| 152 | + 'end >= ' . wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ) |
| 153 | + ) ); |
| 154 | + } |
| 155 | + |
| 156 | + public function getPassedCourses( $fields = null, array $conditions = array() ) { |
| 157 | + return $this->getCourses( $fields, $conditions, array( |
| 158 | + 'end < ' . wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ) |
| 159 | + ) ); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
115 | 163 | * Returns the terms this student is enrolled in. |
116 | 164 | * |
117 | 165 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php |
— | — | @@ -593,8 +593,16 @@ |
594 | 594 | |
595 | 595 | foreach ( $values as $field => $value ) { |
596 | 596 | if ( is_integer( $field ) ) { |
597 | | - $field = $value[0]; |
598 | | - $value = $value[1]; |
| 597 | + if ( is_array( $value ) ) { |
| 598 | + $field = $value[0]; |
| 599 | + $value = $value[1]; |
| 600 | + } |
| 601 | + else { |
| 602 | + $value = explode( ' ', $value, 2 ); |
| 603 | + $value[0] = static::getPrefixedField( $value[0] ); |
| 604 | + $prefixedValues[] = implode( ' ', $value ); |
| 605 | + continue; |
| 606 | + } |
599 | 607 | } |
600 | 608 | |
601 | 609 | $prefixedValues[static::getPrefixedField( $field )] = $value; |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -217,6 +217,8 @@ |
218 | 218 | // Special:MyCourses |
219 | 219 | 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.', |
220 | 220 | 'ep-mycourses-not-enrolled' => 'You are not enrolled in any course. A list of courses can be found [[Special:Courses|here]].', |
| 221 | + 'ep-mycourses-current' => 'Active courses', |
| 222 | + 'ep-mycourses-passed' => 'Passed courses', |
221 | 223 | |
222 | 224 | // Navigation links |
223 | 225 | 'ep-nav-orgs' => 'Institution list', |