+[[!template id="note" text="""
+Ikiwiki is a compiler
+
+One thing to keep in mind when writing a plugin is that ikiwiki is a wiki
+*compiler*. So plugins influence pages when they are built, not when they
+are loaded. A plugin that inserts the current time into a page, for
+example, will insert the build time.
+
+Also, as a compiler, ikiwiki avoids rebuilding pages unless they have
+changed, so a plugin that prints some random or changing thing on a page
+will generate a static page that won't change until ikiwiki rebuilds the
+page for some other reason, like the page being edited.
+
+The [[tutorial]] has some other examples of ways that ikiwiki being a
+compiler may trip up the unwary.
+"""]]
+
+[[!toc levels=2]]
+
+## Highlevel view of ikiwiki
+
+Ikiwiki mostly has two modes of operation. It can either be running
+as a compiler, building or updating a wiki; or as a cgi program, providing
+user interface for editing pages, etc. Almost everything ikiwiki does
+is accomplished by calling various hooks provided by plugins.
+
+### compiler
+
+As a compiler, ikiwiki starts by calling the
+[[`refresh`|plugins/write#refresh]] hook. Then it checks the wiki's source to
+find new or changed pages. The [[`needsbuild`|plugins/write#needsbuild]] hook
+is then called to allow manipulation of the list of pages that need to be
+built.
+
+Now that it knows what pages it needs to build, ikiwiki runs two compile
+passes. First, it runs [[`scan`|plugins/write#scan]] hooks, which collect
+metadata about the pages. Then it runs a page rendering pipeline, by calling
+in turn these hooks: [[`filter`|plugins/write#filter]],
+[[`preprocess`|plugins/write#preprocess]],
+[[`linkify`|plugins/write#linkify]], [[`htmlize`|plugins/write#htmlize]],
+[[`indexhtml`|plugins/write#indexhtml]],
+[[`pagetemplate`|plugins/write#pagetemplate]],
+[[`sanitize`|plugins/write#sanitize]], [[`format`|plugins/write#format]].
+
+After all necessary pages are built, it calls the
+[[`changes`|plugins/write#changes]] hook. Finally, if a page was deleted, the
+[[`delete`|plugins/write#delete]] hook is called, and the files that page had
+previously produced are removed.
+
+### cgi
+
+The flow between hooks when ikiwiki is run as a cgi is best illustrated by
+an example.
+
+Alice browses to a page and clicks Edit.
+
+* Ikiwiki is run as a cgi. It assigns Alice a session cookie, and, by calling
+ the [[`auth`|plugins/write#auth]] hooks, sees that she is not yet logged in.
+* The [[`sessioncgi`|plugins/write#sessioncgi]] hooks are then called, and one
+ of them, from the [[editpage]] plugin, notices that the cgi has been told
+ "do=edit".
+* The [[editpage]] plugin calls the [[`canedit`|plugins/write#canedit]] hook
+ to check if this page edit is allowed. The [[signinedit]] plugin has a hook
+ that says not: Alice is not signed in.
+* The [[signinedit]] plugin then launches the signin process. A signin page is
+ built by calling the [[`formbuilder_setup`|plugins/write#formbuilder]]
+ hook.
+
+Alice signs in with her openid.
+
+* The [[openid]] plugin's [[`formbuilder`|plugins/write#formbuilder]] hook
+ sees that an openid was entered in the signin form, and redirects to Alice's
+ openid provider.
+* Alice's openid provider calls back to ikiwiki. The [[openid]] plugin has an
+ [[`auth`|plugins/write#auth]] hook that finishes the openid signin process.
+* Signin complete, ikiwiki returns to what Alice was doing before; editing
+ a page.
+* Now all the [[`canedit`|plugins/write#canedit]] hooks are happy. The
+ [[editpage]] plugin calls
+ [[`formbuilder_setup`|plugins/write#formbuilder]] to display the page
+ editing form.
+
+Alice saves her change to the page.
+
+* The [[editpage]] plugin's [[`formbuilder`|plugins/write#formbuilder]] hook
+ sees that the Save button was pressed, and calls the
+ [[`checkcontent`|plugins/write#checkcontent]] and
+ [[`editcontent`|plugins/write#editcontent]] hooks. Then it saves the page
+ to disk, and branches into the compiler part of ikiwiki to refresh the wiki.