Dr0ptp4kt has uploaded a new change for review.

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


Change subject: WIP: DO NOT MERGE! Supported flagged revisions of W0 
configurations.
......................................................................

WIP: DO NOT MERGE! Supported flagged revisions of W0 configurations.

* An update will need to be made to mediawiki-config before this can work.
* The mediawiki-config will need to set some FR variables.
* Additionally, this WIP will need review for memcaching on FR approval.
* Additionally, this WIP will need review for roundtrip savings with a 
generator.
* It may turn out that the memcache and roundtrip stuff doesn't require work, 
but we'll see.

Change-Id: I644aecd4a6bb60cbfd371f162147d3cbf1a36ab6
---
M README
M ZeroRatedMobileAccess.php
M includes/CarrierConfigStore.php
3 files changed, 40 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/57/95657/1

diff --git a/README b/README
index bf2e19f..a0be4fa 100644
--- a/README
+++ b/README
@@ -69,7 +69,7 @@
   $wgMFAutodetectMobileView = true; // autodetects mobile User-Agent
   
require_once("$IP/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.php");
   $wgEnableZeroRatedMobileAccessTesting = true;
-  $wgZeroRatedMobileAccessConfigIndexUri = 'http://127.0.0.1/w/index.php';
+  $wgZeroRatedMobileAccessApiUri = 'http://127.0.0.1/w/api.php';
   $wgZeroRatedMobileAccessDisableCache = true;
   $wgZeroRatedMobileAccessEnableZeroConfigPages = true;
   $wgRightsText = 'Sweet license';
diff --git a/ZeroRatedMobileAccess.php b/ZeroRatedMobileAccess.php
index 264e04f..2e5a110 100644
--- a/ZeroRatedMobileAccess.php
+++ b/ZeroRatedMobileAccess.php
@@ -106,7 +106,7 @@
 );
 
 $wgEnableZeroRatedMobileAccessTesting = false;
-$wgZeroRatedMobileAccessConfigIndexUri = false;
+$wgZeroRatedMobileAccessApiUri = false;
 $wgZeroRatedMobileAccessDisableCache = false;
 $wgZeroRatedMobileAccessEnableZeroConfigPages = false;
 $wgZeroRatedMobileAccessEnableESI = false;
diff --git a/includes/CarrierConfigStore.php b/includes/CarrierConfigStore.php
index ebbc627..3fbfe9e 100644
--- a/includes/CarrierConfigStore.php
+++ b/includes/CarrierConfigStore.php
@@ -122,19 +122,47 @@
         * @return string: URI.
         */
        private function getUri() {
-               global $wgZeroRatedMobileAccessConfigIndexUri;
+               global $wgZeroRatedMobileAccessApiUri;
 
-               if ( $wgZeroRatedMobileAccessConfigIndexUri === false ) {
-                       wfLogWarning( '$wgZeroRatedMobileAccessConfigIndexUri 
is not set' );
+               if ( $wgZeroRatedMobileAccessApiUri === false ) {
+                       wfLogWarning( '$wgZeroRatedMobileAccessApiUri is not 
set' );
                        return false;
                }
 
-               $q = array(
-                       'title'  =>  'Zero:' . $this->carrierId,
-                       'action' =>  'raw',
+               $articleName = 'Zero:' . $this->carrierId;
+
+               $qInfo = array(
+                       'action' => 'query',
+                       'prop' => 'info|flagged',
+                       'format' => 'json',
+                       'titles' => $articleName,
                );
 
-               return wfAppendQuery( $wgZeroRatedMobileAccessConfigIndexUri, 
$q );
+               $apiUri = wfAppendQuery( $wgZeroRatedMobileAccessApiUri, $qInfo 
);
+
+               $revInfo = json_decode( $this->http->get( $apiUri, 
self::LOCK_TIMEOUT * 0.8 ), true );
+
+               if ( array_key_exists( '-1', $revInfo['query']['pages'] ) ) {
+                       return false;
+               }
+
+               $pageInfo = array_slice ( $revInfo['query']['pages'], 0, 1 );
+               $revId = array_key_exists ( 'flagged', $pageInfo[0] ) ?
+                       $pageInfo[0]['flagged']['stable_revid'] :
+                       $pageInfo[0]['lastrevid'];
+
+
+               $qRev = array(
+                       'action' => 'query',
+                       'prop' => 'revisions',
+                       'rvlimit' => '1',
+                       'rvprop' => 'content',
+                       'format' => 'json',
+                       'rvstartid' => $revId,
+                       'titles'  =>  $articleName,
+               );
+
+               return wfAppendQuery( $wgZeroRatedMobileAccessApiUri, $qRev );
        }
 
 
@@ -152,9 +180,10 @@
                        return false;
                }
                wfProfileIn( __METHOD__ );
-               $res = $this->http->get( $uri, self::LOCK_TIMEOUT * 0.8 );
+               $rev = json_decode( $this->http->get( $uri, self::LOCK_TIMEOUT 
* 0.8 ), true );
                wfProfileOut( __METHOD__ );
-               return $res;
+               $page = array_slice( $rev['query']['pages'], 0, 1 );
+               return $page[0]['revisions'][0]['*'];
        }
 
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I644aecd4a6bb60cbfd371f162147d3cbf1a36ab6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <[email protected]>

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

Reply via email to