From 5fb49ecb127fc8af6ff8e314800076b204852a6d Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 30 Jul 2008 07:46:25 +0000 Subject: [PATCH] Add new parser function {{apiurl}}. Also, add new global $wgApiScript because manually constructing the api script's path seemed like a bad idea. --- RELEASE-NOTES | 5 +++++ includes/DefaultSettings.php | 1 + includes/Setup.php | 1 + includes/parser/CoreParserFunctions.php | 14 ++++++++++++++ languages/messages/MessagesEn.php | 1 + 5 files changed, 22 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f2a62091eb..aac2744609 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -25,6 +25,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN empt all content namespaces.) * $wgForwardSearchUrl has been removed entirely. Documented setting since 1.4 has been $wgSearchForwardUrl. +* $wgApiScript can now be defined if your API isn't named api.php or it's not + in the usual location. Setting to false defaults to "$wgScriptPath/api + $wgScriptExtension". === New features in 1.14 === @@ -36,6 +39,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN 'EditSectionLinkForOther' hook has been removed, but 'EditSectionLink' is run in all cases instead, so extensions using the old hooks should still work if they ran roughly the same code for both hooks (as is almost certain). +* New parser function {{apiurl:}} links to the local API. {{apiurl:help}} would + link to action=help. Other params are passed as well. === Bug fixes in 1.14 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e50f662b70..127b81dace 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -166,6 +166,7 @@ $wgMathPath = false; ///< defaults to "{$wgUploadPath}/math" $wgMathDirectory = false; ///< defaults to "{$wgUploadDirectory}/math" $wgTmpDirectory = false; ///< defaults to "{$wgUploadDirectory}/tmp" $wgUploadBaseUrl = ""; +$wgApiScript = false; ///< defaults to "{$wgScriptPath}/api{$wgScriptExtension}" /**@}*/ /** diff --git a/includes/Setup.php b/includes/Setup.php index cf8aa9b922..5d3322b24f 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -53,6 +53,7 @@ if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp"; if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR"; if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache"; +if( $wgApiScript == false ) $wgApiScript = "$wgScriptPath/api$wgScriptExtension"; if ( empty( $wgFileStore['deleted']['directory'] ) ) { $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted"; diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index cce00ab32c..90a33c1e9f 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -25,6 +25,7 @@ class CoreParserFunctions { $parser->setFunctionHook( 'localurle', array( __CLASS__, 'localurle' ), SFH_NO_HASH ); $parser->setFunctionHook( 'fullurl', array( __CLASS__, 'fullurl' ), SFH_NO_HASH ); $parser->setFunctionHook( 'fullurle', array( __CLASS__, 'fullurle' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'apiurl', array( __CLASS__, 'apiurl' ), SFH_NO_HASH ); $parser->setFunctionHook( 'formatnum', array( __CLASS__, 'formatnum' ), SFH_NO_HASH ); $parser->setFunctionHook( 'grammar', array( __CLASS__, 'grammar' ), SFH_NO_HASH ); $parser->setFunctionHook( 'plural', array( __CLASS__, 'plural' ), SFH_NO_HASH ); @@ -119,6 +120,19 @@ class CoreParserFunctions { static function localurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeLocalURL', $s, $arg ); } static function fullurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getFullURL', $s, $arg ); } static function fullurle( $parser, $s = '', $arg = null ) { return self::urlFunction( 'escapeFullURL', $s, $arg ); } + static function apiurl( $parser, $s = '', $arg = null ) { + global $wgEnableApi; + # Don't bother linking to the API if they can't use it. + if ( $wgEnableApi === false ) { + return array( 'found' => false ); + } + global $wgServer, $wgApiScript; + $path = $wgServer . $wgApiScript . '?action=' . $s; + if ( !is_null($arg ) ) { + $path .= '&' . $arg; + } + return $path; + } static function urlFunction( $func, $s = '', $arg = null ) { $title = Title::newFromText( $s ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 487217f05b..6768f1f873 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -312,6 +312,7 @@ $magicWords = array( 'plural' => array( 0, 'PLURAL:' ), 'fullurl' => array( 0, 'FULLURL:' ), 'fullurle' => array( 0, 'FULLURLE:' ), + 'apiurl' => array( 0, 'APIURL:' ), 'lcfirst' => array( 0, 'LCFIRST:' ), 'ucfirst' => array( 0, 'UCFIRST:' ), 'lc' => array( 0, 'LC:' ), -- 2.20.1