Difference between revisions of "Notes about legacy page classes"

Jump to: navigation, search
 
 
Line 1: Line 1:
#REDIRECT [[Obsolete:Notes about legacy page classes]]
+
{{obsolete}}
 +
 
 +
The page is some notes about the legacy lib/pagelib.php, and is solely for my benefit as I plan how to change it in [[Navigation 2.0 implementation plan]] without breaking backwards compatibility too badly ;-)
 +
 
 +
==Definition of page classes==
 +
 
 +
===page_base subclasses that exist in core===
 +
 
 +
List of the classes according to the file which defines them.
 +
 
 +
; lib/pagelib.php
 +
: '''page_base''', ''__construct'', ''construct'', ''init_full'', ''init_quick'', ''get_type'', ''get_id'', ''get_format_name'', ''get_body_class'', ''get_body_id'',  ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', ''blocks_get_default'', ''url_get_path'', ''url_get_parameters'', ''url_get_full'', ''user_allowed_editing'', ''user_is_editing'', ''edit_always''
 +
: '''page_course extends''' page_base, ''init_full'', ''init_quick'', ''get_type'', ''get_format_name'', ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', ''blocks_get_default'', ''url_get_path'', ''url_get_parameters'', ''user_allowed_editing'', ''user_is_editing''
 +
: '''page_generic_activity extends''' page_base, ''init_full'', ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''url_get_parameters'', ''url_get_path'', ''user_allowed_editing'', ''user_is_editing''
 +
 
 +
; ✔ admin/pagelib.php
 +
: page_admin extends page_base, ''get_type'', ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', ''blocks_get_default'', ''url_get_path'', ''url_get_parameters'', ''user_allowed_editing'', ''user_is_editing'', ''init_extra'', ''set_extra_button'', ''set_extra_url_params''
 +
 
 +
; blog/blogpage.php ''why isn't this called pagelib.php?''
 +
: '''page_blog extends page_base''', ''init_full'', ''init_quick'', ''get_type'', ''get_format_name'', ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', blocks_get_default, ''url_get_path'', ''url_get_parameters'', ''user_allowed_editing'', ''user_is_editing'', ''get_extra_header_string''
 +
 
 +
; mod/chat/pagelib.php
 +
: '''page_chat''' extends page_generic_activity, ''init_quick'', ''get_type''
 +
 
 +
; mod/data/pagelib.php
 +
: '''page_data''' extends page_generic_activity, ''init_quick'', ''get_type'', ''print_header''
 +
 
 +
; mod/lesson/pagelib.php
 +
: '''page_lesson''' extends page_generic_activity, ''get_type'', ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', ''url_get_parameters'', ''set_lessonpageid''
 +
 
 +
; mod/quiz/pagelib.php
 +
: '''page_quiz''' extends page_generic_activity, ''init_quick'', ''get_type''
 +
 
 +
; my/pagelib.php
 +
: '''page_my_moodle''' extends page_base, ''get_type'', ''print_header'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', ''url_get_parameters'', ''url_get_path'', ''user_allowed_editing'', ''user_is_editing''
 +
 
 +
; ✔ tag/pagelib.php
 +
: '''page_tag''' extends page_base, ''get_type'', ''get_format_name'', ''print_header'', ''print_footer'', ''blocks_get_positions'', ''blocks_default_position'', ''blocks_move_position'', ''url_get_parameters'', ''url_get_path'', ''user_allowed_editing'', ''user_is_editing''
 +
 
 +
===Pagelib files in contrib===
 +
 
 +
I checked the HEAD and 1.9 branches in contrib CVS.
 +
 
 +
; patches/center_blocks_position_patch/lib/pagelib.php
 +
: This is a hack that becomes obsolete. No worries.
 +
 
 +
; plugins/mod/dimdim/pagelib.php
 +
: '''page_dimdim''' extends page_generic_activity, ''init_quick'', ''get_type'', ''print_header''
 +
 
 +
; plugins/mod/game/pagelib.php
 +
: '''page_game''' extends page_generic_activity, ''init_quick'', ''get_type'', ''print_header''
 +
 
 +
; plugins/mod/oublog/pagelib.php
 +
: '''page_game''' extends page_generic_activity, ''init_quick'', ''get_type''
 +
 
 +
; plugins/mod/wiki/pagelib.php
 +
: '''page_wiki''' extends page_generic_activity, ''init_quick'', ''get_type'', ''print_header'', ''blocks_move_position''
 +
 
 +
==Uses of $PAGE==
 +
 
 +
===In core===
 +
 
 +
190 references to $PAGE in 30 files
 +
 
 +
Pages that need a small amount of standard re-work (which should be documented on [[Migrating your code code to the 2.0 rendering API]] as I do it). That is, only uses the things listed as 'Calls to' in the next section.
 +
* course/format/scorm/format.php
 +
* course/format/social/format.php
 +
* course/format/topics/format.php
 +
* course/format/weeks/format.php
 +
* course/rest.php
 +
* course/view.php
 +
* lib/moodlelib.php - isediting function, which we may deprecate since we can now use $PAGE->is_editing() everywhere
 +
* lib/weblib.php - three todos that are waiting for $PAGE->context
 +
* mod/chat/view.php
 +
* mod/data/view.php
 +
* mod/lesson/action/continue.html
 +
* mod/lesson/action/continue.php
 +
* mod/lesson/locallib.php
 +
* mod/lesson/view.php - special $PAGE->set_lessonpageid bit. Replace with $PAGE->set_sub_page.
 +
* mod/lesson/viewend.php
 +
* mod/lesson/viewstart.php
 +
* mod/quiz/view.php
 +
* mod/resource/lib.php
 +
* my/index.php
 +
* tag/index.php
 +
* index.php
 +
 
 +
Pages that need a bit more work that that:
 +
* Things relating to page-admin and $PAGE->section
 +
** admin/settings.php
 +
** blocks/admin_bookmarks/block_admin_bookmarks.php
 +
** blocks/admin_tree/block_admin_tree.php
 +
** lib/adminlib.php
 +
* blocks/moodleblock.class.php - checks $PAGE->type and ->id
 +
 
 +
Pages that will need major rework
 +
* lib/blocklib.php
 +
* admin/stickyblocks.php - will be replaced by the new block editing UI.
 +
* blog
 +
** blog/footer.php
 +
** blog/header.php - sets lots of stuff like $PAGE->courseid, $PAGE->filterselect, $PAGE->tagid - looks like abuse of global variables.
 +
 
 +
===In contrib===
 +
 
 +
204 references, but 122 if you exclude contrib/old on the 1.9 branch.
 +
163 references if you exclude contrib/old on the HEAD branch.
 +
 
 +
Calls to
 +
* $PAGE = page_create_object(...)
 +
* $pageblocks = blocks_setup($PAGE, ...)
 +
* blocks_print_group($PAGE, ...)
 +
* $pageblocks = blocks_get_by_page($PAGE)
 +
* $PAGE->user_allowed_editing()
 +
* $PAGE->user_is_editing()
 +
* $missingblocks = blocks_get_missing($PAGE, $pageblocks) ''Missing blocks are really means blocks that the user is allowed to add to this page.''
 +
* $PAGE->print_header($title)
 +
* $PAGE->url_get_full(...)
 +
* unset($PAGE->_user_allowed_editing) ''horribly, I have seen this hack in several places! will not be backwards compatible, but there will be a new method to do this.''
 +
 
 +
We should be able to support all that in a backwards compatible way.
 +
 
 +
More complex stuff in
 +
* patches/blocktopbottom/... - but that will be obsolete.
 +
* patches/center_blocks_position_patch/... - but that will be obsolete.
 +
* patches/dragmath seems to ship a custom lib/adminlib.php - no idea why, but I am not going to worry about breaking it.
 +
* plugins/mod/customlabel/_goodies/course/format/page/actions/activities.php refers to a non-existent $PAGE->print_tabs(...).
 +
* plugins/theme/wood_custom_corners/header.html does some nasty hacking based on page type. Will break.
 +
 
 +
I expect most of that will break, but I don't think there is anything that important in that list.
 +
 
 +
==What happens to the various pagelib methods==
 +
 
 +
; init_full
 +
; init_quick
 +
: need to work out if any of this logic is important, and if so move it
 +
 
 +
; ✔ blocks_get_positions
 +
; ✔ blocks_default_position
 +
; ✔ blocks_move_position
 +
: obsoleted by the new blocks system. We will just make deprecated functions that do nothing just to prevent fatal errors.
 +
 
 +
; ✔ blocks_get_default
 +
: actually, we don't need a general default blocks mechanism. Instead we should be using sticky blocks for most things. The one exception is default blocks on the course page. We will implement that as a special case using the existing $CFG variables.
 +
 
 +
; ✔ user_allowed_editing
 +
: the logic from subclass implementations needs to be moved elsewhere
 +
 
 +
; ✔ user_is_editing
 +
: keep
 +
 
 +
; ✔ get_type
 +
: becomes return $PAGE->pagetype
 +
 
 +
; ✔ get_format_name
 +
: this is used to filter the allowed blocks by course format, something only about 2 blocks actually take advantage of. I think the correct solution is to set $PAGE->pagetype to, e.g. course-view-weeks or course-edit-weeks on the course view/edit page, and make get_format_name a deprecated synonym for get_type.
 +
 
 +
; get_id
 +
: only used by blocklib when working out what blocks appear on a page, so remove after upgrading the blocks database tables
 +
 
 +
; print_header
 +
: need to examine the logic in all subclasses, and work out what to do about it
 +
 
 +
; ✔ edit_always
 +
: only used by admin/stickyblocks.php - though the reference is actually in lib/blockslib.php - remove
 +
 
 +
; ✔ url_get_path
 +
; ✔ url_get_full
 +
: keep deprecated implementations in terms of $PAGE->url
 +
 
 +
; ✔ url_get_parameters
 +
: move logic from subclasses that used to be here elsewhere, then reimplement in terms of $PAGE->url
 +
 
 +
; ✔ get_body_class
 +
; ✔ get_body_id
 +
: not used anywhere, remove
 +
 
 +
; ✔ init_extra
 +
; set_extra_button
 +
; ✔ set_extra_url_params
 +
: hacks I added to the admin page class - fix admin and remove
 +
 
 +
; ✔ get_extra_header_string
 +
: only used by blog - remove
 +
 
 +
; set_lessonpageid
 +
: only used by lesson - remove and use with $PAGE->subpage instead
 +
 
 +
; ✔ print_footer
 +
: only defined/used in tags - remove.
 +
 
 +
; ✔ $CFG->pagepath
 +
: This was an evil hack - remove - replace with $PAGE->set_pagetype()
 +
 
 +
; ADMIN_STICKYBLOCKS
 +
: this constant is defined by admin/stickyblocks.php as a hack to let the blocks code know we are editing stickyblocks. Remove this once the new blocks editing is done.
 +
 
 +
==See also==
 +
 
 +
* [[Navigation 2.0 implementation plan]]
 +
* [[Migrating your code code to the 2.0 rendering API]]

Latest revision as of 08:12, 27 July 2011

Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable.


The page is some notes about the legacy lib/pagelib.php, and is solely for my benefit as I plan how to change it in Navigation 2.0 implementation plan without breaking backwards compatibility too badly ;-)

Definition of page classes

page_base subclasses that exist in core

List of the classes according to the file which defines them.

lib/pagelib.php
page_base, __construct, construct, init_full, init_quick, get_type, get_id, get_format_name, get_body_class, get_body_id, print_header, blocks_get_positions, blocks_default_position, blocks_move_position, blocks_get_default, url_get_path, url_get_parameters, url_get_full, user_allowed_editing, user_is_editing, edit_always
page_course extends page_base, init_full, init_quick, get_type, get_format_name, print_header, blocks_get_positions, blocks_default_position, blocks_move_position, blocks_get_default, url_get_path, url_get_parameters, user_allowed_editing, user_is_editing
page_generic_activity extends page_base, init_full, print_header, blocks_get_positions, blocks_default_position, url_get_parameters, url_get_path, user_allowed_editing, user_is_editing
✔ admin/pagelib.php
page_admin extends page_base, get_type, print_header, blocks_get_positions, blocks_default_position, blocks_move_position, blocks_get_default, url_get_path, url_get_parameters, user_allowed_editing, user_is_editing, init_extra, set_extra_button, set_extra_url_params
blog/blogpage.php why isn't this called pagelib.php?
page_blog extends page_base, init_full, init_quick, get_type, get_format_name, print_header, blocks_get_positions, blocks_default_position, blocks_move_position, blocks_get_default, url_get_path, url_get_parameters, user_allowed_editing, user_is_editing, get_extra_header_string
mod/chat/pagelib.php
page_chat extends page_generic_activity, init_quick, get_type
mod/data/pagelib.php
page_data extends page_generic_activity, init_quick, get_type, print_header
mod/lesson/pagelib.php
page_lesson extends page_generic_activity, get_type, print_header, blocks_get_positions, blocks_default_position, blocks_move_position, url_get_parameters, set_lessonpageid
mod/quiz/pagelib.php
page_quiz extends page_generic_activity, init_quick, get_type
my/pagelib.php
page_my_moodle extends page_base, get_type, print_header, blocks_get_positions, blocks_default_position, blocks_move_position, url_get_parameters, url_get_path, user_allowed_editing, user_is_editing
✔ tag/pagelib.php
page_tag extends page_base, get_type, get_format_name, print_header, print_footer, blocks_get_positions, blocks_default_position, blocks_move_position, url_get_parameters, url_get_path, user_allowed_editing, user_is_editing

Pagelib files in contrib

I checked the HEAD and 1.9 branches in contrib CVS.

patches/center_blocks_position_patch/lib/pagelib.php
This is a hack that becomes obsolete. No worries.
plugins/mod/dimdim/pagelib.php
page_dimdim extends page_generic_activity, init_quick, get_type, print_header
plugins/mod/game/pagelib.php
page_game extends page_generic_activity, init_quick, get_type, print_header
plugins/mod/oublog/pagelib.php
page_game extends page_generic_activity, init_quick, get_type
plugins/mod/wiki/pagelib.php
page_wiki extends page_generic_activity, init_quick, get_type, print_header, blocks_move_position

Uses of $PAGE

In core

190 references to $PAGE in 30 files

Pages that need a small amount of standard re-work (which should be documented on Migrating your code code to the 2.0 rendering API as I do it). That is, only uses the things listed as 'Calls to' in the next section.

  • course/format/scorm/format.php
  • course/format/social/format.php
  • course/format/topics/format.php
  • course/format/weeks/format.php
  • course/rest.php
  • course/view.php
  • lib/moodlelib.php - isediting function, which we may deprecate since we can now use $PAGE->is_editing() everywhere
  • lib/weblib.php - three todos that are waiting for $PAGE->context
  • mod/chat/view.php
  • mod/data/view.php
  • mod/lesson/action/continue.html
  • mod/lesson/action/continue.php
  • mod/lesson/locallib.php
  • mod/lesson/view.php - special $PAGE->set_lessonpageid bit. Replace with $PAGE->set_sub_page.
  • mod/lesson/viewend.php
  • mod/lesson/viewstart.php
  • mod/quiz/view.php
  • mod/resource/lib.php
  • my/index.php
  • tag/index.php
  • index.php

Pages that need a bit more work that that:

  • Things relating to page-admin and $PAGE->section
    • admin/settings.php
    • blocks/admin_bookmarks/block_admin_bookmarks.php
    • blocks/admin_tree/block_admin_tree.php
    • lib/adminlib.php
  • blocks/moodleblock.class.php - checks $PAGE->type and ->id

Pages that will need major rework

  • lib/blocklib.php
  • admin/stickyblocks.php - will be replaced by the new block editing UI.
  • blog
    • blog/footer.php
    • blog/header.php - sets lots of stuff like $PAGE->courseid, $PAGE->filterselect, $PAGE->tagid - looks like abuse of global variables.

In contrib

204 references, but 122 if you exclude contrib/old on the 1.9 branch. 163 references if you exclude contrib/old on the HEAD branch.

Calls to

  • $PAGE = page_create_object(...)
  • $pageblocks = blocks_setup($PAGE, ...)
  • blocks_print_group($PAGE, ...)
  • $pageblocks = blocks_get_by_page($PAGE)
  • $PAGE->user_allowed_editing()
  • $PAGE->user_is_editing()
  • $missingblocks = blocks_get_missing($PAGE, $pageblocks) Missing blocks are really means blocks that the user is allowed to add to this page.
  • $PAGE->print_header($title)
  • $PAGE->url_get_full(...)
  • unset($PAGE->_user_allowed_editing) horribly, I have seen this hack in several places! will not be backwards compatible, but there will be a new method to do this.

We should be able to support all that in a backwards compatible way.

More complex stuff in

  • patches/blocktopbottom/... - but that will be obsolete.
  • patches/center_blocks_position_patch/... - but that will be obsolete.
  • patches/dragmath seems to ship a custom lib/adminlib.php - no idea why, but I am not going to worry about breaking it.
  • plugins/mod/customlabel/_goodies/course/format/page/actions/activities.php refers to a non-existent $PAGE->print_tabs(...).
  • plugins/theme/wood_custom_corners/header.html does some nasty hacking based on page type. Will break.

I expect most of that will break, but I don't think there is anything that important in that list.

What happens to the various pagelib methods

init_full
init_quick
need to work out if any of this logic is important, and if so move it
✔ blocks_get_positions
✔ blocks_default_position
✔ blocks_move_position
obsoleted by the new blocks system. We will just make deprecated functions that do nothing just to prevent fatal errors.
✔ blocks_get_default
actually, we don't need a general default blocks mechanism. Instead we should be using sticky blocks for most things. The one exception is default blocks on the course page. We will implement that as a special case using the existing $CFG variables.
✔ user_allowed_editing
the logic from subclass implementations needs to be moved elsewhere
✔ user_is_editing
keep
✔ get_type
becomes return $PAGE->pagetype
✔ get_format_name
this is used to filter the allowed blocks by course format, something only about 2 blocks actually take advantage of. I think the correct solution is to set $PAGE->pagetype to, e.g. course-view-weeks or course-edit-weeks on the course view/edit page, and make get_format_name a deprecated synonym for get_type.
get_id
only used by blocklib when working out what blocks appear on a page, so remove after upgrading the blocks database tables
print_header
need to examine the logic in all subclasses, and work out what to do about it
✔ edit_always
only used by admin/stickyblocks.php - though the reference is actually in lib/blockslib.php - remove
✔ url_get_path
✔ url_get_full
keep deprecated implementations in terms of $PAGE->url
✔ url_get_parameters
move logic from subclasses that used to be here elsewhere, then reimplement in terms of $PAGE->url
✔ get_body_class
✔ get_body_id
not used anywhere, remove
✔ init_extra
set_extra_button
✔ set_extra_url_params
hacks I added to the admin page class - fix admin and remove
✔ get_extra_header_string
only used by blog - remove
set_lessonpageid
only used by lesson - remove and use with $PAGE->subpage instead
✔ print_footer
only defined/used in tags - remove.
✔ $CFG->pagepath
This was an evil hack - remove - replace with $PAGE->set_pagetype()
ADMIN_STICKYBLOCKS
this constant is defined by admin/stickyblocks.php as a hack to let the blocks code know we are editing stickyblocks. Remove this once the new blocks editing is done.

See also