Call Linker methods statically
[lhc/web/wiklou.git] / includes / api / ApiQuery.php
index df59704..d0803f1 100644 (file)
@@ -49,7 +49,7 @@ class ApiQuery extends ApiBase {
         */
        private $mPageSet;
 
-       private $params, $redirects, $convertTitles;
+       private $params, $redirects, $convertTitles, $iwUrl;
 
        private $mQueryPropModules = array(
                'info' => 'ApiQueryInfo',
@@ -82,7 +82,7 @@ class ApiQuery extends ApiBase {
                'filearchive' => 'ApiQueryFilearchive',
                'imageusage' => 'ApiQueryBacklinks',
                'iwbacklinks' => 'ApiQueryIWBacklinks',
-               'iwlanglinks' => 'ApiQueryLangLinks',
+               'langbacklinks' => 'ApiQueryLangBacklinks',
                'logevents' => 'ApiQueryLogEvents',
                'recentchanges' => 'ApiQueryRecentChanges',
                'search' => 'ApiQuerySearch',
@@ -179,7 +179,7 @@ class ApiQuery extends ApiBase {
 
        /**
         * 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 );
@@ -232,6 +232,7 @@ class ApiQuery extends ApiBase {
                $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 );
@@ -316,9 +317,8 @@ class ApiQuery extends ApiBase {
         * @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 );
                        }
                }
@@ -368,10 +368,15 @@ class ApiQuery extends ApiBase {
                // 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 ) ) {
@@ -381,11 +386,15 @@ class ApiQuery extends ApiBase {
 
                // 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 ) ) {
@@ -481,10 +490,6 @@ class ApiQuery extends ApiBase {
                                }
                        }
                }
-               // only export when there are titles
-               if ( !count( $exportTitles ) ) {
-                       return;
-               }
 
                $exporter = new WikiExporter( $this->getDB() );
                // WikiExporter writes to stdout, so catch its
@@ -587,6 +592,7 @@ class ApiQuery extends ApiBase {
                        'indexpageids' => false,
                        'export' => false,
                        'exportnowrap' => false,
+                       'iwurl' => false,
                );
        }
 
@@ -595,8 +601,6 @@ class ApiQuery extends ApiBase {
         * @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;
@@ -604,7 +608,7 @@ class ApiQuery extends ApiBase {
 
                $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' );
@@ -673,6 +677,7 @@ class ApiQuery extends ApiBase {
                        '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',
                );
        }
 
@@ -690,13 +695,21 @@ class ApiQuery extends ApiBase {
                ) );
        }
 
-       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();