r113236 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113235‎ | r113236 | r113237 >
Date:15:21, 7 March 2012
Author:maxsem
Status:ok
Tags:
Comment:
Fixed data generation, sectionprop support
Modified paths:
  • /trunk/extensions/MobileFrontend/api/ApiMobileView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/api/ApiMobileView.php
@@ -19,27 +19,28 @@
2020 ? $this->parseSections( $params['section'] )
2121 : array();
2222 $prop = array_flip( $params['prop'] );
23 - $sectionProp = $prop['sectionprop'];
 23+ $sectionProp = array_flip( $params['sectionprop'] );
2424
2525 $title = Title::newFromText( $params['page'] );
26 - if ( !$title || !$title->exists() ) {
27 - $this->dieUsage( "Page `$page' does not exist", 'nopage' );
 26+ if ( !$title || !$title->exists() || $title->getNamespace() < 0 || !$title->isLocal() ) {
 27+ $this->dieUsageMsg( array( 'invalidtitle', $params['page'] ) );
2828 }
29 - if ( $title->getNamespace() < 0 || !$title->isLocal() ) {
30 - $this->dieUsage($description, $errorCode);
31 - }
3229 $data = $this->getData( $title, $params['noimages'] );
 30+ $result = array();
3331 if ( isset( $prop['sections'] ) ) {
3432 $requestedSections = array_flip( $requestedSections );
35 - $result = $data['sections'];
36 - for ( $i = 0; $i < count( $data['sections'] ); $i++ ) {
37 - $result[$i]['id'] = $i;
 33+ for ( $i = 0; $i <= count( $data['sections'] ); $i++ ) {
 34+ $section = array();
 35+ if ( $i > 0 ) {
 36+ $section = array_intersect_key( $data['sections'][$i - 1], $sectionProp );
 37+ }
 38+ $section['id'] = $i;
3839 if ( isset( $requestedSections[$i] ) && isset( $data['text'][$i] ) ) {
39 - $result[$i][$textElement] = $data['text'][$i];
 40+ $section[$textElement] = $data['text'][$i];
4041 }
 42+ $result[] = $section;
4143 }
4244 } else {
43 - $result = array();
4445 foreach ( $requestedSections as $index ) {
4546 $section = array( 'id' => $index );
4647 if ( isset( $data['text'][$index] ) ) {

Status & tagging log