Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/59627


Change subject: Alternative method to detect the existence of a user/talk page 
discussion
......................................................................

Alternative method to detect the existence of a user/talk page discussion

The original method of getting sections from parser output was quite expensive
when parser output is not in cache.
Instead, after clicking the link to add something to a user/talk page, I'll
pass on some parameters, which will be read after saving the page & a flag will
be added in the AFT table to indicate an entry was discussed about.

The slight disadvantage is that at a later point, someone may remove the section
from the talk page, making it no longer "discussed" (but AFT's table will still
think it's discussed). This does not really matter too much; the current
solution was not even capable to recognize section titles that are changed from
what the tool suggests ;)

Change-Id: I84677fedddf09b31d95bcc6aedac6c4fad4a50f6
---
M ArticleFeedbackv5.hooks.php
M ArticleFeedbackv5.model.php
M ArticleFeedbackv5.php
M ArticleFeedbackv5.render.php
M sql/ArticleFeedbackv5.sql
A sql/discuss.sql
6 files changed, 88 insertions(+), 43 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5 
refs/changes/27/59627/1

diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index 6a95ca0..c611ff9 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -85,6 +85,12 @@
                        dirname( __FILE__ ) . '/sql/index_page.sql'
                );
 
+               $updater->addExtensionField(
+                       'aft_feedback',
+                       'aft_discuss',
+                       dirname( __FILE__ ) . '/sql/discuss.sql'
+               );
+
                return true;
        }
 
@@ -289,37 +295,26 @@
        }
 
        /**
-        * Pushes the tracking fields into the edit page
+        * Pushes fields into the edit page. This will allow us to pass on some 
parameter(s)
+        * until the submission of a page (at which point we can check for 
these parameters
+        * with a hook in ArticleSaveComplete)
         *
         * @see 
http://www.mediawiki.org/wiki/Manual:Hooks/EditPage::showEditForm:fields
         * @param $editPage EditPage
         * @param $output OutputPage
         * @return bool
         */
-       public static function pushTrackingFieldsToEdit( $editPage, $output ) {
+       public static function pushFieldsToEdit( $editPage, $output ) {
                $request = $output->getRequest();
-               $tracking   = $request->getVal( 
'articleFeedbackv5_click_tracking' );
-               $ctToken    = $request->getVal( 'articleFeedbackv5_ct_cttoken' 
);
-               $userToken  = $request->getVal( 
'articleFeedbackv5_ct_usertoken' );
-               $ctEvent    = $request->getVal( 'articleFeedbackv5_ct_event' );
+               $requestValues = $request->getValues();
 
-               $editPage->editFormTextAfterContent .= Html::hidden( 
'articleFeedbackv5_click_tracking', $tracking );
-               $editPage->editFormTextAfterContent .= Html::hidden( 
'articleFeedbackv5_ct_cttoken', $ctToken );
-               $editPage->editFormTextAfterContent .= Html::hidden( 
'articleFeedbackv5_ct_usertoken', $userToken );
-               $editPage->editFormTextAfterContent .= Html::hidden( 
'articleFeedbackv5_ct_event', $ctEvent );
+               // push AFTv5 values back into the edit page form, so we can 
pick them up after submitting the form
+               foreach ( $requestValues as $key => $value ) {
+                       if ( strpos( $key, 'articleFeedbackv5_' ) === 0 ) {
+                               $editPage->editFormTextAfterContent .= 
Html::hidden( $key, $value );
+                       }
+               }
 
-               return true;
-       }
-
-       /**
-        * Tracks edit attempts
-        *
-        * @see http://www.mediawiki.org/wiki/Manual:Hooks/EditPage::attemptSave
-        * @param $editpage EditPage
-        * @return bool
-        */
-       public static function trackEditAttempt( $editpage ) {
-               self::trackEvent( 'edit_attempt', 
$editpage->getArticle()->getTitle(), 
$editpage->getArticle()->getRevIdFetched()); // EditPage::getTitle() doesn't 
exist in 1.18wmf1
                return true;
        }
 
@@ -340,12 +335,38 @@
         * @param $baseRevId
         * @return bool
         */
-       public static function trackEditSuccess( &$article, &$user, $text,
-                       $summary, $minoredit, $watchthis, $sectionanchor, 
&$flags,
-                       $revision, &$status, $baseRevId /*, &$redirect */ ) {
+       public static function editSuccess( &$article, &$user, $text, $summary, 
$minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, 
$baseRevId /*, &$redirect */ ) {
                if ( $revision instanceof Revision ) {
+                       $request = RequestContext::getMain()->getRequest();
+                       $feedbackId = $request->getVal( 
'articleFeedbackv5_discuss_id' );
+                       $pageId = $request->getVal( 
'articleFeedbackv5_discuss_page' );
+                       $discussType = $request->getVal( 
'articleFeedbackv5_discuss_type' );
+
+                       if ( $feedbackId && $pageId && $discussType ) {
+                               $feedback = ArticleFeedbackv5Model::get( 
$feedbackId, $pageId );
+
+                               if ( $feedback ) {
+                                       $feedback->aft_discuss = $discussType;
+
+                                       /*
+                                        * Before saving, the AFT data will be 
validated. If the discuss type
+                                        * is invalid, an exception will be 
thrown and the data will not be saved.
+                                        */
+                                       try {
+                                               $feedback->update();
+                                       } catch ( Exception $e ) {
+                                               /*
+                                                * It's great that tainted AFT 
data will not be inserted, but let's
+                                                * not stop the article edit 
when some AFT data is wrong.
+                                                */
+                                       };
+                               }
+                       }
+
+                       // track successful edit
                        self::trackEvent( 'edit_success', $article->getTitle(), 
$revision->getID() );
                } else {
+                       // track unsuccessful edit
                        self::trackEvent( 'edit_norevision', 
$article->getTitle(), 0 );
                }
 
@@ -353,6 +374,18 @@
        }
 
        /**
+        * Tracks edit attempts
+        *
+        * @see http://www.mediawiki.org/wiki/Manual:Hooks/EditPage::attemptSave
+        * @param $editpage EditPage
+        * @return bool
+        */
+       public static function editAttempt( $editpage ) {
+               self::trackEvent( 'edit_attempt', 
$editpage->getArticle()->getTitle(), 
$editpage->getArticle()->getRevIdFetched()); // EditPage::getTitle() doesn't 
exist in 1.18wmf1
+               return true;
+       }
+
+       /**
         * Internal use: Tracks an event
         *
         * @param $event string the event name
diff --git a/ArticleFeedbackv5.model.php b/ArticleFeedbackv5.model.php
index ea8ce42..80a09ae 100644
--- a/ArticleFeedbackv5.model.php
+++ b/ArticleFeedbackv5.model.php
@@ -28,6 +28,12 @@
                $aft_comment,
                $aft_timestamp,
 
+               // will hold the date after which an entry may be archived
+               $aft_archive_date,
+
+               // will hold info if discussion about the feedback has been 
started on user or article talk page
+               $aft_discuss,
+
                // denormalized status indicators for actions of which real 
records are in logging table
                $aft_oversight = 0,
                $aft_decline = 0,
@@ -41,7 +47,6 @@
                $aft_noaction = 0,
                $aft_inappropriate = 0,
                $aft_archive = 0,
-               $aft_archive_date,
                $aft_helpful = 0,
                $aft_unhelpful = 0,
 
@@ -415,6 +420,10 @@
                        throw new MWException( "Comment length exceeds the 
maximum of '$wgArticleFeedbackv5MaxCommentLength'." );
                }
 
+               if ( $this->aft_discuss && !in_array( $this->aft_discuss, 
array( 'talk', 'user' ) ) ) {
+                       throw new MWException( "Invalid discuss type 
'$this->aft_discuss'." );
+               }
+
                return parent::validate();
        }
 
diff --git a/ArticleFeedbackv5.php b/ArticleFeedbackv5.php
index 069159c..79a8737 100644
--- a/ArticleFeedbackv5.php
+++ b/ArticleFeedbackv5.php
@@ -420,9 +420,9 @@
 $wgHooks['ResourceLoaderGetConfigVars'][] = 
'ArticleFeedbackv5Hooks::resourceLoaderGetConfigVars';
 $wgHooks['MakeGlobalVariablesScript'][] = 
'ArticleFeedbackv5Hooks::makeGlobalVariablesScript';
 $wgHooks['GetPreferences'][] = 'ArticleFeedbackv5Hooks::getPreferences';
-$wgHooks['EditPage::showEditForm:fields'][] = 
'ArticleFeedbackv5Hooks::pushTrackingFieldsToEdit';
-$wgHooks['EditPage::attemptSave'][] = 
'ArticleFeedbackv5Hooks::trackEditAttempt';
-$wgHooks['ArticleSaveComplete'][] = 'ArticleFeedbackv5Hooks::trackEditSuccess';
+$wgHooks['EditPage::showEditForm:fields'][] = 
'ArticleFeedbackv5Hooks::pushFieldsToEdit';
+$wgHooks['EditPage::attemptSave'][] = 'ArticleFeedbackv5Hooks::editAttempt';
+$wgHooks['ArticleSaveComplete'][] = 'ArticleFeedbackv5Hooks::editSuccess';
 $wgHooks['ContribsPager::reallyDoQuery'][] = 
'ArticleFeedbackv5Hooks::contributionsData';
 $wgHooks['ContributionsLineEnding'][] = 
'ArticleFeedbackv5Hooks::contributionsLineEnding';
 $wgHooks['ProtectionForm::buildForm'][] = 
'ArticleFeedbackv5Hooks::onProtectionForm';
diff --git a/ArticleFeedbackv5.render.php b/ArticleFeedbackv5.render.php
index 0f6ae35..44d2a64 100644
--- a/ArticleFeedbackv5.render.php
+++ b/ArticleFeedbackv5.render.php
@@ -897,24 +897,24 @@
                                                )
                                                ->escaped();
 
-                                       $sectionAnchor = '';
-                                       // check if feedback is being discussed 
already
-                                       $article = Article::newFromId( 
$discussPage->getArticleID() );
-                                       if ( $article ) {
-                                               $sections = 
$article->getParserOutput()->getSections();
-                                               foreach ( $sections as $section 
) {
-                                                       if ( $section['line'] 
== $sectionTitleTruncated ) {
-                                                               $sectionAnchor 
= $section['anchor'];
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                                       $sectionExists = ( $sectionAnchor !== 
'' );
+                                       $sectionExists = ( $record->aft_discuss 
== $discussType );
 
                                        if ( $sectionExists ) {
+                                               $sectionAnchor = 
Sanitizer::normalizeSectionNameWhitespace( $sectionTitleTruncated );
+                                               $sectionAnchor = 
Sanitizer::escapeId( $sectionAnchor );
+
                                                $discussLink = 
$discussPage->getLinkURL() . '#' . $sectionAnchor;
                                        } else {
-                                               $discussLink = 
$discussPage->getLinkURL( array( 'action' => 'edit', 'section' => 'new', 
'preloadtitle' => $sectionTitleTruncated ) );
+                                               $discussLink = 
$discussPage->getLinkURL(
+                                                       array(
+                                                               'action' => 
'edit',
+                                                               'section' => 
'new',
+                                                               'preloadtitle' 
=> $sectionTitleTruncated,
+                                                               
'articleFeedbackv5_discuss_id' => $record->aft_id,
+                                                               
'articleFeedbackv5_discuss_page' => $record->aft_page,
+                                                               
'articleFeedbackv5_discuss_type' => $discussType,
+                                                       )
+                                               );
                                        }
 
                                        $action = 'discuss';
diff --git a/sql/ArticleFeedbackv5.sql b/sql/ArticleFeedbackv5.sql
index ba43969..7b7e0d7 100644
--- a/sql/ArticleFeedbackv5.sql
+++ b/sql/ArticleFeedbackv5.sql
@@ -12,6 +12,7 @@
   aft_rating boolean NOT NULL,
   aft_comment mediumblob NOT NULL DEFAULT '',
   aft_timestamp varbinary(14) NOT NULL DEFAULT '',
+  aft_discuss enum('user', 'talk') DEFAULT NULL,
   aft_oversight boolean NOT NULL DEFAULT 0,
   aft_decline boolean NOT NULL DEFAULT 0,
   aft_request boolean NOT NULL DEFAULT 0,
diff --git a/sql/discuss.sql b/sql/discuss.sql
new file mode 100644
index 0000000..eff0936
--- /dev/null
+++ b/sql/discuss.sql
@@ -0,0 +1,2 @@
+ALTER TABLE /*_*/aft_feedback
+  ADD COLUMN aft_discuss enum('user', 'talk') DEFAULT NULL;

-- 
To view, visit https://gerrit.wikimedia.org/r/59627
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I84677fedddf09b31d95bcc6aedac6c4fad4a50f6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to