Index: trunk/phase3/includes/api/ApiQueryPageProps.php |
— | — | @@ -2,9 +2,9 @@ |
3 | 3 | /** |
4 | 4 | * API for MediaWiki 1.8+ |
5 | 5 | * |
6 | | - * Created on Sep 25, 2006 |
| 6 | + * Created on Aug 7, 2010 |
7 | 7 | * |
8 | | - * Copyright © 2010 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 8 | + * Copyright © 2010 soxred93, Bryan Tong Minh |
9 | 9 | * |
10 | 10 | * This program is free software; you can redistribute it and/or modify |
11 | 11 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -44,130 +44,76 @@ |
45 | 45 | |
46 | 46 | public function execute() { |
47 | 47 | $this->params = $this->extractRequestParams(); |
48 | | - |
49 | | - $pageSet = $this->getPageSet(); |
50 | | - $this->titles = $pageSet->getGoodTitles(); |
51 | | - $this->missing = $pageSet->getMissingTitles(); |
52 | | - $this->everything = $this->titles + $this->missing; |
| 48 | + |
| 49 | + $pages = $this->getPageSet()->getGoodTitles(); |
| 50 | + |
| 51 | + $this->addTables( 'page_props' ); |
| 52 | + $this->addFields( array( 'pp_page', 'pp_propname', 'pp_value' ) ); |
| 53 | + $this->addWhereFld( 'pp_page', array_keys( $pages ) ); |
| 54 | + |
| 55 | + if ( $this->params['continue'] ) { |
| 56 | + $this->addWhereFld( 'pp_page >=' . intval( $this->params['continue'] ) ); |
| 57 | + } |
| 58 | + |
| 59 | + $this->addOption( 'ORDER BY', 'pp_page' ); |
| 60 | + |
| 61 | + $res = $this->select( __METHOD__ ); |
| 62 | + $currentPage = 0; |
| 63 | + $props = array(); |
53 | 64 | $result = $this->getResult(); |
54 | | - |
55 | | - uasort( $this->everything, array( 'Title', 'compare' ) ); |
56 | | - if ( !is_null( $this->params['continue'] ) ) { |
57 | | - // Throw away any titles we're gonna skip so they don't |
58 | | - // clutter queries |
59 | | - $cont = explode( '|', $this->params['continue'] ); |
60 | | - if ( count( $cont ) != 2 ) { |
61 | | - $this->dieUsage( 'Invalid continue param. You should pass the original ' . |
62 | | - 'value returned by the previous query', '_badcontinue' ); |
63 | | - } |
64 | | - $conttitle = Title::makeTitleSafe( $cont[0], $cont[1] ); |
65 | | - foreach ( $this->everything as $pageid => $title ) { |
66 | | - if ( Title::compare( $title, $conttitle ) >= 0 ) { |
67 | | - break; |
| 65 | + foreach ( $res as $row ) { |
| 66 | + if ( $currentPage != $row->pp_page ) { |
| 67 | + if ( $currentPage ) { |
| 68 | + if ( !$this->addPageProps( $result, $currentPage, $props ) ) { |
| 69 | + break; |
| 70 | + } |
| 71 | + |
| 72 | + $props = array(); |
| 73 | + } else { |
| 74 | + $currentPage = $row->pp_page; |
68 | 75 | } |
69 | | - unset( $this->titles[$pageid] ); |
70 | | - unset( $this->missing[$pageid] ); |
71 | | - unset( $this->everything[$pageid] ); |
72 | 76 | } |
| 77 | + |
| 78 | + $props[$row->pp_propname] = $row->pp_value; |
73 | 79 | } |
74 | | - |
75 | | - foreach ( $this->everything as $pageid => $title ) { |
76 | | - $pageInfo = $this->extractPageInfo( $pageid, $title, $this->params['prop'] ); |
77 | | - $fit = $result->addValue( array( |
78 | | - 'query', |
79 | | - 'pages' |
80 | | - ), $pageid, $pageInfo ); |
81 | | - if ( !$fit ) { |
82 | | - $this->setContinueEnumParameter( 'continue', |
83 | | - $title->getNamespace() . '|' . |
84 | | - $title->getText() ); |
85 | | - break; |
86 | | - } |
| 80 | + |
| 81 | + if ( count( $props ) ) { |
| 82 | + $this->addPageProps( $result, $currentPage, $props ); |
87 | 83 | } |
88 | 84 | } |
89 | 85 | |
90 | 86 | /** |
91 | | - * Get a result array with information about a title |
92 | | - * @param $pageid int Page ID (negative for missing titles) |
93 | | - * @param $title Title object |
94 | | - * @return array |
| 87 | + * Add page properties to an ApiResult, adding a continue |
| 88 | + * parameter if it doesn't fit. |
| 89 | + * |
| 90 | + * @param $result ApiResult |
| 91 | + * @param $page int |
| 92 | + * @param $props array |
| 93 | + * @return bool True if it fits in the result |
95 | 94 | */ |
96 | | - private function extractPageInfo( $pageid, $title, $prop ) { |
97 | | - global $wgPageProps; |
| 95 | + private function addPageProps( $result, $page, $props ) { |
| 96 | + $fit = $result->addValue( array( 'query', 'pages' ), $page, $props ); |
98 | 97 | |
99 | | - $pageInfo = array(); |
100 | | - if ( $title->exists() ) { |
101 | | - |
102 | | - $dbr = wfGetDB( DB_SLAVE ); |
103 | | - |
104 | | - $res = $dbr->select( |
105 | | - 'page_props', |
106 | | - array( 'pp_propname', 'pp_value' ), |
107 | | - array( 'pp_page' => $pageid ), |
108 | | - __METHOD__ |
109 | | - ); |
110 | | - |
111 | | - foreach( $res as $row ) { |
112 | | - if( isset( $wgPageProps[$row->pp_propname] ) ) { |
113 | | - if( !is_null( $prop ) && !in_array( $row->pp_propname, $prop ) ) { |
114 | | - continue; |
115 | | - } |
116 | | - $pageInfo[$row->pp_propname] = $row->pp_value; |
117 | | - } |
118 | | - } |
119 | | - |
| 98 | + if ( !$fit ) { |
| 99 | + $this->setContinueEnumParameter( 'continue', $page ); |
120 | 100 | } |
121 | | - |
122 | | - return $pageInfo; |
| 101 | + return $fit; |
123 | 102 | } |
124 | 103 | |
125 | 104 | public function getCacheMode( $params ) { |
126 | 105 | return 'public'; |
127 | 106 | } |
128 | 107 | |
129 | | - public function getAllowedParams() { |
130 | | - global $wgPageProps; |
131 | | - |
132 | | - return array( |
133 | | - 'prop' => array( |
134 | | - ApiBase::PARAM_DFLT => null, |
135 | | - ApiBase::PARAM_ISMULTI => true, |
136 | | - ApiBase::PARAM_TYPE => array_keys( $wgPageProps ) |
137 | | - ), |
138 | | - 'continue' => null, |
139 | | - ); |
| 108 | + public function getAllowedParams() { |
| 109 | + return array( 'continue' => null ); |
140 | 110 | } |
141 | 111 | |
142 | 112 | public function getParamDescription() { |
143 | | - global $wgPageProps; |
144 | | - |
145 | | - $ret = array( |
146 | | - 'prop' => array( |
147 | | - 'Which additional properties to get:', |
148 | | - ), |
149 | | - 'continue' => 'When more results are available, use this to continue', |
150 | | - ); |
151 | | - |
152 | | - //This mess of code first gets the length of the biggest propname, and adds two onto it to make |
153 | | - //the number of characters should be used before the dash. If the biggest propname is shorter than 12 characters, |
154 | | - //the number of characters before the dash become 14. |
155 | | - $maxLen = max( array_map( 'strlen', array_keys( $wgPageProps ) ) ); |
156 | | - $matchLen = $maxLen + 2; |
157 | | - if( $maxLen < 12 ) { |
158 | | - $matchLen = 14; |
159 | | - } |
160 | | - |
161 | | - foreach( $wgPageProps as $propName => $desc ) { |
162 | | - $pretext = " $propName" . str_repeat( ' ', $matchLen - strlen( $propName ) ); |
163 | | - |
164 | | - $ret['prop'][] = "$pretext- $desc"; |
165 | | - } |
166 | | - |
167 | | - return $ret; |
| 113 | + return array( 'continue' => 'When more results are available, use this to continue' ); |
168 | 114 | } |
169 | 115 | |
170 | 116 | public function getDescription() { |
171 | | - return 'Get various properties about a page...'; |
| 117 | + return 'Get various properties defined in the page content'; |
172 | 118 | } |
173 | 119 | |
174 | 120 | public function getPossibleErrors() { |
Property changes on: trunk/phase3/includes/api/ApiQueryPageProps.php |
___________________________________________________________________ |
Deleted: keywords |
175 | 121 | - Id |
Added: svn:keywords |
176 | 122 | + id |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -4396,17 +4396,6 @@ |
4397 | 4397 | */ |
4398 | 4398 | $wgExceptionHooks = array(); |
4399 | 4399 | |
4400 | | -/** |
4401 | | - * List of page property names and descriptions of what they are. |
4402 | | - * This is used for the API prop=pageprops module to know which |
4403 | | - * page props to search for. The help message is only seen from |
4404 | | - * the API help page. |
4405 | | - */ |
4406 | | -$wgPageProps = array( |
4407 | | - 'displaytitle' => 'Value of the {{DISPLAYTITLE}} tag', |
4408 | | - 'defaultsort' => 'Value of the {{DEFAULTSORT}} tag', |
4409 | | - 'hiddencat' => 'Whether or not the page has a category with the __HIDDENCAT__ magic word', |
4410 | | -); |
4411 | 4400 | |
4412 | 4401 | /** |
4413 | 4402 | * Page property link table invalidation lists. When a page property |