r85230 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85229‎ | r85230 | r85231 >
Date:05:53, 3 April 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* Removed isset() checks - redundant given Parser::version
* For sanity in insertOn(), if the template/file version arrays are null, don't hit the DB - just assume they are empty
* Refactored mFlags handling in FlaggedRevision
* Use accessors for ParserOutput template/file versions
* Added OutputPage accessors for template/file versions
* Changed instance of NS_IMAGE -> NS_FILE
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiReview.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -1266,6 +1266,24 @@
12671267 }
12681268
12691269 /**
 1270+ * Get the templates used on this page
 1271+ *
 1272+ * @return Array (namespace => dbKey => revId)
 1273+ */
 1274+ public function getTemplateIds() {
 1275+ return $this->mTemplateIds;
 1276+ }
 1277+
 1278+ /**
 1279+ * Get the files used on this page
 1280+ *
 1281+ * @return Array (dbKey => array('time' => MW timestamp or null, 'sha1' => sha1 or ''))
 1282+ */
 1283+ public function getImageTimeKeys() {
 1284+ return $this->mImageTimeKeys;
 1285+ }
 1286+
 1287+ /**
12701288 * Convert wikitext to HTML and add it to the buffer
12711289 * Default assumes that the current page title will be used.
12721290 *
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -1193,7 +1193,7 @@
11941194 * and the page tables updated, but before LinksUpdate is called.
11951195 *
11961196 * $auto is here for revisions checked off to be reviewed. Auto-review
1197 - * triggers on edit, but we don't want it to count as just automatic.
 1197+ * triggers on edit, but we don't want those to count as just automatic.
11981198 * This also makes it so the user's name shows up in the page history.
11991199 *
12001200 * If $flags is given, then they will be the review tags. If not, the one
@@ -1232,6 +1232,8 @@
12331233 if ( self::isQuality( $flags ) ) {
12341234 $quality = self::isPristine( $flags ) ? 2 : 1;
12351235 }
 1236+ # Get review property flags
 1237+ $propFlags = $auto ? array( 'auto' ) : array();
12361238
12371239 # Rev ID is not put into parser on edit, so do the same here.
12381240 # Also, a second parse would be triggered otherwise.
@@ -1256,16 +1258,16 @@
12571259 'rev_id' => $rev->getId(),
12581260 'user' => $user->getId(),
12591261 'timestamp' => $rev->getTimestamp(),
1260 - 'comment' => "",
12611262 'quality' => $quality,
12621263 'tags' => FlaggedRevision::flattenRevisionTags( $flags ),
12631264 'img_name' => $fileData['name'],
12641265 'img_timestamp' => $fileData['timestamp'],
12651266 'img_sha1' => $fileData['sha1'],
1266 - 'templateVersions' => $poutput->mTemplateIds,
1267 - 'fileVersions' => $poutput->mImageTimeKeys
 1267+ 'templateVersions' => $poutput->getTemplateIds(),
 1268+ 'fileVersions' => $poutput->getImageTimeKeys(),
 1269+ 'flags' => implode( ',', $propFlags ),
12681270 ) );
1269 - $flaggedRevision->insertOn( $auto );
 1271+ $flaggedRevision->insertOn();
12701272 # Update the article review log
12711273 FlaggedRevsLogs::updateReviewLog( $title,
12721274 $flags, array(), '', $rev->getId(), $oldSvId, true, $auto );
Index: trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php
@@ -414,6 +414,7 @@
415415 'img_sha1' => $fileData['sha1'],
416416 'templateVersions' => $tmpVersions,
417417 'fileVersions' => $fileVersions,
 418+ 'flags' => ''
418419 ) );
419420 $flaggedRevision->insertOn();
420421 # Update recent changes...
@@ -544,8 +545,7 @@
545546 }
546547 # Image -> timestamp -> sha1 mapping
547548 foreach ( $imageSHA1Keys as $dbKey => $timeAndSHA1 ) {
548 - $imageParams .= $dbKey . "|" . $timeAndSHA1['time'];
549 - $imageParams .= "|" . $timeAndSHA1['sha1'] . "#";
 549+ $imageParams .= $dbKey . "|" . $timeAndSHA1['time'] . "|" . $timeAndSHA1['sha1'] . "#";
550550 }
551551 # For image pages, note the displayed image version
552552 if ( $article->getTitle()->getNamespace() == NS_FILE ) {
@@ -601,7 +601,7 @@
602602 }
603603 list( $dbkey, $time, $key ) = $m;
604604 # Get the file title
605 - $img_title = Title::makeTitle( NS_IMAGE, $dbkey ); // Normalize
 605+ $img_title = Title::makeTitle( NS_FILE, $dbkey ); // Normalize
606606 if ( is_null( $img_title ) ) {
607607 continue; // Page must be valid!
608608 }
@@ -724,7 +724,7 @@
725725 $pOutput = $parserCache->get( $article, $wgOut->parserOptions() );
726726 }
727727 # Otherwise (or on cache miss), parse the rev text...
728 - if ( !$pOutput || !isset( $pOutput->mImageTimeKeys ) ) {
 728+ if ( !$pOutput ) {
729729 $text = $rev->getText();
730730 $title = $article->getTitle();
731731 $options = FlaggedRevs::makeParserOptions();
@@ -735,8 +735,8 @@
736736 $parserCache->save( $pOutput, $article, $options );
737737 }
738738 }
739 - $templateIDs = $pOutput->mTemplateIds;
740 - $imageSHA1Keys = $pOutput->mImageTimeKeys;
 739+ $templateIDs = $pOutput->getTemplateIds();
 740+ $imageSHA1Keys = $pOutput->getImageTimeKeys();
741741 }
742742 list( $templateParams, $imageParams, $fileVersion ) =
743743 RevisionReviewForm::getIncludeParams( $article, $templateIDs, $imageSHA1Keys );
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -36,33 +36,31 @@
3737 $this->mTimestamp = $row->fr_timestamp;
3838 $this->mQuality = intval( $row->fr_quality );
3939 $this->mTags = self::expandRevisionTags( strval( $row->fr_tags ) );
 40+ $this->mFlags = explode( ',', $row->fr_flags );
 41+ $this->mUser = intval( $row->fr_user );
4042 # Image page revision relevant params
4143 $this->mFileName = $row->fr_img_name ? $row->fr_img_name : null;
4244 $this->mFileSha1 = $row->fr_img_sha1 ? $row->fr_img_sha1 : null;
4345 $this->mFileTimestamp = $row->fr_img_timestamp ?
4446 $row->fr_img_timestamp : null;
45 - $this->mUser = intval( $row->fr_user );
4647 # Optional fields
4748 $this->mTitle = isset( $row->page_namespace ) && isset( $row->page_title )
4849 ? Title::makeTitleSafe( $row->page_namespace, $row->page_title )
4950 : null;
50 - $this->mFlags = isset( $row->fr_flags ) ?
51 - explode( ',', $row->fr_flags ) : null;
5251 } elseif ( is_array( $row ) ) {
5352 $this->mRevId = intval( $row['rev_id'] );
5453 $this->mPageId = intval( $row['page_id'] );
5554 $this->mTimestamp = $row['timestamp'];
5655 $this->mQuality = intval( $row['quality'] );
5756 $this->mTags = self::expandRevisionTags( strval( $row['tags'] ) );
 57+ $this->mFlags = explode( ',', $row['flags'] );
 58+ $this->mUser = intval( $row['user'] );
5859 # Image page revision relevant params
5960 $this->mFileName = $row['img_name'] ? $row['img_name'] : null;
6061 $this->mFileSha1 = $row['img_sha1'] ? $row['img_sha1'] : null;
6162 $this->mFileTimestamp = $row['img_timestamp'] ?
6263 $row['img_timestamp'] : null;
63 - $this->mUser = intval( $row['user'] );
6464 # Optional fields
65 - $this->mFlags = isset( $row['flags'] ) ?
66 - explode( ',', $row['flags'] ) : null;
6765 $this->mTemplates = isset( $row['templateVersions'] ) ?
6866 $row['templateVersions'] : null;
6967 $this->mFiles = isset( $row['fileVersions'] ) ?
@@ -259,20 +257,15 @@
260258 /*
261259 * Insert a FlaggedRevision object into the database
262260 *
263 - * @param array $tmpRows template version rows
264 - * @param array $fileRows file version rows
265 - * @param bool $auto autopatrolled
266261 * @return bool success
267262 */
268 - public function insertOn( $auto = false ) {
 263+ public function insertOn() {
269264 $dbw = wfGetDB( DB_MASTER );
270 - # Set any text flags
271 - $textFlags = 'dynamic';
272 - if ( $auto ) $textFlags .= ',auto';
273 - $this->mFlags = explode( ',', $textFlags );
 265+ # Set any flagged revision flags
 266+ $this->mFlags = array_merge( $this->mFlags, array( 'dynamic' ) ); // legacy
274267 # Build the inclusion data chunks
275268 $tmpInsertRows = array();
276 - foreach ( $this->getTemplateVersions() as $namespace => $titleAndID ) {
 269+ foreach ( (array)$this->mTemplates as $namespace => $titleAndID ) {
277270 foreach ( $titleAndID as $dbkey => $id ) {
278271 $tmpInsertRows[] = array(
279272 'ft_rev_id' => $this->getRevId(),
@@ -283,7 +276,7 @@
284277 }
285278 }
286279 $fileInsertRows = array();
287 - foreach ( $this->getFileVersions() as $dbkey => $timeSHA1 ) {
 280+ foreach ( (array)$this->mFiles as $dbkey => $timeSHA1 ) {
288281 $fileInsertRows[] = array(
289282 'fi_rev_id' => $this->getRevId(),
290283 'fi_name' => $dbkey,
@@ -302,7 +295,7 @@
303296 'fr_quality' => $this->getQuality(),
304297 'fr_tags' => self::flattenRevisionTags( $this->getTags() ),
305298 'fr_text' => '', # not used anymore
306 - 'fr_flags' => $textFlags,
 299+ 'fr_flags' => implode( ',', $this->mFlags ),
307300 'fr_img_name' => $this->getFileName(),
308301 'fr_img_timestamp' => $dbw->timestampOrNull( $this->getFileTimestamp() ),
309302 'fr_img_sha1' => $this->getFileSha1()
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php
@@ -70,7 +70,7 @@
7171 $parserCache = ParserCache::singleton();
7272 $parserOutput = $parserCache->get( $article, $wgOut->parserOptions() );
7373 }
74 - if ( !$parserOutput || !isset( $parserOutput->mImageTimeKeys ) ) {
 74+ if ( !$parserOutput ) {
7575 // Miss, we have to reparse the page
7676 $text = $article->getContent();
7777 $options = FlaggedRevs::makeParserOptions();
@@ -80,7 +80,7 @@
8181 // Set version parameters for review submission
8282 list( $templateParams, $imageParams, $fileVersion ) =
8383 RevisionReviewForm::getIncludeParams( $article,
84 - $parserOutput->mTemplateIds, $parserOutput->mImageTimeKeys );
 84+ $parserOutput->getTemplateIds(), $parserOutput->getImageTimeKeys() );
8585 $form->setTemplateParams( $templateParams );
8686 $form->setFileParams( $imageParams );
8787 $form->setFileVersion( $fileVersion );
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -1073,12 +1073,9 @@
10741074 # $wgOut may not already have the inclusion IDs, such as for diffonly=1.
10751075 # RevisionReviewForm will fetch them as needed however.
10761076 $templateIDs = $fileSHA1Keys = null;
1077 - if ( $wgOut->getRevisionId() == $rev->getId()
1078 - && isset( $wgOut->mTemplateIds )
1079 - && isset( $wgOut->mImageTimeKeys ) )
1080 - {
1081 - $templateIDs = $wgOut->mTemplateIds;
1082 - $fileSHA1Keys = $wgOut->mImageTimeKeys;
 1077+ if ( $wgOut->getRevisionId() == $rev->getId() ) {
 1078+ $templateIDs = $wgOut->getTemplateIds();
 1079+ $fileSHA1Keys = $wgOut->getImageTimeKeys();
10831080 }
10841081 # Review notice box goes in top of form
10851082 $form = RevisionReviewForm::buildQuickReview(

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84619Follow-up r84610: removed fr_fileSHA1Keys and use core file version tracking ...aaron18:27, 23 March 2011

Comments

#Comment by Nikerabbit (talk | contribs)   15:18, 3 April 2011

@since 1.18 would be nice in OutputPage

#Comment by Aaron Schulz (talk | contribs)   01:25, 4 April 2011

Status & tagging log