Index: trunk/extensions/EducationProgram/pages/CoursePage.php |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 | 'edit' => 'EditCourseAction', |
33 | 33 | 'history' => 'EPHistoryAction', |
34 | 34 | 'delete' => 'EPDeleteAction', |
| 35 | + 'purge' => 'ViewCourseAction', |
35 | 36 | ); |
36 | 37 | } |
37 | 38 | |
Index: trunk/extensions/EducationProgram/pages/OrgPage.php |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 | 'edit' => 'EditOrgAction', |
33 | 33 | 'history' => 'EPHistoryAction', |
34 | 34 | 'delete' => 'EPDeleteAction', |
| 35 | + 'purge' => 'ViewOrgAction', |
35 | 36 | ); |
36 | 37 | } |
37 | 38 | |
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php |
— | — | @@ -36,21 +36,31 @@ |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * (non-PHPdoc) |
40 | | - * @see EPViewAction::displayPage() |
| 40 | + * @see FormlessAction::onView() |
41 | 41 | */ |
42 | | - protected function displayPage( DBDataObject $course ) { |
43 | | - parent::displayPage( $course ); |
| 42 | + public function onView() { |
| 43 | + // Only cache for anon users. Else we need to cache per user, |
| 44 | + // since the page has an EPArticleTable, which has per user stuff. |
| 45 | + $this->cacheEnabled = $this->getUser()->isAnon(); |
44 | 46 | |
45 | | - $out = $this->getOutput(); |
| 47 | + return parent::onView(); |
| 48 | + } |
46 | 49 | |
47 | | - $out->addElement( 'h2', array(), wfMsg( 'ep-course-description' ) ); |
| 50 | + /** |
| 51 | + * (non-PHPdoc) |
| 52 | + * @see EPViewAction::getPageHTML() |
| 53 | + */ |
| 54 | + public function getPageHTML( DBDataObject $course ) { |
| 55 | + $html = parent::getPageHTML( $course ); |
48 | 56 | |
49 | | - $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) ); |
| 57 | + $html .= Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) ); |
50 | 58 | |
| 59 | + $html .= $this->getOutput()->parse( $course->getField( 'description' ) ); |
| 60 | + |
51 | 61 | $studentIds = $course->getField( 'students' ); |
52 | 62 | |
53 | 63 | if ( !empty( $studentIds ) ) { |
54 | | - $out->addElement( 'h2', array(), wfMsg( 'ep-course-students' ) ); |
| 64 | + $html .= Html::element( 'h2', array(), wfMsg( 'ep-course-students' ) ); |
55 | 65 | |
56 | 66 | $pager = new EPArticleTable( |
57 | 67 | $this->getContext(), |
— | — | @@ -59,18 +69,19 @@ |
60 | 70 | ); |
61 | 71 | |
62 | 72 | if ( $pager->getNumRows() ) { |
63 | | - $out->addHTML( |
| 73 | + $html .= |
64 | 74 | $pager->getFilterControl() . |
65 | 75 | $pager->getNavigationBar() . |
66 | 76 | $pager->getBody() . |
67 | 77 | $pager->getNavigationBar() . |
68 | | - $pager->getMultipleItemControl() |
69 | | - ); |
| 78 | + $pager->getMultipleItemControl(); |
70 | 79 | } |
71 | 80 | } |
72 | 81 | else { |
73 | 82 | // TODO |
74 | 83 | } |
| 84 | + |
| 85 | + return $html; |
75 | 86 | } |
76 | 87 | |
77 | 88 | /** |
— | — | @@ -207,5 +218,19 @@ |
208 | 219 | return '<br />' . $this->getLanguage()->pipeList( $links ); |
209 | 220 | } |
210 | 221 | } |
| 222 | + |
| 223 | + /** |
| 224 | + * @see CachedAction::getCacheKey |
| 225 | + * @return array |
| 226 | + */ |
| 227 | + protected function getCacheKey() { |
| 228 | + $user = $this->getUser(); |
| 229 | + |
| 230 | + return array_merge( array( |
| 231 | + $user->isAllowed( 'ep-course' ), |
| 232 | + $user->isAllowed( 'ep-bulkdelcourses' ), |
| 233 | + $user->getOption( 'ep_bulkdelcourses' ), |
| 234 | + ), parent::getCacheKey() ); |
| 235 | + } |
211 | 236 | |
212 | 237 | } |
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php |
— | — | @@ -84,7 +84,14 @@ |
85 | 85 | } |
86 | 86 | else { |
87 | 87 | EPUtils::displayResult( $this->getContext() ); |
88 | | - $this->displayPage( $object ); |
| 88 | + |
| 89 | + $this->displayNavigation(); |
| 90 | + |
| 91 | + $this->startCache( 3600 ); |
| 92 | + |
| 93 | + $this->addCachedHTML( array( $this, 'getPageHTML' ), $object ); |
| 94 | + |
| 95 | + $this->saveCache(); |
89 | 96 | } |
90 | 97 | |
91 | 98 | return ''; |
— | — | @@ -137,10 +144,11 @@ |
138 | 145 | * @since 0.1 |
139 | 146 | * |
140 | 147 | * @param DBDataObject $object |
| 148 | + * |
| 149 | + * @return string |
141 | 150 | */ |
142 | | - protected function displayPage( DBDataObject $object ) { |
143 | | - $this->displayNavigation(); |
144 | | - $this->displaySummary( $object ); |
| 151 | + public function getPageHTML( DBDataObject $object ) { |
| 152 | + return $this->getSummary( $object ); |
145 | 153 | } |
146 | 154 | |
147 | 155 | /** |
— | — | @@ -176,9 +184,11 @@ |
177 | 185 | * @param DBDataObject $item |
178 | 186 | * @param boolean $collapsed |
179 | 187 | * @param array $summaryData |
| 188 | + * |
| 189 | + * @return string |
180 | 190 | */ |
181 | | - protected function displaySummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) { |
182 | | - $out = $this->getOutput(); |
| 191 | + protected function getSummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) { |
| 192 | + $html = ''; |
183 | 193 | |
184 | 194 | $class = 'wikitable ep-summary mw-collapsible'; |
185 | 195 | |
— | — | @@ -186,31 +196,33 @@ |
187 | 197 | $class .= ' mw-collapsed'; |
188 | 198 | } |
189 | 199 | |
190 | | - $out->addHTML( Html::openElement( 'table', array( 'class' => $class ) ) ); |
| 200 | + $html .= Html::openElement( 'table', array( 'class' => $class ) ); |
191 | 201 | |
192 | | - $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>' ); |
| 202 | + $html .= '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>'; |
193 | 203 | |
194 | 204 | $summaryData = is_null( $summaryData ) ? $this->getSummaryData( $item ) : $summaryData; |
195 | 205 | |
196 | 206 | foreach ( $summaryData as $stat => $value ) { |
197 | | - $out->addHTML( '<tr>' ); |
| 207 | + $html .= '<tr>'; |
198 | 208 | |
199 | | - $out->addElement( |
| 209 | + $html .= Html::element( |
200 | 210 | 'th', |
201 | 211 | array( 'class' => 'ep-summary-name' ), |
202 | 212 | wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat ) |
203 | 213 | ); |
204 | 214 | |
205 | | - $out->addHTML( Html::rawElement( |
| 215 | + $html .= Html::rawElement( |
206 | 216 | 'td', |
207 | 217 | array( 'class' => 'ep-summary-value' ), |
208 | 218 | $value |
209 | | - ) ); |
| 219 | + ); |
210 | 220 | |
211 | | - $out->addHTML( '</tr>' ); |
| 221 | + $html .= '</tr>'; |
212 | 222 | } |
213 | 223 | |
214 | | - $out->addHTML( Html::closeElement( 'table' ) ); |
| 224 | + $html .= Html::closeElement( 'table' ); |
| 225 | + |
| 226 | + return $html; |
215 | 227 | } |
216 | 228 | |
217 | 229 | /** |
— | — | @@ -226,5 +238,13 @@ |
227 | 239 | protected function getSummaryData( DBDataObject $item ) { |
228 | 240 | return array(); |
229 | 241 | } |
| 242 | + |
| 243 | + /** |
| 244 | + * @see CachedAction::getCacheKey |
| 245 | + * @return array |
| 246 | + */ |
| 247 | + protected function getCacheKey() { |
| 248 | + return array_merge( $this->getRequest()->getValues(), parent::getCacheKey() ); |
| 249 | + } |
230 | 250 | |
231 | 251 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/actions/EPAction.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | * @licence GNU GPL v3+ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | | -abstract class EPAction extends FormlessAction { |
| 16 | +abstract class EPAction extends CachedAction { |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Display a warning that the page has been deleted together with the first |
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php |
— | — | @@ -28,6 +28,18 @@ |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * (non-PHPdoc) |
| 32 | + * @see FormlessAction::onView() |
| 33 | + */ |
| 34 | + public function onView() { |
| 35 | + if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
| 36 | + $this->getOutput()->addModules( 'ep.addcourse' ); |
| 37 | + } |
| 38 | + |
| 39 | + return parent::onView(); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * (non-PHPdoc) |
32 | 44 | * @see Action::getName() |
33 | 45 | */ |
34 | 46 | public function getName() { |
— | — | @@ -36,23 +48,22 @@ |
37 | 49 | |
38 | 50 | /** |
39 | 51 | * (non-PHPdoc) |
40 | | - * @see EPViewAction::displayPage() |
| 52 | + * @see EPViewAction::getPageHTML() |
| 53 | + * @return string |
41 | 54 | */ |
42 | | - protected function displayPage( DBDataObject $org ) { |
43 | | - parent::displayPage( $org ); |
| 55 | + public function getPageHTML( DBDataObject $org ) { |
| 56 | + $html = parent::getPageHTML( $org ); |
44 | 57 | |
45 | | - $out = $this->getOutput(); |
| 58 | + $html .= Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ); |
46 | 59 | |
47 | | - $out->addElement( 'h2', array(), wfMsg( 'ep-institution-courses' ) ); |
| 60 | + $html .= EPCourse::getPager( $this->getContext(), array( 'org_id' => $org->getId() ) ); |
48 | 61 | |
49 | | - $out->addHTML( EPCourse::getPager( $this->getContext(), array( 'org_id' => $org->getId() ) ) ); |
50 | | - |
51 | 62 | if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
52 | | - $out->addElement( 'h2', array(), wfMsg( 'ep-institution-add-course' ) ); |
| 63 | + $html .= Html::element( 'h2', array(), wfMsg( 'ep-institution-add-course' ) ); |
| 64 | + $html .= EPCourse::getAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) ); |
| 65 | + } |
53 | 66 | |
54 | | - $out->addModules( 'ep.addcourse' ); |
55 | | - $out->addHTML( EPCourse::getAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) ) ); |
56 | | - } |
| 67 | + return $html; |
57 | 68 | } |
58 | 69 | |
59 | 70 | /** |
— | — | @@ -93,5 +104,20 @@ |
94 | 105 | |
95 | 106 | return $stats; |
96 | 107 | } |
| 108 | + |
| 109 | + /** |
| 110 | + * @see CachedAction::getCacheKey |
| 111 | + * @return array |
| 112 | + */ |
| 113 | + protected function getCacheKey() { |
| 114 | + $user = $this->getUser(); |
| 115 | + |
| 116 | + return array_merge( array( |
| 117 | + $user->isAllowed( 'ep-org' ), |
| 118 | + $user->isAllowed( 'ep-course' ), |
| 119 | + $user->isAllowed( 'ep-bulkdelcourses' ), |
| 120 | + $user->getOption( 'ep_bulkdelcourses' ), |
| 121 | + ), parent::getCacheKey() ); |
| 122 | + } |
97 | 123 | |
98 | 124 | } |