Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -362,6 +362,13 @@ |
363 | 363 | $tokenFunctions array and return true (returning false makes no sense) |
364 | 364 | $tokenFunctions: array(action => callback) |
365 | 365 | |
| 366 | +'ApiRsdServiceApis': Add or remove APIs from the RSD services list. |
| 367 | +Each service should have its own entry in the $apis array and have a |
| 368 | +unique name, passed as key for the array that represents the service data. |
| 369 | +In this data array, the key-value-pair identified by the apiLink key is |
| 370 | +required. |
| 371 | +&$apis: array of services |
| 372 | + |
366 | 373 | 'ArticleAfterFetchContent': after fetching content of an article from |
367 | 374 | the database |
368 | 375 | $article: the article (object) being loaded from the database |
Index: trunk/phase3/includes/api/ApiRsd.php |
— | — | @@ -0,0 +1,183 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API for MediaWiki 1.17+ |
| 6 | + * |
| 7 | + * Created on October 26, 2010 |
| 8 | + * |
| 9 | + * Copyright © 2010 Bryan Tong Minh and Brion Vibber |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License along |
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + * |
| 26 | + * @file |
| 27 | + */ |
| 28 | + |
| 29 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 30 | + require_once( 'ApiBase.php' ); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * API interface for page purging |
| 35 | + * @ingroup API |
| 36 | + */ |
| 37 | +class ApiRsd extends ApiBase { |
| 38 | + |
| 39 | + public function __construct( $main, $action ) { |
| 40 | + parent::__construct( $main, $action ); |
| 41 | + } |
| 42 | + |
| 43 | + public function execute() { |
| 44 | + $result = $this->getResult(); |
| 45 | + |
| 46 | + |
| 47 | + $result->addValue( null, 'version', '1.0' ); |
| 48 | + $result->addValue( null, 'xmlns', 'http://archipelago.phrasewise.com/rsd' ); |
| 49 | + |
| 50 | + $service = array( |
| 51 | + 'engineName' => array( |
| 52 | + '*' => 'MediaWiki' |
| 53 | + ), |
| 54 | + 'engineLink' => array( |
| 55 | + '*' => 'http://www.mediawiki.org/' |
| 56 | + ), |
| 57 | + 'apis' => $this->formatRsdApiList() |
| 58 | + ); |
| 59 | + |
| 60 | + $result->setIndexedTagName( $service['apis'], 'api' ); |
| 61 | + |
| 62 | + $result->addValue( null, 'service', $service ); |
| 63 | + } |
| 64 | + |
| 65 | + public function getCustomPrinter() { |
| 66 | + return new ApiFormatXmlRsd( $this->getMain(), 'xml' ); |
| 67 | + } |
| 68 | + |
| 69 | + public function getAllowedParams() { |
| 70 | + return array(); |
| 71 | + } |
| 72 | + |
| 73 | + public function getParamDescription() { |
| 74 | + return array(); |
| 75 | + } |
| 76 | + |
| 77 | + public function getDescription() { |
| 78 | + return 'Export an RSD schema'; |
| 79 | + } |
| 80 | + |
| 81 | + protected function getExamples() { |
| 82 | + return array( |
| 83 | + 'api.php?action=rsd' |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Builds an internal list of APIs to expose information about. |
| 89 | + * Normally this only lists the MediaWiki API, with its base URL, |
| 90 | + * link to documentation, and a marker as to available authentication |
| 91 | + * (to aid in OAuth client apps switching to support in the future). |
| 92 | + * |
| 93 | + * Extensions can expose other APIs, such as WordPress or Twitter- |
| 94 | + * compatible APIs, by hooking 'ApiRsdServiceApis' and adding more |
| 95 | + * elements to the array. |
| 96 | + * |
| 97 | + * See http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html for |
| 98 | + * the base RSD spec, and check WordPress and StatusNet sites for |
| 99 | + * in-production examples listing several blogging and micrblogging |
| 100 | + * APIs. |
| 101 | + * |
| 102 | + * @return array |
| 103 | + */ |
| 104 | + protected function getRsdApiList() { |
| 105 | + $apis = array( |
| 106 | + 'MediaWiki' => array( |
| 107 | + // The API link is required for all RSD API entries. |
| 108 | + 'apiLink' => wfExpandUrl( wfScript( 'api' ) ), |
| 109 | + |
| 110 | + // Docs link is optional, but recommended. |
| 111 | + 'docs' => 'http://mediawiki.org/wiki/API', |
| 112 | + |
| 113 | + // Some APIs may need a blog ID, but it may be left blank. |
| 114 | + 'blogID' => '', |
| 115 | + |
| 116 | + // Additional settings are optional. |
| 117 | + 'settings' => array( |
| 118 | + // Change this to true in the future as an aid to |
| 119 | + // machine discovery of OAuth for API access. |
| 120 | + 'OAuth' => false, |
| 121 | + ) |
| 122 | + ), |
| 123 | + ); |
| 124 | + wfRunHooks( 'ApiRsdServiceApis', array( &$apis ) ); |
| 125 | + return $apis; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Formats the internal list of exposed APIs into an array suitable |
| 130 | + * to pass to the API's XML formatter. |
| 131 | + * |
| 132 | + * @return array |
| 133 | + */ |
| 134 | + protected function formatRsdApiList() { |
| 135 | + $apis = $this->getRsdApiList(); |
| 136 | + |
| 137 | + $outputData = array(); |
| 138 | + foreach ( $apis as $name => $info ) { |
| 139 | + $data = array( |
| 140 | + 'name' => $name, |
| 141 | + 'preferred' => wfBoolToStr( $name == 'MediaWiki' ), |
| 142 | + 'apiLink' => $info['apiLink'], |
| 143 | + 'blogID' => isset( $info['blogID'] ) ? $info['blogID'] : '' |
| 144 | + ); |
| 145 | + if ( isset( $info['docs'] ) ) { |
| 146 | + $data['settings']['docs'] = array( |
| 147 | + '*' => $info['docs'], |
| 148 | + ); |
| 149 | + } |
| 150 | + if ( isset( $info['settings'] ) ) { |
| 151 | + foreach ( $info['settings'] as $setting => $val ) { |
| 152 | + if ( is_bool( $val ) ) { |
| 153 | + $xmlVal = wfBoolToStr( $val ); |
| 154 | + } else { |
| 155 | + $xmlVal = $val; |
| 156 | + } |
| 157 | + $data['settings'][] = array( |
| 158 | + 'name' => $setting, |
| 159 | + '*' => $xmlVal, |
| 160 | + ); |
| 161 | + } |
| 162 | + } |
| 163 | + if ( isset( $data['settings'] ) ) { |
| 164 | + $data['settings']['_element'] = 'setting'; |
| 165 | + } |
| 166 | + $outputData[] = $data; |
| 167 | + } |
| 168 | + return $outputData; |
| 169 | + } |
| 170 | + public function getVersion() { |
| 171 | + return __CLASS__ . ': $Id$'; |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +class ApiFormatXmlRsd extends ApiFormatXml { |
| 176 | + public function __construct( $main, $format ) { |
| 177 | + parent::__construct( $main, $format ); |
| 178 | + $this->setRootElement( 'rsd' ); |
| 179 | + } |
| 180 | + |
| 181 | + public function getMimeType() { |
| 182 | + return 'application/rsd+xml'; |
| 183 | + } |
| 184 | +} |
Property changes on: trunk/phase3/includes/api/ApiRsd.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 185 | + native |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | 'feedwatchlist' => 'ApiFeedWatchlist', |
65 | 65 | 'help' => 'ApiHelp', |
66 | 66 | 'paraminfo' => 'ApiParamInfo', |
| 67 | + 'rsd' => 'ApiRsd', |
67 | 68 | |
68 | 69 | // Write modules |
69 | 70 | 'purge' => 'ApiPurge', |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -216,6 +216,16 @@ |
217 | 217 | 'title' => wfMsgForContent( 'opensearch-desc' ), |
218 | 218 | ) ); |
219 | 219 | |
| 220 | + # Real Simple Discovery link, provides auto-discovery information |
| 221 | + # for the MediaWiki API (and potentially additional custom API |
| 222 | + # support such as WordPress or Twitter-compatible APIs for a |
| 223 | + # blogging extension, etc) |
| 224 | + $out->addLink( array( |
| 225 | + 'rel' => 'EditURI', |
| 226 | + 'type' => 'application/rsd+xml', |
| 227 | + 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ), |
| 228 | + ) ); |
| 229 | + |
220 | 230 | $this->addMetadataLinks( $out ); |
221 | 231 | |
222 | 232 | $this->mRevisionId = $out->mRevisionId; |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -297,6 +297,7 @@ |
298 | 298 | 'ApiPatrol' => 'includes/api/ApiPatrol.php', |
299 | 299 | 'ApiProtect' => 'includes/api/ApiProtect.php', |
300 | 300 | 'ApiPurge' => 'includes/api/ApiPurge.php', |
| 301 | + 'ApiRsd' => 'includes/api/ApiRsd.php', |
301 | 302 | 'ApiQuery' => 'includes/api/ApiQuery.php', |
302 | 303 | 'ApiQueryAllCategories' => 'includes/api/ApiQueryAllCategories.php', |
303 | 304 | 'ApiQueryAllimages' => 'includes/api/ApiQueryAllimages.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -455,6 +455,10 @@ |
456 | 456 | id, try the parser cache, and save it to it if necessary |
457 | 457 | * (bug 25463) Export header should not be shown if no pages were requested, to |
458 | 458 | reduce confusion |
| 459 | +* (bug 25648) API discovery information has been added as RSD link in page |
| 460 | + <head> and by providing an API module action=rsd. Added hook |
| 461 | + ApiRsdServiceApis for extensions to add their own service to the services |
| 462 | + list. |
459 | 463 | |
460 | 464 | === Languages updated in 1.17 === |
461 | 465 | |