r114195 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114194‎ | r114195 | r114196 >
Date:21:49, 19 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
more work on caching of special:institutions and special:courses
Modified paths:
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -45,12 +45,13 @@
4646
4747 $out->addElement( 'h2', array(), wfMsg( 'ep-institution-courses' ) );
4848
49 - $out->addHTML( EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) ) );
 49+ $out->addHTML( EPCourse::getPager( $this->getContext(), array( 'org_id' => $org->getId() ) ) );
5050
5151 if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
5252 $out->addElement( 'h2', array(), wfMsg( 'ep-institution-add-course' ) );
5353
54 - EPCourse::displayAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) );
 54+ $out->addModules( 'ep.addcourse' );
 55+ $out->addHTML( EPCourse::getAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) ) );
5556 }
5657 }
5758
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -31,7 +31,6 @@
3232 * @param string|null $subPage
3333 */
3434 public function execute( $subPage ) {
35 -
3635 parent::execute( $subPage );
3736
3837 if ( $this->subPage === '' ) {
@@ -41,10 +40,10 @@
4241
4342 if ( $this->getUser()->isAllowed( 'ep-org' ) ) {
4443 $this->getOutput()->addModules( 'ep.addorg' );
45 - $this->addCachedHTML( 'EPOrg::getAddNewControl', array( $this->getContext() ) );
 44+ $this->addCachedHTML( 'EPOrg::getAddNewControl' );
4645 }
4746
48 - $this->addCachedHTML( 'EPOrg::getPager', array( $this->getContext() ) );
 47+ $this->addCachedHTML( 'EPOrg::getPager', $this->getContext() );
4948
5049 $this->saveCache();
5150 }
@@ -60,8 +59,12 @@
6160 protected function getCacheKey() {
6261 $values = $this->getRequest()->getValues();
6362
64 - $values[] = $this->getUser()->getId();
 63+ $user = $this->getUser();
6564
 65+ $values[] = $user->isAllowed( 'ep-org' );
 66+ $values[] = $user->isAllowed( 'ep-bulkdelorgs' );
 67+ $values[] = $user->getOption( 'ep_bulkdelorgs' );
 68+
6669 return array_merge( $values, parent::getCacheKey() );
6770 }
6871
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php
@@ -36,18 +36,42 @@
3737 if ( $this->subPage === '' ) {
3838 $this->displayNavigation();
3939
40 - $this->addCachedHTML(
41 - function( IContextSource $context ) {
42 - return
43 - EPCourse::getAddNewRegion( $context ) . // FIXME
44 - EPCourse::getPager( $context );
45 - },
46 - $this->getContext()
47 - );
 40+ $this->startCache( 900 );
 41+
 42+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
 43+ $this->getOutput()->addModules( 'ep.addcourse' );
 44+
 45+ $this->addCachedHTML(
 46+ function( IContextSource $context ) {
 47+ return
 48+ EPCourse::getAddNewRegion( $context ) . // FIXME
 49+ EPCourse::getPager( $context );
 50+ },
 51+ $this->getContext()
 52+ );
 53+ }
 54+
 55+ $this->saveCache();
4856 }
4957 else {
5058 $this->getOutput()->redirect( Title::newFromText( $this->subPage, EP_NS_COURSE )->getLocalURL() );
5159 }
5260 }
5361
 62+ /**
 63+ * @see SpecialCachedPage::getCacheKey
 64+ * @return array
 65+ */
 66+ protected function getCacheKey() {
 67+ $values = $this->getRequest()->getValues();
 68+
 69+ $user = $this->getUser();
 70+
 71+ $values[] = $user->isAllowed( 'ep-course' );
 72+ $values[] = $user->isAllowed( 'ep-bulkdelcourses' );
 73+ $values[] = $user->getOption( 'ep_bulkdelcourses' );
 74+
 75+ return array_merge( $values, parent::getCacheKey() );
 76+ }
 77+
5478 }
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -140,12 +140,11 @@
141141 *
142142 * @since 0.1
143143 *
144 - * @param IContextSource $context
145144 * @param array $args
146145 *
147146 * @return string
148147 */
149 - public static function getAddNewControl( IContextSource $context, array $args = array() ) {
 148+ public static function getAddNewControl( array $args = array() ) {
150149 $html = '';
151150
152151 $html .= Html::openElement(
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -293,32 +293,30 @@
294294 * @param IContextSource $context
295295 * @param array $args
296296 *
297 - * @return boolean
 297+ * @return string
298298 */
299 - public static function displayAddNewControl( IContextSource $context, array $args ) {
 299+ public static function getAddNewControl( IContextSource $context, array $args ) {
300300 if ( !$context->getUser()->isAllowed( 'ep-course' ) ) {
301 - return false;
 301+ return '';
302302 }
303303
304 - $out = $context->getOutput();
305 -
306 - $out->addModules( 'ep.addcourse' );
 304+ $html = '';
307305
308 - $out->addHTML( Html::openElement(
 306+ $html .= Html::openElement(
309307 'form',
310308 array(
311309 'method' => 'post',
312310 'action' => EPCourses::singleton()->getTitleFor( 'NAME_PLACEHOLDER' )->getLocalURL( array( 'action' => 'edit' ) ),
313311 )
314 - ) );
 312+ );
315313
316 - $out->addHTML( '<fieldset>' );
 314+ $html .= '<fieldset>';
317315
318 - $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) . '</legend>' );
 316+ $html .= '<legend>' . $context->msg( 'ep-courses-addnew' )->escaped() . '</legend>';
319317
320 - $out->addElement( 'p', array(), wfMsg( 'ep-courses-namedoc' ) );
 318+ $html .= '<p>' . $context->msg( 'ep-courses-namedoc' )->escaped() . '</p>';
321319
322 - $out->addElement( 'label', array( 'for' => 'neworg' ), wfMsg( 'ep-courses-neworg' ) );
 320+ $html .= Html::element( 'label', array( 'for' => 'neworg' ), $context->msg( 'ep-courses-neworg' ) );
323321
324322 $select = new XmlSelect(
325323 'neworg',
@@ -327,39 +325,39 @@
328326 );
329327
330328 $select->addOptions( EPOrgs::singleton()->getOrgOptions() );
331 - $out->addHTML( $select->getHTML() );
 329+ $html .= $select->getHTML();
332330
333 - $out->addHTML( '&#160;' . Xml::inputLabel(
334 - wfMsg( 'ep-courses-newname' ),
 331+ $html .= '&#160;' . Xml::inputLabel(
 332+ $context->msg( 'ep-courses-newname' )->escaped(),
335333 'newname',
336334 'newname',
337335 20,
338336 array_key_exists( 'name', $args ) ? $args['name'] : false
339 - ) );
 337+ );
340338
341 - $out->addHTML( '&#160;' . Xml::inputLabel(
342 - wfMsg( 'ep-courses-newterm' ),
 339+ $html .= '&#160;' . Xml::inputLabel(
 340+ $context->msg( 'ep-courses-newterm' )->escaped(),
343341 'newterm',
344342 'newterm',
345343 10,
346344 array_key_exists( 'term', $args ) ? $args['term'] : false
347 - ) );
 345+ );
348346
349 - $out->addHTML( '&#160;' . Html::input(
 347+ $html .= '&#160;' . Html::input(
350348 'addnewcourse',
351 - wfMsg( 'ep-courses-add' ),
 349+ $context->msg( 'ep-courses-add' )->escaped(),
352350 'submit',
353351 array(
354352 'disabled' => 'disabled',
355353 'class' => 'ep-course-add',
356354 )
357 - ) );
 355+ );
358356
359 - $out->addHTML( Html::hidden( 'isnew', 1 ) );
 357+ $html .= Html::hidden( 'isnew', 1 );
360358
361 - $out->addHTML( '</fieldset></form>' );
 359+ $html .= '</fieldset></form>';
362360
363 - return true;
 361+ return $html;
364362 }
365363
366364 /**
@@ -370,13 +368,15 @@
371369 *
372370 * @param IContextSource $context
373371 * @param array $args
 372+ *
 373+ * @return string
374374 */
375 - public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
 375+ public static function getAddNewRegion( IContextSource $context, array $args = array() ) {
376376 if ( EPOrgs::singleton()->has() ) {
377 - EPCourse::displayAddNewControl( $context, $args );
 377+ return EPCourse::getAddNewControl( $context, $args );
378378 }
379 - elseif ( $context->getUser()->isAllowed( 'ep-course' ) ) {
380 - $context->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
 379+ else {
 380+ return $context->msg( 'ep-courses-addorgfirst' )->escaped();
381381 }
382382 }
383383

Status & tagging log