r21599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21598‎ | r21599 | r21600 >
Date:02:07, 26 April 2007
Author:aaron
Status:old
Tags:
Comment:
*Schema changes, better relate some data, make restriction table more dynamic
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.sql (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -333,7 +333,8 @@
334334 /**
335335 * Get all the revisions that meet the requirments
336336 * per the $wgFlaggedRevTags variable
337 - * This can become expensive
 337+ * This can become expensive, use it if you changed
 338+ * your quality criteria
338339 * @param database $db
339340 * @param int $page_id
340341 * @param int $limit
@@ -784,10 +785,11 @@
785786 $dbr = wfGetDB( DB_SLAVE );
786787 // Skip deleted revisions
787788 $result = $dbr->select(
788 - array('flaggedpages', 'flaggedrevs', 'revision'),
 789+ array('flaggedrevs', 'revision'),
789790 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
790 - array('fp_page_id' => $article->getId(), 'fp_latest_q = fr_rev_id', 'fp_latest_q=rev_id', 'rev_deleted=0'),
791 - __METHOD__ );
 791+ array('fr_page_id' => $article->getId(), 'fr_rev_id = rev_id', 'fr_quality=1', 'rev_deleted=0'),
 792+ __METHOD__,
 793+ array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
792794 // Do we have one?
793795 if ( $row = $dbr->fetchObject($result) ) {
794796 $this->stablefound = true;
@@ -822,10 +824,11 @@
823825 $dbr = wfGetDB( DB_SLAVE );
824826 // Skip deleted revisions
825827 $result = $dbr->select(
826 - array('flaggedpages', 'flaggedrevs', 'revision'),
 828+ array('flaggedrevs', 'revision'),
827829 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
828 - array('fp_page_id' => $article->getId(), 'fp_latest = fr_rev_id', 'fp_latest=rev_id', 'rev_deleted=0'),
829 - __METHOD__ );
 830+ array('fr_page_id' => $article->getId(), 'fr_rev_id = rev_id', 'rev_deleted=0'),
 831+ __METHOD__,
 832+ array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
830833 // Do we have one?
831834 if ( $row = $dbr->fetchObject($result) ) {
832835 $this->latestfound = true;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.sql
@@ -12,10 +12,11 @@
1313 fr_rev_id int(10) NOT NULL,
1414 fr_user int(5) NOT NULL,
1515 fr_timestamp char(14) NOT NULL,
16 - fr_comment mediumblob default NULL,
 16+ fr_comment mediumblob NOT NULL default '',
1717 -- Store the text with all transclusions resolved
1818 -- This will trade space for more speed and reliability
19 - fr_text mediumblob default NULL,
 19+ fr_text mediumblob NOT NULL default '',
 20+ fr_quality tinyint(1) default 0,
2021
2122 PRIMARY KEY fr_rev_id (fr_rev_id),
2223 UNIQUE KEY (fr_id),
@@ -34,15 +35,13 @@
3536 INDEX frt_page_rev_val (frt_page_id,frt_rev_id,frt_dimension,frt_value)
3637 ) TYPE=InnoDB;
3738
 39+-- For future restrictons
3840 CREATE TABLE /*$wgDBprefix*/flaggedpages (
3941 fp_page_id int(10) NOT NULL,
40 - -- What are the latest reviewed and "quality" revisions
41 - fp_latest int(10) NOT NULL,
42 - fp_latest_q int(10) NOT NULL,
43 - -- minimum quality levels for some pages, csv
44 - fp_restrictions tinyblob NOT NULL,
 42+ -- The tag type
 43+ pr_dimension varchar(255) NOT NULL,
 44+ -- The protection level (Sysop, autoconfirmed, etc)
 45+ pr_level varchar(255) NOT NULL,
4546
4647 PRIMARY KEY fp_page_id (fp_page_id),
47 - INDEX fp_page_latest (fp_page_id,fp_latest,fp_latest_q)
4848 ) TYPE=InnoDB;
\ No newline at end of file
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php
@@ -254,6 +254,12 @@
255255 // Parse the text into HTML
256256 $parserOutput = FlaggedRevs::parseStableText( $rev->getTitle(), $fulltext, $rev->getID(), new ParserOptions, $timestamp );
257257
 258+ $quality = 0;
 259+ if ( FlaggedRevs::isPristine($this->dims) )
 260+ $quality = 2;
 261+ else if ( FlaggedRevs::isQuality($this->dims) )
 262+ $quality = 1;
 263+
258264 $dbw = wfGetDB( DB_MASTER );
259265 // Our review entry
260266 $revset = array(
@@ -262,7 +268,8 @@
263269 'fr_user' => $wgUser->getId(),
264270 'fr_timestamp' => $timestamp,
265271 'fr_comment' => $notes,
266 - 'fr_text' => $fulltext // Store expanded text for good-measure
 272+ 'fr_text' => $fulltext, // Store expanded text for good-measure
 273+ 'fr_quality' => $quality
267274 );
268275 // Our flags
269276 $flagset = array();
@@ -278,26 +285,7 @@
279286 $dbw->replace( 'flaggedrevs', array( array('fr_page_id','fr_rev_id') ), $revset, __METHOD__ );
280287 // Set all of our flags
281288 $dbw->replace( 'flaggedrevtags', array( array('frt_rev_id','frt_dimension') ), $flagset, __METHOD__ );
282 - // Update our flagged page table if needed
283 - $res = $dbw->select( 'flaggedpages', array('fp_page_id'), array('fp_page_id' => $rev->getPage() ), __METHOD__ );
284 - if ( $dbw->numrows($res) ) {
285 - # This page has an entry, update it...
286 - $dbw->update( 'flaggedpages',
287 - array( 'fp_latest' => $rev->getId() ),
288 - array( 'fp_page_id' => $rev->getPage(), "fp_latest < ".$rev->getId() ),
289 - __METHOD__ );
290 - } else {
291 - # Insert our new rows...
292 - $dbw->insert( 'flaggedpages',
293 - array( 'fp_page_id' => $rev->getPage(), 'fp_latest' => $rev->getId(), 'fp_latest_q' => 0 ),
294 - __METHOD__ );
295 - }
296 - if ( FlaggedRevs::isQuality($this->dims) ) {
297 - $dbw->update( 'flaggedpages',
298 - array( 'fp_latest_q' => $rev->getId() ),
299 - array( 'fp_page_id' => $rev->getPage(), "fp_latest_q < ".$rev->getId() ),
300 - __METHOD__ );
301 - }
 289+
302290 // Update the article review log
303291 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, true );
304292
@@ -327,24 +315,7 @@
328316 $dbw->delete( 'flaggedrevs', array( 'fr_rev_id' => $row->fr_rev_id ) );
329317 // And the flags...
330318 $dbw->delete( 'flaggedrevtags', array( 'frt_rev_id' => $row->fr_rev_id ) );
331 - // Update our page table, what is the new top flagged rev?
332 - // Read from the master to get up to date values
333 - // Check for top remaining rev...
334 - list($lrev) = FlaggedRevs::getStableRevisions( $dbw, $row->fr_page_id, 1 );
335 - $dbw->update( 'flaggedpages',
336 - array( 'fp_latest' => $lrev ? $lrev->fr_rev_id : 0 ),
337 - array( 'fp_page_id' => $row->fr_page_id ),
338 - __METHOD__ );
339 - // Check for top remaining quality rev
340 - $lqrev = false;
341 - if ( $lrev ) {
342 - list($lqrev) = FlaggedRevs::getQualityRevisions( $dbw, $row->fr_page_id, 1 );
343 - }
344 - // Fallback to the newest remaining one
345 - $dbw->update( 'flaggedpages',
346 - array( 'fp_latest_q' => $lqrev ? $lrev->fr_rev_id : 0),
347 - array( 'fp_page_id' => $row->fr_page_id ),
348 - __METHOD__ );
 319+
349320 // Update the article review log
350321 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, false );
351322
@@ -653,20 +624,21 @@
654625 function getSQLText( &$dbr, $namespace, $nonquality = false ) {
655626 global $wgContentNamespaces;
656627
657 - list( $page, $flaggedpages ) = $dbr->tableNamesN( 'page', 'flaggedpages' );
 628+ list( $page, $flaggedrevs ) = $dbr->tableNamesN( 'page', 'flaggedrevs' );
658629
659630 $ns = ($namespace !== null) ? "page_namespace=$namespace" : '1 = 1';
660 - $where = $nonquality ? 'fp_latest IS NULL OR fp_latest=0' : 'fp_latest_q IS NULL OR fp_latest_q=0';
 631+ $where = $nonquality ? '1 = 1' : 'fr_rev_id IS NULL';
661632 $content = array();
662633 foreach( $wgContentNamespaces as $cns ) {
663634 $content[] = "page_namespace=$cns";
664635 }
665636 $content = implode(' OR ',$content);
666637 $sql =
667 - "SELECT page_namespace AS namespace,page_title AS title,page_len AS size
 638+ "SELECT page_namespace,page_title,page_len AS size, MAX(fr_quality) as quality, COUNT(*) as num
668639 FROM $page
669 - LEFT JOIN $flaggedpages ON page_id = fp_page_id
670 - WHERE page_is_redirect=0 AND $ns AND ($where) AND ($content) ";
 640+ LEFT JOIN $flaggedrevs ON page_id=fr_page_id
 641+ WHERE page_is_redirect=0 AND $ns AND ($where) AND ($content)
 642+ GROUP BY page_id ";
671643 return $sql;
672644 }
673645
@@ -681,9 +653,13 @@
682654
683655 function formatResult( $skin, $result ) {
684656 global $wgLang;
685 -
 657+
 658+ // If the best revision of the page is quality
 659+ // then skip it...
 660+ if ( $this->nonquality && $result->quality >= 1 )
 661+ return false;
686662 $fname = 'UnreviewedPagesPage::formatResult';
687 - $title = Title::makeTitle( $result->namespace, $result->title );
 663+ $title = Title::makeTitle( $result->page_namespace, $result->page_title );
688664 $link = $skin->makeKnownLinkObj( $title );
689665 $stxt = '';
690666 if (!is_null($size = $result->size)) {