https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113236

Revision: 113236
Author:   maxsem
Date:     2012-03-07 15:21:12 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
Fixed data generation, sectionprop support

Modified Paths:
--------------
    trunk/extensions/MobileFrontend/api/ApiMobileView.php

Modified: trunk/extensions/MobileFrontend/api/ApiMobileView.php
===================================================================
--- trunk/extensions/MobileFrontend/api/ApiMobileView.php       2012-03-07 
15:14:48 UTC (rev 113235)
+++ trunk/extensions/MobileFrontend/api/ApiMobileView.php       2012-03-07 
15:21:12 UTC (rev 113236)
@@ -19,27 +19,28 @@
                        ? $this->parseSections( $params['section'] )
                        : array();
                $prop = array_flip( $params['prop'] );
-               $sectionProp = $prop['sectionprop'];
+               $sectionProp = array_flip( $params['sectionprop'] );
 
                $title = Title::newFromText( $params['page'] );
-               if ( !$title || !$title->exists() ) {
-                       $this->dieUsage( "Page `$page' does not exist", 
'nopage' );
+               if ( !$title || !$title->exists() || $title->getNamespace() < 0 
|| !$title->isLocal() ) {
+                       $this->dieUsageMsg( array( 'invalidtitle', 
$params['page'] ) );
                }
-               if ( $title->getNamespace() < 0 || !$title->isLocal() ) {
-                       $this->dieUsage($description, $errorCode);
-               }
                $data = $this->getData( $title, $params['noimages'] );
+               $result = array();
                if ( isset( $prop['sections'] ) ) {
                        $requestedSections = array_flip( $requestedSections );
-                       $result = $data['sections'];
-                       for ( $i = 0; $i < count( $data['sections'] ); $i++ ) {
-                               $result[$i]['id'] = $i;
+                       for ( $i = 0; $i <= count( $data['sections'] ); $i++ ) {
+                               $section = array();
+                               if ( $i > 0 ) {
+                                       $section = array_intersect_key( 
$data['sections'][$i - 1], $sectionProp );
+                               }
+                               $section['id'] = $i;
                                if ( isset( $requestedSections[$i] ) && isset( 
$data['text'][$i] ) ) {
-                                       $result[$i][$textElement] = 
$data['text'][$i];
+                                       $section[$textElement] = 
$data['text'][$i];
                                }
+                               $result[] = $section;
                        }
                } else {
-                       $result = array();
                        foreach ( $requestedSections as $index ) {
                                $section = array( 'id' => $index );
                                if ( isset( $data['text'][$index] ) ) {


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

Reply via email to