https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114195
Revision: 114195
Author: jeroendedauw
Date: 2012-03-19 21:49:18 +0000 (Mon, 19 Mar 2012)
Log Message:
-----------
more work on caching of special:institutions and special:courses
Modified Paths:
--------------
trunk/extensions/EducationProgram/actions/ViewOrgAction.php
trunk/extensions/EducationProgram/includes/EPCourse.php
trunk/extensions/EducationProgram/includes/EPOrg.php
trunk/extensions/EducationProgram/specials/SpecialCourses.php
trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
Modified: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/ViewOrgAction.php 2012-03-19
21:42:01 UTC (rev 114194)
+++ trunk/extensions/EducationProgram/actions/ViewOrgAction.php 2012-03-19
21:49:18 UTC (rev 114195)
@@ -45,12 +45,13 @@
$out->addElement( 'h2', array(), wfMsg(
'ep-institution-courses' ) );
- $out->addHTML( EPCourse::displayPager( $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' ) );
- EPCourse::displayAddNewControl( $this->getContext(),
array( 'org' => $org->getId() ) );
+ $out->addModules( 'ep.addcourse' );
+ $out->addHTML( EPCourse::getAddNewControl(
$this->getContext(), array( 'org' => $org->getId() ) ) );
}
}
Modified: trunk/extensions/EducationProgram/includes/EPCourse.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPCourse.php 2012-03-19
21:42:01 UTC (rev 114194)
+++ trunk/extensions/EducationProgram/includes/EPCourse.php 2012-03-19
21:49:18 UTC (rev 114195)
@@ -293,32 +293,30 @@
* @param IContextSource $context
* @param array $args
*
- * @return boolean
+ * @return string
*/
- public static function displayAddNewControl( IContextSource $context,
array $args ) {
+ public static function getAddNewControl( IContextSource $context, array
$args ) {
if ( !$context->getUser()->isAllowed( 'ep-course' ) ) {
- return false;
+ return '';
}
- $out = $context->getOutput();
-
- $out->addModules( 'ep.addcourse' );
+ $html = '';
- $out->addHTML( Html::openElement(
+ $html .= Html::openElement(
'form',
array(
'method' => 'post',
'action' =>
EPCourses::singleton()->getTitleFor( 'NAME_PLACEHOLDER' )->getLocalURL( array(
'action' => 'edit' ) ),
)
- ) );
+ );
- $out->addHTML( '<fieldset>' );
+ $html .= '<fieldset>';
- $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) .
'</legend>' );
+ $html .= '<legend>' . $context->msg( 'ep-courses-addnew'
)->escaped() . '</legend>';
- $out->addElement( 'p', array(), wfMsg( 'ep-courses-namedoc' ) );
+ $html .= '<p>' . $context->msg( 'ep-courses-namedoc'
)->escaped() . '</p>';
- $out->addElement( 'label', array( 'for' => 'neworg' ), wfMsg(
'ep-courses-neworg' ) );
+ $html .= Html::element( 'label', array( 'for' => 'neworg' ),
$context->msg( 'ep-courses-neworg' ) );
$select = new XmlSelect(
'neworg',
@@ -327,39 +325,39 @@
);
$select->addOptions( EPOrgs::singleton()->getOrgOptions() );
- $out->addHTML( $select->getHTML() );
+ $html .= $select->getHTML();
- $out->addHTML( ' ' . Xml::inputLabel(
- wfMsg( 'ep-courses-newname' ),
+ $html .= ' ' . Xml::inputLabel(
+ $context->msg( 'ep-courses-newname' )->escaped(),
'newname',
'newname',
20,
array_key_exists( 'name', $args ) ? $args['name'] :
false
- ) );
+ );
- $out->addHTML( ' ' . Xml::inputLabel(
- wfMsg( 'ep-courses-newterm' ),
+ $html .= ' ' . Xml::inputLabel(
+ $context->msg( 'ep-courses-newterm' )->escaped(),
'newterm',
'newterm',
10,
array_key_exists( 'term', $args ) ? $args['term'] :
false
- ) );
+ );
- $out->addHTML( ' ' . Html::input(
+ $html .= ' ' . Html::input(
'addnewcourse',
- wfMsg( 'ep-courses-add' ),
+ $context->msg( 'ep-courses-add' )->escaped(),
'submit',
array(
'disabled' => 'disabled',
'class' => 'ep-course-add',
)
- ) );
+ );
- $out->addHTML( Html::hidden( 'isnew', 1 ) );
+ $html .= Html::hidden( 'isnew', 1 );
- $out->addHTML( '</fieldset></form>' );
+ $html .= '</fieldset></form>';
- return true;
+ return $html;
}
/**
@@ -370,13 +368,15 @@
*
* @param IContextSource $context
* @param array $args
+ *
+ * @return string
*/
- public static function displayAddNewRegion( IContextSource $context,
array $args = array() ) {
+ public static function getAddNewRegion( IContextSource $context, array
$args = array() ) {
if ( EPOrgs::singleton()->has() ) {
- EPCourse::displayAddNewControl( $context, $args );
+ return EPCourse::getAddNewControl( $context, $args );
}
- elseif ( $context->getUser()->isAllowed( 'ep-course' ) ) {
- $context->getOutput()->addWikiMsg(
'ep-courses-addorgfirst' );
+ else {
+ return $context->msg( 'ep-courses-addorgfirst'
)->escaped();
}
}
Modified: trunk/extensions/EducationProgram/includes/EPOrg.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPOrg.php 2012-03-19
21:42:01 UTC (rev 114194)
+++ trunk/extensions/EducationProgram/includes/EPOrg.php 2012-03-19
21:49:18 UTC (rev 114195)
@@ -140,12 +140,11 @@
*
* @since 0.1
*
- * @param IContextSource $context
* @param array $args
*
* @return string
*/
- public static function getAddNewControl( IContextSource $context, array
$args = array() ) {
+ public static function getAddNewControl( array $args = array() ) {
$html = '';
$html .= Html::openElement(
Modified: trunk/extensions/EducationProgram/specials/SpecialCourses.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialCourses.php
2012-03-19 21:42:01 UTC (rev 114194)
+++ trunk/extensions/EducationProgram/specials/SpecialCourses.php
2012-03-19 21:49:18 UTC (rev 114195)
@@ -36,18 +36,42 @@
if ( $this->subPage === '' ) {
$this->displayNavigation();
- $this->addCachedHTML(
- function( IContextSource $context ) {
- return
- EPCourse::getAddNewRegion(
$context ) . // FIXME
- EPCourse::getPager( $context );
- },
- $this->getContext()
- );
+ $this->startCache( 900 );
+
+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
+ $this->getOutput()->addModules( 'ep.addcourse'
);
+
+ $this->addCachedHTML(
+ function( IContextSource $context ) {
+ return
+
EPCourse::getAddNewRegion( $context ) . // FIXME
+ EPCourse::getPager(
$context );
+ },
+ $this->getContext()
+ );
+ }
+
+ $this->saveCache();
}
else {
$this->getOutput()->redirect( Title::newFromText(
$this->subPage, EP_NS_COURSE )->getLocalURL() );
}
}
+ /**
+ * @see SpecialCachedPage::getCacheKey
+ * @return array
+ */
+ protected function getCacheKey() {
+ $values = $this->getRequest()->getValues();
+
+ $user = $this->getUser();
+
+ $values[] = $user->isAllowed( 'ep-course' );
+ $values[] = $user->isAllowed( 'ep-bulkdelcourses' );
+ $values[] = $user->getOption( 'ep_bulkdelcourses' );
+
+ return array_merge( $values, parent::getCacheKey() );
+ }
+
}
Modified: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
2012-03-19 21:42:01 UTC (rev 114194)
+++ trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
2012-03-19 21:49:18 UTC (rev 114195)
@@ -31,7 +31,6 @@
* @param string|null $subPage
*/
public function execute( $subPage ) {
-
parent::execute( $subPage );
if ( $this->subPage === '' ) {
@@ -41,10 +40,10 @@
if ( $this->getUser()->isAllowed( 'ep-org' ) ) {
$this->getOutput()->addModules( 'ep.addorg' );
- $this->addCachedHTML(
'EPOrg::getAddNewControl', array( $this->getContext() ) );
+ $this->addCachedHTML( 'EPOrg::getAddNewControl'
);
}
- $this->addCachedHTML( 'EPOrg::getPager', array(
$this->getContext() ) );
+ $this->addCachedHTML( 'EPOrg::getPager',
$this->getContext() );
$this->saveCache();
}
@@ -60,8 +59,12 @@
protected function getCacheKey() {
$values = $this->getRequest()->getValues();
- $values[] = $this->getUser()->getId();
+ $user = $this->getUser();
+ $values[] = $user->isAllowed( 'ep-org' );
+ $values[] = $user->isAllowed( 'ep-bulkdelorgs' );
+ $values[] = $user->getOption( 'ep_bulkdelorgs' );
+
return array_merge( $values, parent::getCacheKey() );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs