*/
private $mPageSet;
- private $params, $redirects, $convertTitles;
+ private $params, $redirects, $convertTitles, $iwUrl;
private $mQueryPropModules = array(
'info' => 'ApiQueryInfo',
/**
* Get the array mapping module names to class names
- * @return array(modulename => classname)
+ * @return array array(modulename => classname)
*/
function getModules() {
return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
$this->params = $this->extractRequestParams();
$this->redirects = $this->params['redirects'];
$this->convertTitles = $this->params['converttitles'];
+ $this->iwUrl = $this->params['iwurl'];
// Create PageSet
$this->mPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
* @param $moduleList Array array(modulename => classname)
*/
private function instantiateModules( &$modules, $param, $moduleList ) {
- $list = @$this->params[$param];
- if ( !is_null ( $list ) ) {
- foreach ( $list as $moduleName ) {
+ if ( isset( $this->params[$param] ) ) {
+ foreach ( $this->params[$param] as $moduleName ) {
$modules[] = new $moduleList[$moduleName] ( $this, $moduleName );
}
}
// Interwiki titles
$intrwValues = array();
foreach ( $pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
- $intrwValues[] = array(
+ $item = array(
'title' => $rawTitleStr,
- 'iw' => $interwikiStr
+ 'iw' => $interwikiStr,
);
+ if ( $this->iwUrl ) {
+ $title = Title::newFromText( $rawTitleStr );
+ $item['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
+ }
+ $intrwValues[] = $item;
}
if ( count( $intrwValues ) ) {
// Show redirect information
$redirValues = array();
- foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleStrTo ) {
- $redirValues[] = array(
+ foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleTo ) {
+ $r = array(
'from' => strval( $titleStrFrom ),
- 'to' => $titleStrTo
+ 'to' => $titleTo->getPrefixedText(),
);
+ if ( $titleTo->getFragment() !== '' ) {
+ $r['tofragment'] = $titleTo->getFragment();
+ }
+ $redirValues[] = $r;
}
if ( count( $redirValues ) ) {
}
}
}
- // only export when there are titles
- if ( !count( $exportTitles ) ) {
- return;
- }
$exporter = new WikiExporter( $this->getDB() );
// WikiExporter writes to stdout, so catch its
'indexpageids' => false,
'export' => false,
'exportnowrap' => false,
+ 'iwurl' => false,
);
}
* @return string
*/
public function makeHelpMsg() {
- $msg = '';
-
// Make sure the internal object is empty
// (just in case a sub-module decides to optimize during instantiation)
$this->mPageSet = null;
$querySeparator = str_repeat( '--- ', 12 );
$moduleSeparator = str_repeat( '*** ', 14 );
- $msg .= "\n$querySeparator Query: Prop $querySeparator\n\n";
+ $msg = "\n$querySeparator Query: Prop $querySeparator\n\n";
$msg .= $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
$msg .= "\n$querySeparator Query: List $querySeparator\n\n";
$msg .= $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
'export' => 'Export the current revisions of all given or generated pages',
'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',
+ 'iwurl' => 'Whether to get the full URL if the title is an interwiki link',
);
}
) );
}
- protected function getExamples() {
+ public function getExamples() {
return array(
'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment',
'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions',
);
}
+ public function getHelpUrls() {
+ return array(
+ 'http://www.mediawiki.org/wiki/API:Meta',
+ 'http://www.mediawiki.org/wiki/API:Properties',
+ 'http://www.mediawiki.org/wiki/API:Lists',
+ );
+ }
+
public function getVersion() {
$psModule = new ApiPageSet( $this );
$vers = array();