Index: trunk/extensions/MobileFrontend/api/ApiMobileView.php |
— | — | @@ -22,11 +22,15 @@ |
23 | 23 | $sectionProp = array_flip( $params['sectionprop'] ); |
24 | 24 | |
25 | 25 | $title = Title::newFromText( $params['page'] ); |
26 | | - if ( !$title || !$title->exists() || $title->getNamespace() < 0 || !$title->isLocal() ) { |
| 26 | + if ( !$title ) { |
| 27 | + $this->dieUsageMsg( array( 'missingtitle', $params['page'] ) ); |
| 28 | + } |
| 29 | + if ( !$title->exists() ) { |
27 | 30 | $this->dieUsageMsg( array( 'invalidtitle', $params['page'] ) ); |
28 | 31 | } |
29 | 32 | $data = $this->getData( $title, $params['noimages'] ); |
30 | 33 | $result = array(); |
| 34 | + $missingSections = array(); |
31 | 35 | if ( isset( $prop['sections'] ) ) { |
32 | 36 | $requestedSections = array_flip( $requestedSections ); |
33 | 37 | for ( $i = 0; $i <= count( $data['sections'] ); $i++ ) { |
— | — | @@ -37,53 +41,29 @@ |
38 | 42 | $section['id'] = $i; |
39 | 43 | if ( isset( $requestedSections[$i] ) && isset( $data['text'][$i] ) ) { |
40 | 44 | $section[$textElement] = $data['text'][$i]; |
| 45 | + unset( $requestedSections[$i] ); |
41 | 46 | } |
42 | 47 | $result[] = $section; |
43 | 48 | } |
| 49 | + $missingSections = $requestedSections; |
44 | 50 | } else { |
45 | 51 | foreach ( $requestedSections as $index ) { |
46 | 52 | $section = array( 'id' => $index ); |
47 | 53 | if ( isset( $data['text'][$index] ) ) { |
48 | 54 | $section[$textElement] = $data['text'][$index]; |
| 55 | + } else { |
| 56 | + $missingSections[] = $index; |
49 | 57 | } |
50 | 58 | $result[] = $section; |
51 | 59 | } |
52 | 60 | } |
| 61 | + if ( count( $missingSections ) ) { |
| 62 | + $this->setWarning( 'Section(s) ' . implode( ', ', $missingSections ) . ' not found' ); |
| 63 | + } |
53 | 64 | $this->getResult()->setIndexedTagName( $result, 'section' ); |
54 | 65 | $this->getResult()->addValue( null, $this->getModuleName(), array( 'sections' => $result ) ); |
55 | 66 | } |
56 | 67 | |
57 | | - public function getAllowedParams() { |
58 | | - return array( |
59 | | - 'page' => array( |
60 | | - ApiBase::PARAM_REQUIRED => true, |
61 | | - ), |
62 | | - 'section' => null, |
63 | | - 'prop' => array( |
64 | | - ApiBase::PARAM_DFLT => 'text|sections', |
65 | | - ApiBase::PARAM_ISMULTI => true, |
66 | | - ApiBase::PARAM_TYPE => array( |
67 | | - 'text', |
68 | | - 'sections', |
69 | | - ) |
70 | | - ), |
71 | | - 'sectionprop' => array( |
72 | | - ApiBase::PARAM_TYPE => array( |
73 | | - 'toclevel', |
74 | | - 'level', |
75 | | - 'line', |
76 | | - 'number', |
77 | | - 'index', |
78 | | - 'fromtitle', |
79 | | - 'anchor', |
80 | | - ), |
81 | | - ApiBase::PARAM_ISMULTI => true, |
82 | | - ApiBase::PARAM_DFLT => 'toclevel|line', |
83 | | - ), |
84 | | - 'noimages' => false, |
85 | | - ); |
86 | | - } |
87 | | - |
88 | 68 | private function parseSections( $str ) { |
89 | 69 | $sections = array_map( 'intval', explode( '|', $str ) ); |
90 | 70 | return $sections; |
— | — | @@ -133,9 +113,48 @@ |
134 | 114 | return $data; |
135 | 115 | } |
136 | 116 | |
| 117 | + public function getAllowedParams() { |
| 118 | + return array( |
| 119 | + 'page' => array( |
| 120 | + ApiBase::PARAM_REQUIRED => true, |
| 121 | + ), |
| 122 | + 'section' => null, |
| 123 | + 'prop' => array( |
| 124 | + ApiBase::PARAM_DFLT => 'text|sections', |
| 125 | + ApiBase::PARAM_ISMULTI => true, |
| 126 | + ApiBase::PARAM_TYPE => array( |
| 127 | + 'text', |
| 128 | + 'sections', |
| 129 | + ) |
| 130 | + ), |
| 131 | + 'sectionprop' => array( |
| 132 | + ApiBase::PARAM_TYPE => array( |
| 133 | + 'toclevel', |
| 134 | + 'level', |
| 135 | + 'line', |
| 136 | + 'number', |
| 137 | + 'index', |
| 138 | + 'fromtitle', |
| 139 | + 'anchor', |
| 140 | + ), |
| 141 | + ApiBase::PARAM_ISMULTI => true, |
| 142 | + ApiBase::PARAM_DFLT => 'toclevel|line', |
| 143 | + ), |
| 144 | + 'noimages' => false, |
| 145 | + ); |
| 146 | + } |
| 147 | + |
137 | 148 | public function getParamDescription() { |
138 | 149 | return array( |
139 | | - |
| 150 | + 'page' => 'Title of page to process', |
| 151 | + 'section' => 'Pipe-separated list of section numbers for which to return text', |
| 152 | + 'prop' => array( |
| 153 | + 'Which information to get', |
| 154 | + ' text - HTML of selected section(s)', |
| 155 | + ' sections - information about all sections on page', |
| 156 | + ), |
| 157 | + 'sectionprop' => 'What information about sections to get', |
| 158 | + 'noimages' => 'Return HTML without images', |
140 | 159 | ); |
141 | 160 | } |
142 | 161 | |
— | — | @@ -146,7 +165,8 @@ |
147 | 166 | public function getPossibleErrors() { |
148 | 167 | return array_merge( parent::getPossibleErrors(), |
149 | 168 | array( |
150 | | - array( 'code' => 'invalid-section', 'info' => '' ), |
| 169 | + array( 'missingtitle' ), |
| 170 | + array( 'invalidtitle' ), |
151 | 171 | ) |
152 | 172 | ); |
153 | 173 | } |