r75331 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75330‎ | r75331 | r75332 >
Date:18:48, 24 October 2010
Author:pdhanda
Status:resolved (Comments)
Tags:
Comment:
bug25289 Changes to make revisions with pending changes not load content immediately. Added javascript to get revisions content via API call
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/client/flaggedrevs.css (modified) (history)
  • /trunk/extensions/FlaggedRevs/client/flaggedrevs.js (modified) (history)
  • /trunk/extensions/FlaggedRevs/client/img/loading-small.gif (added) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -255,7 +255,7 @@
256256 $wgAvailableRights[] = 'stablesettings';
257257
258258 # Bump this number every time you change flaggedrevs.css/flaggedrevs.js
259 -$wgFlaggedRevStyleVersion = 77;
 259+$wgFlaggedRevStyleVersion = '78';
260260
261261 $wgExtensionFunctions[] = 'efLoadFlaggedRevs';
262262
@@ -492,6 +492,10 @@
493493
494494 # Database schema changes
495495 $wgHooks['LoadExtensionSchemaUpdates'][] = 'FlaggedRevsHooks::addSchemaUpdates';
 496+
 497+# Performance Don't show content on diff
 498+$wgHooks['ArticleContentOnDiff'][] = 'FlaggedRevsHooks::addCustomHtml';
 499+
496500 # ########
497501
498502 function efSetFlaggedRevsConditionalHooks() {
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -53,15 +53,18 @@
5454 if ( !$fa || !$fa->isReviewable() ) {
5555 return true;
5656 }
57 - global $wgJsMimeType, $wgFlaggedRevStyleVersion;
 57+ global $wgJsMimeType, $wgFlaggedRevStyleVersion, $wgStylePath, $wgStyleVersion;
5858 $stylePath = FlaggedRevs::styleUrlPath();
5959 # Get JS/CSS file locations
6060 $encCssFile = htmlspecialchars( "$stylePath/flaggedrevs.css?$wgFlaggedRevStyleVersion" );
6161 $encJsFile = htmlspecialchars( "$stylePath/flaggedrevs.js?$wgFlaggedRevStyleVersion" );
 62+
 63+ //TODO fix this to use the correct method
6264 # Add CSS file
63 - $wgOut->addExtensionStyle( $encCssFile );
 65+ //$wgOut->addExtensionStyle( $encCssFile );
6466 # Add main JS file
6567 $head = "<script type=\"{$wgJsMimeType}\" src=\"{$encJsFile}\"></script>";
 68+ $head .= "<link rel=\"stylesheet\" href=\"{$encCssFile}\"></link>";
6669 # Add review form JS for reviewers
6770 if ( $wgUser->isAllowed( 'review' ) ) {
6871 $encJsFile = htmlspecialchars( "$stylePath/review.js?$wgFlaggedRevStyleVersion" );
@@ -108,6 +111,8 @@
109112 $stableId = null;
110113 }
111114 $globalVars['wgStableRevisionId'] = $stableId;
 115+ $globalVars['wgLatestRevisionId'] = $fa->getLatest();
 116+ $globalVars['wgPageId'] = $fa->getID();
112117 if ( $wgUser->isAllowed( 'review' ) ) {
113118 $ajaxReview = (object) array(
114119 'sendMsg' => wfMsgHtml( 'revreview-submit' ),
@@ -1805,6 +1810,20 @@
18061811 $view->addToDiffView( $diff, $oldRev, $newRev );
18071812 return true;
18081813 }
 1814+
 1815+ /*
 1816+ * If an article is reviewable, get custom article contents from the FlaggedArticleView
 1817+ */
 1818+ public static function addCustomHtml( $diffEngine, &$out ) {
 1819+ $fa = FlaggedArticle::getTitleInstance( $out->getTitle() );
 1820+ if ( !$fa->isReviewable() ) {
 1821+ return true; // nothing to do
 1822+ }
 1823+
 1824+ $view = FlaggedArticleView::singleton();
 1825+ $view->addCustomHtml( $out );
 1826+ return false;
 1827+ }
18091828
18101829 public static function addRevisionIDField( $editPage, $out ) {
18111830 $view = FlaggedArticleView::singleton();
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -164,9 +164,9 @@
165165 */
166166 public function displayTag() {
167167 global $wgOut;
168 - $this->load();
 168+ $this->load();
169169 // Sanity check that this is a reviewable page
170 - if ( $this->article->isReviewable() ) {
 170+ if ( $this->article->isReviewable() ) {
171171 $wgOut->appendSubtitle( $this->reviewNotice );
172172 }
173173 return true;
@@ -1811,4 +1811,19 @@
18121812 }
18131813 return true;
18141814 }
 1815+
 1816+ /*
 1817+ * If this is a diff page then replace the article contents with a link to the specific revision.
 1818+ * This will be replaced with artice content using javascript and an api call.
 1819+ */
 1820+ public function addCustomHtml( OutputPage &$out ) {
 1821+ global $wgTitle, $wgScript, $wgRequest;
 1822+ $this->load();
 1823+ if ( $wgRequest->getVal( 'oldid' ) ) {
 1824+ $oldId = $wgRequest->getVal( 'oldid' );
 1825+ $oldRevisionUrl = $wgScript . '?title=' . $wgTitle . '&oldid=' . $oldId;
 1826+ $out->addHTML( "<div id='mw-fr-revisioncontents'>Click <a href='" . $oldRevisionUrl . "' >here</a> to view this revision.</div>" );
 1827+ }
 1828+
 1829+ }
18151830 }
Index: trunk/extensions/FlaggedRevs/client/flaggedrevs.css
@@ -336,3 +336,18 @@
337337 .fr-hiddenform {
338338 display: none;
339339 }
 340+
 341+.loading {
 342+ display: block;
 343+ color: #666666;
 344+ padding-left: 32px;
 345+ height: 32px;
 346+}
 347+.spinner {
 348+ background-image: url(img/loading-small.gif) !important;
 349+ background-position: left center;
 350+ background-repeat: no-repeat;
 351+ margin-left: 0.5em;
 352+ margin-top: -0.25em;
 353+ float: left;
 354+}
Index: trunk/extensions/FlaggedRevs/client/flaggedrevs.js
@@ -182,9 +182,57 @@
183183 }
184184 }
185185
 186+FlaggedRevs.getRevisionContents = function() {
 187+ //get the contents div and replace it with actual parsed article contents via an API call.
 188+ var contentsDiv = document.getElementById("mw-fr-revisioncontents");
 189+ var prevLink = document.getElementById("differences-prevlink");
 190+ var nextLink = document.getElementById("differences-nextlink");
 191+ var timeoutId = null;
 192+ if( contentsDiv ) {
 193+ var diffUIParams = document.getElementById("mw-fr-diff-dataform");
 194+ var oldRevId = diffUIParams.getElementsByTagName('input')[1].value;
 195+ contentsDiv.innerHTML = "<span class='loading spinner'></span><span class='loading' >Waiting for contents</span>";
 196+ var requestArgs = 'action=parse&prop=text&format=xml';
 197+ if ( window.wgLatestRevisionId == oldRevId ) {
 198+ requestArgs += '&pageid=' + window.wgPageId;
 199+ } else {
 200+ requestArgs += '&oldid=' + oldRevId;
 201+ }
 202+ timeoutId = window.setTimeout( function() {
 203+ $.ajax({
 204+ url : wgScriptPath + '/api.php',
 205+ type : "GET",
 206+ data : requestArgs,
 207+ dataType: "xml",
 208+ success : function( result ) {
 209+ contents = $(result).find("text");
 210+ if ( contents ) {
 211+ contentsDiv.innerHTML = contents.text();
 212+ }
 213+ },
 214+ error : function(xmlHttpRequest, textStatus, errThrown) {
 215+ alert("error: " + textStauts);
 216+ }
 217+ });
 218+ }, 1000 );
 219+ }
 220+ if ( prevLink && timeoutId ) {
 221+ prevLink.onclick = function() {
 222+ window.clearTimeout( timeoutId );
 223+ }
 224+ }
 225+ if ( nextLink && timeoutId ) {
 226+ nextLink.onclick = function() {
 227+ window.clearTimeout( timeoutId );
 228+ }
 229+ }
 230+}
 231+
186232 FlaggedRevs.setJSTriggers = function() {
187233 FlaggedRevs.enableShowhide();
188234 FlaggedRevs.setCheckTrigger();
 235+ FlaggedRevs.getRevisionContents();
189236 }
190237
191 -hookEvent("load", FlaggedRevs.setJSTriggers);
 238+//TODO figure out the correct way to do this
 239+window.onload = FlaggedRevs.setJSTriggers;
Index: trunk/extensions/FlaggedRevs/client/img/loading-small.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/extensions/FlaggedRevs/client/img/loading-small.gif
___________________________________________________________________
Added: svn:mime-type
192240 + application/octet-stream

Follow-up revisions

RevisionCommit summaryAuthorDate
r75747* (bug 24043) Changed edit review checkbox to "accept this page *with* my edits"...aaron21:16, 31 October 2010
r76353Better error handling. Fixed how css and js file are included. Followup to r7...pdhanda23:32, 8 November 2010
r76360Reusing existing class, mw-small-spinner. Followup to r75331pdhanda00:37, 9 November 2010
r76877Follow-up r75331: escape page name in URLaaron10:23, 17 November 2010
r76878Follow-up r75331: we already have wgCurRevisionId, just use itaaron10:36, 17 November 2010

Comments

#Comment by Aaron Schulz (talk | contribs)   16:21, 28 October 2010

Ideally this could just be in the core someday, so diffs (sans preview) would go faster on all sites rather than just for some pages on wikis that happen to have a certain extension enabled.

#Comment by Aaron Schulz (talk | contribs)   16:25, 28 October 2010

"Detected bug in an extension! Hook FlaggedRevsHooks::addCustomHtml has invalid call signature; Parameter 2 to FlaggedRevsHooks::addCustomHtml() expected to be a reference, value given"

#Comment by Nikerabbit (talk | contribs)   16:32, 28 October 2010

Yay, r70109 is finally useful.

#Comment by RobLa-WMF (talk | contribs)   22:22, 2 November 2010

Per our discussion, also should change this: $wgFlaggedRevStyleVersion = '78'; ...to: $wgFlaggedRevStyleVersion = 78;

#Comment by P858snake (talk | contribs)   00:17, 3 November 2010

"/trunk/extensions/FlaggedRevs/client/img/loading-small.gif (added)", Couldn't you just use "/trunk/phase3/skins/common/images/ajax-loader.gif" instead of having to package a separate one so they are standardized onto one image?

#Comment by Umherirrender (talk | contribs)   15:13, 1 December 2010

Need check of wgEnableAPI.

You can use wgScriptExtension.

Status & tagging log