r66878 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66877‎ | r66878 | r66879 >
Date:16:40, 25 May 2010
Author:happy-melon
Status:reverted (Comments)
Tags:
Comment:
(bug 23641) refactor code around Article::doEdit(), and restored access to watch/unwatch settings to ArticleSaveComplete hook, removed in r14834 AFAICT. Patch by Tisane.
Modified paths:
  • /trunk/phase3/CREDITS (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/CREDITS
@@ -125,6 +125,7 @@
126126 * Stefano Codari
127127 * Str4nd
128128 * svip
 129+* Tisane
129130 * Zachary Hauri
130131
131132 == Translators ==
Index: trunk/phase3/includes/Article.php
@@ -1811,28 +1811,8 @@
18121812 ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) |
18131813 ( $bot ? EDIT_FORCE_BOT : 0 );
18141814
1815 - # If this is a comment, add the summary as headline
1816 - if ( $comment && $summary != "" ) {
1817 - $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text;
1818 - }
 1815+ $this->doEdit( $text, $summary, $flags, false, null, $watchthis, $comment, '', true );
18191816
1820 - $this->doEdit( $text, $summary, $flags );
1821 -
1822 - $dbw = wfGetDB( DB_MASTER );
1823 - if ( $watchthis ) {
1824 - if ( !$this->mTitle->userIsWatching() ) {
1825 - $dbw->begin();
1826 - $this->doWatch();
1827 - $dbw->commit();
1828 - }
1829 - } else {
1830 - if ( $this->mTitle->userIsWatching() ) {
1831 - $dbw->begin();
1832 - $this->doUnwatch();
1833 - $dbw->commit();
1834 - }
1835 - }
1836 - $this->doRedirect( $this->isRedirect( $text ) );
18371817 }
18381818
18391819 /**
@@ -1843,30 +1823,11 @@
18441824 ( $minor ? EDIT_MINOR : 0 ) |
18451825 ( $forceBot ? EDIT_FORCE_BOT : 0 );
18461826
1847 - $status = $this->doEdit( $text, $summary, $flags );
 1827+ $status = $this->doEdit( $text, $summary, $flags, false, null, $watchthis, false, $sectionanchor, true );
18481828 if ( !$status->isOK() ) {
18491829 return false;
18501830 }
18511831
1852 - $dbw = wfGetDB( DB_MASTER );
1853 - if ( $watchthis ) {
1854 - if ( !$this->mTitle->userIsWatching() ) {
1855 - $dbw->begin();
1856 - $this->doWatch();
1857 - $dbw->commit();
1858 - }
1859 - } else {
1860 - if ( $this->mTitle->userIsWatching() ) {
1861 - $dbw->begin();
1862 - $this->doUnwatch();
1863 - $dbw->commit();
1864 - }
1865 - }
1866 -
1867 - $extraQuery = ''; // Give extensions a chance to modify URL query on update
1868 - wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
1869 -
1870 - $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
18711832 return true;
18721833 }
18731834
@@ -1920,6 +1881,10 @@
19211882 *
19221883 * @param $baseRevId the revision ID this edit was based off, if any
19231884 * @param $user Optional user object, $wgUser will be used if not passed
 1885+ * @param $watchthis Watch the page if true, unwatch the page if false, do nothing if null
 1886+ * @param $sectionanchor The section anchor for the page; used for redirecting the user back to the page
 1887+ * after the edit is successfully committed
 1888+ * @param $redirect If true, redirect the user back to the page after the edit is successfully committed
19241889 *
19251890 * @return Status object. Possible errors:
19261891 * edit-hook-aborted: The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
@@ -1936,7 +1901,8 @@
19371902 *
19381903 * Compatibility note: this function previously returned a boolean value indicating success/failure
19391904 */
1940 - public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
 1905+ public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null , $watchthis = null,
 1906+ $comment = false, $sectionanchor = '', $redirect = false) {
19411907 global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
19421908
19431909 # Low-level sanity check
@@ -1953,9 +1919,14 @@
19541920 $this->loadPageData();
19551921
19561922 $flags = $this->checkFlags( $flags );
 1923+
 1924+ # If this is a comment, add the summary as headline
 1925+ if ( $comment && $summary != "" ) {
 1926+ $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text;
 1927+ }
19571928
19581929 if ( !wfRunHooks( 'ArticleSave', array( &$this, &$user, &$text, &$summary,
1959 - $flags & EDIT_MINOR, null, null, &$flags, &$status ) ) )
 1930+ $flags & EDIT_MINOR, &$watchthis, null, &$flags, &$status) ) )
19601931 {
19611932 wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" );
19621933 wfProfileOut( __METHOD__ );
@@ -2085,6 +2056,9 @@
20862057 Article::onArticleEdit( $this->mTitle );
20872058 # Update links tables, site stats, etc.
20882059 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
 2060+
 2061+ $extraQuery = ''; # Give extensions a chance to modify URL query on update
 2062+ wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
20892063 } else {
20902064 # Create new article
20912065 $status->value['new'] = true;
@@ -2148,7 +2122,7 @@
21492123 Article::onArticleCreate( $this->mTitle );
21502124
21512125 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$user, $text, $summary,
2152 - $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
 2126+ $flags & EDIT_MINOR, &$watchthis, null, &$flags, $revision ) );
21532127 }
21542128
21552129 # Do updates right now unless deferral was requested
@@ -2160,9 +2134,34 @@
21612135 $status->value['revision'] = $revision;
21622136
21632137 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary,
2164 - $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId ) );
2165 -
 2138+ $flags & EDIT_MINOR, &$watchthis, null, &$flags, $revision, &$status, $baseRevId,
 2139+ &$redirect) );
 2140+
 2141+ # Watch or unwatch the page
 2142+ if ( $watchthis == true) {
 2143+ if ( !$this->mTitle->userIsWatching() ) {
 2144+ $dbw->begin();
 2145+ $this->doWatch();
 2146+ $dbw->commit();
 2147+ }
 2148+ } elseif ($watchthis == false) {
 2149+ if ( $this->mTitle->userIsWatching() ) {
 2150+ $dbw->begin();
 2151+ $this->doUnwatch();
 2152+ $dbw->commit();
 2153+ }
 2154+ }
 2155+
 2156+ if ( $redirect ) {
 2157+ if ( $sectionanchor || $extraQuery ) {
 2158+ $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
 2159+ } else {
 2160+ $this->doRedirect( $this->isRedirect( $text ) );
 2161+ }
 2162+ }
 2163+
21662164 wfProfileOut( __METHOD__ );
 2165+
21672166 return $status;
21682167 }
21692168

Follow-up revisions

RevisionCommit summaryAuthorDate
r66880Follow-up r66878 per CR.happy-melon17:04, 25 May 2010
r70760* Revert r66878, completely misses the point of factoring out doEdit() in the...tstarling08:33, 9 August 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r14834Did some refactoring in Article.php:...tstarling09:50, 20 June 2006

Comments

#Comment by Reedy (talk | contribs)   16:57, 25 May 2010

-rakkaus/#mediawiki-i18n- [25-May-2010 16:56:25] PHP Notice: Undefined variable: extraQuery in /www/w/includes/Article.php on line 2156

#Comment by Happy-melon (talk | contribs)   16:59, 25 May 2010

Doing what? Do you know?

#Comment by Reedy (talk | contribs)   17:02, 25 May 2010

It would look like $extraQuery is only assigned on one path through the code

#Comment by Reedy (talk | contribs)   16:59, 25 May 2010

Also

if ( $watchthis == true)

The == true should be removed if it's only a bool, else it should be triple equals

And if it is bool, you don't need the binary comparison of equals true/euqals false

#Comment by Happy-melon (talk | contribs)   17:06, 25 May 2010

Should be fixed in r66880. The $watchthis is a true/false/null comparison, so identity is required.

#Comment by Tisane (talk | contribs)   17:25, 25 May 2010

I was trying to replicate the existing functionality in which $extraQuery was assigned, and the ArticleUpdateBeforeRedirect hook was run (with possible changes to $extraQuery), through updateArticle but not through insertNewArticle. Maybe we should fix the notice by using an isset test?

#Comment by Tim Starling (talk | contribs)   03:48, 14 July 2010

The whole point of r14834 was to remove this exact UI crap from the backend API, so as to present a clean non-UI-dependent function to callers that need it. Are you opposed to this whole program of separating UI code from backend code? And what the hell are you doing adding boolean parameters to a function with a perfectly good flags list?

Status & tagging log