r109890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109889‎ | r109890 | r109891 >
Date:01:16, 24 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r109872; r109876; make use of chronological pager to list revs
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionPager.php (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourseHistory.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPHistory.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutionHistory.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMasterCourseHistory.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialMasterCourseHistory.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'MasterCourseHistory', '', false );
 23+ parent::__construct( 'MasterCourseHistory' );
2424 }
2525
2626 /**
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutionHistory.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'InstitutionHistory', '', false );
 23+ parent::__construct( 'InstitutionHistory' );
2424 }
2525
2626 /**
Index: trunk/extensions/EducationProgram/specials/SpecialCourseHistory.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'CourseHistory', '', false );
 23+ parent::__construct( 'CourseHistory' );
2424 }
2525
2626 /**
Index: trunk/extensions/EducationProgram/specials/SpecialEPHistory.php
@@ -13,6 +13,25 @@
1414 */
1515 abstract class SpecialEPHistory extends SpecialEPPage {
1616
 17+ /**
 18+ * @see parent::__construct
 19+ *
 20+ * @since 0.1
 21+ *
 22+ * @param string $name
 23+ * @param string $restriction
 24+ */
 25+ public function __construct( $name, $restriction = '' ) {
 26+ parent::__construct( $name, $restriction, false );
 27+ }
 28+
 29+ /**
 30+ * Display a list with the passed revisions.
 31+ *
 32+ * @since 0.1
 33+ *
 34+ * @param EPDBObject $object
 35+ */
1736 protected function displayRevisions( EPDBObject $object ) {
1837 $conditions = array(
1938 'type' => get_class( $object ),
@@ -22,18 +41,70 @@
2342 $conditions['object_id'] = $object->getId();
2443 }
2544
26 - $revisions = EPRevision::select(
27 - null,
28 - $conditions
 45+ $action = htmlspecialchars( $GLOBALS['wgScript'] );
 46+
 47+ $request = $this->getRequest();
 48+ $out = $this->getOutput();
 49+
 50+ /**
 51+ * Add date selector to quickly get to a certain time
 52+ */
 53+ $year = $request->getInt( 'year' );
 54+ $month = $request->getInt( 'month' );
 55+ $tagFilter = $request->getVal( 'tagfilter' );
 56+ $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
 57+
 58+ /**
 59+ * Option to show only revisions that have been (partially) hidden via RevisionDelete
 60+ */
 61+ if ( $request->getBool( 'deleted' ) ) {
 62+ $conditions['deleted'] = true;
 63+ }
 64+
 65+ $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
 66+ 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
 67+
 68+ $out->addHTML(
 69+ "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
 70+ Xml::fieldset(
 71+ $this->msg( 'history-fieldset-title' )->text(),
 72+ false,
 73+ array( 'id' => 'mw-history-search' )
 74+ ) .
 75+ Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" .
 76+ Html::hidden( 'action', 'history' ) . "\n" .
 77+ Xml::dateMenu( $year, $month ) . '&#160;' .
 78+ ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
 79+ $checkDeleted .
 80+ Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
 81+ '</fieldset></form>'
2982 );
3083
31 - if ( count( $revisions ) > 0 ) {
32 - array_unshift( $revisions, EPRevision::newFromObject( $object ) );
33 - $this->displayRevisionList( $revisions );
 84+ $pager = new EPRevisionPager( $this->getContext(), $conditions );
 85+
 86+ if ( $pager->getNumRows() ) {
 87+ $out->addHTML(
 88+ $pager->getNavigationBar() .
 89+ $pager->getBody() .
 90+ $pager->getNavigationBar()
 91+ );
3492 }
3593 else {
3694 // TODO
3795 }
 96+
 97+// $revisions = EPRevision::select(
 98+// null,
 99+// $conditions
 100+// );
 101+//
 102+// if ( count( $revisions ) > 0 ) {
 103+// array_unshift( $revisions, EPRevision::newFromObject( $object ) );
 104+// $this->displayRevisionList( $revisions );
 105+// }
 106+// else {
 107+// // TODO
 108+// }
38109 }
39110
40111 protected function displayRevisionList( array /* of EPRevision */ $revisions ) {
Index: trunk/extensions/EducationProgram/includes/EPRevisionPager.php
@@ -0,0 +1,154 @@
 2+<?php
 3+
 4+/**
 5+ * History pager.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPRevisionPager.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPRevisionPager extends ReverseChronologicalPager {
 16+
 17+ /**
 18+ * Context in which this pager is being shown.
 19+ * @since 0.1
 20+ * @var IContextSource
 21+ */
 22+ protected $context;
 23+
 24+ /**
 25+ * Constructor.
 26+ *
 27+ * @param IContextSource $context
 28+ * @param array $conds
 29+ * @param string $className
 30+ */
 31+ public function __construct( IContextSource $context, array $conds ) {
 32+ $this->conds = $conds;
 33+ $this->context = $context;
 34+
 35+ $this->mDefaultDirection = true;
 36+
 37+ if ( method_exists( 'ReverseChronologicalPager', 'getUser' ) ) {
 38+ parent::__construct( $context );
 39+ }
 40+ else {
 41+ parent::__construct();
 42+ }
 43+ }
 44+
 45+ /**
 46+ * Get the OutputPage being used for this instance.
 47+ * IndexPager extends ContextSource as of 1.19.
 48+ *
 49+ * @since 0.1
 50+ *
 51+ * @return OutputPage
 52+ */
 53+ public function getOutput() {
 54+ return $this->context->getOutput();
 55+ }
 56+
 57+ /**
 58+ * Get the Language being used for this instance.
 59+ * IndexPager extends ContextSource as of 1.19.
 60+ *
 61+ * @since 0.1
 62+ *
 63+ * @return Language
 64+ */
 65+ public function getLanguage() {
 66+ return method_exists( $this->context, 'getLanguage' ) ? $this->context->getLanguage() : $this->context->getLang();
 67+ }
 68+
 69+ /**
 70+ * Get the User being used for this instance.
 71+ * IndexPager extends ContextSource as of 1.19.
 72+ *
 73+ * @since 0.1
 74+ *
 75+ * @return User
 76+ */
 77+ public function getUser() {
 78+ return $this->context->getUser();
 79+ }
 80+
 81+ /**
 82+ * Get the WebRequest being used for this instance.
 83+ * IndexPager extends ContextSource as of 1.19.
 84+ *
 85+ * @since 0.1
 86+ *
 87+ * @return WebRequest
 88+ */
 89+ public function getRequest() {
 90+ return $this->context->getRequest();
 91+ }
 92+
 93+ /**
 94+ * Get the Title being used for this instance.
 95+ * IndexPager extends ContextSource as of 1.19.
 96+ *
 97+ * @since 0.1
 98+ *
 99+ * @return Title
 100+ */
 101+ public function getTitle() {
 102+ return $this->context->getTitle();
 103+ }
 104+
 105+ /**
 106+ * Abstract formatting function. This should return an HTML string
 107+ * representing the result row $row. Rows will be concatenated and
 108+ * returned by getBody()
 109+ *
 110+ * @param $row Object: database row
 111+ *
 112+ * @return String
 113+ */
 114+ function formatRow( $row ) {
 115+ return json_encode( $row ); // TODO
 116+ }
 117+
 118+ /**
 119+ * This function should be overridden to provide all parameters
 120+ * needed for the main paged query. It returns an associative
 121+ * array with the following elements:
 122+ * tables => Table(s) for passing to Database::select()
 123+ * fields => Field(s) for passing to Database::select(), may be *
 124+ * conds => WHERE conditions
 125+ * options => option array
 126+ * join_conds => JOIN conditions
 127+ *
 128+ * @return Array
 129+ */
 130+ function getQueryInfo() {
 131+ return array(
 132+ 'tables' => EPRevision::getDBTable(),
 133+ 'fields' => EPRevision::getPrefixedFields( EPRevision::getFieldNames() ),
 134+ 'conds' => EPRevision::getPrefixedValues( $this->conds )
 135+ );
 136+ }
 137+
 138+ /**
 139+ * This function should be overridden to return the name of the index fi-
 140+ * eld. If the pager supports multiple orders, it may return an array of
 141+ * 'querykey' => 'indexfield' pairs, so that a request with &count=querykey
 142+ * will use indexfield to sort. In this case, the first returned key is
 143+ * the default.
 144+ *
 145+ * Needless to say, it's really not a good idea to use a non-unique index
 146+ * for this! That won't page right.
 147+ *
 148+ * @return string|Array
 149+ */
 150+ function getIndexField() {
 151+ return EPRevision::getPrefixedField( 'id' );
 152+ }
 153+
 154+
 155+}
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -82,6 +82,7 @@
8383 $wgAutoloadClasses['EPCAPager'] = dirname( __FILE__ ) . '/includes/EPCAPager.php';
8484 $wgAutoloadClasses['EPHTMLDateField'] = dirname( __FILE__ ) . '/includes/EPHTMLDateField.php';
8585 $wgAutoloadClasses['EPRevision'] = dirname( __FILE__ ) . '/includes/EPRevision.php';
 86+$wgAutoloadClasses['EPRevisionPager'] = dirname( __FILE__ ) . '/includes/EPRevisionPager.php';
8687
8788 $wgAutoloadClasses['SpecialCourse'] = dirname( __FILE__ ) . '/specials/SpecialCourse.php';
8889 $wgAutoloadClasses['SpecialCourses'] = dirname( __FILE__ ) . '/specials/SpecialCourses.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r109891follow up to r109890; some refactoringjeroendedauw01:33, 24 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109872some initial work on revision supportjeroendedauw23:35, 23 January 2012
r109876Follow up to r109872; added extra special pagesjeroendedauw23:58, 23 January 2012

Status & tagging log