https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114227
Revision: 114227
Author: jeroendedauw
Date: 2012-03-20 00:31:29 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
implemented caching for course and org pages
Modified Paths:
--------------
trunk/extensions/EducationProgram/actions/EPAction.php
trunk/extensions/EducationProgram/actions/EPViewAction.php
trunk/extensions/EducationProgram/actions/ViewCourseAction.php
trunk/extensions/EducationProgram/actions/ViewOrgAction.php
trunk/extensions/EducationProgram/pages/CoursePage.php
trunk/extensions/EducationProgram/pages/OrgPage.php
Modified: trunk/extensions/EducationProgram/actions/EPAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAction.php 2012-03-20
00:31:10 UTC (rev 114226)
+++ trunk/extensions/EducationProgram/actions/EPAction.php 2012-03-20
00:31:29 UTC (rev 114227)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-abstract class EPAction extends FormlessAction {
+abstract class EPAction extends CachedAction {
/**
* Display a warning that the page has been deleted together with the
first
Modified: trunk/extensions/EducationProgram/actions/EPViewAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPViewAction.php 2012-03-20
00:31:10 UTC (rev 114226)
+++ trunk/extensions/EducationProgram/actions/EPViewAction.php 2012-03-20
00:31:29 UTC (rev 114227)
@@ -84,7 +84,14 @@
}
else {
EPUtils::displayResult( $this->getContext() );
- $this->displayPage( $object );
+
+ $this->displayNavigation();
+
+ $this->startCache( 3600 );
+
+ $this->addCachedHTML( array( $this, 'getPageHTML' ),
$object );
+
+ $this->saveCache();
}
return '';
@@ -137,10 +144,11 @@
* @since 0.1
*
* @param DBDataObject $object
+ *
+ * @return string
*/
- protected function displayPage( DBDataObject $object ) {
- $this->displayNavigation();
- $this->displaySummary( $object );
+ public function getPageHTML( DBDataObject $object ) {
+ return $this->getSummary( $object );
}
/**
@@ -176,9 +184,11 @@
* @param DBDataObject $item
* @param boolean $collapsed
* @param array $summaryData
+ *
+ * @return string
*/
- protected function displaySummary( DBDataObject $item, $collapsed =
false, array $summaryData = null ) {
- $out = $this->getOutput();
+ protected function getSummary( DBDataObject $item, $collapsed = false,
array $summaryData = null ) {
+ $html = '';
$class = 'wikitable ep-summary mw-collapsible';
@@ -186,31 +196,33 @@
$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;
}
/**
@@ -226,5 +238,13 @@
protected function getSummaryData( DBDataObject $item ) {
return array();
}
+
+ /**
+ * @see CachedAction::getCacheKey
+ * @return array
+ */
+ protected function getCacheKey() {
+ return array_merge( $this->getRequest()->getValues(),
parent::getCacheKey() );
+ }
}
\ No newline at end of file
Modified: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/ViewCourseAction.php
2012-03-20 00:31:10 UTC (rev 114226)
+++ trunk/extensions/EducationProgram/actions/ViewCourseAction.php
2012-03-20 00:31:29 UTC (rev 114227)
@@ -36,21 +36,31 @@
/**
* (non-PHPdoc)
- * @see EPViewAction::displayPage()
+ * @see FormlessAction::onView()
*/
- protected function displayPage( DBDataObject $course ) {
- parent::displayPage( $course );
+ public function onView() {
+ // Only cache for anon users. Else we need to cache per user,
+ // since the page has an EPArticleTable, which has per user
stuff.
+ $this->cacheEnabled = $this->getUser()->isAnon();
- $out = $this->getOutput();
+ return parent::onView();
+ }
- $out->addElement( 'h2', array(), wfMsg( 'ep-course-description'
) );
+ /**
+ * (non-PHPdoc)
+ * @see EPViewAction::getPageHTML()
+ */
+ public function getPageHTML( DBDataObject $course ) {
+ $html = parent::getPageHTML( $course );
- $out->addHTML( $this->getOutput()->parse( $course->getField(
'description' ) ) );
+ $html .= Html::element( 'h2', array(), wfMsg(
'ep-course-description' ) );
+ $html .= $this->getOutput()->parse( $course->getField(
'description' ) );
+
$studentIds = $course->getField( 'students' );
if ( !empty( $studentIds ) ) {
- $out->addElement( 'h2', array(), wfMsg(
'ep-course-students' ) );
+ $html .= Html::element( 'h2', array(), wfMsg(
'ep-course-students' ) );
$pager = new EPArticleTable(
$this->getContext(),
@@ -59,18 +69,19 @@
);
if ( $pager->getNumRows() ) {
- $out->addHTML(
+ $html .=
$pager->getFilterControl() .
$pager->getNavigationBar() .
$pager->getBody() .
$pager->getNavigationBar() .
- $pager->getMultipleItemControl()
- );
+ $pager->getMultipleItemControl();
}
}
else {
// TODO
}
+
+ return $html;
}
/**
@@ -207,5 +218,19 @@
return '<br />' . $this->getLanguage()->pipeList(
$links );
}
}
+
+ /**
+ * @see CachedAction::getCacheKey
+ * @return array
+ */
+ protected function getCacheKey() {
+ $user = $this->getUser();
+
+ return array_merge( array(
+ $user->isAllowed( 'ep-course' ),
+ $user->isAllowed( 'ep-bulkdelcourses' ),
+ $user->getOption( 'ep_bulkdelcourses' ),
+ ), parent::getCacheKey() );
+ }
}
Modified: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/ViewOrgAction.php 2012-03-20
00:31:10 UTC (rev 114226)
+++ trunk/extensions/EducationProgram/actions/ViewOrgAction.php 2012-03-20
00:31:29 UTC (rev 114227)
@@ -28,6 +28,18 @@
/**
* (non-PHPdoc)
+ * @see FormlessAction::onView()
+ */
+ public function onView() {
+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
+ $this->getOutput()->addModules( 'ep.addcourse' );
+ }
+
+ return parent::onView();
+ }
+
+ /**
+ * (non-PHPdoc)
* @see Action::getName()
*/
public function getName() {
@@ -36,23 +48,22 @@
/**
* (non-PHPdoc)
- * @see EPViewAction::displayPage()
+ * @see EPViewAction::getPageHTML()
+ * @return string
*/
- protected function displayPage( DBDataObject $org ) {
- parent::displayPage( $org );
+ public function getPageHTML( DBDataObject $org ) {
+ $html = parent::getPageHTML( $org );
- $out = $this->getOutput();
+ $html .= Html::element( 'h2', array(), wfMsg(
'ep-institution-courses' ) );
- $out->addElement( 'h2', array(), wfMsg(
'ep-institution-courses' ) );
+ $html .= EPCourse::getPager( $this->getContext(), array(
'org_id' => $org->getId() ) );
- $out->addHTML( EPCourse::getPager( $this->getContext(), array(
'org_id' => $org->getId() ) ) );
-
if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
- $out->addElement( 'h2', array(), wfMsg(
'ep-institution-add-course' ) );
+ $html .= Html::element( 'h2', array(), wfMsg(
'ep-institution-add-course' ) );
+ $html .= EPCourse::getAddNewControl(
$this->getContext(), array( 'org' => $org->getId() ) );
+ }
- $out->addModules( 'ep.addcourse' );
- $out->addHTML( EPCourse::getAddNewControl(
$this->getContext(), array( 'org' => $org->getId() ) ) );
- }
+ return $html;
}
/**
@@ -93,5 +104,20 @@
return $stats;
}
+
+ /**
+ * @see CachedAction::getCacheKey
+ * @return array
+ */
+ protected function getCacheKey() {
+ $user = $this->getUser();
+
+ return array_merge( array(
+ $user->isAllowed( 'ep-org' ),
+ $user->isAllowed( 'ep-course' ),
+ $user->isAllowed( 'ep-bulkdelcourses' ),
+ $user->getOption( 'ep_bulkdelcourses' ),
+ ), parent::getCacheKey() );
+ }
}
Modified: trunk/extensions/EducationProgram/pages/CoursePage.php
===================================================================
--- trunk/extensions/EducationProgram/pages/CoursePage.php 2012-03-20
00:31:10 UTC (rev 114226)
+++ trunk/extensions/EducationProgram/pages/CoursePage.php 2012-03-20
00:31:29 UTC (rev 114227)
@@ -31,6 +31,7 @@
'edit' => 'EditCourseAction',
'history' => 'EPHistoryAction',
'delete' => 'EPDeleteAction',
+ 'purge' => 'ViewCourseAction',
);
}
Modified: trunk/extensions/EducationProgram/pages/OrgPage.php
===================================================================
--- trunk/extensions/EducationProgram/pages/OrgPage.php 2012-03-20 00:31:10 UTC
(rev 114226)
+++ trunk/extensions/EducationProgram/pages/OrgPage.php 2012-03-20 00:31:29 UTC
(rev 114227)
@@ -31,6 +31,7 @@
'edit' => 'EditOrgAction',
'history' => 'EPHistoryAction',
'delete' => 'EPDeleteAction',
+ 'purge' => 'ViewOrgAction',
);
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs