r91180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91179‎ | r91180 | r91181 >
Date:15:26, 30 June 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
Fixes for r88113 and some realted changes:
* Modified <s>Article::editUpdates()</s> WikiPage::doEditUpdates() arguments to take a Revision object, an User object and options (much more readable that those boolean parameters)
* Call isCountable() on the old content and pass it to WikiPage::doEditUpdates() with the 'oldcountable' option so that it really reflects the old state of the page
* Updated all calls (no one in extensions) and removed the wrapper WikiPage::editUpdates()
* Call onArticleEdit() and onArticleCreate() (the one that is of course) from doEditUpdates()
* Removed $wgTitle hack from Import.php
Modified paths:
  • /trunk/phase3/includes/Import.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WikiPage.php
@@ -1004,6 +1004,7 @@
10051005
10061006 $oldtext = $this->getRawText(); // current revision
10071007 $oldsize = strlen( $oldtext );
 1008+ $oldcountable = $this->isCountable();
10081009
10091010 # Provide autosummaries if one is not provided and autosummaries are enabled.
10101011 if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) {
@@ -1027,6 +1028,17 @@
10281029 $userAbort = ignore_user_abort( true );
10291030 }
10301031
 1032+ $revision = new Revision( array(
 1033+ 'page' => $this->getId(),
 1034+ 'comment' => $summary,
 1035+ 'minor_edit' => $isminor,
 1036+ 'text' => $text,
 1037+ 'parent_id' => $this->mLatest,
 1038+ 'user' => $user->getId(),
 1039+ 'user_text' => $user->getName(),
 1040+ 'timestamp' => $now
 1041+ ) );
 1042+
10311043 $changed = ( strcmp( $text, $oldtext ) != 0 );
10321044
10331045 if ( $changed ) {
@@ -1039,17 +1051,6 @@
10401052 return $status;
10411053 }
10421054
1043 - $revision = new Revision( array(
1044 - 'page' => $this->getId(),
1045 - 'comment' => $summary,
1046 - 'minor_edit' => $isminor,
1047 - 'text' => $text,
1048 - 'parent_id' => $this->mLatest,
1049 - 'user' => $user->getId(),
1050 - 'user_text' => $user->getName(),
1051 - 'timestamp' => $now
1052 - ) );
1053 -
10541055 $dbw->begin();
10551056 $revisionId = $revision->insertOn( $dbw );
10561057
@@ -1095,14 +1096,6 @@
10961097 $user->incEditCount();
10971098 $dbw->commit();
10981099 }
1099 - } else {
1100 - $status->warning( 'edit-no-change' );
1101 - $revision = null;
1102 - // Keep the same revision ID, but do some updates on it
1103 - $revisionId = $this->getLatest();
1104 - // Update page_touched, this is usually implicit in the page update
1105 - // Other cache updates are done in onArticleEdit()
1106 - $this->mTitle->invalidateCache();
11071100 }
11081101
11091102 if ( !$wgDBtransactions ) {
@@ -1115,11 +1108,19 @@
11161109 return $status;
11171110 }
11181111
1119 - # Invalidate cache of this article and all pages using this article
1120 - # as a template. Partly deferred.
1121 - self::onArticleEdit( $this->mTitle );
11221112 # Update links tables, site stats, etc.
1123 - $this->doEditUpdates( $text, $user, $summary, $isminor, $revisionId, $changed );
 1113+ $this->doEditUpdates( $revision, $user, array( 'changed' => $changed,
 1114+ 'oldcountable' => $oldcountable ) );
 1115+
 1116+ if ( !$changed ) {
 1117+ $status->warning( 'edit-no-change' );
 1118+ $revision = null;
 1119+ // Keep the same revision ID, but do some updates on it
 1120+ $revisionId = $this->getLatest();
 1121+ // Update page_touched, this is usually implicit in the page update
 1122+ // Other cache updates are done in onArticleEdit()
 1123+ $this->mTitle->invalidateCache();
 1124+ }
11241125 } else {
11251126 # Create new article
11261127 $status->value['new'] = true;
@@ -1180,11 +1181,8 @@
11811182 $dbw->commit();
11821183
11831184 # Update links, etc.
1184 - $this->doEditUpdates( $text, $user, $summary, $isminor, $revisionId, true, true );
 1185+ $this->doEditUpdates( $revision, $user, array( 'created' => true ) );
11851186
1186 - # Clear caches
1187 - self::onArticleCreate( $this->mTitle );
1188 -
11891187 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$user, $text, $summary,
11901188 $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
11911189 }
@@ -1900,26 +1898,29 @@
19011899 * Every 100th edit, prune the recent changes table.
19021900 *
19031901 * @private
1904 - * @param $text String: New text of the article
1905 - * @param $user User object: User doing the edit
1906 - * @param $summary String: Edit summary
1907 - * @param $minoredit Boolean: Minor edit
1908 - * @param $newid Integer: rev_id value of the new revision
1909 - * @param $changed Boolean: Whether or not the content actually changed
1910 - * @param $created Boolean: Whether the edit created the page
 1902+ * @param $revision Revision object
 1903+ * @param $user User object that did the revision
 1904+ * @param $options Array of options, following indexes are used:
 1905+ * - changed: boolean, whether the revision changed the content (default true)
 1906+ * - created: boolean, whether the revision created the page (default false)
 1907+ * - oldcountable: boolean or null (default null):
 1908+ * - boolean: whether the page was counted as an article before that
 1909+ * revision, only used in changed is true and created is false
 1910+ * - null: don't change the article count
19111911 */
1912 - public function doEditUpdates(
1913 - $text, $user, $summary, $minoredit, $newid, $changed = true, $created = false
1914 - ) {
 1912+ public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
19151913 global $wgDeferredUpdateList, $wgEnableParserCache;
19161914
19171915 wfProfileIn( __METHOD__ );
19181916
 1917+ $options += array( 'changed' => true, 'created' => false, 'oldcountable' => null );
 1918+ $text = $revision->getText();
 1919+
19191920 # Parse the text
19201921 # Be careful not to double-PST: $text is usually already PST-ed once
19211922 if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
19221923 wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" );
1923 - $editInfo = $this->prepareTextForEdit( $text, $newid, $user );
 1924+ $editInfo = $this->prepareTextForEdit( $text, $revision->getId(), $user );
19241925 } else {
19251926 wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" );
19261927 $editInfo = $this->mPreparedEdit;
@@ -1935,7 +1936,7 @@
19361937 $u = new LinksUpdate( $this->mTitle, $editInfo->output );
19371938 $u->doUpdate();
19381939
1939 - wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $changed ) );
 1940+ wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
19401941
19411942 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
19421943 if ( 0 == mt_rand( 0, 99 ) ) {
@@ -1962,14 +1963,17 @@
19631964 return;
19641965 }
19651966
1966 - if ( !$changed ) {
 1967+ if ( !$options['changed'] ) {
19671968 $good = 0;
19681969 $total = 0;
1969 - } elseif ( $created ) {
 1970+ } elseif ( $options['created'] ) {
19701971 $good = (int)$this->isCountable( $editInfo );
19711972 $total = 1;
 1973+ } elseif ( $options['oldcountable'] !== null ) {
 1974+ $good = (int)$this->isCountable( $editInfo ) - (int)$options['oldcountable'];
 1975+ $total = 0;
19721976 } else {
1973 - $good = (int)$this->isCountable( $editInfo ) - (int)$this->isCountable();
 1977+ $good = 0;
19741978 $total = 0;
19751979 }
19761980
@@ -1981,7 +1985,7 @@
19821986 # load of user talk pages and piss people off, nor if it's a minor edit
19831987 # by a properly-flagged bot.
19841988 if ( $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $user->getTitleKey() && $changed
1985 - && !( $minoredit && $user->isAllowed( 'nominornewtalk' ) )
 1989+ && !( $revision->isMinor() && $user->isAllowed( 'nominornewtalk' ) )
19861990 ) {
19871991 if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this ) ) ) {
19881992 $other = User::newFromName( $shortTitle, false );
@@ -2002,6 +2006,12 @@
20032007 MessageCache::singleton()->replace( $shortTitle, $text );
20042008 }
20052009
 2010+ if( $options['created'] ) {
 2011+ self::onArticleCreate( $this->mTitle );
 2012+ } else {
 2013+ self::onArticleEdit( $this->mTitle );
 2014+ }
 2015+
20062016 wfProfileOut( __METHOD__ );
20072017 }
20082018
@@ -2017,8 +2027,7 @@
20182028 */
20192029 public function createUpdates( $rev ) {
20202030 global $wgUser;
2021 - $this->doEditUpdates( $rev->getText(), $wgUser, $rev->getComment(),
2022 - $rev->isMinor(), $rev->getId(), true, true );
 2031+ $this->doEditUpdates( $rev, $wgUser, array( 'created' => true ) );
20232032 }
20242033
20252034 /**
@@ -2419,17 +2428,6 @@
24202429 /*
24212430 * @deprecated since 1.19
24222431 */
2423 - public function editUpdates(
2424 - $text, $summary, $minoredit, $timestamp_of_pagechange, $newid,
2425 - $changed = true, User $user = null, $created = false
2426 - ) {
2427 - global $wgUser;
2428 - return $this->doEditUpdates( $text, $wgUser, $summary, $minoredit, $newid, $changed, $created );
2429 - }
2430 -
2431 - /*
2432 - * @deprecated since 1.19
2433 - */
24342432 public function viewUpdates() {
24352433 global $wgUser;
24362434 return $this->doViewUpdates( $wgUser );
Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -532,23 +532,18 @@
533533 }
534534
535535 $created = (bool)$newid;
 536+ $oldcountable = $article->isCountable();
536537
537538 // Attach the latest revision to the page...
538539 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
539540 if ( $created || $wasnew ) {
540541 // Update site stats, link tables, etc
541 - $article->editUpdates( $revision->getText(), $revision->getComment(),
542 - $revision->isMinor(), wfTimestamp(), $revision->getId(), true, null, $created );
 542+ $user = User::newFromName( $revision->getRawUserText() );
 543+ $article->doEditUpdates( $revision, $user, array( 'created' => $created, 'oldcountable' => $oldcountable ) );
543544 }
544545
545546 wfRunHooks( 'ArticleUndelete', array( &$this->title, $created, $comment ) );
546547
547 - if( $created ) {
548 - Article::onArticleCreate( $this->title );
549 - } else {
550 - Article::onArticleEdit( $this->title );
551 - }
552 -
553548 if( $this->title->getNamespace() == NS_FILE ) {
554549 $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
555550 $update->doUpdate();
Index: trunk/phase3/includes/Import.php
@@ -1000,9 +1000,11 @@
10011001 if( $user ) {
10021002 $userId = intval( $user->getId() );
10031003 $userText = $user->getName();
 1004+ $userObj = $user;
10041005 } else {
10051006 $userId = 0;
10061007 $userText = $this->getUser();
 1008+ $userObj = new User;
10071009 }
10081010
10091011 // avoid memory leak...?
@@ -1015,6 +1017,7 @@
10161018 # must create the page...
10171019 $pageId = $article->insertOn( $dbw );
10181020 $created = true;
 1021+ $oldcountable = null;
10191022 } else {
10201023 $created = false;
10211024
@@ -1031,6 +1034,7 @@
10321035 $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n" );
10331036 return false;
10341037 }
 1038+ $oldcountable = $article->isCountable();
10351039 }
10361040
10371041 # @todo FIXME: Use original rev_id optionally (better for backups)
@@ -1044,34 +1048,14 @@
10451049 'timestamp' => $this->timestamp,
10461050 'minor_edit' => $this->minor,
10471051 ) );
1048 - $revId = $revision->insertOn( $dbw );
 1052+ $revision->insertOn( $dbw );
10491053 $changed = $article->updateIfNewerOn( $dbw, $revision );
10501054
1051 - # To be on the safe side...
1052 - $tempTitle = $GLOBALS['wgTitle'];
1053 - $GLOBALS['wgTitle'] = $this->title;
1054 -
1055 - if ( $created ) {
1056 - wfDebug( __METHOD__ . ": running onArticleCreate\n" );
1057 - Article::onArticleCreate( $this->title );
1058 - } elseif( $changed ) {
1059 - wfDebug( __METHOD__ . ": running onArticleEdit\n" );
1060 - Article::onArticleEdit( $this->title );
 1055+ if ( $changed !== false ) {
 1056+ wfDebug( __METHOD__ . ": running updates\n" );
 1057+ $article->doEditUpdates( $revision, $userObj, array( 'created' => $created, 'oldcountable' => $oldcountable ) );
10611058 }
10621059
1063 - wfDebug( __METHOD__ . ": running updates\n" );
1064 - $article->editUpdates(
1065 - $this->getText(),
1066 - $this->getComment(),
1067 - $this->minor,
1068 - $this->timestamp,
1069 - $revId,
1070 - true,
1071 - null,
1072 - $created );
1073 -
1074 - $GLOBALS['wgTitle'] = $tempTitle;
1075 -
10761060 return true;
10771061 }
10781062

Follow-up revisions

RevisionCommit summaryAuthorDate
r91203Per Aaron, fix for r91180: pass false to second parameter of User::newFromNam...ialex19:34, 30 June 2011
r91208* Marked WikiCategoryPage::hasViewableContent() as "public"...aaron19:44, 30 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88113Rewrote the article counting code and related:...ialex17:11, 14 May 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   17:33, 30 June 2011

+ $user = User::newFromName( $revision->getRawUserText() );

You need to pass <false> into the second newFromName param or this will fail on IP users.

#Comment by IAlex (talk | contribs)   19:34, 30 June 2011

Done in r91203.

#Comment by Umherirrender (talk | contribs)   21:18, 20 January 2012

This revision breaks the REVISION* vars in WikiText after a nulledit (save without change), see bug 32948.

$revision is now always created with current timestamp and than this object is used to reparse the page (in doEditUpdates). But than the current timestamp is used for the vars. REVISIONID is also empty, because for $changed = true the revision id in $revision is never set. But I am unsure why REVISIONUSER is also empty.

#Comment by IAlex (talk | contribs)   08:00, 21 January 2012

Fixed in r109679.

#Comment by Umherirrender (talk | contribs)   10:09, 21 January 2012

Thanks. Looks good.

Status & tagging log