https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114181
Revision: 114181 Author: jeroendedauw Date: 2012-03-19 20:51:55 +0000 (Mon, 19 Mar 2012) Log Message: ----------- work on caching of special:student Modified Paths: -------------- trunk/extensions/EducationProgram/specials/SpecialEPPage.php trunk/extensions/EducationProgram/specials/SpecialInstitutions.php trunk/extensions/EducationProgram/specials/SpecialStudent.php Modified: trunk/extensions/EducationProgram/specials/SpecialEPPage.php =================================================================== --- trunk/extensions/EducationProgram/specials/SpecialEPPage.php 2012-03-19 20:51:36 UTC (rev 114180) +++ trunk/extensions/EducationProgram/specials/SpecialEPPage.php 2012-03-19 20:51:55 UTC (rev 114181) @@ -150,39 +150,56 @@ * @param array $summaryData */ protected function displaySummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) { - $out = $this->getOutput(); + $this->getOutput()->addHTML( $item, $collapsed, $summaryData ); + } + /** + * Display the summary data. + * + * @since 0.1 + * + * @param DBDataObject $item + * @param boolean $collapsed + * @param array $summaryData + * + * @return string + */ + protected function getSummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) { + $html = ''; + $class = 'wikitable ep-summary mw-collapsible'; if ( $collapsed ) { $class .= ' mw-collapsed'; } - $out->addHTML( Html::openElement( 'table', array( 'class' => $class ) ) ); + $html .= Html::openElement( 'table', array( 'class' => $class ) ); - $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>' ); + $html .= '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>'; $summaryData = is_null( $summaryData ) ? $this->getSummaryData( $item ) : $summaryData; foreach ( $summaryData as $stat => $value ) { - $out->addHTML( '<tr>' ); + $html .= '<tr>'; - $out->addElement( + $html .= Html::element( 'th', array( 'class' => 'ep-summary-name' ), wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat ) ); - $out->addHTML( Html::rawElement( + $html .= Html::rawElement( 'td', array( 'class' => 'ep-summary-value' ), $value - ) ); + ); - $out->addHTML( '</tr>' ); + $html .= '</tr>'; } - $out->addHTML( Html::closeElement( 'table' ) ); + $html .= Html::closeElement( 'table' ); + + return $html; } /** Modified: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php =================================================================== --- trunk/extensions/EducationProgram/specials/SpecialInstitutions.php 2012-03-19 20:51:36 UTC (rev 114180) +++ trunk/extensions/EducationProgram/specials/SpecialInstitutions.php 2012-03-19 20:51:55 UTC (rev 114181) @@ -35,7 +35,7 @@ parent::execute( $subPage ); if ( $this->subPage === '' ) { - $this->startCache( 3600, $this->getUser()->isAnon() ); + $this->startCache( 3600 ); $this->displayNavigation(); @@ -60,9 +60,7 @@ protected function getCacheKey() { $values = $this->getRequest()->getValues(); - if ( array_key_exists( 'action', $values ) && $values['action'] === 'purge' ) { - unset( $values['action'] ); - } + $values[] = $this->getUser()->getId(); return array_merge( $values, parent::getCacheKey() ); } Modified: trunk/extensions/EducationProgram/specials/SpecialStudent.php =================================================================== --- trunk/extensions/EducationProgram/specials/SpecialStudent.php 2012-03-19 20:51:36 UTC (rev 114180) +++ trunk/extensions/EducationProgram/specials/SpecialStudent.php 2012-03-19 20:51:55 UTC (rev 114181) @@ -38,13 +38,20 @@ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Students' )->getLocalURL() ); } else { + $this->startCache( 3600 ); + $this->displayNavigation(); $student = false; $user = User::newFromName( $subPage ); if ( $user !== false && $user->getId() !== 0 ) { - $student = EPStudents::singleton()->selectRow( null, array( 'user_id' => $user->getId() ) ); + $student = $this->getCachedValue( + function( $userId ) { + return EPStudents::singleton()->selectRow( null, array( 'user_id' => $userId ) ); + }, + $user->getId() + ); } if ( $student === false ) { @@ -53,27 +60,49 @@ else { $out->setPageTitle( wfMsgExt( 'ep-student-title', 'parsemag', $student->getName() ) ); - $this->displaySummary( $student ); + $this->addCachedHTML( array( $this, 'getSummary' ), $student ); - $courseIds = array_map( - function( EPCourse $course ) { - return $course->getId(); - }, - $student->getCourses( 'id' ) - ); + $this->addCachedHTML( function( EPStudent $student ) { + $courseIds = array_map( + function( EPCourse $course ) { + return $course->getId(); + }, + $student->getCourses( 'id' ) + ); - if ( empty( $courseIds ) ) { - // TODO: high - } - else { - $out->addElement( 'h2', array(), wfMsg( 'ep-student-courses' ) ); - EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) ); - } + $html = ''; + + if ( empty( $courseIds ) ) { + // TODO: high + } + else { + $html .= Html::element( 'h2', array(), wfMsg( 'ep-student-courses' ) ); + $html .= ''; // TODO + // EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) ); + } + + return $html; + }, $student ); } + + $this->saveCache(); } } /** + * @see SpecialCachedPage::getCacheKey + * @return array + */ + protected function getCacheKey() { + $values = $this->getRequest()->getValues(); + + $values[] = $this->getUser()->getId(); + $values[] = $this->subPage; + + return array_merge( $values, parent::getCacheKey() ); + } + + /** * Gets the summary data. * * @since 0.1 _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs