Florianschmidtwelzow has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/349768 )

Change subject: Fix bad newlines
......................................................................


Fix bad newlines

Removed \r from files

Change-Id: I5a54ae533838d8ec2bedd87436816d689f2612f3
---
M includes/apis/SRF_Xml.php
M includes/apis/WOM_GetWikiResult.php
M includes/apis/WOM_WikiObjectApi.php
M includes/models/WOM_OM_Redirect.php
M includes/parsers/WOMAskParser.php
M includes/parsers/WOMParserFunctionParameterParser.php
M includes/parsers/WOMRedirectParser.php
7 files changed, 588 insertions(+), 588 deletions(-)

Approvals:
  Florianschmidtwelzow: Verified; Looks good to me, approved



diff --git a/includes/apis/SRF_Xml.php b/includes/apis/SRF_Xml.php
index 460ce9d..31a22fb 100644
--- a/includes/apis/SRF_Xml.php
+++ b/includes/apis/SRF_Xml.php
@@ -1,50 +1,50 @@
-<?php
-/**
- * A query printer for xml
- *
- * @note AUTOLOADED
- */
-
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( 'Not an entry point.' );
-}
-
-class SRFXml extends SMWResultPrinter {
-       protected function getResultText( $res, $outputmode ) {
-               $heads = array();
-               $first = true;
-               foreach ( $res->getPrintRequests() as $pr ) {
-                       $head = $pr->getText( $outputmode, null );
-                       if ( $first ) {
-                               if ( !$head ) $head = 'mainlabel';
-                               $first = false;
-                       }
-
-                       $heads[] = str_replace( ' ', '_', str_replace( '/', 
'_', $head ) );
-               }
-
-               $xml = '<res>' . "\n";
-               // print all result rows
-               while ( $row = $res->getNext() ) {
-                       $xml .= '<row>' . "\n";
-                       $firstcol = true;
-                       $idx = 0;
-                       foreach ( $row as $field ) {
-                               $xml .= "<{$heads[$idx]}>\n";
-//                             $growing = array();
-                               while ( ( $object = $field->getNextObject() ) 
!== false ) {
-                                       $text = 
Sanitizer::decodeCharReferences( $object->getWikiValue() );
-                                       $xml .= "<val>{$text}</val>";
-//                                     $growing[] = $text;
-                               } // while...
-//                             $xml .= implode( ',', $growing );
-                               $xml .= "</{$heads[$idx]}>\n";
-                               ++ $idx;
-                       } // foreach...
-                       $xml .= '</row>' . "\n";
-               }
-               $xml .= '</res>' . "\n";
-
-               return $xml;
-       }
+<?php
+/**
+ * A query printer for xml
+ *
+ * @note AUTOLOADED
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+       die( 'Not an entry point.' );
+}
+
+class SRFXml extends SMWResultPrinter {
+       protected function getResultText( $res, $outputmode ) {
+               $heads = array();
+               $first = true;
+               foreach ( $res->getPrintRequests() as $pr ) {
+                       $head = $pr->getText( $outputmode, null );
+                       if ( $first ) {
+                               if ( !$head ) $head = 'mainlabel';
+                               $first = false;
+                       }
+
+                       $heads[] = str_replace( ' ', '_', str_replace( '/', 
'_', $head ) );
+               }
+
+               $xml = '<res>' . "\n";
+               // print all result rows
+               while ( $row = $res->getNext() ) {
+                       $xml .= '<row>' . "\n";
+                       $firstcol = true;
+                       $idx = 0;
+                       foreach ( $row as $field ) {
+                               $xml .= "<{$heads[$idx]}>\n";
+//                             $growing = array();
+                               while ( ( $object = $field->getNextObject() ) 
!== false ) {
+                                       $text = 
Sanitizer::decodeCharReferences( $object->getWikiValue() );
+                                       $xml .= "<val>{$text}</val>";
+//                                     $growing[] = $text;
+                               } // while...
+//                             $xml .= implode( ',', $growing );
+                               $xml .= "</{$heads[$idx]}>\n";
+                               ++ $idx;
+                       } // foreach...
+                       $xml .= '</row>' . "\n";
+               }
+               $xml .= '</res>' . "\n";
+
+               return $xml;
+       }
 }
\ No newline at end of file
diff --git a/includes/apis/WOM_GetWikiResult.php 
b/includes/apis/WOM_GetWikiResult.php
index c70afac..946c7c1 100644
--- a/includes/apis/WOM_GetWikiResult.php
+++ b/includes/apis/WOM_GetWikiResult.php
@@ -1,146 +1,146 @@
-<?php
-
-/**
- * @addtogroup API
- */
-class ApiWOMGetWikiResult extends ApiBase {
-
-       public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
-       }
-
-       public function execute() {
-               global $wgUser;
-
-               $params = $this->extractRequestParams();
-               if ( is_null( $params['wiki'] ) )
-                       $this->dieUsage( 'Must specify wiki text', 0 );
-               $wiki = $params['wiki'];
-               $type = $params['type'];
-
-               $result = array(
-                       'wiki' => array(),
-                       'message' => array(),
-                       'return' => array(),
-               );
-               if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                       ApiResult::setContentValue( $result['wiki'], 'wiki', 
$wiki );
-               } else {
-                       ApiResult::setContent( $result['wiki'], $wiki );
-               }
-
-               global $wgParser;
-               $popt = new ParserOptions();
-               $popt->setEditSection( false );
-               $title = Title::newFromText( '__TEMPWIKITITLE__' );
-               if ( strtolower( $type ) == 'ask' ) {
-                       $_wiki = "{$wiki}|format=xml";
-
-                       global $wgOMIP, $smwgResultFormats, $wgAutoloadClasses;
-                       $smwgResultFormats['xml'] = 'SRFXml';
-                       $wgAutoloadClasses['SRFXml'] = $wgOMIP . 
'/includes/apis/SRF_Xml.php';
-
-                       $s = $wgParser->preprocess( $_wiki, $title, $popt );
-                       $b = 0;
-                       for ( $i = 0; $i < strlen( $s ); ++$i ) {
-                               if ( $s { $i } == '[' ) {
-                                       ++ $b;
-                               } elseif ( $s { $i } == ']' ) {
-                                       -- $b;
-                               } elseif ( $s { $i } == '|' ) {
-                                       if ( $b == 0 ) break;
-                               }
-                       }
-                       $rawparams = array( substr( $s, 0, $i ) );
-                       if ( $i < strlen( $s ) ) $rawparams = array_merge( 
$rawparams, explode( '|', substr( $s, $i + 1 ) ) );
-                       $xml = SMWQueryProcessor::getResultFromFunctionParams( 
$rawparams, SMW_OUTPUT_WIKI );
-
-                       $xObj = simplexml_load_string( $xml );
-                       try {
-                               $rows = array();
-                               foreach ( $xObj->xpath( '/res/row' ) as $objs ) 
{
-                                       $row = array();
-                                       foreach ( $objs as $label => $vals ) {
-                                               $vs = array();
-                                               foreach ( $vals as $v ) {
-                                                       $vs[] = strval( $v );
-                                               }
-                               $this->getResult()->setIndexedTagName( $vs, 
'value' );
-                                               $row[$label] = $vs;
-                                       }
-//                                     
$this->getResult()->setIndexedTagName($rows, 'list-item');
-                                       $rows[] = $row;
-                               }
-                   $this->getResult()->setIndexedTagName( $rows, 'item' );
-                   $result['return'] = $rows;
-//                 $this->getResult()->addValue(array($this->getModuleName(), 
'result'), 'items', $rows);
-                       } catch ( Exception $e ) {
-                               $err = $e->getMessage();
-                       }
-               } else {
-                       $pout = $wgParser->parse( $wiki, $title, $popt );
-                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                               ApiResult::setContentValue( $result['return'], 
'text', $pout->getText() );
-                       } else {
-                               ApiResult::setContent( $result['return'], 
$pout->getText() );
-                       }
-               }
-               if ( isset( $err ) ) {
-                       $result['result'] = 'Failure';
-                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                               ApiResult::setContentValue( $result['message'], 
'message', $err );
-                       } else {
-                               ApiResult::setContent( $result['message'], $err 
);
-                       }
-               } else {
-                       $result['result'] = 'Success';
-                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                               ApiResult::setContentValue( $result['message'], 
'message', 'no error' );
-                       } else {
-                               ApiResult::setContent( $result['message'], 'no 
error' );
-                       }
-               }
-               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
-       }
-
-       protected function getAllowedParams() {
-               $types = defined( 'SMW_VERSION' ) ? array( 'wiki', 'ask' ) : 
array( 'wiki' );
-               return array (
-                       'wiki' => null,
-                       'type' => array(
-                               ApiBase :: PARAM_DFLT => 'wiki',
-                               ApiBase :: PARAM_TYPE => $types
-                       ),
-               );
-       }
-
-       protected function getParamDescription() {
-               $types = defined( 'SMW_VERSION' ) ? array(
-                               'Type to fetch wiki parse result',
-                               'type = wiki, get parser result of wiki text',
-                               'type = ask, get parser result of ask query'
-                       ) : array(
-                               'Type to fetch wiki parse result',
-                               'type = wiki, get parser result of wiki text',
-                       );
-               return array (
-                       'wiki' => 'Wiki text',
-                       'type' => $types
-               );
-       }
-
-       protected function getDescription() {
-               return 'Call to get parse result of wiki';
-       }
-
-       protected function getExamples() {
-               return array (
-                       'api.php?action=womwiki&wiki=[[Hello]]',
-                       
'api.php?action=womwiki&wiki=[[Category:Hello]]&type=ask'
-               );
-       }
-
-//     public function mustBePosted() {
-//             return true;
-//     }
-}
+<?php
+
+/**
+ * @addtogroup API
+ */
+class ApiWOMGetWikiResult extends ApiBase {
+
+       public function __construct( $main, $action ) {
+               parent :: __construct( $main, $action );
+       }
+
+       public function execute() {
+               global $wgUser;
+
+               $params = $this->extractRequestParams();
+               if ( is_null( $params['wiki'] ) )
+                       $this->dieUsage( 'Must specify wiki text', 0 );
+               $wiki = $params['wiki'];
+               $type = $params['type'];
+
+               $result = array(
+                       'wiki' => array(),
+                       'message' => array(),
+                       'return' => array(),
+               );
+               if ( defined( 'ApiResult::META_CONTENT' ) ) {
+                       ApiResult::setContentValue( $result['wiki'], 'wiki', 
$wiki );
+               } else {
+                       ApiResult::setContent( $result['wiki'], $wiki );
+               }
+
+               global $wgParser;
+               $popt = new ParserOptions();
+               $popt->setEditSection( false );
+               $title = Title::newFromText( '__TEMPWIKITITLE__' );
+               if ( strtolower( $type ) == 'ask' ) {
+                       $_wiki = "{$wiki}|format=xml";
+
+                       global $wgOMIP, $smwgResultFormats, $wgAutoloadClasses;
+                       $smwgResultFormats['xml'] = 'SRFXml';
+                       $wgAutoloadClasses['SRFXml'] = $wgOMIP . 
'/includes/apis/SRF_Xml.php';
+
+                       $s = $wgParser->preprocess( $_wiki, $title, $popt );
+                       $b = 0;
+                       for ( $i = 0; $i < strlen( $s ); ++$i ) {
+                               if ( $s { $i } == '[' ) {
+                                       ++ $b;
+                               } elseif ( $s { $i } == ']' ) {
+                                       -- $b;
+                               } elseif ( $s { $i } == '|' ) {
+                                       if ( $b == 0 ) break;
+                               }
+                       }
+                       $rawparams = array( substr( $s, 0, $i ) );
+                       if ( $i < strlen( $s ) ) $rawparams = array_merge( 
$rawparams, explode( '|', substr( $s, $i + 1 ) ) );
+                       $xml = SMWQueryProcessor::getResultFromFunctionParams( 
$rawparams, SMW_OUTPUT_WIKI );
+
+                       $xObj = simplexml_load_string( $xml );
+                       try {
+                               $rows = array();
+                               foreach ( $xObj->xpath( '/res/row' ) as $objs ) 
{
+                                       $row = array();
+                                       foreach ( $objs as $label => $vals ) {
+                                               $vs = array();
+                                               foreach ( $vals as $v ) {
+                                                       $vs[] = strval( $v );
+                                               }
+                               $this->getResult()->setIndexedTagName( $vs, 
'value' );
+                                               $row[$label] = $vs;
+                                       }
+//                                     
$this->getResult()->setIndexedTagName($rows, 'list-item');
+                                       $rows[] = $row;
+                               }
+                   $this->getResult()->setIndexedTagName( $rows, 'item' );
+                   $result['return'] = $rows;
+//                 $this->getResult()->addValue(array($this->getModuleName(), 
'result'), 'items', $rows);
+                       } catch ( Exception $e ) {
+                               $err = $e->getMessage();
+                       }
+               } else {
+                       $pout = $wgParser->parse( $wiki, $title, $popt );
+                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
+                               ApiResult::setContentValue( $result['return'], 
'text', $pout->getText() );
+                       } else {
+                               ApiResult::setContent( $result['return'], 
$pout->getText() );
+                       }
+               }
+               if ( isset( $err ) ) {
+                       $result['result'] = 'Failure';
+                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
+                               ApiResult::setContentValue( $result['message'], 
'message', $err );
+                       } else {
+                               ApiResult::setContent( $result['message'], $err 
);
+                       }
+               } else {
+                       $result['result'] = 'Success';
+                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
+                               ApiResult::setContentValue( $result['message'], 
'message', 'no error' );
+                       } else {
+                               ApiResult::setContent( $result['message'], 'no 
error' );
+                       }
+               }
+               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
+       }
+
+       protected function getAllowedParams() {
+               $types = defined( 'SMW_VERSION' ) ? array( 'wiki', 'ask' ) : 
array( 'wiki' );
+               return array (
+                       'wiki' => null,
+                       'type' => array(
+                               ApiBase :: PARAM_DFLT => 'wiki',
+                               ApiBase :: PARAM_TYPE => $types
+                       ),
+               );
+       }
+
+       protected function getParamDescription() {
+               $types = defined( 'SMW_VERSION' ) ? array(
+                               'Type to fetch wiki parse result',
+                               'type = wiki, get parser result of wiki text',
+                               'type = ask, get parser result of ask query'
+                       ) : array(
+                               'Type to fetch wiki parse result',
+                               'type = wiki, get parser result of wiki text',
+                       );
+               return array (
+                       'wiki' => 'Wiki text',
+                       'type' => $types
+               );
+       }
+
+       protected function getDescription() {
+               return 'Call to get parse result of wiki';
+       }
+
+       protected function getExamples() {
+               return array (
+                       'api.php?action=womwiki&wiki=[[Hello]]',
+                       
'api.php?action=womwiki&wiki=[[Category:Hello]]&type=ask'
+               );
+       }
+
+//     public function mustBePosted() {
+//             return true;
+//     }
+}
diff --git a/includes/apis/WOM_WikiObjectApi.php 
b/includes/apis/WOM_WikiObjectApi.php
index ac0cec6..cd1a44d 100644
--- a/includes/apis/WOM_WikiObjectApi.php
+++ b/includes/apis/WOM_WikiObjectApi.php
@@ -1,205 +1,205 @@
-<?php
-
-/**
- * @addtogroup API
- */
-class ApiWOMWikiObjectApi extends ApiBase {
-       private $m_apiInst = null;
-
-       public function __construct( $main, $action ) {
-               parent :: __construct( $main, $action );
-       }
-
-       public function execute() {
-               global $wgUser;
-
-               $params = $this->extractRequestParams();
-               if ( is_null( $params['title'] ) )
-                       $this->dieUsage( 'Must specify page title', 0 );
-               if ( is_null( $params['xpath'] ) )
-                       $this->dieUsage( 'Must specify xpath', 1 );
-               if ( is_null( $params['api'] ) )
-                       $this->dieUsage( 'Must specify api action name', 2 );
-               if ( is_null( $params['wommap'] ) )
-                       $this->dieUsage( 'Must specify wom => api mapping 
info', 3 );
-
-               $page_name = $params['title'];
-               $xpath = $params['xpath'];
-               $api = $params['api'];
-               $rid = $params['rid'];
-
-               $wommaps = $this->parseMapInfo( $params['wommap'] );
-
-               $articleTitle = Title::newFromText( $page_name );
-               if ( !$articleTitle )
-                       $this->dieUsage( "Can't create title object 
($page_name)", 2 );
-
-               $article = new Article( $articleTitle );
-               if ( !$article->exists() )
-                       $this->dieUsage( "Article doesn't exist ($page_name)", 
3 );
-
-               try {
-                       $page_obj = WOMProcessor::getPageObject( $articleTitle, 
$rid );
-                       $objs = WOMProcessor::getObjIdByXPath2( $page_obj, 
$xpath );
-
-                       $vals = array();
-                       $first = true;
-                       foreach ( $objs as $id ) {
-                               if ( $id == '' ) continue;
-                               $wobj = $page_obj->getObject( $id );
-
-                               foreach ( $wommaps as $idx => $map ) {
-                                       if ( !$map['setting']['multiple'] && 
!$first ) continue;
-                                       $val = '';
-                                       if ( strtolower( $map['xpath'] ) == 
'innerwiki' ) {
-                                               $val = ( $wobj instanceof 
WikiObjectModelCollection ) ? $wobj->getInnerWikiText() : $wobj->getWikiText();
-                                       } else {
-                                               $xObj = simplexml_load_string( 
$wobj->toXML() );
-                                               $os = $xObj->xpath( 
$map['xpath'] );
-                                               if ( count( $os ) > 0 ) {
-                                                       foreach ( $os as $o ) 
$val .= strval( $o );
-                                               }
-                                       }
-                                       $wommaps[$idx]['value'] .=
-                                               ( $map['setting']['prefix'] ? 
$map['setting']['prefix']:'' ) .
-                                               $val .
-                                               ( $map['setting']['delimiter'] 
? $map['setting']['delimiter']:'' );
-                               }
-                               if ( $first ) $first = false;
-                       }
-               } catch ( Exception $e ) {
-                       $err = $e->getMessage();
-               }
-
-               $result = array();
-               if ( isset( $err ) ) {
-                       $result = array(
-                               'result' => 'Failure',
-                               'message' => array(),
-                       );
-                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
-                               ApiResult::setContentValue( $result['message'], 
'message', $err );
-                       } else {
-                               ApiResult::setContent( $result['message'], $err 
);
-                       }
-               } else {
-                       $result['result'] = 'Success';
-                       $result['revisionID'] = $page_obj->getRevisionID();
-                       foreach ( $wommaps as $map ) {
-                               $this->getMain()->getRequest()->setVal( 
$map['param'], $map['value'] );
-                       }
-                       $this->m_apiInst->profileIn();
-                       $this->m_apiInst->execute();
-                       $this->m_apiInst->profileOut();
-               }
-
-               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
-       }
-
-       private function parseMapInfo( $mapinfo ) {
-               $wommaps = array();
-               foreach ( explode( '|', str_replace( '||', 
'___PIPEPLACEHOLDER__', $mapinfo ) ) as $map ) {
-                       $s = explode( '=', str_replace( '___PIPEPLACEHOLDER__', 
'|', $map ), 2 );
-                       $settings = array();
-                       $first = true;
-                       $param = '';
-                       foreach ( explode( ',', str_replace( ',,', 
'___DELIMITERPLACEHOLDER__', $s[1] ) ) as $set ) {
-                               $set = str_replace( 
'___DELIMITERPLACEHOLDER__', '|', $set );
-                               if ( $first ) {
-                                       $param = $set;
-                                       $first = false;
-                                       continue;
-                               }
-                               if ( strtolower( $set { 0 } ) == 'm' ) {
-                                       $settings['multiple'] = true;
-                                       $settings['delimiter'] = substr( $set, 
1 );
-                               } elseif ( strtolower( $set { 0 } ) == 'p' ) {
-                                       $settings['prefix'] = substr( $set, 1 );
-                               }
-                       }
-                       $wommaps[] = array(
-                               'xpath' => $s[0],
-                               'param' => $param,
-                               'setting' => $settings,
-                               'value' => ''
-                       );
-               }
-               return $wommaps;
-       }
-
-       protected function getAllowedParams() {
-               // tricky here
-               $mainInst = $this->getMain();
-               $tmp = array_keys( 
$mainInst->getModuleManager()->getNamesWithClasses( 'action' ) );
-               $ids = array(
-                       array_search( 'womset', $tmp ),
-                       array_search( 'womget', $tmp ),
-                       array_search( 'womapi', $tmp ),
-                       array_search( 'womoutput', $tmp ),
-                       array_search( 'womwiki', $tmp ),
-                       array_search( 'womquery', $tmp )
-               );
-               foreach ( $ids as $id ) unset( $tmp[$id] );
-
-               $params = array (
-                       'title' => null,
-                       'xpath' => null,
-                       'rid' => array (
-                               ApiBase :: PARAM_TYPE => 'integer',
-                               ApiBase :: PARAM_DFLT => 0,
-                               ApiBase :: PARAM_MIN => 0
-                       ),
-                       'wommap' => null,
-                       'api' => array(
-                               ApiBase :: PARAM_DFLT => 'help',
-                               ApiBase :: PARAM_TYPE => $tmp
-                       ),
-               );
-
-               $api = $mainInst->getRequest()->getVal( $this->encodeParamName( 
'api' ), 'help' );
-               if ( $api == 'help' ) {
-                       // apply description
-                       $params['...'] = null;
-               } else {
-//                     $mainInst = new ApiMain($mainInst->getRequest());
-                       $modules = 
$mainInst->getModuleManager()->getNamesWithClasses( 'action' );
-                       $this->m_apiInst = new $modules[$api] ( $mainInst, $api 
);
-                       $params = $params + $this->m_apiInst->getFinalParams();
-               }
-
-               return $params;
-       }
-
-       protected function getParamDescription() {
-               return array (
-                       'title' => 'Title of the page to modify',
-                       'xpath' => 'DOM-like xpath to locate WOM object 
instances (http://www.w3schools.com/xpath/xpath_syntax.asp)',
-                       'wommap' => array (
-                               'Settings to map WOM result on parameter(s) of 
api actions',
-                               '"|" as delimiter, to separate map items',
-                               'format: xpath of values=api parameter 
name,other settings',
-                               '    for "|" inside map item, use "||" to 
escape',
-                               '    for "," inside map item, use ",," to 
escape',
-                               '  xpath:',
-                               '    "@property" as property name,',
-                               '    "innerwiki" as wiki text inside xml 
object',
-                               '  settings:',
-                               '    "m<delimiter>", multiple field, if 
multiple flag is not set, always use the first result,',
-                               '    "p<prefix>", prefix',
-                       ),
-                       'api' => 'Api (action) name of common Wiki',
-                       'rid' => 'Revision id of specified page - by dafault 
latest updated revision (0) is used',
-                       '...' => 'standard api parameters',
-               );
-       }
-
-       protected function getDescription() {
-               return 'Call to execute MW apis upon Wiki objects inside title';
-       }
-
-       protected function getExamples() {
-               return array (
-                       
'api.php?action=womapi&title=Somepage&xpath=//template&wommap=@name=titles,m||,ptemplate:&api=query&prop=info'
-               );
-       }
-}
+<?php
+
+/**
+ * @addtogroup API
+ */
+class ApiWOMWikiObjectApi extends ApiBase {
+       private $m_apiInst = null;
+
+       public function __construct( $main, $action ) {
+               parent :: __construct( $main, $action );
+       }
+
+       public function execute() {
+               global $wgUser;
+
+               $params = $this->extractRequestParams();
+               if ( is_null( $params['title'] ) )
+                       $this->dieUsage( 'Must specify page title', 0 );
+               if ( is_null( $params['xpath'] ) )
+                       $this->dieUsage( 'Must specify xpath', 1 );
+               if ( is_null( $params['api'] ) )
+                       $this->dieUsage( 'Must specify api action name', 2 );
+               if ( is_null( $params['wommap'] ) )
+                       $this->dieUsage( 'Must specify wom => api mapping 
info', 3 );
+
+               $page_name = $params['title'];
+               $xpath = $params['xpath'];
+               $api = $params['api'];
+               $rid = $params['rid'];
+
+               $wommaps = $this->parseMapInfo( $params['wommap'] );
+
+               $articleTitle = Title::newFromText( $page_name );
+               if ( !$articleTitle )
+                       $this->dieUsage( "Can't create title object 
($page_name)", 2 );
+
+               $article = new Article( $articleTitle );
+               if ( !$article->exists() )
+                       $this->dieUsage( "Article doesn't exist ($page_name)", 
3 );
+
+               try {
+                       $page_obj = WOMProcessor::getPageObject( $articleTitle, 
$rid );
+                       $objs = WOMProcessor::getObjIdByXPath2( $page_obj, 
$xpath );
+
+                       $vals = array();
+                       $first = true;
+                       foreach ( $objs as $id ) {
+                               if ( $id == '' ) continue;
+                               $wobj = $page_obj->getObject( $id );
+
+                               foreach ( $wommaps as $idx => $map ) {
+                                       if ( !$map['setting']['multiple'] && 
!$first ) continue;
+                                       $val = '';
+                                       if ( strtolower( $map['xpath'] ) == 
'innerwiki' ) {
+                                               $val = ( $wobj instanceof 
WikiObjectModelCollection ) ? $wobj->getInnerWikiText() : $wobj->getWikiText();
+                                       } else {
+                                               $xObj = simplexml_load_string( 
$wobj->toXML() );
+                                               $os = $xObj->xpath( 
$map['xpath'] );
+                                               if ( count( $os ) > 0 ) {
+                                                       foreach ( $os as $o ) 
$val .= strval( $o );
+                                               }
+                                       }
+                                       $wommaps[$idx]['value'] .=
+                                               ( $map['setting']['prefix'] ? 
$map['setting']['prefix']:'' ) .
+                                               $val .
+                                               ( $map['setting']['delimiter'] 
? $map['setting']['delimiter']:'' );
+                               }
+                               if ( $first ) $first = false;
+                       }
+               } catch ( Exception $e ) {
+                       $err = $e->getMessage();
+               }
+
+               $result = array();
+               if ( isset( $err ) ) {
+                       $result = array(
+                               'result' => 'Failure',
+                               'message' => array(),
+                       );
+                       if ( defined( 'ApiResult::META_CONTENT' ) ) {
+                               ApiResult::setContentValue( $result['message'], 
'message', $err );
+                       } else {
+                               ApiResult::setContent( $result['message'], $err 
);
+                       }
+               } else {
+                       $result['result'] = 'Success';
+                       $result['revisionID'] = $page_obj->getRevisionID();
+                       foreach ( $wommaps as $map ) {
+                               $this->getMain()->getRequest()->setVal( 
$map['param'], $map['value'] );
+                       }
+                       $this->m_apiInst->profileIn();
+                       $this->m_apiInst->execute();
+                       $this->m_apiInst->profileOut();
+               }
+
+               $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
+       }
+
+       private function parseMapInfo( $mapinfo ) {
+               $wommaps = array();
+               foreach ( explode( '|', str_replace( '||', 
'___PIPEPLACEHOLDER__', $mapinfo ) ) as $map ) {
+                       $s = explode( '=', str_replace( '___PIPEPLACEHOLDER__', 
'|', $map ), 2 );
+                       $settings = array();
+                       $first = true;
+                       $param = '';
+                       foreach ( explode( ',', str_replace( ',,', 
'___DELIMITERPLACEHOLDER__', $s[1] ) ) as $set ) {
+                               $set = str_replace( 
'___DELIMITERPLACEHOLDER__', '|', $set );
+                               if ( $first ) {
+                                       $param = $set;
+                                       $first = false;
+                                       continue;
+                               }
+                               if ( strtolower( $set { 0 } ) == 'm' ) {
+                                       $settings['multiple'] = true;
+                                       $settings['delimiter'] = substr( $set, 
1 );
+                               } elseif ( strtolower( $set { 0 } ) == 'p' ) {
+                                       $settings['prefix'] = substr( $set, 1 );
+                               }
+                       }
+                       $wommaps[] = array(
+                               'xpath' => $s[0],
+                               'param' => $param,
+                               'setting' => $settings,
+                               'value' => ''
+                       );
+               }
+               return $wommaps;
+       }
+
+       protected function getAllowedParams() {
+               // tricky here
+               $mainInst = $this->getMain();
+               $tmp = array_keys( 
$mainInst->getModuleManager()->getNamesWithClasses( 'action' ) );
+               $ids = array(
+                       array_search( 'womset', $tmp ),
+                       array_search( 'womget', $tmp ),
+                       array_search( 'womapi', $tmp ),
+                       array_search( 'womoutput', $tmp ),
+                       array_search( 'womwiki', $tmp ),
+                       array_search( 'womquery', $tmp )
+               );
+               foreach ( $ids as $id ) unset( $tmp[$id] );
+
+               $params = array (
+                       'title' => null,
+                       'xpath' => null,
+                       'rid' => array (
+                               ApiBase :: PARAM_TYPE => 'integer',
+                               ApiBase :: PARAM_DFLT => 0,
+                               ApiBase :: PARAM_MIN => 0
+                       ),
+                       'wommap' => null,
+                       'api' => array(
+                               ApiBase :: PARAM_DFLT => 'help',
+                               ApiBase :: PARAM_TYPE => $tmp
+                       ),
+               );
+
+               $api = $mainInst->getRequest()->getVal( $this->encodeParamName( 
'api' ), 'help' );
+               if ( $api == 'help' ) {
+                       // apply description
+                       $params['...'] = null;
+               } else {
+//                     $mainInst = new ApiMain($mainInst->getRequest());
+                       $modules = 
$mainInst->getModuleManager()->getNamesWithClasses( 'action' );
+                       $this->m_apiInst = new $modules[$api] ( $mainInst, $api 
);
+                       $params = $params + $this->m_apiInst->getFinalParams();
+               }
+
+               return $params;
+       }
+
+       protected function getParamDescription() {
+               return array (
+                       'title' => 'Title of the page to modify',
+                       'xpath' => 'DOM-like xpath to locate WOM object 
instances (http://www.w3schools.com/xpath/xpath_syntax.asp)',
+                       'wommap' => array (
+                               'Settings to map WOM result on parameter(s) of 
api actions',
+                               '"|" as delimiter, to separate map items',
+                               'format: xpath of values=api parameter 
name,other settings',
+                               '    for "|" inside map item, use "||" to 
escape',
+                               '    for "," inside map item, use ",," to 
escape',
+                               '  xpath:',
+                               '    "@property" as property name,',
+                               '    "innerwiki" as wiki text inside xml 
object',
+                               '  settings:',
+                               '    "m<delimiter>", multiple field, if 
multiple flag is not set, always use the first result,',
+                               '    "p<prefix>", prefix',
+                       ),
+                       'api' => 'Api (action) name of common Wiki',
+                       'rid' => 'Revision id of specified page - by dafault 
latest updated revision (0) is used',
+                       '...' => 'standard api parameters',
+               );
+       }
+
+       protected function getDescription() {
+               return 'Call to execute MW apis upon Wiki objects inside title';
+       }
+
+       protected function getExamples() {
+               return array (
+                       
'api.php?action=womapi&title=Somepage&xpath=//template&wommap=@name=titles,m||,ptemplate:&api=query&prop=info'
+               );
+       }
+}
diff --git a/includes/models/WOM_OM_Redirect.php 
b/includes/models/WOM_OM_Redirect.php
index dfc7916..58b720e 100644
--- a/includes/models/WOM_OM_Redirect.php
+++ b/includes/models/WOM_OM_Redirect.php
@@ -1,29 +1,29 @@
-<?php
-/**
- * This model implements redirect models.
- *
- * #REDIRECT [[Pagename]]
- * Consider that #REDIRECT can be localized.
- *
- * @author Ning
- * @file
- * @ingroup WikiObjectModels
- *
- */
-
-class WOMRedirectModel extends WikiObjectModel {
-       private $m_to_page;
-
-       public function __construct( $to_page ) {
-               parent::__construct( WOM_TYPE_REDIRECT );
-               $this->m_to_page = $to_page;
-       }
-
-       public function getWikiText() {
-               return '#REDIRECT [[' . $this->m_to_page . ']]';
-       }
-
-       protected function getXMLContent() {
-               return "<![CDATA[{$this->m_to_page}]]>";
-       }
-}
+<?php
+/**
+ * This model implements redirect models.
+ *
+ * #REDIRECT [[Pagename]]
+ * Consider that #REDIRECT can be localized.
+ *
+ * @author Ning
+ * @file
+ * @ingroup WikiObjectModels
+ *
+ */
+
+class WOMRedirectModel extends WikiObjectModel {
+       private $m_to_page;
+
+       public function __construct( $to_page ) {
+               parent::__construct( WOM_TYPE_REDIRECT );
+               $this->m_to_page = $to_page;
+       }
+
+       public function getWikiText() {
+               return '#REDIRECT [[' . $this->m_to_page . ']]';
+       }
+
+       protected function getXMLContent() {
+               return "<![CDATA[{$this->m_to_page}]]>";
+       }
+}
diff --git a/includes/parsers/WOMAskParser.php 
b/includes/parsers/WOMAskParser.php
index 0abf003..806e499 100644
--- a/includes/parsers/WOMAskParser.php
+++ b/includes/parsers/WOMAskParser.php
@@ -1,67 +1,67 @@
-<?php
-/**
- * @author Ning
- *
- * @file
- * @ingroup WikiObjectModels
- */
-
-class WOMAskParser extends WOMParserFunctionParameterParser {
-
-       public function __construct() {
-               $this->m_parserId = WOM_PFPARSER_ID_ASK;
-       }
-
-       public function getValidModelTypes() {
-               return array(
-                       WOM_TYPE_QUERYSTRING,
-                       WOM_TYPE_QUERYPRINTOUT
-               );
-       }
-
-       private function parseAskParameters ( $text, WikiObjectModelCollection 
$parentObj ) {
-               if ( defined( 'SMW_AGGREGATION_VERSION' ) ) {
-                       $r = preg_match( 
'/^(\s*\?([^>=|}]+)(?:\>([^=|}]*))?(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
-                       if ( !$r ) return null;
-                       return array(
-                               'len' => strlen( $m[5] == '|' ? $m[0] : $m[1] ),
-                               'obj' => new WOMQueryPrintoutModel( trim( $m[2] 
), trim( $m[4] ), trim( $m[3] ) ) );
-               } else {
-                       $r = preg_match( 
'/^(\s*\?([^=|}]+)(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
-                       if ( !$r ) return null;
-                       return array(
-                               'len' => strlen( $m[4] == '|' ? $m[0] : $m[1] ),
-                               'obj' => new WOMQueryPrintoutModel( trim( $m[2] 
), trim( $m[3] ) ) );
-               }
-       }
-
-       public function parseParserFunctionParameter ( $text, 
WikiObjectModelCollection $parentObj ) {
-               if ( !defined( 'SMW_VERSION' )
-                       || !( $parentObj instanceof WOMParserFunctionModel ) )
-                               return null;
-
-               if ( trim( strtolower( $parentObj->getFunctionKey() ) ) != 
'ask' ) return null;
-
-               if ( count ( $parentObj->getObjects() ) == 0 ) {
-                       return array( 'len' => 0, 'obj' => new 
WOMQuerystringModel() );
-               }
-
-               return $this->parseAskParameters( $text, $parentObj );
-       }
-
-       public function getSubParserID( $obj ) {
-               if ( ( $obj instanceof WOMQuerystringModel )
-                       || ( $obj instanceof WOMQueryPrintoutModel ) )
-                               return '';
-
-               return null;
-       }
-
-       public function validate ( $obj ) {
-               if ( !( ( $obj instanceof WOMQuerystringModel )
-                       || ( $obj instanceof WOMQueryPrintoutModel ) ) )
-                               return false;
-
-               return true;
-       }
-}
+<?php
+/**
+ * @author Ning
+ *
+ * @file
+ * @ingroup WikiObjectModels
+ */
+
+class WOMAskParser extends WOMParserFunctionParameterParser {
+
+       public function __construct() {
+               $this->m_parserId = WOM_PFPARSER_ID_ASK;
+       }
+
+       public function getValidModelTypes() {
+               return array(
+                       WOM_TYPE_QUERYSTRING,
+                       WOM_TYPE_QUERYPRINTOUT
+               );
+       }
+
+       private function parseAskParameters ( $text, WikiObjectModelCollection 
$parentObj ) {
+               if ( defined( 'SMW_AGGREGATION_VERSION' ) ) {
+                       $r = preg_match( 
'/^(\s*\?([^>=|}]+)(?:\>([^=|}]*))?(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
+                       if ( !$r ) return null;
+                       return array(
+                               'len' => strlen( $m[5] == '|' ? $m[0] : $m[1] ),
+                               'obj' => new WOMQueryPrintoutModel( trim( $m[2] 
), trim( $m[4] ), trim( $m[3] ) ) );
+               } else {
+                       $r = preg_match( 
'/^(\s*\?([^=|}]+)(?:=([^|}]*))?)(\||\}|$)/', $text, $m );
+                       if ( !$r ) return null;
+                       return array(
+                               'len' => strlen( $m[4] == '|' ? $m[0] : $m[1] ),
+                               'obj' => new WOMQueryPrintoutModel( trim( $m[2] 
), trim( $m[3] ) ) );
+               }
+       }
+
+       public function parseParserFunctionParameter ( $text, 
WikiObjectModelCollection $parentObj ) {
+               if ( !defined( 'SMW_VERSION' )
+                       || !( $parentObj instanceof WOMParserFunctionModel ) )
+                               return null;
+
+               if ( trim( strtolower( $parentObj->getFunctionKey() ) ) != 
'ask' ) return null;
+
+               if ( count ( $parentObj->getObjects() ) == 0 ) {
+                       return array( 'len' => 0, 'obj' => new 
WOMQuerystringModel() );
+               }
+
+               return $this->parseAskParameters( $text, $parentObj );
+       }
+
+       public function getSubParserID( $obj ) {
+               if ( ( $obj instanceof WOMQuerystringModel )
+                       || ( $obj instanceof WOMQueryPrintoutModel ) )
+                               return '';
+
+               return null;
+       }
+
+       public function validate ( $obj ) {
+               if ( !( ( $obj instanceof WOMQuerystringModel )
+                       || ( $obj instanceof WOMQueryPrintoutModel ) ) )
+                               return false;
+
+               return true;
+       }
+}
diff --git a/includes/parsers/WOMParserFunctionParameterParser.php 
b/includes/parsers/WOMParserFunctionParameterParser.php
index af5866a..add2f41 100644
--- a/includes/parsers/WOMParserFunctionParameterParser.php
+++ b/includes/parsers/WOMParserFunctionParameterParser.php
@@ -1,59 +1,59 @@
-<?php
-/**
- * @author Ning
- *
- * @file
- * @ingroup WikiObjectModels
- */
-
-abstract class WOMParserFunctionParameterParser {
-       protected $m_parserId;
-
-       /**
-        * Array of error text messages. Private to allow us to track error 
insertion
-        * (PHP's count() is too slow when called often) by using $mHasErrors.
-        * @var array
-        */
-       protected $mErrors = array();
-
-       /**
-        * Boolean indicating if there where any errors.
-        * Should be modified accordingly when modifying $mErrors.
-        * @var boolean
-        */
-       protected $mHasErrors = false;
-
-// /// Processing methods /////
-       public abstract function parseParserFunctionParameter ( $text, 
WikiObjectModelCollection $parentObj );
-
-       public abstract function validate( $obj );
-
-       public abstract function getValidModelTypes();
-
-// /// Get methods /////
-       public function getParserID() {
-               return $this->m_parserId;
-       }
-
-       // specified next parser. e.g., template parser -> parameter parser
-       public function getSubParserID( $obj ) { return ''; }
-
-       /**
-        * Return a string that displays all error messages as a tooltip, or
-        * an empty string if no errors happened.
-        */
-       public function getErrorText() {
-               if ( defined( 'SMW_VERSION' ) )
-                       return smwfEncodeMessages( $this->mErrors );
-
-               return $this->mErrors;
-       }
-
-       /**
-        * Return an array of error messages, or an empty array
-        * if no errors occurred.
-        */
-       public function getErrors() {
-               return $this->mErrors;
-       }
-}
+<?php
+/**
+ * @author Ning
+ *
+ * @file
+ * @ingroup WikiObjectModels
+ */
+
+abstract class WOMParserFunctionParameterParser {
+       protected $m_parserId;
+
+       /**
+        * Array of error text messages. Private to allow us to track error 
insertion
+        * (PHP's count() is too slow when called often) by using $mHasErrors.
+        * @var array
+        */
+       protected $mErrors = array();
+
+       /**
+        * Boolean indicating if there where any errors.
+        * Should be modified accordingly when modifying $mErrors.
+        * @var boolean
+        */
+       protected $mHasErrors = false;
+
+// /// Processing methods /////
+       public abstract function parseParserFunctionParameter ( $text, 
WikiObjectModelCollection $parentObj );
+
+       public abstract function validate( $obj );
+
+       public abstract function getValidModelTypes();
+
+// /// Get methods /////
+       public function getParserID() {
+               return $this->m_parserId;
+       }
+
+       // specified next parser. e.g., template parser -> parameter parser
+       public function getSubParserID( $obj ) { return ''; }
+
+       /**
+        * Return a string that displays all error messages as a tooltip, or
+        * an empty string if no errors happened.
+        */
+       public function getErrorText() {
+               if ( defined( 'SMW_VERSION' ) )
+                       return smwfEncodeMessages( $this->mErrors );
+
+               return $this->mErrors;
+       }
+
+       /**
+        * Return an array of error messages, or an empty array
+        * if no errors occurred.
+        */
+       public function getErrors() {
+               return $this->mErrors;
+       }
+}
diff --git a/includes/parsers/WOMRedirectParser.php 
b/includes/parsers/WOMRedirectParser.php
index efe7120..90a930a 100644
--- a/includes/parsers/WOMRedirectParser.php
+++ b/includes/parsers/WOMRedirectParser.php
@@ -1,33 +1,33 @@
-<?php
-/**
- * @author Ning
- *
- * @file
- * @ingroup WikiObjectModels
- */
-
-class WOMRedirectParser extends WikiObjectModelParser {
-
-       public function __construct() {
-               parent::__construct();
-               $this->m_parserId = WOM_PARSER_ID_REDIRECT;
-       }
-
-       public function getValidModelTypes() {
-               return array( WOM_TYPE_REDIRECT );
-       }
-
-       public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
-               if ( $offset != 0 ) return null;
-
-               $redirect = MagicWord::get( 'redirect' );
-               if ( !preg_match( '/^\s*(?:' . $redirect->getBaseRegex() . ')/' 
. $redirect->getRegexCase(), $text, $m ) )
-                       return null;
-               $len = strlen( $m[0] );
-               $text = substr( $text, $len );
-               if ( !preg_match( '/^\s*\[\[:?(.*?)(\|(.*?))*\]\]/', $text, $m 
) )
-                       return null;
-
-               return array( 'len' => $len + strlen( $m[0] ), 'obj' => new 
WOMRedirectModel( $m[1] ) );
-       }
-}
+<?php
+/**
+ * @author Ning
+ *
+ * @file
+ * @ingroup WikiObjectModels
+ */
+
+class WOMRedirectParser extends WikiObjectModelParser {
+
+       public function __construct() {
+               parent::__construct();
+               $this->m_parserId = WOM_PARSER_ID_REDIRECT;
+       }
+
+       public function getValidModelTypes() {
+               return array( WOM_TYPE_REDIRECT );
+       }
+
+       public function parseNext( $text, WikiObjectModelCollection $parentObj, 
$offset = 0 ) {
+               if ( $offset != 0 ) return null;
+
+               $redirect = MagicWord::get( 'redirect' );
+               if ( !preg_match( '/^\s*(?:' . $redirect->getBaseRegex() . ')/' 
. $redirect->getRegexCase(), $text, $m ) )
+                       return null;
+               $len = strlen( $m[0] );
+               $text = substr( $text, $len );
+               if ( !preg_match( '/^\s*\[\[:?(.*?)(\|(.*?))*\]\]/', $text, $m 
) )
+                       return null;
+
+               return array( 'len' => $len + strlen( $m[0] ), 'obj' => new 
WOMRedirectModel( $m[1] ) );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5a54ae533838d8ec2bedd87436816d689f2612f3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiObjectModel
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to