From: Matthias Mullie Date: Mon, 23 Mar 2015 13:47:58 +0000 (+0100) Subject: Let extensions add entries to Special:DeletedContributions X-Git-Tag: 1.31.0-rc.0~11932^2 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=62a5454aad86951e239223224083dbe4cb75c4cb;p=lhc%2Fweb%2Fwiklou.git Let extensions add entries to Special:DeletedContributions Bug: T90973 Change-Id: I0cb5340311262084a3120fdb0314fd26193c07a3 --- diff --git a/HISTORY b/HISTORY index e5864fd670..6ea5c2e0a8 100644 --- a/HISTORY +++ b/HISTORY @@ -190,6 +190,10 @@ Change notes from older releases. For current info see RELEASE-NOTES-1.25. to multiple Config instances. * Update CSSJanus to v1.1.0. * Added FormatJson::parse() returning status with result or localized error message +* Added DeletedContribsPager::reallyDoQuery hook allowing extensions to data to + Special:DeletedContributions +* Added DeletedContributionsLineEnding hook allowing extensions to format + Special:DeletedContributions lines === Bug fixes in 1.24 === * (bug 50572) MediaWiki:Blockip should support gender diff --git a/docs/hooks.txt b/docs/hooks.txt index 20f5de8671..f2c47cac6e 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1061,6 +1061,21 @@ etc. 'DatabaseOraclePostInit': Called after initialising an Oracle database &$db: the DatabaseOracle object +'DeletedContribsPager::reallyDoQuery': Called before really executing the query for Special:DeletedContributions +Similar to ContribsPager::reallyDoQuery +&$data: an array of results of all contribs queries +$pager: The DeletedContribsPager object hooked into +$offset: Index offset, inclusive +$limit: Exact query limit +$descending: Query direction, false for ascending, true for descending + +'DeletedContributionsLineEnding': Called before a DeletedContributions HTML line is finished. +Similar to ContributionsLineEnding +$page: SpecialPage object for DeletedContributions +&$ret: the HTML line +$row: the DB row for this line +&$classes: the classes to add to the surrounding
  • + 'NewDifferenceEngine': Called when a new DifferenceEngine object is made $title: the diff page title (nullable) &$oldId: the actual old Id to use in the diff diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 680aa35933..9e4bbbe532 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -78,6 +78,53 @@ class DeletedContribsPager extends IndexPager { ); } + /** + * This method basically executes the exact same code as the parent class, though with + * a hook added, to allow extensions to add additional queries. + * + * @param string $offset Index offset, inclusive + * @param int $limit Exact query limit + * @param bool $descending Query direction, false for ascending, true for descending + * @return ResultWrapper + */ + function reallyDoQuery( $offset, $limit, $descending ) { + $pager = $this; + + $data = array( parent::reallyDoQuery( $offset, $limit, $descending ) ); + + // This hook will allow extensions to add in additional queries, nearly + // identical to ContribsPager::reallyDoQuery. + Hooks::run( + 'DeletedContribsPager::reallyDoQuery', + array( &$data, $pager, $offset, $limit, $descending ) + ); + + $result = array(); + + // loop all results and collect them in an array + foreach ( $data as $query ) { + foreach ( $query as $i => $row ) { + // use index column as key, allowing us to easily sort in PHP + $result[$row->{$this->getIndexField()} . "-$i"] = $row; + } + } + + // sort results + if ( $descending ) { + ksort( $result ); + } else { + krsort( $result ); + } + + // enforce limit + $result = array_slice( $result, 0, $limit ); + + // get rid of array keys + $result = array_values( $result ); + + return new FakeResultWrapper( $result ); + } + function getUserCond() { $condition = array(); @@ -141,6 +188,50 @@ class DeletedContribsPager extends IndexPager { /** * Generates each row in the contributions list. * + * @todo This would probably look a lot nicer in a table. + * @param stdClass $row + * @return string + */ + function formatRow( $row ) { + $ret = ''; + $classes = array(); + + /* + * There may be more than just revision rows. To make sure that we'll only be processing + * revisions here, let's _try_ to build a revision out of our row (without displaying + * notices though) and then trying to grab data from the built object. If we succeed, + * we're definitely dealing with revision data and we may proceed, if not, we'll leave it + * to extensions to subscribe to the hook to parse the row. + */ + wfSuppressWarnings(); + try { + $rev = Revision::newFromArchiveRow( $row ); + $validRevision = (bool)$rev->getId(); + } catch ( Exception $e ) { + $validRevision = false; + } + wfRestoreWarnings(); + + if ( $validRevision ) { + $ret = $this->formatRevisionRow( $row ); + } + + // Let extensions add data + Hooks::run( 'DeletedContributionsLineEnding', array( $this, &$ret, $row, &$classes ) ); + + if ( $classes === array() && $ret === '' ) { + wfDebug( "Dropping Special:DeletedContribution row that could not be formatted\n" ); + $ret = "\n"; + } else { + $ret = Html::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n"; + } + + return $ret; + } + + /** + * Generates each row in the contributions list for archive entries. + * * Contributions which are marked "top" are currently on top of the history. * For these contributions, a [rollback] link is shown for users with sysop * privileges. The rollback link restores the most recent version that was not @@ -150,8 +241,7 @@ class DeletedContribsPager extends IndexPager { * @param stdClass $row * @return string */ - function formatRow( $row ) { - + function formatRevisionRow( $row ) { $page = Title::makeTitle( $row->ar_namespace, $row->ar_title ); $rev = new Revision( array( @@ -255,8 +345,6 @@ class DeletedContribsPager extends IndexPager { $ret .= " " . $this->msg( 'rev-deleted-user-contribs' )->escaped() . ""; } - $ret = Html::rawElement( 'li', array(), $ret ) . "\n"; - return $ret; }