diff --git a/botclasses.php b/botclasses.php index 8c47bf6..9200478 100644 --- a/botclasses.php +++ b/botclasses.php @@ -227,7 +227,7 @@ function query ($query,$post=null,$repeat=0) { throw new Exception("HTTP Error."); } } - return unserialize($ret); + return json_decode($ret, true); } /** @@ -240,7 +240,7 @@ function getpage ($page,$revid=null,$detectEditConflict=false) { $append = ''; if ($revid!=null) $append = '&rvstartid='.$revid; - $x = $this->query('?action=query&format=php&prop=revisions&titles='.urlencode($page).'&rvlimit=1&rvprop=content|timestamp'.$append); + $x = $this->query('?action=query&format=json&prop=revisions&titles='.urlencode($page).'&rvlimit=1&rvprop=content|timestamp'.$append); foreach ($x['query']['pages'] as $ret) { if (isset($ret['revisions'][0]['*'])) { if ($detectEditConflict) @@ -257,7 +257,7 @@ function getpage ($page,$revid=null,$detectEditConflict=false) { * @return The page id of the page. **/ function getpageid ($page) { - $x = $this->query('?action=query&format=php&prop=revisions&titles='.urlencode($page).'&rvlimit=1&rvprop=content'); + $x = $this->query('?action=query&format=json&prop=revisions&titles='.urlencode($page).'&rvlimit=1&rvprop=content'); foreach ($x['query']['pages'] as $ret) { return $ret['pageid']; } @@ -269,7 +269,7 @@ function getpageid ($page) { * @return The number of contributions the user has. **/ function contribcount ($user) { - $x = $this->query('?action=query&list=allusers&format=php&auprop=editcount&aulimit=1&aufrom='.urlencode($user)); + $x = $this->query('?action=query&list=allusers&format=json&auprop=editcount&aulimit=1&aufrom='.urlencode($user)); return $x['query']['allusers'][0]['editcount']; } @@ -283,7 +283,7 @@ function categorymembers ($category,$subcat=false) { $continue = '&rawcontinue='; $pages = array(); while (true) { - $res = $this->query('?action=query&list=categorymembers&cmtitle='.urlencode($category).'&format=php&cmlimit=500'.$continue); + $res = $this->query('?action=query&list=categorymembers&cmtitle='.urlencode($category).'&format=json&cmlimit=500'.$continue); if (isset($x['error'])) { return false; } @@ -312,7 +312,7 @@ function categorymembers ($category,$subcat=false) { * @return integer **/ function categorypagecount ($category) { - $res = $this->query('?action=query&format=php&titles='.urlencode($category).'&prop=categoryinfo&formatversion=2'); + $res = $this->query('?action=query&format=json&titles='.urlencode($category).'&prop=categoryinfo&formatversion=2'); return $res['query']['pages'][0]['categoryinfo']['pages']; } @@ -326,7 +326,7 @@ function whatlinkshere ($page,$extra=null) { $continue = '&rawcontinue='; $pages = array(); while (true) { - $res = $this->query('?action=query&list=backlinks&bltitle='.urlencode($page).'&bllimit=500&format=php'.$continue.$extra); + $res = $this->query('?action=query&list=backlinks&bltitle='.urlencode($page).'&bllimit=500&format=json'.$continue.$extra); if (isset($res['error'])) { return false; } @@ -351,7 +351,7 @@ function whereisincluded ($image,$extre=null) { $continue = '&rawcontinue='; $pages = array(); while (true) { - $res = $this->query('?action=query&list=imageusage&iutitle='.urlencode($image).'&iulimit=500&format=php'.$continue.$extra); + $res = $this->query('?action=query&list=imageusage&iutitle='.urlencode($image).'&iulimit=500&format=json'.$continue.$extra); if (isset($res['error'])) return false; foreach ($res['query']['imageusage'] as $x) { @@ -374,7 +374,7 @@ function whatusethetemplate ($template,$extra=null) { $continue = '&rawcontinue='; $pages = array(); while (true) { - $res = $this->query('?action=query&list=embeddedin&eititle=Template:'.urlencode($template).'&eilimit=500&format=php'.$continue.$extra); + $res = $this->query('?action=query&list=embeddedin&eititle=Template:'.urlencode($template).'&eilimit=500&format=json'.$continue.$extra); if (isset($res['error'])) { return false; } @@ -396,7 +396,7 @@ function whatusethetemplate ($template,$extra=null) { **/ function subpages ($page) { /* Calculate all the namespace codes */ - $ret = $this->query('?action=query&meta=siteinfo&siprop=namespaces&format=php'); + $ret = $this->query('?action=query&meta=siteinfo&siprop=namespaces&format=json'); foreach ($ret['query']['namespaces'] as $x) { $namespaces[$x['*']] = $x['id']; } @@ -406,7 +406,7 @@ function subpages ($page) { $continue = '&rawcontinue='; $subpages = array(); while (true) { - $res = $this->query('?action=query&format=php&list=allpages&apprefix='.urlencode($title).'&aplimit=500&apnamespace='.$namespace.$continue); + $res = $this->query('?action=query&format=json&list=allpages&apprefix='.urlencode($title).'&aplimit=500&apnamespace='.$namespace.$continue); if (isset($x['error'])) { return false; } @@ -429,11 +429,11 @@ function subpages ($page) { **/ function login ($user,$pass) { $post = array('lgname' => $user, 'lgpassword' => $pass); - $ret = $this->query('?action=login&format=php',$post); + $ret = $this->query('?action=login&format=json',$post); /* This is now required - see https://bugzilla.wikimedia.org/show_bug.cgi?id=23076 */ if ($ret['login']['result'] == 'NeedToken') { $post['lgtoken'] = $ret['login']['token']; - $ret = $this->query( '?action=login&format=php', $post ); + $ret = $this->query( '?action=login&format=json', $post ); } if ($ret['login']['result'] != 'Success') { echo "Login error: \n"; @@ -484,7 +484,7 @@ function nobots ($page,$user=null,$text=null) { * @return string edit token. **/ function getedittoken() { - $x = $this->query('?action=query&prop=info&intoken=edit&titles=Main%20Page&format=php'); + $x = $this->query('?action=query&prop=info&intoken=edit&titles=Main%20Page&format=json'); foreach ($x['query']['pages'] as $ret) { return $ret['edittoken']; } @@ -496,7 +496,7 @@ function getedittoken() { * @return Api result. **/ function purgeCache($page) { - return $this->query('?action=purge&titles='.urlencode($page).'&format=php'); + return $this->query('?action=purge&titles='.urlencode($page).'&format=json'); } /** @@ -506,7 +506,7 @@ function purgeCache($page) { * @return bool. **/ function checkEmail($user) { - $x = $this->query('?action=query&meta=allmessages&ammessages=noemailtext|notargettext&amlang=en&format=php'); + $x = $this->query('?action=query&meta=allmessages&ammessages=noemailtext|notargettext&amlang=en&format=json'); $messages[0] = $x['query']['allmessages'][0]['*']; $messages[1] = $x['query']['allmessages'][1]['*']; $page = $this->http->get(str_replace('api.php','index.php',$this->url).'?title=Special:EmailUser&target='.urlencode($user)); @@ -527,7 +527,7 @@ function getTransclusions($page,$sleep=null,$extra=null) { $continue = '&rawcontinue='; $pages = array(); while (true) { - $ret = $this->query('?action=query&list=embeddedin&eititle='.urlencode($page).$continue.$extra.'&eilimit=500&format=php'); + $ret = $this->query('?action=query&list=embeddedin&eititle='.urlencode($page).$continue.$extra.'&eilimit=500&format=json'); if ($sleep != null) { sleep($sleep); } @@ -573,7 +573,7 @@ function edit ($page,$data,$summary = '',$minor = false,$bot = true,$section = n if ($maxlag!='') { $maxlag='&maxlag='.$maxlag; } - return $this->query('?action=edit&format=php'.$maxlag,$params); + return $this->query('?action=edit&format=json'.$maxlag,$params); } /** @@ -616,7 +616,7 @@ function move ($old,$new,$reason,$options=null) { $params[$o] = true; } } - return $this->query('?action=move&format=php',$params); + return $this->query('?action=move&format=json',$params); } /** @@ -628,7 +628,7 @@ function move ($old,$new,$reason,$options=null) { * @return api result **/ function rollback ($title,$user,$reason=null,$bot=false) { - $ret = $this->query('?action=query&prop=revisions&rvtoken=rollback&titles='.urlencode($title).'&format=php'); + $ret = $this->query('?action=query&prop=revisions&rvtoken=rollback&titles='.urlencode($title).'&format=json'); foreach ($ret['query']['pages'] as $x) { $token = $x['revisions'][0]['rollbacktoken']; break; @@ -642,7 +642,7 @@ function rollback ($title,$user,$reason=null,$bot=false) { $params['markbot'] = true; } if ($reason != null) { $params['summary'] = $reason; } - return $this->query('?action=rollback&format=php',$params); + return $this->query('?action=rollback&format=json',$params); } /** @@ -669,7 +669,7 @@ function block ($user,$reason='vand',$expiry='infinite',$options=null,$retry=tru $params[$o] = true; } } - $ret = $this->query('?action=block&format=php',$params); + $ret = $this->query('?action=block&format=json',$params); /* Retry on a failed token. */ if ($retry and $ret['error']['code']=='badtoken') { $this->token = $this->getedittoken(); @@ -693,7 +693,7 @@ function unblock ($user,$reason) { 'reason' => $reason, 'token' => $this->token ); - return $this->query('?action=unblock&format=php',$params); + return $this->query('?action=unblock&format=json',$params); } /** @@ -717,7 +717,7 @@ function email ($target,$subject,$text,$ccme=false) { if ($ccme) { $params['ccme'] = true; } - return $this->query('?action=emailuser&format=php',$params); + return $this->query('?action=emailuser&format=json',$params); } /** @@ -735,7 +735,7 @@ function delete ($title,$reason) { 'reason' => $reason, 'token' => $this->token ); - return $this->query('?action=delete&format=php',$params); + return $this->query('?action=delete&format=json',$params); } /** @@ -753,7 +753,7 @@ function undelete ($title,$reason) { 'reason' => $reason, 'token' => $this->token ); - return $this->query('?action=undelete&format=php',$params); + return $this->query('?action=undelete&format=json',$params); } /** @@ -779,7 +779,7 @@ function protect ($title,$protections,$expiry,$reason,$cascade=false) { if ($cascade) { $params['cascade'] = true; } - return $this->query('?action=protect&format=php',$params); + return $this->query('?action=protect&format=json',$params); } /** @@ -800,7 +800,7 @@ function upload ($page,$file,$desc='') { 'ignorewarnings' => '1', 'file' => '@'.$file ); - return $this->query('?action=upload&format=php',$params); + return $this->query('?action=upload&format=json',$params); } /* @@ -858,7 +858,7 @@ function createaccount ($username,$password,$email=null) { **/ function userrights ($user,$add,$remove,$reason='') { // get the userrights token - $token = $this->query('?action=query&list=users&ususers='.urlencode($user).'&ustoken=userrights&format=php'); + $token = $this->query('?action=query&list=users&ususers='.urlencode($user).'&ustoken=userrights&format=json'); $token = $token['query']['users'][0]['userrightstoken']; $params = array( 'user' => $user, @@ -867,7 +867,7 @@ function userrights ($user,$add,$remove,$reason='') { 'remove' => $remove, 'reason' => $reason ); - return $this->query('?action=userrights&format=php',$params); + return $this->query('?action=userrights&format=json',$params); } /** @@ -876,7 +876,7 @@ function userrights ($user,$add,$remove,$reason='') { * @return The number of images with the same sha1 hash. **/ function imagematches ($hash) { - $x = $this->query('?action=query&list=allimages&format=php&aisha1='.$hash); + $x = $this->query('?action=query&list=allimages&format=json&aisha1='.$hash); return count($x['query']['allimages']); } @@ -886,7 +886,7 @@ function imagematches ($hash) { * @return The URL pointing directly to the media file (Eg http://upload.mediawiki.org/wikipedia/en/1/1/Example.jpg) **/ function getfilelocation ($page) { - $x = $this->query('?action=query&format=php&prop=imageinfo&titles='.urlencode($page).'&iilimit=1&iiprop=url'); + $x = $this->query('?action=query&format=json&prop=imageinfo&titles='.urlencode($page).'&iilimit=1&iiprop=url'); foreach ($x['query']['pages'] as $ret ) { if (isset($ret['imageinfo'][0]['url'])) { return $ret['imageinfo'][0]['url']; @@ -901,7 +901,7 @@ function getfilelocation ($page) { * @return The user who uploaded the topmost version of the file. **/ function getfileuploader ($page) { - $x = $this->query('?action=query&format=php&prop=imageinfo&titles='.urlencode($page).'&iilimit=1&iiprop=user'); + $x = $this->query('?action=query&format=json&prop=imageinfo&titles='.urlencode($page).'&iilimit=1&iiprop=user'); foreach ($x['query']['pages'] as $ret ) { if (isset($ret['imageinfo'][0]['user'])) { return $ret['imageinfo'][0]['user']; diff --git a/goodarticles.php b/goodarticles.php index 8dd4940..5c6af16 100644 --- a/goodarticles.php +++ b/goodarticles.php @@ -40,7 +40,7 @@ public function getpage ($page,$revid=null,$detectEditConflict=false) { $append = '&rvstartid='.$revid; for ($i=0;$i<5;$i++) { - $x = parent::query('?action=query&format=php&prop=revisions&titles='.urlencode($page).'&rvlimit=1&rvprop=content|timestamp'.$append); + $x = parent::query('?action=query&format=json&prop=revisions&titles='.urlencode($page).'&rvlimit=1&rvprop=content|timestamp'.$append); if (isset($x['query']['pages'])) { foreach ($x['query']['pages'] as $ret) { if (isset($ret['revisions'][0]['*'])) { diff --git a/mediawiki.php b/mediawiki.php index 8ec2edb..0db838f 100644 --- a/mediawiki.php +++ b/mediawiki.php @@ -54,11 +54,11 @@ public function query ($query, $post = null) { $data = $this->http->get($this->url . $query); else $data = $this->http->post($this->url . $query, $post); - return unserialize($data); + return json_decode($data, true); } protected function queryString ($query) { - $return = "?format=php"; + $return = "?format=json"; foreach ($query as $key => $value) { $return .= "&" . urlencode($key) . "=" . urlencode($value); } diff --git a/new_mediawiki.php b/new_mediawiki.php index 874b1c9..3698abe 100644 --- a/new_mediawiki.php +++ b/new_mediawiki.php @@ -54,14 +54,14 @@ public function query( $query, $post = null ) { if ( is_array($query) ) { $query = $this->queryString($query); } else { - $query .= '&format=php'; + $query .= '&format=json'; } if ( $post === null || $post === false ) { $data = $this->http->get($this->url . $query); } else { $data = $this->http->post($this->url . $query, $post); } - return unserialize($data); + return json_decode($data, true); } /** @@ -69,7 +69,7 @@ public function query( $query, $post = null ) { * @return string */ protected function queryString( $query ) { - $return = "?format=php"; + $return = "?format=json"; foreach ($query as $key => $value) { $return .= "&" . urlencode($key) . "=" . urlencode($value); } diff --git a/noticeboards.php b/noticeboards.php index 0b3b626..4345053 100644 --- a/noticeboards.php +++ b/noticeboards.php @@ -40,7 +40,7 @@ function nbprocess ($pagearray, $color, $submissionpage) { foreach ($pagearray as $topic => $page) { - $raw = $objwiki->query("?action=parse&page=". urlencode($page) . "&prop=sections&format=php"); + $raw = $objwiki->query("?action=parse&page=". urlencode($page) . "&prop=sections&format=json"); $sections = array(); $seccount = 0;