Index: trunk/phase3/includes/api/ApiQueryQuerypage.php |
— | — | @@ -35,7 +35,10 @@ |
36 | 36 | */ |
37 | 37 | class ApiQueryQuerypage extends ApiQueryBase { |
38 | 38 | static $queryPages = array( |
39 | | - 'brokenredirects' => 'BrokenRedirectsPage' |
| 39 | + 'ancientpages' => 'AncientPagesPage', |
| 40 | + 'brokenredirects' => 'BrokenRedirectsPage', |
| 41 | + 'deadendpages' => 'DeadendPagesPage', |
| 42 | + 'disambiguations' => 'DisambiguationsPage', |
40 | 43 | ); |
41 | 44 | |
42 | 45 | public function __construct($query, $moduleName) { |
— | — | @@ -56,31 +59,35 @@ |
57 | 60 | $limit = $params['limit']; |
58 | 61 | |
59 | 62 | // Try to find an entry in $wgQueryPages |
60 | | - $qpName = $params['querypage']; |
61 | | - if ( is_null( $qpName ) ) |
| 63 | + $name = $params['querypage']; |
| 64 | + if ( is_null( $name ) ) |
62 | 65 | $this->dieUsageMsg( array( 'missingparam', 'querypage' ) ); |
63 | | - if ( !isset( self::$queryPages[$qpName] ) ) |
| 66 | + if ( !isset( self::$queryPages[$name] ) ) |
64 | 67 | $this->dieUsage( 'Querypage unrecognized', 'unknownquerypage' ); |
65 | 68 | |
66 | | - $qpClass = self::$queryPages[$qpName]; |
67 | | - $qpInstance = new $qpClass; |
68 | | - $result = $qpInstance->reallyDoQuery( $offset, $limit + 1 ); |
| 69 | + // Get the result from the query page |
| 70 | + $class = self::$queryPages[$name]; |
| 71 | + $queryPage = new $class; |
| 72 | + $result = $queryPage->reallyDoQuery( $offset, $limit + 1 ); |
69 | 73 | |
| 74 | + // Output the result |
70 | 75 | $apiResult = $this->getResult(); |
| 76 | + $resultPath = array( 'query', $this->getModuleName() ); |
71 | 77 | $count = 0; |
72 | 78 | while ( $row = $result['dbr']->fetchObject( $result['result'] ) ) { |
73 | 79 | if ( ++ $count > $limit ) { |
74 | 80 | // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
75 | 81 | $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); |
76 | 82 | break; |
77 | | - } |
| 83 | + } |
| 84 | + |
78 | 85 | if ( is_null( $resultPageSet ) ) { |
79 | 86 | // Normal mode; let the query page make a sensible result out of it |
80 | | - $vals = $qpInstance->formatApiResult( $row ); |
81 | | - $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
| 87 | + $vals = $queryPage->formatApiResult( $row ); |
| 88 | + $fit = $apiResult->addValue( $resultPath, null, $vals ); |
82 | 89 | if( !$fit ) |
83 | 90 | { |
84 | | - $this->setContinueEnumParameter( 'offset', $params['offset'] + $count ); |
| 91 | + $this->setContinueEnumParameter( 'offset', $offset + $count ); |
85 | 92 | break; |
86 | 93 | } |
87 | 94 | } else { |
— | — | @@ -88,15 +95,25 @@ |
89 | 96 | $resultPageSet->processDbRow( $row ); |
90 | 97 | } |
91 | 98 | } |
92 | | - |
93 | | - |
| 99 | + // Set XML element to 'p' |
94 | 100 | if ( is_null( $resultPageSet ) ) { |
95 | 101 | $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName()), 'p' ); |
| 102 | + } |
| 103 | + |
| 104 | + // Set meta information |
| 105 | + if ( $result['cached'] ) { |
| 106 | + // Set cached date if available, else simply true |
| 107 | + $apiResult->addValue( $resultPath, 'cached', |
| 108 | + $result === true ? true : wfTimestamp( TS_ISO_8601, $result['cached'] ) ); |
96 | 109 | } |
| 110 | + if ( $result['disabled'] ) |
| 111 | + // No further updates will be performed |
| 112 | + $apiResult->addValue( $resultPath, 'disabled', true ); |
| 113 | + |
| 114 | + |
97 | 115 | } |
98 | 116 | |
99 | 117 | public function getAllowedParams() { |
100 | | - |
101 | 118 | return array ( |
102 | 119 | 'offset' => 0, |
103 | 120 | 'limit' => array ( |
Index: trunk/phase3/includes/specials/SpecialDisambiguations.php |
— | — | @@ -94,6 +94,12 @@ |
95 | 95 | |
96 | 96 | return "$from $edit $arr $to"; |
97 | 97 | } |
| 98 | + function formatApiResult( $row ) { |
| 99 | + $linkTo = Title::makeTitle( NS_MAIN, $row->value ); |
| 100 | + $result = parent::formatApiResult( $row ); |
| 101 | + $result['to'] = $linkTo->getPrefixedText(); |
| 102 | + return $result; |
| 103 | + } |
98 | 104 | } |
99 | 105 | |
100 | 106 | /** |
Index: trunk/phase3/includes/specials/SpecialAncientpages.php |
— | — | @@ -62,6 +62,10 @@ |
63 | 63 | ); |
64 | 64 | return wfSpecialList($link, htmlspecialchars($d) ); |
65 | 65 | } |
| 66 | + function formatApiResult( $row ) { |
| 67 | + $result = parent::formatApiResult( $row ); |
| 68 | + $result['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value ); |
| 69 | + } |
66 | 70 | } |
67 | 71 | |
68 | 72 | function wfSpecialAncientpages() { |
Index: trunk/phase3/includes/QueryPage.php |
— | — | @@ -179,9 +179,8 @@ |
180 | 180 | function formatApiResult( $row ) { |
181 | 181 | $title = Title::makeTitle( $row->namespace, $row->title ); |
182 | 182 | return array( |
183 | | - //'pageid' => intval( $row->id ), |
184 | | - 'ns' => intval( $title->getNamespace() ), |
185 | | - 'title' => $title->getPrefixedText(), |
| 183 | + 'ns' => intval( $title->getNamespace() ), |
| 184 | + 'title' => $title->getPrefixedText(), |
186 | 185 | ); |
187 | 186 | } |
188 | 187 | |