r23371 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23370‎ | r23371 | r23372 >
Date:08:52, 25 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Reports can append additional bits of SQL to queries, e.g. for grouping, etc.
* Port Special:WantedPages
* Profile cache updates, and spit out the read times in maintenance/updateReports.php too
Modified paths:
  • /branches/robchurch/reports/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/reports/includes/QueryPage.php (modified) (history)
  • /branches/robchurch/reports/includes/SpecialPage.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportCache.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportPager.php (modified) (history)
  • /branches/robchurch/reports/languages/messages/MessagesEn.php (modified) (history)
  • /branches/robchurch/reports/maintenance/language/messageTypes.inc (modified) (history)
  • /branches/robchurch/reports/maintenance/language/messages.inc (modified) (history)
  • /branches/robchurch/reports/maintenance/updateReports.php (modified) (history)

Diff [purge]

Index: branches/robchurch/reports/languages/messages/MessagesEn.php
@@ -1576,7 +1576,7 @@
15771577 'wantedcategories' => 'Wanted categories',
15781578 'wantedcategories-summary' => '', # only translate this message to other languages if you have to change it
15791579 'wantedpages' => 'Wanted pages',
1580 -'wantedpages-summary' => '', # only translate this message to other languages if you have to change it
 1580+'wantedpages-header' => 'This report lists pages which don\'t exist, but have $1 or more incoming links.',
15811581 'mostlinked' => 'Most linked to pages',
15821582 'mostlinked-summary' => '', # only translate this message to other languages if you have to change it
15831583 'mostlinkedcategories' => 'Most linked to categories',
Index: branches/robchurch/reports/includes/SpecialPage.php
@@ -97,7 +97,7 @@
9898 'Uncategorizedtemplates' => array( 'SpecialRedirect', 'Uncategorizedpages', array( 'namespace' => NS_TEMPLATE ) ),
9999 'Unusedcategories' => array( 'SpecialPage', 'Unusedcategories' ),
100100 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ),
101 - 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ),
 101+ 'Wantedpages' => 'WantedPagesReport',
102102 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ),
103103 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
104104 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
Index: branches/robchurch/reports/includes/reports/ReportPager.php
@@ -62,6 +62,7 @@
6363
6464 $sql = $this->report->getBaseSql( $this->mDb )
6565 . ' WHERE ' . implode( ' AND ', $conds )
 66+ . $this->report->getExtraSql( $this->mDb )
6667 . ' ' . implode( ' ', $options );
6768 wfDebugLog( 'reports', __METHOD__ . " executing `{$sql}`" );
6869 $this->mResult = new ResultWrapper(
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -143,6 +143,17 @@
144144 }
145145
146146 /**
 147+ * Get additional SQL to be inserted between the
 148+ * conditions and ORDER clauses when the report is run live
 149+ *
 150+ * @param Database $dbr Database object being queried
 151+ * @return string
 152+ */
 153+ public function getExtraSql( $dbr ) {
 154+ return '';
 155+ }
 156+
 157+ /**
147158 * Get ORDER BY clauses to be applied when the
148159 * report is run live
149160 *
@@ -375,6 +386,7 @@
376387 'ShortPagesReport',
377388 'UncategorisedPagesReport',
378389 'UnwatchedPagesReport',
 390+ 'WantedPagesReport',
379391 'WithoutInterwikiReport',
380392 ) + $GLOBALS['wgCustomReports'];
381393 }
Index: branches/robchurch/reports/includes/reports/ReportCache.php
@@ -16,7 +16,9 @@
1717 * @param callback $namespaceCallback Callback after each namespace
1818 */
1919 public static function recache( $report, $limit = 1000, $namespaceCallback = null ) {
 20+ wfProfileIn( __METHOD__ );
2021 foreach( self::getNamespaces( $report ) as $namespace ) {
 22+ $fname = __METHOD__ . '::' . $report->getName() . '_(' . $namespace . ')';
2123 # Clear existing cached entries for this report and namespace
2224 $dbw = wfGetDB( DB_MASTER );
2325 $dbw->delete(
@@ -27,15 +29,19 @@
2830 ),
2931 __METHOD__
3032 );
31 - # Obtain fresh entries for the report
 33+ # Obtain fresh entries for the report
 34+ wfProfileIn( "{$fname}-read" );
 35+ $start = time();
3236 $dbr = wfGetDB( DB_SLAVE );
3337 $sql = $report->getBaseSql( $dbr );
3438 $conds = $report->getExtraConditions( $dbr );
3539 $conds[] = $report->getNamespaceClause( $namespace );
3640 $sql .= ' WHERE ' . implode( ' AND ', $conds );
 41+ $sql .= $report->getExtraSql( $dbr );
3742 $sql .= " LIMIT {$limit}";
3843 $res = $dbr->query( $sql, __METHOD__ );
3944 $rows = $dbr->numRows( $res );
 45+ wfProfileOut( "{$fname}-read" );
4046 # Insert the new entries into the cache
4147 while( $row = $dbr->fetchObject( $res ) ) {
4248 $dbw->insert(
@@ -61,10 +67,12 @@
6268 ),
6369 __METHOD__
6470 );
 71+ $time = time() - $start;
6572 # Callback?
6673 if( is_callable( $namespaceCallback ) )
67 - call_user_func( $namespaceCallback, $report, $namespace, $rows );
 74+ call_user_func( $namespaceCallback, $report, $namespace, $rows, $time );
6875 }
 76+ wfProfileOut( __METHOD__ );
6977 }
7078
7179 /**
Index: branches/robchurch/reports/includes/AutoLoader.php
@@ -217,7 +217,6 @@
218218 'UserrightsForm' => 'includes/SpecialUserrights.php',
219219 'SpecialVersion' => 'includes/SpecialVersion.php',
220220 'WantedCategoriesPage' => 'includes/SpecialWantedcategories.php',
221 - 'WantedPagesPage' => 'includes/SpecialWantedpages.php',
222221 'WhatLinksHerePage' => 'includes/SpecialWhatlinkshere.php',
223222 'SquidUpdate' => 'includes/SquidUpdate.php',
224223 'ReplacementArray' => 'includes/StringUtils.php',
@@ -292,6 +291,7 @@
293292 'ShortPagesReport' => 'includes/reports/ShortPagesReport.php',
294293 'UncategorisedPagesReport' => 'includes/reports/UncategorisedPagesReport.php',
295294 'UnwatchedPagesReport' => 'includes/reports/UnwatchedPagesReport.php',
 295+ 'WantedPagesReport' => 'includes/reports/WantedPagesReport.php',
296296 'WithoutInterwikiReport' => 'includes/reports/WithoutInterwikiReport.php',
297297
298298 # API
Index: branches/robchurch/reports/includes/QueryPage.php
@@ -25,8 +25,9 @@
2626 array( 'FewestrevisionsPage', 'Fewestrevisions' ),
2727 array( 'UnusedCategoriesPage', 'Unusedcategories' ),
2828 array( 'UnusedimagesPage', 'Unusedimages' ),
 29+
2930 array( 'WantedCategoriesPage', 'Wantedcategories' ),
30 - array( 'WantedPagesPage', 'Wantedpages' ),
 31+
3132 array( 'UnusedtemplatesPage', 'Unusedtemplates' ),
3233 );
3334 wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
Index: branches/robchurch/reports/maintenance/updateReports.php
@@ -34,8 +34,9 @@
3535 }
3636 echo( "Done!\n" );
3737
38 -function updateReportsCallback( $report, $namespace, $rows ) {
39 - echo( "\tNamespace {$namespace}\t{$rows} rows\n" );
 38+function updateReportsCallback( $report, $namespace, $rows, $time ) {
 39+ $time = round( $time, 3 );
 40+ echo( "\tNamespace {$namespace}\t{$rows} rows\t{$time}s\n" );
4041 }
4142
4243 ?>
\ No newline at end of file
Index: branches/robchurch/reports/maintenance/language/messages.inc
@@ -967,7 +967,7 @@
968968 'wantedcategories',
969969 'wantedcategories-summary',
970970 'wantedpages',
971 - 'wantedpages-summary',
 971+ 'wantedpages-header',
972972 'mostlinked',
973973 'mostlinked-summary',
974974 'mostlinkedcategories',
Index: branches/robchurch/reports/maintenance/language/messageTypes.inc
@@ -120,7 +120,6 @@
121121 'whatlinkshere-barrow',
122122 'imagelist-summary',
123123 'wantedcategories-summary',
124 - 'wantedpages-summary',
125124 'mostlinked-summary',
126125 'mostlinkedcategories-summary',
127126 'mostlinkedtemplates-summary',

Status & tagging log