r74035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74034‎ | r74035 | r74036 >
Date:19:14, 30 September 2010
Author:demon
Status:resolved (Comments)
Tags:
Comment:
Follow up r74034: Refactor GAID_FOR_UPDATE into Title::GAID_FOR_UPDATE. Yay less file-scope code (for extensions)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /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/forms/PageStabilityForm.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageHooks.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsage_body.php (modified) (history)
  • /trunk/extensions/GlobalUsage/refreshGlobalimagelinks.php (modified) (history)
  • /trunk/extensions/MirrorTools/MirrorTools.classes.php (modified) (history)
  • /trunk/extensions/ReaderFeedback/specialpages/ReaderFeedback_body.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslationMovePage.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogComment.php (modified) (history)
  • /trunk/extensions/Wikilog/WikilogCommentsPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MirrorTools/MirrorTools.classes.php
@@ -109,7 +109,7 @@
110110 wfProfileOut( __METHOD__ . '-checks' );
111111
112112 # If article is new, insert it.
113 - $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
 113+ $aid = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
114114 if ( 0 == $aid ) {
115115 // Late check for create permission, just in case *PARANOIA*
116116 if ( !$this->mTitle->userCan( 'create' ) ) {
Index: trunk/extensions/GlobalUsage/GlobalUsageHooks.php
@@ -24,11 +24,11 @@
2525 $gu = self::getGlobalUsage();
2626 if ( $wgUseDumbLinkUpdate ) {
2727 // Delete all entries to the page
28 - $gu->deleteLinksFromPage( $title->getArticleId( GAID_FOR_UPDATE ) );
 28+ $gu->deleteLinksFromPage( $title->getArticleId( Title::GAID_FOR_UPDATE ) );
2929 // Re-insert new usage for the page
3030 $gu->insertLinks( $title, $missingFiles );
3131 } else {
32 - $articleId = $title->getArticleId( GAID_FOR_UPDATE );
 32+ $articleId = $title->getArticleId( Title::GAID_FOR_UPDATE );
3333 $existing = $gu->getLinksFromPage( $articleId );
3434
3535 // Calculate changes
Index: trunk/extensions/GlobalUsage/GlobalUsage_body.php
@@ -21,7 +21,7 @@
2222 * @param $title Title Title of the page
2323 * @param $images array Array of db keys of images used
2424 */
25 - public function insertLinks( $title, $images, $pageIdFlags = GAID_FOR_UPDATE ) {
 25+ public function insertLinks( $title, $images, $pageIdFlags = Title::GAID_FOR_UPDATE ) {
2626 $insert = array();
2727 foreach ( $images as $name ) {
2828 $insert[] = array(
Index: trunk/extensions/GlobalUsage/refreshGlobalimagelinks.php
@@ -82,7 +82,7 @@
8383 $title = Title::newFromRow( reset( $rows ) );
8484 $images = array_keys( $rows );
8585 # Since we have a pretty accurate page_id, don't specify
86 - # GAID_FOR_UPDATE
 86+ # Title::GAID_FOR_UPDATE
8787 $gu->insertLinks( $title, $images, /* $flags */ 0 );
8888 }
8989 }
Index: trunk/extensions/Wikilog/WikilogCommentsPage.php
@@ -399,7 +399,7 @@
400400 array( 'content', 'parsemag' ),
401401 $comment->mUserText
402402 );
403 - $id = $title->getArticleID( GAID_FOR_UPDATE );
 403+ $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
404404 if ( $this->doDeleteArticle( $reason, false, $id ) ) {
405405 $comment->deleteComment();
406406 $log->addEntry( 'c-reject', $title, '' );
Index: trunk/extensions/Wikilog/WikilogComment.php
@@ -243,7 +243,7 @@
244244 if ( $this->mCommentTitle ) {
245245 return $this->mCommentTitle;
246246 } else if ( $this->mCommentPage ) {
247 - return Title::newFromID( $this->mCommentPage, GAID_FOR_UPDATE );
 247+ return Title::newFromID( $this->mCommentPage, Title::GAID_FOR_UPDATE );
248248 } else {
249249 $it = $this->mItem->mTitle;
250250 return Title::makeTitle(
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -109,7 +109,7 @@
110110 $srev = $this->getStableRev( $flags );
111111 if ( $srev ) {
112112 if ( $flags & FR_MASTER ) {
113 - $latest = $this->getTitle()->getLatestRevID( GAID_FOR_UPDATE );
 113+ $latest = $this->getTitle()->getLatestRevID( Title::GAID_FOR_UPDATE );
114114 } else {
115115 $latest = $this->getLatest();
116116 }
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -716,7 +716,7 @@
717717 }
718718 # Get the latest revision ID if not set
719719 if ( !$latest ) {
720 - $latest = $article->getTitle()->getLatestRevID( GAID_FOR_UPDATE );
 720+ $latest = $article->getTitle()->getLatestRevID( Title::GAID_FOR_UPDATE );
721721 }
722722 # Get the highest quality revision (not necessarily this one)
723723 $dbw = wfGetDB( DB_MASTER );
@@ -776,7 +776,7 @@
777777 }
778778 # Get the latest revision ID if not set
779779 if ( !$latest ) {
780 - $latest = $article->getTitle()->getLatestRevID( GAID_FOR_UPDATE );
 780+ $latest = $article->getTitle()->getLatestRevID( Title::GAID_FOR_UPDATE );
781781 }
782782 $pageId = $article->getId();
783783 # Update pending times for each level, going from highest to lowest
Index: trunk/extensions/FlaggedRevs/forms/PageStabilityForm.php
@@ -290,7 +290,7 @@
291291 protected function updateLogsAndHistory( $reset ) {
292292 global $wgContLang;
293293 $article = new Article( $this->page );
294 - $latest = $this->page->getLatestRevID( GAID_FOR_UPDATE );
 294+ $latest = $this->page->getLatestRevID( Title::GAID_FOR_UPDATE );
295295 # Config may have changed to allow stable versions.
296296 # Refresh tracking to account for any hidden reviewed versions...
297297 $frev = FlaggedRevision::newFromStable( $this->page, FR_MASTER );
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -96,7 +96,7 @@
9797 } else {
9898 $db = wfGetDB( DB_SLAVE );
9999 }
100 - $pageId = $title->getArticleID( $flags & FR_FOR_UPDATE ? GAID_FOR_UPDATE : 0 );
 100+ $pageId = $title->getArticleID( $flags & FR_FOR_UPDATE ? Title::GAID_FOR_UPDATE : 0 );
101101 # Short-circuit query
102102 if ( !$pageId ) {
103103 return null;
@@ -134,7 +134,7 @@
135135 }
136136 $columns = self::selectFields();
137137 $options = array();
138 - $pageId = $title->getArticleID( $flags & FR_MASTER ? GAID_FOR_UPDATE : 0 );
 138+ $pageId = $title->getArticleID( $flags & FR_MASTER ? Title::GAID_FOR_UPDATE : 0 );
139139 if ( !$pageId ) {
140140 return null; // short-circuit query
141141 }
@@ -181,7 +181,7 @@
182182 }
183183 $columns = self::selectFields();
184184 $options = array();
185 - $pageId = $title->getArticleID( $flags & FR_FOR_UPDATE ? GAID_FOR_UPDATE : 0 );
 185+ $pageId = $title->getArticleID( $flags & FR_FOR_UPDATE ? Title::GAID_FOR_UPDATE : 0 );
186186 if ( !$pageId ) {
187187 return null; // short-circuit query
188188 }
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -1584,7 +1584,7 @@
15851585 return true;
15861586 }
15871587 # Get latest revision Id (lag safe)
1588 - $latest = $this->article->getTitle()->getLatestRevID( GAID_FOR_UPDATE );
 1588+ $latest = $this->article->getTitle()->getLatestRevID( Title::GAID_FOR_UPDATE );
15891589 if ( $latest == $frev->getRevId() ) {
15901590 return true; // only for pages with pending edits
15911591 }
@@ -1779,7 +1779,7 @@
17801780 # We are undoing all edits *after* some rev ID (undoafter).
17811781 # If undoafter is not given, then it is the previous rev ID.
17821782 $revId = $wgRequest->getInt( 'undoafter',
1783 - $article->getTitle()->getPreviousRevisionID( $latestId, GAID_FOR_UPDATE ) );
 1783+ $article->getTitle()->getPreviousRevisionID( $latestId, Title::GAID_FOR_UPDATE ) );
17841784 # Undoing other edits...
17851785 } elseif ( $undo ) {
17861786 $revId = $latestId; // current rev is the base rev
Index: trunk/extensions/ReaderFeedback/specialpages/ReaderFeedback_body.php
@@ -230,7 +230,7 @@
231231 static $stackDepth = 0;
232232 $userVoted = false;
233233 # Use page_latest if $revId not given
234 - $revId = $revId ? $revId : $title->getLatestRevID( GAID_FOR_UPDATE );
 234+ $revId = $revId ? $revId : $title->getLatestRevID( Title::GAID_FOR_UPDATE );
235235 $rev = Revision::newFromTitle( $title, $revId );
236236 if( !$rev ) return false; // shouldn't happen; just in case
237237 # Check if this revision is by this user...
Index: trunk/extensions/Translate/tag/SpecialPageTranslationMovePage.php
@@ -375,10 +375,10 @@
376376 MoveJob::forceRedirects( true );
377377
378378 $newTpage = TranslatablePage::newFromTitle( $this->newTitle );
379 - $newTpage->addReadyTag( $this->newTitle->getLatestRevId( GAID_FOR_UPDATE ) );
 379+ $newTpage->addReadyTag( $this->newTitle->getLatestRevId( Title::GAID_FOR_UPDATE ) );
380380
381381 if ( $newTpage->getMarkedTag() === $oldLatest ) {
382 - $newTpage->addMarkedTag( $this->newTitle->getLatestRevId( GAID_FOR_UPDATE ) );
 382+ $newTpage->addMarkedTag( $this->newTitle->getLatestRevId( Title::GAID_FOR_UPDATE ) );
383383 }
384384
385385 MessageGroups::clearCache();

Follow-up revisions

RevisionCommit summaryAuthorDate
r75182Follow-up r74035. Keep GAID_FOR_UPDATE in order to allow the extension to run...juliano05:00, 22 October 2010
r75379Followup r74035, add GAID_FOR_UPDATE to the defines for back-compatdemon20:25, 25 October 2010
r75422Keep it in Title.php Having it on Defines would allow to use it wrong....platonides14:08, 26 October 2010
r76597Per CR on r76482, back out changes from r72509 and r74035, relies on core cha...demon21:23, 12 November 2010
r89696Translate extension wants to keep 1.16 compatible....platonides21:32, 7 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74034Refactor GAID_FOR_UPDATE into Title::GAID_FOR_UPDATE. Yay less file-scope cod...demon19:13, 30 September 2010

Comments

#Comment by Juliano (talk | contribs)   18:29, 6 October 2010

This breaks compatibility with current 1.16 branch (again...). I would like that people using 1.16 be able to use the extension in trunk/, at least until Mw 1.17 is released (when you can safely tell people to upgrade MediaWiki before using the trunk version of the extension).

#Comment by 😂 (talk | contribs)   18:59, 6 October 2010

If I revert this, I'll have to add the GAID_FOR_UPDATE constant back that I removed in r74035, since doing one without the other would break these on trunk too.

#Comment by Juliano (talk | contribs)   19:08, 6 October 2010

There should be no problem to have both define() and the const. PHP (at least current 5.3.2) evaluate these two in different parser contexts.

Simple test:

<?php
define( 'GAID_FOR_UPDATE', 1 );
class Title {
	const GAID_FOR_UPDATE = 1;
};
print GAID_FOR_UPDATE . "\n";
print Title::GAID_FOR_UPDATE . "\n";

But the new replacement constant doesn't have to have the same name too. s/Title::GAID_FOR_UPDATE/Title::LATEST_REV_FOR_UPDATE/g (for example) should fix this problem.

#Comment by 😂 (talk | contribs)   19:11, 6 October 2010

I'm not saying it's a problem, I was just stating it would have to be done.

#Comment by 😂 (talk | contribs)   18:32, 6 October 2010

Back-compat be damned.

#Comment by MaxSem (talk | contribs)   18:32, 6 October 2010

+1

#Comment by Juliano (talk | contribs)   18:46, 6 October 2010

A few months ago, r66934 had to be reverted for the very same reason. I thought it was accepted that it is desirable that extensions in trunk/ be compatible with the current stable release of MediaWiki (currently 1.16). Not a requirement, but at least an expectation for a good reason.

#Comment by 😂 (talk | contribs)   18:47, 6 October 2010

It didn't have to be reverted. It was reverted because I didn't want to argue it.

#Comment by Platonides (talk | contribs)   19:01, 6 October 2010

It could also be done in the extensions themselves: if version_compare ( $wgVersion , 1.17, >=) define('GAID_FOR_UPDATE', Title::GAID_FOR_UPDATE);

#Comment by Platonides (talk | contribs)   19:02, 6 October 2010

(with a !defined() so you don't create warnings by including several of these extensions)

#Comment by Bryan (talk | contribs)   19:06, 23 October 2010

I would support adding define('GAID_FOR_UPDATE', Title::GAID_FOR_UPDATE) for at least until 1.17 is released and possibly later.

#Comment by Aaron Schulz (talk | contribs)   21:10, 23 October 2010

+1

#Comment by Bryan (talk | contribs)   12:28, 24 October 2010

That would cause Title.php to be autoloaded when Defines.php is included though

#Comment by Platonides (talk | contribs)   20:04, 25 October 2010

I don't think that would be nice for installs without a bytecache. For instance, load.php would be loading that file for nothing. Also note, Defines.php is currently included before the autoloader.

#Comment by Juliano (talk | contribs)   20:18, 25 October 2010

This is a temporary hack for backwards compatibility. I don't think anyone intends to change that constant anytime soon. It should be fine to have the constant be doubly-defined until the old one gets removed after 1.17.

   define( 'GAID_FOR_UPDATE', 1 );

If necessary, leave a comment near it to warn careless passers-by that the value must be the same in Title::GAID_FOR_UPDATE.

IMO, more than that is to overthink the issue.

#Comment by Platonides (talk | contribs)   21:11, 25 October 2010

In fact, there wouldn't be such autoloading issue if the bc define was kept in Title.php

#Comment by 😂 (talk | contribs)   21:12, 25 October 2010

I just put it in defines.php

#Comment by Bryan (talk | contribs)   14:13, 26 October 2010

Except that it will break if you do not have Title.php autoloaded. It all depends on subtle differences in code flow that I would rather not rely on.

#Comment by Platonides (talk | contribs)   14:16, 26 October 2010

But that issue already existed in the previous version where the define was in Title.php. If it worked, it will continue working, if it's new it should be using Title::GAID_FOR_UPDATE anyway. I moved it in r75422

#Comment by Bryan (talk | contribs)   14:21, 26 October 2010

Ok.

#Comment by Nikerabbit (talk | contribs)   18:16, 3 June 2011

Translate extension is broken for 1.16.

#Comment by Platonides (talk | contribs)   21:32, 7 June 2011

Fixed in r89696.

Status & tagging log