]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/action.php
Just discovered the PEAR_Error handling function in index.php. Duh.
[quix0rs-gnu-social.git] / lib / action.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Base class for all actions (~views)
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Action
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/noticeform.php';
36 require_once INSTALLDIR.'/lib/htmloutputter.php';
37
38 /**
39  * Base class for all actions
40  *
41  * This is the base class for all actions in the package. An action is
42  * more or less a "view" in an MVC framework.
43  *
44  * Actions are responsible for extracting and validating parameters; using
45  * model classes to read and write to the database; and doing ouput.
46  *
47  * @category Output
48  * @package  Laconica
49  * @author   Evan Prodromou <evan@controlyourself.ca>
50  * @author   Sarven Capadisli <csarven@controlyourself.ca>
51  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52  * @link     http://laconi.ca/
53  *
54  * @see      HTMLOutputter
55  */
56 class Action extends HTMLOutputter // lawsuit
57 {
58     var $args;
59
60     /**
61      * Constructor
62      *
63      * Just wraps the HTMLOutputter constructor.
64      *
65      * @param string  $output URI to output to, default = stdout
66      * @param boolean $indent Whether to indent output, default true
67      *
68      * @see XMLOutputter::__construct
69      * @see HTMLOutputter::__construct
70      */
71     function __construct($output='php://output', $indent=true)
72     {
73         parent::__construct($output, $indent);
74     }
75
76     /**
77      * For initializing members of the class.
78      *
79      * @param array $argarray misc. arguments
80      *
81      * @return boolean true
82      */
83     function prepare($argarray)
84     {
85      
86         // For PEAR_Errors comming from DB_DataObject
87         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 
88                array($this, "handleError"));
89         
90         $this->args =& common_copy_args($argarray);
91         return true;
92     }
93
94     /**
95      * Show page, a template method.
96      *
97      * @return nothing
98      */
99     function showPage()
100     {
101         $this->startHTML();
102         $this->showHead();
103         $this->showBody();
104         $this->endHTML();
105     }
106
107     /**
108      * Show head, a template method.
109      *
110      * @return nothing
111      */
112     function showHead()
113     {
114         // XXX: attributes (profile?)
115         $this->elementStart('head');
116         $this->showTitle();
117         $this->showStylesheets();
118         $this->showScripts();
119         $this->showOpenSearch();
120         $this->showFeeds();
121         $this->showDescription();
122         $this->extraHead();
123         $this->elementEnd('head');
124     }
125
126     /**
127      * Show title, a template method.
128      *
129      * @return nothing
130      */
131     function showTitle()
132     {
133         $this->element('title', null,
134                        sprintf(_("%s - %s"),
135                                $this->title(),
136                                common_config('site', 'name')));
137     }
138
139     /**
140      * Returns the page title
141      *
142      * SHOULD overload
143      *
144      * @return string page title
145      */
146
147     function title()
148     {
149         return _("Untitled page");
150     }
151
152     /**
153      * Show stylesheets
154      *
155      * @return nothing
156      */
157     function showStylesheets()
158     {
159         $this->element('link', array('rel' => 'stylesheet',
160                                      'type' => 'text/css',
161                                      'href' => theme_path('css/display.css', 'base') . '?version=' . LACONICA_VERSION,
162                                      'media' => 'screen, projection, tv'));
163         $this->element('link', array('rel' => 'stylesheet',
164                                      'type' => 'text/css',
165                                      'href' => theme_path('css/display.css', null) . '?version=' . LACONICA_VERSION,
166                                      'media' => 'screen, projection, tv'));
167         $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
168                        'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
169         foreach (array(6,7) as $ver) {
170             if (file_exists(theme_file('css/ie'.$ver.'.css', 'base'))) {
171                 // Yes, IE people should be put in jail.
172                 $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
173                                'href="'.theme_path('css/ie'.$ver.'.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
174             }
175         }
176         $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
177                        'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
178     }
179
180     /**
181      * Show javascript headers
182      *
183      * @return nothing
184      */
185     function showScripts()
186     {
187         if (Event::handle('StartShowScripts', array($this))) {
188             if (Event::handle('StartShowJQueryScripts', array($this))) {
189                 $this->element('script', array('type' => 'text/javascript',
190                                                'src' => common_path('js/jquery.min.js')),
191                                ' ');
192                 $this->element('script', array('type' => 'text/javascript',
193                                                'src' => common_path('js/jquery.form.js')),
194                                ' ');
195                 Event::handle('EndShowJQueryScripts', array($this));
196             }
197             if (Event::handle('StartShowLaconicaScripts', array($this))) {
198                 $this->element('script', array('type' => 'text/javascript',
199                                                'src' => common_path('js/xbImportNode.js')),
200                                ' ');
201                 $this->element('script', array('type' => 'text/javascript',
202                                                'src' => common_path('js/util.js?version='.LACONICA_VERSION)),
203                                ' ');
204                 Event::handle('EndShowLaconicaScripts', array($this));
205             }
206             Event::handle('EndShowScripts', array($this));
207         }
208     }
209
210     /**
211      * Show OpenSearch headers
212      *
213      * @return nothing
214      */
215     function showOpenSearch()
216     {
217         $this->element('link', array('rel' => 'search',
218                                      'type' => 'application/opensearchdescription+xml',
219                                      'href' =>  common_local_url('opensearch', array('type' => 'people')),
220                                      'title' => common_config('site', 'name').' People Search'));
221         $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
222                                      'href' =>  common_local_url('opensearch', array('type' => 'notice')),
223                                      'title' => common_config('site', 'name').' Notice Search'));
224     }
225
226     /**
227      * Show feed headers
228      *
229      * MAY overload
230      *
231      * @return nothing
232      */
233
234     function showFeeds()
235     {
236         $feeds = $this->getFeeds();
237
238         if ($feeds) {
239             foreach ($feeds as $feed) {
240                 $this->element('link', array('rel' => $feed->rel(),
241                                              'href' => $feed->url,
242                                              'type' => $feed->mimeType(),
243                                              'title' => $feed->title));
244             }
245         }
246     }
247
248     /**
249      * Show description.
250      *
251      * SHOULD overload
252      *
253      * @return nothing
254      */
255     function showDescription()
256     {
257         // does nothing by default
258     }
259
260     /**
261      * Show extra stuff in <head>.
262      *
263      * MAY overload
264      *
265      * @return nothing
266      */
267     function extraHead()
268     {
269         // does nothing by default
270     }
271
272     /**
273      * Show body.
274      *
275      * Calls template methods
276      *
277      * @return nothing
278      */
279     function showBody()
280     {
281         $this->elementStart('body', array('id' => $this->trimmed('action')));
282         $this->elementStart('div', array('id' => 'wrap'));
283         $this->showHeader();
284         $this->showCore();
285         $this->showFooter();
286         $this->elementEnd('div');
287         $this->elementEnd('body');
288     }
289
290     /**
291      * Show header of the page.
292      *
293      * Calls template methods
294      *
295      * @return nothing
296      */
297     function showHeader()
298     {
299         $this->elementStart('div', array('id' => 'header'));
300         $this->showLogo();
301         $this->showPrimaryNav();
302         $this->showSiteNotice();
303         if (common_logged_in()) {
304             $this->showNoticeForm();
305         } else {
306             $this->showAnonymousMessage();
307         }
308         $this->elementEnd('div');
309     }
310
311     /**
312      * Show configured logo.
313      *
314      * @return nothing
315      */
316     function showLogo()
317     {
318         $this->elementStart('address', array('id' => 'site_contact',
319                                              'class' => 'vcard'));
320         $this->elementStart('a', array('class' => 'url home bookmark',
321                                        'href' => common_local_url('public')));
322         if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) {
323             $this->element('img', array('class' => 'logo photo',
324                                         'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : theme_path('logo.png'),
325                                         'alt' => common_config('site', 'name')));
326         }
327         $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
328         $this->elementEnd('a');
329         $this->elementEnd('address');
330     }
331
332     /**
333      * Show primary navigation.
334      *
335      * @return nothing
336      */
337     function showPrimaryNav()
338     {
339         $user = common_current_user();
340
341         $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
342         $this->element('dt', null, _('Primary site navigation'));
343         $this->elementStart('dd');
344         $this->elementStart('ul', array('class' => 'nav'));
345         if (Event::handle('StartPrimaryNav', array($this))) {
346             if ($user) {
347                 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
348                                 _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
349             }
350             $this->menuItem(common_local_url('peoplesearch'),
351                             _('Search'), _('Search for people or text'), false, 'nav_search');
352             if ($user) {
353                 $this->menuItem(common_local_url('profilesettings'),
354                                 _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
355
356                 if (common_config('xmpp', 'enabled')) {
357                     $this->menuItem(common_local_url('imsettings'),
358                                     _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
359                 } else {
360                     $this->menuItem(common_local_url('smssettings'),
361                                     _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
362                 }
363                 $this->menuItem(common_local_url('logout'),
364                                 _('Logout'), _('Logout from the site'), false, 'nav_logout');
365             } else {
366                 $this->menuItem(common_local_url('login'),
367                                 _('Login'), _('Login to the site'), false, 'nav_login');
368                 if (!common_config('site', 'closed')) {
369                     $this->menuItem(common_local_url('register'),
370                                     _('Register'), _('Create an account'), false, 'nav_register');
371                 }
372                 $this->menuItem(common_local_url('openidlogin'),
373                                 _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
374             }
375             $this->menuItem(common_local_url('doc', array('title' => 'help')),
376                             _('Help'), _('Help me!'), false, 'nav_help');
377             Event::handle('EndPrimaryNav', array($this));
378         }
379         $this->elementEnd('ul');
380         $this->elementEnd('dd');
381         $this->elementEnd('dl');
382     }
383
384     /**
385      * Show site notice.
386      *
387      * @return nothing
388      */
389     function showSiteNotice()
390     {
391         // Revist. Should probably do an hAtom pattern here
392         $text = common_config('site', 'notice');
393         if ($text) {
394             $this->elementStart('dl', array('id' => 'site_notice',
395                                             'class' => 'system_notice'));
396             $this->element('dt', null, _('Site notice'));
397             $this->elementStart('dd', null);
398             $this->raw($text);
399             $this->elementEnd('dd');
400             $this->elementEnd('dl');
401         }
402     }
403
404     /**
405      * Show notice form.
406      *
407      * MAY overload if no notice form needed... or direct message box????
408      *
409      * @return nothing
410      */
411     function showNoticeForm()
412     {
413         $notice_form = new NoticeForm($this);
414         $notice_form->show();
415     }
416
417     /**
418      * Show anonymous message.
419      *
420      * SHOULD overload
421      *
422      * @return nothing
423      */
424     function showAnonymousMessage()
425     {
426         // needs to be defined by the class
427     }
428
429     /**
430      * Show core.
431      *
432      * Shows local navigation, content block and aside.
433      *
434      * @return nothing
435      */
436     function showCore()
437     {
438         $this->elementStart('div', array('id' => 'core'));
439         $this->showLocalNavBlock();
440         $this->showContentBlock();
441         $this->showAside();
442         $this->elementEnd('div');
443     }
444
445     /**
446      * Show local navigation block.
447      *
448      * @return nothing
449      */
450     function showLocalNavBlock()
451     {
452         $this->elementStart('dl', array('id' => 'site_nav_local_views'));
453         $this->element('dt', null, _('Local views'));
454         $this->elementStart('dd');
455         $this->showLocalNav();
456         $this->elementEnd('dd');
457         $this->elementEnd('dl');
458     }
459
460     /**
461      * Show local navigation.
462      *
463      * SHOULD overload
464      *
465      * @return nothing
466      */
467     function showLocalNav()
468     {
469         // does nothing by default
470     }
471
472     /**
473      * Show content block.
474      *
475      * @return nothing
476      */
477     function showContentBlock()
478     {
479         $this->elementStart('div', array('id' => 'content'));
480         $this->showPageTitle();
481         $this->showPageNoticeBlock();
482         $this->elementStart('div', array('id' => 'content_inner'));
483         // show the actual content (forms, lists, whatever)
484         $this->showContent();
485         $this->elementEnd('div');
486         $this->elementEnd('div');
487     }
488
489     /**
490      * Show page title.
491      *
492      * @return nothing
493      */
494     function showPageTitle()
495     {
496         $this->element('h1', null, $this->title());
497     }
498
499     /**
500      * Show page notice block.
501      *
502      * @return nothing
503      */
504     function showPageNoticeBlock()
505     {
506         $this->elementStart('dl', array('id' => 'page_notice',
507                                         'class' => 'system_notice'));
508         $this->element('dt', null, _('Page notice'));
509         $this->elementStart('dd');
510         $this->showPageNotice();
511         $this->elementEnd('dd');
512         $this->elementEnd('dl');
513     }
514
515     /**
516      * Show page notice.
517      *
518      * SHOULD overload (unless there's not a notice)
519      *
520      * @return nothing
521      */
522     function showPageNotice()
523     {
524     }
525
526     /**
527      * Show content.
528      *
529      * MUST overload (unless there's not a notice)
530      *
531      * @return nothing
532      */
533     function showContent()
534     {
535     }
536
537     /**
538      * Show Aside.
539      *
540      * @return nothing
541      */
542
543     function showAside()
544     {
545         $this->elementStart('div', array('id' => 'aside_primary',
546                                          'class' => 'aside'));
547         $this->showExportData();
548         if (Event::handle('StartShowSections', array($this))) {
549             $this->showSections();
550             Event::handle('EndShowSections', array($this));
551         }
552         $this->elementEnd('div');
553     }
554
555     /**
556      * Show export data feeds.
557      *
558      * @return void
559      */
560
561     function showExportData()
562     {
563         $feeds = $this->getFeeds();
564         if ($feeds) {
565             $fl = new FeedList($this);
566             $fl->show($feeds);
567         }
568     }
569
570     /**
571      * Show sections.
572      *
573      * SHOULD overload
574      *
575      * @return nothing
576      */
577     function showSections()
578     {
579         // for each section, show it
580     }
581
582     /**
583      * Show footer.
584      *
585      * @return nothing
586      */
587     function showFooter()
588     {
589         $this->elementStart('div', array('id' => 'footer'));
590         $this->showSecondaryNav();
591         $this->showLicenses();
592         $this->elementEnd('div');
593     }
594
595     /**
596      * Show secondary navigation.
597      *
598      * @return nothing
599      */
600     function showSecondaryNav()
601     {
602         $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
603         $this->element('dt', null, _('Secondary site navigation'));
604         $this->elementStart('dd', null);
605         $this->elementStart('ul', array('class' => 'nav'));
606         if (Event::handle('StartSecondaryNav', array($this))) {
607             $this->menuItem(common_local_url('doc', array('title' => 'help')),
608                             _('Help'));
609             $this->menuItem(common_local_url('doc', array('title' => 'about')),
610                             _('About'));
611             $this->menuItem(common_local_url('doc', array('title' => 'faq')),
612                             _('FAQ'));
613             $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
614                             _('Privacy'));
615             $this->menuItem(common_local_url('doc', array('title' => 'source')),
616                             _('Source'));
617             $this->menuItem(common_local_url('doc', array('title' => 'contact')),
618                             _('Contact'));
619             Event::handle('EndSecondaryNav', array($this));
620         }
621         $this->elementEnd('ul');
622         $this->elementEnd('dd');
623         $this->elementEnd('dl');
624     }
625
626     /**
627      * Show licenses.
628      *
629      * @return nothing
630      */
631     function showLicenses()
632     {
633         $this->elementStart('dl', array('id' => 'licenses'));
634         $this->showLaconicaLicense();
635         $this->showContentLicense();
636         $this->elementEnd('dl');
637     }
638
639     /**
640      * Show Laconica license.
641      *
642      * @return nothing
643      */
644     function showLaconicaLicense()
645     {
646         $this->element('dt', array('id' => 'site_laconica_license'), _('Laconica software license'));
647         $this->elementStart('dd', null);
648         if (common_config('site', 'broughtby')) {
649             $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
650         } else {
651             $instr = _('**%%site.name%%** is a microblogging service. ');
652         }
653         $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION);
654         $output = common_markup_to_html($instr);
655         $this->raw($output);
656         $this->elementEnd('dd');
657         // do it
658     }
659
660     /**
661      * Show content license.
662      *
663      * @return nothing
664      */
665     function showContentLicense()
666     {
667         $this->element('dt', array('id' => 'site_content_license'), _('Laconica software license'));
668         $this->elementStart('dd', array('id' => 'site_content_license_cc'));
669         $this->elementStart('p');
670         $this->element('img', array('id' => 'license_cc',
671                                     'src' => common_config('license', 'image'),
672                                     'alt' => common_config('license', 'title')));
673         //TODO: This is dirty: i18n
674         $this->text(_('All '.common_config('site', 'name').' content and data are available under the '));
675         $this->element('a', array('class' => 'license',
676                                   'rel' => 'external license',
677                                   'href' => common_config('license', 'url')),
678                        common_config('license', 'title'));
679         $this->text(_('license.'));
680         $this->elementEnd('p');
681         $this->elementEnd('dd');
682     }
683
684     /**
685      * Return last modified, if applicable.
686      *
687      * MAY override
688      *
689      * @return string last modified http header
690      */
691     function lastModified()
692     {
693         // For comparison with If-Last-Modified
694         // If not applicable, return null
695         return null;
696     }
697
698     /**
699      * Return etag, if applicable.
700      *
701      * MAY override
702      *
703      * @return string etag http header
704      */
705     function etag()
706     {
707         return null;
708     }
709
710     /**
711      * Return true if read only.
712      *
713      * MAY override
714      *
715      * @return boolean is read only action?
716      */
717     function isReadOnly()
718     {
719         return false;
720     }
721
722     /**
723      * Returns query argument or default value if not found
724      *
725      * @param string $key requested argument
726      * @param string $def default value to return if $key is not provided
727      *
728      * @return boolean is read only action?
729      */
730     function arg($key, $def=null)
731     {
732         if (array_key_exists($key, $this->args)) {
733             return $this->args[$key];
734         } else {
735             return $def;
736         }
737     }
738
739     /**
740      * Returns trimmed query argument or default value if not found
741      *
742      * @param string $key requested argument
743      * @param string $def default value to return if $key is not provided
744      *
745      * @return boolean is read only action?
746      */
747     function trimmed($key, $def=null)
748     {
749         $arg = $this->arg($key, $def);
750         return is_string($arg) ? trim($arg) : $arg;
751     }
752
753     /**
754      * Handler method
755      *
756      * @param array $argarray is ignored since it's now passed in in prepare()
757      *
758      * @return boolean is read only action?
759      */
760     function handle($argarray=null)
761     {
762         $lm   = $this->lastModified();
763         $etag = $this->etag();
764         if ($etag) {
765             header('ETag: ' . $etag);
766         }
767         if ($lm) {
768             header('Last-Modified: ' . date(DATE_RFC1123, $lm));
769             $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
770             if ($if_modified_since) {
771                 $ims = strtotime($if_modified_since);
772                 if ($lm <= $ims) {
773                     if (!$etag ||
774                         $this->_hasEtag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) {
775                         header('HTTP/1.1 304 Not Modified');
776                         // Better way to do this?
777                         exit(0);
778                     }
779                 }
780             }
781         }
782     }
783
784     /**
785      * HasĀ etag? (private)
786      *
787      * @param string $etag          etag http header
788      * @param string $if_none_match ifNoneMatch http header
789      *
790      * @return boolean
791      */
792     function _hasEtag($etag, $if_none_match)
793     {
794         return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
795     }
796
797     /**
798      * Boolean understands english (yes, no, true, false)
799      *
800      * @param string $key query key we're interested in
801      * @param string $def default value
802      *
803      * @return boolean interprets yes/no strings as boolean
804      */
805     function boolean($key, $def=false)
806     {
807         $arg = strtolower($this->trimmed($key));
808
809         if (is_null($arg)) {
810             return $def;
811         } else if (in_array($arg, array('true', 'yes', '1'))) {
812             return true;
813         } else if (in_array($arg, array('false', 'no', '0'))) {
814             return false;
815         } else {
816             return $def;
817         }
818     }
819
820     /**
821      * Server error
822      *
823      * @param string  $msg  error message to display
824      * @param integer $code http error code, 500 by default
825      *
826      * @return nothing
827      */
828
829     function serverError($msg, $code=500)
830     {
831         $action = $this->trimmed('action');
832         common_debug("Server error '$code' on '$action': $msg", __FILE__);
833         throw new ServerException($msg, $code);
834     }
835
836     /**
837      * Client error
838      *
839      * @param string  $msg  error message to display
840      * @param integer $code http error code, 400 by default
841      *
842      * @return nothing
843      */
844
845     function clientError($msg, $code=400)
846     {
847         $action = $this->trimmed('action');
848         common_debug("User error '$code' on '$action': $msg", __FILE__);
849         throw new ClientException($msg, $code);
850     }
851
852     /**
853      * Handle old fashioned PEAR_Error msgs coming from DB_DataObject
854      *
855      * Logs the DB_DataObject error. Override to do something else.
856      * 
857      * @param PEAR_Error 
858      *
859      * @return nothing
860      */
861      
862     function handleError($error) {
863                         
864         common_log(LOG_ERR, "PEAR error: " . $error->getMessage());
865          $msg = sprintf(_('The database for %s isn\'t responding correctly, '.
866                           'so the site won\'t work properly. '.
867                           'The site admins probably know about the problem, '.
868                           'but you can contact them at %s to make sure. '.
869                           'Otherwise, wait a few minutes and try again.'),
870                         common_config('site', 'name'),
871                         common_config('site', 'email'));
872
873          $dac = new DBErrorAction($msg, 500);
874          $dac->showPage();
875          exit(-1);            
876     }
877     
878     /**
879      * Returns the current URL
880      *
881      * @return string current URL
882      */
883     function selfUrl()
884     {
885         $action = $this->trimmed('action');
886         $args   = $this->args;
887         unset($args['action']);
888         foreach (array_keys($_COOKIE) as $cookie) {
889             unset($args[$cookie]);
890         }
891         return common_local_url($action, $args);
892     }
893
894     /**
895      * Generate a menu item
896      *
897      * @param string  $url         menu URL
898      * @param string  $text        menu name
899      * @param string  $title       title attribute, null by default
900      * @param boolean $is_selected current menu item, false by default
901      * @param string  $id          element id, null by default
902      *
903      * @return nothing
904      */
905     function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
906     {
907         // Added @id to li for some control.
908         // XXX: We might want to move this to htmloutputter.php
909         $lattrs = array();
910         if ($is_selected) {
911             $lattrs['class'] = 'current';
912         }
913
914         (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
915
916         $this->elementStart('li', $lattrs);
917         $attrs['href'] = $url;
918         if ($title) {
919             $attrs['title'] = $title;
920         }
921         $this->element('a', $attrs, $text);
922         $this->elementEnd('li');
923     }
924
925     /**
926      * Generate pagination links
927      *
928      * @param boolean $have_before is there something before?
929      * @param boolean $have_after  is there something after?
930      * @param integer $page        current page
931      * @param string  $action      current action
932      * @param array   $args        rest of query arguments
933      *
934      * @return nothing
935      */
936     function pagination($have_before, $have_after, $page, $action, $args=null)
937     {
938         // Does a little before-after block for next/prev page
939         if ($have_before || $have_after) {
940             $this->elementStart('div', array('class' => 'pagination'));
941             $this->elementStart('dl', null);
942             $this->element('dt', null, _('Pagination'));
943             $this->elementStart('dd', null);
944             $this->elementStart('ul', array('class' => 'nav'));
945         }
946         if ($have_before) {
947             $pargs   = array('page' => $page-1);
948             $newargs = $args ? array_merge($args, $pargs) : $pargs;
949             $this->elementStart('li', array('class' => 'nav_prev'));
950             $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'),
951                            _('After'));
952             $this->elementEnd('li');
953         }
954         if ($have_after) {
955             $pargs   = array('page' => $page+1);
956             $newargs = $args ? array_merge($args, $pargs) : $pargs;
957             $this->elementStart('li', array('class' => 'nav_next'));
958             $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'),
959                            _('Before'));
960             $this->elementEnd('li');
961         }
962         if ($have_before || $have_after) {
963             $this->elementEnd('ul');
964             $this->elementEnd('dd');
965             $this->elementEnd('dl');
966             $this->elementEnd('div');
967         }
968     }
969
970     /**
971      * An array of feeds for this action.
972      *
973      * Returns an array of potential feeds for this action.
974      *
975      * @return array Feed object to show in head and links
976      */
977
978     function getFeeds()
979     {
980         return null;
981     }
982 }