From 96b2c66e242954d8591e7b8ca7b9d6a2a4e1074a Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Fri, 11 Oct 2013 21:13:40 +0000 Subject: [PATCH] Include short descriptions for extensions bundled in the release Also fix styling for the list of extensions. Bug: 43817 Change-Id: I5335225683ec8f1c163bb67f478787ebc52ee3a9 --- includes/cache/LinkCache.php | 18 +++ includes/cache/LocalisationCache.php | 19 +++ includes/installer/Installer.php | 38 ++++- includes/installer/LocalSettingsGenerator.php | 13 +- includes/installer/WebInstaller.php | 4 +- includes/installer/WebInstallerPage.php | 27 +++- includes/parser/LinkHolderArray.php | 138 +++++++++--------- skins/common/config.css | 8 +- 8 files changed, 181 insertions(+), 84 deletions(-) diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index de2a728b06..169816b8f3 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -35,6 +35,7 @@ class LinkCache { private $mGoodLinkFields = array(); private $mBadLinks = array(); private $mForUpdate = false; + private $useDatabase = true; /** * @var LinkCache @@ -209,6 +210,19 @@ class LinkCache { } } + /** + * Enable or disable database use. + * @since 1.22 + * @param $value Boolean + * @return Boolean + */ + public function useDatabase( $value = null ) { + if ( $value !== null ) { + $this->useDatabase = (bool)$value; + } + return $this->useDatabase; + } + /** * Add a title to the link cache, return the page_id or zero if non-existent * @@ -239,6 +253,10 @@ class LinkCache { return 0; } + if( !$this->useDatabase ) { + return 0; + } + # Some fields heavily used for linking... if ( $this->mForUpdate ) { $db = wfGetDB( DB_MASTER ); diff --git a/includes/cache/LocalisationCache.php b/includes/cache/LocalisationCache.php index cba2ba7932..321d476ca4 100644 --- a/includes/cache/LocalisationCache.php +++ b/includes/cache/LocalisationCache.php @@ -1027,6 +1027,25 @@ class LocalisationCache { $this->store = new LCStoreNull; $this->manualRecache = false; } + + /** + * Return an array with initialised languages. + * + * @return array + */ + public function getInitialisedLanguages() { + return $this->initialisedLangs; + } + + /** + * Set initialised languages. + * + * @param array $languages Optional array of initialised languages. + */ + public function setInitialisedLanguages( $languages = array() ) { + $this->initialisedLangs = $languages; + } + } /** diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 765838bd1f..e7ef537620 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -1407,6 +1407,24 @@ abstract class Installer { return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page ); } + /** + * Load the extension credits for i18n strings. Very hacky for + * now, but I expect it only be used for 1.22.0 at the most. + */ + public function getExtensionInfo( $file ) { + global $wgExtensionCredits, $wgVersion, $wgResourceModules; + + $wgVersion = "1.22"; + $wgResourceModules = array(); + require_once $file ; + $e = array_values( $wgExtensionCredits ); + if( $e ) { + $ext = array_values( $e[0] ); + $wgExtensionCredits = array(); + return $ext[0]; + } + } + /** * Finds extensions that follow the format /extensions/Name/Name.php, * and returns an array containing the value for 'Name' for each found extension. @@ -1429,13 +1447,22 @@ abstract class Installer { if ( !is_dir( "$extDir/$file" ) ) { continue; } - if ( file_exists( "$extDir/$file/$file.php" ) ) { - $exts[] = $file; + + $extFile = "$extDir/$file/$file.php"; + $extI18NFile = "$extDir/$file/$file.i18n.php"; + if ( file_exists( $extFile ) ) { + if ( $info = $this->getExtensionInfo( $extFile ) ) { + $exts[$info['name']] = $info; + + if ( file_exists( $extI18NFile ) ) { + global $wgExtensionMessagesFiles; + $wgExtensionMessagesFiles[$file] = $extI18NFile; + } + } } } closedir( $dh ); - natcasesort( $exts ); - + uksort( $exts, 'strnatcasecmp' ); return $exts; } @@ -1462,8 +1489,9 @@ abstract class Installer { require "$IP/includes/DefaultSettings.php"; + $extensions = $this->findExtensions(); foreach ( $exts as $e ) { - require_once "$IP/extensions/$e/$e.php"; + require_once $extensions[$e]['path']; } $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ? diff --git a/includes/installer/LocalSettingsGenerator.php b/includes/installer/LocalSettingsGenerator.php index 68664c955c..6b72047b24 100644 --- a/includes/installer/LocalSettingsGenerator.php +++ b/includes/installer/LocalSettingsGenerator.php @@ -137,14 +137,21 @@ class LocalSettingsGenerator { $localSettings = $this->getDefaultText(); if ( count( $this->extensions ) ) { + $extensions = $this->installer->findExtensions(); $localSettings .= " # Enabled Extensions. Most extensions are enabled by including the base extension file here # but check specific extension documentation for more details # The following extensions were automatically enabled:\n"; - foreach ( $this->extensions as $extName ) { - $encExtName = self::escapePhpString( $extName ); - $localSettings .= "require_once \"\$IP/extensions/$encExtName/$encExtName.php\";\n"; + $ip = $this->installer->getVar( 'IP' ); + foreach ( $this->extensions as $ext) { + $path = str_replace( $ip, '', $extensions[$ext]['path'] ); + $prefix = ''; + if ( $path !== $extensions[$ext]['path'] ) { + $prefix = '$IP'; + } + $path = $prefix . self::escapePhpString( $path ); + $localSettings .= "require_once \"$path\";\n"; } } diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 79fdc99319..25470207e0 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -923,8 +923,10 @@ class WebInstaller extends Installer { } if ( isset( $params['rawtext'] ) ) { $labelText = $params['rawtext']; - } else { + } elseif ( isset( $params['label'] ) ) { $labelText = $this->parse( wfMessage( $params['label'] )->text() ); + } else { + $labelText = ""; } return "
\n" . diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php index d4b3d65713..b12b686b10 100644 --- a/includes/installer/WebInstallerPage.php +++ b/includes/installer/WebInstallerPage.php @@ -948,11 +948,20 @@ class WebInstaller_Options extends WebInstallerPage { if ( $extensions ) { $extHtml = $this->getFieldSetStart( 'config-extensions' ); + /* Force a recache, so we load extensions descriptions */ + global $wgLang; + $lc = Language::getLocalisationCache(); + $lc->setInitialisedLanguages( array() ); + $lc->getItem( $wgLang->mCode, '' ); + LinkCache::singleton()->useDatabase( false ); + foreach ( $extensions as $ext ) { $extHtml .= $this->parent->getCheckBox( array( - 'var' => "ext-$ext", - 'rawtext' => $ext, - ) ); + 'var' => "ext-{$ext['name']}", + 'rawtext' => "{$ext['name']}: " . + wfMessage( $ext['descriptionmsg'] )->useDatabase( false )->parse(), + ) ); + } $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) . @@ -1175,11 +1184,17 @@ class WebInstaller_Options extends WebInstallerPage { $this->setVar( 'wgRightsIcon', '' ); } - $extsAvailable = $this->parent->findExtensions(); + $extsAvailable = array_map( + function($e) { + if( isset($e['name']) ) { + return $e['name']; + } + }, $this->parent->findExtensions() ); $extsToInstall = array(); - foreach ( $extsAvailable as $ext ) { + foreach ( $extsAvailable as $key => $ext ) { + var_dump("config_ext-$ext"); if ( $this->parent->request->getCheck( 'config_ext-' . $ext ) ) { - $extsToInstall[] = $ext; + $extsToInstall[] = $extsAvailable[ $key ]; } } $this->parent->setVar( '_Extensions', $extsToInstall ); diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 40c0a89b82..46a0760845 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -280,85 +280,87 @@ class LinkHolderArray { $linkCache = LinkCache::singleton(); $output = $this->parent->getOutput(); - wfProfileIn( __METHOD__ . '-check' ); - $dbr = wfGetDB( DB_SLAVE ); - $threshold = $this->parent->getOptions()->getStubThreshold(); + if( $linkCache->useDatabase() ) { + wfProfileIn( __METHOD__ . '-check' ); + $dbr = wfGetDB( DB_SLAVE ); + $threshold = $this->parent->getOptions()->getStubThreshold(); - # Sort by namespace - ksort( $this->internals ); + # Sort by namespace + ksort( $this->internals ); - $linkcolour_ids = array(); + $linkcolour_ids = array(); - # Generate query - $queries = array(); - foreach ( $this->internals as $ns => $entries ) { - foreach ( $entries as $entry ) { - $title = $entry['title']; - $pdbk = $entry['pdbk']; + # Generate query + $queries = array(); + foreach ( $this->internals as $ns => $entries ) { + foreach ( $entries as $entry ) { + $title = $entry['title']; + $pdbk = $entry['pdbk']; - # Skip invalid entries. - # Result will be ugly, but prevents crash. - if ( is_null( $title ) ) { - continue; - } + # Skip invalid entries. + # Result will be ugly, but prevents crash. + if ( is_null( $title ) ) { + continue; + } - # Check if it's a static known link, e.g. interwiki - if ( $title->isAlwaysKnown() ) { - $colours[$pdbk] = ''; - } elseif ( $ns == NS_SPECIAL ) { - $colours[$pdbk] = 'new'; - } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) { - $colours[$pdbk] = Linker::getLinkColour( $title, $threshold ); - $output->addLink( $title, $id ); - $linkcolour_ids[$id] = $pdbk; - } elseif ( $linkCache->isBadLink( $pdbk ) ) { - $colours[$pdbk] = 'new'; - } else { - # Not in the link cache, add it to the query - $queries[$ns][] = $title->getDBkey(); + # Check if it's a static known link, e.g. interwiki + if ( $title->isAlwaysKnown() ) { + $colours[$pdbk] = ''; + } elseif ( $ns == NS_SPECIAL ) { + $colours[$pdbk] = 'new'; + } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) { + $colours[$pdbk] = Linker::getLinkColour( $title, $threshold ); + $output->addLink( $title, $id ); + $linkcolour_ids[$id] = $pdbk; + } elseif ( $linkCache->isBadLink( $pdbk ) ) { + $colours[$pdbk] = 'new'; + } else { + # Not in the link cache, add it to the query + $queries[$ns][] = $title->getDBkey(); + } } } - } - if ( $queries ) { - $where = array(); - foreach ( $queries as $ns => $pages ) { - $where[] = $dbr->makeList( - array( - 'page_namespace' => $ns, - 'page_title' => $pages, - ), - LIST_AND - ); - } + if ( $queries ) { + $where = array(); + foreach ( $queries as $ns => $pages ) { + $where[] = $dbr->makeList( + array( + 'page_namespace' => $ns, + 'page_title' => $pages, + ), + LIST_AND + ); + } - $res = $dbr->select( - 'page', - array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest' ), - $dbr->makeList( $where, LIST_OR ), - __METHOD__ - ); + $res = $dbr->select( + 'page', + array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest' ), + $dbr->makeList( $where, LIST_OR ), + __METHOD__ + ); - # Fetch data and form into an associative array - # non-existent = broken - foreach ( $res as $s ) { - $title = Title::makeTitle( $s->page_namespace, $s->page_title ); - $pdbk = $title->getPrefixedDBkey(); - $linkCache->addGoodLinkObjFromRow( $title, $s ); - $output->addLink( $title, $s->page_id ); - # @todo FIXME: Convoluted data flow - # The redirect status and length is passed to getLinkColour via the LinkCache - # Use formal parameters instead - $colours[$pdbk] = Linker::getLinkColour( $title, $threshold ); - //add id to the extension todolist - $linkcolour_ids[$s->page_id] = $pdbk; + # Fetch data and form into an associative array + # non-existent = broken + foreach ( $res as $s ) { + $title = Title::makeTitle( $s->page_namespace, $s->page_title ); + $pdbk = $title->getPrefixedDBkey(); + $linkCache->addGoodLinkObjFromRow( $title, $s ); + $output->addLink( $title, $s->page_id ); + # @todo FIXME: Convoluted data flow + # The redirect status and length is passed to getLinkColour via the LinkCache + # Use formal parameters instead + $colours[$pdbk] = Linker::getLinkColour( $title, $threshold ); + //add id to the extension todolist + $linkcolour_ids[$s->page_id] = $pdbk; + } + unset( $res ); } - unset( $res ); - } - if ( count( $linkcolour_ids ) ) { - //pass an array of page_ids to an extension - wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) ); + if ( count( $linkcolour_ids ) ) { + //pass an array of page_ids to an extension + wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) ); + } + wfProfileOut( __METHOD__ . '-check' ); } - wfProfileOut( __METHOD__ . '-check' ); # Do a second query for different language variants of links and categories if ( $wgContLang->hasVariants() ) { diff --git a/skins/common/config.css b/skins/common/config.css index 39206c3a00..79780da9e6 100644 --- a/skins/common/config.css +++ b/skins/common/config.css @@ -88,7 +88,13 @@ } .config-input-check { - margin-left: 10em; + margin-left: 3.7em; + margin-right: 2em; + margin-bottom: 0.25em; +} + +.config-input-check input { + margin-left: -1em; } .error { -- 2.20.1