« Utilisateur:Amgine/mwApiXmlParse.php » : différence entre les versions

Contenu supprimé Contenu ajouté
Amgine (discuter | contributions)
init
(Aucune différence)

Version du 5 janvier 2010 à 21:51

<?php /**

* mwApiXmlParse class
**
* Class to hold parsing methods re: Mediawiki API
* 
* This class has several dependencies/assumptions
* 		* PHP xml module is enabled (which, in turn, relies on expat
* 		  by James Clark.
* 		* mwApiXmlItem (class in mwApiXmlParse.php)
**
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the Free
*  Software Foundation; either version 2 of the License, or (at your option)
*  any later version.
*
*  This program is distributed in the hope that it will be useful, but WITHOUT
*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
*  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
*  more details.
*
*  You should have received a copy of the GNU General Public License along with
*  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
*  Place - Suite 330, Boston, MA 02111-1307, USA.
*  http://www.gnu.org/copyleft/gpl.html
**
* @author Amgine <amgine.saewyc@gmail.com>
* @copyright 2010 by Amgine <amgine.saewyc@gmail.com>
*/

class mwApiXmlParse{ /** * @var $tag string xml tag name **/ public $tag = ;

/** * @var $depth int xml element nested depth **/ public $depth = array();

/** * @var $allElements string text map **/ public $allElements = ;

/** * @var $item object mwApiXmlItem **/ public $item;

/** * @var $values **/

/** * __construct method **/ private function __construct(){ $this->item = new mwApiXmlItem; }

/** * startElement method ** * Process new xml tags, as called by xml_parse in an event-driven * xml parser. ** * @param $parser string resource handler * @param $tag string name of xml element * @param $attrib array associative array of element attributes **/ private function startElement( $parser, $tag, $attrib ){ for ($i = 0; $i < $this->depth[$parser]; $i++) { $this->allElements .= ' '; } $this->allElements .= "$tag\n"; $this->depth[$parser]++; switch( $tag ){ case 'login': if( 'Success' == $attrib['result'] ){ $this->item->userid = $attrib['lguserid']; $this->item->username = $attrib['lgusername']; $this->item->loginToken = $attrib['lgtoken']; $this->item->cookiePrefix = $attrib['cookieprefix']; $this->item->sessionId = $attrib['sessionid']; } break;

} }

/** * endElement method ** * Process at the end of xml tags, as called by xml_parse in an * event-driven xml parser. ** * @param $pasers string Resource handler * @param $tag string xml element name **/ function endElement( $parser, $tag ) { $this->depth[$parser]--; } }

/**

* mwApiXmlItem class
**
* Class to hold returned values and tokens re: Mediawiki API
**
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the Free
*  Software Foundation; either version 2 of the License, or (at your option)
*  any later version.
*
*  This program is distributed in the hope that it will be useful, but WITHOUT
*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
*  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
*  more details.
*
*  You should have received a copy of the GNU General Public License along with
*  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
*  Place - Suite 330, Boston, MA 02111-1307, USA.
*  http://www.gnu.org/copyleft/gpl.html
**
* @author Amgine <amgine.saewyc@gmail.com>
* @copyright 2010 by Amgine <amgine.saewyc@gmail.com>
*/

class mwApiXmlItem{ /** * @var $userid string User id **/ public $userid = ;

/** * @var $username string User name **/ public $username = ;

/** * @var $loginToken string Login token **/ public $loginToken = ;

/** * @var $cookiePrefix string prefix for cookie names **/ public $cookiePrefix = ;

/** * @var $sessionId string session id hash **/ public $sessionId = ;

}