Gallery: 代码概览:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
第1行: 第1行:
== Code Overview ==
== 代码回顾 ==


This page describes the basic structure of the Gallery 2 application and some high level design concepts.  It will help you learn your way around the codebase before developing new modules or themes, or modifying existing code.  It helps if readers have some knowledge of object oriented programming and web based applications.
该页面描述Gallery2应用程序的基本结构以及一些高级设计概念。它能帮你在开发新模块,外观主题或修改现有代码之前找到门路。它能帮助读者了解面向软件编程以及基于web的应用程序。


Gallery 2 is a PHP application that uses a single entry point to handle all HTTP requests: <tt>main.php</tt>.  This script reads your configuration file (<tt>config.php</tt>) and then checks some basic parameters so it can handoff processing of the request to the right code.  Gallery uses the [http://en.wikipedia.org/wiki/Model-view-controller Model-View-Controller] design pattern (though with loosely defined models).  In short, views are for display and controllers perform actions.  So main.php determines which view or controller will process the request and hands over control.  Views are then wrapped in a theme system to give site builders the ability to control much of the layout and appearance of the site with minimal PHP code involved.
Gallery2是一个PHP应用程序,它使用单个入口点来处理所有的HTTP请求:<tt>main.php</tt>。此脚本会读取你的配置文件(<tt>config.php</tt>)然后检查某些基础参量,这样它就能将请求处理转为正确的代码了。Gallery使用 [http://en.wikipedia.org/wiki/Model-view-controller模型—视图—控制器范式]的设计模式(尽管使用的是松散定义的模型)。简言之就是,视图用于显示而控制器用于发出动作。所以main.php决定处理请求由哪个视图或控制器进行控制,并会将控制权移交给选择。视图是被包裹在一个外观主题系统中的,这样就能使得网站建立者可以对网站布局和外观进行控制,而只需要牵涉到最少的PHP代码就可以达到目的。


[[img:146290]]
[[img:146290]]


== Views ==
== 视图 ==


Modules define views (classes extending <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryView.html GalleryView]</tt>) in <tt>*.inc</tt> files in the module's directory (alongside <tt>module.inc</tt>).  There are two flavors of views:
模块在模块目录的<tt>*.inc</tt>文件中对视图(类别扩展<tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryView.html Gallery视图]</tt>)进行定义。有两类视图:


'''Standard Views''':
'''标准视图(Standard Views)'''
These views create an HTML page in the application.  To separate the code from the user interface, all data needed for creating the page is loaded first.  The container for this data is the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryTemplate.html GalleryTemplate]</tt>.  The view loads whatever data it will need and then the theme (which may also load some data) takes over to render the page.
这些视图在应用程序中创建一个HTML页面。要将代码从用户界面中分离出来的话,所有页面创建所需的数据都会先被载入。数据容器为<tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryTemplate.html Gallery模板]</tt>。视图会读取其所需的任何数据,然后外观主题(外观主题也会载入某些数据)则接手并对页面进行渲染。


'''Immediate Views''':
'''即时视图(Immediate Views)'''
These are special purpose views which bypass the theme system and send their output directly.  This can be to send non-HTML output such as {{H:title|example: core.DownloadItem|binary}} or {{H:title|example: rss.Render|XML}} data.  Immediate views are also used for AJAX requests, where javascript code interacts with the Gallery server behind-the-scenes and updates the page dynamically as results come back.  Some AJAX views may save changes to the database (arguably these should be controllers).
这些应特殊目的而存在的视图会绕过外观主题系统并直接发送输出。这可发送非HTML的输出,如{{H:title|example: core.DownloadItem|binary}}{{H:title|example: rss.Render|XML}}数据。即时视图也可用于AJAX请求,其中javascript代码能与Gallery服务器后台进行交互,并在结果返回时动态更新页面。某些AJAX视图可能会将更改保存到数据库(也有争议说这些应是控制器)。


* Technical notes: an immediate view includes an <tt>isImmediate</tt> function that returns true.  An AJAX view that saves changes should also include an <tt>isControllerLike</tt> function that returns true.
* 技术注解:一个即时视图包括一个返回true值的<tt>isImmediate</tt>函数;一个保存更改的AJAX视图还应包括一个返回true值的<tt>isControllerLike</tt>函数。




== Themes ==
== 外观主题 ==


Themes have total control of Gallery's page layout and appearance.  The Gallery framework determines the type of page being accessed and calls one of six functions in the active theme's <tt>theme.inc</tt> file (a class extending <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryTheme.html GalleryTheme]</tt>).
Themes have total control of Gallery's page layout and appearance.  The Gallery framework determines the type of page being accessed and calls one of six functions in the active theme's <tt>theme.inc</tt> file (a class extending <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryTheme.html GalleryTheme]</tt>).
第32行: 第32行:
Each of these functions loads any additional required data into the template and then specifies a <tt>tpl</tt> file for the page display.  In most cases this is <tt>theme.tpl</tt>. Calling theme.tpl first creates a wrapper for other page types and maintains a basic look and feel (headers, banners, etc) across all Gallery pages.  The <tt>theme.tpl</tt> then rechecks the page type and includes the associated <tt>tpl</tt> for the Gallery content requested.  [[Gallery2:Themes|More about themes and the template system]]
Each of these functions loads any additional required data into the template and then specifies a <tt>tpl</tt> file for the page display.  In most cases this is <tt>theme.tpl</tt>. Calling theme.tpl first creates a wrapper for other page types and maintains a basic look and feel (headers, banners, etc) across all Gallery pages.  The <tt>theme.tpl</tt> then rechecks the page type and includes the associated <tt>tpl</tt> for the Gallery content requested.  [[Gallery2:Themes|More about themes and the template system]]


== Controllers ==
== 控制器 ==


Controllers perform actions that will save changes on the server.  Adding new photos or comments, changing settings or even logging in are actions handled by controllers.  Controllers extend the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryController.html GalleryController]</tt> class and their code resides in the <tt>*.inc</tt> files in a module's directory along with the views.
Controllers perform actions that will save changes on the server.  Adding new photos or comments, changing settings or even logging in are actions handled by controllers.  Controllers extend the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryController.html GalleryController]</tt> class and their code resides in the <tt>*.inc</tt> files in a module's directory along with the views.
第41行: 第41行:




== Subviews, *Plugins and *Options ==
== 子视图,*插件和*选项 ==


Some views make it possible for other modules to add components, bringing different features together in a common user interface.  All three of the admin type views (<tt>core.SiteAdmin</tt>, <tt>core.ItemAdmin</tt> and <tt>core.UserAdmin</tt>) use "subviews" to group those functions together.  A subview is defined in a <tt>*.inc</tt> file and is written like a normal view.  The difference is the <tt>module.inc</tt> file will list the view in its <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodgetSiteAdminViews getSiteAdminViews]</tt>, <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodgetItemAdminViews getItemAdminViews]</tt> or <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodgetUserAdminViews getUserAdminViews]</tt> function so a link for the view will appear in the sidebar of the appropriate admin area.  Note that subviews use their own controllers (there is no "subcontroller").
Some views make it possible for other modules to add components, bringing different features together in a common user interface.  All three of the admin type views (<tt>core.SiteAdmin</tt>, <tt>core.ItemAdmin</tt> and <tt>core.UserAdmin</tt>) use "subviews" to group those functions together.  A subview is defined in a <tt>*.inc</tt> file and is written like a normal view.  The difference is the <tt>module.inc</tt> file will list the view in its <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodgetSiteAdminViews getSiteAdminViews]</tt>, <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodgetItemAdminViews getItemAdminViews]</tt> or <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodgetUserAdminViews getUserAdminViews]</tt> function so a link for the view will appear in the sidebar of the appropriate admin area.  Note that subviews use their own controllers (there is no "subcontroller").
第47行: 第47行:
Two subviews have additional levels of depth for adding user interface components.  <tt>core.ItemAdd</tt> and <tt>core.ItemEdit</tt> are both <tt>ItemAdmin</tt> subviews, but each includes too many options to show on a single page.  So each offers a plugin interface (not to be confused with the usual meaning of a Gallery plugin, which is a module or theme) to add components, which are shown as tabs.  Modules can register implementations of the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemAddPlugin.html ItemAddPlugin]</tt> or <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemEditPlugin.html ItemEditPlugin]</tt> interface in the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodperformFactoryRegistrations performFactoryRegistrations]</tt> function to make these components available when the module is activated.  While registered in a different manner, these are still similar to subviews in that they control the main content of the page.  The final level of depth is <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemAddOption.html ItemAddOption]</tt> and <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemEditOption.html ItemEditOption]</tt>.  These are also factory registrations, but instead of defining an entire form they add just a section to a form and some processing upon form submission.  <tt>ItemAddOption</tt>s may add some form controls (such as the checkbox for whether to build thumbnails), or they may add no UI component and just perform post-processing (such as EXIF autorotate).  <tt>ItemEditOption</tt>s usually have both UI and post-processing, and also are registered to appear with a particular <tt>ItemEditPlugin</tt>.  For example, the thumbnail module adds its custom thumbnail controls to the ''General'' tab, as any item type can use a custom thumbnail.  The size limit module adds controls to the ''Album'' tab, as its settings are defined for an entire album.
Two subviews have additional levels of depth for adding user interface components.  <tt>core.ItemAdd</tt> and <tt>core.ItemEdit</tt> are both <tt>ItemAdmin</tt> subviews, but each includes too many options to show on a single page.  So each offers a plugin interface (not to be confused with the usual meaning of a Gallery plugin, which is a module or theme) to add components, which are shown as tabs.  Modules can register implementations of the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemAddPlugin.html ItemAddPlugin]</tt> or <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemEditPlugin.html ItemEditPlugin]</tt> interface in the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodperformFactoryRegistrations performFactoryRegistrations]</tt> function to make these components available when the module is activated.  While registered in a different manner, these are still similar to subviews in that they control the main content of the page.  The final level of depth is <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemAddOption.html ItemAddOption]</tt> and <tt>[http://gallery.menalto.com/apidoc/GalleryCore/UserInterface/ItemEditOption.html ItemEditOption]</tt>.  These are also factory registrations, but instead of defining an entire form they add just a section to a form and some processing upon form submission.  <tt>ItemAddOption</tt>s may add some form controls (such as the checkbox for whether to build thumbnails), or they may add no UI component and just perform post-processing (such as EXIF autorotate).  <tt>ItemEditOption</tt>s usually have both UI and post-processing, and also are registered to appear with a particular <tt>ItemEditPlugin</tt>.  For example, the thumbnail module adds its custom thumbnail controls to the ''General'' tab, as any item type can use a custom thumbnail.  The size limit module adds controls to the ''Album'' tab, as its settings are defined for an entire album.


== Factory ==
== 厂(Factory) ==


The *Option classes discussed above are two examples of factory interfaces.  Gallery uses this mechanism for all communication between modules.  A module defines an interface class that describes the functions of the interface.  This can be used in two ways: other modules can define implementations of the interface, allowing those implementations to be found and used.  This is how the *Option classes are discovered.  It is also how the search module allows other modules to make their data searchable.  Alternatively, the module itself can implement the interface which allows other modules to use it.  This is how the EXIF module allows other modules to read EXIF data from image files.  Implementations are always registered in the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodperformFactoryRegistrations performFactoryRegistrations]</tt> function of <tt>module.inc</tt>.  The interfaces themselves don't need to be registered.
The *Option classes discussed above are two examples of factory interfaces.  Gallery uses this mechanism for all communication between modules.  A module defines an interface class that describes the functions of the interface.  This can be used in two ways: other modules can define implementations of the interface, allowing those implementations to be found and used.  This is how the *Option classes are discovered.  It is also how the search module allows other modules to make their data searchable.  Alternatively, the module itself can implement the interface which allows other modules to use it.  This is how the EXIF module allows other modules to read EXIF data from image files.  Implementations are always registered in the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryModule.html#methodperformFactoryRegistrations performFactoryRegistrations]</tt> function of <tt>module.inc</tt>.  The interfaces themselves don't need to be registered.




== Event Listeners ==
== 事件侦听器 ==


Gallery includes an event system so that modules may take action when certain events take place.  For example, the ratings module listens for <tt>GalleryEntity::delete</tt> events and remove all ratings for an item when the item is deleted.  No registration is needed for event types; other modules just need to listen for the right event name.  Read more about [[Gallery2:Events|events]].
Gallery includes an event system so that modules may take action when certain events take place.  For example, the ratings module listens for <tt>GalleryEntity::delete</tt> events and remove all ratings for an item when the item is deleted.  No registration is needed for event types; other modules just need to listen for the right event name.  Read more about [[Gallery2:Events|events]].




== Security ==
== 安全性 ==


Security is a shared responsibility of modules and the Gallery framework.  The framework provides tools such as GalleryUtilities::getRequestVariables and GalleryCoreApi::assertHasItemPermission, but modules must also use these properly.  Other aspects of security are transparent to modules, and handled automatically by the framework, such as preventing [http://en.wikipedia.org/wiki/Session_hijacking session hijacking] or [http://en.wikipedia.org/wiki/Cross-site_request_forgery cross site request forgery].  Read more about [[Gallery2:Security|Gallery 2 Security]].
Security is a shared responsibility of modules and the Gallery framework.  The framework provides tools such as GalleryUtilities::getRequestVariables and GalleryCoreApi::assertHasItemPermission, but modules must also use these properly.  Other aspects of security are transparent to modules, and handled automatically by the framework, such as preventing [http://en.wikipedia.org/wiki/Session_hijacking session hijacking] or [http://en.wikipedia.org/wiki/Cross-site_request_forgery cross site request forgery].  Read more about [[Gallery2:Security|Gallery 2 Security]].




== Session Management ==
== 会话管理 ==


Gallery manages user sessions automatically.  When a user logs in or a guest does something that requires saving state between requests (such as adding items to a cart), a persistent session is created.  Modules can store short-lived information in the session too.  This information is discarded if the user logs out or the session expires.  Gallery takes care of creating a [http://en.wikipedia.org/wiki/HTTP_cookie cookie] to track the session, or adding the session ID to all URLs in the page if the browser does not accept cookies.  Read more about [[Gallery2:GallerySession|session management]].
Gallery manages user sessions automatically.  When a user logs in or a guest does something that requires saving state between requests (such as adding items to a cart), a persistent session is created.  Modules can store short-lived information in the session too.  This information is discarded if the user logs out or the session expires.  Gallery takes care of creating a [http://en.wikipedia.org/wiki/HTTP_cookie cookie] to track the session, or adding the session ID to all URLs in the page if the browser does not accept cookies.  Read more about [[Gallery2:GallerySession|session management]].




== Internationalization ==
== 国际化 ==


Gallery is an internationalized application.  This means all user-visible text in the application can be translated for display in any language.  Modules make text available for translation by using the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryPlugin.html#methodtranslate $module->translate()]</tt> or <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/Gallery.html#methodi18n $gallery->i18n()]</tt> functions in PHP code, and the <tt>[[Gallery2:Themes:Reference:Tags#text|{g->text}]]</tt> tag in <tt>tpl</tt> files.  Note that these translations are for text included with the application.  User entered text (such as image titles and captions) are not translated by this system.  The [[Gallery2:Modules:multilang|multilanguage module]] does make it possible to enter a few basic fields in more than one language.  Read more about [[Gallery2:Internationalization|internationalization]] and [[Gallery2:Localization|translations]].
Gallery is an internationalized application.  This means all user-visible text in the application can be translated for display in any language.  Modules make text available for translation by using the <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryPlugin.html#methodtranslate $module->translate()]</tt> or <tt>[http://gallery.menalto.com/apidoc/GalleryCore/Classes/Gallery.html#methodi18n $gallery->i18n()]</tt> functions in PHP code, and the <tt>[[Gallery2:Themes:Reference:Tags#text|{g->text}]]</tt> tag in <tt>tpl</tt> files.  Note that these translations are for text included with the application.  User entered text (such as image titles and captions) are not translated by this system.  The [[Gallery2:Modules:multilang|multilanguage module]] does make it possible to enter a few basic fields in more than one language.  Read more about [[Gallery2:Internationalization|internationalization]] and [[Gallery2:Localization|translations]].




== Next Steps ==
== 接下来的步骤 ==


Check the available documents in the [[:Category:Gallery 2:Development|Gallery 2 Development]] category to find additional detail on these and other topics.  Particularly look for the [[Gallery2:Module Development Tutorial|Module development tutorial]] and information about the [[Gallery2:API|Gallery 2 APIs]].  Also, once you understand the basics, looking at existing code is a great way to learn how to accomplish various tasks in Gallery code.  You can also visit the <tt>#gallery</tt> channel on irc://chat.freenode.net to ask development questions.  Good luck!
Check the available documents in the [[:Category:Gallery 2:Development|Gallery 2 Development]] category to find additional detail on these and other topics.  Particularly look for the [[Gallery2:Module Development Tutorial|Module development tutorial]] and information about the [[Gallery2:API|Gallery 2 APIs]].  Also, once you understand the basics, looking at existing code is a great way to learn how to accomplish various tasks in Gallery code.  You can also visit the <tt>#gallery</tt> channel on irc://chat.freenode.net to ask development questions.  Good luck!

2008年11月25日 (二) 16:57的版本

代码回顾

该页面描述Gallery2应用程序的基本结构以及一些高级设计概念。它能帮你在开发新模块,外观主题或修改现有代码之前找到门路。它能帮助读者了解面向软件编程以及基于web的应用程序。

Gallery2是一个PHP应用程序,它使用单个入口点来处理所有的HTTP请求:main.php。此脚本会读取你的配置文件(config.php)然后检查某些基础参量,这样它就能将请求处理转为正确的代码了。Gallery使用 [1]的设计模式(尽管使用的是松散定义的模型)。简言之就是,视图用于显示而控制器用于发出动作。所以main.php决定处理请求由哪个视图或控制器进行控制,并会将控制权移交给选择。视图是被包裹在一个外观主题系统中的,这样就能使得网站建立者可以对网站布局和外观进行控制,而只需要牵涉到最少的PHP代码就可以达到目的。

img:146290

视图

模块在模块目录的*.inc文件中对视图(类别扩展Gallery视图)进行定义。有两类视图:

标准视图(Standard Views): 这些视图在应用程序中创建一个HTML页面。要将代码从用户界面中分离出来的话,所有页面创建所需的数据都会先被载入。数据容器为Gallery模板。视图会读取其所需的任何数据,然后外观主题(外观主题也会载入某些数据)则接手并对页面进行渲染。

即时视图(Immediate Views): 这些应特殊目的而存在的视图会绕过外观主题系统并直接发送输出。这可发送非HTML的输出,如binaryXML数据。即时视图也可用于AJAX请求,其中javascript代码能与Gallery服务器后台进行交互,并在结果返回时动态更新页面。某些AJAX视图可能会将更改保存到数据库(也有争议说这些应是控制器)。

  • 技术注解:一个即时视图包括一个返回true值的isImmediate函数;一个保存更改的AJAX视图还应包括一个返回true值的isControllerLike函数。


外观主题

Themes have total control of Gallery's page layout and appearance. The Gallery framework determines the type of page being accessed and calls one of six functions in the active theme's theme.inc file (a class extending GalleryTheme).

  • showAlbumPage or showPhotoPage: Displays individual or grouped Gallery items
  • showModulePage: Other Gallery pages added by modules
  • showAdminPage: Gallery administration pages; they function just like module pages, but call a different theme function in case the theme wants to customize the display of browsing vs admin pages
  • showErrorPage: main.php routes errors to the core.ErrorPage view
  • showProgressBar: Controllers may delegate control to the core.ProgressBar view for long running tasks

Each of these functions loads any additional required data into the template and then specifies a tpl file for the page display. In most cases this is theme.tpl. Calling theme.tpl first creates a wrapper for other page types and maintains a basic look and feel (headers, banners, etc) across all Gallery pages. The theme.tpl then rechecks the page type and includes the associated tpl for the Gallery content requested. More about themes and the template system

控制器

Controllers perform actions that will save changes on the server. Adding new photos or comments, changing settings or even logging in are actions handled by controllers. Controllers extend the GalleryController class and their code resides in the *.inc files in a module's directory along with the views.

Generally the first task done by controllers is to verify proper permissions for the requested action. Always remember that even if your view omits a button or link based on permissions, the controller still must check permissions as HTTP requests can be manually constructed.

The second task is to validate the input data. If any user entered data is missing or invalid, the controller adds a token to the $error array that will be returned. Only if the inputs are valid does the controller proceed with the operation and set a key in the $success array. Controllers then instruct main.php what to do next. Upon success a controller will send a redirect, usually back to the same view. The $success data is stored in the session and made available to the view in the next request so it can show a status message. If $error is nonempty usually a controller will delegate back to the same view. This means the view is rendered in the same HTTP request, so the given $form data is still available. The view can then fill in the user entered data (so they don't have to enter it again) and check the $error tokens to show the appropriate error message next to the invalid data. These checks and messages are in the tpl file for the view.


子视图,*插件和*选项

Some views make it possible for other modules to add components, bringing different features together in a common user interface. All three of the admin type views (core.SiteAdmin, core.ItemAdmin and core.UserAdmin) use "subviews" to group those functions together. A subview is defined in a *.inc file and is written like a normal view. The difference is the module.inc file will list the view in its getSiteAdminViews, getItemAdminViews or getUserAdminViews function so a link for the view will appear in the sidebar of the appropriate admin area. Note that subviews use their own controllers (there is no "subcontroller").

Two subviews have additional levels of depth for adding user interface components. core.ItemAdd and core.ItemEdit are both ItemAdmin subviews, but each includes too many options to show on a single page. So each offers a plugin interface (not to be confused with the usual meaning of a Gallery plugin, which is a module or theme) to add components, which are shown as tabs. Modules can register implementations of the ItemAddPlugin or ItemEditPlugin interface in the performFactoryRegistrations function to make these components available when the module is activated. While registered in a different manner, these are still similar to subviews in that they control the main content of the page. The final level of depth is ItemAddOption and ItemEditOption. These are also factory registrations, but instead of defining an entire form they add just a section to a form and some processing upon form submission. ItemAddOptions may add some form controls (such as the checkbox for whether to build thumbnails), or they may add no UI component and just perform post-processing (such as EXIF autorotate). ItemEditOptions usually have both UI and post-processing, and also are registered to appear with a particular ItemEditPlugin. For example, the thumbnail module adds its custom thumbnail controls to the General tab, as any item type can use a custom thumbnail. The size limit module adds controls to the Album tab, as its settings are defined for an entire album.

厂(Factory)

The *Option classes discussed above are two examples of factory interfaces. Gallery uses this mechanism for all communication between modules. A module defines an interface class that describes the functions of the interface. This can be used in two ways: other modules can define implementations of the interface, allowing those implementations to be found and used. This is how the *Option classes are discovered. It is also how the search module allows other modules to make their data searchable. Alternatively, the module itself can implement the interface which allows other modules to use it. This is how the EXIF module allows other modules to read EXIF data from image files. Implementations are always registered in the performFactoryRegistrations function of module.inc. The interfaces themselves don't need to be registered.


事件侦听器

Gallery includes an event system so that modules may take action when certain events take place. For example, the ratings module listens for GalleryEntity::delete events and remove all ratings for an item when the item is deleted. No registration is needed for event types; other modules just need to listen for the right event name. Read more about events.


安全性

Security is a shared responsibility of modules and the Gallery framework. The framework provides tools such as GalleryUtilities::getRequestVariables and GalleryCoreApi::assertHasItemPermission, but modules must also use these properly. Other aspects of security are transparent to modules, and handled automatically by the framework, such as preventing session hijacking or cross site request forgery. Read more about Gallery 2 Security.


会话管理

Gallery manages user sessions automatically. When a user logs in or a guest does something that requires saving state between requests (such as adding items to a cart), a persistent session is created. Modules can store short-lived information in the session too. This information is discarded if the user logs out or the session expires. Gallery takes care of creating a cookie to track the session, or adding the session ID to all URLs in the page if the browser does not accept cookies. Read more about session management.


国际化

Gallery is an internationalized application. This means all user-visible text in the application can be translated for display in any language. Modules make text available for translation by using the $module->translate() or $gallery->i18n() functions in PHP code, and the {g->text} tag in tpl files. Note that these translations are for text included with the application. User entered text (such as image titles and captions) are not translated by this system. The multilanguage module does make it possible to enter a few basic fields in more than one language. Read more about internationalization and translations.


接下来的步骤

Check the available documents in the Gallery 2 Development category to find additional detail on these and other topics. Particularly look for the Module development tutorial and information about the Gallery 2 APIs. Also, once you understand the basics, looking at existing code is a great way to learn how to accomplish various tasks in Gallery code. You can also visit the #gallery channel on irc://chat.freenode.net to ask development questions. Good luck!