r114227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114226‎ | r114227 | r114228 >
Date:00:31, 20 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
implemented caching for course and org pages
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EPAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/pages/CoursePage.php (modified) (history)
  • /trunk/extensions/EducationProgram/pages/OrgPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/pages/CoursePage.php
@@ -31,6 +31,7 @@
3232 'edit' => 'EditCourseAction',
3333 'history' => 'EPHistoryAction',
3434 'delete' => 'EPDeleteAction',
 35+ 'purge' => 'ViewCourseAction',
3536 );
3637 }
3738
Index: trunk/extensions/EducationProgram/pages/OrgPage.php
@@ -31,6 +31,7 @@
3232 'edit' => 'EditOrgAction',
3333 'history' => 'EPHistoryAction',
3434 'delete' => 'EPDeleteAction',
 35+ 'purge' => 'ViewOrgAction',
3536 );
3637 }
3738
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -36,21 +36,31 @@
3737
3838 /**
3939 * (non-PHPdoc)
40 - * @see EPViewAction::displayPage()
 40+ * @see FormlessAction::onView()
4141 */
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();
4446
45 - $out = $this->getOutput();
 47+ return parent::onView();
 48+ }
4649
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 );
4856
49 - $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) );
 57+ $html .= Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) );
5058
 59+ $html .= $this->getOutput()->parse( $course->getField( 'description' ) );
 60+
5161 $studentIds = $course->getField( 'students' );
5262
5363 if ( !empty( $studentIds ) ) {
54 - $out->addElement( 'h2', array(), wfMsg( 'ep-course-students' ) );
 64+ $html .= Html::element( 'h2', array(), wfMsg( 'ep-course-students' ) );
5565
5666 $pager = new EPArticleTable(
5767 $this->getContext(),
@@ -59,18 +69,19 @@
6070 );
6171
6272 if ( $pager->getNumRows() ) {
63 - $out->addHTML(
 73+ $html .=
6474 $pager->getFilterControl() .
6575 $pager->getNavigationBar() .
6676 $pager->getBody() .
6777 $pager->getNavigationBar() .
68 - $pager->getMultipleItemControl()
69 - );
 78+ $pager->getMultipleItemControl();
7079 }
7180 }
7281 else {
7382 // TODO
7483 }
 84+
 85+ return $html;
7586 }
7687
7788 /**
@@ -207,5 +218,19 @@
208219 return '<br />' . $this->getLanguage()->pipeList( $links );
209220 }
210221 }
 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+ }
211236
212237 }
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -84,7 +84,14 @@
8585 }
8686 else {
8787 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();
8996 }
9097
9198 return '';
@@ -137,10 +144,11 @@
138145 * @since 0.1
139146 *
140147 * @param DBDataObject $object
 148+ *
 149+ * @return string
141150 */
142 - protected function displayPage( DBDataObject $object ) {
143 - $this->displayNavigation();
144 - $this->displaySummary( $object );
 151+ public function getPageHTML( DBDataObject $object ) {
 152+ return $this->getSummary( $object );
145153 }
146154
147155 /**
@@ -176,9 +184,11 @@
177185 * @param DBDataObject $item
178186 * @param boolean $collapsed
179187 * @param array $summaryData
 188+ *
 189+ * @return string
180190 */
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 = '';
183193
184194 $class = 'wikitable ep-summary mw-collapsible';
185195
@@ -186,31 +196,33 @@
187197 $class .= ' mw-collapsed';
188198 }
189199
190 - $out->addHTML( Html::openElement( 'table', array( 'class' => $class ) ) );
 200+ $html .= Html::openElement( 'table', array( 'class' => $class ) );
191201
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>';
193203
194204 $summaryData = is_null( $summaryData ) ? $this->getSummaryData( $item ) : $summaryData;
195205
196206 foreach ( $summaryData as $stat => $value ) {
197 - $out->addHTML( '<tr>' );
 207+ $html .= '<tr>';
198208
199 - $out->addElement(
 209+ $html .= Html::element(
200210 'th',
201211 array( 'class' => 'ep-summary-name' ),
202212 wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat )
203213 );
204214
205 - $out->addHTML( Html::rawElement(
 215+ $html .= Html::rawElement(
206216 'td',
207217 array( 'class' => 'ep-summary-value' ),
208218 $value
209 - ) );
 219+ );
210220
211 - $out->addHTML( '</tr>' );
 221+ $html .= '</tr>';
212222 }
213223
214 - $out->addHTML( Html::closeElement( 'table' ) );
 224+ $html .= Html::closeElement( 'table' );
 225+
 226+ return $html;
215227 }
216228
217229 /**
@@ -226,5 +238,13 @@
227239 protected function getSummaryData( DBDataObject $item ) {
228240 return array();
229241 }
 242+
 243+ /**
 244+ * @see CachedAction::getCacheKey
 245+ * @return array
 246+ */
 247+ protected function getCacheKey() {
 248+ return array_merge( $this->getRequest()->getValues(), parent::getCacheKey() );
 249+ }
230250
231251 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/actions/EPAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -abstract class EPAction extends FormlessAction {
 16+abstract class EPAction extends CachedAction {
1717
1818 /**
1919 * Display a warning that the page has been deleted together with the first
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -28,6 +28,18 @@
2929
3030 /**
3131 * (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)
3244 * @see Action::getName()
3345 */
3446 public function getName() {
@@ -36,23 +48,22 @@
3749
3850 /**
3951 * (non-PHPdoc)
40 - * @see EPViewAction::displayPage()
 52+ * @see EPViewAction::getPageHTML()
 53+ * @return string
4154 */
42 - protected function displayPage( DBDataObject $org ) {
43 - parent::displayPage( $org );
 55+ public function getPageHTML( DBDataObject $org ) {
 56+ $html = parent::getPageHTML( $org );
4457
45 - $out = $this->getOutput();
 58+ $html .= Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) );
4659
47 - $out->addElement( 'h2', array(), wfMsg( 'ep-institution-courses' ) );
 60+ $html .= EPCourse::getPager( $this->getContext(), array( 'org_id' => $org->getId() ) );
4861
49 - $out->addHTML( EPCourse::getPager( $this->getContext(), array( 'org_id' => $org->getId() ) ) );
50 -
5162 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+ }
5366
54 - $out->addModules( 'ep.addcourse' );
55 - $out->addHTML( EPCourse::getAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) ) );
56 - }
 67+ return $html;
5768 }
5869
5970 /**
@@ -93,5 +104,20 @@
94105
95106 return $stats;
96107 }
 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+ }
97123
98124 }

Status & tagging log