r84381 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84380‎ | r84381 | r84382 >
Date:13:41, 20 March 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 16288) API: consider making closure status of wikis more clear with meta=siteinfo

Added bug to RELEASE-NOTES, this adds the hook and usage into SiteMatrix


Have I got my & all right? I can never remember
Modified paths:
  • /trunk/extensions/SiteMatrix/SiteMatrix.php (modified) (history)
  • /trunk/extensions/SiteMatrix/SiteMatrix_body.php (modified) (history)
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -356,8 +356,8 @@
357357
358358 'APIQuerySiteInfoGeneralInfo': use this hook to add extra information to
359359 the sites general information.
360 -$module: the current ApiQuerySiteInfo module
361 -$resutls: array of results, add things here
 360+&$module: the current ApiQuerySiteInfo module
 361+&$results: array of results, add things here
362362
363363 'APIQueryUsersTokens': use this hook to add custom token to list=users.
364364 Every token has an action, which will be used in the ustoken parameter
Index: trunk/phase3/RELEASE-NOTES
@@ -273,6 +273,8 @@
274274 list=users&usprop=groups
275275 * Addition of APIQuerySiteInfoGeneralInfo hook to add extra information to
276276 the general site info results
 277+* (bug 16288) API: consider making closure status of wikis more clear
 278+ with meta=siteinfo
277279
278280 === Languages updated in 1.18 ===
279281
Index: trunk/extensions/SiteMatrix/SiteMatrix.php
@@ -73,3 +73,4 @@
7474 $wgAutoloadClasses['ApiQuerySiteMatrix'] = $dir . 'SiteMatrixApi.php';
7575 $wgAPIModules['sitematrix'] = 'ApiQuerySiteMatrix';
7676
 77+$wgHooks['APIQuerySiteInfoGeneralInfo'][] = 'SiteMatrix::APIQuerySiteInfoGeneralInfo';
\ No newline at end of file
Index: trunk/extensions/SiteMatrix/SiteMatrix_body.php
@@ -149,7 +149,7 @@
150150 return !empty( $this->matrix[$major][$minor] );
151151 }
152152
153 - /**
 153+ /**
154154 * @param string $minor Language
155155 * @param string $major Site
156156 * @return bool
@@ -240,6 +240,45 @@
241241 private function extractFile( $filename ) {
242242 return array_map( 'trim', file( $filename ) );
243243 }
 244+
 245+ /**
 246+ * Handler method for the APISiteInfoGeneralInfo hook
 247+ *
 248+ * @static
 249+ * @param ApiQuerySiteinfo $module
 250+ * @param array $results
 251+ * @return void
 252+ */
 253+ public static function APIQuerySiteInfoGeneralInfo( $module, $results ) {
 254+ global $wgDBname, $wgLanguageCode;
 255+
 256+ $matrix = new SiteMatrix();
 257+
 258+ $db = $wgDBname;
 259+ $lang = $wgLanguageCode;
 260+ if ( strpos( $wgDBname, $wgLanguageCode ) == 0 ) {
 261+ $db = str_replace( $wgLanguageCode, '', $wgDBname );
 262+ $lang = '';
 263+ }
 264+
 265+ if ( $matrix->isClosed( $lang, $db ) ) {
 266+ $results['closed'] = '';
 267+ }
 268+
 269+ if ( $matrix->isSpecial( $wgDBname ) ) {
 270+ $results['special'] = '';
 271+ }
 272+
 273+ if ( $matrix->isPrivate( $wgDBname ) ) {
 274+ $results['private'] = '';
 275+ }
 276+
 277+ if ( $matrix->isFishbowl( $wgDBname ) ) {
 278+ $results['fishbowl'] = '';
 279+ }
 280+
 281+ return true;
 282+ }
244283 }
245284
246285 class SiteMatrixPage extends SpecialPage {

Sign-offs

UserFlagDate
Nikerabbitinspected14:23, 20 March 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r84396Fixup strpos logic, and swap setting of $lang (noticed it's wrong)...reedy16:47, 20 March 2011
r84409Make implementation match documentation and definition. Followup r84381reedy18:33, 20 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84367Add isSpecial method. Likely to be used for bug 16288reedy01:15, 20 March 2011
r84380Addition of 'APIQuerySiteInfoGeneralInfo' hook for usage in bug 16288 "API: c...reedy13:31, 20 March 2011

Comments

#Comment by Nikerabbit (talk | contribs)   14:23, 20 March 2011
+if ( strpos( $wgDBname, $wgLanguageCode ) == 0 ) {

strpos can return false.

> var_dump( false == 0 );
bool(true)

In docs you say that both are passed as &, but yet the function only accepts values?

#Comment by Reedy (talk | contribs)   16:14, 20 March 2011

I thought that putting & on the function hook, it gave those stupid warnings...?

Should the document be listed as it has & or not?

Halp.

Status & tagging log