Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | parent::execute( $subPage ); |
37 | 37 | |
38 | 38 | if ( $this->subPage === '' ) { |
39 | | - $this->startCache( 3600, $this->getUser()->isAnon() ); |
| 39 | + $this->startCache( 3600 ); |
40 | 40 | |
41 | 41 | $this->displayNavigation(); |
42 | 42 | |
— | — | @@ -60,9 +60,7 @@ |
61 | 61 | protected function getCacheKey() { |
62 | 62 | $values = $this->getRequest()->getValues(); |
63 | 63 | |
64 | | - if ( array_key_exists( 'action', $values ) && $values['action'] === 'purge' ) { |
65 | | - unset( $values['action'] ); |
66 | | - } |
| 64 | + $values[] = $this->getUser()->getId(); |
67 | 65 | |
68 | 66 | return array_merge( $values, parent::getCacheKey() ); |
69 | 67 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php |
— | — | @@ -150,39 +150,56 @@ |
151 | 151 | * @param array $summaryData |
152 | 152 | */ |
153 | 153 | protected function displaySummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) { |
154 | | - $out = $this->getOutput(); |
| 154 | + $this->getOutput()->addHTML( $item, $collapsed, $summaryData ); |
| 155 | + } |
155 | 156 | |
| 157 | + /** |
| 158 | + * Display the summary data. |
| 159 | + * |
| 160 | + * @since 0.1 |
| 161 | + * |
| 162 | + * @param DBDataObject $item |
| 163 | + * @param boolean $collapsed |
| 164 | + * @param array $summaryData |
| 165 | + * |
| 166 | + * @return string |
| 167 | + */ |
| 168 | + protected function getSummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) { |
| 169 | + $html = ''; |
| 170 | + |
156 | 171 | $class = 'wikitable ep-summary mw-collapsible'; |
157 | 172 | |
158 | 173 | if ( $collapsed ) { |
159 | 174 | $class .= ' mw-collapsed'; |
160 | 175 | } |
161 | 176 | |
162 | | - $out->addHTML( Html::openElement( 'table', array( 'class' => $class ) ) ); |
| 177 | + $html .= Html::openElement( 'table', array( 'class' => $class ) ); |
163 | 178 | |
164 | | - $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>' ); |
| 179 | + $html .= '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>'; |
165 | 180 | |
166 | 181 | $summaryData = is_null( $summaryData ) ? $this->getSummaryData( $item ) : $summaryData; |
167 | 182 | |
168 | 183 | foreach ( $summaryData as $stat => $value ) { |
169 | | - $out->addHTML( '<tr>' ); |
| 184 | + $html .= '<tr>'; |
170 | 185 | |
171 | | - $out->addElement( |
| 186 | + $html .= Html::element( |
172 | 187 | 'th', |
173 | 188 | array( 'class' => 'ep-summary-name' ), |
174 | 189 | wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat ) |
175 | 190 | ); |
176 | 191 | |
177 | | - $out->addHTML( Html::rawElement( |
| 192 | + $html .= Html::rawElement( |
178 | 193 | 'td', |
179 | 194 | array( 'class' => 'ep-summary-value' ), |
180 | 195 | $value |
181 | | - ) ); |
| 196 | + ); |
182 | 197 | |
183 | | - $out->addHTML( '</tr>' ); |
| 198 | + $html .= '</tr>'; |
184 | 199 | } |
185 | 200 | |
186 | | - $out->addHTML( Html::closeElement( 'table' ) ); |
| 201 | + $html .= Html::closeElement( 'table' ); |
| 202 | + |
| 203 | + return $html; |
187 | 204 | } |
188 | 205 | |
189 | 206 | /** |
Index: trunk/extensions/EducationProgram/specials/SpecialStudent.php |
— | — | @@ -38,13 +38,20 @@ |
39 | 39 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Students' )->getLocalURL() ); |
40 | 40 | } |
41 | 41 | else { |
| 42 | + $this->startCache( 3600 ); |
| 43 | + |
42 | 44 | $this->displayNavigation(); |
43 | 45 | |
44 | 46 | $student = false; |
45 | 47 | $user = User::newFromName( $subPage ); |
46 | 48 | |
47 | 49 | if ( $user !== false && $user->getId() !== 0 ) { |
48 | | - $student = EPStudents::singleton()->selectRow( null, array( 'user_id' => $user->getId() ) ); |
| 50 | + $student = $this->getCachedValue( |
| 51 | + function( $userId ) { |
| 52 | + return EPStudents::singleton()->selectRow( null, array( 'user_id' => $userId ) ); |
| 53 | + }, |
| 54 | + $user->getId() |
| 55 | + ); |
49 | 56 | } |
50 | 57 | |
51 | 58 | if ( $student === false ) { |
— | — | @@ -53,27 +60,49 @@ |
54 | 61 | else { |
55 | 62 | $out->setPageTitle( wfMsgExt( 'ep-student-title', 'parsemag', $student->getName() ) ); |
56 | 63 | |
57 | | - $this->displaySummary( $student ); |
| 64 | + $this->addCachedHTML( array( $this, 'getSummary' ), $student ); |
58 | 65 | |
59 | | - $courseIds = array_map( |
60 | | - function( EPCourse $course ) { |
61 | | - return $course->getId(); |
62 | | - }, |
63 | | - $student->getCourses( 'id' ) |
64 | | - ); |
| 66 | + $this->addCachedHTML( function( EPStudent $student ) { |
| 67 | + $courseIds = array_map( |
| 68 | + function( EPCourse $course ) { |
| 69 | + return $course->getId(); |
| 70 | + }, |
| 71 | + $student->getCourses( 'id' ) |
| 72 | + ); |
65 | 73 | |
66 | | - if ( empty( $courseIds ) ) { |
67 | | - // TODO: high |
68 | | - } |
69 | | - else { |
70 | | - $out->addElement( 'h2', array(), wfMsg( 'ep-student-courses' ) ); |
71 | | - EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) ); |
72 | | - } |
| 74 | + $html = ''; |
| 75 | + |
| 76 | + if ( empty( $courseIds ) ) { |
| 77 | + // TODO: high |
| 78 | + } |
| 79 | + else { |
| 80 | + $html .= Html::element( 'h2', array(), wfMsg( 'ep-student-courses' ) ); |
| 81 | + $html .= ''; // TODO |
| 82 | + // EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) ); |
| 83 | + } |
| 84 | + |
| 85 | + return $html; |
| 86 | + }, $student ); |
73 | 87 | } |
| 88 | + |
| 89 | + $this->saveCache(); |
74 | 90 | } |
75 | 91 | } |
76 | 92 | |
77 | 93 | /** |
| 94 | + * @see SpecialCachedPage::getCacheKey |
| 95 | + * @return array |
| 96 | + */ |
| 97 | + protected function getCacheKey() { |
| 98 | + $values = $this->getRequest()->getValues(); |
| 99 | + |
| 100 | + $values[] = $this->getUser()->getId(); |
| 101 | + $values[] = $this->subPage; |
| 102 | + |
| 103 | + return array_merge( $values, parent::getCacheKey() ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
78 | 107 | * Gets the summary data. |
79 | 108 | * |
80 | 109 | * @since 0.1 |