r23083 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23082‎ | r23083 | r23084 >
Date:01:18, 19 June 2007
Author:aaron
Status:old
Tags:
Comment:
*SQL query simplifications and optimizations, use proper labeling
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.sql (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.sql
@@ -6,7 +6,6 @@
77 -- This stores all of our reviews,
88 -- the corresponding tags are stored in the tag table
99 CREATE TABLE /*$wgDBprefix*/flaggedrevs (
10 - fr_id int(10) NOT NULL auto_increment,
1110 fr_namespace int NOT NULL default '0',
1211 fr_title varchar(255) binary NOT NULL default '',
1312 fr_rev_id int(10) NOT NULL,
@@ -21,7 +20,7 @@
2221
2322 PRIMARY KEY (fr_namespace,fr_title,fr_rev_id),
2423 UNIQUE KEY (fr_rev_id),
25 - UNIQUE KEY (fr_id)
 24+ INDEX (fr_namespace,fr_title,fr_quality,fr_rev_id)
2625 ) TYPE=InnoDB;
2726
2827 -- This stores all of our tag data
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php
@@ -86,7 +86,7 @@
8787 // We must at least rate each category as 1, the minimum
8888 // Exception: we can rate ALL as unapproved to depreciate a revision
8989 $this->isValid = true;
90 - if ( $this->upprovedTags && $this->upprovedTags < count($wgFlaggedRevTags) )
 90+ if ( $this->upprovedTags && ($this->upprovedTags < count($wgFlaggedRevTags) || !$this->oflags) )
9191 $this->isValid = false;
9292
9393 if( $this->isValid && $wgRequest->wasPosted() ) {
@@ -173,9 +173,12 @@
174174 foreach( $ratioset as $item ) {
175175 list( $message, $name, $field ) = $item;
176176 // Don't give options the user can't set unless its the status quo
177 - $disabled = ( !$this->userCan($set,$field) ) ? array('disabled' => 'true') : array();
 177+ $attribs = array('id' => $name.$field);
 178+ if( !$this->userCan($set,$field) )
 179+ $attribs['disabled'] = 'true';
178180 $form .= "<div>";
179 - $form .= Xml::radio( $name, $field, ($field==$this->dims[$set]), $disabled ) . ' ' . wfMsg($message);
 181+ $form .= Xml::radio( $name, $field, ($field==$this->dims[$set]), $attribs );
 182+ $form .= Xml::label( wfMsg($message), $name.$field );
180183 $form .= "</div>\n";
181184 }
182185 $form .= '</td><td width=\'20\'></td>';
@@ -225,30 +228,37 @@
226229 $approved = false;
227230 # If all values are set to zero, this has been unapproved
228231 foreach( $this->dims as $quality => $value ) {
229 - if( $value ) $approved = true;
 232+ if( $value ) {
 233+ $approved = true;
 234+ break;
 235+ }
230236 }
231237 // We can only approve actual revisions...
232238 if ( $approved ) {
233239 $rev = Revision::newFromTitle( $this->page, $this->oldid );
234240 // Do not mess with archived/deleted revisions
235241 if ( is_null($rev) || $rev->mDeleted ) {
236 - $wgOut->showErrorPage( 'internalerror', 'badarticleerror' );
 242+ $wgOut->showErrorPage( 'internalerror', 'revnotfoundtext' );
237243 return;
238244 }
239245 } else {
240246 $frev = FlaggedRevs::getFlaggedRev( $this->oldid );
 247+ // If we can't find this flagged rev, return to page???
241248 if ( is_null($frev) ) {
242 - $wgOut->showErrorPage( 'internalerror', 'badarticleerror' );
 249+ $wgOut->redirect( $this->page->escapeLocalUrl() );
243250 return;
244251 }
245252 }
246253
247 - $success = ( $approved ) ?
248 - $this->approveRevision( $rev, $this->notes ) : $this->unapproveRevision( $frev );
 254+ $success = $approved ? $this->approveRevision( $rev, $this->notes ) : $this->unapproveRevision( $frev );
 255+
249256 // Return to our page
250257 if ( $success ) {
251 - if( $request->getCheck( 'wpWatchthis' ) )
 258+ if( $request->getCheck( 'wpWatchthis' ) ) {
252259 $wgUser->addWatch( $this->page );
 260+ } else {
 261+ $wgUser->removeWatch( $this->page );
 262+ }
253263 $wgOut->redirect( $this->page->escapeLocalUrl() );
254264 } else {
255265 $wgOut->showErrorPage( 'internalerror', 'badarticleerror' );
@@ -739,20 +749,20 @@
740750 global $wgContentNamespaces;
741751
742752 list( $page, $flaggedrevs ) = $dbr->tableNamesN( 'page', 'flaggedrevs' );
743 -
 753+
 754+ # Must be a content page...
 755+ $contentNS = 'page_namespace IN(' . implode(',',$wgContentNamespaces) . ')';
 756+
744757 $ns = ($namespace !== null) ? "page_namespace=$namespace" : '1 = 1';
 758+
745759 $where = $includenonquality ? '1 = 1' : 'fr_rev_id IS NULL';
746 - $having = $includenonquality ? '(MAX(fr_quality) IS NULL OR MAX(fr_quality) < 1)' : '1 = 1';
747 - $content = array();
748 - foreach( $wgContentNamespaces as $cns ) {
749 - $content[] = "page_namespace=$cns";
750 - }
751 - $content = implode(' OR ',$content);
 760+ $having = $includenonquality ? 'NOT MAX(fr_quality) > 1' : '1 = 1';
 761+
752762 $sql =
753763 "SELECT page_namespace,page_title,page_len AS size
754764 FROM $page
755765 LEFT JOIN $flaggedrevs ON (fr_namespace = page_namespace AND fr_title = page_title)
756 - WHERE page_is_redirect=0 AND $ns AND ($content) AND ($where)
 766+ WHERE page_is_redirect=0 AND $ns AND $contentNS AND ($where)
757767 GROUP BY page_id HAVING $having ";
758768 return $sql;
759769 }

Status & tagging log